Skip to content

Commit e656081

Browse files
committed
Accept ?Sized as well as Sized?
Includes a bit of refactoring to store `?` unbounds as bounds with a modifier, rather than in their own world, in the AST at least.
1 parent 5ba6102 commit e656081

File tree

26 files changed

+179
-138
lines changed

26 files changed

+179
-138
lines changed

src/librustc/lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,9 +1782,9 @@ impl LintPass for Stability {
17821782
if self.is_internal(cx, item.span) { return }
17831783

17841784
match item.node {
1785-
ast::ItemTrait(_, _, _, ref supertraits, _) => {
1785+
ast::ItemTrait(_, _, ref supertraits, _) => {
17861786
for t in supertraits.iter() {
1787-
if let ast::TraitTyParamBound(ref t) = *t {
1787+
if let ast::TraitTyParamBound(ref t, _) = *t {
17881788
let id = ty::trait_ref_to_def_id(cx.tcx, &t.trait_ref);
17891789
self.lint(cx, id, t.trait_ref.path.span);
17901790
}

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
13081308
}
13091309
}
13101310
}
1311-
ast::ItemTrait(_, _, _, _, ref ms) => {
1311+
ast::ItemTrait(_, _, _, ref ms) => {
13121312
add_to_index(item, rbml_w, index);
13131313
rbml_w.start_tag(tag_items_data_item);
13141314
encode_def_id(rbml_w, def_id);

src/librustc/middle/infer/error_reporting.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,6 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
10431043
ident: ty_param.ident,
10441044
id: ty_param.id,
10451045
bounds: bounds,
1046-
unbound: ty_param.unbound.clone(),
10471046
default: ty_param.default.clone(),
10481047
span: ty_param.span,
10491048
}
@@ -1063,7 +1062,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
10631062
// be passing down a map.
10641063
ast::RegionTyParamBound(lt)
10651064
}
1066-
&ast::TraitTyParamBound(ref poly_tr) => {
1065+
&ast::TraitTyParamBound(ref poly_tr, modifier) => {
10671066
let tr = &poly_tr.trait_ref;
10681067
let last_seg = tr.path.segments.last().unwrap();
10691068
let mut insert = Vec::new();
@@ -1087,7 +1086,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
10871086
path: new_path,
10881087
ref_id: tr.ref_id,
10891088
}
1090-
})
1089+
}, modifier)
10911090
}
10921091
}
10931092
})

