about summary refs log tree commit diff
path: root/compiler/rustc_span/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-12-04 13:23:50 +0000
committerbors <bors@rust-lang.org>2021-12-04 13:23:50 +0000
commitefec545293b9263be9edfb283a7aa66350b3acbf (patch)
tree9cec8a6ff34e219b97d4f32ed62812b50533be54 /compiler/rustc_span/src
parent887999d163bace7e79370b952bdd1f930ff4cdd5 (diff)
parent0311cfa88cd4f86493b197ad4d337eb6085c8c03 (diff)
downloadrust-efec545293b9263be9edfb283a7aa66350b3acbf.tar.gz
rust-efec545293b9263be9edfb283a7aa66350b3acbf.zip
Auto merge of #91517 - matthiaskrgr:rollup-3fmp4go, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #87054 (Add a `try_reduce` method to the Iterator trait)
 - #89701 (Updated error message for accidental uses of derive attribute as a crate attribute)
 - #90519 (Keep spans for generics in `#[derive(_)]` desugaring)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_span/src')
-rw-r--r--compiler/rustc_span/src/lib.rs10
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)