Fixes #12423.
let region_map = time(time_passes, "region resolution", (), |_|
middle::region::resolve_crate(sess, krate));
- let ty_cx = ty::mk_ctxt(sess, def_map, named_region_map, ast_map, freevars,
- region_map, lang_items);
+ let ty_cx = ty::mk_ctxt(sess, def_map, named_region_map, ast_map,
+ freevars, region_map, lang_items);
// passes are timed inside typeck
let (method_map, vtable_map) = typeck::check_crate(ty_cx, trait_map, krate);
lints: RefCell::new(HashMap::new()),
node_id: Cell::new(1),
crate_types: @RefCell::new(~[]),
+ features: front::feature_gate::Features::new()
}
}
use back::target_strs;
use back;
use driver::driver::host_triple;
+use front;
use metadata::filesearch;
use metadata;
use middle::lint;
~[(lint::Lint, codemap::Span, ~str)]>>,
node_id: Cell<ast::NodeId>,
crate_types: @RefCell<~[CrateType]>,
+ features: front::feature_gate::Features
}
pub type Session = @Session_;
use driver::session::Session;
+use std::cell::Cell;
+
/// This is a list of all known features since the beginning of time. This list
/// can never shrink, it may only be expanded (in order to prevent old programs
/// from failing to compile). The status of each feature may change, however.
Accepted,
}
+/// A set of features to be used by later passes.
+pub struct Features {
+ default_type_params: Cell<bool>
+}
+
+impl Features {
+ pub fn new() -> Features {
+ Features {
+ default_type_params: Cell::new(false)
+ }
+ }
+}
+
struct Context {
features: ~[&'static str],
sess: Session,
visit::walk_crate(&mut cx, krate, ());
sess.abort_if_errors();
+
+ sess.features.default_type_params.set(cx.has_feature("default_type_params"));
}
AttributeUsage,
UnknownFeatures,
UnknownCrateType,
- DefaultTypeParamUsage,
ManagedHeapMemory,
OwnedHeapMemory,
lint: UnusedResult,
desc: "unused result of an expression in a statement",
default: allow,
- }),
-
- ("default_type_param_usage",
- LintSpec {
- lint: DefaultTypeParamUsage,
- desc: "prevents explicitly setting a type parameter with a default",
- default: deny,
- }),
+ })
];
/*
region_maps: middle::region::RegionMaps,
lang_items: @middle::lang_items::LanguageItems)
-> ctxt {
+
@ctxt_ {
named_region_map: named_region_map,
item_variance_map: RefCell::new(HashMap::new()),
upvar_borrow_map: RefCell::new(HashMap::new()),
extern_const_statics: RefCell::new(HashMap::new()),
extern_const_variants: RefCell::new(HashMap::new()),
- }
+ }
}
// Type constructors
use middle::const_eval;
-use middle::lint;
use middle::subst::Subst;
use middle::ty::{substs};
use middle::ty::{ty_param_substs_and_ty};
expected, formal_ty_param_count, supplied_ty_param_count));
}
- if supplied_ty_param_count > required_ty_param_count {
- let id = path.segments.iter().flat_map(|s| s.types.iter())
- .nth(required_ty_param_count).unwrap().id;
- this.tcx().sess.add_lint(lint::DefaultTypeParamUsage, id, path.span,
- ~"provided type arguments with defaults");
+ if supplied_ty_param_count > required_ty_param_count
+ && !this.tcx().sess.features.default_type_params.get() {
+ this.tcx().sess.span_err(path.span, "default type parameters are \
+ experimental and possibly buggy");
+ this.tcx().sess.span_note(path.span, "add #[feature(default_type_params)] \
+ to the crate attributes to enable");
}
let tps = path.segments.iter().flat_map(|s| s.types.iter())
use middle::lang_items::{ExchangeHeapLangItem, GcLangItem};
use middle::lang_items::{ManagedHeapLangItem};
use middle::lint::UnreachableCode;
-use middle::lint;
use middle::pat_util::pat_id_map;
use middle::pat_util;
use middle::subst::Subst;
expected, user_ty_param_req, ty_substs_len));
(fcx.infcx().next_ty_vars(ty_param_count), regions)
} else {
- if ty_substs_len > user_ty_param_req {
- fcx.tcx().sess.add_lint(lint::DefaultTypeParamUsage, node_id, pth.span,
- ~"provided type arguments with defaults");
+ if ty_substs_len > user_ty_param_req
+ && !fcx.tcx().sess.features.default_type_params.get() {
+ fcx.tcx().sess.span_err(pth.span, "default type parameters are \
+ experimental and possibly buggy");
+ fcx.tcx().sess.span_note(pth.span, "add #[feature(default_type_params)] \
+ to the crate attributes to enable");
}
// Build up the list of type parameters, inserting the self parameter
// Turn on default type parameters.
#[feature(default_type_params)];
+// NOTE remove the following two attributes after the next snapshot.
+#[allow(unrecognized_lint)];
#[allow(default_type_param_usage)];
// Don't link to std. We are std.
use ext::base::ExtCtxt;
use ext::build::AstBuilder;
use ext::deriving::generic::*;
-use parse::token::InternedString;
pub fn expand_deriving_hash(cx: &mut ExtCtxt,
span: Span,
item: @Item,
push: |@Item|) {
- let allow_default_type_param_usage = cx.attribute(
- span,
- cx.meta_list(
- span,
- InternedString::new("allow"),
- ~[cx.meta_word(span, InternedString::new("default_type_param_usage"))]));
-
let hash_trait_def = TraitDef {
span: span,
- attributes: ~[allow_default_type_param_usage],
- path: Path::new_(~["std", "hash", "Hash"], None,
- ~[~Literal(Path::new_local("__H"))], true),
+ attributes: ~[],
+ path: Path::new(~["std", "hash", "Hash"]),
additional_bounds: ~[],
- generics: LifetimeBounds {
- lifetimes: ~[],
- bounds: ~[("__H", ~[Path::new(~["std", "io", "Writer"])])],
- },
+ generics: LifetimeBounds::empty(),
methods: ~[
MethodDef {
name: "hash",
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
- args: ~[Ptr(~Literal(Path::new_local("__H")),
+ args: ~[Ptr(~Literal(Path::new(~["std", "hash", "sip", "SipState"])),
Borrowed(None, MutMutable))],
ret_ty: nil_ty(),
inline: true,
--- /dev/null
+// 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.
+
+// aux-build:default_type_params_xc.rs
+
+#[deny(default_type_param_usage)];
+
+extern crate default_type_params_xc;
+
+pub struct FooAlloc;
+
+pub type VecFoo<T> = default_type_params_xc::FakeVec<T, FooAlloc>;
+//~^ ERROR: default type parameters are experimental
+
+fn main() {}
+++ /dev/null
-// 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.
-
-#[feature(default_type_params)];
-
-#[deny(default_type_param_usage)];
-
-pub struct Heap;
-
-pub struct Vec<T, A = Heap>;
-
-pub struct FooAlloc;
-
-pub type VecFoo<T> = Vec<T, FooAlloc>; //~ ERROR provided type arguments with defaults
-
-fn main() {}
// ignore-fast #[feature] doesn't work with check-fast
#[feature(default_type_params)];
-#[allow(default_type_param_usage)];
-
extern crate default_type_params_xc;
struct Vec<T, A = default_type_params_xc::Heap>;
// ignore-fast #[feature] doesn't work with check-fast
#[feature(default_type_params)];
-#[allow(default_type_param_usage)];
-
struct Foo<A = (int, char)> {
a: A
}