Introduce helper ty::Generics::has_own_self

This commit is contained in:
León Orell Valerian Liehr 2026-02-06 23:45:57 +01:00
parent 38c71295e8
commit 5ea37f7add
No known key found for this signature in database
GPG key ID: D17A07215F68E713
4 changed files with 9 additions and 6 deletions

View file

@ -393,8 +393,7 @@ pub fn check_generic_arg_count_for_call(
IsMethodCall::Yes => GenericArgPosition::MethodCall,
IsMethodCall::No => GenericArgPosition::Value,
};
let has_self = generics.parent.is_none() && generics.has_self;
check_generic_arg_count(cx, def_id, seg, generics, gen_pos, has_self)
check_generic_arg_count(cx, def_id, seg, generics, gen_pos, generics.has_own_self())
}
/// Checks that the correct number of generic arguments have been provided.

View file

@ -284,7 +284,7 @@ impl<'tcx> Generics {
args: &'a [ty::GenericArg<'tcx>],
) -> &'a [ty::GenericArg<'tcx>] {
let mut own_params = self.parent_count..self.count();
if self.has_self && self.parent.is_none() {
if self.has_own_self() {
own_params.start = 1;
}
@ -316,7 +316,7 @@ impl<'tcx> Generics {
args: &'tcx [ty::GenericArg<'tcx>],
) -> &'tcx [ty::GenericArg<'tcx>] {
let own = &args[self.parent_count..][..self.own_params.len()];
if self.has_self && self.parent.is_none() { &own[1..] } else { own }
if self.has_own_self() { &own[1..] } else { own }
}
/// Returns true if a concrete type is specified after a default type.
@ -350,6 +350,10 @@ impl<'tcx> Generics {
pub fn is_own_empty(&'tcx self) -> bool {
self.own_params.is_empty()
}
pub fn has_own_self(&'tcx self) -> bool {
self.has_self && self.parent.is_none()
}
}
/// Bounds on generics.

View file

@ -1263,7 +1263,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
.iter()
.position(|&arg| self.generic_arg_contains_target(arg))
{
if generics.parent.is_none() && generics.has_self {
if generics.has_own_self() {
argument_index += 1;
}
let args = self.tecx.resolve_vars_if_possible(args);

View file

@ -105,7 +105,7 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
// to align the arguments and parameters for the iteration below and to enable us to correctly
// instantiate the generic parameter default later.
let generics = cx.tcx.generics_of(owner);
let args = if !has_self && generics.parent.is_none() && generics.has_self {
let args = if !has_self && generics.has_own_self() {
has_self = true;
[cx.tcx.types.trait_object_dummy_self.into()]
.into_iter()