Skip to content

Commit 4d28a9d

Browse files
committed
Split AssocItemContainer::{InherentImpl,TraitImpl}
1 parent 167df48 commit 4d28a9d

File tree

23 files changed

+97
-108
lines changed

23 files changed

+97
-108
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
600600
fn opt_trait_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
601601
let impl_item = tcx.opt_associated_item(def_id)?;
602602
match impl_item.container {
603-
ty::AssocItemContainer::Impl => impl_item.trait_item_def_id,
603+
ty::AssocItemContainer::TraitImpl => impl_item.trait_item_def_id,
604604
_ => None,
605605
}
606606
}

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
10091009
res = res.and(check_associated_item(tcx, def_id));
10101010
let assoc_item = tcx.associated_item(def_id);
10111011
match assoc_item.container {
1012-
ty::AssocItemContainer::Impl => {}
1012+
ty::AssocItemContainer::InherentImpl | ty::AssocItemContainer::TraitImpl => {}
10131013
ty::AssocItemContainer::Trait => {
10141014
res = res.and(check_trait_item(tcx, def_id));
10151015
}
@@ -1026,7 +1026,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
10261026
res = res.and(check_associated_item(tcx, def_id));
10271027
let assoc_item = tcx.associated_item(def_id);
10281028
match assoc_item.container {
1029-
ty::AssocItemContainer::Impl => {}
1029+
ty::AssocItemContainer::InherentImpl | ty::AssocItemContainer::TraitImpl => {}
10301030
ty::AssocItemContainer::Trait => {
10311031
res = res.and(check_trait_item(tcx, def_id));
10321032
}
@@ -1043,7 +1043,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
10431043

10441044
let assoc_item = tcx.associated_item(def_id);
10451045
let has_type = match assoc_item.container {
1046-
ty::AssocItemContainer::Impl => true,
1046+
ty::AssocItemContainer::InherentImpl | ty::AssocItemContainer::TraitImpl => true,
10471047
ty::AssocItemContainer::Trait => {
10481048
tcx.ensure_ok().explicit_item_bounds(def_id);
10491049
tcx.ensure_ok().explicit_item_self_bounds(def_id);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,9 @@ fn compare_self_type<'tcx>(
14491449

14501450
let self_string = |method: ty::AssocItem| {
14511451
let untransformed_self_ty = match method.container {
1452-
ty::AssocItemContainer::Impl => impl_trait_ref.self_ty(),
1452+
ty::AssocItemContainer::InherentImpl | ty::AssocItemContainer::TraitImpl => {
1453+
impl_trait_ref.self_ty()
1454+
}
14531455
ty::AssocItemContainer::Trait => tcx.types.self_param,
14541456
};
14551457
let self_arg_ty = tcx.fn_sig(method.def_id).instantiate_identity().input(0);
@@ -2458,8 +2460,11 @@ fn param_env_with_gat_bounds<'tcx>(
24582460

24592461
for impl_ty in impl_tys_to_install {
24602462
let trait_ty = match impl_ty.container {
2463+
ty::AssocItemContainer::InherentImpl => bug!(),
24612464
ty::AssocItemContainer::Trait => impl_ty,
2462-
ty::AssocItemContainer::Impl => tcx.associated_item(impl_ty.trait_item_def_id.unwrap()),
2465+
ty::AssocItemContainer::TraitImpl => {
2466+
tcx.associated_item(impl_ty.trait_item_def_id.unwrap())
2467+
}
24632468
};
24642469

24652470
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> =

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ pub(crate) fn check_associated_item(
949949

950950
let self_ty = match item.container {
951951
ty::AssocItemContainer::Trait => tcx.types.self_param,
952-
ty::AssocItemContainer::Impl => {
952+
ty::AssocItemContainer::InherentImpl | ty::AssocItemContainer::TraitImpl => {
953953
tcx.type_of(item.container_id(tcx)).instantiate_identity()
954954
}
955955
};

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10331033
self.set_tainted_by_errors(e);
10341034
}
10351035
}
1036-
ty::AssocItemContainer::Impl => {
1036+
ty::AssocItemContainer::InherentImpl | ty::AssocItemContainer::TraitImpl => {
10371037
if segments.len() == 1 {
10381038
// `<T>::assoc` will end up here, and so
10391039
// can `T::assoc`. If this came from an

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
290290
{
291291
if let Some(item) = tcx.opt_associated_item(def_id.into())
292292
&& let ty::AssocKind::Const { .. } = item.kind
293-
&& let ty::AssocItemContainer::Impl = item.container
293+
&& let ty::AssocItemContainer::TraitImpl = item.container
294294
&& let Some(trait_item_def_id) = item.trait_item_def_id
295295
{
296296
let impl_def_id = item.container_id(tcx);

compiler/rustc_lint/src/builtin.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ use rustc_middle::bug;
3333
use rustc_middle::lint::LevelAndSource;
3434
use rustc_middle::ty::layout::LayoutOf;
3535
use rustc_middle::ty::print::with_no_trimmed_paths;
36-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, Upcast, VariantDef};
36+
use rustc_middle::ty::{
37+
self, AssocItemContainer, Ty, TyCtxt, TypeVisitableExt, Upcast, VariantDef,
38+
};
3739
use rustc_session::lint::FutureIncompatibilityReason;
3840
// hardwired lints from rustc_lint_defs
3941
pub use rustc_session::lint::builtin::*;
@@ -60,7 +62,6 @@ use crate::lints::{
6062
BuiltinUnreachablePub, BuiltinUnsafe, BuiltinUnstableFeatures, BuiltinUnusedDocComment,
6163
BuiltinUnusedDocCommentSub, BuiltinWhileTrue, InvalidAsmLabel,
6264
};
63-
use crate::nonstandard_style::{MethodLateContext, method_context};
6465
use crate::{
6566
EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext,
6667
fluent_generated as fluent,
@@ -458,14 +459,14 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
458459
}
459460

460461
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
461-
let context = method_context(cx, impl_item.owner_id.def_id);
462+
let container = cx.tcx.associated_item(impl_item.owner_id.def_id).container;
462463

463-
match context {
464+
match container {
464465
// If the method is an impl for a trait, don't doc.
465-
MethodLateContext::TraitImpl => return,
466-
MethodLateContext::TraitAutoImpl => {}
466+
AssocItemContainer::TraitImpl => return,
467+
AssocItemContainer::Trait => {}
467468
// If the method is an impl for an item with docs_hidden, don't doc.
468-
MethodLateContext::PlainImpl => {
469+
AssocItemContainer::InherentImpl => {
469470
let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id());
470471
let impl_ty = cx.tcx.type_of(parent).instantiate_identity();
471472
let outerdef = match impl_ty.kind() {

compiler/rustc_lint/src/nonstandard_style.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId;
77
use rustc_hir::intravisit::{FnKind, Visitor};
88
use rustc_hir::{AttrArgs, AttrItem, Attribute, GenericParamKind, PatExprKind, PatKind, find_attr};
99
use rustc_middle::hir::nested_filter::All;
10-
use rustc_middle::ty;
10+
use rustc_middle::ty::AssocItemContainer;
1111
use rustc_session::config::CrateType;
1212
use rustc_session::{declare_lint, declare_lint_pass};
1313
use rustc_span::def_id::LocalDefId;
@@ -20,24 +20,6 @@ use crate::lints::{
2020
};
2121
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
2222

23-
#[derive(PartialEq)]
24-
pub(crate) enum MethodLateContext {
25-
TraitAutoImpl,
26-
TraitImpl,
27-
PlainImpl,
28-
}
29-
30-
pub(crate) fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLateContext {
31-
let item = cx.tcx.associated_item(id);
32-
match item.container {
33-
ty::AssocItemContainer::Trait => MethodLateContext::TraitAutoImpl,
34-
ty::AssocItemContainer::Impl => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) {
35-
Some(_) => MethodLateContext::TraitImpl,
36-
None => MethodLateContext::PlainImpl,
37-
},
38-
}
39-
}
40-
4123
fn assoc_item_in_trait_impl(cx: &LateContext<'_>, ii: &hir::ImplItem<'_>) -> bool {
4224
let item = cx.tcx.associated_item(ii.owner_id);
4325
item.trait_item_def_id.is_some()
@@ -397,19 +379,19 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
397379
id: LocalDefId,
398380
) {
399381
match &fk {
400-
FnKind::Method(ident, sig, ..) => match method_context(cx, id) {
401-
MethodLateContext::PlainImpl => {
382+
FnKind::Method(ident, sig, ..) => match cx.tcx.associated_item(id).container {
383+
AssocItemContainer::InherentImpl => {
402384
if sig.header.abi != ExternAbi::Rust
403385
&& find_attr!(cx.tcx.get_all_attrs(id), AttributeKind::NoMangle(..))
404386
{
405387
return;
406388
}
407389
self.check_snake_case(cx, "method", ident);
408390
}
409-
MethodLateContext::TraitAutoImpl => {
391+
AssocItemContainer::Trait => {
410392
self.check_snake_case(cx, "trait method", ident);
411393
}
412-
_ => (),
394+
AssocItemContainer::TraitImpl => {}
413395
},
414396
FnKind::ItemFn(ident, _, header) => {
415397
// Skip foreign-ABI #[no_mangle] functions (Issue #31924)

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
12541254
DefKind::AssocTy => {
12551255
let assoc_item = tcx.associated_item(def_id);
12561256
match assoc_item.container {
1257-
ty::AssocItemContainer::Impl => true,
1257+
ty::AssocItemContainer::InherentImpl | ty::AssocItemContainer::TraitImpl => true,
12581258
ty::AssocItemContainer::Trait => assoc_item.defaultness(tcx).has_value(),
12591259
}
12601260
}
@@ -1739,11 +1739,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17391739
}
17401740
}
17411741
}
1742-
AssocItemContainer::Impl => {
1742+
AssocItemContainer::TraitImpl => {
17431743
if let Some(trait_item_def_id) = item.trait_item_def_id {
17441744
self.tables.trait_item_def_id.set_some(def_id.index, trait_item_def_id.into());
17451745
}
17461746
}
1747+
AssocItemContainer::InherentImpl => {}
17471748
}
17481749
if let ty::AssocKind::Type { data: ty::AssocTypeData::Rpitit(rpitit_info) } = item.kind {
17491750
record!(self.tables.opt_rpitit_info[def_id] <- rpitit_info);

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ fixed_size_enum! {
205205

206206
fixed_size_enum! {
207207
ty::AssocItemContainer {
208-
( Trait )
209-
( Impl )
208+
( InherentImpl )
209+
( TraitImpl )
210+
( Trait )
210211
}
211212
}
212213

0 commit comments

Comments
 (0)