Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add suggestion to lint
  • Loading branch information
Manishearth committed Apr 20, 2018
commit f56c61face0e6ca8eaef8d872413e984c717657b
20 changes: 19 additions & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ impl LintPass for HardwiredLints {
#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)]
pub enum BuiltinLintDiagnostics {
Normal,
BareTraitObject(Span, /* is_global */ bool)
BareTraitObject(Span, /* is_global */ bool),
AbsPathWithModule(Span),
}

impl BuiltinLintDiagnostics {
Expand All @@ -347,6 +348,23 @@ impl BuiltinLintDiagnostics {
};
db.span_suggestion(span, "use `dyn`", sugg);
}
BuiltinLintDiagnostics::AbsPathWithModule(span) => {
let sugg = match sess.codemap().span_to_snippet(span) {
Ok(ref s) => {
// FIXME(Manishearth) ideally the emitting code
// can tell us whether or not this is global
let opt_colon = if s.trim_left().starts_with("::") {
""
} else {
"::"
};

format!("crate{}{}", opt_colon, s)
}
Err(_) => format!("crate::<path>")
};
db.span_suggestion(span, "use `crate`", sugg);
}
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3344,11 +3344,14 @@ impl<'a> Resolver<'a> {
}

if !is_crate {
self.session.buffer_lint(
let diag = lint::builtin::BuiltinLintDiagnostics
::AbsPathWithModule(path_span);
self.session.buffer_lint_with_diagnostic(
lint::builtin::ABSOLUTE_PATH_STARTING_WITH_MODULE,
id, path_span,
"Fully-qualified paths must start with `self`, `super`,
`crate`, or an external crate name in the 2018 edition");
"Absolute paths must start with `self`, `super`, \
`crate`, or an external crate name in the 2018 edition",
diag);
}
}
}
Expand Down