summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/ty/generics.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_middle/src/ty/generics.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_middle/src/ty/generics.rs')
-rw-r--r--compiler/rustc_middle/src/ty/generics.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs
index 8e6c1cd4b..888ee1d23 100644
--- a/compiler/rustc_middle/src/ty/generics.rs
+++ b/compiler/rustc_middle/src/ty/generics.rs
@@ -79,6 +79,10 @@ impl GenericParamDef {
}
}
+ pub fn is_host_effect(&self) -> bool {
+ matches!(self.kind, GenericParamDefKind::Const { is_host_effect: true, .. })
+ }
+
pub fn default_value<'tcx>(
&self,
tcx: TyCtxt<'tcx>,
@@ -233,6 +237,20 @@ impl<'tcx> Generics {
}
}
+ /// Returns the `GenericParamDef` with the given index if available.
+ pub fn opt_param_at(
+ &'tcx self,
+ param_index: usize,
+ tcx: TyCtxt<'tcx>,
+ ) -> Option<&'tcx GenericParamDef> {
+ if let Some(index) = param_index.checked_sub(self.parent_count) {
+ self.params.get(index)
+ } else {
+ tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
+ .opt_param_at(param_index, tcx)
+ }
+ }
+
pub fn params_to(&'tcx self, param_index: usize, tcx: TyCtxt<'tcx>) -> &'tcx [GenericParamDef] {
if let Some(index) = param_index.checked_sub(self.parent_count) {
&self.params[..index]
@@ -264,6 +282,20 @@ impl<'tcx> Generics {
}
}
+ /// Returns the `GenericParamDef` associated with this `ParamTy` if it belongs to this
+ /// `Generics`.
+ pub fn opt_type_param(
+ &'tcx self,
+ param: &ParamTy,
+ tcx: TyCtxt<'tcx>,
+ ) -> Option<&'tcx GenericParamDef> {
+ let param = self.opt_param_at(param.index as usize, tcx)?;
+ match param.kind {
+ GenericParamDefKind::Type { .. } => Some(param),
+ _ => None,
+ }
+ }
+
/// Returns the `GenericParamDef` associated with this `ParamConst`.
pub fn const_param(&'tcx self, param: &ParamConst, tcx: TyCtxt<'tcx>) -> &GenericParamDef {
let param = self.param_at(param.index as usize, tcx);