rustc: rename hir::def::Def to Res (short for "resolution").

This commit is contained in:
Eduard-Mihai Burtescu 2019-04-20 19:36:05 +03:00
parent b92b1a76e1
commit ff174fe09e
51 changed files with 1334 additions and 1336 deletions

View file

@ -128,7 +128,7 @@ impl DefKind {
}
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
pub enum Def<Id = hir::HirId> {
pub enum Res<Id = hir::HirId> {
Def(DefKind, DefId),
// Type namespace
@ -152,38 +152,38 @@ pub enum Def<Id = hir::HirId> {
}
/// The result of resolving a path before lowering to HIR.
/// `base_def` is definition of resolved part of the
/// `base_res` is the resolution of the resolved part of the
/// path, `unresolved_segments` is the number of unresolved
/// segments.
///
/// ```text
/// module::Type::AssocX::AssocY::MethodOrAssocType
/// ^~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// base_def unresolved_segments = 3
/// base_res unresolved_segments = 3
///
/// <T as Trait>::AssocX::AssocY::MethodOrAssocType
/// ^~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~
/// base_def unresolved_segments = 2
/// base_res unresolved_segments = 2
/// ```
#[derive(Copy, Clone, Debug)]
pub struct PathResolution {
base_def: Def<NodeId>,
base_res: Res<NodeId>,
unresolved_segments: usize,
}
impl PathResolution {
pub fn new(def: Def<NodeId>) -> Self {
PathResolution { base_def: def, unresolved_segments: 0 }
pub fn new(res: Res<NodeId>) -> Self {
PathResolution { base_res: res, unresolved_segments: 0 }
}
pub fn with_unresolved_segments(def: Def<NodeId>, mut unresolved_segments: usize) -> Self {
if def == Def::Err { unresolved_segments = 0 }
PathResolution { base_def: def, unresolved_segments: unresolved_segments }
pub fn with_unresolved_segments(res: Res<NodeId>, mut unresolved_segments: usize) -> Self {
if res == Res::Err { unresolved_segments = 0 }
PathResolution { base_res: res, unresolved_segments: unresolved_segments }
}
#[inline]
pub fn base_def(&self) -> Def<NodeId> {
self.base_def
pub fn base_res(&self) -> Res<NodeId> {
self.base_res
}
#[inline]
@ -270,7 +270,7 @@ impl<T> PerNS<Option<T>> {
}
/// Definition mapping
pub type DefMap = NodeMap<PathResolution>;
pub type ResMap = NodeMap<PathResolution>;
/// This is the replacement export map. It maps a module to all of the exports
/// within.
@ -284,9 +284,9 @@ pub type ImportMap = NodeMap<PerNS<Option<PathResolution>>>;
pub struct Export<Id> {
/// The name of the target.
pub ident: ast::Ident,
/// The definition of the target.
pub def: Def<Id>,
/// The span of the target definition.
/// The resolution of the target.
pub res: Res<Id>,
/// The span of the target.
pub span: Span,
/// The visibility of the export.
/// We include non-`pub` exports for hygienic macros that get used from extern crates.
@ -297,7 +297,7 @@ impl<Id> Export<Id> {
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Export<R> {
Export {
ident: self.ident,
def: self.def.map_id(map),
res: self.res.map_id(map),
span: self.span,
vis: self.vis,
}
@ -334,85 +334,85 @@ impl NonMacroAttrKind {
}
}
impl<Id> Def<Id> {
impl<Id> Res<Id> {
/// Return the `DefId` of this `Def` if it has an id, else panic.
pub fn def_id(&self) -> DefId
where
Id: Debug,
{
self.opt_def_id().unwrap_or_else(|| {
bug!("attempted .def_id() on invalid def: {:?}", self)
bug!("attempted .def_id() on invalid res: {:?}", self)
})
}
/// Return `Some(..)` with the `DefId` of this `Def` if it has a id, else `None`.
/// Return `Some(..)` with the `DefId` of this `Res` if it has a id, else `None`.
pub fn opt_def_id(&self) -> Option<DefId> {
match *self {
Def::Def(_, id) => Some(id),
Res::Def(_, id) => Some(id),
Def::Local(..) |
Def::Upvar(..) |
Def::Label(..) |
Def::PrimTy(..) |
Def::SelfTy(..) |
Def::SelfCtor(..) |
Def::ToolMod |
Def::NonMacroAttr(..) |
Def::Err => {
Res::Local(..) |
Res::Upvar(..) |
Res::Label(..) |
Res::PrimTy(..) |
Res::SelfTy(..) |
Res::SelfCtor(..) |
Res::ToolMod |
Res::NonMacroAttr(..) |
Res::Err => {
None
}
}
}
/// Return the `DefId` of this `Def` if it represents a module.
/// Return the `DefId` of this `Res` if it represents a module.
pub fn mod_def_id(&self) -> Option<DefId> {
match *self {
Def::Def(DefKind::Mod, id) => Some(id),
Res::Def(DefKind::Mod, id) => Some(id),
_ => None,
}
}
/// A human readable name for the def kind ("function", "module", etc.).
/// A human readable name for the res kind ("function", "module", etc.).
pub fn kind_name(&self) -> &'static str {
match *self {
Def::Def(kind, _) => kind.descr(),
Def::SelfCtor(..) => "self constructor",
Def::PrimTy(..) => "builtin type",
Def::Local(..) => "local variable",
Def::Upvar(..) => "closure capture",
Def::Label(..) => "label",
Def::SelfTy(..) => "self type",
Def::ToolMod => "tool module",
Def::NonMacroAttr(attr_kind) => attr_kind.descr(),
Def::Err => "unresolved item",
Res::Def(kind, _) => kind.descr(),
Res::SelfCtor(..) => "self constructor",
Res::PrimTy(..) => "builtin type",
Res::Local(..) => "local variable",
Res::Upvar(..) => "closure capture",
Res::Label(..) => "label",
Res::SelfTy(..) => "self type",
Res::ToolMod => "tool module",
Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
Res::Err => "unresolved item",
}
}
/// An English article for the def.
/// An English article for the res.
pub fn article(&self) -> &'static str {
match *self {
Def::Def(kind, _) => kind.article(),
Def::Err => "an",
Res::Def(kind, _) => kind.article(),
Res::Err => "an",
_ => "a",
}
}
pub fn map_id<R>(self, mut map: impl FnMut(Id) -> R) -> Def<R> {
pub fn map_id<R>(self, mut map: impl FnMut(Id) -> R) -> Res<R> {
match self {
Def::Def(kind, id) => Def::Def(kind, id),
Def::SelfCtor(id) => Def::SelfCtor(id),
Def::PrimTy(id) => Def::PrimTy(id),
Def::Local(id) => Def::Local(map(id)),
Def::Upvar(id, index, closure) => Def::Upvar(
Res::Def(kind, id) => Res::Def(kind, id),
Res::SelfCtor(id) => Res::SelfCtor(id),
Res::PrimTy(id) => Res::PrimTy(id),
Res::Local(id) => Res::Local(map(id)),
Res::Upvar(id, index, closure) => Res::Upvar(
map(id),
index,
closure
),
Def::Label(id) => Def::Label(id),
Def::SelfTy(a, b) => Def::SelfTy(a, b),
Def::ToolMod => Def::ToolMod,
Def::NonMacroAttr(attr_kind) => Def::NonMacroAttr(attr_kind),
Def::Err => Def::Err,
Res::Label(id) => Res::Label(id),
Res::SelfTy(a, b) => Res::SelfTy(a, b),
Res::ToolMod => Res::ToolMod,
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
Res::Err => Res::Err,
}
}
}

View file

@ -37,7 +37,7 @@ use crate::hir::{self, ParamName};
use crate::hir::HirVec;
use crate::hir::map::{DefKey, DefPathData, Definitions};
use crate::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX};
use crate::hir::def::{Def, DefKind, PathResolution, PerNS};
use crate::hir::def::{Res, DefKind, PathResolution, PerNS};
use crate::hir::{GenericArg, ConstArg};
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
ELIDED_LIFETIMES_IN_PATHS};
@ -812,29 +812,29 @@ impl<'a> LoweringContext<'a> {
self.lower_node_id(self.sess.next_node_id())
}
fn lower_def(&mut self, def: Def<NodeId>) -> Def {
def.map_id(|id| {
fn lower_res(&mut self, res: Res<NodeId>) -> Res {
res.map_id(|id| {
self.lower_node_id_generic(id, |_| {
panic!("expected node_id to be lowered already for def {:#?}", def)
panic!("expected node_id to be lowered already for res {:#?}", res)
})
})
}
fn expect_full_def(&mut self, id: NodeId) -> Def<NodeId> {
self.resolver.get_resolution(id).map_or(Def::Err, |pr| {
fn expect_full_res(&mut self, id: NodeId) -> Res<NodeId> {
self.resolver.get_resolution(id).map_or(Res::Err, |pr| {
if pr.unresolved_segments() != 0 {
bug!("path not fully resolved: {:?}", pr);
}
pr.base_def()
pr.base_res()
})
}
fn expect_full_def_from_use(&mut self, id: NodeId) -> impl Iterator<Item = Def<NodeId>> {
fn expect_full_res_from_use(&mut self, id: NodeId) -> impl Iterator<Item = Res<NodeId>> {
self.resolver.get_import(id).present_items().map(|pr| {
if pr.unresolved_segments() != 0 {
bug!("path not fully resolved: {:?}", pr);
}
pr.base_def()
pr.base_res()
})
}
@ -1136,7 +1136,7 @@ impl<'a> LoweringContext<'a> {
output,
c_variadic: false
};
// Lower the arguments before the body otherwise the body will call `lower_def` expecting
// Lower the arguments before the body otherwise the body will call `lower_res` expecting
// the argument to have been assigned an id already.
let arguments = self.lower_args(Some(&decl));
let body_expr = body(self);
@ -1251,7 +1251,7 @@ impl<'a> LoweringContext<'a> {
fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination {
let target_id = match destination {
Some((id, _)) => {
if let Def::Label(loop_id) = self.expect_full_def(id) {
if let Res::Label(loop_id) = self.expect_full_res(id) {
Ok(self.lower_node_id(loop_id))
} else {
Err(hir::LoopIdError::UnresolvedLabel)
@ -1417,12 +1417,12 @@ impl<'a> LoweringContext<'a> {
return ty;
}
TyKind::ImplicitSelf => {
let def = self.expect_full_def(t.id);
let def = self.lower_def(def);
let res = self.expect_full_res(t.id);
let res = self.lower_res(res);
hir::TyKind::Path(hir::QPath::Resolved(
None,
P(hir::Path {
def,
res,
segments: hir_vec![hir::PathSegment::from_ident(
keywords::SelfUpper.ident()
)],
@ -1500,7 +1500,7 @@ impl<'a> LoweringContext<'a> {
None,
P(hir::Path {
span,
def: Def::Def(DefKind::TyParam, DefId::local(def_index)),
res: Res::Def(DefKind::TyParam, DefId::local(def_index)),
segments: hir_vec![hir::PathSegment::from_ident(ident)],
}),
))
@ -1844,11 +1844,11 @@ impl<'a> LoweringContext<'a> {
let resolution = self.resolver
.get_resolution(id)
.unwrap_or_else(|| PathResolution::new(Def::Err));
.unwrap_or_else(|| PathResolution::new(Res::Err));
let proj_start = p.segments.len() - resolution.unresolved_segments();
let path = P(hir::Path {
def: self.lower_def(resolution.base_def()),
res: self.lower_res(resolution.base_res()),
segments: p.segments[..proj_start]
.iter()
.enumerate()
@ -1869,43 +1869,43 @@ impl<'a> LoweringContext<'a> {
krate: def_id.krate,
index: this.def_key(def_id).parent.expect("missing parent"),
};
let type_def_id = match resolution.base_def() {
Def::Def(DefKind::AssociatedTy, def_id) if i + 2 == proj_start => {
let type_def_id = match resolution.base_res() {
Res::Def(DefKind::AssociatedTy, def_id) if i + 2 == proj_start => {
Some(parent_def_id(self, def_id))
}
Def::Def(DefKind::Variant, def_id) if i + 1 == proj_start => {
Res::Def(DefKind::Variant, def_id) if i + 1 == proj_start => {
Some(parent_def_id(self, def_id))
}
Def::Def(DefKind::Struct, def_id)
| Def::Def(DefKind::Union, def_id)
| Def::Def(DefKind::Enum, def_id)
| Def::Def(DefKind::TyAlias, def_id)
| Def::Def(DefKind::Trait, def_id) if i + 1 == proj_start =>
Res::Def(DefKind::Struct, def_id)
| Res::Def(DefKind::Union, def_id)
| Res::Def(DefKind::Enum, def_id)
| Res::Def(DefKind::TyAlias, def_id)
| Res::Def(DefKind::Trait, def_id) if i + 1 == proj_start =>
{
Some(def_id)
}
_ => None,
};
let parenthesized_generic_args = match resolution.base_def() {
let parenthesized_generic_args = match resolution.base_res() {
// `a::b::Trait(Args)`
Def::Def(DefKind::Trait, _)
Res::Def(DefKind::Trait, _)
if i + 1 == proj_start => ParenthesizedGenericArgs::Ok,
// `a::b::Trait(Args)::TraitItem`
Def::Def(DefKind::Method, _)
| Def::Def(DefKind::AssociatedConst, _)
| Def::Def(DefKind::AssociatedTy, _)
Res::Def(DefKind::Method, _)
| Res::Def(DefKind::AssociatedConst, _)
| Res::Def(DefKind::AssociatedTy, _)
if i + 2 == proj_start =>
{
ParenthesizedGenericArgs::Ok
}
// Avoid duplicated errors.
Def::Err => ParenthesizedGenericArgs::Ok,
Res::Err => ParenthesizedGenericArgs::Ok,
// An error
Def::Def(DefKind::Struct, _)
| Def::Def(DefKind::Enum, _)
| Def::Def(DefKind::Union, _)
| Def::Def(DefKind::TyAlias, _)
| Def::Def(DefKind::Variant, _) if i + 1 == proj_start =>
Res::Def(DefKind::Struct, _)
| Res::Def(DefKind::Enum, _)
| Res::Def(DefKind::Union, _)
| Res::Def(DefKind::TyAlias, _)
| Res::Def(DefKind::Variant, _) if i + 1 == proj_start =>
{
ParenthesizedGenericArgs::Err
}
@ -2000,13 +2000,13 @@ impl<'a> LoweringContext<'a> {
fn lower_path_extra(
&mut self,
def: Def,
res: Res,
p: &Path,
param_mode: ParamMode,
explicit_owner: Option<NodeId>,
) -> hir::Path {
hir::Path {
def,
res,
segments: p.segments
.iter()
.map(|segment| {
@ -2026,9 +2026,9 @@ impl<'a> LoweringContext<'a> {
}
fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> hir::Path {
let def = self.expect_full_def(id);
let def = self.lower_def(def);
self.lower_path_extra(def, p, param_mode, None)
let res = self.expect_full_res(id);
let res = self.lower_res(res);
self.lower_path_extra(res, p, param_mode, None)
}
fn lower_path_segment(
@ -2159,7 +2159,7 @@ impl<'a> LoweringContext<'a> {
}
}
let def = self.expect_full_def(segment.id);
let res = self.expect_full_res(segment.id);
let id = if let Some(owner) = explicit_owner {
self.lower_node_id_with_owner(segment.id, owner)
} else {
@ -2173,7 +2173,7 @@ impl<'a> LoweringContext<'a> {
hir::PathSegment::new(
segment.ident,
Some(id),
Some(self.lower_def(def)),
Some(self.lower_res(res)),
generic_args,
infer_types,
)
@ -2791,9 +2791,9 @@ impl<'a> LoweringContext<'a> {
if path.segments.len() == 1
&& bound_pred.bound_generic_params.is_empty() =>
{
if let Some(Def::Def(DefKind::TyParam, def_id)) = self.resolver
if let Some(Res::Def(DefKind::TyParam, def_id)) = self.resolver
.get_resolution(bound_pred.bounded_ty.id)
.map(|d| d.base_def())
.map(|d| d.base_res())
{
if let Some(node_id) =
self.resolver.definitions().as_local_node_id(def_id)
@ -3245,7 +3245,7 @@ impl<'a> LoweringContext<'a> {
});
if let Some(ref trait_ref) = trait_ref {
if let Def::Def(DefKind::Trait, def_id) = trait_ref.path.def {
if let Res::Def(DefKind::Trait, def_id) = trait_ref.path.res {
this.trait_impls.entry(def_id).or_default().push(
lowered_trait_impl_id);
}
@ -3342,17 +3342,17 @@ impl<'a> LoweringContext<'a> {
}
}
let mut defs = self.expect_full_def_from_use(id);
let mut resolutions = self.expect_full_res_from_use(id);
// We want to return *something* from this function, so hold onto the first item
// for later.
let ret_def = self.lower_def(defs.next().unwrap_or(Def::Err));
let ret_res = self.lower_res(resolutions.next().unwrap_or(Res::Err));
// Here, we are looping over namespaces, if they exist for the definition
// being imported. We only handle type and value namespaces because we
// won't be dealing with macros in the rest of the compiler.
// Essentially a single `use` which imports two names is desugared into
// two imports.
for (def, &new_node_id) in defs.zip([id1, id2].iter()) {
for (res, &new_node_id) in resolutions.zip([id1, id2].iter()) {
let vis = vis.clone();
let ident = ident.clone();
let mut path = path.clone();
@ -3363,9 +3363,9 @@ impl<'a> LoweringContext<'a> {
self.with_hir_id_owner(new_node_id, |this| {
let new_id = this.lower_node_id(new_node_id);
let def = this.lower_def(def);
let res = this.lower_res(res);
let path =
this.lower_path_extra(def, &path, ParamMode::Explicit, None);
this.lower_path_extra(res, &path, ParamMode::Explicit, None);
let item = hir::ItemKind::Use(P(path), hir::UseKind::Single);
let vis_kind = match vis.node {
hir::VisibilityKind::Public => hir::VisibilityKind::Public,
@ -3395,7 +3395,7 @@ impl<'a> LoweringContext<'a> {
}
let path =
P(self.lower_path_extra(ret_def, &path, ParamMode::Explicit, None));
P(self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None));
hir::ItemKind::Use(path, hir::UseKind::Single)
}
UseTreeKind::Glob => {
@ -3513,9 +3513,9 @@ impl<'a> LoweringContext<'a> {
}
}
let def = self.expect_full_def_from_use(id).next().unwrap_or(Def::Err);
let def = self.lower_def(def);
let path = P(self.lower_path_extra(def, &prefix, ParamMode::Explicit, None));
let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err);
let res = self.lower_res(res);
let path = P(self.lower_path_extra(res, &prefix, ParamMode::Explicit, None));
hir::ItemKind::Use(path, hir::UseKind::ListStem)
}
}
@ -3769,7 +3769,7 @@ impl<'a> LoweringContext<'a> {
},
UseTreeKind::Glob => {}
UseTreeKind::Simple(_, id1, id2) => {
for (_, &id) in self.expect_full_def_from_use(base_id)
for (_, &id) in self.expect_full_res_from_use(base_id)
.skip(1)
.zip([id1, id2].iter())
{
@ -3946,11 +3946,11 @@ impl<'a> LoweringContext<'a> {
let node = match p.node {
PatKind::Wild => hir::PatKind::Wild,
PatKind::Ident(ref binding_mode, ident, ref sub) => {
match self.resolver.get_resolution(p.id).map(|d| d.base_def()) {
match self.resolver.get_resolution(p.id).map(|d| d.base_res()) {
// `None` can occur in body-less function signatures
def @ None | def @ Some(Def::Local(_)) => {
let canonical_id = match def {
Some(Def::Local(id)) => id,
res @ None | res @ Some(Res::Local(_)) => {
let canonical_id = match res {
Some(Res::Local(id)) => id,
_ => p.id,
};
@ -3961,11 +3961,11 @@ impl<'a> LoweringContext<'a> {
sub.as_ref().map(|x| self.lower_pat(x)),
)
}
Some(def) => hir::PatKind::Path(hir::QPath::Resolved(
Some(res) => hir::PatKind::Path(hir::QPath::Resolved(
None,
P(hir::Path {
span: ident.span,
def: self.lower_def(def),
res: self.lower_res(res),
segments: hir_vec![hir::PathSegment::from_ident(ident)],
}),
)),
@ -4957,11 +4957,11 @@ impl<'a> LoweringContext<'a> {
} else {
self.lower_node_id(id)
};
let def = self.expect_full_def(id);
let def = self.lower_def(def);
let res = self.expect_full_res(id);
let res = self.lower_res(res);
hir::VisibilityKind::Restricted {
path: P(self.lower_path_extra(
def,
res,
path,
ParamMode::Explicit,
explicit_owner,
@ -5073,7 +5073,7 @@ impl<'a> LoweringContext<'a> {
None,
P(hir::Path {
span,
def: Def::Local(binding),
res: Res::Local(binding),
segments: hir_vec![hir::PathSegment::from_ident(ident)],
}),
));
@ -5279,8 +5279,8 @@ impl<'a> LoweringContext<'a> {
let node = match qpath {
hir::QPath::Resolved(None, path) => {
// Turn trait object paths into `TyKind::TraitObject` instead.
match path.def {
Def::Def(DefKind::Trait, _) | Def::Def(DefKind::TraitAlias, _) => {
match path.res {
Res::Def(DefKind::Trait, _) | Res::Def(DefKind::TraitAlias, _) => {
let principal = hir::PolyTraitRef {
bound_generic_params: hir::HirVec::new(),
trait_ref: hir::TraitRef {

View file

@ -10,7 +10,7 @@ pub use self::PrimTy::*;
pub use self::UnOp::*;
pub use self::UnsafeSource::*;
use crate::hir::def::{Def, DefKind};
use crate::hir::def::{Res, DefKind};
use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
use crate::util::nodemap::{NodeMap, FxHashSet};
use crate::mir::mono::Linkage;
@ -296,8 +296,8 @@ impl Lifetime {
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
pub struct Path {
pub span: Span,
/// The definition that the path resolved to.
pub def: Def,
/// The resolution for the path.
pub res: Res,
/// The segments in the path: the things separated by `::`.
pub segments: HirVec<PathSegment>,
}
@ -327,13 +327,13 @@ pub struct PathSegment {
/// The identifier portion of this path segment.
#[stable_hasher(project(name))]
pub ident: Ident,
// `id` and `def` are optional. We currently only use these in save-analysis,
// `id` and `res` are optional. We currently only use these in save-analysis,
// any path segments without these will not have save-analysis info and
// therefore will not have 'jump to def' in IDEs, but otherwise will not be
// affected. (In general, we don't bother to get the defs for synthesized
// segments, only for segments which have come from the AST).
pub hir_id: Option<HirId>,
pub def: Option<Def>,
pub res: Option<Res>,
/// Type/lifetime parameters attached to this path. They come in
/// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
@ -355,7 +355,7 @@ impl PathSegment {
PathSegment {
ident,
hir_id: None,
def: None,
res: None,
infer_types: true,
args: None,
}
@ -364,14 +364,14 @@ impl PathSegment {
pub fn new(
ident: Ident,
hir_id: Option<HirId>,
def: Option<Def>,
res: Option<Res>,
args: GenericArgs,
infer_types: bool,
) -> Self {
PathSegment {
ident,
hir_id,
def,
res,
infer_types,
args: if args.is_empty() {
None
@ -1393,11 +1393,11 @@ impl Expr {
pub fn is_place_expr(&self) -> bool {
match self.node {
ExprKind::Path(QPath::Resolved(_, ref path)) => {
match path.def {
Def::Local(..)
| Def::Upvar(..)
| Def::Def(DefKind::Static, _)
| Def::Err => true,
match path.res {
Res::Local(..)
| Res::Upvar(..)
| Res::Def(DefKind::Static, _)
| Res::Err => true,
_ => false,
}
}
@ -2142,7 +2142,7 @@ pub enum UseKind {
/// resolve maps each TraitRef's ref_id to its defining trait; that's all
/// that the ref_id is for. Note that ref_id's value is not the NodeId of the
/// trait being referred to but just a unique NodeId that serves as a key
/// within the DefMap.
/// within the ResMap.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct TraitRef {
pub path: Path,
@ -2154,10 +2154,10 @@ pub struct TraitRef {
impl TraitRef {
/// Gets the `DefId` of the referenced trait. It _must_ actually be a trait or trait alias.
pub fn trait_def_id(&self) -> DefId {
match self.path.def {
Def::Def(DefKind::Trait, did) => did,
Def::Def(DefKind::TraitAlias, did) => did,
Def::Err => {
match self.path.res {
Res::Def(DefKind::Trait, did) => did,
Res::Def(DefKind::TraitAlias, did) => did,
Res::Err => {
FatalError.raise();
}
_ => unreachable!(),
@ -2479,7 +2479,7 @@ impl ForeignItemKind {
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
pub struct Freevar<Id = HirId> {
/// The variable being accessed free.
pub def: def::Def<Id>,
pub res: Res<Id>,
// First span where it is accessed (there can be multiple).
pub span: Span
@ -2488,15 +2488,15 @@ pub struct Freevar<Id = HirId> {
impl<Id: fmt::Debug + Copy> Freevar<Id> {
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Freevar<R> {
Freevar {
def: self.def.map_id(map),
res: self.res.map_id(map),
span: self.span,
}
}
pub fn var_id(&self) -> Id {
match self.def {
Def::Local(id) | Def::Upvar(id, ..) => id,
_ => bug!("Freevar::var_id: bad def ({:?})", self.def)
match self.res {
Res::Local(id) | Res::Upvar(id, ..) => id,
_ => bug!("Freevar::var_id: bad res ({:?})", self.res)
}
}
}

View file

@ -1,4 +1,4 @@
use crate::hir::def::{CtorOf, Def, DefKind};
use crate::hir::def::{CtorOf, Res, DefKind};
use crate::hir::def_id::DefId;
use crate::hir::{self, HirId, PatKind};
use syntax::ast;
@ -54,8 +54,8 @@ impl hir::Pat {
PatKind::Path(hir::QPath::Resolved(_, ref path)) |
PatKind::TupleStruct(hir::QPath::Resolved(_, ref path), ..) |
PatKind::Struct(hir::QPath::Resolved(_, ref path), ..) => {
match path.def {
Def::Def(DefKind::Variant, _) => true,
match path.res {
Res::Def(DefKind::Variant, _) => true,
_ => false
}
}
@ -124,9 +124,9 @@ impl hir::Pat {
PatKind::Path(hir::QPath::Resolved(_, ref path)) |
PatKind::TupleStruct(hir::QPath::Resolved(_, ref path), ..) |
PatKind::Struct(hir::QPath::Resolved(_, ref path), ..) => {
match path.def {
Def::Def(DefKind::Variant, id) => variants.push(id),
Def::Def(DefKind::Ctor(CtorOf::Variant, ..), id) => variants.push(id),
match path.res {
Res::Def(DefKind::Variant, id) => variants.push(id),
Res::Def(DefKind::Ctor(CtorOf::Variant, ..), id) => variants.push(id),
_ => ()
}
}

View file

@ -170,8 +170,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment) -> bool {
if segment.ident.as_str() == "TyKind" {
if let Some(def) = segment.def {
if let Some(did) = def.opt_def_id() {
if let Some(res) = segment.res {
if let Some(did) = res.opt_def_id() {
return cx.match_def_path(did, &["rustc", "ty", "sty", "TyKind"]);
}
}
@ -184,7 +184,7 @@ fn is_ty_or_ty_ctxt(cx: &LateContext<'_, '_>, ty: &Ty) -> Option<String> {
match &ty.node {
TyKind::Path(qpath) => {
if let QPath::Resolved(_, path) = qpath {
let did = path.def.opt_def_id()?;
let did = path.res.opt_def_id()?;
if cx.match_def_path(did, &["rustc", "ty", "Ty"]) {
return Some(format!("Ty{}", gen_args(path.segments.last().unwrap())));
} else if cx.match_def_path(did, &["rustc", "ty", "context", "TyCtxt"]) {

View file

@ -7,7 +7,7 @@ use crate::hir::{self, PatKind, TyKind};
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
use crate::hir::itemlikevisit::ItemLikeVisitor;
use crate::hir::def::{CtorOf, Def, DefKind};
use crate::hir::def::{CtorOf, Res, DefKind};
use crate::hir::CodegenFnAttrFlags;
use crate::hir::def_id::{DefId, LOCAL_CRATE};
use crate::lint;
@ -68,17 +68,17 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}
}
fn handle_definition(&mut self, def: Def) {
match def {
Def::Def(DefKind::Const, _)
| Def::Def(DefKind::AssociatedConst, _)
| Def::Def(DefKind::TyAlias, _) => {
self.check_def_id(def.def_id());
fn handle_res(&mut self, res: Res) {
match res {
Res::Def(DefKind::Const, _)
| Res::Def(DefKind::AssociatedConst, _)
| Res::Def(DefKind::TyAlias, _) => {
self.check_def_id(res.def_id());
}
_ if self.in_pat => {},
Def::PrimTy(..) | Def::SelfTy(..) | Def::SelfCtor(..) |
Def::Local(..) | Def::Upvar(..) => {}
Def::Def(DefKind::Ctor(CtorOf::Variant, ..), ctor_def_id) => {
Res::PrimTy(..) | Res::SelfTy(..) | Res::SelfCtor(..) |
Res::Local(..) | Res::Upvar(..) => {}
Res::Def(DefKind::Ctor(CtorOf::Variant, ..), ctor_def_id) => {
let variant_id = self.tcx.parent(ctor_def_id).unwrap();
let enum_id = self.tcx.parent(variant_id).unwrap();
self.check_def_id(enum_id);
@ -86,16 +86,16 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
self.check_def_id(variant_id);
}
}
Def::Def(DefKind::Variant, variant_id) => {
Res::Def(DefKind::Variant, variant_id) => {
let enum_id = self.tcx.parent(variant_id).unwrap();
self.check_def_id(enum_id);
if !self.ignore_variant_stack.contains(&variant_id) {
self.check_def_id(variant_id);
}
}
Def::ToolMod | Def::NonMacroAttr(..) | Def::Err => {}
Res::ToolMod | Res::NonMacroAttr(..) | Res::Err => {}
_ => {
self.check_def_id(def.def_id());
self.check_def_id(res.def_id());
}
}
}
@ -119,10 +119,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}
}
fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, def: Def,
fn handle_field_pattern_match(&mut self, lhs: &hir::Pat, res: Res,
pats: &[source_map::Spanned<hir::FieldPat>]) {
let variant = match self.tables.node_type(lhs.hir_id).sty {
ty::Adt(adt, _) => adt.variant_of_def(def),
ty::Adt(adt, _) => adt.variant_of_res(res),
_ => span_bug!(lhs.span, "non-ADT in struct pattern")
};
for pat in pats {
@ -231,8 +231,8 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
match expr.node {
hir::ExprKind::Path(ref qpath @ hir::QPath::TypeRelative(..)) => {
let def = self.tables.qpath_def(qpath, expr.hir_id);
self.handle_definition(def);
let res = self.tables.qpath_res(qpath, expr.hir_id);
self.handle_res(res);
}
hir::ExprKind::MethodCall(..) => {
self.lookup_and_handle_method(expr.hir_id);
@ -270,11 +270,11 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
fn visit_pat(&mut self, pat: &'tcx hir::Pat) {
match pat.node {
PatKind::Struct(hir::QPath::Resolved(_, ref path), ref fields, _) => {
self.handle_field_pattern_match(pat, path.def, fields);
self.handle_field_pattern_match(pat, path.res, fields);
}
PatKind::Path(ref qpath @ hir::QPath::TypeRelative(..)) => {
let def = self.tables.qpath_def(qpath, pat.hir_id);
self.handle_definition(def);
let res = self.tables.qpath_res(qpath, pat.hir_id);
self.handle_res(res);
}
_ => ()
}
@ -285,7 +285,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
}
fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) {
self.handle_definition(path.def);
self.handle_res(path.res);
intravisit::walk_path(self, path);
}

View file

@ -9,7 +9,7 @@ pub use self::MatchMode::*;
use self::TrackMatchMode::*;
use self::OverloadedCallType::*;
use crate::hir::def::{CtorOf, Def, DefKind};
use crate::hir::def::{CtorOf, Res, DefKind};
use crate::hir::def_id::DefId;
use crate::infer::InferCtxt;
use crate::middle::mem_categorization as mc;
@ -862,8 +862,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
// Each match binding is effectively an assignment to the
// binding being produced.
let def = Def::Local(canonical_id);
if let Ok(ref binding_cmt) = mc.cat_def(pat.hir_id, pat.span, pat_ty, def) {
let def = Res::Local(canonical_id);
if let Ok(ref binding_cmt) = mc.cat_res(pat.hir_id, pat.span, pat_ty, def) {
delegate.mutate(pat.hir_id, pat.span, binding_cmt, MutateMode::Init);
}
@ -898,27 +898,27 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
PatKind::Struct(ref qpath, ..) => qpath,
_ => return
};
let def = mc.tables.qpath_def(qpath, pat.hir_id);
match def {
Def::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_did) => {
let res = mc.tables.qpath_res(qpath, pat.hir_id);
match res {
Res::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_did) => {
let variant_did = mc.tcx.parent(variant_ctor_did).unwrap();
let downcast_cmt = mc.cat_downcast_if_needed(pat, cmt_pat, variant_did);
debug!("variantctor downcast_cmt={:?} pat={:?}", downcast_cmt, pat);
delegate.matched_pat(pat, &downcast_cmt, match_mode);
}
Def::Def(DefKind::Variant, variant_did) => {
Res::Def(DefKind::Variant, variant_did) => {
let downcast_cmt = mc.cat_downcast_if_needed(pat, cmt_pat, variant_did);
debug!("variant downcast_cmt={:?} pat={:?}", downcast_cmt, pat);
delegate.matched_pat(pat, &downcast_cmt, match_mode);
}
Def::Def(DefKind::Struct, _)
| Def::Def(DefKind::Ctor(..), _)
| Def::Def(DefKind::Union, _)
| Def::Def(DefKind::TyAlias, _)
| Def::Def(DefKind::AssociatedTy, _)
| Def::SelfTy(..) => {
Res::Def(DefKind::Struct, _)
| Res::Def(DefKind::Ctor(..), _)
| Res::Def(DefKind::Union, _)
| Res::Def(DefKind::TyAlias, _)
| Res::Def(DefKind::AssociatedTy, _)
| Res::SelfTy(..) => {
debug!("struct cmt_pat={:?} pat={:?}", cmt_pat, pat);
delegate.matched_pat(pat, &cmt_pat, match_mode);
}
@ -972,7 +972,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
// caller's perspective
let var_hir_id = upvar.var_id();
let var_ty = self.mc.node_ty(var_hir_id)?;
self.mc.cat_def(closure_hir_id, closure_span, var_ty, upvar.def)
self.mc.cat_res(closure_hir_id, closure_span, var_ty, upvar.res)
}
}

View file

@ -1,4 +1,4 @@
use crate::hir::def::{Def, DefKind};
use crate::hir::def::{Res, DefKind};
use crate::hir::def_id::DefId;
use crate::ty::{self, Ty, TyCtxt};
use crate::ty::layout::{LayoutError, Pointer, SizeSkeleton, VariantIdx};
@ -152,12 +152,12 @@ impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
}
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
let def = if let hir::ExprKind::Path(ref qpath) = expr.node {
self.tables.qpath_def(qpath, expr.hir_id)
let res = if let hir::ExprKind::Path(ref qpath) = expr.node {
self.tables.qpath_res(qpath, expr.hir_id)
} else {
Def::Err
Res::Err
};
if let Def::Def(DefKind::Fn, did) = def {
if let Res::Def(DefKind::Fn, did) = res {
if self.def_id_is_transmute(did) {
let typ = self.tables.node_type(expr.hir_id);
let sig = typ.fn_sig(self.tcx);

View file

@ -467,8 +467,8 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
match expr.node {
// live nodes required for uses or definitions of variables:
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
debug!("expr {}: path that leads to {:?}", expr.hir_id, path.def);
if let Def::Local(..) = path.def {
debug!("expr {}: path that leads to {:?}", expr.hir_id, path.res);
if let Res::Local(..) = path.res {
ir.add_live_node_for_node(expr.hir_id, ExprNode(expr.span));
}
intravisit::walk_expr(ir, expr);
@ -485,7 +485,7 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
let mut call_caps = Vec::new();
ir.tcx.with_freevars(expr.hir_id, |freevars| {
call_caps.extend(freevars.iter().filter_map(|fv| {
if let Def::Local(rv) = fv.def {
if let Res::Local(rv) = fv.res {
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
Some(CaptureInfo { ln: fv_ln, var_hid: rv })
} else {
@ -1347,8 +1347,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn access_path(&mut self, hir_id: HirId, path: &hir::Path, succ: LiveNode, acc: u32)
-> LiveNode {
match path.def {
Def::Local(hid) => {
match path.res {
Res::Local(hid) => {
let nid = self.ir.tcx.hir().hir_to_node_id(hid);
self.access_var(hir_id, nid, succ, acc, path.span)
}
@ -1541,7 +1541,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn check_place(&mut self, expr: &'tcx Expr) {
match expr.node {
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
if let Def::Local(var_hid) = path.def {
if let Res::Local(var_hid) = path.res {
// Assignment to an immutable variable or argument: only legal
// if there is no later assignment. If this local is actually
// mutable, then check for a reassignment to flag the mutability

View file

@ -62,7 +62,7 @@ use crate::middle::region;
use crate::hir::def_id::{DefId, LocalDefId};
use crate::hir::Node;
use crate::infer::InferCtxt;
use crate::hir::def::{CtorOf, Def, DefKind, CtorKind};
use crate::hir::def::{CtorOf, Res, DefKind, CtorKind};
use crate::ty::adjustment;
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
use crate::ty::fold::TypeFoldable;
@ -665,8 +665,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
}
hir::ExprKind::Path(ref qpath) => {
let def = self.tables.qpath_def(qpath, expr.hir_id);
self.cat_def(expr.hir_id, expr.span, expr_ty, def)
let res = self.tables.qpath_res(qpath, expr.hir_id);
self.cat_res(expr.hir_id, expr.span, expr_ty, res)
}
hir::ExprKind::Type(ref e, _) => {
@ -689,27 +689,27 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
}
}
pub fn cat_def(&self,
pub fn cat_res(&self,
hir_id: hir::HirId,
span: Span,
expr_ty: Ty<'tcx>,
def: Def)
res: Res)
-> McResult<cmt_<'tcx>> {
debug!("cat_def: id={:?} expr={:?} def={:?}",
hir_id, expr_ty, def);
debug!("cat_res: id={:?} expr={:?} def={:?}",
hir_id, expr_ty, res);
match def {
Def::Def(DefKind::Ctor(..), _)
| Def::Def(DefKind::Const, _)
| Def::Def(DefKind::ConstParam, _)
| Def::Def(DefKind::AssociatedConst, _)
| Def::Def(DefKind::Fn, _)
| Def::Def(DefKind::Method, _)
| Def::SelfCtor(..) => {
match res {
Res::Def(DefKind::Ctor(..), _)
| Res::Def(DefKind::Const, _)
| Res::Def(DefKind::ConstParam, _)
| Res::Def(DefKind::AssociatedConst, _)
| Res::Def(DefKind::Fn, _)
| Res::Def(DefKind::Method, _)
| Res::SelfCtor(..) => {
Ok(self.cat_rvalue_node(hir_id, span, expr_ty))
}
Def::Def(DefKind::Static, def_id) => {
Res::Def(DefKind::Static, def_id) => {
// `#[thread_local]` statics may not outlive the current function, but
// they also cannot be moved out of.
let is_thread_local = self.tcx.get_attrs(def_id)[..]
@ -736,12 +736,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
})
}
Def::Upvar(var_id, _, fn_node_id) => {
Res::Upvar(var_id, _, fn_node_id) => {
let var_nid = self.tcx.hir().hir_to_node_id(var_id);
self.cat_upvar(hir_id, span, var_nid, fn_node_id)
}
Def::Local(vid) => {
Res::Local(vid) => {
let vnid = self.tcx.hir().hir_to_node_id(vid);
Ok(cmt_ {
hir_id,
@ -1273,21 +1273,21 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
match pat.node {
PatKind::TupleStruct(ref qpath, ref subpats, ddpos) => {
let def = self.tables.qpath_def(qpath, pat.hir_id);
let (cmt, expected_len) = match def {
Def::Err => {
let res = self.tables.qpath_res(qpath, pat.hir_id);
let (cmt, expected_len) = match res {
Res::Err => {
debug!("access to unresolvable pattern {:?}", pat);
return Err(())
}
Def::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fn), variant_ctor_did) => {
Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fn), variant_ctor_did) => {
let variant_did = self.tcx.parent(variant_ctor_did).unwrap();
let enum_did = self.tcx.parent(variant_did).unwrap();
(self.cat_downcast_if_needed(pat, cmt, variant_did),
self.tcx.adt_def(enum_did)
.variant_with_ctor_id(variant_ctor_did).fields.len())
}
Def::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fn), _)
| Def::SelfCtor(..) => {
Res::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fn), _)
| Res::SelfCtor(..) => {
let ty = self.pat_ty_unadjusted(&pat)?;
match ty.sty {
ty::Adt(adt_def, _) => {
@ -1316,17 +1316,17 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
PatKind::Struct(ref qpath, ref field_pats, _) => {
// {f1: p1, ..., fN: pN}
let def = self.tables.qpath_def(qpath, pat.hir_id);
let cmt = match def {
Def::Err => {
let res = self.tables.qpath_res(qpath, pat.hir_id);
let cmt = match res {
Res::Err => {
debug!("access to unresolvable pattern {:?}", pat);
return Err(())
}
Def::Def(DefKind::Ctor(CtorOf::Variant, _), variant_ctor_did) => {
Res::Def(DefKind::Ctor(CtorOf::Variant, _), variant_ctor_did) => {
let variant_did = self.tcx.parent(variant_ctor_did).unwrap();
self.cat_downcast_if_needed(pat, cmt, variant_did)
}
Def::Def(DefKind::Variant, variant_did) => {
Res::Def(DefKind::Variant, variant_did) => {
self.cat_downcast_if_needed(pat, cmt, variant_did)
}
_ => cmt,

View file

@ -7,7 +7,7 @@
use crate::hir::{CodegenFnAttrs, CodegenFnAttrFlags};
use crate::hir::Node;
use crate::hir::def::{Def, DefKind};
use crate::hir::def::{Res, DefKind};
use crate::hir::def_id::{DefId, CrateNum};
use rustc_data_structures::sync::Lrc;
use crate::ty::{self, TyCtxt};
@ -92,33 +92,33 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
}
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
let def = match expr.node {
let res = match expr.node {
hir::ExprKind::Path(ref qpath) => {
Some(self.tables.qpath_def(qpath, expr.hir_id))
Some(self.tables.qpath_res(qpath, expr.hir_id))
}
hir::ExprKind::MethodCall(..) => {
self.tables.type_dependent_def(expr.hir_id)
.map(|(kind, def_id)| Def::Def(kind, def_id))
.map(|(kind, def_id)| Res::Def(kind, def_id))
}
_ => None
};
match def {
Some(Def::Local(hir_id)) | Some(Def::Upvar(hir_id, ..)) => {
match res {
Some(Res::Local(hir_id)) | Some(Res::Upvar(hir_id, ..)) => {
self.reachable_symbols.insert(hir_id);
}
Some(def) => {
if let Some((hir_id, def_id)) = def.opt_def_id().and_then(|def_id| {
Some(res) => {
if let Some((hir_id, def_id)) = res.opt_def_id().and_then(|def_id| {
self.tcx.hir().as_local_hir_id(def_id).map(|hir_id| (hir_id, def_id))
}) {
if self.def_id_represents_local_inlined_item(def_id) {
self.worklist.push(hir_id);
} else {
match def {
match res {
// If this path leads to a constant, then we need to
// recurse into the constant to continue finding
// items that are reachable.
Def::Def(DefKind::Const, _) | Def::Def(DefKind::AssociatedConst, _) => {
Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssociatedConst, _) => {
self.worklist.push(hir_id);
}
@ -357,8 +357,8 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
if !self.access_levels.is_reachable(item.hir_id) {
self.worklist.extend(impl_item_refs.iter().map(|ii_ref| ii_ref.id.hir_id));
let trait_def_id = match trait_ref.path.def {
Def::Def(DefKind::Trait, def_id) => def_id,
let trait_def_id = match trait_ref.path.res {
Res::Def(DefKind::Trait, def_id) => def_id,
_ => unreachable!()
};

View file

@ -5,7 +5,7 @@
//! used between functions, and they operate in a purely top-down
//! way. Therefore, we break lifetime name resolution into a separate pass.
use crate::hir::def::{Def, DefKind};
use crate::hir::def::{Res, DefKind};
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use crate::hir::map::Map;
use crate::hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName};
@ -925,7 +925,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
for (i, segment) in path.segments.iter().enumerate() {
let depth = path.segments.len() - i - 1;
if let Some(ref args) = segment.args {
self.visit_segment_args(path.def, depth, args);
self.visit_segment_args(path.res, depth, args);
}
}
}
@ -1360,12 +1360,12 @@ fn object_lifetime_defaults_for_item(
continue;
}
let def = match data.bounded_ty.node {
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => path.def,
let res = match data.bounded_ty.node {
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => path.res,
_ => continue,
};
if def == Def::Def(DefKind::TyParam, param_def_id) {
if res == Res::Def(DefKind::TyParam, param_def_id) {
add_bounds(&mut set, &data.bounds);
}
}
@ -1890,7 +1890,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
}
fn visit_segment_args(&mut self, def: Def, depth: usize, generic_args: &'tcx hir::GenericArgs) {
fn visit_segment_args(&mut self, res: Res, depth: usize, generic_args: &'tcx hir::GenericArgs) {
if generic_args.parenthesized {
let was_in_fn_syntax = self.is_in_fn_syntax;
self.is_in_fn_syntax = true;
@ -1928,16 +1928,16 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
index: def_key.parent.expect("missing parent"),
}
};
let type_def_id = match def {
Def::Def(DefKind::AssociatedTy, def_id)
let type_def_id = match res {
Res::Def(DefKind::AssociatedTy, def_id)
if depth == 1 => Some(parent_def_id(self, def_id)),
Def::Def(DefKind::Variant, def_id)
Res::Def(DefKind::Variant, def_id)
if depth == 0 => Some(parent_def_id(self, def_id)),
Def::Def(DefKind::Struct, def_id)
| Def::Def(DefKind::Union, def_id)
| Def::Def(DefKind::Enum, def_id)
| Def::Def(DefKind::TyAlias, def_id)
| Def::Def(DefKind::Trait, def_id) if depth == 0 =>
Res::Def(DefKind::Struct, def_id)
| Res::Def(DefKind::Union, def_id)
| Res::Def(DefKind::Enum, def_id)
| Res::Def(DefKind::TyAlias, def_id)
| Res::Def(DefKind::Trait, def_id) if depth == 0 =>
{
Some(def_id)
}
@ -2128,8 +2128,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
if has_self {
// Look for `self: &'a Self` - also desugared from `&'a self`,
// and if that matches, use it for elision and return early.
let is_self_ty = |def: Def| {
if let Def::SelfTy(..) = def {
let is_self_ty = |res: Res| {
if let Res::SelfTy(..) = res {
return true;
}
@ -2137,15 +2137,15 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
// to the way elision rules were originally specified.
let impl_self = impl_self.map(|ty| &ty.node);
if let Some(&hir::TyKind::Path(hir::QPath::Resolved(None, ref path))) = impl_self {
match path.def {
match path.res {
// Whitelist the types that unambiguously always
// result in the same type constructor being used
// (it can't differ between `Self` and `self`).
Def::Def(DefKind::Struct, _)
| Def::Def(DefKind::Union, _)
| Def::Def(DefKind::Enum, _)
| Def::PrimTy(_) => {
return def == path.def
Res::Def(DefKind::Struct, _)
| Res::Def(DefKind::Union, _)
| Res::Def(DefKind::Enum, _)
| Res::PrimTy(_) => {
return res == path.res
}
_ => {}
}
@ -2156,7 +2156,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
if let hir::TyKind::Rptr(lifetime_ref, ref mt) = inputs[0].node {
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = mt.ty.node {
if is_self_ty(path.def) {
if is_self_ty(path.res) {
if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.hir_id) {
let scope = Scope::Elision {
elide: Elide::Exact(lifetime),

View file

@ -5,7 +5,7 @@ pub use self::StabilityLevel::*;
use crate::lint::{self, Lint, in_derive_expansion};
use crate::hir::{self, Item, Generics, StructField, Variant, HirId};
use crate::hir::def::{Def, DefKind};
use crate::hir::def::{Res, DefKind};
use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
use crate::ty::query::Providers;
@ -779,7 +779,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
// individually as it's possible to have a stable trait with unstable
// items.
hir::ItemKind::Impl(.., Some(ref t), _, ref impl_item_refs) => {
if let Def::Def(DefKind::Trait, trait_did) = t.path.def {
if let Res::Def(DefKind::Trait, trait_did) = t.path.res {
for impl_item_ref in impl_item_refs {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
let trait_item_def_id = self.tcx.associated_items(trait_did)
@ -820,7 +820,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
}
fn visit_path(&mut self, path: &'tcx hir::Path, id: hir::HirId) {
if let Some(def_id) = path.def.opt_def_id() {
if let Some(def_id) = path.res.opt_def_id() {
self.tcx.check_stability(def_id, Some(id), path.span)
}
intravisit::walk_path(self, path)

View file

@ -10,7 +10,7 @@ use crate::session::config::{BorrowckMode, OutputFilenames};
use crate::session::config::CrateType;
use crate::middle;
use crate::hir::{TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
use crate::hir::def::{Def, DefKind, Export};
use crate::hir::def::{Res, DefKind, Export};
use crate::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
use crate::hir::map as hir_map;
use crate::hir::map::DefPathHash;
@ -479,11 +479,11 @@ impl<'tcx> TypeckTables<'tcx> {
}
/// Returns the final resolution of a `QPath` in an `Expr` or `Pat` node.
pub fn qpath_def(&self, qpath: &hir::QPath, id: hir::HirId) -> Def {
pub fn qpath_res(&self, qpath: &hir::QPath, id: hir::HirId) -> Res {
match *qpath {
hir::QPath::Resolved(_, ref path) => path.def,
hir::QPath::Resolved(_, ref path) => path.res,
hir::QPath::TypeRelative(..) => self.type_dependent_def(id)
.map_or(Def::Err, |(kind, def_id)| Def::Def(kind, def_id)),
.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)),
}
}

View file

@ -10,7 +10,7 @@ pub use self::fold::TypeFoldable;
use crate::hir::{map as hir_map, FreevarMap, GlobMap, TraitMap};
use crate::hir::{HirId, Node};
use crate::hir::def::{Def, DefKind, CtorOf, CtorKind, ExportMap};
use crate::hir::def::{Res, DefKind, CtorOf, CtorKind, ExportMap};
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_data_structures::svh::Svh;
use rustc_macros::HashStable;
@ -269,10 +269,10 @@ impl Visibility {
match visibility.node {
hir::VisibilityKind::Public => Visibility::Public,
hir::VisibilityKind::Crate(_) => Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)),
hir::VisibilityKind::Restricted { ref path, .. } => match path.def {
hir::VisibilityKind::Restricted { ref path, .. } => match path.res {
// If there is no resolution, `resolve` will have already reported an error, so
// assume that the visibility is public to avoid reporting more privacy errors.
Def::Err => Visibility::Public,
Res::Err => Visibility::Public,
def => Visibility::Restricted(def.def_id()),
},
hir::VisibilityKind::Inherited => {
@ -812,7 +812,7 @@ pub type UpvarCaptureMap<'tcx> = FxHashMap<UpvarId, UpvarCapture<'tcx>>;
#[derive(Copy, Clone)]
pub struct ClosureUpvar<'tcx> {
pub def: Def,
pub res: Res,
pub span: Span,
pub ty: Ty<'tcx>,
}
@ -2337,14 +2337,14 @@ impl<'a, 'gcx, 'tcx> AdtDef {
.expect("variant_index_with_ctor_id: unknown variant").0
}
pub fn variant_of_def(&self, def: Def) -> &VariantDef {
match def {
Def::Def(DefKind::Variant, vid) => self.variant_with_id(vid),
Def::Def(DefKind::Ctor(..), cid) => self.variant_with_ctor_id(cid),
Def::Def(DefKind::Struct, _) | Def::Def(DefKind::Union, _) |
Def::Def(DefKind::TyAlias, _) | Def::Def(DefKind::AssociatedTy, _) | Def::SelfTy(..) |
Def::SelfCtor(..) => self.non_enum_variant(),
_ => bug!("unexpected def {:?} in variant_of_def", def)
pub fn variant_of_res(&self, res: Res) -> &VariantDef {
match res {
Res::Def(DefKind::Variant, vid) => self.variant_with_id(vid),
Res::Def(DefKind::Ctor(..), cid) => self.variant_with_ctor_id(cid),
Res::Def(DefKind::Struct, _) | Res::Def(DefKind::Union, _) |
Res::Def(DefKind::TyAlias, _) | Res::Def(DefKind::AssociatedTy, _) | Res::SelfTy(..) |
Res::SelfCtor(..) => self.non_enum_variant(),
_ => bug!("unexpected res {:?} in variant_of_res", res)
}
}
@ -2950,27 +2950,27 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
}
/// Returns `ty::VariantDef` if `def` refers to a struct,
/// Returns `ty::VariantDef` if `res` refers to a struct,
/// or variant or their constructors, panics otherwise.
pub fn expect_variant_def(self, def: Def) -> &'tcx VariantDef {
match def {
Def::Def(DefKind::Variant, did) => {
pub fn expect_variant_res(self, res: Res) -> &'tcx VariantDef {
match res {
Res::Def(DefKind::Variant, did) => {
let enum_did = self.parent(did).unwrap();
self.adt_def(enum_did).variant_with_id(did)
}
Def::Def(DefKind::Struct, did) | Def::Def(DefKind::Union, did) => {
Res::Def(DefKind::Struct, did) | Res::Def(DefKind::Union, did) => {
self.adt_def(did).non_enum_variant()
}
Def::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_did) => {
Res::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_did) => {
let variant_did = self.parent(variant_ctor_did).unwrap();
let enum_did = self.parent(variant_did).unwrap();
self.adt_def(enum_did).variant_with_ctor_id(variant_ctor_did)
}
Def::Def(DefKind::Ctor(CtorOf::Struct, ..), ctor_did) => {
Res::Def(DefKind::Ctor(CtorOf::Struct, ..), ctor_did) => {
let struct_did = self.parent(ctor_did).expect("struct ctor has no parent");
self.adt_def(struct_did).non_enum_variant()
}
_ => bug!("expect_variant_def used with unexpected def {:?}", def)
_ => bug!("expect_variant_res used with unexpected res {:?}", res)
}
}

View file

@ -359,7 +359,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
DefPathData::TypeNs(ref mut name) if Some(visible_parent) != actual_parent => {
let reexport = self.tcx().item_children(visible_parent)
.iter()
.find(|child| child.def.def_id() == def_id)
.find(|child| child.res.def_id() == def_id)
.map(|child| child.ident.as_interned_str());
if let Some(reexport) = reexport {
*name = reexport;

View file

@ -55,7 +55,7 @@ impl fmt::Debug for ty::AdtDef {
impl fmt::Debug for ty::ClosureUpvar<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ClosureUpvar({:?},{:?})",
self.def,
self.res,
self.ty)
}
}
@ -302,7 +302,7 @@ CloneTypeFoldableAndLiftImpls! {
::syntax::ast::FloatTy,
::syntax::ast::NodeId,
::syntax_pos::symbol::Symbol,
crate::hir::def::Def,
crate::hir::def::Res,
crate::hir::def_id::DefId,
crate::hir::InlineAsm,
crate::hir::MatchSource,
@ -1279,7 +1279,7 @@ TupleStructTypeFoldableImpl! {
BraceStructTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
def, span, ty
res, span, ty
}
}