diff options
| author | Esteban Kuber <esteban@kuber.com.ar> | 2021-11-20 18:46:36 +0000 |
|---|---|---|
| committer | Esteban Kuber <esteban@kuber.com.ar> | 2021-12-03 18:41:40 +0000 |
| commit | 962b2197a5d5796ee030a05f534ee0fde8ce07bb (patch) | |
| tree | b9cec8cf9bceb90e7ad55c5f669eee43a29da822 /compiler/rustc_span | |
| parent | 8bee2b88c075a2f007a7d5762727a840477c0893 (diff) | |
| download | rust-962b2197a5d5796ee030a05f534ee0fde8ce07bb.tar.gz rust-962b2197a5d5796ee030a05f534ee0fde8ce07bb.zip | |
Annotate `derive`d spans and move span suggestion code
* Annotate `derive`d spans from the user's code with the appropciate context * Add `Span::can_be_used_for_suggestion` to query if the underlying span at the users' code
Diffstat (limited to 'compiler/rustc_span')
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 66c01140abc..98478cf5dec 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -551,6 +551,16 @@ impl Span { matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _)) } + /// Gate suggestions that would not be appropriate in a context the user didn't write. + pub fn can_be_used_for_suggestions(self) -> bool { + !self.from_expansion() + // FIXME: If this span comes from a `derive` macro but it points at code the user wrote, + // the callsite span and the span will be pointing at different places. It also means that + // we can safely provide suggestions on this span. + || (matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _)) + && self.parent_callsite().map(|p| (p.lo(), p.hi())) != Some((self.lo(), self.hi()))) + } + #[inline] pub fn with_root_ctxt(lo: BytePos, hi: BytePos) -> Span { Span::new(lo, hi, SyntaxContext::root(), None) |
