diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2019-03-16 22:33:15 +0100 |
|---|---|---|
| committer | Pietro Albini <pietro@pietroalbini.org> | 2019-04-06 21:18:46 +0200 |
| commit | e6687f39d9d5250bbdbba5dff602fe9f2a1469b5 (patch) | |
| tree | e321ffa81485941a491f9a33177172e65a6f1ac7 /src | |
| parent | c02a36acc170595c488ff96727515d8c56da7539 (diff) | |
| download | rust-e6687f39d9d5250bbdbba5dff602fe9f2a1469b5.tar.gz rust-e6687f39d9d5250bbdbba5dff602fe9f2a1469b5.zip | |
Don't report deprecation lints in derive expansions
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/lint/mod.rs | 17 | ||||
| -rw-r--r-- | src/librustc/middle/stability.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/deprecation/derive_on_deprecated.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/deprecation/derive_on_deprecated_forbidden.rs | 9 |
4 files changed, 38 insertions, 2 deletions
diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 6c60f3f5a80..f2ce9534b50 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -812,7 +812,8 @@ pub fn provide(providers: &mut Providers<'_>) { /// Returns whether `span` originates in a foreign crate's external macro. /// -/// This is used to test whether a lint should be entirely aborted above. +/// This is used to test whether a lint should not even begin to figure out whether it should +/// be reported on the current node. pub fn in_external_macro(sess: &Session, span: Span) -> bool { let info = match span.ctxt().outer().expn_info() { Some(info) => info, @@ -838,3 +839,17 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool { Err(_) => true, } } + +/// Returns whether `span` originates in a derive macro's expansion +pub fn in_derive_expansion(span: Span) -> bool { + let info = match span.ctxt().outer().expn_info() { + Some(info) => info, + // no ExpnInfo means this span doesn't come from a macro + None => return false, + }; + + match info.format { + ExpnFormat::MacroAttribute(symbol) => symbol.as_str().starts_with("derive("), + _ => false, + } +} diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 1190103d849..62a9e9e5d90 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -3,7 +3,7 @@ pub use self::StabilityLevel::*; -use crate::lint::{self, Lint}; +use crate::lint::{self, Lint, in_derive_expansion}; use crate::hir::{self, Item, Generics, StructField, Variant, HirId}; use crate::hir::def::Def; use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE}; @@ -571,6 +571,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { suggestion: Option<Symbol>, message: &str, lint: &'static Lint| { + if in_derive_expansion(span) { + return; + } let msg = if let Some(note) = note { format!("{}: {}", message, note) } else { diff --git a/src/test/ui/deprecation/derive_on_deprecated.rs b/src/test/ui/deprecation/derive_on_deprecated.rs new file mode 100644 index 00000000000..4980a7f5aa3 --- /dev/null +++ b/src/test/ui/deprecation/derive_on_deprecated.rs @@ -0,0 +1,9 @@ +// compile-pass + +#![deny(deprecated)] + +#[deprecated = "oh no"] +#[derive(Default)] +struct X; + +fn main() {} diff --git a/src/test/ui/deprecation/derive_on_deprecated_forbidden.rs b/src/test/ui/deprecation/derive_on_deprecated_forbidden.rs new file mode 100644 index 00000000000..235146bad9c --- /dev/null +++ b/src/test/ui/deprecation/derive_on_deprecated_forbidden.rs @@ -0,0 +1,9 @@ +// compile-pass + +#![forbid(deprecated)] + +#[deprecated = "oh no"] +#[derive(Default)] +struct X; + +fn main() {} |
