Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1e84163

Browse files
Rollup merge of #124080 - oli-obk:define_opaque_types10, r=compiler-errors
Some unstable changes to where opaque types get defined None of these can be reached from stable afaict. r? ``@compiler-errors`` cc #116652
2 parents 7fb8122 + 4387eea commit 1e84163

35 files changed

+364
-122
lines changed

‎compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
25392539
let InferOk { obligations, .. } = self
25402540
.infcx
25412541
.at(&cause, obligation.param_env)
2542-
.eq(DefineOpaqueTypes::No, placeholder_obligation_trait_ref, impl_trait_ref)
2542+
.eq(DefineOpaqueTypes::Yes, placeholder_obligation_trait_ref, impl_trait_ref)
25432543
.map_err(|e| {
25442544
debug!("match_impl: failed eq_trait_refs due to `{}`", e.to_string(self.tcx()))
25452545
})?;
@@ -2594,7 +2594,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
25942594
self.infcx
25952595
.at(&obligation.cause, obligation.param_env)
25962596
.eq(
2597-
DefineOpaqueTypes::No,
2597+
DefineOpaqueTypes::Yes,
25982598
upcast_principal.map_bound(|trait_ref| {
25992599
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
26002600
}),
@@ -2631,7 +2631,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
26312631
nested.extend(
26322632
self.infcx
26332633
.at(&obligation.cause, obligation.param_env)
2634-
.eq(DefineOpaqueTypes::No, source_projection, target_projection)
2634+
.eq(DefineOpaqueTypes::Yes, source_projection, target_projection)
26352635
.map_err(|_| SelectionError::Unimplemented)?
26362636
.into_obligations(),
26372637
);

‎tests/ui/impl-trait/equality.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn sum_to(n: u32) -> impl Foo {
2222
0
2323
} else {
2424
n + sum_to(n - 1)
25-
//~^ ERROR cannot add `impl Foo` to `u32`
25+
//~^ ERROR cannot satisfy `<u32 as Add<impl Foo>>::Output == i32`
2626
}
2727
}
2828

@@ -32,12 +32,15 @@ trait Leak: Sized {
3232
}
3333
impl<T> Leak for T {
3434
default type T = ();
35-
default fn leak(self) -> Self::T { panic!() }
35+
default fn leak(self) -> Self::T {
36+
panic!()
37+
}
3638
}
3739
impl Leak for i32 {
3840
type T = i32;
39-
fn leak(self) -> i32 { self }
41+
fn leak(self) -> i32 {
42+
self
43+
}
4044
}
4145

42-
fn main() {
43-
}
46+
fn main() {}

‎tests/ui/impl-trait/equality.stderr

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@ help: change the type of the numeric literal from `u32` to `i32`
2222
LL | 0_i32
2323
| ~~~
2424

25-
error[E0277]: cannot add `impl Foo` to `u32`
25+
error[E0284]: type annotations needed: cannot satisfy `<u32 as Add<impl Foo>>::Output == i32`
2626
--> $DIR/equality.rs:24:11
2727
|
2828
LL | n + sum_to(n - 1)
29-
| ^ no implementation for `u32 + impl Foo`
30-
|
31-
= help: the trait `Add<impl Foo>` is not implemented for `u32`
32-
= help: the following other types implement trait `Add<Rhs>`:
33-
<&'a u32 as Add<u32>>
34-
<&u32 as Add<&u32>>
35-
<u32 as Add<&u32>>
36-
<u32 as Add>
29+
| ^ cannot satisfy `<u32 as Add<impl Foo>>::Output == i32`
3730

3831
error: aborting due to 2 previous errors; 1 warning emitted
3932

40-
Some errors have detailed explanations: E0277, E0308.
41-
For more information about an error, try `rustc --explain E0277`.
33+
Some errors have detailed explanations: E0284, E0308.
34+
For more information about an error, try `rustc --explain E0284`.

‎tests/ui/impl-trait/nested_impl_trait.stderr

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,23 @@ error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfie
4646
--> $DIR/nested_impl_trait.rs:6:46
4747
|
4848
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
49-
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Into<u32>`, which is required by `impl Into<u32>: Into<impl Debug>`
49+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into<u32>`
5050
|
51-
= help: the trait `Into<U>` is implemented for `T`
52-
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`
51+
help: consider further restricting this bound
52+
|
53+
LL | fn bad_in_ret_position(x: impl Into<u32> + std::fmt::Debug) -> impl Into<impl Debug> { x }
54+
| +++++++++++++++++
5355

5456
error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
5557
--> $DIR/nested_impl_trait.rs:19:34
5658
|
5759
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
58-
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Into<u32>`, which is required by `impl Into<u32>: Into<impl Debug>`
60+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into<u32>`
61+
|
62+
help: consider further restricting this bound
5963
|
60-
= help: the trait `Into<U>` is implemented for `T`
61-
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`
64+
LL | fn bad(x: impl Into<u32> + std::fmt::Debug) -> impl Into<impl Debug> { x }
65+
| +++++++++++++++++
6266

6367
error: aborting due to 7 previous errors
6468

‎tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl PartialEq<(Bar, i32)> for Bar {
1111
}
1212

1313
fn foo() -> Foo {
14-
//~^ ERROR can't compare `Bar` with `(Foo, i32)`
14+
//~^ ERROR overflow evaluating the requirement `Bar: PartialEq<(Foo, i32)>`
1515
Bar
1616
}
1717

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
error[E0277]: can't compare `Bar` with `(Foo, i32)`
1+
error[E0275]: overflow evaluating the requirement `Bar: PartialEq<(Foo, i32)>`
22
--> $DIR/recursive-type-alias-impl-trait-declaration.rs:13:13
33
|
44
LL | fn foo() -> Foo {
5-
| ^^^ no implementation for `Bar == (Foo, i32)`
6-
LL |
7-
LL | Bar
8-
| --- return type was inferred to be `Bar` here
9-
|
10-
= help: the trait `PartialEq<(Foo, i32)>` is not implemented for `Bar`
11-
= help: the trait `PartialEq<(Bar, i32)>` is implemented for `Bar`
5+
| ^^^
126

137
error: aborting due to 1 previous error
148

15-
For more information about this error, try `rustc --explain E0277`.
9+
For more information about this error, try `rustc --explain E0275`.

‎tests/ui/impl-trait/unsize_adt.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Test that we do not allow unsizing `Foo<[Opaque; N]>` to `Foo<[Concrete]>`.
2+
3+
struct Foo<T: ?Sized>(T);
4+
5+
fn hello() -> Foo<[impl Sized; 2]> {
6+
if false {
7+
let x = hello();
8+
let _: &Foo<[i32]> = &x;
9+
//~^ ERROR: mismatched types
10+
}
11+
todo!()
12+
}
13+
14+
fn main() {}

‎tests/ui/impl-trait/unsize_adt.stderr

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/unsize_adt.rs:8:30
3+
|
4+
LL | fn hello() -> Foo<[impl Sized; 2]> {
5+
| ---------- the found opaque type
6+
...
7+
LL | let _: &Foo<[i32]> = &x;
8+
| ----------- ^^ expected `&Foo<[i32]>`, found `&Foo<[impl Sized; 2]>`
9+
| |
10+
| expected due to this
11+
|
12+
= note: expected reference `&Foo<[i32]>`
13+
found reference `&Foo<[impl Sized; 2]>`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0308`.

‎tests/ui/impl-trait/unsize_slice.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! Test that we do not allow unsizing `[Opaque; N]` to `[Concrete]`.
2+
3+
fn hello() -> [impl Sized; 2] {
4+
if false {
5+
let x = hello();
6+
let _: &[i32] = &x;
7+
//~^ ERROR: mismatched types
8+
}
9+
todo!()
10+
}
11+
12+
fn main() {}

‎tests/ui/impl-trait/unsize_slice.stderr

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/unsize_slice.rs:6:25
3+
|
4+
LL | fn hello() -> [impl Sized; 2] {
5+
| ---------- the found opaque type
6+
...
7+
LL | let _: &[i32] = &x;
8+
| ------ ^^ expected `&[i32]`, found `&[impl Sized; 2]`
9+
| |
10+
| expected due to this
11+
|
12+
= note: expected reference `&[i32]`
13+
found reference `&[impl Sized; 2]`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /