lint: port unused diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
0602729c71
commit
1999a4c421
2 changed files with 56 additions and 30 deletions
|
@ -251,3 +251,25 @@ lint-atomic-ordering-invalid-fail-success = `{$method}`'s success ordering must
|
||||||
.fail-label = `{$fail_ordering}` failure ordering
|
.fail-label = `{$fail_ordering}` failure ordering
|
||||||
.success-label = `{$success_ordering}` success ordering
|
.success-label = `{$success_ordering}` success ordering
|
||||||
.suggestion = consider using `{$success_suggestion}` success ordering instead
|
.suggestion = consider using `{$success_suggestion}` success ordering instead
|
||||||
|
|
||||||
|
lint-unused-op = unused {$op} that must be used
|
||||||
|
.label = the {$op} produces a value
|
||||||
|
.suggestion = use `let _ = ...` to ignore the resulting value
|
||||||
|
|
||||||
|
lint-unused-result = unused result of type `{$ty}`
|
||||||
|
|
||||||
|
lint-unused-closure =
|
||||||
|
unused {$pre}{$count ->
|
||||||
|
[one] closure
|
||||||
|
*[other] closures
|
||||||
|
}{$post} that must be used
|
||||||
|
.note = closures are lazy and do nothing unless called
|
||||||
|
|
||||||
|
lint-unused-generator =
|
||||||
|
unused {$pre}{$count ->
|
||||||
|
[one] generator
|
||||||
|
*[other] generator
|
||||||
|
}{$post} that must be used
|
||||||
|
.note = generators are lazy and do nothing unless resumed
|
||||||
|
|
||||||
|
lint-unused-def = unused {$pre}`{$def}`{$post} that must be used
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast::util::{classify, parser};
|
use rustc_ast::util::{classify, parser};
|
||||||
use rustc_ast::{ExprKind, StmtKind};
|
use rustc_ast::{ExprKind, StmtKind};
|
||||||
use rustc_errors::{pluralize, Applicability, MultiSpan};
|
use rustc_errors::{fluent, pluralize, Applicability, MultiSpan};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
@ -155,22 +155,23 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
||||||
|
|
||||||
if let Some(must_use_op) = must_use_op {
|
if let Some(must_use_op) = must_use_op {
|
||||||
cx.struct_span_lint(UNUSED_MUST_USE, expr.span, |lint| {
|
cx.struct_span_lint(UNUSED_MUST_USE, expr.span, |lint| {
|
||||||
let mut lint = lint.build(&format!("unused {} that must be used", must_use_op));
|
lint.build(fluent::lint::unused_op)
|
||||||
lint.span_label(expr.span, &format!("the {} produces a value", must_use_op));
|
.set_arg("op", must_use_op)
|
||||||
lint.span_suggestion_verbose(
|
.span_label(expr.span, fluent::lint::label)
|
||||||
expr.span.shrink_to_lo(),
|
.span_suggestion_verbose(
|
||||||
"use `let _ = ...` to ignore the resulting value",
|
expr.span.shrink_to_lo(),
|
||||||
"let _ = ",
|
fluent::lint::suggestion,
|
||||||
Applicability::MachineApplicable,
|
"let _ = ",
|
||||||
);
|
Applicability::MachineApplicable,
|
||||||
lint.emit();
|
)
|
||||||
|
.emit();
|
||||||
});
|
});
|
||||||
op_warned = true;
|
op_warned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(type_permits_lack_of_use || fn_warned || op_warned) {
|
if !(type_permits_lack_of_use || fn_warned || op_warned) {
|
||||||
cx.struct_span_lint(UNUSED_RESULTS, s.span, |lint| {
|
cx.struct_span_lint(UNUSED_RESULTS, s.span, |lint| {
|
||||||
lint.build(&format!("unused result of type `{}`", ty)).emit();
|
lint.build(fluent::lint::unused_result).set_arg("ty", ty).emit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,23 +268,27 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
||||||
},
|
},
|
||||||
ty::Closure(..) => {
|
ty::Closure(..) => {
|
||||||
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {
|
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {
|
||||||
let mut err = lint.build(&format!(
|
// FIXME(davidtwco): this isn't properly translatable becauses of the
|
||||||
"unused {}closure{}{} that must be used",
|
// pre/post strings
|
||||||
descr_pre, plural_suffix, descr_post,
|
lint.build(fluent::lint::unused_closure)
|
||||||
));
|
.set_arg("count", plural_len)
|
||||||
err.note("closures are lazy and do nothing unless called");
|
.set_arg("pre", descr_pre)
|
||||||
err.emit();
|
.set_arg("post", descr_post)
|
||||||
|
.note(fluent::lint::note)
|
||||||
|
.emit();
|
||||||
});
|
});
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
ty::Generator(..) => {
|
ty::Generator(..) => {
|
||||||
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {
|
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {
|
||||||
let mut err = lint.build(&format!(
|
// FIXME(davidtwco): this isn't properly translatable becauses of the
|
||||||
"unused {}generator{}{} that must be used",
|
// pre/post strings
|
||||||
descr_pre, plural_suffix, descr_post,
|
lint.build(fluent::lint::unused_generator)
|
||||||
));
|
.set_arg("count", plural_len)
|
||||||
err.note("generators are lazy and do nothing unless resumed");
|
.set_arg("pre", descr_pre)
|
||||||
err.emit();
|
.set_arg("post", descr_post)
|
||||||
|
.note(fluent::lint::note)
|
||||||
|
.emit();
|
||||||
});
|
});
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -305,13 +310,12 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Some(attr) = cx.tcx.get_attr(def_id, sym::must_use) {
|
if let Some(attr) = cx.tcx.get_attr(def_id, sym::must_use) {
|
||||||
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {
|
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {
|
||||||
let msg = format!(
|
// FIXME(davidtwco): this isn't properly translatable becauses of the pre/post
|
||||||
"unused {}`{}`{} that must be used",
|
// strings
|
||||||
descr_pre_path,
|
let mut err = lint.build(fluent::lint::unused_def);
|
||||||
cx.tcx.def_path_str(def_id),
|
err.set_arg("pre", descr_pre_path);
|
||||||
descr_post_path
|
err.set_arg("post", descr_post_path);
|
||||||
);
|
err.set_arg("def", cx.tcx.def_path_str(def_id));
|
||||||
let mut err = lint.build(&msg);
|
|
||||||
// check for #[must_use = "..."]
|
// check for #[must_use = "..."]
|
||||||
if let Some(note) = attr.value_str() {
|
if let Some(note) = attr.value_str() {
|
||||||
err.note(note.as_str());
|
err.note(note.as_str());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue