Skip to content

Commit 15d32ff

Browse files
committed
Feature-gate defaulted type parameters outside of types.
1 parent 191ff2d commit 15d32ff

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

src/libcollections/btree/map.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1591,10 +1591,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
15911591
#[unstable(feature = "btree_range",
15921592
reason = "matches collection reform specification, waiting for dust to settle",
15931593
issue = "27787")]
1594-
pub fn range<Min: ?Sized + Ord = K, Max: ?Sized + Ord = K>(&self,
1595-
min: Bound<&Min>,
1596-
max: Bound<&Max>)
1597-
-> Range<K, V>
1594+
pub fn range<Min: ?Sized + Ord, Max: ?Sized + Ord>(&self,
1595+
min: Bound<&Min>,
1596+
max: Bound<&Max>)
1597+
-> Range<K, V>
15981598
where K: Borrow<Min> + Borrow<Max>
15991599
{
16001600
range_impl!(&self.root,
@@ -1633,10 +1633,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
16331633
#[unstable(feature = "btree_range",
16341634
reason = "matches collection reform specification, waiting for dust to settle",
16351635
issue = "27787")]
1636-
pub fn range_mut<Min: ?Sized + Ord = K, Max: ?Sized + Ord = K>(&mut self,
1637-
min: Bound<&Min>,
1638-
max: Bound<&Max>)
1639-
-> RangeMut<K, V>
1636+
pub fn range_mut<Min: ?Sized + Ord, Max: ?Sized + Ord>(&mut self,
1637+
min: Bound<&Min>,
1638+
max: Bound<&Max>)
1639+
-> RangeMut<K, V>
16401640
where K: Borrow<Min> + Borrow<Max>
16411641
{
16421642
range_impl!(&mut self.root,

src/libcollections/btree/set.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ impl<T: Ord> BTreeSet<T> {
154154
#[unstable(feature = "btree_range",
155155
reason = "matches collection reform specification, waiting for dust to settle",
156156
issue = "27787")]
157-
pub fn range<'a, Min: ?Sized + Ord = T, Max: ?Sized + Ord = T>(&'a self,
158-
min: Bound<&Min>,
159-
max: Bound<&Max>)
160-
-> Range<'a, T>
157+
pub fn range<'a, Min: ?Sized + Ord, Max: ?Sized + Ord>(&'a self,
158+
min: Bound<&Min>,
159+
max: Bound<&Max>)
160+
-> Range<'a, T>
161161
where T: Borrow<Min> + Borrow<Max>
162162
{
163163
fn first<A, B>((a, _): (A, B)) -> A {

src/libcore/iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ pub trait Iterator {
21322132
/// ```
21332133
#[unstable(feature = "iter_arith", reason = "bounds recently changed",
21342134
issue = "27739")]
2135-
fn sum<S=<Self as Iterator>::Item>(self) -> S where
2135+
fn sum<S>(self) -> S where
21362136
S: Add<Self::Item, Output=S> + Zero,
21372137
Self: Sized,
21382138
{
@@ -2157,7 +2157,7 @@ pub trait Iterator {
21572157
/// ```
21582158
#[unstable(feature="iter_arith", reason = "bounds recently changed",
21592159
issue = "27739")]
2160-
fn product<P=<Self as Iterator>::Item>(self) -> P where
2160+
fn product<P>(self) -> P where
21612161
P: Mul<Self::Item, Output=P> + One,
21622162
Self: Sized,
21632163
{

src/librustc_typeck/collect.rs

+13
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ use syntax::abi;
9292
use syntax::ast;
9393
use syntax::attr;
9494
use syntax::codemap::Span;
95+
use syntax::feature_gate::{GateIssue, emit_feature_err};
9596
use syntax::parse::token::special_idents;
9697
use syntax::ptr::P;
9798
use rustc_front::hir;
@@ -1933,6 +1934,18 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
19331934

19341935
let parent = tcx.map.get_parent(param.id);
19351936

1937+
if space != TypeSpace && default.is_some() {
1938+
if !tcx.sess.features.borrow().default_type_parameter_fallback {
1939+
emit_feature_err(&tcx.sess.parse_sess.span_diagnostic,
1940+
"default_type_parameter_fallback",
1941+
param.span,
1942+
GateIssue::Language,
1943+
"other than on a `struct` or `enum` definition, \
1944+
defaults for type parameters are experimental \
1945+
and known to be buggy");
1946+
}
1947+
}
1948+
19361949
let def = ty::TypeParameterDef {
19371950
space: space,
19381951
index: index,

src/test/auxiliary/default_ty_param_cross_crate_crate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#![crate_type = "lib"]
1212
#![crate_name = "default_param_test"]
13+
#![feature(default_type_parameter_fallback)]
1314

1415
use std::marker::PhantomData;
1516

src/test/compile-fail/issue-26812.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(default_type_parameter_fallback)]
12+
1113
fn avg<T=T::Item>(_: T) {} //~ ERROR associated type `Item` not found for `T`
1214
fn main() {}

0 commit comments

Comments
 (0)