Skip to content

Commit 22f777b

Browse files
committed
Parse unsafe impl but don't do anything particularly interesting with the results.
1 parent 5686a91 commit 22f777b

File tree

28 files changed

+97
-57
lines changed

28 files changed

+97
-57
lines changed

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ impl LintPass for Stability {
17291729
}
17301730
}
17311731
}
1732-
ast::ItemImpl(_, Some(ref t), _, _) => {
1732+
ast::ItemImpl(_, _, Some(ref t), _, _) => {
17331733
let id = ty::trait_ref_to_def_id(cx.tcx, t);
17341734
self.lint(cx, id, t.path.span);
17351735
}

src/librustc/metadata/decoder.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,23 @@ fn item_to_def_like(item: rbml::Doc, did: ast::DefId, cnum: ast::CrateNum)
361361
}
362362
}
363363

364+
fn parse_unsafety(item_doc: rbml::Doc) -> ast::Unsafety {
365+
let unsafety_doc = reader::get_doc(item_doc, tag_unsafety);
366+
if reader::doc_as_u8(unsafety_doc) != 0 {
367+
ast::Unsafety::Unsafe
368+
} else {
369+
ast::Unsafety::Normal
370+
}
371+
}
372+
364373
pub fn get_trait_def<'tcx>(cdata: Cmd,
365374
item_id: ast::NodeId,
366375
tcx: &ty::ctxt<'tcx>) -> ty::TraitDef<'tcx>
367376
{
368377
let item_doc = lookup_item(item_id, cdata.data());
369378
let generics = doc_generics(item_doc, tcx, cdata, tag_item_generics);
370379
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-
};
380+
let unsafety = parse_unsafety(item_doc);
375381

