Skip to content

Commit e6a14c0

Browse files
committed
Use default params until effects in desugaring
1 parent 0a83e43 commit e6a14c0

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

compiler/rustc_hir_analysis/src/astconv/generics.rs

+25
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,31 @@ pub fn create_args_for_parent_generic_args<'tcx, 'a>(
243243
match (args_iter.peek(), params.peek()) {
244244
(Some(&arg), Some(&param)) => {
245245
match (arg, &param.kind, arg_count.explicit_late_bound) {
246+
(
247+
GenericArg::Const(hir::ConstArg {
248+
is_desugared_from_effects: true,
249+
..
250+
}),
251+
GenericParamDefKind::Const { is_host_effect: false, .. }
252+
| GenericParamDefKind::Type { .. }
253+
| GenericParamDefKind::Lifetime,
254+
_,
255+
) => {
256+
// SPECIAL CASE FOR DESUGARED EFFECT PARAMS
257+
// This comes from the following example:
258+
//
259+
// ```
260+
// #[const_trait]
261+
// pub trait PartialEq<Rhs: ?Sized = Self> {}
262+
// impl const PartialEq for () {}
263+
// ```
264+
//
265+
// Since this is a const impl, we need to insert `<false>` at the end of
266+
// `PartialEq`'s generics, but this errors since `Rhs` isn't specified.
267+
// To work around this, we infer all arguments until we reach the host param.
268+
args.push(ctx.inferred_kind(Some(&args), param, infer_args));
269+
params.next();
270+
}
246271
(GenericArg::Lifetime(_), GenericParamDefKind::Lifetime, _)
247272
| (
248273
GenericArg::Type(_) | GenericArg::Infer(_),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Ensure that we don't get a mismatch error when inserting the host param
2+
// at the end of generic args when the generics have defaulted params.
3+
//
4+
// check-pass
5+
6+
#![feature(const_trait_impl, effects)]
7+
8+
#[const_trait]
9+
pub trait Foo<Rhs: ?Sized = Self> {
10+
/* stuff */
11+
}
12+
13+
impl const Foo for () {}
14+
15+
fn main() {}

tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ trait Add<Rhs = Self> {
2121
fn add(self, rhs: Rhs) -> Self::Output;
2222
}
2323

24-
// FIXME(effects) we shouldn't need to have to specify `Rhs`.
25-
impl const Add<i32> for i32 {
24+
impl const Add for i32 {
2625
type Output = i32;
2726
fn add(self, rhs: i32) -> i32 {
2827
loop {}
@@ -353,8 +352,7 @@ where
353352
}
354353
}
355354

356-
// FIXME(effects): again, this should not error without Rhs specified
357-
impl PartialEq<str> for str {
355+
impl PartialEq for str {
358356
fn eq(&self, other: &str) -> bool {
359357
loop {}
360358
}

tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0493]: destructor of `Self` cannot be evaluated at compile-time
2-
--> $DIR/minicore.rs:503:9
2+
--> $DIR/minicore.rs:501:9
33
|
44
LL | *self = source.clone()
55
| ^^^^^
@@ -8,7 +8,7 @@ LL | *self = source.clone()
88
| value is dropped here
99

1010
error[E0493]: destructor of `T` cannot be evaluated at compile-time
11-
--> $DIR/minicore.rs:513:35
11+
--> $DIR/minicore.rs:511:35
1212
|
1313
LL | const fn drop<T: ~const Destruct>(_: T) {}
1414
| ^ - value is dropped here

0 commit comments

Comments
 (0)