Feature-gate defaulted type parameters outside of types.

This commit is contained in:
Niko Matsakis 2015-12-15 13:02:14 -05:00
parent 191ff2d8fd
commit 15d32ffbb2
6 changed files with 30 additions and 14 deletions

View 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 @@ 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_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,

View 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 {

View file

@ -2132,7 +2132,7 @@ pub trait Iterator {
/// ```
#[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 @@ pub trait Iterator {
/// ```
#[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,
{

View file

@ -92,6 +92,7 @@ use syntax::abi;
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,

View file

@ -10,6 +10,7 @@
#![crate_type = "lib"]
#![crate_name = "default_param_test"]
#![feature(default_type_parameter_fallback)]
use std::marker::PhantomData;

View 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() {}