mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Don't report deprecation lints in derive expansions
This commit is contained in:
parent
2c8bbf50db
commit
a69e12c21b
@ -833,7 +833,8 @@ pub fn provide(providers: &mut Providers<'_>) {
|
|||||||
|
|
||||||
/// Returns whether `span` originates in a foreign crate's external macro.
|
/// 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 {
|
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
|
||||||
let info = match span.ctxt().outer().expn_info() {
|
let info = match span.ctxt().outer().expn_info() {
|
||||||
Some(info) => info,
|
Some(info) => info,
|
||||||
@ -859,3 +860,17 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
|
|||||||
Err(_) => true,
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
pub use self::StabilityLevel::*;
|
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::{self, Item, Generics, StructField, Variant, HirId};
|
||||||
use crate::hir::def::Def;
|
use crate::hir::def::Def;
|
||||||
use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
|
use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
|
||||||
@ -561,6 +561,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
suggestion: Option<Symbol>,
|
suggestion: Option<Symbol>,
|
||||||
message: &str,
|
message: &str,
|
||||||
lint: &'static Lint| {
|
lint: &'static Lint| {
|
||||||
|
if in_derive_expansion(span) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let msg = if let Some(note) = note {
|
let msg = if let Some(note) = note {
|
||||||
format!("{}: {}", message, note)
|
format!("{}: {}", message, note)
|
||||||
} else {
|
} else {
|
||||||
|
9
src/test/ui/deprecation/derive_on_deprecated.rs
Normal file
9
src/test/ui/deprecation/derive_on_deprecated.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// compile-pass
|
||||||
|
|
||||||
|
#![deny(deprecated)]
|
||||||
|
|
||||||
|
#[deprecated = "oh no"]
|
||||||
|
#[derive(Default)]
|
||||||
|
struct X;
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,9 @@
|
|||||||
|
// compile-pass
|
||||||
|
|
||||||
|
#![forbid(deprecated)]
|
||||||
|
|
||||||
|
#[deprecated = "oh no"]
|
||||||
|
#[derive(Default)]
|
||||||
|
struct X;
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user