Rollup merge of #118608 - fee1-dead-contrib:backdoor-in-askconv, r=compiler-errors

Use default params until effects in desugaring

See the comment and [this section](https://fee1-dead.github.io/devlog001/#effects-desugaring-with-default-type-params) from my blog post

r? ``@compiler-errors``
This commit is contained in:
Matthias Krüger 2023-12-05 16:08:37 +01:00 committed by GitHub
commit c6c0c658df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 6 deletions

View File

@ -243,6 +243,31 @@ pub fn create_args_for_parent_generic_args<'tcx, 'a>(
match (args_iter.peek(), params.peek()) { match (args_iter.peek(), params.peek()) {
(Some(&arg), Some(&param)) => { (Some(&arg), Some(&param)) => {
match (arg, &param.kind, arg_count.explicit_late_bound) { match (arg, &param.kind, arg_count.explicit_late_bound) {
(
GenericArg::Const(hir::ConstArg {
is_desugared_from_effects: true,
..
}),
GenericParamDefKind::Const { is_host_effect: false, .. }
| GenericParamDefKind::Type { .. }
| GenericParamDefKind::Lifetime,
_,
) => {
// SPECIAL CASE FOR DESUGARED EFFECT PARAMS
// This comes from the following example:
//
// ```
// #[const_trait]
// pub trait PartialEq<Rhs: ?Sized = Self> {}
// impl const PartialEq for () {}
// ```
//
// Since this is a const impl, we need to insert `<false>` at the end of
// `PartialEq`'s generics, but this errors since `Rhs` isn't specified.
// To work around this, we infer all arguments until we reach the host param.
args.push(ctx.inferred_kind(Some(&args), param, infer_args));
params.next();
}
(GenericArg::Lifetime(_), GenericParamDefKind::Lifetime, _) (GenericArg::Lifetime(_), GenericParamDefKind::Lifetime, _)
| ( | (
GenericArg::Type(_) | GenericArg::Infer(_), GenericArg::Type(_) | GenericArg::Infer(_),

View File

@ -0,0 +1,15 @@
// Ensure that we don't get a mismatch error when inserting the host param
// at the end of generic args when the generics have defaulted params.
//
// check-pass
#![feature(const_trait_impl, effects)]
#[const_trait]
pub trait Foo<Rhs: ?Sized = Self> {
/* stuff */
}
impl const Foo for () {}
fn main() {}

View File

@ -21,8 +21,7 @@ trait Add<Rhs = Self> {
fn add(self, rhs: Rhs) -> Self::Output; fn add(self, rhs: Rhs) -> Self::Output;
} }
// FIXME(effects) we shouldn't need to have to specify `Rhs`. impl const Add for i32 {
impl const Add<i32> for i32 {
type Output = i32; type Output = i32;
fn add(self, rhs: i32) -> i32 { fn add(self, rhs: i32) -> i32 {
loop {} loop {}
@ -353,8 +352,7 @@ fn eq(&self, other: &&B) -> bool {
} }
} }
// FIXME(effects): again, this should not error without Rhs specified impl PartialEq for str {
impl PartialEq<str> for str {
fn eq(&self, other: &str) -> bool { fn eq(&self, other: &str) -> bool {
loop {} loop {}
} }

View File

@ -1,5 +1,5 @@
error[E0493]: destructor of `Self` cannot be evaluated at compile-time error[E0493]: destructor of `Self` cannot be evaluated at compile-time
--> $DIR/minicore.rs:503:9 --> $DIR/minicore.rs:501:9
| |
LL | *self = source.clone() LL | *self = source.clone()
| ^^^^^ | ^^^^^
@ -8,7 +8,7 @@ LL | *self = source.clone()
| value is dropped here | value is dropped here
error[E0493]: destructor of `T` cannot be evaluated at compile-time error[E0493]: destructor of `T` cannot be evaluated at compile-time
--> $DIR/minicore.rs:513:35 --> $DIR/minicore.rs:511:35
| |
LL | const fn drop<T: ~const Destruct>(_: T) {} LL | const fn drop<T: ~const Destruct>(_: T) {}
| ^ - value is dropped here | ^ - value is dropped here