move in_derive_expansion as Span method

This commit is contained in:
Mazdak Farrokhzad 2020-01-09 03:03:48 +01:00
parent 3a2af3242c
commit b93addba7a
3 changed files with 7 additions and 11 deletions

View File

@ -494,11 +494,3 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
ExpnKind::Macro(..) => true, // definitely a plugin
}
}
/// Returns `true` if `span` originates in a derive-macro's expansion.
pub fn in_derive_expansion(span: Span) -> bool {
if let ExpnKind::Macro(MacroKind::Derive, _) = span.ctxt().outer_expn_data().kind {
return true;
}
false
}

View File

@ -3,7 +3,6 @@
pub use self::StabilityLevel::*;
use crate::lint::in_derive_expansion;
use crate::session::{DiagnosticMessageId, Session};
use crate::ty::{self, TyCtxt};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@ -201,7 +200,7 @@ pub fn early_report_deprecation(
lint: &'static Lint,
span: Span,
) {
if in_derive_expansion(span) {
if span.in_derive_expansion() {
return;
}
@ -218,7 +217,7 @@ fn late_report_deprecation(
def_id: DefId,
hir_id: HirId,
) {
if in_derive_expansion(span) {
if span.in_derive_expansion() {
return;
}

View File

@ -309,6 +309,11 @@ impl Span {
self.ctxt() != SyntaxContext::root()
}
/// Returns `true` if `span` originates in a derive-macro's expansion.
pub fn in_derive_expansion(self) -> bool {
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))
}
#[inline]
pub fn with_root_ctxt(lo: BytePos, hi: BytePos) -> Span {
Span::new(lo, hi, SyntaxContext::root())