diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 3e628c99ff9..b8c970d376e 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -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()); diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr index 65975c5177c..8570dccd0fe 100644 --- a/tests/ui/methods.stderr +++ b/tests/ui/methods.stderr @@ -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