Skip to content

Commit c150b3b

Browse files
committed
---
yaml --- r: 164840 b: refs/heads/try c: 5686a91 h: refs/heads/master v: v3
1 parent 80ac796 commit c150b3b

File tree

26 files changed

+104
-35
lines changed

26 files changed

+104
-35
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: f8f2c7a9537c7f333b242f616aefb75a83860927
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 8443b09e361b96d1f9b7f45a65ed0d31c0e86e70
5-
refs/heads/try: 092d04a40a3db44af2dd50e43a77449a7e56dd13
5+
refs/heads/try: 5686a91914ac678ccb78220367daefe585a0d66a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ impl LintPass for Stability {
17211721
if self.is_internal(cx, item.span) { return }
17221722

17231723
match item.node {
1724-
ast::ItemTrait(_, _, ref supertraits, _) => {
1724+
ast::ItemTrait(_, _, _, ref supertraits, _) => {
17251725
for t in supertraits.iter() {
17261726
if let ast::TraitTyParamBound(ref t) = *t {
17271727
let id = ty::trait_ref_to_def_id(cx.tcx, &t.trait_ref);

branches/try/src/librustc/metadata/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,5 @@ pub const tag_method_ty_generics: uint = 0xa7;
255255
pub const tag_predicate: uint = 0xa8;
256256
pub const tag_predicate_space: uint = 0xa9;
257257
pub const tag_predicate_data: uint = 0xb0;
258+
259+
pub const tag_unsafety: uint = 0xb1;

branches/try/src/librustc/metadata/decoder.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,13 @@ pub fn get_trait_def<'tcx>(cdata: Cmd,
368368
let item_doc = lookup_item(item_id, cdata.data());
369369
let generics = doc_generics(item_doc, tcx, cdata, tag_item_generics);
370370
let bounds = trait_def_bounds(item_doc, tcx, cdata);
371+
let unsafety = match reader::maybe_get_doc(item_doc, tag_unsafety) {
372+
Some(_) => ast::Unsafety::Unsafe,
373+
None => ast::Unsafety::Normal,
374+
};
371375

372376
ty::TraitDef {
377+
unsafety: unsafety,
373378
generics: generics,
374379
bounds: bounds,
375380
trait_ref: Rc::new(item_trait_ref(item_doc, tcx, cdata))

branches/try/src/librustc/metadata/encoder.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,13 +1308,22 @@ 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);
13151315
encode_family(rbml_w, 'I');
13161316
encode_item_variances(rbml_w, ecx, item.id);
13171317
let trait_def = ty::lookup_trait_def(tcx, def_id);
1318+
1319+
match trait_def.unsafety {
1320+
ast::Unsafety::Unsafe => {
1321+
rbml_w.start_tag(tag_unsafety);
1322+
rbml_w.end_tag();
1323+
}
1324+
ast::Unsafety::Normal => { }
1325+
}
1326+
13181327
encode_generics(rbml_w, ecx, &trait_def.generics, tag_item_generics);
13191328
encode_trait_ref(rbml_w, ecx, &*trait_def.trait_ref, tag_item_trait_ref);
13201329
encode_name(rbml_w, item.ident.name);

branches/try/src/librustc/middle/privacy.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'v> Visitor<'v> for ParentVisitor {
7676
// method to the root. In this case, if the trait is private, then
7777
// parent all the methods to the trait to indicate that they're
7878
// private.
79-
ast::ItemTrait(_, _, _, ref methods) if item.vis != ast::Public => {
79+
ast::ItemTrait(_, _, _, _, ref methods) if item.vis != ast::Public => {
8080
for m in methods.iter() {
8181
match *m {
8282
ast::ProvidedMethod(ref m) => {
@@ -282,7 +282,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
282282

283283
// Default methods on traits are all public so long as the trait
284284
// is public
285-
ast::ItemTrait(_, _, _, ref methods) if public_first => {
285+
ast::ItemTrait(_, _, _, _, ref methods) if public_first => {
286286
for method in methods.iter() {
287287
match *method {
288288
ast::ProvidedMethod(ref m) => {
@@ -1134,7 +1134,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11341134
}
11351135
}
11361136

1137-
ast::ItemTrait(_, _, _, ref methods) => {
1137+
ast::ItemTrait(_, _, _, _, ref methods) => {
11381138
for m in methods.iter() {
11391139
match *m {
11401140
ast::ProvidedMethod(ref m) => {
@@ -1198,7 +1198,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11981198

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

1201-
ast::ItemTrait(_, _, _, ref methods) => {
1201+
ast::ItemTrait(_, _, _, _, ref methods) => {
12021202
for m in methods.iter() {
12031203
match *m {
12041204
ast::RequiredMethod(..) => {}
@@ -1305,7 +1305,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
13051305
// namespace (the contents have their own privacies).
13061306
ast::ItemForeignMod(_) => {}
13071307

1308-
ast::ItemTrait(_, _, ref bounds, _) => {
1308+
ast::ItemTrait(_, _, _, ref bounds, _) => {
13091309
if !self.trait_is_public(item.id) {
13101310
return
13111311
}

branches/try/src/librustc/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ impl<'a> Resolver<'a> {
15831583

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

1586-
ItemTrait(_, _, _, ref items) => {
1586+
ItemTrait(_, _, _, _, ref items) => {
15871587
let name_bindings =
15881588
self.add_child(name,
15891589
parent.clone(),
@@ -4241,7 +4241,7 @@ impl<'a> Resolver<'a> {
42414241
impl_items.as_slice());
42424242
}
42434243

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

branches/try/src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
106106
ast::ItemTy(_, ref generics) |
107107
ast::ItemEnum(_, ref generics) |
108108
ast::ItemStruct(_, ref generics) |
109-
ast::ItemTrait(ref generics, _, _, _) => {
109+
ast::ItemTrait(_, ref generics, _, _, _) => {
110110
// These kinds of items have only early bound lifetime parameters.
111111
let lifetimes = &generics.lifetimes;
112112
self.with(EarlyScope(subst::TypeSpace, lifetimes, &ROOT_SCOPE), |this| {

branches/try/src/librustc/middle/ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,8 @@ pub struct Polytype<'tcx> {
19151915

19161916
/// As `Polytype` but for a trait ref.
19171917
pub struct TraitDef<'tcx> {
1918+
pub unsafety: ast::Unsafety,
1919+
19181920
/// Generic type definitions. Note that `Self` is listed in here
19191921
/// as having a single bound, the trait itself (e.g., in the trait
19201922
/// `Eq`, there is a single bound `Self : Eq`). This is so that
@@ -4572,7 +4574,7 @@ pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
45724574
match cx.map.find(id.node) {
45734575
Some(ast_map::NodeItem(item)) => {
45744576
match item.node {
4575-
ItemTrait(_, _, _, ref ms) => {
4577+
ItemTrait(_, _, _, _, ref ms) => {
45764578
let (_, p) =
45774579
ast_util::split_trait_methods(ms.as_slice());
45784580
p.iter()

branches/try/src/librustc_trans/save/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
10501050
&**typ,
10511051
impl_items)
10521052
}
1053-
ast::ItemTrait(ref generics, _, ref trait_refs, ref methods) =>
1053+
ast::ItemTrait(_, ref generics, _, ref trait_refs, ref methods) =>
10541054
self.process_trait(item, generics, trait_refs, methods),
10551055
ast::ItemMod(ref m) => self.process_mod(item, m),
10561056
ast::ItemTy(ref ty, ref ty_params) => {

branches/try/src/librustc_typeck/check/mod.rs

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

627627
}
628-
ast::ItemTrait(_, _, _, ref trait_methods) => {
628+
ast::ItemTrait(_, _, _, _, ref trait_methods) => {
629629
let trait_def = ty::lookup_trait_def(ccx.tcx, local_def(it.id));
630630
for trait_method in trait_methods.iter() {
631631
match *trait_method {

branches/try/src/librustc_typeck/collect.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
258258
trait_def: &ty::TraitDef<'tcx>) {
259259
let tcx = ccx.tcx;
260260
if let ast_map::NodeItem(item) = tcx.map.get(trait_id) {
261-
if let ast::ItemTrait(_, _, _, ref trait_items) = item.node {
261+
if let ast::ItemTrait(_, _, _, _, ref trait_items) = item.node {
262262
// For each method, construct a suitable ty::Method and
263263
// store it into the `tcx.impl_or_trait_items` table:
264264
for trait_item in trait_items.iter() {
@@ -1144,7 +1144,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
11441144
AllowEqConstraints::DontAllow);
11451145
}
11461146
},
1147-
ast::ItemTrait(_, _, _, ref trait_methods) => {
1147+
ast::ItemTrait(_, _, _, _, ref trait_methods) => {
11481148
let trait_def = trait_def_of_item(ccx, it);
11491149

11501150
debug!("trait_def: ident={} trait_def={}",
@@ -1335,12 +1335,13 @@ pub fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
13351335
return def.clone();
13361336
}
13371337

1338-
let (generics, unbound, bounds, items) = match it.node {
1339-
ast::ItemTrait(ref generics,
1338+
let (unsafety, generics, unbound, bounds, items) = match it.node {
1339+
ast::ItemTrait(unsafety,
1340+
ref generics,
13401341
ref unbound,
13411342
ref supertraits,
13421343
ref items) => {
1343-
(generics, unbound, supertraits, items.as_slice())
1344+
(unsafety, generics, unbound, supertraits, items.as_slice())
13441345
}
13451346
ref s => {
13461347
tcx.sess.span_bug(
@@ -1369,6 +1370,7 @@ pub fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
13691370

13701371
let substs = mk_item_substs(ccx, &ty_generics);
13711372
let trait_def = Rc::new(ty::TraitDef {
1373+
unsafety: unsafety,
13721374
generics: ty_generics,
13731375
bounds: bounds,
13741376
trait_ref: Rc::new(ty::TraitRef {

branches/try/src/librustc_typeck/variance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for TermsContext<'a, 'tcx> {
358358
match item.node {
359359
ast::ItemEnum(_, ref generics) |
360360
ast::ItemStruct(_, ref generics) |
361-
ast::ItemTrait(ref generics, _, _, _) => {
361+
ast::ItemTrait(_, ref generics, _, _, _) => {
362362
for (i, p) in generics.lifetimes.iter().enumerate() {
363363
let id = p.lifetime.id;
364364
self.add_inferred(item.id, RegionParam, TypeSpace, i, id);

branches/try/src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub fn build_external_trait(cx: &DocContext, tcx: &ty::ctxt,
161161
let trait_def = ty::lookup_trait_def(tcx, did);
162162
let (bounds, default_unbound) = trait_def.bounds.clean(cx);
163163
clean::Trait {
164+
unsafety: def.unsafety,
164165
generics: (&def.generics, subst::TypeSpace).clean(cx),
165166
items: items.collect(),
166167
bounds: bounds,

branches/try/src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ impl Clean<FunctionRetTy> for ast::FunctionRetTy {
974974

975975
#[deriving(Clone, Encodable, Decodable)]
976976
pub struct Trait {
977+
pub unsafety: ast::Unsafety,
977978
pub items: Vec<TraitMethod>,
978979
pub generics: Generics,
979980
pub bounds: Vec<TyParamBound>,
@@ -991,6 +992,7 @@ impl Clean<Item> for doctree::Trait {
991992
visibility: self.vis.clean(cx),
992993
stability: self.stab.clean(cx),
993994
inner: TraitItem(Trait {
995+
unsafety: self.unsafety,
994996
items: self.items.clean(cx),
995997
generics: self.generics.clean(cx),
996998
bounds: self.bounds.clean(cx),

branches/try/src/librustdoc/doctree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub struct Constant {
170170
}
171171

172172
pub struct Trait {
173+
pub unsafety: ast::Unsafety,
173174
pub name: Ident,
174175
pub items: Vec<ast::TraitItem>, //should be TraitItem
175176
pub generics: ast::Generics,

branches/try/src/librustdoc/html/render.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,8 +1693,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
16931693
}
16941694

16951695
// Output the trait definition
1696-
try!(write!(w, "<pre class='rust trait'>{}trait {}{}{}{} ",
1696+
try!(write!(w, "<pre class='rust trait'>{}{}trait {}{}{}{} ",
16971697
VisSpace(it.visibility),
1698+
UnsafetySpace(t.unsafety),
16981699
it.name.as_ref().unwrap().as_slice(),
16991700
t.generics,
17001701
bounds,

branches/try/src/librustdoc/visit_ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
322322
};
323323
om.constants.push(s);
324324
},
325-
ast::ItemTrait(ref gen, ref def_ub, ref b, ref items) => {
325+
ast::ItemTrait(unsafety, ref gen, ref def_ub, ref b, ref items) => {
326326
let t = Trait {
327+
unsafety: unsafety,
327328
name: name,
328329
items: items.clone(),
329330
generics: gen.clone(),

branches/try/src/libsyntax/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,8 @@ pub enum Item_ {
16111611
ItemEnum(EnumDef, Generics),
16121612
ItemStruct(P<StructDef>, Generics),
16131613
/// Represents a Trait Declaration
1614-
ItemTrait(Generics,
1614+
ItemTrait(Unsafety,
1615+
Generics,
16151616
Option<TraitRef>, // (optional) default bound not required for Self.
16161617
// Currently, only Sized makes sense here.
16171618
TyParamBounds,

branches/try/src/libsyntax/ast_map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
786786
None => {}
787787
}
788788
}
789-
ItemTrait(_, _, ref bounds, ref trait_items) => {
789+
ItemTrait(_, _, _, ref bounds, ref trait_items) => {
790790
for b in bounds.iter() {
791791
if let TraitTyParamBound(ref t) = *b {
792792
self.insert(t.trait_ref.ref_id, NodeItem(i));

branches/try/src/libsyntax/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ fn fold_item_underscore<F>(cx: &mut Context<F>, item: ast::Item_) -> ast::Item_
139139
.collect();
140140
ast::ItemImpl(a, b, c, impl_items)
141141
}
142-
ast::ItemTrait(a, b, c, methods) => {
142+
ast::ItemTrait(u, a, b, c, methods) => {
143143
let methods = methods.into_iter()
144144
.filter(|m| trait_method_in_cfg(cx, m))
145145
.collect();
146-
ast::ItemTrait(a, b, c, methods)
146+
ast::ItemTrait(u, a, b, c, methods)
147147
}
148148
ast::ItemStruct(def, generics) => {
149149
ast::ItemStruct(fold_struct(cx, def), generics)

branches/try/src/libsyntax/fold.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
10351035
folder.fold_ty(ty),
10361036
new_impl_items)
10371037
}
1038-
ItemTrait(generics, unbound, bounds, methods) => {
1038+
ItemTrait(unsafety, generics, unbound, bounds, methods) => {
10391039
let bounds = folder.fold_bounds(bounds);
10401040
let methods = methods.into_iter().flat_map(|method| {
10411041
let r = match method {
@@ -1063,7 +1063,8 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
10631063
};
10641064
r
10651065
}).collect();
1066-
ItemTrait(folder.fold_generics(generics),
1066+
ItemTrait(unsafety,
1067+
folder.fold_generics(generics),
10671068
unbound,
10681069
bounds,
10691070
methods)

branches/try/src/libsyntax/parse/parser.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4628,7 +4628,7 @@ impl<'a> Parser<'a> {
46284628
}
46294629

46304630
/// Parse trait Foo { ... }
4631-
fn parse_item_trait(&mut self) -> ItemInfo {
4631+
fn parse_item_trait(&mut self, unsafety: Unsafety) -> ItemInfo {
46324632
let ident = self.parse_ident();
46334633
let mut tps = self.parse_generics();
46344634
let sized = self.parse_for_sized();
@@ -4639,7 +4639,7 @@ impl<'a> Parser<'a> {
46394639
self.parse_where_clause(&mut tps);
46404640

46414641
let meths = self.parse_trait_items();
4642-
(ident, ItemTrait(tps, sized, bounds, meths), None)
4642+
(ident, ItemTrait(unsafety, tps, sized, bounds, meths), None)
46434643
}
46444644

46454645
fn parse_impl_items(&mut self) -> (Vec<ImplItem>, Vec<Attribute>) {
@@ -5539,6 +5539,23 @@ impl<'a> Parser<'a> {
55395539
maybe_append(attrs, extra_attrs));
55405540
return IoviItem(item);
55415541
}
5542+
if self.token.is_keyword(keywords::Unsafe) &&
5543+
self.look_ahead(1u, |t| t.is_keyword(keywords::Trait))
5544+
{
5545+
// UNSAFE TRAIT ITEM
5546+
self.expect_keyword(keywords::Unsafe);
5547+
self.expect_keyword(keywords::Trait);
5548+
let (ident, item_, extra_attrs) =
5549+
self.parse_item_trait(ast::Unsafety::Unsafe);
5550+
let last_span = self.last_span;
5551+
let item = self.mk_item(lo,
5552+
last_span.hi,
5553+
ident,
5554+
item_,
5555+
visibility,
5556+
maybe_append(attrs, extra_attrs));
5557+
return IoviItem(item);
5558+
}
55425559
if self.token.is_keyword(keywords::Fn) &&
55435560
self.look_ahead(1, |f| !Parser::fn_expr_lookahead(f)) {
55445561
// FUNCTION ITEM
@@ -5614,7 +5631,8 @@ impl<'a> Parser<'a> {
56145631
}
56155632
if self.eat_keyword(keywords::Trait) {
56165633
// TRAIT ITEM
5617-
let (ident, item_, extra_attrs) = self.parse_item_trait();
5634+
let (ident, item_, extra_attrs) =
5635+
self.parse_item_trait(ast::Unsafety::Normal);
56185636
let last_span = self.last_span;
56195637
let item = self.mk_item(lo,
56205638
last_span.hi,

branches/try/src/libsyntax/print/pprust.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -955,9 +955,11 @@ impl<'a> State<'a> {
955955
}
956956
try!(self.bclose(item.span));
957957
}
958-
ast::ItemTrait(ref generics, ref unbound, ref bounds, ref methods) => {
959-
try!(self.head(visibility_qualified(item.vis,
960-
"trait").as_slice()));
958+
ast::ItemTrait(unsafety, ref generics, ref unbound, ref bounds, ref methods) => {
959+
try!(self.head(""));
960+
try!(self.print_visibility(item.vis));
961+
try!(self.print_unsafety(unsafety));
962+
try!(self.word_nbsp("trait"));
961963
try!(self.print_ident(item.ident));
962964
try!(self.print_generics(generics));
963965
if let &Some(ref tref) = unbound {

0 commit comments

Comments
 (0)