]> git.lizzy.rs Git - rust.git/commitdiff
lint #1674: lifetimed types exclusion
authorTim Nielens <tim.nielens@gmail.com>
Tue, 22 Aug 2017 17:22:47 +0000 (19:22 +0200)
committerTim Nielens <tim.nielens@gmail.com>
Tue, 22 Aug 2017 17:22:47 +0000 (19:22 +0200)
add expect() message and update test results

clippy_lints/src/use_self.rs
tests/ui/methods.stderr

index 3e628c99ff9b1af3c7ae398273ead1b77fb78275..b8c970d376ef6f8d7ccd3f914cf7cf0a883f3873 100644 (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());
index 65975c5177c47a088ae390c005603fb1635541ba..8570dccd0febe81fe23348b0f103bde1e3ab549a 100644 (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