Skip to content

Commit

Permalink
lowering: Omit bare trait lint on macro call sites
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidtwco committed Jul 26, 2019
1 parent 44bf6b6 commit cae8680
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
22 changes: 15 additions & 7 deletions src/librustc/hir/lowering.rs
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/suggestions/issue-61963.rs
Expand Up @@ -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>,
Expand Down
10 changes: 2 additions & 8 deletions src/test/ui/suggestions/issue-61963.stderr
@@ -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`
Expand All @@ -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

0 comments on commit cae8680

Please sign in to comment.