Skip to content

Commit 7baacc5

Browse files
authored
Unrolled build for rust-lang#124080
Rollup merge of rust-lang#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 rust-lang#116652
2 parents 1ba35e9 + 4387eea commit 7baacc5

35 files changed

+364
-122
lines changed

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

+3-3
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

+8-5
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

+4-11
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

+10-6
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

+1-1
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

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

+14
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

+17
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

+12
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() {}
+17
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`.

tests/ui/impl-trait/unsize_tuple.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Test that we do not allow unsizing `([Opaque; N],)` to `([Concrete],)`.
2+
3+
#![feature(unsized_tuple_coercion)]
4+
5+
fn hello() -> ([impl Sized; 2],) {
6+
if false {
7+
let x = hello();
8+
let _: &([i32],) = &x;
9+
//~^ ERROR: mismatched types
10+
}
11+
todo!()
12+
}
13+
14+
fn main() {}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/unsize_tuple.rs:8:28
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`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
//@[next] failure-status: 101
4+
//@[next] known-bug: unknown
5+
//@[next] normalize-stderr-test "note: .*\n\n" -> ""
6+
//@[next] normalize-stderr-test "thread 'rustc' panicked.*\n.*\n" -> ""
7+
//@[next] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
8+
//@[next] normalize-stderr-test "delayed at .*" -> ""
9+
//@[next] rustc-env:RUST_BACKTRACE=0
10+
//@ check-pass
11+
12+
#![feature(trait_upcasting)]
13+
14+
trait Super {
15+
type Assoc;
16+
}
17+
18+
trait Sub: Super {}
19+
20+
impl<T: ?Sized> Super for T {
21+
type Assoc = i32;
22+
}
23+
24+
fn illegal(x: &dyn Sub<Assoc = i32>) -> &dyn Super<Assoc = impl Sized> {
25+
x
26+
}
27+
28+
fn main() {}

tests/ui/traits/trait-upcasting/type-checking-test-4.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ fn test_correct(x: &dyn Foo<'static>) {
1111
let _ = x as &dyn Bar<'static, 'static>;
1212
}
1313

14+
fn test_correct2<'a>(x: &dyn Foo<'a>) {
15+
let _ = x as &dyn Bar<'_, '_>;
16+
}
17+
1418
fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
1519
let _ = x as &dyn Bar<'static, 'a>; // Error
1620
//~^ ERROR lifetime may not live long enough

tests/ui/traits/trait-upcasting/type-checking-test-4.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error: lifetime may not live long enough
2-
--> $DIR/type-checking-test-4.rs:15:13
2+
--> $DIR/type-checking-test-4.rs:19:13
33
|
44
LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
55
| -- lifetime `'a` defined here
66
LL | let _ = x as &dyn Bar<'static, 'a>; // Error
77
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
88

99
error: lifetime may not live long enough
10-
--> $DIR/type-checking-test-4.rs:20:13
10+
--> $DIR/type-checking-test-4.rs:24:13
1111
|
1212
LL | fn test_wrong2<'a>(x: &dyn Foo<'static>, y: &'a u32) {
1313
| -- lifetime `'a` defined here
1414
LL | let _ = x as &dyn Bar<'a, 'static>; // Error
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
1616

1717
error: lifetime may not live long enough
18-
--> $DIR/type-checking-test-4.rs:26:5
18+
--> $DIR/type-checking-test-4.rs:30:5
1919
|
2020
LL | fn test_wrong3<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
2121
| -- lifetime `'a` defined here
@@ -24,23 +24,23 @@ LL | y.get_b() // ERROR
2424
| ^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
2525

2626
error: lifetime may not live long enough
27-
--> $DIR/type-checking-test-4.rs:31:5
27+
--> $DIR/type-checking-test-4.rs:35:5
2828
|
2929
LL | fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
3030
| -- lifetime `'a` defined here
3131
LL | <_ as Bar>::get_b(x) // ERROR
3232
| ^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
3333

3434
error: lifetime may not live long enough
35-
--> $DIR/type-checking-test-4.rs:36:5
35+
--> $DIR/type-checking-test-4.rs:40:5
3636
|
3737
LL | fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
3838
| -- lifetime `'a` defined here
3939
LL | <_ as Bar<'_, '_>>::get_b(x) // ERROR
4040
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
4141

4242
error: lifetime may not live long enough
43-
--> $DIR/type-checking-test-4.rs:44:5
43+
--> $DIR/type-checking-test-4.rs:48:5
4444
|
4545
LL | fn test_wrong6<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
4646
| -- lifetime `'a` defined here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(trait_upcasting, type_alias_impl_trait)]
2+
3+
//@ check-pass
4+
5+
type Tait = impl Sized;
6+
7+
trait Foo<'a>: Bar<'a, 'a, Tait> {}
8+
trait Bar<'a, 'b, T> {}
9+
10+
fn test_correct(x: &dyn Foo<'static>) {
11+
let _ = x as &dyn Bar<'static, 'static, Tait>;
12+
}
13+
14+
fn test_correct2<'a>(x: &dyn Foo<'a>) {
15+
let _ = x as &dyn Bar<'_, '_, Tait>;
16+
}
17+
18+
fn test_correct3<'a>(x: &dyn Foo<'a>, _: Tait) {
19+
let _ = x as &dyn Bar<'_, '_, ()>;
20+
}
21+
22+
fn main() {}

tests/ui/traits/trait-upcasting/upcast-defining-opaque.current.stderr

-17
This file was deleted.

tests/ui/traits/trait-upcasting/upcast-defining-opaque.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ revisions: current next
22
//@[next] compile-flags: -Znext-solver
33
//@ ignore-compare-mode-next-solver (explicit revisions)
4-
//@[next] check-pass
4+
//@check-pass
55

66
#![feature(trait_upcasting, type_alias_impl_trait)]
77

@@ -18,7 +18,7 @@ impl<T: ?Sized> Super for T {
1818
type Foo = impl Sized;
1919

2020
fn upcast(x: &dyn Sub<Assoc = Foo>) -> &dyn Super<Assoc = i32> {
21-
x //[current]~ mismatched types
21+
x
2222
}
2323

2424
fn main() {}

0 commit comments

Comments
 (0)