mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add suggestion to lint
This commit is contained in:
parent
37d3bea3ec
commit
f56c61face
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user