Skip to content

Commit

Permalink
Emit parentheses in suggestion for global paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Feb 28, 2018
1 parent dd67fe1 commit 0cb3672
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ impl<'a> LoweringContext<'a> {
let qpath = self.lower_qpath(t.id, qself, path, ParamMode::Explicit, itctx);
let ty = self.ty_path(id, t.span, qpath);
if let hir::TyTraitObject(..) = ty.node {
self.maybe_lint_bare_trait(t.span, t.id);
self.maybe_lint_bare_trait(t.span, t.id, qself.is_none() && path.is_global());
}
return ty;
}
Expand Down Expand Up @@ -955,7 +955,7 @@ impl<'a> LoweringContext<'a> {
self.elided_lifetime(t.span)
});
if kind != TraitObjectSyntax::Dyn {
self.maybe_lint_bare_trait(t.span, t.id);
self.maybe_lint_bare_trait(t.span, t.id, false);
}
hir::TyTraitObject(bounds, lifetime_bound)
}
Expand Down Expand Up @@ -3710,12 +3710,12 @@ impl<'a> LoweringContext<'a> {
}
}

fn maybe_lint_bare_trait(&self, span: Span, id: NodeId) {
fn maybe_lint_bare_trait(&self, span: Span, id: NodeId, is_global: bool) {
if self.sess.features.borrow().dyn_trait {
self.sess.buffer_lint_with_diagnostic(
builtin::BARE_TRAIT_OBJECT, id, span,
"trait objects without an explicit `dyn` are deprecated",
builtin::BuiltinLintDiagnostics::BareTraitObject(span)
builtin::BuiltinLintDiagnostics::BareTraitObject(span, is_global)
)
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,16 @@ impl LintPass for HardwiredLints {
#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)]
pub enum BuiltinLintDiagnostics {
Normal,
BareTraitObject(Span)
BareTraitObject(Span, /* is_global */ bool)
}

impl BuiltinLintDiagnostics {
pub fn run(self, sess: &Session, db: &mut DiagnosticBuilder) {
match self {
BuiltinLintDiagnostics::Normal => (),
BuiltinLintDiagnostics::BareTraitObject(span) => {
BuiltinLintDiagnostics::BareTraitObject(span, is_global) => {
let sugg = match sess.codemap().span_to_snippet(span) {
Ok(ref s) if is_global => format!("dyn ({})", s),
Ok(s) => format!("dyn {}", s),
Err(_) => format!("dyn <type>")
};
Expand Down

0 comments on commit 0cb3672

Please sign in to comment.