}
}
+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) {
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,
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());
|
= 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
|
|
= note: `-D iter-cloned-collect` implied by `-D warnings`
-error: aborting due to 106 previous errors
+error: aborting due to 103 previous errors