Skip to content

Commit ff174fe

Browse files
committed
rustc: rename hir::def::Def to Res (short for "resolution").
1 parent b92b1a7 commit ff174fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1337
-1339
lines changed

src/librustc/hir/def.rs

+58-58
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl DefKind {
128128
}
129129

130130
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
131-
pub enum Def<Id = hir::HirId> {
131+
pub enum Res<Id = hir::HirId> {
132132
Def(DefKind, DefId),
133133

134134
// Type namespace
@@ -152,38 +152,38 @@ pub enum Def<Id = hir::HirId> {
152152
}
153153

154154
/// The result of resolving a path before lowering to HIR.
155-
/// `base_def` is definition of resolved part of the
155+
/// `base_res` is the resolution of the resolved part of the
156156
/// path, `unresolved_segments` is the number of unresolved
157157
/// segments.
158158
///
159159
/// ```text
160160
/// module::Type::AssocX::AssocY::MethodOrAssocType
161161
/// ^~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162-
/// base_def unresolved_segments = 3
162+
/// base_res unresolved_segments = 3
163163
///
164164
/// <T as Trait>::AssocX::AssocY::MethodOrAssocType
165165
/// ^~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~
166-
/// base_def unresolved_segments = 2
166+
/// base_res unresolved_segments = 2
167167
/// ```
168168
#[derive(Copy, Clone, Debug)]
169169
pub struct PathResolution {
170-
base_def: Def<NodeId>,
170+
base_res: Res<NodeId>,
171171
unresolved_segments: usize,
172172
}
173173

174174
impl PathResolution {
175-
pub fn new(def: Def<NodeId>) -> Self {
176-
PathResolution { base_def: def, unresolved_segments: 0 }
175+
pub fn new(res: Res<NodeId>) -> Self {
176+
PathResolution { base_res: res, unresolved_segments: 0 }
177177
}
178178

179-
pub fn with_unresolved_segments(def: Def<NodeId>, mut unresolved_segments: usize) -> Self {
180-
if def == Def::Err { unresolved_segments = 0 }
181-
PathResolution { base_def: def, unresolved_segments: unresolved_segments }
179+
pub fn with_unresolved_segments(res: Res<NodeId>, mut unresolved_segments: usize) -> Self {
180+
if res == Res::Err { unresolved_segments = 0 }
181+
PathResolution { base_res: res, unresolved_segments: unresolved_segments }
182182
}
183183

184184
#[inline]
185-
pub fn base_def(&self) -> Def<NodeId> {
186-
self.base_def
185+
pub fn base_res(&self) -> Res<NodeId> {
186+
self.base_res
187187
}
188188

189189
#[inline]
@@ -270,7 +270,7 @@ impl<T> PerNS<Option<T>> {
270270
}
271271

272272
/// Definition mapping
273-
pub type DefMap = NodeMap<PathResolution>;
273+
pub type ResMap = NodeMap<PathResolution>;
274274

275275
/// This is the replacement export map. It maps a module to all of the exports
276276
/// within.
@@ -284,9 +284,9 @@ pub type ImportMap = NodeMap<PerNS<Option<PathResolution>>>;
284284
pub struct Export<Id> {
285285
/// The name of the target.
286286
pub ident: ast::Ident,
287-
/// The definition of the target.
288-
pub def: Def<Id>,
289-
/// The span of the target definition.
287+
/// The resolution of the target.
288+
pub res: Res<Id>,
289+
/// The span of the target.
290290
pub span: Span,
291291
/// The visibility of the export.
292292
/// We include non-`pub` exports for hygienic macros that get used from extern crates.
@@ -297,7 +297,7 @@ impl<Id> Export<Id> {
297297
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Export<R> {
298298
Export {
299299
ident: self.ident,
300-
def: self.def.map_id(map),
300+
res: self.res.map_id(map),
301301
span: self.span,
302302
vis: self.vis,
303303
}
@@ -334,85 +334,85 @@ impl NonMacroAttrKind {
334334
}
335335
}
336336

337-
impl<Id> Def<Id> {
337+
impl<Id> Res<Id> {
338338
/// Return the `DefId` of this `Def` if it has an id, else panic.
339339
pub fn def_id(&self) -> DefId
340340
where
341341
Id: Debug,
342342
{
343343
self.opt_def_id().unwrap_or_else(|| {
344-
bug!("attempted .def_id() on invalid def: {:?}", self)
344+
bug!("attempted .def_id() on invalid res: {:?}", self)
345345
})
346346
}
347347

348-
/// Return `Some(..)` with the `DefId` of this `Def` if it has a id, else `None`.
348+
/// Return `Some(..)` with the `DefId` of this `Res` if it has a id, else `None`.
349349
pub fn opt_def_id(&self) -> Option<DefId> {
350350
match *self {
351-
Def::Def(_, id) => Some(id),
352-
353-
Def::Local(..) |
354-
Def::Upvar(..) |
355-
Def::Label(..) |
356-
Def::PrimTy(..) |
357-
Def::SelfTy(..) |
358-
Def::SelfCtor(..) |
359-
Def::ToolMod |
360-
Def::NonMacroAttr(..) |
361-
Def::Err => {
351+
Res::Def(_, id) => Some(id),
352+
353+
Res::Local(..) |
354+
Res::Upvar(..) |
355+
Res::Label(..) |
356+
Res::PrimTy(..) |
357+
Res::SelfTy(..) |
358+
Res::SelfCtor(..) |
359+
Res::ToolMod |
360+
Res::NonMacroAttr(..) |
361+
Res::Err => {
362362
None
363363
}
364364
}
365365
}
366366

367-
/// Return the `DefId` of this `Def` if it represents a module.
367+
/// Return the `DefId` of this `Res` if it represents a module.
368368
pub fn mod_def_id(&self) -> Option<DefId> {
369369
match *self {
370-
Def::Def(DefKind::Mod, id) => Some(id),
370+
Res::Def(DefKind::Mod, id) => Some(id),
371371
_ => None,
372372
}
373373
}
374374

375-
/// A human readable name for the def kind ("function", "module", etc.).
375+
/// A human readable name for the res kind ("function", "module", etc.).
376376
pub fn kind_name(&self) -> &'static str {
377377
match *self {
378-
Def::Def(kind, _) => kind.descr(),
379-
Def::SelfCtor(..) => "self constructor",
380-
Def::PrimTy(..) => "builtin type",
381-
Def::Local(..) => "local variable",
382-
Def::Upvar(..) => "closure capture",
383-
Def::Label(..) => "label",
384-
Def::SelfTy(..) => "self type",
385-
Def::ToolMod => "tool module",
386-
Def::NonMacroAttr(attr_kind) => attr_kind.descr(),
387-
Def::Err => "unresolved item",
378+
Res::Def(kind, _) => kind.descr(),
379+
Res::SelfCtor(..) => "self constructor",
380+
Res::PrimTy(..) => "builtin type",
381+
Res::Local(..) => "local variable",
382+
Res::Upvar(..) => "closure capture",
383+
Res::Label(..) => "label",
384+
Res::SelfTy(..) => "self type",
385+
Res::ToolMod => "tool module",
386+
Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
387+
Res::Err => "unresolved item",
388388
}
389389
}
390390

391-
/// An English article for the def.
391+
/// An English article for the res.
392392
pub fn article(&self) -> &'static str {
393393
match *self {
394-
Def::Def(kind, _) => kind.article(),
395-
Def::Err => "an",
394+
Res::Def(kind, _) => kind.article(),
395+
Res::Err => "an",
396396
_ => "a",
397397
}
398398
}
399399

400-
pub fn map_id<R>(self, mut map: impl FnMut(Id) -> R) -> Def<R> {
400+
pub fn map_id<R>(self, mut map: impl FnMut(Id) -> R) -> Res<R> {
401401
match self {
402-
Def::Def(kind, id) => Def::Def(kind, id),
403-
Def::SelfCtor(id) => Def::SelfCtor(id),
404-
Def::PrimTy(id) => Def::PrimTy(id),
405-
Def::Local(id) => Def::Local(map(id)),
406-
Def::Upvar(id, index, closure) => Def::Upvar(
402+
Res::Def(kind, id) => Res::Def(kind, id),
403+
Res::SelfCtor(id) => Res::SelfCtor(id),
404+
Res::PrimTy(id) => Res::PrimTy(id),
405+
Res::Local(id) => Res::Local(map(id)),
406+
Res::Upvar(id, index, closure) => Res::Upvar(
407407
map(id),
408408
index,
409409
closure
410410
),
411-
Def::Label(id) => Def::Label(id),
412-
Def::SelfTy(a, b) => Def::SelfTy(a, b),
413-
Def::ToolMod => Def::ToolMod,
414-
Def::NonMacroAttr(attr_kind) => Def::NonMacroAttr(attr_kind),
415-
Def::Err => Def::Err,
411+
Res::Label(id) => Res::Label(id),
412+
Res::SelfTy(a, b) => Res::SelfTy(a, b),
413+
Res::ToolMod => Res::ToolMod,
414+
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
415+
Res::Err => Res::Err,
416416
}
417417
}
418418
}

0 commit comments

Comments
 (0)