change to a struct variant
This commit is contained in:
parent
9cdefd763b
commit
e81e09a24e
27 changed files with 68 additions and 57 deletions
|
@ -313,12 +313,12 @@ pub enum Res<Id = hir::HirId> {
|
||||||
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat lint.
|
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat lint.
|
||||||
///
|
///
|
||||||
/// FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
|
/// FIXME(generic_const_exprs): Remove this bodge once that feature is stable.
|
||||||
SelfTy(
|
SelfTy {
|
||||||
/// Optionally, the trait associated with this `Self` type.
|
/// Optionally, the trait associated with this `Self` type.
|
||||||
Option<DefId>,
|
trait_: Option<DefId>,
|
||||||
/// Optionally, the impl associated with this `Self` type.
|
/// Optionally, the impl or adt associated with this `Self` type.
|
||||||
Option<(DefId, bool)>,
|
alias_to: Option<(DefId, bool)>,
|
||||||
),
|
},
|
||||||
/// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
|
/// A tool attribute module; e.g., the `rustfmt` in `#[rustfmt::skip]`.
|
||||||
///
|
///
|
||||||
/// **Belongs to the type namespace.**
|
/// **Belongs to the type namespace.**
|
||||||
|
@ -550,7 +550,7 @@ impl<Id> Res<Id> {
|
||||||
|
|
||||||
Res::Local(..)
|
Res::Local(..)
|
||||||
| Res::PrimTy(..)
|
| Res::PrimTy(..)
|
||||||
| Res::SelfTy(..)
|
| Res::SelfTy { .. }
|
||||||
| Res::SelfCtor(..)
|
| Res::SelfCtor(..)
|
||||||
| Res::ToolMod
|
| Res::ToolMod
|
||||||
| Res::NonMacroAttr(..)
|
| Res::NonMacroAttr(..)
|
||||||
|
@ -573,7 +573,7 @@ impl<Id> Res<Id> {
|
||||||
Res::SelfCtor(..) => "self constructor",
|
Res::SelfCtor(..) => "self constructor",
|
||||||
Res::PrimTy(..) => "builtin type",
|
Res::PrimTy(..) => "builtin type",
|
||||||
Res::Local(..) => "local variable",
|
Res::Local(..) => "local variable",
|
||||||
Res::SelfTy(..) => "self type",
|
Res::SelfTy { .. } => "self type",
|
||||||
Res::ToolMod => "tool module",
|
Res::ToolMod => "tool module",
|
||||||
Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
|
Res::NonMacroAttr(attr_kind) => attr_kind.descr(),
|
||||||
Res::Err => "unresolved item",
|
Res::Err => "unresolved item",
|
||||||
|
@ -596,7 +596,7 @@ impl<Id> Res<Id> {
|
||||||
Res::SelfCtor(id) => Res::SelfCtor(id),
|
Res::SelfCtor(id) => Res::SelfCtor(id),
|
||||||
Res::PrimTy(id) => Res::PrimTy(id),
|
Res::PrimTy(id) => Res::PrimTy(id),
|
||||||
Res::Local(id) => Res::Local(map(id)),
|
Res::Local(id) => Res::Local(map(id)),
|
||||||
Res::SelfTy(a, b) => Res::SelfTy(a, b),
|
Res::SelfTy { trait_, alias_to } => Res::SelfTy { trait_, alias_to },
|
||||||
Res::ToolMod => Res::ToolMod,
|
Res::ToolMod => Res::ToolMod,
|
||||||
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
|
Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
|
||||||
Res::Err => Res::Err,
|
Res::Err => Res::Err,
|
||||||
|
@ -620,7 +620,7 @@ impl<Id> Res<Id> {
|
||||||
pub fn ns(&self) -> Option<Namespace> {
|
pub fn ns(&self) -> Option<Namespace> {
|
||||||
match self {
|
match self {
|
||||||
Res::Def(kind, ..) => kind.ns(),
|
Res::Def(kind, ..) => kind.ns(),
|
||||||
Res::PrimTy(..) | Res::SelfTy(..) | Res::ToolMod => Some(Namespace::TypeNS),
|
Res::PrimTy(..) | Res::SelfTy { .. } | Res::ToolMod => Some(Namespace::TypeNS),
|
||||||
Res::SelfCtor(..) | Res::Local(..) => Some(Namespace::ValueNS),
|
Res::SelfCtor(..) | Res::Local(..) => Some(Namespace::ValueNS),
|
||||||
Res::NonMacroAttr(..) => Some(Namespace::MacroNS),
|
Res::NonMacroAttr(..) => Some(Namespace::MacroNS),
|
||||||
Res::Err => None,
|
Res::Err => None,
|
||||||
|
|
|
@ -640,9 +640,8 @@ impl<'hir> WhereBoundPredicate<'hir> {
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
match path.res {
|
match path.res {
|
||||||
Res::Def(DefKind::TyParam, def_id) | Res::SelfTy(Some(def_id), None) => {
|
Res::Def(DefKind::TyParam, def_id)
|
||||||
def_id == param_def_id
|
| Res::SelfTy { trait_: Some(def_id), alias_to: None } => def_id == param_def_id,
|
||||||
}
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,8 @@ impl<'tcx> Visitor<'tcx> for TypeParamSpanVisitor<'tcx> {
|
||||||
.map(|res| {
|
.map(|res| {
|
||||||
matches!(
|
matches!(
|
||||||
res,
|
res,
|
||||||
Res::SelfTy(_, _) | Res::Def(hir::def::DefKind::TyParam, _)
|
Res::SelfTy { trait_: _, alias_to: _ }
|
||||||
|
| Res::Def(hir::def::DefKind::TyParam, _)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.unwrap_or(false) =>
|
.unwrap_or(false) =>
|
||||||
|
|
|
@ -202,7 +202,7 @@ fn is_ty_or_ty_ctxt(cx: &LateContext<'_>, ty: &Ty<'_>) -> Option<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
|
// Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
|
||||||
Res::SelfTy(None, Some((did, _))) => {
|
Res::SelfTy { trait_: None, alias_to: Some((did, _)) } => {
|
||||||
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
|
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
|
||||||
if let Some(name @ (sym::Ty | sym::TyCtxt)) =
|
if let Some(name @ (sym::Ty | sym::TyCtxt)) =
|
||||||
cx.tcx.get_diagnostic_name(adt.did)
|
cx.tcx.get_diagnostic_name(adt.did)
|
||||||
|
|
|
@ -54,7 +54,7 @@ fn path_for_pass_by_value(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> Option<Stri
|
||||||
let path_segment = path.segments.last().unwrap();
|
let path_segment = path.segments.last().unwrap();
|
||||||
return Some(format!("{}{}", name, gen_args(cx, path_segment)));
|
return Some(format!("{}{}", name, gen_args(cx, path_segment)));
|
||||||
}
|
}
|
||||||
Res::SelfTy(None, Some((did, _))) => {
|
Res::SelfTy { trait_: None, alias_to: Some((did, _)) } => {
|
||||||
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
|
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
|
||||||
if cx.tcx.has_attr(adt.did, sym::rustc_pass_by_value) {
|
if cx.tcx.has_attr(adt.did, sym::rustc_pass_by_value) {
|
||||||
return Some(cx.tcx.def_path_str_with_substs(adt.did, substs));
|
return Some(cx.tcx.def_path_str_with_substs(adt.did, substs));
|
||||||
|
|
|
@ -395,7 +395,7 @@ impl<'tcx> AdtDef {
|
||||||
| Res::Def(DefKind::Union, _)
|
| Res::Def(DefKind::Union, _)
|
||||||
| Res::Def(DefKind::TyAlias, _)
|
| Res::Def(DefKind::TyAlias, _)
|
||||||
| Res::Def(DefKind::AssocTy, _)
|
| Res::Def(DefKind::AssocTy, _)
|
||||||
| Res::SelfTy(..)
|
| Res::SelfTy { .. }
|
||||||
| Res::SelfCtor(..) => self.non_enum_variant(),
|
| Res::SelfCtor(..) => self.non_enum_variant(),
|
||||||
_ => bug!("unexpected res {:?} in variant_of_res", res),
|
_ => bug!("unexpected res {:?} in variant_of_res", res),
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,7 +417,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
||||||
| DefKind::AssocTy,
|
| DefKind::AssocTy,
|
||||||
_,
|
_,
|
||||||
)
|
)
|
||||||
| Res::SelfTy(..)
|
| Res::SelfTy { .. }
|
||||||
| Res::SelfCtor(..) => PatKind::Leaf { subpatterns },
|
| Res::SelfCtor(..) => PatKind::Leaf { subpatterns },
|
||||||
_ => {
|
_ => {
|
||||||
let pattern_error = match res {
|
let pattern_error = match res {
|
||||||
|
|
|
@ -104,7 +104,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
||||||
self.check_def_id(variant_id);
|
self.check_def_id(variant_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Res::SelfTy(t, i) => {
|
Res::SelfTy { trait_: t, alias_to: i } => {
|
||||||
if let Some(t) = t {
|
if let Some(t) = t {
|
||||||
self.check_def_id(t);
|
self.check_def_id(t);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1350,7 +1350,7 @@ struct ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> {
|
||||||
impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||||
fn path_is_private_type(&self, path: &hir::Path<'_>) -> bool {
|
fn path_is_private_type(&self, path: &hir::Path<'_>) -> bool {
|
||||||
let did = match path.res {
|
let did = match path.res {
|
||||||
Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => return false,
|
Res::PrimTy(..) | Res::SelfTy { .. } | Res::Err => return false,
|
||||||
res => res.def_id(),
|
res => res.def_id(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -991,7 +991,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
_,
|
_,
|
||||||
)
|
)
|
||||||
| Res::Local(..)
|
| Res::Local(..)
|
||||||
| Res::SelfTy(..)
|
| Res::SelfTy { .. }
|
||||||
| Res::SelfCtor(..)
|
| Res::SelfCtor(..)
|
||||||
| Res::Err => bug!("unexpected resolution: {:?}", res),
|
| Res::Err => bug!("unexpected resolution: {:?}", res),
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
let sm = self.session.source_map();
|
let sm = self.session.source_map();
|
||||||
match outer_res {
|
match outer_res {
|
||||||
Res::SelfTy(maybe_trait_defid, maybe_impl_defid) => {
|
Res::SelfTy { trait_: maybe_trait_defid, alias_to: maybe_impl_defid } => {
|
||||||
if let Some(impl_span) =
|
if let Some(impl_span) =
|
||||||
maybe_impl_defid.and_then(|(def_id, _)| self.opt_span(def_id))
|
maybe_impl_defid.and_then(|(def_id, _)| self.opt_span(def_id))
|
||||||
{
|
{
|
||||||
|
|
|
@ -289,7 +289,7 @@ impl<'a> PathSource<'a> {
|
||||||
| DefKind::ForeignTy,
|
| DefKind::ForeignTy,
|
||||||
_,
|
_,
|
||||||
) | Res::PrimTy(..)
|
) | Res::PrimTy(..)
|
||||||
| Res::SelfTy(..)
|
| Res::SelfTy { .. }
|
||||||
),
|
),
|
||||||
PathSource::Trait(AliasPossibility::No) => matches!(res, Res::Def(DefKind::Trait, _)),
|
PathSource::Trait(AliasPossibility::No) => matches!(res, Res::Def(DefKind::Trait, _)),
|
||||||
PathSource::Trait(AliasPossibility::Maybe) => {
|
PathSource::Trait(AliasPossibility::Maybe) => {
|
||||||
|
@ -326,7 +326,7 @@ impl<'a> PathSource<'a> {
|
||||||
| DefKind::TyAlias
|
| DefKind::TyAlias
|
||||||
| DefKind::AssocTy,
|
| DefKind::AssocTy,
|
||||||
_,
|
_,
|
||||||
) | Res::SelfTy(..)
|
) | Res::SelfTy { .. }
|
||||||
),
|
),
|
||||||
PathSource::TraitItem(ns) => match res {
|
PathSource::TraitItem(ns) => match res {
|
||||||
Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) if ns == ValueNS => true,
|
Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) if ns == ValueNS => true,
|
||||||
|
@ -911,9 +911,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
self.with_current_self_item(item, |this| {
|
self.with_current_self_item(item, |this| {
|
||||||
this.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
|
this.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
|
||||||
let item_def_id = this.r.local_def_id(item.id).to_def_id();
|
let item_def_id = this.r.local_def_id(item.id).to_def_id();
|
||||||
this.with_self_rib(Res::SelfTy(None, Some((item_def_id, false))), |this| {
|
this.with_self_rib(
|
||||||
visit::walk_item(this, item);
|
Res::SelfTy { trait_: None, alias_to: Some((item_def_id, false)) },
|
||||||
});
|
|this| {
|
||||||
|
visit::walk_item(this, item);
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -999,8 +1002,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
self.compute_num_lifetime_params(item.id, generics);
|
self.compute_num_lifetime_params(item.id, generics);
|
||||||
// Create a new rib for the trait-wide type parameters.
|
// Create a new rib for the trait-wide type parameters.
|
||||||
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
|
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
|
||||||
let local_def_id = this.r.local_def_id(item.id).to_def_id();
|
let def = this.r.local_def_id(item.id).to_def_id();
|
||||||
this.with_self_rib(Res::SelfTy(Some(local_def_id), None), |this| {
|
this.with_self_rib(Res::SelfTy { trait_: Some(def), alias_to: None }, |this| {
|
||||||
this.visit_generics(generics);
|
this.visit_generics(generics);
|
||||||
walk_list!(this, visit_param_bound, bounds);
|
walk_list!(this, visit_param_bound, bounds);
|
||||||
|
|
||||||
|
@ -1051,8 +1054,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
self.compute_num_lifetime_params(item.id, generics);
|
self.compute_num_lifetime_params(item.id, generics);
|
||||||
// Create a new rib for the trait-wide type parameters.
|
// Create a new rib for the trait-wide type parameters.
|
||||||
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
|
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
|
||||||
let local_def_id = this.r.local_def_id(item.id).to_def_id();
|
let def = this.r.local_def_id(item.id).to_def_id();
|
||||||
this.with_self_rib(Res::SelfTy(Some(local_def_id), None), |this| {
|
this.with_self_rib(Res::SelfTy { trait_: Some(def), alias_to: None }, |this| {
|
||||||
this.visit_generics(generics);
|
this.visit_generics(generics);
|
||||||
walk_list!(this, visit_param_bound, bounds);
|
walk_list!(this, visit_param_bound, bounds);
|
||||||
});
|
});
|
||||||
|
@ -1296,7 +1299,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
// If applicable, create a rib for the type parameters.
|
// If applicable, create a rib for the type parameters.
|
||||||
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
|
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
|
||||||
// Dummy self type for better errors if `Self` is used in the trait path.
|
// Dummy self type for better errors if `Self` is used in the trait path.
|
||||||
this.with_self_rib(Res::SelfTy(None, None), |this| {
|
this.with_self_rib(Res::SelfTy { trait_: None, alias_to: None }, |this| {
|
||||||
// Resolve the trait reference, if necessary.
|
// Resolve the trait reference, if necessary.
|
||||||
this.with_optional_trait_ref(opt_trait_reference.as_ref(), |this, trait_id| {
|
this.with_optional_trait_ref(opt_trait_reference.as_ref(), |this, trait_id| {
|
||||||
let item_def_id = this.r.local_def_id(item_id);
|
let item_def_id = this.r.local_def_id(item_id);
|
||||||
|
@ -1307,7 +1310,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let item_def_id = item_def_id.to_def_id();
|
let item_def_id = item_def_id.to_def_id();
|
||||||
this.with_self_rib(Res::SelfTy(trait_id, Some((item_def_id, false))), |this| {
|
let res =
|
||||||
|
Res::SelfTy { trait_: trait_id, alias_to: Some((item_def_id, false)) };
|
||||||
|
this.with_self_rib(res, |this| {
|
||||||
if let Some(trait_ref) = opt_trait_reference.as_ref() {
|
if let Some(trait_ref) = opt_trait_reference.as_ref() {
|
||||||
// Resolve type arguments in the trait path.
|
// Resolve type arguments in the trait path.
|
||||||
visit::walk_trait_ref(this, trait_ref);
|
visit::walk_trait_ref(this, trait_ref);
|
||||||
|
|
|
@ -1189,7 +1189,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
Applicability::HasPlaceholders,
|
Applicability::HasPlaceholders,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(Res::SelfTy(..), _) if ns == ValueNS => {
|
(Res::SelfTy { .. }, _) if ns == ValueNS => {
|
||||||
err.span_label(span, fallback_label);
|
err.span_label(span, fallback_label);
|
||||||
err.note("can't use `Self` as a constructor, you must use the implemented struct");
|
err.note("can't use `Self` as a constructor, you must use the implemented struct");
|
||||||
}
|
}
|
||||||
|
|
|
@ -2793,7 +2793,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
// Look for `self: &'a Self` - also desugared from `&'a self`,
|
// Look for `self: &'a Self` - also desugared from `&'a self`,
|
||||||
// and if that matches, use it for elision and return early.
|
// and if that matches, use it for elision and return early.
|
||||||
fn is_self_ty(&self, res: Res) -> bool {
|
fn is_self_ty(&self, res: Res) -> bool {
|
||||||
if let Res::SelfTy(..) = res {
|
if let Res::SelfTy { .. } = res {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2784,7 +2784,7 @@ impl<'a> Resolver<'a> {
|
||||||
return Res::Err;
|
return Res::Err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::TyParam, _) | Res::SelfTy(..) => {
|
Res::Def(DefKind::TyParam, _) | Res::SelfTy { .. } => {
|
||||||
for rib in ribs {
|
for rib in ribs {
|
||||||
let has_generic_params: HasGenericParams = match rib.kind {
|
let has_generic_params: HasGenericParams = match rib.kind {
|
||||||
NormalRibKind
|
NormalRibKind
|
||||||
|
@ -2804,8 +2804,8 @@ impl<'a> Resolver<'a> {
|
||||||
// HACK(min_const_generics): If we encounter `Self` in an anonymous constant
|
// HACK(min_const_generics): If we encounter `Self` in an anonymous constant
|
||||||
// we can't easily tell if it's generic at this stage, so we instead remember
|
// we can't easily tell if it's generic at this stage, so we instead remember
|
||||||
// this and then enforce the self type to be concrete later on.
|
// this and then enforce the self type to be concrete later on.
|
||||||
if let Res::SelfTy(trait_def, Some((impl_def, _))) = res {
|
if let Res::SelfTy { trait_, alias_to: Some((def, _)) } = res {
|
||||||
res = Res::SelfTy(trait_def, Some((impl_def, true)));
|
res = Res::SelfTy { trait_, alias_to: Some((def, true)) }
|
||||||
} else {
|
} else {
|
||||||
if record_used {
|
if record_used {
|
||||||
self.report_error(
|
self.report_error(
|
||||||
|
|
|
@ -921,7 +921,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||||
| HirDefKind::AssocTy,
|
| HirDefKind::AssocTy,
|
||||||
_,
|
_,
|
||||||
)
|
)
|
||||||
| Res::SelfTy(..) => {
|
| Res::SelfTy { .. } => {
|
||||||
self.dump_path_segment_ref(id, &hir::PathSegment::from_ident(ident));
|
self.dump_path_segment_ref(id, &hir::PathSegment::from_ident(ident));
|
||||||
}
|
}
|
||||||
def => {
|
def => {
|
||||||
|
|
|
@ -749,7 +749,7 @@ impl<'tcx> SaveContext<'tcx> {
|
||||||
_,
|
_,
|
||||||
)
|
)
|
||||||
| Res::PrimTy(..)
|
| Res::PrimTy(..)
|
||||||
| Res::SelfTy(..)
|
| Res::SelfTy { .. }
|
||||||
| Res::ToolMod
|
| Res::ToolMod
|
||||||
| Res::NonMacroAttr(..)
|
| Res::NonMacroAttr(..)
|
||||||
| Res::SelfCtor(..)
|
| Res::SelfCtor(..)
|
||||||
|
@ -814,7 +814,7 @@ impl<'tcx> SaveContext<'tcx> {
|
||||||
|
|
||||||
fn lookup_def_id(&self, ref_id: hir::HirId) -> Option<DefId> {
|
fn lookup_def_id(&self, ref_id: hir::HirId) -> Option<DefId> {
|
||||||
match self.get_path_res(ref_id) {
|
match self.get_path_res(ref_id) {
|
||||||
Res::PrimTy(_) | Res::SelfTy(..) | Res::Err => None,
|
Res::PrimTy(_) | Res::SelfTy { .. } | Res::Err => None,
|
||||||
def => def.opt_def_id(),
|
def => def.opt_def_id(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -573,7 +573,7 @@ impl<'hir> Sig for hir::Path<'hir> {
|
||||||
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
|
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
|
||||||
|
|
||||||
let (name, start, end) = match res {
|
let (name, start, end) = match res {
|
||||||
Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => {
|
Res::PrimTy(..) | Res::SelfTy { .. } | Res::Err => {
|
||||||
return Ok(Signature { text: path_to_string(self), defs: vec![], refs: vec![] });
|
return Ok(Signature { text: path_to_string(self), defs: vec![], refs: vec![] });
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::AssocConst | DefKind::Variant | DefKind::Ctor(..), _) => {
|
Res::Def(DefKind::AssocConst | DefKind::Variant | DefKind::Ctor(..), _) => {
|
||||||
|
|
|
@ -1805,7 +1805,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
// Find the type of the associated item, and the trait where the associated
|
// Find the type of the associated item, and the trait where the associated
|
||||||
// item is declared.
|
// item is declared.
|
||||||
let bound = match (&qself_ty.kind(), qself_res) {
|
let bound = match (&qself_ty.kind(), qself_res) {
|
||||||
(_, Res::SelfTy(Some(_), Some((impl_def_id, _)))) => {
|
(_, Res::SelfTy { trait_: Some(_), alias_to: Some((impl_def_id, _)) }) => {
|
||||||
// `Self` in an impl of a trait -- we have a concrete self type and a
|
// `Self` in an impl of a trait -- we have a concrete self type and a
|
||||||
// trait reference.
|
// trait reference.
|
||||||
let trait_ref = match tcx.impl_trait_ref(impl_def_id) {
|
let trait_ref = match tcx.impl_trait_ref(impl_def_id) {
|
||||||
|
@ -1826,7 +1826,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
&ty::Param(_),
|
&ty::Param(_),
|
||||||
Res::SelfTy(Some(param_did), None) | Res::Def(DefKind::TyParam, param_did),
|
Res::SelfTy { trait_: Some(param_did), alias_to: None }
|
||||||
|
| Res::Def(DefKind::TyParam, param_did),
|
||||||
) => self.find_bound_for_assoc_item(param_did.expect_local(), assoc_ident, span)?,
|
) => self.find_bound_for_assoc_item(param_did.expect_local(), assoc_ident, span)?,
|
||||||
_ => {
|
_ => {
|
||||||
if variant_resolution.is_some() {
|
if variant_resolution.is_some() {
|
||||||
|
@ -2270,13 +2271,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
let index = generics.param_def_id_to_index[&def_id];
|
let index = generics.param_def_id_to_index[&def_id];
|
||||||
tcx.mk_ty_param(index, tcx.hir().name(hir_id))
|
tcx.mk_ty_param(index, tcx.hir().name(hir_id))
|
||||||
}
|
}
|
||||||
Res::SelfTy(Some(_), None) => {
|
Res::SelfTy { trait_: Some(_), alias_to: None } => {
|
||||||
// `Self` in trait or type alias.
|
// `Self` in trait or type alias.
|
||||||
assert_eq!(opt_self_ty, None);
|
assert_eq!(opt_self_ty, None);
|
||||||
self.prohibit_generics(path.segments);
|
self.prohibit_generics(path.segments);
|
||||||
tcx.types.self_param
|
tcx.types.self_param
|
||||||
}
|
}
|
||||||
Res::SelfTy(_, Some((def_id, forbid_generic))) => {
|
Res::SelfTy { trait_: _, alias_to: Some((def_id, forbid_generic)) } => {
|
||||||
// `Self` in impl (we know the concrete type).
|
// `Self` in impl (we know the concrete type).
|
||||||
assert_eq!(opt_self_ty, None);
|
assert_eq!(opt_self_ty, None);
|
||||||
self.prohibit_generics(path.segments);
|
self.prohibit_generics(path.segments);
|
||||||
|
|
|
@ -522,7 +522,12 @@ pub(super) fn check_opaque_for_inheriting_lifetimes<'tcx>(
|
||||||
fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
|
fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx>) {
|
||||||
match arg.kind {
|
match arg.kind {
|
||||||
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => match &path.segments {
|
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => match &path.segments {
|
||||||
[PathSegment { res: Some(Res::SelfTy(_, impl_ref)), .. }] => {
|
[
|
||||||
|
PathSegment {
|
||||||
|
res: Some(Res::SelfTy { trait_: _, alias_to: impl_ref }),
|
||||||
|
..
|
||||||
|
},
|
||||||
|
] => {
|
||||||
let impl_ty_name =
|
let impl_ty_name =
|
||||||
impl_ref.map(|(def_id, _)| self.tcx.def_path_str(def_id));
|
impl_ref.map(|(def_id, _)| self.tcx.def_path_str(def_id));
|
||||||
self.selftys.push((path.span, impl_ty_name));
|
self.selftys.push((path.span, impl_ty_name));
|
||||||
|
|
|
@ -578,7 +578,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
_ => bug!("unexpected type: {:?}", ty),
|
_ => bug!("unexpected type: {:?}", ty),
|
||||||
},
|
},
|
||||||
Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
|
Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
|
||||||
| Res::SelfTy(..) => match ty.kind() {
|
| Res::SelfTy { .. } => match ty.kind() {
|
||||||
ty::Adt(adt, substs) if !adt.is_enum() => {
|
ty::Adt(adt, substs) if !adt.is_enum() => {
|
||||||
Some((adt.non_enum_variant(), adt.did, substs))
|
Some((adt.non_enum_variant(), adt.did, substs))
|
||||||
}
|
}
|
||||||
|
|
|
@ -562,7 +562,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
||||||
Res::Def(DefKind::Ctor(CtorOf::Struct, ..), _)
|
Res::Def(DefKind::Ctor(CtorOf::Struct, ..), _)
|
||||||
| Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
|
| Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
|
||||||
| Res::SelfCtor(..)
|
| Res::SelfCtor(..)
|
||||||
| Res::SelfTy(..) => {
|
| Res::SelfTy { .. } => {
|
||||||
// Structs and Unions have only have one variant.
|
// Structs and Unions have only have one variant.
|
||||||
Ok(VariantIdx::new(0))
|
Ok(VariantIdx::new(0))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1972,7 +1972,7 @@ impl Path {
|
||||||
/// Checks if this is a `T::Name` path for an associated type.
|
/// Checks if this is a `T::Name` path for an associated type.
|
||||||
crate fn is_assoc_ty(&self) -> bool {
|
crate fn is_assoc_ty(&self) -> bool {
|
||||||
match self.res {
|
match self.res {
|
||||||
Res::SelfTy(..) if self.segments.len() != 1 => true,
|
Res::SelfTy { .. } if self.segments.len() != 1 => true,
|
||||||
Res::Def(DefKind::TyParam, _) if self.segments.len() != 1 => true,
|
Res::Def(DefKind::TyParam, _) if self.segments.len() != 1 => true,
|
||||||
Res::Def(DefKind::AssocTy, _) => true,
|
Res::Def(DefKind::AssocTy, _) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -355,7 +355,7 @@ crate fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
|
||||||
|
|
||||||
match path.res {
|
match path.res {
|
||||||
Res::PrimTy(p) => Primitive(PrimitiveType::from(p)),
|
Res::PrimTy(p) => Primitive(PrimitiveType::from(p)),
|
||||||
Res::SelfTy(..) if path.segments.len() == 1 => Generic(kw::SelfUpper),
|
Res::SelfTy { .. } if path.segments.len() == 1 => Generic(kw::SelfUpper),
|
||||||
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
|
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
|
||||||
_ => {
|
_ => {
|
||||||
let _ = register_res(cx, path.res);
|
let _ = register_res(cx, path.res);
|
||||||
|
@ -398,10 +398,10 @@ crate fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
|
||||||
i,
|
i,
|
||||||
) => (i, kind.into()),
|
) => (i, kind.into()),
|
||||||
// This is part of a trait definition; document the trait.
|
// This is part of a trait definition; document the trait.
|
||||||
Res::SelfTy(Some(trait_def_id), _) => (trait_def_id, ItemType::Trait),
|
Res::SelfTy { trait_: Some(trait_def_id), alias_to: _ } => (trait_def_id, ItemType::Trait),
|
||||||
// This is an inherent impl; it doesn't have its own page.
|
// This is an inherent impl; it doesn't have its own page.
|
||||||
Res::SelfTy(None, Some((impl_def_id, _))) => return impl_def_id,
|
Res::SelfTy { trait_: None, alias_to: Some((impl_def_id, _)) } => return impl_def_id,
|
||||||
Res::SelfTy(None, None)
|
Res::SelfTy { trait_: None, alias_to: None }
|
||||||
| Res::PrimTy(_)
|
| Res::PrimTy(_)
|
||||||
| Res::ToolMod
|
| Res::ToolMod
|
||||||
| Res::SelfCtor(_)
|
| Res::SelfCtor(_)
|
||||||
|
|
|
@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
|
||||||
if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate;
|
if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate;
|
||||||
if !bound_predicate.span.from_expansion();
|
if !bound_predicate.span.from_expansion();
|
||||||
if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind;
|
if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind;
|
||||||
if let Some(PathSegment { res: Some(Res::SelfTy(Some(def_id), _)), .. }) = segments.first();
|
if let Some(PathSegment { res: Some(Res::SelfTy{ trait_: Some(def_id), alias_to: _ }), .. }) = segments.first();
|
||||||
|
|
||||||
if let Some(
|
if let Some(
|
||||||
Node::Item(
|
Node::Item(
|
||||||
|
|
|
@ -204,7 +204,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||||
ref types_to_skip,
|
ref types_to_skip,
|
||||||
}) = self.stack.last();
|
}) = self.stack.last();
|
||||||
if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind;
|
if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind;
|
||||||
if !matches!(path.res, Res::SelfTy(..) | Res::Def(DefKind::TyParam, _));
|
if !matches!(path.res, Res::SelfTy { .. } | Res::Def(DefKind::TyParam, _));
|
||||||
if !types_to_skip.contains(&hir_ty.hir_id);
|
if !types_to_skip.contains(&hir_ty.hir_id);
|
||||||
let ty = if in_body > 0 {
|
let ty = if in_body > 0 {
|
||||||
cx.typeck_results().node_type(hir_ty.hir_id)
|
cx.typeck_results().node_type(hir_ty.hir_id)
|
||||||
|
@ -231,7 +231,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||||
}
|
}
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
ExprKind::Struct(QPath::Resolved(_, path), ..) => match path.res {
|
ExprKind::Struct(QPath::Resolved(_, path), ..) => match path.res {
|
||||||
Res::SelfTy(..) => (),
|
Res::SelfTy { .. } => (),
|
||||||
Res::Def(DefKind::Variant, _) => lint_path_to_variant(cx, path),
|
Res::Def(DefKind::Variant, _) => lint_path_to_variant(cx, path),
|
||||||
_ => span_lint(cx, path.span),
|
_ => span_lint(cx, path.span),
|
||||||
},
|
},
|
||||||
|
|
|
@ -1460,7 +1460,7 @@ pub fn is_self(slf: &Param<'_>) -> bool {
|
||||||
|
|
||||||
pub fn is_self_ty(slf: &hir::Ty<'_>) -> bool {
|
pub fn is_self_ty(slf: &hir::Ty<'_>) -> bool {
|
||||||
if let TyKind::Path(QPath::Resolved(None, path)) = slf.kind {
|
if let TyKind::Path(QPath::Resolved(None, path)) = slf.kind {
|
||||||
if let Res::SelfTy(..) = path.res {
|
if let Res::SelfTy { .. } = path.res {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue