Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e110231

Browse files
committed
Improve AdtDef interning.
This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`.
1 parent a4d6c61 commit e110231

Some content is hidden

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

42 files changed

+93
-92
lines changed

clippy_lints/src/await_holding_invalid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl LateLintPass<'_> for AwaitHolding {
149149
fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorTypeCause<'_>], span: Span) {
150150
for ty_cause in ty_causes {
151151
if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind() {
152-
if is_mutex_guard(cx, adt.did) {
152+
if is_mutex_guard(cx, adt.did()) {
153153
span_lint_and_then(
154154
cx,
155155
AWAIT_HOLDING_LOCK,
@@ -167,7 +167,7 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType
167167
},
168168
);
169169
}
170-
if is_refcell_ref(cx, adt.did) {
170+
if is_refcell_ref(cx, adt.did()) {
171171
span_lint_and_then(
172172
cx,
173173
AWAIT_HOLDING_REFCELL_REF,

clippy_lints/src/case_sensitive_file_extension_comparisons.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use if_chain::if_chain;
33
use rustc_ast::ast::LitKind;
4+
use rustc_data_structures::intern::Interned;
45
use rustc_hir::{Expr, ExprKind, PathSegment};
56
use rustc_lint::{LateContext, LateLintPass};
67
use rustc_middle::ty;
@@ -55,7 +56,7 @@ fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: &
5556
ty::Str => {
5657
return Some(span);
5758
},
58-
ty::Adt(&ty::AdtDef { did, .. }, _) => {
59+
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did, .. }, _)), _) => {
5960
if ctx.tcx.is_diagnostic_item(sym::String, did) {
6061
return Some(span);
6162
}

clippy_lints/src/casts/cast_possible_truncation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
116116
&& let Res::Def(DefKind::Ctor(..), id) = cx.qpath_res(p, cast_expr.hir_id)
117117
{
118118
let i = def.variant_index_with_ctor_id(id);
119-
let variant = &def.variants[i];
120-
let nbits = utils::enum_value_nbits(get_discriminant_value(cx.tcx, def, i));
119+
let variant = def.variant(i);
120+
let nbits = utils::enum_value_nbits(get_discriminant_value(cx.tcx, *def, i));
121121
(nbits, Some(variant))
122122
} else {
123-
(utils::enum_ty_to_nbits(def, cx.tcx), None)
123+
(utils::enum_ty_to_nbits(*def, cx.tcx), None)
124124
};
125125
let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx);
126126

127-
let cast_from_ptr_size = def.repr.int.map_or(true, |ty| {
127+
let cast_from_ptr_size = def.repr().int.map_or(true, |ty| {
128128
matches!(
129129
ty,
130130
IntType::SignedInt(ast::IntTy::Isize) | IntType::UnsignedInt(ast::UintTy::Usize)

clippy_lints/src/casts/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ pub(super) fn enum_value_nbits(value: EnumValue) -> u64 {
3434
.into()
3535
}
3636

37-
pub(super) fn enum_ty_to_nbits(adt: &AdtDef, tcx: TyCtxt<'_>) -> u64 {
37+
pub(super) fn enum_ty_to_nbits(adt: AdtDef<'_>, tcx: TyCtxt<'_>) -> u64 {
3838
let mut explicit = 0i128;
3939
let (start, end) = adt
40-
.variants
40+
.variants()
4141
.iter()
4242
.fold((0, i128::MIN), |(start, end), variant| match variant.discr {
4343
VariantDiscr::Relative(x) => match explicit.checked_add(i128::from(x)) {

clippy_lints/src/default.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
9696
then {
9797
// TODO: Work out a way to put "whatever the imported way of referencing
9898
// this type in this file" rather than a fully-qualified type.
99-
let replacement = format!("{}::default()", cx.tcx.def_path_str(def.did));
99+
let replacement = format!("{}::default()", cx.tcx.def_path_str(def.did()));
100100
span_lint_and_sugg(
101101
cx,
102102
DEFAULT_TRAIT_ACCESS,
@@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
137137
if let Some(adt) = binding_type.ty_adt_def();
138138
if adt.is_struct();
139139
let variant = adt.non_enum_variant();
140-
if adt.did.is_local() || !variant.is_field_list_non_exhaustive();
140+
if adt.did().is_local() || !variant.is_field_list_non_exhaustive();
141141
let module_did = cx.tcx.parent_module(stmt.hir_id).to_def_id();
142142
if variant
143143
.fields
@@ -216,7 +216,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
216216
if let ty::Adt(adt_def, substs) = binding_type.kind();
217217
if !substs.is_empty();
218218
then {
219-
let adt_def_ty_name = cx.tcx.item_name(adt_def.did);
219+
let adt_def_ty_name = cx.tcx.item_name(adt_def.did());
220220
let generic_args = substs.iter().collect::<Vec<_>>();
221221
let tys_str = generic_args
222222
.iter()

clippy_lints/src/default_numeric_fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
148148
if_chain! {
149149
if let Some(adt_def) = ty.ty_adt_def();
150150
if adt_def.is_struct();
151-
if let Some(variant) = adt_def.variants.iter().next();
151+
if let Some(variant) = adt_def.variants().iter().next();
152152
then {
153153
let fields_def = &variant.fields;
154154

clippy_lints/src/derivable_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
103103
_ => false,
104104
};
105105
if should_emit {
106-
let path_string = cx.tcx.def_path_str(adt_def.did);
106+
let path_string = cx.tcx.def_path_str(adt_def.did());
107107
span_lint_and_help(
108108
cx,
109109
DERIVABLE_IMPLS,

clippy_lints/src/derive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &T
315315
let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(&copy_id).map_or(false, |impls| {
316316
impls
317317
.iter()
318-
.any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did == adt.did))
318+
.any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did()))
319319
});
320320
if !has_copy_impl {
321321
return;
@@ -357,10 +357,10 @@ fn check_unsafe_derive_deserialize<'tcx>(
357357
if let Some(trait_def_id) = trait_ref.trait_def_id();
358358
if match_def_path(cx, trait_def_id, &paths::SERDE_DESERIALIZE);
359359
if let ty::Adt(def, _) = ty.kind();
360-
if let Some(local_def_id) = def.did.as_local();
360+
if let Some(local_def_id) = def.did().as_local();
361361
let adt_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
362362
if !is_lint_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id);
363-
if cx.tcx.inherent_impls(def.did)
363+
if cx.tcx.inherent_impls(def.did())
364364
.iter()
365365
.map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local()))
366366
.any(|imp| has_unsafe(cx, imp));

clippy_lints/src/empty_enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
5252
if let ItemKind::Enum(..) = item.kind {
5353
let ty = cx.tcx.type_of(item.def_id);
5454
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
55-
if adt.variants.is_empty() {
55+
if adt.variants().is_empty() {
5656
span_lint_and_help(
5757
cx,
5858
EMPTY_ENUM,

clippy_lints/src/enum_clike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
5555
if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) {
5656
if let ty::Adt(adt, _) = ty.kind() {
5757
if adt.is_enum() {
58-
ty = adt.repr.discr_type().to_ty(cx.tcx);
58+
ty = adt.repr().discr_type().to_ty(cx.tcx);
5959
}
6060
}
6161
match ty.kind() {

0 commit comments

Comments
 (0)