about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-02-05 21:20:57 +0100
committerRalf Jung <post@ralfj.de>2018-02-05 21:20:57 +0100
commit2aae22746e70eea96b0959f6e7b603576e14f3bb (patch)
treeefae49d137fc78caa3e0a148e73ad82c4efc88f4 /src
parentc83dd0306215e21ce5f8dab92edcc3ac9795f3da (diff)
downloadrust-2aae22746e70eea96b0959f6e7b603576e14f3bb.tar.gz
rust-2aae22746e70eea96b0959f6e7b603576e14f3bb.zip
Warn about more ignored bounds on type aliases
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/collect.rs35
-rw-r--r--src/test/compile-fail/dst-bad-assign-3.rs2
-rw-r--r--src/test/compile-fail/private-in-public-warn.rs2
-rw-r--r--src/test/ui/param-bounds-ignored.rs33
-rw-r--r--src/test/ui/param-bounds-ignored.stderr18
5 files changed, 68 insertions, 22 deletions
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 8b0d4248bbf..ecef168dcad 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -355,40 +355,35 @@ fn is_param<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
     }
 }
 
-fn ensure_no_ty_param_bounds(tcx: TyCtxt,
-                             span: Span,
-                             generics: &hir::Generics,
-                             thing: &'static str) {
+fn ensure_no_param_bounds(tcx: TyCtxt,
+                          span: Span,
+                          generics: &hir::Generics,
+                          thing: &'static str) {
     let mut warn = false;
 
     for ty_param in generics.ty_params() {
-        for bound in ty_param.bounds.iter() {
-            match *bound {
-                hir::TraitTyParamBound(..) => {
-                    warn = true;
-                }
-                hir::RegionTyParamBound(..) => { }
-            }
+        if !ty_param.bounds.is_empty() {
+            warn = true;
         }
     }
 
-    for predicate in generics.where_clause.predicates.iter() {
-        match *predicate {
-            hir::WherePredicate::BoundPredicate(..) => {
-                warn = true;
-            }
-            hir::WherePredicate::RegionPredicate(..) => { }
-            hir::WherePredicate::EqPredicate(..) => { }
+    for lft_param in generics.lifetimes() {
+        if !lft_param.bounds.is_empty() {
+            warn = true;
         }
     }
 
+    if !generics.where_clause.predicates.is_empty() {
+        warn = true;
+    }
+
     if warn {
         // According to accepted RFC #XXX, we should
         // eventually accept these, but it will not be
         // part of this PR. Still, convert to warning to
         // make bootstrapping easier.
         span_warn!(tcx.sess, span, E0122,
-                   "trait bounds are ignored in {} definitions",
+                   "bounds are ignored in {}",
                    thing);
     }
 }
@@ -454,7 +449,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) {
             }
         },
         hir::ItemTy(_, ref generics) => {
-            ensure_no_ty_param_bounds(tcx, it.span, generics, "type");
+            ensure_no_param_bounds(tcx, it.span, generics, "type aliases");
             tcx.generics_of(def_id);
             tcx.type_of(def_id);
             tcx.predicates_of(def_id);
diff --git a/src/test/compile-fail/dst-bad-assign-3.rs b/src/test/compile-fail/dst-bad-assign-3.rs
index 1c3bad5ba56..759da7b2bde 100644
--- a/src/test/compile-fail/dst-bad-assign-3.rs
+++ b/src/test/compile-fail/dst-bad-assign-3.rs
@@ -13,7 +13,7 @@
 #![feature(unsized_tuple_coercion)]
 
 type Fat<T: ?Sized> = (isize, &'static str, T);
-//~^ WARNING trait bounds are not (yet) enforced
+//~^ WARNING bounds are ignored
 
 #[derive(PartialEq,Eq)]
 struct Bar;
diff --git a/src/test/compile-fail/private-in-public-warn.rs b/src/test/compile-fail/private-in-public-warn.rs
index dfcf4dc01b8..aa91ce27c37 100644
--- a/src/test/compile-fail/private-in-public-warn.rs
+++ b/src/test/compile-fail/private-in-public-warn.rs
@@ -58,7 +58,7 @@ mod traits {
     pub trait PubTr {}
 
     pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface
-    //~^ WARN trait bounds are not (yet) enforced in type definitions
+    //~^ WARN bounds are ignored in type aliases
     //~| WARNING hard error
     pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface
     //~^ WARNING hard error
diff --git a/src/test/ui/param-bounds-ignored.rs b/src/test/ui/param-bounds-ignored.rs
new file mode 100644
index 00000000000..9e09102f2d4
--- /dev/null
+++ b/src/test/ui/param-bounds-ignored.rs
@@ -0,0 +1,33 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// must-compile-successfully
+
+use std::rc::Rc;
+
+type SVec<T: Send> = Vec<T>;
+type VVec<'b, 'a: 'b> = Vec<&'a i32>;
+type WVec<'b, T: 'b> = Vec<T>;
+
+fn foo<'a>(y: &'a i32) {
+    // If the bounds above would matter, the code below would be rejected.
+    let mut x : SVec<_> = Vec::new();
+    x.push(Rc::new(42));
+
+    let mut x : VVec<'static, 'a> = Vec::new();
+    x.push(y);
+
+    let mut x : WVec<'static, & 'a i32> = Vec::new();
+    x.push(y);
+}
+
+fn main() {
+    foo(&42);
+}
diff --git a/src/test/ui/param-bounds-ignored.stderr b/src/test/ui/param-bounds-ignored.stderr
new file mode 100644
index 00000000000..a14d416aaa7
--- /dev/null
+++ b/src/test/ui/param-bounds-ignored.stderr
@@ -0,0 +1,18 @@
+warning[E0122]: bounds are ignored in type aliases
+  --> $DIR/param-bounds-ignored.rs:15:1
+   |
+15 | type SVec<T: Send> = Vec<T>;
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning[E0122]: bounds are ignored in type aliases
+  --> $DIR/param-bounds-ignored.rs:16:1
+   |
+16 | type VVec<'b, 'a: 'b> = Vec<&'a i32>;
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning[E0122]: bounds are ignored in type aliases
+  --> $DIR/param-bounds-ignored.rs:17:1
+   |
+17 | type WVec<'b, T: 'b> = Vec<T>;
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+