Skip to content

Commit a69e12c

Browse files
committed
Don't report deprecation lints in derive expansions
1 parent 2c8bbf5 commit a69e12c

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

src/librustc/lint/mod.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,8 @@ pub fn provide(providers: &mut Providers<'_>) {
833833

834834
/// Returns whether `span` originates in a foreign crate's external macro.
835835
///
836-
/// This is used to test whether a lint should be entirely aborted above.
836+
/// This is used to test whether a lint should not even begin to figure out whether it should
837+
/// be reported on the current node.
837838
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
838839
let info = match span.ctxt().outer().expn_info() {
839840
Some(info) => info,
@@ -859,3 +860,17 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
859860
Err(_) => true,
860861
}
861862
}
863+
864+
/// Returns whether `span` originates in a derive macro's expansion
865+
pub fn in_derive_expansion(span: Span) -> bool {
866+
let info = match span.ctxt().outer().expn_info() {
867+
Some(info) => info,
868+
// no ExpnInfo means this span doesn't come from a macro
869+
None => return false,
870+
};
871+
872+
match info.format {
873+
ExpnFormat::MacroAttribute(symbol) => symbol.as_str().starts_with("derive("),
874+
_ => false,
875+
}
876+
}

src/librustc/middle/stability.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
pub use self::StabilityLevel::*;
55

6-
use crate::lint::{self, Lint};
6+
use crate::lint::{self, Lint, in_derive_expansion};
77
use crate::hir::{self, Item, Generics, StructField, Variant, HirId};
88
use crate::hir::def::Def;
99
use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
@@ -561,6 +561,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
561561
suggestion: Option<Symbol>,
562562
message: &str,
563563
lint: &'static Lint| {
564+
if in_derive_expansion(span) {
565+
return;
566+
}
564567
let msg = if let Some(note) = note {
565568
format!("{}: {}", message, note)
566569
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-pass
2+
3+
#![deny(deprecated)]
4+
5+
#[deprecated = "oh no"]
6+
#[derive(Default)]
7+
struct X;
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-pass
2+
3+
#![forbid(deprecated)]
4+
5+
#[deprecated = "oh no"]
6+
#[derive(Default)]
7+
struct X;
8+
9+
fn main() {}

0 commit comments

Comments
 (0)