376382
ty::TraitDef {
377383
unsafety: unsafety,

src/librustc/metadata/encoder.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12051205
None => {}
12061206
}
12071207
}
1208-
ast::ItemImpl(_, ref opt_trait, ref ty, ref ast_items) => {
1208+
ast::ItemImpl(unsafety, _, ref opt_trait, ref ty, ref ast_items) => {
12091209
// We need to encode information about the default methods we
12101210
// have inherited, so we drive this based on the impl structure.
12111211
let impl_items = tcx.impl_items.borrow();
@@ -1218,6 +1218,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12181218
encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
12191219
encode_name(rbml_w, item.ident.name);
12201220
encode_attributes(rbml_w, item.attrs.as_slice());
1221+
encode_unsafety(rbml_w, unsafety);
12211222
match ty.node {
12221223
ast::TyPath(ref path, _) if path.segments
12231224
.len() == 1 => {
@@ -1315,15 +1316,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
13151316
encode_family(rbml_w, 'I');
13161317
encode_item_variances(rbml_w, ecx, item.id);
13171318
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-
1319+
encode_unsafety(rbml_w, trait_def.unsafety);
13271320
encode_generics(rbml_w, ecx, &trait_def.generics, tag_item_generics);
13281321
encode_trait_ref(rbml_w, ecx, &*trait_def.trait_ref, tag_item_trait_ref);
13291322
encode_name(rbml_w, item.ident.name);
@@ -1683,6 +1676,14 @@ fn encode_attributes(rbml_w: &mut Encoder, attrs: &[ast::Attribute]) {
16831676
rbml_w.end_tag();
16841677
}
16851678

1679+
fn encode_unsafety(rbml_w: &mut Encoder, unsafety: ast::Unsafety) {
1680+
let byte: u8 = match unsafety {
1681+
ast::Unsafety::Normal => 0,
1682+
ast::Unsafety::Unsafe => 1,
1683+
};
1684+
rbml_w.wr_tagged_u8(tag_unsafety, byte);
1685+
}
1686+
16861687
fn encode_crate_deps(rbml_w: &mut Encoder, cstore: &cstore::CStore) {
16871688
fn get_ordered_deps(cstore: &cstore::CStore) -> Vec<decoder::CrateDep> {
16881689
// Pull the cnums and name,vers,hash out of cstore
@@ -1864,7 +1865,7 @@ struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> {
18641865

18651866
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
18661867
fn visit_item(&mut self, item: &ast::Item) {
1867-
if let ast::ItemImpl(_, Some(ref trait_ref), _, _) = item.node {
1868+
if let ast::ItemImpl(_, _, Some(ref trait_ref), _, _) = item.node {
18681869
let def_map = &self.ecx.tcx.def_map;
18691870
let trait_def = def_map.borrow()[trait_ref.ref_id].clone();
18701871
let def_id = trait_def.def_id();

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl<'v> Visitor<'v> for LifeSeeder {
355355
ast::ItemEnum(ref enum_def, _) if allow_dead_code => {
356356
self.worklist.extend(enum_def.variants.iter().map(|variant| variant.node.id));
357357
}
358-
ast::ItemImpl(_, Some(ref _trait_ref), _, ref impl_items) => {
358+
ast::ItemImpl(_, _, Some(ref _trait_ref), _, ref impl_items) => {
359359
for impl_item in impl_items.iter() {
360360
match *impl_item {
361361
ast::MethodImplItem(ref method) => {

src/librustc/middle/infer/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ fn lifetimes_in_scope(tcx: &ty::ctxt,
16901690
match tcx.map.find(parent) {
16911691
Some(node) => match node {
16921692
ast_map::NodeItem(item) => match item.node {
1693-
ast::ItemImpl(ref gen, _, _, _) => {
1693+
ast::ItemImpl(_, ref gen, _, _, _) => {
16941694
taken.push_all(gen.lifetimes.as_slice());
16951695
}
16961696
_ => ()

src/librustc/middle/privacy.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
241241
// undefined symbols at linkage time if this case is not handled.
242242
//
243243
// * Private trait impls for private types can be completely ignored
244-
ast::ItemImpl(_, _, ref ty, ref impl_items) => {
244+
ast::ItemImpl(_, _, _, ref ty, ref impl_items) => {
245245
let public_ty = match ty.node {
246246
ast::TyPath(_, id) => {
247247
match self.tcx.def_map.borrow()[id].clone() {
@@ -611,7 +611,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
611611
// invoked, and the struct/enum itself is private. Crawl
612612
// back up the chains to find the relevant struct/enum that
613613
// was private.
614-
ast::ItemImpl(_, _, ref ty, _) => {
614+
ast::ItemImpl(_, _, _, ref ty, _) => {
615615
let id = match ty.node {
616616
ast::TyPath(_, id) => id,
617617
_ => return Some((err_span, err_msg, None)),
@@ -1096,7 +1096,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
10961096
match item.node {
10971097
// implementations of traits don't need visibility qualifiers because
10981098
// that's controlled by having the trait in scope.
1099-
ast::ItemImpl(_, Some(..), _, ref impl_items) => {
1099+
ast::ItemImpl(_, _, Some(..), _, ref impl_items) => {
11001100
check_inherited(item.span, item.vis,
11011101
"visibility qualifiers have no effect on trait \
11021102
impls");
@@ -1175,7 +1175,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11751175
};
11761176
check_inherited(tcx, item.span, item.vis);
11771177
match item.node {
1178-
ast::ItemImpl(_, _, _, ref impl_items) => {
1178+
ast::ItemImpl(_, _, _, _, ref impl_items) => {
11791179
for impl_item in impl_items.iter() {
11801180
match *impl_item {
11811181
ast::MethodImplItem(ref m) => {
@@ -1320,7 +1320,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
13201320
// (i.e. we could just return here to not check them at
13211321
// all, or some worse estimation of whether an impl is
13221322
// publicly visible.
1323-
ast::ItemImpl(ref g, ref trait_ref, ref self_, ref impl_items) => {
1323+
ast::ItemImpl(_, ref g, ref trait_ref, ref self_, ref impl_items) => {
13241324
// `impl [... for] Private` is never visible.
13251325
let self_contains_private;
13261326
// impl [... for] Public<...>, but not `impl [... for]

src/librustc/middle/reachable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn item_might_be_inlined(item: &ast::Item) -> bool {
5555
}
5656

5757
match item.node {
58-
ast::ItemImpl(ref generics, _, _, _) |
58+
ast::ItemImpl(_, ref generics, _, _, _) |
5959
ast::ItemFn(_, _, _, ref generics, _) => {
6060
generics_require_inlining(generics)
6161
}
@@ -216,7 +216,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
216216
.map
217217
.expect_item(impl_did.node)
218218
.node {
219-
ast::ItemImpl(ref generics, _, _, _) => {
219+
ast::ItemImpl(_, ref generics, _, _, _) => {
220220
generics_require_inlining(generics)
221221
}
222222
_ => false

src/librustc/middle/resolve.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ impl<'a> Resolver<'a> {
14321432
parent
14331433
}
14341434

1435-
ItemImpl(_, None, ref ty, ref impl_items) => {
1435+
ItemImpl(_, _, None, ref ty, ref impl_items) => {
14361436
// If this implements an anonymous trait, then add all the
14371437
// methods within to a new module, if the type was defined
14381438
// within this module.
@@ -1581,7 +1581,7 @@ impl<'a> Resolver<'a> {
15811581
parent
15821582
}
15831583

1584-
ItemImpl(_, Some(_), _, _) => parent,
1584+
ItemImpl(_, _, Some(_), _, _) => parent,
15851585

15861586
ItemTrait(_, _, _, _, ref items) => {
15871587
let name_bindings =
@@ -4230,7 +4230,8 @@ impl<'a> Resolver<'a> {
42304230
});
42314231
}
42324232

4233-
ItemImpl(ref generics,
4233+
ItemImpl(_,
4234+
ref generics,
42344235
ref implemented_traits,
42354236
ref self_type,
42364237
ref impl_items) => {

src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
114114
visit::walk_item(this, item);
115115
});
116116
}
117-
ast::ItemImpl(ref generics, _, _, _) => {
117+
ast::ItemImpl(_, ref generics, _, _, _) => {
118118
// Impls have both early- and late-bound lifetimes.
119119
self.visit_early_late(subst::TypeSpace, generics, |this| {
120120
this.check_lifetime_defs(&generics.lifetimes);

src/librustc/middle/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4741,7 +4741,7 @@ pub fn impl_trait_ref<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
47414741
match cx.map.find(id.node) {
47424742
Some(ast_map::NodeItem(item)) => {
47434743
match item.node {
4744-
ast::ItemImpl(_, ref opt_trait, _, _) => {
4744+
ast::ItemImpl(_, _, ref opt_trait, _, _) => {
47454745
match opt_trait {
47464746
&Some(ref t) => {
47474747
Some(ty::node_id_to_trait_ref(cx, t.ref_id))
@@ -5722,7 +5722,7 @@ pub fn trait_id_of_impl(tcx: &ctxt,
57225722
match node {
57235723
ast_map::NodeItem(item) => {
57245724
match item.node {
5725-
ast::ItemImpl(_, Some(ref trait_ref), _, _) => {
5725+
ast::ItemImpl(_, _, Some(ref trait_ref), _, _) => {
57265726
Some(node_id_to_trait_ref(tcx, trait_ref.ref_id).def_id)
57275727
}
57285728
_ => None

0 commit comments

Comments
 (0)