]> git.lizzy.rs Git - rust.git/commitdiff
Feature-gate defaulted type parameters outside of types.
authorNiko Matsakis <niko@alum.mit.edu>
Tue, 15 Dec 2015 18:02:14 +0000 (13:02 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 4 Jan 2016 10:18:56 +0000 (05:18 -0500)
src/libcollections/btree/map.rs
src/libcollections/btree/set.rs
src/libcore/iter.rs
src/librustc_typeck/collect.rs
src/test/auxiliary/default_ty_param_cross_crate_crate.rs
src/test/compile-fail/issue-26812.rs

index de9c8a2feafb84ab69f7eceb98f6c03031f0f569..f87f5e6c2e6b74f7769d238b2542c7cbb473b8f0 100644 (file)
@@ -1591,10 +1591,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
     #[unstable(feature = "btree_range",
                reason = "matches collection reform specification, waiting for dust to settle",
                issue = "27787")]
-    pub fn range<Min: ?Sized + Ord = K, Max: ?Sized + Ord = K>(&self,
-                                                               min: Bound<&Min>,
-                                                               max: Bound<&Max>)
-                                                               -> Range<K, V>
+    pub fn range<Min: ?Sized + Ord, Max: ?Sized + Ord>(&self,
+                                                       min: Bound<&Min>,
+                                                       max: Bound<&Max>)
+                                                       -> Range<K, V>
         where K: Borrow<Min> + Borrow<Max>
     {
         range_impl!(&self.root,
@@ -1633,10 +1633,10 @@ pub fn range<Min: ?Sized + Ord = K, Max: ?Sized + Ord = K>(&self,
     #[unstable(feature = "btree_range",
                reason = "matches collection reform specification, waiting for dust to settle",
                issue = "27787")]
-    pub fn range_mut<Min: ?Sized + Ord = K, Max: ?Sized + Ord = K>(&mut self,
-                                                                   min: Bound<&Min>,
-                                                                   max: Bound<&Max>)
-                                                                   -> RangeMut<K, V>
+    pub fn range_mut<Min: ?Sized + Ord, Max: ?Sized + Ord>(&mut self,
+                                                           min: Bound<&Min>,
+                                                           max: Bound<&Max>)
+                                                           -> RangeMut<K, V>
         where K: Borrow<Min> + Borrow<Max>
     {
         range_impl!(&mut self.root,
index 12d3465e5188d646706889aa795320b516868a83..55e9e3a1c34bb15644e9f8d0ec4f88e5b7b6ed0b 100644 (file)
@@ -154,10 +154,10 @@ impl<T: Ord> BTreeSet<T> {
     #[unstable(feature = "btree_range",
                reason = "matches collection reform specification, waiting for dust to settle",
                issue = "27787")]
-    pub fn range<'a, Min: ?Sized + Ord = T, Max: ?Sized + Ord = T>(&'a self,
-                                                                   min: Bound<&Min>,
-                                                                   max: Bound<&Max>)
-                                                                   -> Range<'a, T>
+    pub fn range<'a, Min: ?Sized + Ord, Max: ?Sized + Ord>(&'a self,
+                                                           min: Bound<&Min>,
+                                                           max: Bound<&Max>)
+                                                           -> Range<'a, T>
         where T: Borrow<Min> + Borrow<Max>
     {
         fn first<A, B>((a, _): (A, B)) -> A {
index 6f052f964c675a67f1995a0a1543fdfbf01b868d..a30e5b1372af98daf081ea88d524c177e1d0b533 100644 (file)
@@ -2132,7 +2132,7 @@ fn cycle(self) -> Cycle<Self> where Self: Sized + Clone {
     /// ```
     #[unstable(feature = "iter_arith", reason = "bounds recently changed",
                issue = "27739")]
-    fn sum<S=<Self as Iterator>::Item>(self) -> S where
+    fn sum<S>(self) -> S where
         S: Add<Self::Item, Output=S> + Zero,
         Self: Sized,
     {
@@ -2157,7 +2157,7 @@ fn sum<S=<Self as Iterator>::Item>(self) -> S where
     /// ```
     #[unstable(feature="iter_arith", reason = "bounds recently changed",
                issue = "27739")]
-    fn product<P=<Self as Iterator>::Item>(self) -> P where
+    fn product<P>(self) -> P where
         P: Mul<Self::Item, Output=P> + One,
         Self: Sized,
     {
index eaaa2c773791e8c24776d5f4d09fca35e533bb8e..2b3ee9fe6dc6663353c6706ac89e8100b35982db 100644 (file)
@@ -92,6 +92,7 @@
 use syntax::ast;
 use syntax::attr;
 use syntax::codemap::Span;
+use syntax::feature_gate::{GateIssue, emit_feature_err};
 use syntax::parse::token::special_idents;
 use syntax::ptr::P;
 use rustc_front::hir;
@@ -1933,6 +1934,18 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
 
     let parent = tcx.map.get_parent(param.id);
 
+    if space != TypeSpace && default.is_some() {
+        if !tcx.sess.features.borrow().default_type_parameter_fallback {
+            emit_feature_err(&tcx.sess.parse_sess.span_diagnostic,
+                             "default_type_parameter_fallback",
+                             param.span,
+                             GateIssue::Language,
+                             "other than on a `struct` or `enum` definition, \
+                              defaults for type parameters are experimental \
+                              and known to be buggy");
+        }
+    }
+
     let def = ty::TypeParameterDef {
         space: space,
         index: index,
index 270cfdcb7f651cec9d893d5f9d22da99d97c8719..4bd8ecacb96b3ddcb5e86e42654dd18cfe6c0fa9 100644 (file)
@@ -10,6 +10,7 @@
 
 #![crate_type = "lib"]
 #![crate_name = "default_param_test"]
+#![feature(default_type_parameter_fallback)]
 
 use std::marker::PhantomData;
 
index c1ccfe269cdd3c49cd81977e114461e864102f12..060a66846d36f7afcaba4e4a38ac03f7d95c9fe3 100644 (file)
@@ -8,5 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(default_type_parameter_fallback)]
+
 fn avg<T=T::Item>(_: T) {} //~ ERROR associated type `Item` not found for `T`
 fn main() {}