Rollup merge of #52968 - zackmdavis:app-lint-cability, r=estebank

App-lint-cability

@eminence recently pointed out (rust-lang/cargo#5846) that it's
surprising that `cargo fix` (now shipping with Cargo itself!) doesn't
fix very common lint warnings, which is as good of a reminder as any
that we should finish #50723.

(Previously, we did this on the librustc and libsyntax crates in #50724. I filed cmr/this-week-in-rust#685 in hopes of recruiting new contributors to do the rest.)

r? @estebank
This commit is contained in:
kennytm 2018-08-04 14:35:50 +08:00 committed by GitHub
commit e82dab7c0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 19 deletions

View File

@ -84,7 +84,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue {
let msg = "denote infinite loops with `loop { ... }`";
let condition_span = cx.tcx.sess.codemap().def_span(e.span);
let mut err = cx.struct_span_lint(WHILE_TRUE, condition_span, msg);
err.span_suggestion_short(condition_span, "use `loop`", "loop".to_owned());
err.span_suggestion_short_with_applicability(
condition_span,
"use `loop`",
"loop".to_owned(),
Applicability::MachineApplicable
);
err.emit();
}
}
@ -191,7 +196,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
fieldpat.span,
&format!("the `{}:` in this pattern is redundant", ident));
let subspan = cx.tcx.sess.codemap().span_through_char(fieldpat.span, ':');
err.span_suggestion_short(subspan, "remove this", ident.to_string());
err.span_suggestion_short_with_applicability(
subspan,
"remove this",
ident.to_string(),
Applicability::MachineApplicable
);
err.emit();
}
}
@ -708,10 +718,11 @@ impl EarlyLintPass for BadRepr {
| "i8" | "i16" | "i32" | "i64" | "i128" | "isize" => {
// if the literal could have been a valid `repr` arg,
// suggest the correct syntax
warn.span_suggestion(
warn.span_suggestion_with_applicability(
attr.span,
"give `repr` a hint",
repr_str(&lit.as_str()),
Applicability::MachineApplicable
);
suggested = true;
}
@ -779,7 +790,12 @@ impl EarlyLintPass for DeprecatedAttr {
let msg = format!("use of deprecated attribute `{}`: {}. See {}",
name, reason, link);
let mut err = cx.struct_span_lint(DEPRECATED, attr.span, &msg);
err.span_suggestion_short(attr.span, "remove this attribute", "".to_owned());
err.span_suggestion_short_with_applicability(
attr.span,
"remove this attribute",
"".to_owned(),
Applicability::MachineApplicable
);
err.emit();
}
return;
@ -1201,7 +1217,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
}
};
if let Some(replacement) = suggestion {
err.span_suggestion(vis.span, "try making it public", replacement);
err.span_suggestion_with_applicability(
vis.span,
"try making it public",
replacement,
Applicability::MachineApplicable
);
}
};
@ -1225,9 +1246,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
it.span,
"functions generic over \
types must be mangled");
err.span_suggestion_short(no_mangle_attr.span,
"remove this attribute",
"".to_owned());
err.span_suggestion_short_with_applicability(
no_mangle_attr.span,
"remove this attribute",
"".to_owned(),
// Use of `#[no_mangle]` suggests FFI intent; correct
// fix may be to monomorphize source by hand
Applicability::MaybeIncorrect
);
err.emit();
break;
}
@ -1257,9 +1283,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
.unwrap_or(0) as u32;
// `const` is 5 chars
let const_span = it.span.with_hi(BytePos(it.span.lo().0 + start + 5));
err.span_suggestion(const_span,
"try a static value",
"pub static".to_owned());
err.span_suggestion_with_applicability(
const_span,
"try a static value",
"pub static".to_owned(),
Applicability::MachineApplicable
);
err.emit();
}
}

View File

@ -22,6 +22,7 @@ use std::cmp;
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
use syntax::{ast, attr};
use syntax::errors::Applicability;
use rustc_target::spec::abi::Abi;
use syntax_pos::Span;
use syntax::codemap;
@ -143,9 +144,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
OVERFLOWING_LITERALS,
parent_expr.span,
"only u8 can be cast into char");
err.span_suggestion(parent_expr.span,
&"use a char literal instead",
format!("'\\u{{{:X}}}'", lit_val));
err.span_suggestion_with_applicability(
parent_expr.span,
&"use a char literal instead",
format!("'\\u{{{:X}}}'", lit_val),
Applicability::MachineApplicable
);
err.emit();
return
}
@ -398,10 +402,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
{
if let Some(pos) = repr_str.chars().position(|c| c == 'i' || c == 'u') {
let (sans_suffix, _) = repr_str.split_at(pos);
err.span_suggestion(
err.span_suggestion_with_applicability(
expr.span,
&format!("consider using `{}` instead", sugg_ty),
format!("{}{}", sans_suffix, sugg_ty),
Applicability::MachineApplicable
);
} else {
err.help(&format!("consider using `{}` instead", sugg_ty));

View File

@ -17,6 +17,7 @@ use lint::{LintPass, EarlyLintPass, LateLintPass};
use syntax::ast;
use syntax::attr;
use syntax::errors::Applicability;
use syntax::feature_gate::{BUILTIN_ATTRIBUTES, AttributeType};
use syntax::print::pprust;
use syntax::symbol::keywords;
@ -303,9 +304,12 @@ impl UnusedParens {
_ => false,
}
}).to_owned();
err.span_suggestion_short(value.span,
"remove these parentheses",
parens_removed);
err.span_suggestion_short_with_applicability(
value.span,
"remove these parentheses",
parens_removed,
Applicability::MachineApplicable
);
err.emit();
}
}

View File

@ -82,7 +82,7 @@
],
"label": null,
"suggested_replacement": "1 / (2 + 3)",
"suggestion_applicability": "Unspecified",
"suggestion_applicability": "MachineApplicable",
"expansion": null
}
],