lowering: Omit bare trait lint on macro call sites
This commit implements a hacky fix for detecting when a span is pointing at a macro call site so that bare trait lints are not made incorrectly.
This commit is contained in:
parent
44bf6b6f55
commit
cae8680544
3 changed files with 17 additions and 16 deletions
|
@ -5754,13 +5754,21 @@ impl<'a> LoweringContext<'a> {
|
|||
}
|
||||
|
||||
fn maybe_lint_bare_trait(&self, span: Span, id: NodeId, is_global: bool) {
|
||||
self.sess.buffer_lint_with_diagnostic(
|
||||
builtin::BARE_TRAIT_OBJECTS,
|
||||
id,
|
||||
span,
|
||||
"trait objects without an explicit `dyn` are deprecated",
|
||||
builtin::BuiltinLintDiagnostics::BareTraitObject(span, is_global),
|
||||
)
|
||||
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
|
||||
// call site which do not have a macro backtrace. See #61963.
|
||||
let is_macro_callsite = self.sess.source_map()
|
||||
.span_to_snippet(span)
|
||||
.map(|snippet| snippet.starts_with("#["))
|
||||
.unwrap_or(true);
|
||||
if !is_macro_callsite {
|
||||
self.sess.buffer_lint_with_diagnostic(
|
||||
builtin::BARE_TRAIT_OBJECTS,
|
||||
id,
|
||||
span,
|
||||
"trait objects without an explicit `dyn` are deprecated",
|
||||
builtin::BuiltinLintDiagnostics::BareTraitObject(span, is_global),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn wrap_in_try_constructor(
|
||||
|
|
|
@ -15,7 +15,6 @@ pub trait Bar { }
|
|||
pub struct Qux<T>(T);
|
||||
|
||||
#[dom_struct]
|
||||
//~^ ERROR trait objects without an explicit `dyn` are deprecated [bare_trait_objects]
|
||||
pub struct Foo {
|
||||
qux: Qux<Qux<Baz>>,
|
||||
bar: Box<Bar>,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: trait objects without an explicit `dyn` are deprecated
|
||||
--> $DIR/issue-61963.rs:21:14
|
||||
--> $DIR/issue-61963.rs:20:14
|
||||
|
|
||||
LL | bar: Box<Bar>,
|
||||
| ^^^ help: use `dyn`: `dyn Bar`
|
||||
|
@ -10,11 +10,5 @@ note: lint level defined here
|
|||
LL | #![deny(bare_trait_objects)]
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: trait objects without an explicit `dyn` are deprecated
|
||||
--> $DIR/issue-61963.rs:17:1
|
||||
|
|
||||
LL | #[dom_struct]
|
||||
| ^^^^^^^^^^^^^ help: use `dyn`: `dyn #[dom_struct]`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
Loading…
Reference in a new issue