diff options
| author | Michael Goulet <michael@errs.io> | 2025-02-24 21:37:01 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-03-04 00:04:01 +0000 |
| commit | 09e584671b439dc8a9d57cc900cc26668a69ddea (patch) | |
| tree | 38763c999f24e795c21a0ccd88a763ba64cccbcf /compiler/rustc_span/src | |
| parent | 06072468fe8de249a39d2fcc42cea51db2649a80 (diff) | |
| download | rust-09e584671b439dc8a9d57cc900cc26668a69ddea.tar.gz rust-09e584671b439dc8a9d57cc900cc26668a69ddea.zip | |
Also note struct access, and fix macro expansion from foreign crates
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index d23e1825e6e..798e186a94b 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1071,9 +1071,17 @@ impl Span { /// /// If "self" is the span of the outer_ident, and "within" is the span of the `($ident,)` /// expr, then this will return the span of the `$ident` macro variable. - pub fn within_macro(self, within: Span) -> Option<Span> { + pub fn within_macro(self, within: Span, sm: &SourceMap) -> Option<Span> { match Span::prepare_to_combine(self, within) { - Ok((self_, _, parent)) if self_.lo != self.lo() && self.hi() != self_.hi => { + // Only return something if it doesn't overlap with the original span, + // and the span isn't "imported" (i.e. from unavailable sources). + // FIXME: This does limit the usefulness of the error when the macro is + // from a foreign crate; we could also take into account `-Zmacro-backtrace`, + // which doesn't redact this span (but that would mean passing in even more + // args to this function, lol). + Ok((self_, _, parent)) + if self_.hi < self.lo() || self.hi() < self_.lo && !sm.is_imported(within) => + { Some(Span::new(self_.lo, self_.hi, self_.ctxt, parent)) } _ => None, |
