Skip to content

Commit 3b1399d

Browse files
committed
Make calling def_id on a DefSelfTy an error; the previous defids that
were returned, either the trait or the *self type itself*, were not particularly representative of what the Def is (a type parameter). Rewrite paths to handle this case specially, just as they handle the primitive case specifically. This entire `def_id` codepath is kind of a mess.
1 parent 95ce1eb commit 3b1399d

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

src/librustc/middle/dead.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
9999
}
100100
_ if self.ignore_non_const_paths => (),
101101
def::DefPrimTy(_) => (),
102+
def::DefSelfTy(..) => (),
102103
def::DefVariant(enum_id, variant_id, _) => {
103104
self.check_def_id(enum_id);
104105
if !self.ignore_variant_stack.contains(&variant_id) {

src/librustc/middle/def.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,12 @@ impl Def {
135135
DefFn(id, _) | DefMod(id) | DefForeignMod(id) | DefStatic(id, _) |
136136
DefVariant(_, id, _) | DefTy(id, _) | DefAssociatedTy(_, id) |
137137
DefTyParam(_, _, id, _) | DefUse(id) | DefStruct(id) | DefTrait(id) |
138-
DefMethod(id) | DefConst(id) | DefAssociatedConst(id) |
139-
DefSelfTy(Some(id), None)=> {
138+
DefMethod(id) | DefConst(id) | DefAssociatedConst(id) => {
140139
id
141140
}
142141

143142
DefLocal(id) |
144-
DefUpvar(id, _, _) |
145-
DefSelfTy(_, Some((_, id))) => {
143+
DefUpvar(id, _, _) => {
146144
DefId::xxx_local(id) // TODO, clearly
147145
}
148146

src/librustc/middle/stability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ pub fn check_path(tcx: &ty::ctxt, path: &hir::Path, id: ast::NodeId,
474474
cb: &mut FnMut(DefId, Span, &Option<&Stability>)) {
475475
match tcx.def_map.borrow().get(&id).map(|d| d.full_def()) {
476476
Some(def::DefPrimTy(..)) => {}
477+
Some(def::DefSelfTy(..)) => {}
477478
Some(def) => {
478479
maybe_do_stability_check(tcx, def.def_id(), path.span, cb);
479480
}

src/librustc_privacy/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
263263
hir::TyPath(..) => {
264264
match self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def() {
265265
def::DefPrimTy(..) => true,
266+
def::DefSelfTy(..) => true,
266267
def => {
267268
let did = def.def_id();
268269
if let Some(node_id) = self.tcx.map.as_local_node_id(did) {
@@ -337,7 +338,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
337338
hir::ItemTy(ref ty, _) if public_first => {
338339
if let hir::TyPath(..) = ty.node {
339340
match self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def() {
340-
def::DefPrimTy(..) | def::DefTyParam(..) => {},
341+
def::DefPrimTy(..) | def::DefSelfTy(..) | def::DefTyParam(..) => {},
341342
def => {
342343
let did = def.def_id();
343344
if let Some(node_id) = self.tcx.map.as_local_node_id(did) {
@@ -1148,7 +1149,7 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
11481149
fn path_is_private_type(&self, path_id: ast::NodeId) -> bool {
11491150
let did = match self.tcx.def_map.borrow().get(&path_id).map(|d| d.full_def()) {
11501151
// `int` etc. (None doesn't seem to occur.)
1151-
None | Some(def::DefPrimTy(..)) => return false,
1152+
None | Some(def::DefPrimTy(..)) | Some(def::DefSelfTy(..)) => return false,
11521153
Some(def) => def.def_id(),
11531154
};
11541155

src/librustc_trans/save/dump_csv.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
235235
}
236236
let def = self.tcx.def_map.borrow().get(&ref_id).unwrap().full_def();
237237
match def {
238-
def::DefPrimTy(_) => None,
238+
def::DefPrimTy(..) => None,
239+
def::DefSelfTy(..) => None,
239240
_ => Some(def.def_id()),
240241
}
241242
}

src/librustc_trans/save/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
637637
}
638638
let def = self.tcx.def_map.borrow().get(&ref_id).unwrap().full_def();
639639
match def {
640-
def::DefPrimTy(_) => None,
640+
def::DefPrimTy(_) | def::DefSelfTy(..) => None,
641641
_ => Some(def.def_id()),
642642
}
643643
}

src/librustdoc/clean/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2570,17 +2570,19 @@ fn name_from_pat(p: &hir::Pat) -> String {
25702570
fn resolve_type(cx: &DocContext,
25712571
path: Path,
25722572
id: ast::NodeId) -> Type {
2573+
debug!("resolve_type({:?},{:?})", path, id);
25732574
let tcx = match cx.tcx_opt() {
25742575
Some(tcx) => tcx,
25752576
// If we're extracting tests, this return value doesn't matter.
25762577
None => return Primitive(Bool),
25772578
};
2578-
debug!("searching for {} in defmap", id);
25792579
let def = match tcx.def_map.borrow().get(&id) {
25802580
Some(k) => k.full_def(),
25812581
None => panic!("unresolved id not in defmap")
25822582
};
25832583

2584+
debug!("resolve_type: def={:?}", def);
2585+
25842586
let is_generic = match def {
25852587
def::DefPrimTy(p) => match p {
25862588
hir::TyStr => return Primitive(Str),
@@ -2610,6 +2612,8 @@ fn resolve_type(cx: &DocContext,
26102612
}
26112613

26122614
fn register_def(cx: &DocContext, def: def::Def) -> DefId {
2615+
debug!("register_def({:?})", def);
2616+
26132617
let (did, kind) = match def {
26142618
def::DefFn(i, _) => (i, TypeFunction),
26152619
def::DefTy(i, false) => (i, TypeTypedef),
@@ -2619,6 +2623,8 @@ fn register_def(cx: &DocContext, def: def::Def) -> DefId {
26192623
def::DefMod(i) => (i, TypeModule),
26202624
def::DefStatic(i, _) => (i, TypeStatic),
26212625
def::DefVariant(i, _, _) => (i, TypeEnum),
2626+
def::DefSelfTy(Some(def_id), _) => (def_id, TypeTrait),
2627+
def::DefSelfTy(_, Some((impl_id, _))) => return cx.map.local_def_id(impl_id),
26222628
_ => return def.def_id()
26232629
};
26242630
if did.is_local() { return did }

0 commit comments

Comments
 (0)