1
Fork 0

Fortify check for const generics.

This commit is contained in:
Camille GILLOT 2022-08-17 20:22:52 +02:00
parent 4b16214163
commit be2641a61f

View file

@ -1453,16 +1453,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.enumerate() .enumerate()
.skip(1) // Remove `Self` for `ExistentialPredicate`. .skip(1) // Remove `Self` for `ExistentialPredicate`.
.map(|(index, arg)| { .map(|(index, arg)| {
if let ty::GenericArgKind::Type(ty) = arg.unpack() { if arg == dummy_self.into() {
debug!(?ty); let param = &generics.params[index];
if ty == dummy_self { missing_type_params.push(param.name);
let param = &generics.params[index]; return tcx.ty_error().into();
missing_type_params.push(param.name); } else if arg.walk().any(|arg| arg == dummy_self.into()) {
return tcx.ty_error().into(); references_self = true;
} else if ty.walk().any(|arg| arg == dummy_self.into()) { return tcx.ty_error().into();
references_self = true;
return tcx.ty_error().into();
}
} }
arg arg
}) })
@ -1509,10 +1506,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// Like for trait refs, verify that `dummy_self` did not leak inside default type // Like for trait refs, verify that `dummy_self` did not leak inside default type
// parameters. // parameters.
let references_self = b.projection_ty.substs.iter().skip(1).any(|arg| { let references_self = b.projection_ty.substs.iter().skip(1).any(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.unpack() { if arg.walk().any(|arg| arg == dummy_self.into()) {
if ty == dummy_self || ty.walk().any(|arg| arg == dummy_self.into()) { return true;
return true;
}
} }
false false
}); });
@ -1524,7 +1519,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.substs .substs
.iter() .iter()
.map(|arg| { .map(|arg| {
if let ty::GenericArgKind::Type(_) = arg.unpack() { if arg.walk().any(|arg| arg == dummy_self.into()) {
return tcx.ty_error().into(); return tcx.ty_error().into();
} }
arg arg