src/librustc/middle/privacy.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'v> Visitor<'v> for ParentVisitor {
122122
// method to the root. In this case, if the trait is private, then
123123
// parent all the methods to the trait to indicate that they're
124124
// private.
125-
ast::ItemTrait(_, _, _, _, ref methods) if item.vis != ast::Public => {
125+
ast::ItemTrait(_, _, _, ref methods) if item.vis != ast::Public => {
126126
for m in methods.iter() {
127127
match *m {
128128
ast::ProvidedMethod(ref m) => {
@@ -328,7 +328,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
328328

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

1181-
ast::ItemTrait(_, _, _, _, ref methods) => {
1181+
ast::ItemTrait(_, _, _, ref methods) => {
11821182
for m in methods.iter() {
11831183
match *m {
11841184
ast::ProvidedMethod(ref m) => {
@@ -1242,7 +1242,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
12421242

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

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

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

1352-
ast::ItemTrait(_, _, _, ref bounds, _) => {
1352+
ast::ItemTrait(_, _, ref bounds, _) => {
13531353
if !self.trait_is_public(item.id) {
13541354
return
13551355
}

src/librustc/middle/resolve_lifetime.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
105105
ast::ItemTy(_, ref generics) |
106106
ast::ItemEnum(_, ref generics) |
107107
ast::ItemStruct(_, ref generics) |
108-
ast::ItemTrait(_, ref generics, _, _, _) |
108+
ast::ItemTrait(_, ref generics, _, _) |
109109
ast::ItemImpl(_, ref generics, _, _, _) => {
110110
// These kinds of items have only early bound lifetime parameters.
111111
let lifetimes = &generics.lifetimes;
@@ -232,7 +232,9 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
232232
}
233233
}
234234

235-
fn visit_poly_trait_ref(&mut self, trait_ref: &ast::PolyTraitRef) {
235+
fn visit_poly_trait_ref(&mut self, trait_ref:
236+
&ast::PolyTraitRef,
237+
_modifier: &ast::TraitBoundModifier) {
236238
debug!("visit_poly_trait_ref trait_ref={}", trait_ref);
237239

238240
self.with(LateScope(&trait_ref.bound_lifetimes, self.scope), |old_scope, this| {

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4608,7 +4608,7 @@ pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
46084608
match cx.map.find(id.node) {
46094609
Some(ast_map::NodeItem(item)) => {
46104610
match item.node {
4611-
ItemTrait(_, _, _, _, ref ms) => {
4611+
ItemTrait(_, _, _, ref ms) => {
46124612
let (_, p) =
46134613
ast_util::split_trait_methods(ms[]);
46144614
p.iter()

src/librustc_resolve/lib.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ impl<'a> Resolver<'a> {
14591459

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

1462-
ItemTrait(_, _, _, _, ref items) => {
1462+
ItemTrait(_, _, _, ref items) => {
14631463
let name_bindings =
14641464
self.add_child(name,
14651465
parent.clone(),
@@ -3998,7 +3998,7 @@ impl<'a> Resolver<'a> {
39983998
impl_items[]);
39993999
}
40004000

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

@@ -4019,13 +4019,6 @@ impl<'a> Resolver<'a> {
40194019
this.resolve_type_parameter_bounds(item.id, bounds,
40204020
TraitDerivation);
40214021

4022-
match *unbound {
4023-
Some(ref tpb) => {
4024-
this.resolve_trait_reference(item.id, tpb, TraitDerivation);
4025-
}
4026-
None => {}
4027-
}
4028-
40294022
for trait_item in (*trait_items).iter() {
40304023
// Create a new rib for the trait_item-specific type
40314024
// parameters.
@@ -4273,12 +4266,6 @@ impl<'a> Resolver<'a> {
42734266
self.resolve_type_parameter_bound(type_parameter.id, bound,
42744267
TraitBoundingTypeParameter);
42754268
}
4276-
match &type_parameter.unbound {
4277-
&Some(ref unbound) =>
4278-
self.resolve_trait_reference(
4279-
type_parameter.id, unbound, TraitBoundingTypeParameter),
4280-
&None => {}
4281-
}
42824269
match type_parameter.default {
42834270
Some(ref ty) => self.resolve_type(&**ty),
42844271
None => {}
@@ -4300,7 +4287,7 @@ impl<'a> Resolver<'a> {
43004287
type_parameter_bound: &TyParamBound,
43014288
reference_type: TraitReferenceType) {
43024289
match *type_parameter_bound {
4303-
TraitTyParamBound(ref tref) => {
4290+
TraitTyParamBound(ref tref, _) => {
43044291
self.resolve_poly_trait_reference(id, tref, reference_type)
43054292
}
43064293
RegionTyParamBound(..) => {}

src/librustc_trans/save/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
710710
// super-traits
711711
for super_bound in trait_refs.iter() {
712712
let trait_ref = match *super_bound {
713-
ast::TraitTyParamBound(ref trait_ref) => {
713+
ast::TraitTyParamBound(ref trait_ref, _) => {
714714
trait_ref
715715
}
716716
ast::RegionTyParamBound(..) => {
@@ -1052,7 +1052,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
10521052
&**typ,
10531053
impl_items)
10541054
}
1055-
ast::ItemTrait(_, ref generics, _, ref trait_refs, ref methods) =>
1055+
ast::ItemTrait(_, ref generics, ref trait_refs, ref methods) =>
10561056
self.process_trait(item, generics, trait_refs, methods),
10571057
ast::ItemMod(ref m) => self.process_mod(item, m),
10581058
ast::ItemTy(ref ty, ref ty_params) => {
@@ -1076,7 +1076,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
10761076
fn visit_generics(&mut self, generics: &ast::Generics) {
10771077
for param in generics.ty_params.iter() {
10781078
for bound in param.bounds.iter() {
1079-
if let ast::TraitTyParamBound(ref trait_ref) = *bound {
1079+
if let ast::TraitTyParamBound(ref trait_ref, _) = *bound {
10801080
self.process_trait_ref(&trait_ref.trait_ref, None);
10811081
}
10821082
}

src/librustc_typeck/astconv.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
16251625
let mut trait_def_ids = DefIdMap::new();
16261626
for ast_bound in ast_bounds.iter() {
16271627
match *ast_bound {
1628-
ast::TraitTyParamBound(ref b) => {
1628+
ast::TraitTyParamBound(ref b, ast::TraitBoundModifier::None) => {
16291629
match ::lookup_def_tcx(tcx, b.trait_ref.path.span, b.trait_ref.ref_id) {
16301630
def::DefTrait(trait_did) => {
16311631
match trait_def_ids.get(&trait_did) {
@@ -1663,6 +1663,7 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
16631663
}
16641664
trait_bounds.push(b);
16651665
}
1666+
ast::TraitTyParamBound(_, ast::TraitBoundModifier::Maybe) => {}
16661667
ast::RegionTyParamBound(ref l) => {
16671668
region_bounds.push(l);
16681669
}

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) {
658658
}
659659

660660
}
661-
ast::ItemTrait(_, _, _, _, ref trait_methods) => {
661+
ast::ItemTrait(_, _, _, ref trait_methods) => {
662662
let trait_def = ty::lookup_trait_def(ccx.tcx, local_def(it.id));
663663
for trait_method in trait_methods.iter() {
664664
match *trait_method {

0 commit comments

Comments
 (0)