ty::KContainer -> ty::AssocItemContainer::K

This commit is contained in:
Michael Goulet 2024-11-03 21:47:56 +00:00
parent 8e6af16192
commit be4b0261c2
21 changed files with 59 additions and 61 deletions

View File

@ -710,7 +710,7 @@ pub fn check_tied_features(
/// applied to the method prototype.
fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
if let Some(impl_item) = tcx.opt_associated_item(def_id)
&& let ty::AssocItemContainer::ImplContainer = impl_item.container
&& let ty::AssocItemContainer::Impl = impl_item.container
&& let Some(trait_item) = impl_item.trait_item_def_id
{
return tcx.codegen_fn_attrs(trait_item).flags.intersects(CodegenFnAttrFlags::TRACK_CALLER);

View File

@ -1189,8 +1189,8 @@ fn compare_self_type<'tcx>(
let self_string = |method: ty::AssocItem| {
let untransformed_self_ty = match method.container {
ty::ImplContainer => impl_trait_ref.self_ty(),
ty::TraitContainer => tcx.types.self_param,
ty::AssocItemContainer::Impl => impl_trait_ref.self_ty(),
ty::AssocItemContainer::Trait => tcx.types.self_param,
};
let self_arg_ty = tcx.fn_sig(method.def_id).instantiate_identity().input(0);
let param_env = ty::ParamEnv::reveal_all();
@ -2224,10 +2224,8 @@ fn param_env_with_gat_bounds<'tcx>(
for impl_ty in impl_tys_to_install {
let trait_ty = match impl_ty.container {
ty::AssocItemContainer::TraitContainer => impl_ty,
ty::AssocItemContainer::ImplContainer => {
tcx.associated_item(impl_ty.trait_item_def_id.unwrap())
}
ty::AssocItemContainer::Trait => impl_ty,
ty::AssocItemContainer::Impl => tcx.associated_item(impl_ty.trait_item_def_id.unwrap()),
};
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> =

View File

@ -1048,8 +1048,10 @@ fn check_associated_item(
.coherent_trait(tcx.parent(item.trait_item_def_id.unwrap_or(item_id.into())))?;
let self_ty = match item.container {
ty::TraitContainer => tcx.types.self_param,
ty::ImplContainer => tcx.type_of(item.container_id(tcx)).instantiate_identity(),
ty::AssocItemContainer::Trait => tcx.types.self_param,
ty::AssocItemContainer::Impl => {
tcx.type_of(item.container_id(tcx)).instantiate_identity()
}
};
match item.kind {
@ -1072,7 +1074,7 @@ fn check_associated_item(
check_method_receiver(wfcx, hir_sig, item, self_ty)
}
ty::AssocKind::Type => {
if let ty::AssocItemContainer::TraitContainer = item.container {
if let ty::AssocItemContainer::Trait = item.container {
check_associated_type_bounds(wfcx, item, span)
}
if item.defaultness(tcx).has_value() {

View File

@ -1025,7 +1025,7 @@ pub(crate) fn instantiate_value_path(
let container_id = assoc_item.container_id(tcx);
debug!(?def_id, ?container, ?container_id);
match container {
ty::TraitContainer => {
ty::AssocItemContainer::Trait => {
if let Err(e) = callee::check_legal_trait_for_method_call(
tcx,
path_span,
@ -1037,7 +1037,7 @@ pub(crate) fn instantiate_value_path(
self.set_tainted_by_errors(e);
}
}
ty::ImplContainer => {
ty::AssocItemContainer::Impl => {
if segments.len() == 1 {
// `<T>::assoc` will end up here, and so
// can `T::assoc`. If this came from an

View File

@ -1796,7 +1796,7 @@ pub(crate) fn note_type_is_not_clone(
false,
|did| {
let assoc_item = self.tcx.associated_item(did);
assoc_item.container == ty::AssocItemContainer::TraitContainer
assoc_item.container == ty::AssocItemContainer::Trait
&& assoc_item.container_id(self.tcx) == clone_trait_did
},
)

View File

@ -239,7 +239,7 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
let expected_type = if let Some(&hir::Ty { kind: hir::TyKind::Infer, span, .. }) = node.ty() {
if let Some(item) = tcx.opt_associated_item(def_id.into())
&& let ty::AssocKind::Const = item.kind
&& let ty::ImplContainer = item.container
&& let ty::AssocItemContainer::Impl = item.container
&& let Some(trait_item_def_id) = item.trait_item_def_id
{
let impl_def_id = item.container_id(tcx);

View File

@ -480,7 +480,7 @@ pub(crate) fn probe_op<OP, R>(
ProbeScope::Single(def_id) => {
let item = self.tcx.associated_item(def_id);
// FIXME(fn_delegation): Delegation to inherent methods is not yet supported.
assert_eq!(item.container, AssocItemContainer::TraitContainer);
assert_eq!(item.container, AssocItemContainer::Trait);
let trait_def_id = self.tcx.parent(def_id);
let trait_span = self.tcx.def_span(trait_def_id);
@ -1406,7 +1406,7 @@ pub(crate) fn maybe_emit_unstable_name_collision_hint(
tcx.def_path_str(self.item.def_id),
));
}
(ty::AssocKind::Const, ty::AssocItemContainer::TraitContainer) => {
(ty::AssocKind::Const, ty::AssocItemContainer::Trait) => {
let def_id = self.item.container_id(tcx);
lint.span_suggestion(
span,

View File

@ -26,8 +26,8 @@ pub(crate) enum MethodLateContext {
pub(crate) fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLateContext {
let item = cx.tcx.associated_item(id);
match item.container {
ty::TraitContainer => MethodLateContext::TraitAutoImpl,
ty::ImplContainer => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) {
ty::AssocItemContainer::Trait => MethodLateContext::TraitAutoImpl,
ty::AssocItemContainer::Impl => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) {
Some(_) => MethodLateContext::TraitImpl,
None => MethodLateContext::PlainImpl,
},

View File

@ -1203,8 +1203,8 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
DefKind::AssocTy => {
let assoc_item = tcx.associated_item(def_id);
match assoc_item.container {
ty::AssocItemContainer::ImplContainer => true,
ty::AssocItemContainer::TraitContainer => assoc_item.defaultness(tcx).has_value(),
ty::AssocItemContainer::Impl => true,
ty::AssocItemContainer::Trait => assoc_item.defaultness(tcx).has_value(),
}
}
DefKind::TyParam => {
@ -1336,7 +1336,7 @@ fn should_encode_const(def_kind: DefKind) -> bool {
fn should_encode_fn_impl_trait_in_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
if let Some(assoc_item) = tcx.opt_associated_item(def_id)
&& assoc_item.container == ty::AssocItemContainer::TraitContainer
&& assoc_item.container == ty::AssocItemContainer::Trait
&& assoc_item.kind == ty::AssocKind::Fn
{
true
@ -1649,7 +1649,7 @@ fn encode_info_for_assoc_item(&mut self, def_id: DefId) {
self.tables.assoc_container.set_some(def_id.index, item.container);
match item.container {
AssocItemContainer::TraitContainer => {
AssocItemContainer::Trait => {
if let ty::AssocKind::Type = item.kind {
self.encode_explicit_item_bounds(def_id);
self.encode_explicit_item_super_predicates(def_id);
@ -1659,7 +1659,7 @@ fn encode_info_for_assoc_item(&mut self, def_id: DefId) {
}
}
}
AssocItemContainer::ImplContainer => {
AssocItemContainer::Impl => {
if let Some(trait_item_def_id) = item.trait_item_def_id {
self.tables.trait_item_def_id.set_some(def_id.index, trait_item_def_id.into());
}

View File

@ -223,8 +223,8 @@ impl FixedSizeEncoding for Option<$ty> {
fixed_size_enum! {
ty::AssocItemContainer {
( TraitContainer )
( ImplContainer )
( Trait )
( Impl )
}
}

View File

@ -10,8 +10,8 @@
#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable, Hash, Encodable, Decodable)]
pub enum AssocItemContainer {
TraitContainer,
ImplContainer,
Trait,
Impl,
}
/// Information about an associated item
@ -63,16 +63,16 @@ pub fn container_id(&self, tcx: TyCtxt<'_>) -> DefId {
#[inline]
pub fn trait_container(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
match self.container {
AssocItemContainer::ImplContainer => None,
AssocItemContainer::TraitContainer => Some(tcx.parent(self.def_id)),
AssocItemContainer::Impl => None,
AssocItemContainer::Trait => Some(tcx.parent(self.def_id)),
}
}
#[inline]
pub fn impl_container(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
match self.container {
AssocItemContainer::ImplContainer => Some(tcx.parent(self.def_id)),
AssocItemContainer::TraitContainer => None,
AssocItemContainer::Impl => Some(tcx.parent(self.def_id)),
AssocItemContainer::Trait => None,
}
}

View File

@ -690,7 +690,7 @@ pub fn expect_resolve_for_vtable(
&& !matches!(
tcx.opt_associated_item(def),
Some(ty::AssocItem {
container: ty::AssocItemContainer::TraitContainer,
container: ty::AssocItemContainer::Trait,
..
})
)

View File

@ -55,9 +55,7 @@
pub use vtable::*;
use {rustc_ast as ast, rustc_attr as attr, rustc_hir as hir};
pub use self::AssocItemContainer::*;
pub use self::BorrowKind::*;
pub use self::IntVarValue::*;
pub use self::closure::{
BorrowKind, CAPTURE_STRUCT_LOCAL, CaptureInfo, CapturedPlace, ClosureTypeInfo,
MinCaptureInformationMap, MinCaptureList, RootVariableMinCaptureList, UpvarCapture, UpvarId,
@ -2074,7 +2072,7 @@ pub fn impl_method_has_trait_impl_trait_tys(self, def_id: DefId) -> bool {
let Some(item) = self.opt_associated_item(def_id) else {
return false;
};
if item.container != ty::AssocItemContainer::ImplContainer {
if item.container != ty::AssocItemContainer::Impl {
return false;
}

View File

@ -72,8 +72,8 @@ pub fn call_kind<'tcx>(
let parent = tcx.opt_associated_item(method_did).and_then(|assoc| {
let container_id = assoc.container_id(tcx);
match assoc.container {
AssocItemContainer::ImplContainer => tcx.trait_id_of_impl(container_id),
AssocItemContainer::TraitContainer => Some(container_id),
AssocItemContainer::Impl => tcx.trait_id_of_impl(container_id),
AssocItemContainer::Trait => Some(container_id),
}
});

View File

@ -59,11 +59,11 @@ pub(super) fn try_report_static_impl_trait(&self) -> Option<ErrorGuaranteed> {
let simple_ident = param.param.pat.simple_ident();
let (has_impl_path, impl_path) = match ctxt.assoc_item.container {
AssocItemContainer::TraitContainer => {
AssocItemContainer::Trait => {
let id = ctxt.assoc_item.container_id(tcx);
(true, tcx.def_path_str(id))
}
AssocItemContainer::ImplContainer => (false, String::new()),
AssocItemContainer::Impl => (false, String::new()),
};
let mut err = self.tcx().dcx().create_err(ButCallingIntroduces {

View File

@ -140,7 +140,7 @@ fn associated_item_from_trait_item_ref(trait_item_ref: &hir::TraitItemRef) -> ty
kind,
def_id: owner_id.to_def_id(),
trait_item_def_id: Some(owner_id.to_def_id()),
container: ty::TraitContainer,
container: ty::AssocItemContainer::Trait,
fn_has_self_parameter: has_self,
opt_rpitit_info: None,
}
@ -159,7 +159,7 @@ fn associated_item_from_impl_item_ref(impl_item_ref: &hir::ImplItemRef) -> ty::A
kind,
def_id: def_id.to_def_id(),
trait_item_def_id: impl_item_ref.trait_item_def_id,
container: ty::ImplContainer,
container: ty::AssocItemContainer::Impl,
fn_has_self_parameter: has_self,
opt_rpitit_info: None,
}
@ -267,7 +267,7 @@ fn associated_type_for_impl_trait_in_trait(
kind: ty::AssocKind::Type,
def_id,
trait_item_def_id: None,
container: ty::TraitContainer,
container: ty::AssocItemContainer::Trait,
fn_has_self_parameter: false,
opt_rpitit_info: Some(ImplTraitInTraitData::Trait {
fn_def_id: fn_def_id.to_def_id(),
@ -319,7 +319,7 @@ fn associated_type_for_impl_trait_in_impl(
kind: ty::AssocKind::Type,
def_id,
trait_item_def_id: Some(trait_assoc_def_id),
container: ty::ImplContainer,
container: ty::AssocItemContainer::Impl,
fn_has_self_parameter: false,
opt_rpitit_info: Some(ImplTraitInTraitData::Impl { fn_def_id: impl_fn_def_id.to_def_id() }),
});

View File

@ -135,7 +135,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
if tcx.def_kind(def_id) == DefKind::AssocFn
&& let assoc_item = tcx.associated_item(def_id)
&& assoc_item.container == ty::AssocItemContainer::TraitContainer
&& assoc_item.container == ty::AssocItemContainer::Trait
&& assoc_item.defaultness(tcx).has_value()
{
let sig = tcx.fn_sig(def_id).instantiate_identity();

View File

@ -1317,8 +1317,8 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
simplify::move_bounds_to_generic_parameters(&mut generics);
let provided = match assoc_item.container {
ty::ImplContainer => true,
ty::TraitContainer => tcx.defaultness(assoc_item.def_id).has_value(),
ty::AssocItemContainer::Impl => true,
ty::AssocItemContainer::Trait => tcx.defaultness(assoc_item.def_id).has_value(),
};
if provided {
AssocConstItem(Box::new(Constant {
@ -1335,10 +1335,10 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
if assoc_item.fn_has_self_parameter {
let self_ty = match assoc_item.container {
ty::ImplContainer => {
ty::AssocItemContainer::Impl => {
tcx.type_of(assoc_item.container_id(tcx)).instantiate_identity()
}
ty::TraitContainer => tcx.types.self_param,
ty::AssocItemContainer::Trait => tcx.types.self_param,
};
let self_arg_ty =
tcx.fn_sig(assoc_item.def_id).instantiate_identity().input(0).skip_binder();
@ -1355,13 +1355,13 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
}
let provided = match assoc_item.container {
ty::ImplContainer => true,
ty::TraitContainer => assoc_item.defaultness(tcx).has_value(),
ty::AssocItemContainer::Impl => true,
ty::AssocItemContainer::Trait => assoc_item.defaultness(tcx).has_value(),
};
if provided {
let defaultness = match assoc_item.container {
ty::ImplContainer => Some(assoc_item.defaultness(tcx)),
ty::TraitContainer => None,
ty::AssocItemContainer::Impl => Some(assoc_item.defaultness(tcx)),
ty::AssocItemContainer::Trait => None,
};
MethodItem(item, defaultness)
} else {
@ -1392,7 +1392,7 @@ fn param_eq_arg(param: &GenericParamDef, arg: &GenericArg) -> bool {
}
let mut predicates = tcx.explicit_predicates_of(assoc_item.def_id).predicates;
if let ty::TraitContainer = assoc_item.container {
if let ty::AssocItemContainer::Trait = assoc_item.container {
let bounds = tcx.explicit_item_bounds(assoc_item.def_id).iter_identity_copied();
predicates = tcx.arena.alloc_from_iter(bounds.chain(predicates.iter().copied()));
}
@ -1403,7 +1403,7 @@ fn param_eq_arg(param: &GenericParamDef, arg: &GenericArg) -> bool {
});
simplify::move_bounds_to_generic_parameters(&mut generics);
if let ty::TraitContainer = assoc_item.container {
if let ty::AssocItemContainer::Trait = assoc_item.container {
// Move bounds that are (likely) directly attached to the associated type
// from the where-clause to the associated type.
// There is no guarantee that this is what the user actually wrote but we have

View File

@ -703,8 +703,8 @@ pub(crate) fn visibility(&self, tcx: TyCtxt<'_>) -> Option<Visibility<DefId>> {
| TyMethodItem(..) | MethodItem(..) => {
let assoc_item = tcx.associated_item(def_id);
let is_trait_item = match assoc_item.container {
ty::TraitContainer => true,
ty::ImplContainer => {
ty::AssocItemContainer::Trait => true,
ty::AssocItemContainer::Impl => {
// Trait impl items always inherit the impl's visibility --
// we don't want to show `pub`.
tcx.impl_trait_ref(tcx.parent(assoc_item.def_id)).is_some()

View File

@ -2,6 +2,7 @@
use rustc_ast::ast;
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::AssocItemContainer;
use rustc_session::declare_lint_pass;
use rustc_span::{Span, sym};
@ -138,7 +139,6 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
}
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
use rustc_middle::ty::{ImplContainer, TraitContainer};
if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable_or_proc_macro(cx) {
return;
}
@ -156,8 +156,8 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
let assoc_item = cx.tcx.associated_item(impl_item.owner_id);
let container_id = assoc_item.container_id(cx.tcx);
let trait_def_id = match assoc_item.container {
TraitContainer => Some(container_id),
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
AssocItemContainer::Trait => Some(container_id),
AssocItemContainer::Impl => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
};
if let Some(trait_def_id) = trait_def_id {

View File

@ -3340,8 +3340,8 @@ pub fn get_path_from_caller_to_method_type<'tcx>(
let assoc_item = tcx.associated_item(method);
let def_id = assoc_item.container_id(tcx);
match assoc_item.container {
rustc_ty::TraitContainer => get_path_to_callee(tcx, from, def_id),
rustc_ty::ImplContainer => {
rustc_ty::AssocItemContainer::Trait => get_path_to_callee(tcx, from, def_id),
rustc_ty::AssocItemContainer::Impl => {
let ty = tcx.type_of(def_id).instantiate_identity();
get_path_to_ty(tcx, from, ty, args)
},