lint #1674: lifetimed types exclusion

add expect() message and update test results
This commit is contained in:
Tim Nielens 2017-08-22 19:22:47 +02:00
parent 3f575d874b
commit 572b3388ac
2 changed files with 7 additions and 23 deletions

View File

@ -46,6 +46,8 @@ fn get_lints(&self) -> LintArray {
}
}
const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if in_macro(item.span) {
@ -54,9 +56,9 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if_let_chain!([
let ItemImpl(.., ref item_type, ref refs) = item.node,
let Ty_::TyPath(QPath::Resolved(_, ref item_path)) = item_type.node,
let PathParameters::AngleBracketedParameters(ref angleBracketedParameterData)
= item_path.segments.last().unwrap().parameters,
angleBracketedParameterData.lifetimes.len() == 0,
let PathParameters::AngleBracketedParameters(ref param_data)
= item_path.segments.last().expect(SEGMENTS_MSG).parameters,
param_data.lifetimes.len() == 0,
], {
let visitor = &mut UseSelfVisitor {
item_path: item_path,
@ -79,7 +81,7 @@ fn visit_path(&mut self, path: &'tcx Path, _id: NodeId) {
if self.item_path.def == path.def &&
path.segments
.last()
.unwrap()
.expect(SEGMENTS_MSG)
.name != SelfType.name() {
span_lint_and_then(self.cx, USE_SELF, path.span, "unnecessary structure name repetition", |db| {
db.span_suggestion(path.span, "use the applicable keyword", "Self".to_owned());

View File

@ -78,24 +78,6 @@ error: methods called `new` usually return `Self`
|
= note: `-D new-ret-no-self` implied by `-D warnings`
error: unnecessary structure name repetition
--> $DIR/methods.rs:40:35
|
40 | pub fn new<'b>(s: &'b str) -> Lt<'b> { unimplemented!() }
| ^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/methods.rs:49:28
|
49 | pub fn new(s: &str) -> Lt2 { unimplemented!() }
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/methods.rs:58:21
|
58 | pub fn new() -> Lt3<'static> { unimplemented!() }
| ^^^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/methods.rs:74:24
|
@ -730,5 +712,5 @@ error: called `cloned().collect()` on a slice to create a `Vec`. Calling `to_vec
|
= note: `-D iter-cloned-collect` implied by `-D warnings`
error: aborting due to 106 previous errors
error: aborting due to 103 previous errors