]> git.lizzy.rs Git - rust.git/commitdiff
Don't lint lifetimes after trait objects
authorOliver Schneider <git-no-reply-9879165716479413131@oli-obk.de>
Tue, 11 Apr 2017 12:29:58 +0000 (14:29 +0200)
committerOliver Schneider <git-no-reply-9879165716479413131@oli-obk.de>
Tue, 11 Apr 2017 12:29:58 +0000 (14:29 +0200)
clippy_lints/src/lifetimes.rs
tests/ui/lifetimes.stderr

index 6bfcc475841a070235e4b64b8da17726158ce667..88285cac037038ac9115d4a6afc17e07d1252648 100644 (file)
@@ -150,8 +150,14 @@ fn could_use_elision<'a, 'tcx: 'a, T: Iterator<Item = &'tcx Lifetime>>(
         output_visitor.visit_ty(ty);
     }
 
-    let input_lts = lts_from_bounds(input_visitor.into_vec(), bounds_lts);
-    let output_lts = output_visitor.into_vec();
+    let input_lts = match input_visitor.into_vec() {
+        Some(lts) => lts_from_bounds(lts, bounds_lts),
+        None => return false,
+    };
+    let output_lts = match output_visitor.into_vec() {
+        Some(val) => val,
+        None => return false,
+    };
 
     if let Some(body_id) = body {
         let mut checker = BodyLifetimeChecker { lifetimes_used_in_body: false };
@@ -230,6 +236,7 @@ fn unique_lifetimes(lts: &[RefLt]) -> usize {
 struct RefVisitor<'a, 'tcx: 'a> {
     cx: &'a LateContext<'a, 'tcx>,
     lts: Vec<RefLt>,
+    abort: bool,
 }
 
 impl<'v, 't> RefVisitor<'v, 't> {
@@ -237,6 +244,7 @@ fn new(cx: &'v LateContext<'v, 't>) -> RefVisitor<'v, 't> {
         RefVisitor {
             cx: cx,
             lts: Vec::new(),
+            abort: false,
         }
     }
 
@@ -254,8 +262,12 @@ fn record(&mut self, lifetime: &Option<Lifetime>) {
         }
     }
 
-    fn into_vec(self) -> Vec<RefLt> {
-        self.lts
+    fn into_vec(self) -> Option<Vec<RefLt>> {
+        if self.abort {
+            None
+        } else {
+            Some(self.lts)
+        }
     }
 
     fn collect_anonymous_lifetimes(&mut self, qpath: &QPath, ty: &Ty) {
@@ -306,7 +318,7 @@ fn visit_ty(&mut self, ty: &'tcx Ty) {
             },
             TyTraitObject(ref bounds, ref lt) => {
                 if !lt.is_elided() {
-                    self.record(&Some(*lt));
+                    self.abort = true;
                 }
                 for bound in bounds {
                     self.visit_poly_trait_ref(bound, TraitBoundModifier::None);
@@ -343,10 +355,13 @@ fn has_where_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, where_clause: &
                     walk_ty_param_bound(&mut visitor, bound);
                 }
                 // and check that all lifetimes are allowed
-                for lt in visitor.into_vec() {
-                    if !allowed_lts.contains(&lt) {
-                        return true;
-                    }
+                match visitor.into_vec() {
+                    None => return false,
+                    Some(lts) => for lt in lts {
+                        if !allowed_lts.contains(&lt) {
+                            return true;
+                        }
+                    },
                 }
             },
             WherePredicate::EqPredicate(ref pred) => {
index aa12547bb2069cbbcada8a274dfa0d3676378beb..0a201222910c53421e116ffcbe571b3f0bc14a35 100644 (file)
@@ -97,15 +97,6 @@ error: explicit lifetimes given in parameter types where they could be elided
 132 | fn trait_bound_bug<'a, T: WithLifetime<'a>>() { unimplemented!() }
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: explicit lifetimes given in parameter types where they could be elided
-   --> $DIR/lifetimes.rs:140:5
-    |
-140 |       fn iter<'a>(&'a self) -> Box<Iterator<Item = usize> + 'a> {
-    |  _____^ starting here...
-141 | |         unimplemented!()
-142 | |     }
-    | |_____^ ...ending here
-
 warning: unused variable: `cx`
    --> $DIR/lifetimes.rs:148:30
     |
@@ -114,5 +105,5 @@ warning: unused variable: `cx`
     |
     = note: #[warn(unused_variables)] on by default
 
-error: aborting due to 16 previous errors
+error: aborting due to 15 previous errors