Skip to content

Commit

Permalink
rollup merge of rust-lang#20194: nick29581/dst-syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Dec 30, 2014
2 parents 28f424f + c4640a2 commit 2a85477
Show file tree
Hide file tree
Showing 41 changed files with 242 additions and 222 deletions.
4 changes: 2 additions & 2 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,9 +1782,9 @@ impl LintPass for Stability {
if self.is_internal(cx, item.span) { return }

match item.node {
ast::ItemTrait(_, _, _, ref supertraits, _) => {
ast::ItemTrait(_, _, ref supertraits, _) => {
for t in supertraits.iter() {
if let ast::TraitTyParamBound(ref t) = *t {
if let ast::TraitTyParamBound(ref t, _) = *t {
let id = ty::trait_ref_to_def_id(cx.tcx, &t.trait_ref);
self.lint(cx, id, t.trait_ref.path.span);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
}
}
}
ast::ItemTrait(_, _, _, _, ref ms) => {
ast::ItemTrait(_, _, _, ref ms) => {
add_to_index(item, rbml_w, index);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,6 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
ident: ty_param.ident,
id: ty_param.id,
bounds: bounds,
unbound: ty_param.unbound.clone(),
default: ty_param.default.clone(),
span: ty_param.span,
}
Expand All @@ -1063,7 +1062,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
// be passing down a map.
ast::RegionTyParamBound(lt)
}
&ast::TraitTyParamBound(ref poly_tr) => {
&ast::TraitTyParamBound(ref poly_tr, modifier) => {
let tr = &poly_tr.trait_ref;
let last_seg = tr.path.segments.last().unwrap();
let mut insert = Vec::new();
Expand All @@ -1087,7 +1086,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
path: new_path,
ref_id: tr.ref_id,
}
})
}, modifier)
}
}
})
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'v> Visitor<'v> for ParentVisitor {
// method to the root. In this case, if the trait is private, then
// parent all the methods to the trait to indicate that they're
// private.
ast::ItemTrait(_, _, _, _, ref methods) if item.vis != ast::Public => {
ast::ItemTrait(_, _, _, ref methods) if item.vis != ast::Public => {
for m in methods.iter() {
match *m {
ast::ProvidedMethod(ref m) => {
Expand Down Expand Up @@ -328,7 +328,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {

// Default methods on traits are all public so long as the trait
// is public
ast::ItemTrait(_, _, _, _, ref methods) if public_first => {
ast::ItemTrait(_, _, _, ref methods) if public_first => {
for method in methods.iter() {
match *method {
ast::ProvidedMethod(ref m) => {
Expand Down Expand Up @@ -1178,7 +1178,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
}
}

ast::ItemTrait(_, _, _, _, ref methods) => {
ast::ItemTrait(_, _, _, ref methods) => {
for m in methods.iter() {
match *m {
ast::ProvidedMethod(ref m) => {
Expand Down Expand Up @@ -1242,7 +1242,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {

ast::ItemStruct(ref def, _) => check_struct(&**def),

ast::ItemTrait(_, _, _, _, ref methods) => {
ast::ItemTrait(_, _, _, ref methods) => {
for m in methods.iter() {
match *m {
ast::RequiredMethod(..) => {}
Expand Down Expand Up @@ -1306,7 +1306,7 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {

fn check_ty_param_bound(&self,
ty_param_bound: &ast::TyParamBound) {
if let ast::TraitTyParamBound(ref trait_ref) = *ty_param_bound {
if let ast::TraitTyParamBound(ref trait_ref, _) = *ty_param_bound {
if !self.tcx.sess.features.borrow().visible_private_types &&
self.path_is_private_type(trait_ref.trait_ref.ref_id) {
let span = trait_ref.trait_ref.path.span;
Expand Down Expand Up @@ -1349,7 +1349,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
// namespace (the contents have their own privacies).
ast::ItemForeignMod(_) => {}

ast::ItemTrait(_, _, _, ref bounds, _) => {
ast::ItemTrait(_, _, ref bounds, _) => {
if !self.trait_is_public(item.id) {
return
}
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
ast::ItemTy(_, ref generics) |
ast::ItemEnum(_, ref generics) |
ast::ItemStruct(_, ref generics) |
ast::ItemTrait(_, ref generics, _, _, _) |
ast::ItemTrait(_, ref generics, _, _) |
ast::ItemImpl(_, ref generics, _, _, _) => {
// These kinds of items have only early bound lifetime parameters.
let lifetimes = &generics.lifetimes;
Expand Down Expand Up @@ -232,7 +232,9 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
}
}

fn visit_poly_trait_ref(&mut self, trait_ref: &ast::PolyTraitRef) {
fn visit_poly_trait_ref(&mut self, trait_ref:
&ast::PolyTraitRef,
_modifier: &ast::TraitBoundModifier) {
debug!("visit_poly_trait_ref trait_ref={}", trait_ref);

self.with(LateScope(&trait_ref.bound_lifetimes, self.scope), |old_scope, this| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4740,7 +4740,7 @@ pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
match cx.map.find(id.node) {
Some(ast_map::NodeItem(item)) => {
match item.node {
ItemTrait(_, _, _, _, ref ms) => {
ItemTrait(_, _, _, ref ms) => {
let (_, p) =
ast_util::split_trait_methods(ms[]);
p.iter()
Expand Down
19 changes: 3 additions & 16 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {

ItemImpl(_, _, Some(_), _, _) => parent,

ItemTrait(_, _, _, _, ref items) => {
ItemTrait(_, _, _, ref items) => {
let name_bindings =
self.add_child(name,
parent.clone(),
Expand Down Expand Up @@ -4093,7 +4093,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
impl_items[]);
}

ItemTrait(_, ref generics, ref unbound, ref bounds, ref trait_items) => {
ItemTrait(_, ref generics, ref bounds, ref trait_items) => {
// Create a new rib for the self type.
let mut self_type_rib = Rib::new(ItemRibKind);

Expand All @@ -4114,13 +4114,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
this.resolve_type_parameter_bounds(item.id, bounds,
TraitDerivation);

match *unbound {
Some(ref tpb) => {
this.resolve_trait_reference(item.id, tpb, TraitDerivation);
}
None => {}
}

for trait_item in (*trait_items).iter() {
// Create a new rib for the trait_item-specific type
// parameters.
Expand Down Expand Up @@ -4368,12 +4361,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
self.resolve_type_parameter_bound(type_parameter.id, bound,
TraitBoundingTypeParameter);
}
match &type_parameter.unbound {
&Some(ref unbound) =>
self.resolve_trait_reference(
type_parameter.id, unbound, TraitBoundingTypeParameter),
&None => {}
}
match type_parameter.default {
Some(ref ty) => self.resolve_type(&**ty),
None => {}
Expand All @@ -4395,7 +4382,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
type_parameter_bound: &TyParamBound,
reference_type: TraitReferenceType) {
match *type_parameter_bound {
TraitTyParamBound(ref tref) => {
TraitTyParamBound(ref tref, _) => {
self.resolve_poly_trait_reference(id, tref, reference_type)
}
RegionTyParamBound(..) => {}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/save/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
// super-traits
for super_bound in trait_refs.iter() {
let trait_ref = match *super_bound {
ast::TraitTyParamBound(ref trait_ref) => {
ast::TraitTyParamBound(ref trait_ref, _) => {
trait_ref
}
ast::RegionTyParamBound(..) => {
Expand Down Expand Up @@ -1052,7 +1052,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
&**typ,
impl_items)
}
ast::ItemTrait(_, ref generics, _, ref trait_refs, ref methods) =>
ast::ItemTrait(_, ref generics, ref trait_refs, ref methods) =>
self.process_trait(item, generics, trait_refs, methods),
ast::ItemMod(ref m) => self.process_mod(item, m),
ast::ItemTy(ref ty, ref ty_params) => {
Expand All @@ -1076,7 +1076,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
fn visit_generics(&mut self, generics: &ast::Generics) {
for param in generics.ty_params.iter() {
for bound in param.bounds.iter() {
if let ast::TraitTyParamBound(ref trait_ref) = *bound {
if let ast::TraitTyParamBound(ref trait_ref, _) = *bound {
self.process_trait_ref(&trait_ref.trait_ref, None);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
let mut trait_def_ids = DefIdMap::new();
for ast_bound in ast_bounds.iter() {
match *ast_bound {
ast::TraitTyParamBound(ref b) => {
ast::TraitTyParamBound(ref b, ast::TraitBoundModifier::None) => {
match ::lookup_def_tcx(tcx, b.trait_ref.path.span, b.trait_ref.ref_id) {
def::DefTrait(trait_did) => {
match trait_def_ids.get(&trait_did) {
Expand Down Expand Up @@ -1664,6 +1664,7 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
}
trait_bounds.push(b);
}
ast::TraitTyParamBound(_, ast::TraitBoundModifier::Maybe) => {}
ast::RegionTyParamBound(ref l) => {
region_bounds.push(l);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) {
}

}
ast::ItemTrait(_, _, _, _, ref trait_methods) => {
ast::ItemTrait(_, _, _, ref trait_methods) => {
let trait_def = ty::lookup_trait_def(ccx.tcx, local_def(it.id));
for trait_method in trait_methods.iter() {
match *trait_method {
Expand Down
59 changes: 28 additions & 31 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
trait_def: &ty::TraitDef<'tcx>) {
let tcx = ccx.tcx;
if let ast_map::NodeItem(item) = tcx.map.get(trait_id) {
if let ast::ItemTrait(_, _, _, _, ref trait_items) = item.node {
if let ast::ItemTrait(_, _, _, ref trait_items) = item.node {
// For each method, construct a suitable ty::Method and
// store it into the `tcx.impl_or_trait_items` table:
for trait_item in trait_items.iter() {
Expand Down Expand Up @@ -627,11 +627,6 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
ast::RegionTyParamBound(..) => { }
}
}

match ty_param.unbound {
Some(_) => { warn = true; }
None => { }
}
}

if warn {
Expand Down Expand Up @@ -1146,7 +1141,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
AllowEqConstraints::DontAllow);
}
},
ast::ItemTrait(_, _, _, _, ref trait_methods) => {
ast::ItemTrait(_, _, _, ref trait_methods) => {
let trait_def = trait_def_of_item(ccx, it);

debug!("trait_def: ident={} trait_def={}",
Expand Down Expand Up @@ -1338,13 +1333,12 @@ pub fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
return def.clone();
}

let (unsafety, generics, unbound, bounds, items) = match it.node {
let (unsafety, generics, bounds, items) = match it.node {
ast::ItemTrait(unsafety,
ref generics,
ref unbound,
ref supertraits,
ref items) => {
(unsafety, generics, unbound, supertraits, items.as_slice())
(unsafety, generics, supertraits, items.as_slice())
}
ref s => {
tcx.sess.span_bug(
Expand All @@ -1367,7 +1361,6 @@ pub fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
token::SELF_KEYWORD_NAME,
self_param_ty,
bounds.as_slice(),
unbound,
it.span);

let substs = mk_item_substs(ccx, &ty_generics);
Expand Down Expand Up @@ -1683,29 +1676,37 @@ fn ty_generics_for_fn_or_method<'tcx,AC>(
create_type_parameters_for_associated_types)
}

// Add the Sized bound, unless the type parameter is marked as `Sized?`.
// Add the Sized bound, unless the type parameter is marked as `?Sized`.
fn add_unsized_bound<'tcx,AC>(this: &AC,
unbound: &Option<ast::TraitRef>,
bounds: &mut ty::BuiltinBounds,
desc: &str,
ast_bounds: &[ast::TyParamBound],
span: Span)
where AC: AstConv<'tcx> {
// Try to find an unbound in bounds.
let mut unbound = None;
for ab in ast_bounds.iter() {
if let &ast::TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = ab {
if unbound.is_none() {
assert!(ptr.bound_lifetimes.is_empty());
unbound = Some(ptr.trait_ref.clone());
} else {
this.tcx().sess.span_err(span, "type parameter has more than one relaxed default \
bound, only one is supported");
}
}
}

let kind_id = this.tcx().lang_items.require(SizedTraitLangItem);
match unbound {
&Some(ref tpb) => {
Some(ref tpb) => {
// FIXME(#8559) currently requires the unbound to be built-in.
let trait_def_id = ty::trait_ref_to_def_id(this.tcx(), tpb);
match kind_id {
Ok(kind_id) if trait_def_id != kind_id => {
this.tcx().sess.span_warn(span,
format!("default bound relaxed \
for a {}, but this \
does nothing because \
the given bound is not \
a default. \
Only `Sized?` is \
supported",
desc)[]);
"default bound relaxed for a type parameter, but \
this does nothing because the given bound is not \
a default. Only `?Sized` is supported");
ty::try_add_builtin_trait(this.tcx(),
kind_id,
bounds);
Expand All @@ -1717,7 +1718,7 @@ fn add_unsized_bound<'tcx,AC>(this: &AC,
ty::try_add_builtin_trait(this.tcx(), kind_id.unwrap(), bounds);
}
// No lang item for Sized, so we can't add it as a bound.
&None => {}
None => {}
}
}

Expand Down Expand Up @@ -1807,7 +1808,7 @@ fn ty_generics<'tcx,AC>(this: &AC,

for bound in bound_pred.bounds.iter() {
match bound {
&ast::TyParamBound::TraitTyParamBound(ref poly_trait_ref) => {
&ast::TyParamBound::TraitTyParamBound(ref poly_trait_ref, _) => {
let trait_ref = astconv::instantiate_poly_trait_ref(
this,
&ExplicitRscope,
Expand Down Expand Up @@ -1880,7 +1881,7 @@ fn ty_generics<'tcx,AC>(this: &AC,
for bound in param.bounds.iter() {
// In the above example, `ast_trait_ref` is `Iterator`.
let ast_trait_ref = match *bound {
ast::TraitTyParamBound(ref r) => r,
ast::TraitTyParamBound(ref r, _) => r,
ast::RegionTyParamBound(..) => { continue; }
};

Expand Down Expand Up @@ -1978,7 +1979,6 @@ fn get_or_create_type_parameter_def<'tcx,AC>(this: &AC,
param.ident.name,
param_ty,
param.bounds[],
&param.unbound,
param.span);
let default = match param.default {
None => None,
Expand Down Expand Up @@ -2023,7 +2023,6 @@ fn compute_bounds<'tcx,AC>(this: &AC,
name_of_bounded_thing: ast::Name,
param_ty: ty::ParamTy,
ast_bounds: &[ast::TyParamBound],
unbound: &Option<ast::TraitRef>,
span: Span)
-> ty::ParamBounds<'tcx>
where AC: AstConv<'tcx> {
Expand All @@ -2032,11 +2031,9 @@ fn compute_bounds<'tcx,AC>(this: &AC,
param_ty,
ast_bounds);


add_unsized_bound(this,
unbound,
&mut param_bounds.builtin_bounds,
"type parameter",
ast_bounds,
span);

check_bounds_compatible(this.tcx(),
Expand Down
Loading

0 comments on commit 2a85477

Please sign in to comment.