diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2024-12-10 10:12:36 +0000 |
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2024-12-11 11:07:02 +0000 |
| commit | c0e0d8f8746740768c13bdb632d7b7f1fef2f17a (patch) | |
| tree | 616c629311c93757c7f769cfef2af751f9a624c5 /compiler/rustc_middle | |
| parent | 3d0bf6862590808edffb10994a504c1018ba8501 (diff) | |
| download | rust-c0e0d8f8746740768c13bdb632d7b7f1fef2f17a.tar.gz rust-c0e0d8f8746740768c13bdb632d7b7f1fef2f17a.zip | |
Require the `constness` query to only be invoked on things that can have constness
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 14 |
2 files changed, 15 insertions, 3 deletions
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index fc3d690a8a9..ec44801ea91 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -746,7 +746,9 @@ rustc_queries! { desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) } } - /// Returns `true` if this is a const fn / const impl. + /// Returns the constness of functions and impls. + /// + /// Will ICE if used on things that are always const or never const. /// /// **Do not call this function manually.** It is only meant to cache the base data for the /// higher-level functions. Consider using `is_const_fn` or `is_const_trait_impl` instead. diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 70e0568b202..4f08d9e4251 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2014,7 +2014,17 @@ impl<'tcx> TyCtxt<'tcx> { self.constness(def_id) == hir::Constness::Const } DefKind::Trait => self.is_const_trait(def_id), - DefKind::AssocTy | DefKind::AssocFn => { + DefKind::AssocTy => { + let parent_def_id = self.parent(def_id); + match self.def_kind(parent_def_id) { + DefKind::Impl { of_trait: false } => false, + DefKind::Impl { of_trait: true } | DefKind::Trait => { + self.is_conditionally_const(parent_def_id) + } + _ => bug!("unexpected parent item of associated type: {parent_def_id:?}"), + } + } + DefKind::AssocFn => { let parent_def_id = self.parent(def_id); match self.def_kind(parent_def_id) { DefKind::Impl { of_trait: false } => { @@ -2023,7 +2033,7 @@ impl<'tcx> TyCtxt<'tcx> { DefKind::Impl { of_trait: true } | DefKind::Trait => { self.is_conditionally_const(parent_def_id) } - _ => bug!("unexpected parent item of associated item: {parent_def_id:?}"), + _ => bug!("unexpected parent item of associated fn: {parent_def_id:?}"), } } DefKind::OpaqueTy => match self.opaque_ty_origin(def_id) { |
