Skip to content

Commit dca160a

Browse files
committed
diagnostics: use module_path to check crate import instead of strings
1 parent e237690 commit dca160a

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+4-20
Original file line numberDiff line numberDiff line change
@@ -2126,26 +2126,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
21262126
let source_map = self.r.session.source_map();
21272127

21282128
// Make sure this is actually crate-relative.
2129-
let use_and_crate = import.use_span.with_hi(after_crate_name.lo());
2130-
let is_definitely_crate =
2131-
source_map.span_to_snippet(use_and_crate).map_or(false, |s| {
2132-
let mut s = s.trim();
2133-
debug!("check_for_module_export_macro: s={s:?}",);
2134-
s = s
2135-
.split_whitespace()
2136-
.rev()
2137-
.next()
2138-
.expect("split_whitespace always yields at least once");
2139-
debug!("check_for_module_export_macro: s={s:?}",);
2140-
if s.ends_with("::") {
2141-
s = &s[..s.len() - 2];
2142-
} else {
2143-
return false;
2144-
}
2145-
s = s.trim();
2146-
debug!("check_for_module_export_macro: s={s:?}",);
2147-
s != "self" && s != "super"
2148-
});
2129+
let is_definitely_crate = import
2130+
.module_path
2131+
.first()
2132+
.map_or(false, |f| f.ident.name != kw::SelfLower && f.ident.name != kw::Super);
21492133

21502134
// Add the import to the start, with a `{` if required.
21512135
let start_point = source_map.start_point(after_crate_name);

0 commit comments

Comments
 (0)