]> git.lizzy.rs Git - rust.git/commitdiff
diagnostics: use `module_path` to check crate import instead of strings
authorMichael Howell <michael@notriddle.com>
Tue, 6 Dec 2022 15:42:30 +0000 (08:42 -0700)
committerMichael Howell <michael@notriddle.com>
Fri, 20 Jan 2023 21:53:34 +0000 (14:53 -0700)
compiler/rustc_resolve/src/diagnostics.rs

index af4d7a8eafff3afb2172167a3b6e659757adde79..0b60952ae3c0865ac567d3bbb8f0f74d1c759a6b 100644 (file)
@@ -2126,26 +2126,10 @@ pub(crate) fn check_for_module_export_macro(
                 let source_map = self.r.session.source_map();
 
                 // Make sure this is actually crate-relative.
-                let use_and_crate = import.use_span.with_hi(after_crate_name.lo());
-                let is_definitely_crate =
-                    source_map.span_to_snippet(use_and_crate).map_or(false, |s| {
-                        let mut s = s.trim();
-                        debug!("check_for_module_export_macro: s={s:?}",);
-                        s = s
-                            .split_whitespace()
-                            .rev()
-                            .next()
-                            .expect("split_whitespace always yields at least once");
-                        debug!("check_for_module_export_macro: s={s:?}",);
-                        if s.ends_with("::") {
-                            s = &s[..s.len() - 2];
-                        } else {
-                            return false;
-                        }
-                        s = s.trim();
-                        debug!("check_for_module_export_macro: s={s:?}",);
-                        s != "self" && s != "super"
-                    });
+                let is_definitely_crate = import
+                    .module_path
+                    .first()
+                    .map_or(false, |f| f.ident.name != kw::SelfLower && f.ident.name != kw::Super);
 
                 // Add the import to the start, with a `{` if required.
                 let start_point = source_map.start_point(after_crate_name);