Skip to content

Rollup of 5 pull requests #63864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
7 changes: 3 additions & 4 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,19 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
});
}

fn visit_variant(&mut self, v: &'a Variant, g: &'a Generics, item_id: NodeId) {
fn visit_variant(&mut self, v: &'a Variant) {
let def = self.create_def(v.id,
DefPathData::TypeNs(v.ident.as_interned_str()),
v.span);
self.with_parent(def, |this| {
if let Some(ctor_hir_id) = v.data.ctor_id() {
this.create_def(ctor_hir_id, DefPathData::Ctor, v.span);
}
visit::walk_variant(this, v, g, item_id)
visit::walk_variant(this, v)
});
}

fn visit_variant_data(&mut self, data: &'a VariantData, _: Ident,
_: &'a Generics, _: NodeId, _: Span) {
fn visit_variant_data(&mut self, data: &'a VariantData) {
for (index, field) in data.fields().iter().enumerate() {
let name = field.ident.map(|ident| ident.name)
.unwrap_or_else(|| sym::integer(index));
Expand Down
35 changes: 15 additions & 20 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,13 +1040,13 @@ for LateContextAndPass<'a, 'tcx, T> {

fn visit_variant_data(&mut self,
s: &'tcx hir::VariantData,
name: ast::Name,
g: &'tcx hir::Generics,
item_id: hir::HirId,
_: ast::Name,
_: &'tcx hir::Generics,
_: hir::HirId,
_: Span) {
lint_callback!(self, check_struct_def, s, name, g, item_id);
lint_callback!(self, check_struct_def, s);
hir_visit::walk_struct_def(self, s);
lint_callback!(self, check_struct_def_post, s, name, g, item_id);
lint_callback!(self, check_struct_def_post, s);
}

fn visit_struct_field(&mut self, s: &'tcx hir::StructField) {
Expand All @@ -1061,9 +1061,9 @@ for LateContextAndPass<'a, 'tcx, T> {
g: &'tcx hir::Generics,
item_id: hir::HirId) {
self.with_lint_attrs(v.id, &v.attrs, |cx| {
lint_callback!(cx, check_variant, v, g);
lint_callback!(cx, check_variant, v);
hir_visit::walk_variant(cx, v, g, item_id);
lint_callback!(cx, check_variant_post, v, g);
lint_callback!(cx, check_variant_post, v);
})
}

Expand Down Expand Up @@ -1214,18 +1214,13 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
run_early_pass!(self, check_fn_post, fk, decl, span, id);
}

fn visit_variant_data(&mut self,
s: &'a ast::VariantData,
ident: ast::Ident,
g: &'a ast::Generics,
item_id: ast::NodeId,
_: Span) {
run_early_pass!(self, check_struct_def, s, ident, g, item_id);
fn visit_variant_data(&mut self, s: &'a ast::VariantData) {
run_early_pass!(self, check_struct_def, s);
if let Some(ctor_hir_id) = s.ctor_id() {
self.check_id(ctor_hir_id);
}
ast_visit::walk_struct_def(self, s);
run_early_pass!(self, check_struct_def_post, s, ident, g, item_id);
run_early_pass!(self, check_struct_def_post, s);
}

fn visit_struct_field(&mut self, s: &'a ast::StructField) {
Expand All @@ -1235,11 +1230,11 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
})
}

fn visit_variant(&mut self, v: &'a ast::Variant, g: &'a ast::Generics, item_id: ast::NodeId) {
self.with_lint_attrs(item_id, &v.attrs, |cx| {
run_early_pass!(cx, check_variant, v, g);
ast_visit::walk_variant(cx, v, g, item_id);
run_early_pass!(cx, check_variant_post, v, g);
fn visit_variant(&mut self, v: &'a ast::Variant) {
self.with_lint_attrs(v.id, &v.attrs, |cx| {
run_early_pass!(cx, check_variant, v);
ast_visit::walk_variant(cx, v);
run_early_pass!(cx, check_variant_post, v);
})
}

Expand Down
36 changes: 8 additions & 28 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,11 @@ macro_rules! late_lint_methods {
fn check_trait_item_post(a: &$hir hir::TraitItem);
fn check_impl_item(a: &$hir hir::ImplItem);
fn check_impl_item_post(a: &$hir hir::ImplItem);
fn check_struct_def(
a: &$hir hir::VariantData,
b: ast::Name,
c: &$hir hir::Generics,
d: hir::HirId
);
fn check_struct_def_post(
a: &$hir hir::VariantData,
b: ast::Name,
c: &$hir hir::Generics,
d: hir::HirId
);
fn check_struct_def(a: &$hir hir::VariantData);
fn check_struct_def_post(a: &$hir hir::VariantData);
fn check_struct_field(a: &$hir hir::StructField);
fn check_variant(a: &$hir hir::Variant, b: &$hir hir::Generics);
fn check_variant_post(a: &$hir hir::Variant, b: &$hir hir::Generics);
fn check_variant(a: &$hir hir::Variant);
fn check_variant_post(a: &$hir hir::Variant);
fn check_lifetime(a: &$hir hir::Lifetime);
fn check_path(a: &$hir hir::Path, b: hir::HirId);
fn check_attribute(a: &$hir ast::Attribute);
Expand Down Expand Up @@ -395,21 +385,11 @@ macro_rules! early_lint_methods {
fn check_trait_item_post(a: &ast::TraitItem);
fn check_impl_item(a: &ast::ImplItem);
fn check_impl_item_post(a: &ast::ImplItem);
fn check_struct_def(
a: &ast::VariantData,
b: ast::Ident,
c: &ast::Generics,
d: ast::NodeId
);
fn check_struct_def_post(
a: &ast::VariantData,
b: ast::Ident,
c: &ast::Generics,
d: ast::NodeId
);
fn check_struct_def(a: &ast::VariantData);
fn check_struct_def_post(a: &ast::VariantData);
fn check_struct_field(a: &ast::StructField);
fn check_variant(a: &ast::Variant, b: &ast::Generics);
fn check_variant_post(a: &ast::Variant, b: &ast::Generics);
fn check_variant(a: &ast::Variant);
fn check_variant_post(a: &ast::Variant);
fn check_lifetime(a: &ast::Lifetime);
fn check_path(a: &ast::Path, b: ast::NodeId);
fn check_attribute(a: &ast::Attribute);
Expand Down
18 changes: 11 additions & 7 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1719,13 +1719,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
static, framework, or dylib (the default).",
"[KIND=]NAME",
),
opt::multi_s(
"",
"crate-type",
"Comma separated list of types of crates
for the compiler to emit",
"[bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]",
),
make_crate_type_option(),
opt::opt_s(
"",
"crate-name",
Expand Down Expand Up @@ -2506,6 +2500,16 @@ pub fn build_session_options_and_crate_config(
)
}

pub fn make_crate_type_option() -> RustcOptGroup {
opt::multi_s(
"",
"crate-type",
"Comma separated list of types of crates
for the compiler to emit",
"[bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]",
)
}

pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateType>, String> {
let mut crate_types: Vec<CrateType> = Vec::new();
for unparsed_crate_type in &list_list {
Expand Down
37 changes: 16 additions & 21 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,27 +473,22 @@ fn configure_and_expand_inner<'a>(
ast_validation::check_crate(sess, &krate)
});

// If we're in rustdoc we're always compiling as an rlib, but that'll trip a
// bunch of checks in the `modify` function below. For now just skip this
// step entirely if we're rustdoc as it's not too useful anyway.
if !sess.opts.actually_rustdoc {
krate = time(sess, "maybe creating a macro crate", || {
let crate_types = sess.crate_types.borrow();
let num_crate_types = crate_types.len();
let is_proc_macro_crate = crate_types.contains(&config::CrateType::ProcMacro);
let is_test_crate = sess.opts.test;
syntax_ext::proc_macro_harness::inject(
&sess.parse_sess,
&mut resolver,
krate,
is_proc_macro_crate,
has_proc_macro_decls,
is_test_crate,
num_crate_types,
sess.diagnostic(),
)
});
}
krate = time(sess, "maybe creating a macro crate", || {
let crate_types = sess.crate_types.borrow();
let num_crate_types = crate_types.len();
let is_proc_macro_crate = crate_types.contains(&config::CrateType::ProcMacro);
let is_test_crate = sess.opts.test;
syntax_ext::proc_macro_harness::inject(
&sess.parse_sess,
&mut resolver,
krate,
is_proc_macro_crate,
has_proc_macro_decls,
is_test_crate,
num_crate_types,
sess.diagnostic(),
)
});

// Done with macro expansion!

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
}
}

fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant, _: &hir::Generics) {
fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant) {
self.check_missing_docs_attrs(cx,
Some(v.id),
&v.attrs,
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_lint/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
}
}

fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant, _: &ast::Generics) {
fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant) {
self.check_case(cx, "variant", &v.ident);
}

Expand Down Expand Up @@ -350,9 +350,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
&mut self,
cx: &LateContext<'_, '_>,
s: &hir::VariantData,
_: ast::Name,
_: &hir::Generics,
_: hir::HirId,
) {
for sf in s.fields() {
self.check_snake_case(cx, "structure field", &sf.ident);
Expand Down
84 changes: 43 additions & 41 deletions src/librustc_mir/borrow_check/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,20 +415,21 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
"{:?}",
move_place.ty(self.body, self.infcx.tcx).ty,
);
let snippet = self.infcx.tcx.sess.source_map().span_to_snippet(span).unwrap();
let is_option = move_ty.starts_with("std::option::Option");
let is_result = move_ty.starts_with("std::result::Result");
if is_option || is_result {
err.span_suggestion(
span,
&format!("consider borrowing the `{}`'s content", if is_option {
"Option"
} else {
"Result"
}),
format!("{}.as_ref()", snippet),
Applicability::MaybeIncorrect,
);
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
let is_option = move_ty.starts_with("std::option::Option");
let is_result = move_ty.starts_with("std::result::Result");
if is_option || is_result {
err.span_suggestion(
span,
&format!("consider borrowing the `{}`'s content", if is_option {
"Option"
} else {
"Result"
}),
format!("{}.as_ref()", snippet),
Applicability::MaybeIncorrect,
);
}
}
err
}
Expand All @@ -439,19 +440,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err: &mut DiagnosticBuilder<'a>,
span: Span,
) {
let snippet = self.infcx.tcx.sess.source_map().span_to_snippet(span).unwrap();
match error {
GroupedMoveError::MovesFromPlace {
mut binds_to,
move_from,
..
} => {
err.span_suggestion(
span,
"consider borrowing here",
format!("&{}", snippet),
Applicability::Unspecified,
);
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
err.span_suggestion(
span,
"consider borrowing here",
format!("&{}", snippet),
Applicability::Unspecified,
);
}

if binds_to.is_empty() {
let place_ty = move_from.ty(self.body, self.infcx.tcx).ty;
Expand Down Expand Up @@ -517,27 +519,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
..
}))
) = bind_to.is_user_variable {
let pat_snippet = self.infcx.tcx.sess.source_map()
.span_to_snippet(pat_span)
.unwrap();
if pat_snippet.starts_with('&') {
let pat_snippet = pat_snippet[1..].trim_start();
let suggestion;
let to_remove;
if pat_snippet.starts_with("mut")
&& pat_snippet["mut".len()..].starts_with(Pattern_White_Space)
{
suggestion = pat_snippet["mut".len()..].trim_start();
to_remove = "&mut";
} else {
suggestion = pat_snippet;
to_remove = "&";
if let Ok(pat_snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(pat_span)
{
if pat_snippet.starts_with('&') {
let pat_snippet = pat_snippet[1..].trim_start();
let suggestion;
let to_remove;
if pat_snippet.starts_with("mut")
&& pat_snippet["mut".len()..].starts_with(Pattern_White_Space)
{
suggestion = pat_snippet["mut".len()..].trim_start();
to_remove = "&mut";
} else {
suggestion = pat_snippet;
to_remove = "&";
}
suggestions.push((
pat_span,
to_remove,
suggestion.to_owned(),
));
}
suggestions.push((
pat_span,
to_remove,
suggestion.to_owned(),
));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@ fn annotate_struct_field(
}

/// If possible, suggest replacing `ref` with `ref mut`.
fn suggest_ref_mut(tcx: TyCtxt<'_>, binding_span: Span) -> Option<(String)> {
let hi_src = tcx.sess.source_map().span_to_snippet(binding_span).unwrap();
fn suggest_ref_mut(tcx: TyCtxt<'_>, binding_span: Span) -> Option<String> {
let hi_src = tcx.sess.source_map().span_to_snippet(binding_span).ok()?;
if hi_src.starts_with("ref")
&& hi_src["ref".len()..].starts_with(Pattern_White_Space)
{
Expand Down
Loading