Add suggestion to lint

This commit is contained in:
Manish Goregaokar 2018-04-19 19:51:53 -07:00
parent 37d3bea3ec
commit f56c61face
2 changed files with 25 additions and 4 deletions

View File

@ -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 {
@ -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);
}
}
}
}

View File

@ -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);
}
}
}