Improve error messages for generics with default parameters
Fixes #120785
This commit is contained in:
parent
c475e2303b
commit
49961947c8
4 changed files with 82 additions and 4 deletions
|
@ -360,6 +360,33 @@ impl<'tcx> Generics {
|
|||
let own = &args[self.parent_count..][..self.params.len()];
|
||||
if self.has_self && self.parent.is_none() { &own[1..] } else { own }
|
||||
}
|
||||
|
||||
/// Returns true if a concrete type is specified after a default type.
|
||||
/// For example, consider `struct T<W = usize, X = Vec<W>>(W, X)`
|
||||
/// `T<usize, String>` will return true
|
||||
/// `T<usize>` will return false
|
||||
pub fn check_concrete_type_after_default(
|
||||
&'tcx self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
args: &'tcx [ty::GenericArg<'tcx>],
|
||||
) -> bool {
|
||||
let mut default_param_seen = false;
|
||||
for param in self.params.iter() {
|
||||
if param
|
||||
.default_value(tcx)
|
||||
.is_some_and(|default| default.instantiate(tcx, args) == args[param.index as usize])
|
||||
{
|
||||
default_param_seen = true;
|
||||
} else if default_param_seen
|
||||
&& param.default_value(tcx).is_some_and(|default| {
|
||||
default.instantiate(tcx, args) != args[param.index as usize]
|
||||
})
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Bounds on generics.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue