diff options
| author | Michael Goulet <michael@errs.io> | 2025-03-30 03:40:14 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-04-09 20:26:58 +0000 |
| commit | 830aeb610289924b5910f409f6751fcf4e497f1e (patch) | |
| tree | 6f159ee38305150b708ef9c7794aa2d08423d739 /compiler/rustc_middle/src | |
| parent | ccdfd310be12f0c46be8b3266b3ff4e2ce5b3806 (diff) | |
Use a query rather than recomputing the tail repeatedly
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 37 |
3 files changed, 11 insertions, 37 deletions
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index a1df27ac788..40d0028db86 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1026,6 +1026,13 @@ rustc_queries! { separate_provide_extern } + /// Given an `impl_def_id`, return true if the self type is guaranteed to be unsized due + /// to either being one of the built-in unsized types (str/slice/dyn) or to be a struct + /// whose tail is one of those types. + query impl_self_is_guaranteed_unsized(impl_def_id: DefId) -> bool { + desc { |tcx| "computing whether `{}` has a guaranteed unsized self type", tcx.def_path_str(impl_def_id) } + } + /// Maps a `DefId` of a type to a list of its inherent impls. /// Contains implementations of methods that are inherent to a type. /// Methods in these implementations don't need to be exported. diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 162ca1f4af8..abf6cbbcd87 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -437,6 +437,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> { ) } + fn impl_self_is_guaranteed_unsized(self, impl_def_id: DefId) -> bool { + self.impl_self_is_guaranteed_unsized(impl_def_id) + } + fn has_target_features(self, def_id: DefId) -> bool { !self.codegen_fn_attrs(def_id).target_features.is_empty() } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index fb15ab8d848..27ee363f1c1 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -2029,43 +2029,6 @@ impl<'tcx> Ty<'tcx> { pub fn is_known_rigid(self) -> bool { self.kind().is_known_rigid() } - - /// Returns true if the type is guaranteed to be one of the three built-in unsized types: - /// `dyn Trait`/`[T]`/`str`. This function is *raw* because it does not compute the struct - /// tail of the type, so you are responsible for doing that yourself. - // NOTE: Keep this in sync with `rustc_type_ir`'s copy. - pub fn is_guaranteed_unsized_raw(self) -> bool { - match self.kind() { - Dynamic(_, _, ty::Dyn) | ty::Slice(_) | ty::Str => true, - Bool - | Char - | Int(_) - | Uint(_) - | Float(_) - | Adt(_, _) - | Foreign(_) - | Array(_, _) - | Pat(_, _) - | RawPtr(_, _) - | Ref(_, _, _) - | FnDef(_, _) - | FnPtr(_, _) - | UnsafeBinder(_) - | Closure(_, _) - | CoroutineClosure(_, _) - | Coroutine(_, _) - | CoroutineWitness(_, _) - | Never - | Tuple(_) - | Alias(_, _) - | Param(_) - | Bound(_, _) - | Placeholder(_) - | Infer(_) - | Error(_) - | Dynamic(_, _, ty::DynStar) => false, - } - } } impl<'tcx> rustc_type_ir::inherent::Tys<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx>> { |
