Skip to content

Commit 41885a4

Browse files
authored
Rollup merge of rust-lang#135826 - yotamofek:resolve-cleanups4, r=petrochenkov
Misc. `rustc_resolve` cleanups Hopefully this PR should make `rustc_resolve` a bit cleaner. Each commit here stands on its own. I tried to only include changes that are easy to review, and are a clear improvement. (but I'll be happy to revert any changes that turn out to be more controversial than I'd thought) Best viewed with whitespace ignored 😁 (especially [these two commits](https://github.com/rust-lang/rust/pull/135826/files/a93616acf3118ef233027d74e8c636f9b79c342d..ae87d005bc92cbecc47b554e634d1bd3d22e1068?diff=unified&w=1))
2 parents 672d2de + efabee2 commit 41885a4

File tree

6 files changed

+562
-606
lines changed

6 files changed

+562
-606
lines changed

Diff for: compiler/rustc_resolve/src/build_reduced_graph.rs

+26-28
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,10 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
645645
let self_spans = items
646646
.iter()
647647
.filter_map(|(use_tree, _)| {
648-
if let ast::UseTreeKind::Simple(..) = use_tree.kind {
649-
if use_tree.ident().name == kw::SelfLower {
650-
return Some(use_tree.span);
651-
}
648+
if let ast::UseTreeKind::Simple(..) = use_tree.kind
649+
&& use_tree.ident().name == kw::SelfLower
650+
{
651+
return Some(use_tree.span);
652652
}
653653

654654
None
@@ -947,19 +947,19 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
947947
let imported_binding = self.r.import(binding, import);
948948
if parent == self.r.graph_root {
949949
let ident = ident.normalize_to_macros_2_0();
950-
if let Some(entry) = self.r.extern_prelude.get(&ident) {
951-
if expansion != LocalExpnId::ROOT && orig_name.is_some() && !entry.is_import() {
952-
self.r.dcx().emit_err(
953-
errors::MacroExpandedExternCrateCannotShadowExternArguments {
954-
span: item.span,
955-
},
956-
);
957-
// `return` is intended to discard this binding because it's an
958-
// unregistered ambiguity error which would result in a panic
959-
// caused by inconsistency `path_res`
960-
// more details: https://github.com/rust-lang/rust/pull/111761
961-
return;
962-
}
950+
if let Some(entry) = self.r.extern_prelude.get(&ident)
951+
&& expansion != LocalExpnId::ROOT
952+
&& orig_name.is_some()
953+
&& !entry.is_import()
954+
{
955+
self.r.dcx().emit_err(
956+
errors::MacroExpandedExternCrateCannotShadowExternArguments { span: item.span },
957+
);
958+
// `return` is intended to discard this binding because it's an
959+
// unregistered ambiguity error which would result in a panic
960+
// caused by inconsistency `path_res`
961+
// more details: https://github.com/rust-lang/rust/pull/111761
962+
return;
963963
}
964964
let entry = self
965965
.r
@@ -1040,10 +1040,10 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
10401040
span: item.span,
10411041
});
10421042
}
1043-
if let ItemKind::ExternCrate(Some(orig_name)) = item.kind {
1044-
if orig_name == kw::SelfLower {
1045-
self.r.dcx().emit_err(errors::MacroUseExternCrateSelf { span: attr.span });
1046-
}
1043+
if let ItemKind::ExternCrate(Some(orig_name)) = item.kind
1044+
&& orig_name == kw::SelfLower
1045+
{
1046+
self.r.dcx().emit_err(errors::MacroUseExternCrateSelf { span: attr.span });
10471047
}
10481048
let ill_formed = |span| {
10491049
self.r.dcx().emit_err(errors::BadMacroImport { span });
@@ -1179,14 +1179,12 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
11791179
return Some((MacroKind::Bang, item.ident, item.span));
11801180
} else if ast::attr::contains_name(&item.attrs, sym::proc_macro_attribute) {
11811181
return Some((MacroKind::Attr, item.ident, item.span));
1182-
} else if let Some(attr) = ast::attr::find_by_name(&item.attrs, sym::proc_macro_derive) {
1183-
if let Some(meta_item_inner) =
1182+
} else if let Some(attr) = ast::attr::find_by_name(&item.attrs, sym::proc_macro_derive)
1183+
&& let Some(meta_item_inner) =
11841184
attr.meta_item_list().and_then(|list| list.get(0).cloned())
1185-
{
1186-
if let Some(ident) = meta_item_inner.ident() {
1187-
return Some((MacroKind::Derive, ident, ident.span));
1188-
}
1189-
}
1185+
&& let Some(ident) = meta_item_inner.ident()
1186+
{
1187+
return Some((MacroKind::Derive, ident, ident.span));
11901188
}
11911189
None
11921190
}

0 commit comments

Comments
 (0)