Skip to content

Commit 0cb3672

Browse files
committed
Emit parentheses in suggestion for global paths
1 parent dd67fe1 commit 0cb3672

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/librustc/hir/lowering.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ impl<'a> LoweringContext<'a> {
914914
let qpath = self.lower_qpath(t.id, qself, path, ParamMode::Explicit, itctx);
915915
let ty = self.ty_path(id, t.span, qpath);
916916
if let hir::TyTraitObject(..) = ty.node {
917-
self.maybe_lint_bare_trait(t.span, t.id);
917+
self.maybe_lint_bare_trait(t.span, t.id, qself.is_none() && path.is_global());
918918
}
919919
return ty;
920920
}
@@ -955,7 +955,7 @@ impl<'a> LoweringContext<'a> {
955955
self.elided_lifetime(t.span)
956956
});
957957
if kind != TraitObjectSyntax::Dyn {
958-
self.maybe_lint_bare_trait(t.span, t.id);
958+
self.maybe_lint_bare_trait(t.span, t.id, false);
959959
}
960960
hir::TyTraitObject(bounds, lifetime_bound)
961961
}
@@ -3710,12 +3710,12 @@ impl<'a> LoweringContext<'a> {
37103710
}
37113711
}
37123712

3713-
fn maybe_lint_bare_trait(&self, span: Span, id: NodeId) {
3713+
fn maybe_lint_bare_trait(&self, span: Span, id: NodeId, is_global: bool) {
37143714
if self.sess.features.borrow().dyn_trait {
37153715
self.sess.buffer_lint_with_diagnostic(
37163716
builtin::BARE_TRAIT_OBJECT, id, span,
37173717
"trait objects without an explicit `dyn` are deprecated",
3718-
builtin::BuiltinLintDiagnostics::BareTraitObject(span)
3718+
builtin::BuiltinLintDiagnostics::BareTraitObject(span, is_global)
37193719
)
37203720
}
37213721
}

src/librustc/lint/builtin.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,16 @@ impl LintPass for HardwiredLints {
320320
#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)]
321321
pub enum BuiltinLintDiagnostics {
322322
Normal,
323-
BareTraitObject(Span)
323+
BareTraitObject(Span, /* is_global */ bool)
324324
}
325325

326326
impl BuiltinLintDiagnostics {
327327
pub fn run(self, sess: &Session, db: &mut DiagnosticBuilder) {
328328
match self {
329329
BuiltinLintDiagnostics::Normal => (),
330-
BuiltinLintDiagnostics::BareTraitObject(span) => {
330+
BuiltinLintDiagnostics::BareTraitObject(span, is_global) => {
331331
let sugg = match sess.codemap().span_to_snippet(span) {
332+
Ok(ref s) if is_global => format!("dyn ({})", s),
332333
Ok(s) => format!("dyn {}", s),
333334
Err(_) => format!("dyn <type>")
334335
};

0 commit comments

Comments
 (0)