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:
David Wood 2019-07-26 17:31:39 +01:00
parent 44bf6b6f55
commit cae8680544
No known key found for this signature in database
GPG key ID: 2592E76C87381FD9
3 changed files with 17 additions and 16 deletions

View file

@ -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(

View file

@ -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>,

View file

@ -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