Skip to content

Commit 5686a91

Browse files
committed
Parse unsafe trait but do not do anything with it beyond parsing and integrating into rustdoc etc.
1 parent 092d04a commit 5686a91

File tree

25 files changed

+103
-34
lines changed

25 files changed

+103
-34
lines changed

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);

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;

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))

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);

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
}

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

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

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()

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) => {

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 {

0 commit comments

Comments
 (0)