Skip to content

Commit 04af19f

Browse files
committed
diagnostics: use module_path to check crate import instead of strings
1 parent 98091c0 commit 04af19f

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,26 +2286,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
22862286
let source_map = self.r.session.source_map();
22872287

22882288
// Make sure this is actually crate-relative.
2289-
let use_and_crate = import.use_span.with_hi(after_crate_name.lo());
2290-
let is_definitely_crate =
2291-
source_map.span_to_snippet(use_and_crate).map_or(false, |s| {
2292-
let mut s = s.trim();
2293-
debug!("check_for_module_export_macro: s={s:?}",);
2294-
s = s
2295-
.split_whitespace()
2296-
.rev()
2297-
.next()
2298-
.expect("split_whitespace always yields at least once");
2299-
debug!("check_for_module_export_macro: s={s:?}",);
2300-
if s.ends_with("::") {
2301-
s = &s[..s.len() - 2];
2302-
} else {
2303-
return false;
2304-
}
2305-
s = s.trim();
2306-
debug!("check_for_module_export_macro: s={s:?}",);
2307-
s != "self" && s != "super"
2308-
});
2289+
let is_definitely_crate = import
2290+
.module_path
2291+
.first()
2292+
.map_or(false, |f| f.ident.name != kw::SelfLower && f.ident.name != kw::Super);
23092293

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

0 commit comments

Comments
 (0)