diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-12-14 04:09:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-14 04:09:36 +0100 |
| commit | c55a97ed849a0579e7bc71b5ba8b96ce74128656 (patch) | |
| tree | 215066979eb0426d43ebfb574c65c389125b0296 /compiler/rustc_middle/src | |
| parent | 2fc9ce70804bf610fd9d59410c0a367aba35eba2 (diff) | |
| parent | efb66e7e385da37015925b23c199efdf3b246d35 (diff) | |
| download | rust-c55a97ed849a0579e7bc71b5ba8b96ce74128656.tar.gz rust-c55a97ed849a0579e7bc71b5ba8b96ce74128656.zip | |
Rollup merge of #134265 - compiler-errors:ty_def_id, r=oli-obk
Rename `ty_def_id` so people will stop using it by accident This function is just for cycle detection, but people keep using it because they think it's the right way of getting the def id from a `Ty` (and I can't blame them necessarily).
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/query/keys.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/values.rs | 6 |
2 files changed, 9 insertions, 8 deletions
diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 970dc72e1ff..66fec2dd0f7 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -41,7 +41,8 @@ pub trait Key: Sized { None } - fn ty_def_id(&self) -> Option<DefId> { + /// Used to detect when ADT def ids are used as keys in a cycle for better error reporting. + fn def_id_for_ty_in_cycle(&self) -> Option<DefId> { None } } @@ -423,7 +424,7 @@ impl<'tcx> Key for Ty<'tcx> { DUMMY_SP } - fn ty_def_id(&self) -> Option<DefId> { + fn def_id_for_ty_in_cycle(&self) -> Option<DefId> { match *self.kind() { ty::Adt(adt, _) => Some(adt.did()), ty::Coroutine(def_id, ..) => Some(def_id), @@ -471,8 +472,8 @@ impl<'tcx, T: Key> Key for ty::PseudoCanonicalInput<'tcx, T> { self.value.default_span(tcx) } - fn ty_def_id(&self) -> Option<DefId> { - self.value.ty_def_id() + fn def_id_for_ty_in_cycle(&self) -> Option<DefId> { + self.value.def_id_for_ty_in_cycle() } } @@ -593,7 +594,7 @@ impl<'tcx> Key for (ValidityRequirement, ty::PseudoCanonicalInput<'tcx, Ty<'tcx> DUMMY_SP } - fn ty_def_id(&self) -> Option<DefId> { + fn def_id_for_ty_in_cycle(&self) -> Option<DefId> { match self.1.value.kind() { ty::Adt(adt, _) => Some(adt.did()), _ => None, diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index 48d744a9ef6..390909bb0ab 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -100,7 +100,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for Representability { } for info in &cycle_error.cycle { if info.query.dep_kind == dep_kinds::representability_adt_ty - && let Some(def_id) = info.query.ty_def_id + && let Some(def_id) = info.query.def_id_for_ty_in_cycle && let Some(def_id) = def_id.as_local() && !item_and_field_ids.iter().any(|&(id, _)| id == def_id) { @@ -182,7 +182,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>> &cycle_error.cycle, |cycle| { if cycle[0].query.dep_kind == dep_kinds::layout_of - && let Some(def_id) = cycle[0].query.ty_def_id + && let Some(def_id) = cycle[0].query.def_id_for_ty_in_cycle && let Some(def_id) = def_id.as_local() && let def_kind = tcx.def_kind(def_id) && matches!(def_kind, DefKind::Closure) @@ -209,7 +209,7 @@ impl<'tcx, T> Value<TyCtxt<'tcx>> for Result<T, &'_ ty::layout::LayoutError<'_>> if frame.query.dep_kind != dep_kinds::layout_of { continue; } - let Some(frame_def_id) = frame.query.ty_def_id else { + let Some(frame_def_id) = frame.query.def_id_for_ty_in_cycle else { continue; }; let Some(frame_coroutine_kind) = tcx.coroutine_kind(frame_def_id) else { |
