Skip to content

Commit 9883ea3

Browse files
Rename ty_def_id so people will stop using it by accident
1 parent 4847d6a commit 9883ea3

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
10071007
)),
10081008
..
10091009
}) = node
1010-
&& let Some(ty_def_id) = qself_ty.ty_def_id()
1011-
&& let [inherent_impl] = tcx.inherent_impls(ty_def_id)
1010+
&& let Some(adt_def) = qself_ty.ty_adt_def()
1011+
&& let [inherent_impl] = tcx.inherent_impls(adt_def.did)
10121012
&& let name = format!("{ident2}_{ident3}")
10131013
&& let Some(ty::AssocItem { kind: ty::AssocKind::Fn, .. }) = tcx
10141014
.associated_items(inherent_impl)

compiler/rustc_middle/src/query/keys.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ pub trait Key: Sized {
4141
None
4242
}
4343

44-
fn ty_def_id(&self) -> Option<DefId> {
44+
/// Used to detect when ADT def ids are used as keys in a cycle for better error reporting.
45+
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
4546
None
4647
}
4748
}
@@ -423,7 +424,7 @@ impl<'tcx> Key for Ty<'tcx> {
423424
DUMMY_SP
424425
}
425426

426-
fn ty_def_id(&self) -> Option<DefId> {
427+
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
427428
match *self.kind() {
428429
ty::Adt(adt, _) => Some(adt.did()),
429430
ty::Coroutine(def_id, ..) => Some(def_id),
@@ -471,8 +472,8 @@ impl<'tcx, T: Key> Key for ty::PseudoCanonicalInput<'tcx, T> {
471472
self.value.default_span(tcx)
472473
}
473474

474-
fn ty_def_id(&self) -> Option<DefId> {
475-
self.value.ty_def_id()
475+
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
476+
self.value.def_id_for_ty_in_cycle()
476477
}
477478
}
478479

@@ -593,7 +594,7 @@ impl<'tcx> Key for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx>
593594
DUMMY_SP
594595
}
595596

596-
fn ty_def_id(&self) -> Option<DefId> {
597+
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
597598
match self.1.value.kind() {
598599
ty::Adt(adt, _) => Some(adt.did()),
599600
_ => None,

compiler/rustc_middle/src/values.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability {
100100
}
101101
for info in &cycle_error.cycle {
102102
if info.query.dep_kind == dep_kinds::representability_adt_ty
103-
&& let Some(def_id) = info.query.ty_def_id
103+
&& let Some(def_id) = info.query.def_id_for_ty_in_cycle
104104
&& let Some(def_id) = def_id.as_local()
105105
&& !item_and_field_ids.iter().any(|&(id, _)| id == def_id)
106106
{
@@ -182,7 +182,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
182182
&cycle_error.cycle,
183183
|cycle| {
184184
if cycle[0].query.dep_kind == dep_kinds::layout_of
185-
&& let Some(def_id) = cycle[0].query.ty_def_id
185+
&& let Some(def_id) = cycle[0].query.def_id_for_ty_in_cycle
186186
&& let Some(def_id) = def_id.as_local()
187187
&& let def_kind = tcx.def_kind(def_id)
188188
&& matches!(def_kind, DefKind::Closure)
@@ -209,7 +209,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>>
209209
if frame.query.dep_kind != dep_kinds::layout_of {
210210
continue;
211211
}
212-
let Some(frame_def_id) = frame.query.ty_def_id else {
212+
let Some(frame_def_id) = frame.query.def_id_for_ty_in_cycle else {
213213
continue;
214214
};
215215
let Some(frame_coroutine_kind) = tcx.coroutine_kind(frame_def_id) else {

compiler/rustc_query_impl/src/plumbing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ pub(crate) fn create_query_frame<
349349
hasher.finish::<Hash64>()
350350
})
351351
};
352-
let ty_def_id = key.ty_def_id();
352+
let def_id_for_ty_in_cycle = key.def_id_for_ty_in_cycle();
353353

354-
QueryStackFrame::new(description, span, def_id, def_kind, kind, ty_def_id, hash)
354+
QueryStackFrame::new(description, span, def_id, def_kind, kind, def_id_for_ty_in_cycle, hash)
355355
}
356356

357357
pub(crate) fn encode_query_results<'a, 'tcx, Q>(

compiler/rustc_query_system/src/query/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct QueryStackFrame {
3333
pub def_id: Option<DefId>,
3434
pub def_kind: Option<DefKind>,
3535
/// A def-id that is extracted from a `Ty` in a query key
36-
pub ty_def_id: Option<DefId>,
36+
pub def_id_for_ty_in_cycle: Option<DefId>,
3737
pub dep_kind: DepKind,
3838
/// This hash is used to deterministically pick
3939
/// a query to remove cycles in the parallel compiler.
@@ -48,10 +48,10 @@ impl QueryStackFrame {
4848
def_id: Option<DefId>,
4949
def_kind: Option<DefKind>,
5050
dep_kind: DepKind,
51-
ty_def_id: Option<DefId>,
51+
def_id_for_ty_in_cycle: Option<DefId>,
5252
hash: impl FnOnce() -> Hash64,
5353
) -> Self {
54-
Self { description, span, def_id, def_kind, ty_def_id, dep_kind, hash: hash() }
54+
Self { description, span, def_id, def_kind, def_id_for_ty_in_cycle, dep_kind, hash: hash() }
5555
}
5656

5757
// FIXME(eddyb) Get more valid `Span`s on queries.

src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, a
4444
if name == "filter_map"
4545
&& let hir::ExprKind::Call(expr, args) = body.value.kind
4646
&& is_res_lang_ctor(cx, path_res(cx, expr), OptionSome)
47-
&& arg_id.ty_def_id() == args[0].hir_id().ty_def_id()
4847
&& let hir::ExprKind::Path(_) = args[0].kind
4948
{
5049
span_lint_and_sugg(

0 commit comments

Comments
 (0)