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

src/librustc_trans/save/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
282282
NodeItem(item) => {
283283
scope_id = item.id;
284284
match item.node {
285-
ast::ItemImpl(_, _, ref ty, _) => {
285+
ast::ItemImpl(_, _, _, ref ty, _) => {
286286
let mut result = String::from_str("<");
287287
result.push_str(ty_to_string(&**ty).as_slice());
288288

@@ -1040,7 +1040,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
10401040
self.process_const(item, &**typ, &**expr),
10411041
ast::ItemStruct(ref def, ref ty_params) => self.process_struct(item, &**def, ty_params),
10421042
ast::ItemEnum(ref def, ref ty_params) => self.process_enum(item, def, ty_params),
1043-
ast::ItemImpl(ref ty_params,
1043+
ast::ItemImpl(_,
1044+
ref ty_params,
10441045
ref trait_ref,
10451046
ref typ,
10461047
ref impl_items) => {

src/librustc_trans/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
23042304
let mut v = TransItemVisitor{ ccx: ccx };
23052305
v.visit_block(&**body);
23062306
}
2307-
ast::ItemImpl(ref generics, _, _, ref impl_items) => {
2307+
ast::ItemImpl(_, ref generics, _, _, ref impl_items) => {
23082308
meth::trans_impl(ccx,
23092309
item.ident,
23102310
impl_items.as_slice(),

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) {
595595
let param_env = ParameterEnvironment::for_item(ccx.tcx, it.id);
596596
check_bare_fn(ccx, &**decl, &**body, it.id, fn_pty.ty, param_env);
597597
}
598-
ast::ItemImpl(_, ref opt_trait_ref, _, ref impl_items) => {
598+
ast::ItemImpl(_, _, ref opt_trait_ref, _, ref impl_items) => {
599599
debug!("ItemImpl {} with id {}", token::get_ident(it.ident), it.id);
600600

601601
let impl_pty = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id));

src/librustc_typeck/coherence/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for CoherenceCheckVisitor<'a, 'tcx> {
145145
//debug!("(checking coherence) item '{}'", token::get_ident(item.ident));
146146

147147
match item.node {
148-
ItemImpl(_, ref opt_trait, _, _) => {
148+
ItemImpl(_, _, ref opt_trait, _, _) => {
149149
match opt_trait.clone() {
150150
Some(opt_trait) => {
151151
self.cc.check_implementation(item, &[opt_trait]);
@@ -325,7 +325,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
325325
// Converts an implementation in the AST to a vector of items.
326326
fn create_impl_from_item(&self, item: &Item) -> Vec<ImplOrTraitItemId> {
327327
match item.node {
328-
ItemImpl(_, ref trait_refs, _, ref ast_items) => {
328+
ItemImpl(_, _, ref trait_refs, _, ref ast_items) => {
329329
let mut items: Vec<ImplOrTraitItemId> =
330330
ast_items.iter()
331331
.map(|ast_item| {

src/librustc_typeck/coherence/orphan.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> {
4444
fn visit_item(&mut self, item: &'v ast::Item) {
4545
let def_id = ast_util::local_def(item.id);
4646
match item.node {
47-
ast::ItemImpl(_, None, _, _) => {
47+
ast::ItemImpl(_, _, None, _, _) => {
4848
// For inherent impls, self type must be a nominal type
4949
// defined in this crate.
5050
debug!("coherence2::orphan check: inherent impl {}", item.repr(self.tcx));
@@ -64,7 +64,7 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for OrphanChecker<'cx, 'tcx> {
6464
}
6565
}
6666
}
67-
ast::ItemImpl(_, Some(_), _, _) => {
67+
ast::ItemImpl(_, _, Some(_), _, _) => {
6868
// "Trait" impl
6969
debug!("coherence2::orphan check: trait impl {}", item.repr(self.tcx));
7070
if traits::is_orphan_impl(self.tcx, def_id) {

src/librustc_typeck/collect.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,8 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
10451045
enum_definition.variants.as_slice(),
10461046
generics);
10471047
},
1048-
ast::ItemImpl(ref generics,
1048+
ast::ItemImpl(_,
1049+
ref generics,
10491050
ref opt_trait_ref,
10501051
ref selfty,
10511052
ref impl_items) => {

src/librustdoc/doctree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ pub struct Trait {
184184
}
185185

186186
pub struct Impl {
187+
pub unsafety: ast::Unsafety,
187188
pub generics: ast::Generics,
188189
pub trait_: Option<ast::TraitRef>,
189190
pub for_: P<ast::Ty>,

src/librustdoc/visit_ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
338338
};
339339
om.traits.push(t);
340340
},
341-
ast::ItemImpl(ref gen, ref tr, ref ty, ref items) => {
341+
ast::ItemImpl(unsafety, ref gen, ref tr, ref ty, ref items) => {
342342
let i = Impl {
343+
unsafety: unsafety,
343344
generics: gen.clone(),
344345
trait_: tr.clone(),
345346
for_: ty.clone(),

src/libsyntax/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,8 @@ pub enum Item_ {
16171617
// Currently, only Sized makes sense here.
16181618
TyParamBounds,
16191619
Vec<TraitItem>),
1620-
ItemImpl(Generics,
1620+
ItemImpl(Unsafety,
1621+
Generics,
16211622
Option<TraitRef>, // (optional) trait this impl implements
16221623
P<Ty>, // self
16231624
Vec<ImplItem>),

src/libsyntax/ast_map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
755755
let parent = self.parent;
756756
self.parent = i.id;
757757
match i.node {
758-
ItemImpl(_, _, _, ref impl_items) => {
758+
ItemImpl(_, _, _, _, ref impl_items) => {
759759
for impl_item in impl_items.iter() {
760760
match *impl_item {
761761
MethodImplItem(ref m) => {

src/libsyntax/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ fn fold_item_underscore<F>(cx: &mut Context<F>, item: ast::Item_) -> ast::Item_
133133
F: FnMut(&[ast::Attribute]) -> bool
134134
{
135135
let item = match item {
136-
ast::ItemImpl(a, b, c, impl_items) => {
136+
ast::ItemImpl(u, a, b, c, impl_items) => {
137137
let impl_items = impl_items.into_iter()
138138
.filter(|ii| impl_item_in_cfg(cx, ii))
139139
.collect();
140-
ast::ItemImpl(a, b, c, impl_items)
140+
ast::ItemImpl(u, a, b, c, impl_items)
141141
}
142142
ast::ItemTrait(u, a, b, c, methods) => {
143143
let methods = methods.into_iter()

src/libsyntax/ext/deriving/generic/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ impl<'a> TraitDef<'a> {
462462
self.span,
463463
ident,
464464
a,
465-
ast::ItemImpl(trait_generics,
465+
ast::ItemImpl(ast::Unsafety::Normal,
466+
trait_generics,
466467
opt_trait_ref,
467468
self_type,
468469
methods.into_iter()

src/libsyntax/feature_gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
215215
}
216216
}
217217

218-
ast::ItemImpl(_, _, _, ref items) => {
218+
ast::ItemImpl(_, _, _, _, ref items) => {
219219
if attr::contains_name(i.attrs.as_slice(),
220220
"unsafe_destructor") {
221221
self.gate_feature("unsafe_destructor",

0 commit comments

Comments
 (0)