Skip to content

Commit

Permalink
Rollup merge of rust-lang#96516 - oli-obk:impl_trait_inference_accide…
Browse files Browse the repository at this point in the history
…ntal_permitted, r=jackh726

Revert diagnostic duplication and accidental stabilization

fixes rust-lang#96460

this is an accidental stabilization that we should put into the beta. I believe it is low-risk, because it was literally what we had before rust-lang#94081

The effect on tests is massive, but mostly deduplication of diagnostics and some minor span changes.
  • Loading branch information
Dylan-DPC authored and MabezDev committed May 17, 2022
1 parent a7fcff3 commit 2ef5103
Show file tree
Hide file tree
Showing 44 changed files with 97 additions and 384 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ pub(super) fn check_fn<'a, 'tcx>(
DUMMY_SP,
param_env,
));
// HACK(oli-obk): we rewrite the declared return type, too, so that we don't end up inferring all
// unconstrained RPIT to have `()` as their hidden type. This would happen because further down we
// compare the ret_coercion with declared_ret_ty, and anything uninferred would be inferred to the
// opaque type itself. That again would cause writeback to assume we have a recursive call site
// and do the sadly stabilized fallback to `()`.
let declared_ret_ty = ret_ty;
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
fcx.ret_type_span = Some(decl.output.span());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ fn bar() -> impl Bar {

fn baz() -> impl Bar<Item = i32> {
//~^ ERROR type mismatch resolving `<impl Bar as Foo>::Item == i32`
//~| ERROR type mismatch resolving `<impl Bar as Foo>::Item == i32`
bar()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,6 @@ help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i3
LL | fn bar() -> impl Bar<Item = i32> {
| ++++++++++++

error[E0271]: type mismatch resolving `<impl Bar as Foo>::Item == i32`
--> $DIR/impl-trait-return-missing-constraint.rs:25:34
|
LL | fn bar() -> impl Bar {
| -------- the expected opaque type
...
LL | fn baz() -> impl Bar<Item = i32> {
| __________________________________^
LL | |
LL | |
LL | | bar()
LL | | }
| |_^ expected associated type, found `i32`
|
= note: expected associated type `<impl Bar as Foo>::Item`
found type `i32`
= help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32` or calling a method that returns `<impl Bar as Foo>::Item`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32`
|
LL | fn bar() -> impl Bar<Item = i32> {
| ++++++++++++

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0271`.
1 change: 0 additions & 1 deletion src/test/ui/conservative_impl_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

fn will_ice(something: &u32) -> impl Iterator<Item = &u32> {
//~^ ERROR `()` is not an iterator
//~| ERROR `()` is not an iterator
}

fn main() {}
14 changes: 1 addition & 13 deletions src/test/ui/conservative_impl_trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ LL | fn will_ice(something: &u32) -> impl Iterator<Item = &u32> {
|
= help: the trait `Iterator` is not implemented for `()`

error[E0277]: `()` is not an iterator
--> $DIR/conservative_impl_trait.rs:3:60
|
LL | fn will_ice(something: &u32) -> impl Iterator<Item = &u32> {
| ____________________________________________________________^
LL | |
LL | |
LL | | }
| |_^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
3 changes: 0 additions & 3 deletions src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ impl<const N: u32> Trait for Uwu<N> {}

fn rawr() -> impl Trait {
//~^ error: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
//~| error: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
Uwu::<10, 12>
}

Expand All @@ -17,13 +16,11 @@ impl Traitor<1, 2> for u64 {}

fn uwu<const N: u8>() -> impl Traitor<N> {
//~^ error: the trait bound `u32: Traitor<N, N>` is not satisfied
//~| error: the trait bound `u32: Traitor<N, N>` is not satisfied
1_u32
}

fn owo() -> impl Traitor {
//~^ error: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
//~| error: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
1_u64
}

Expand Down
50 changes: 3 additions & 47 deletions src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,8 @@ LL | fn rawr() -> impl Trait {
= help: the following implementations were found:
<Uwu<N> as Trait>

error[E0277]: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
--> $DIR/rp_impl_trait_fail.rs:6:25
|
LL | fn rawr() -> impl Trait {
| _________________________^
LL | |
LL | |
LL | | Uwu::<10, 12>
LL | | }
| |_^ the trait `Trait` is not implemented for `Uwu<10_u32, 12_u32>`
|
= help: the following implementations were found:
<Uwu<N> as Trait>

error[E0277]: the trait bound `u32: Traitor<N, N>` is not satisfied
--> $DIR/rp_impl_trait_fail.rs:18:26
--> $DIR/rp_impl_trait_fail.rs:17:26
|
LL | fn uwu<const N: u8>() -> impl Traitor<N> {
| ^^^^^^^^^^^^^^^ the trait `Traitor<N, N>` is not implemented for `u32`
Expand All @@ -31,23 +17,8 @@ LL | fn uwu<const N: u8>() -> impl Traitor<N> {
<u32 as Traitor<N, 2_u8>>
<u64 as Traitor<1_u8, 2_u8>>

error[E0277]: the trait bound `u32: Traitor<N, N>` is not satisfied
--> $DIR/rp_impl_trait_fail.rs:18:42
|
LL | fn uwu<const N: u8>() -> impl Traitor<N> {
| __________________________________________^
LL | |
LL | |
LL | | 1_u32
LL | | }
| |_^ the trait `Traitor<N, N>` is not implemented for `u32`
|
= help: the following implementations were found:
<u32 as Traitor<N, 2_u8>>
<u64 as Traitor<1_u8, 2_u8>>

error[E0277]: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
--> $DIR/rp_impl_trait_fail.rs:24:13
--> $DIR/rp_impl_trait_fail.rs:22:13
|
LL | fn owo() -> impl Traitor {
| ^^^^^^^^^^^^ the trait `Traitor<1_u8, 1_u8>` is not implemented for `u64`
Expand All @@ -56,21 +27,6 @@ LL | fn owo() -> impl Traitor {
<u64 as Traitor<1_u8, 2_u8>>
<u32 as Traitor<N, 2_u8>>

error[E0277]: the trait bound `u64: Traitor<1_u8, 1_u8>` is not satisfied
--> $DIR/rp_impl_trait_fail.rs:24:26
|
LL | fn owo() -> impl Traitor {
| __________________________^
LL | |
LL | |
LL | | 1_u64
LL | | }
| |_^ the trait `Traitor<1_u8, 1_u8>` is not implemented for `u64`
|
= help: the following implementations were found:
<u64 as Traitor<1_u8, 2_u8>>
<u32 as Traitor<N, 2_u8>>

error: aborting due to 6 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.
3 changes: 0 additions & 3 deletions src/test/ui/generator/issue-88653.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ use std::ops::Generator;

fn foo(bar: bool) -> impl Generator<(bool,)> {
//~^ ERROR: type mismatch in generator arguments [E0631]
//~| ERROR: type mismatch in generator arguments [E0631]
//~| NOTE: expected signature of `fn((bool,)) -> _`
//~| NOTE: expected signature of `fn((bool,)) -> _`
//~| NOTE: in this expansion of desugaring of `impl Trait`
|bar| {
//~^ NOTE: found signature of `fn(bool) -> _`
//~| NOTE: found signature of `fn(bool) -> _`
if bar {
yield bar;
}
Expand Down
18 changes: 1 addition & 17 deletions src/test/ui/generator/issue-88653.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@ LL | fn foo(bar: bool) -> impl Generator<(bool,)> {
LL | |bar| {
| ----- found signature of `fn(bool) -> _`

error[E0631]: type mismatch in generator arguments
--> $DIR/issue-88653.rs:8:46
|
LL | fn foo(bar: bool) -> impl Generator<(bool,)> {
| ______________________________________________^
LL | |
LL | |
LL | |
... |
LL | | |bar| {
| | ----- found signature of `fn(bool) -> _`
... |
LL | | }
LL | | }
| |_^ expected signature of `fn((bool,)) -> _`

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0631`.
1 change: 0 additions & 1 deletion src/test/ui/generator/type-mismatch-signature-deduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::ops::Generator;

fn foo() -> impl Generator<Return = i32> {
//~^ ERROR type mismatch
//~| ERROR type mismatch
|| {
if false {
return Ok(6);
Expand Down
24 changes: 4 additions & 20 deletions src/test/ui/generator/type-mismatch-signature-deduction.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error[E0308]: mismatched types
--> $DIR/type-mismatch-signature-deduction.rs:15:9
--> $DIR/type-mismatch-signature-deduction.rs:14:9
|
LL | 5
| ^ expected enum `Result`, found integer
|
= note: expected type `Result<{integer}, _>`
found type `{integer}`
note: return type inferred to be `Result<{integer}, _>` here
--> $DIR/type-mismatch-signature-deduction.rs:10:20
--> $DIR/type-mismatch-signature-deduction.rs:9:20
|
LL | return Ok(6);
| ^^^^^

error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature-deduction.rs:8:5: 16:6] as Generator>::Return == i32`
error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature-deduction.rs:7:5: 15:6] as Generator>::Return == i32`
--> $DIR/type-mismatch-signature-deduction.rs:5:13
|
LL | fn foo() -> impl Generator<Return = i32> {
Expand All @@ -21,23 +21,7 @@ LL | fn foo() -> impl Generator<Return = i32> {
= note: expected enum `Result<{integer}, _>`
found type `i32`

error[E0271]: type mismatch resolving `<[generator@$DIR/type-mismatch-signature-deduction.rs:8:5: 16:6] as Generator>::Return == i32`
--> $DIR/type-mismatch-signature-deduction.rs:5:42
|
LL | fn foo() -> impl Generator<Return = i32> {
| __________________________________________^
LL | |
LL | |
LL | | || {
... |
LL | | }
LL | | }
| |_^ expected enum `Result`, found `i32`
|
= note: expected enum `Result<{integer}, _>`
found type `i32`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0271, E0308.
For more information about an error, try `rustc --explain E0271`.
2 changes: 0 additions & 2 deletions src/test/ui/impl-trait/bound-normalization-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ mod impl_trait {
/// `T::Assoc` can't be normalized any further here.
fn foo_fail<T: Trait>() -> impl FooLike<Output = T::Assoc> {
//~^ ERROR: type mismatch
//~| ERROR: type mismatch
Foo(())
}
}
Expand All @@ -42,7 +41,6 @@ mod lifetimes {
fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output = T::Assoc> {
//~^ ERROR `impl Trait` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
//~| ERROR: type mismatch
//~| ERROR: type mismatch
Foo(())
}
}
Expand Down
53 changes: 3 additions & 50 deletions src/test/ui/impl-trait/bound-normalization-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,14 @@ help: consider constraining the associated type `<T as impl_trait::Trait>::Assoc
LL | fn foo_fail<T: Trait<Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
| ++++++++++++

error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc`
--> $DIR/bound-normalization-fail.rs:25:64
|
LL | fn foo_fail<T: Trait>() -> impl FooLike<Output = T::Assoc> {
| ________________________________________________________________^
LL | |
LL | |
LL | | Foo(())
LL | | }
| |_____^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc`
|
note: expected this to be `()`
--> $DIR/bound-normalization-fail.rs:14:19
|
LL | type Output = T;
| ^
= note: expected unit type `()`
found associated type `<T as impl_trait::Trait>::Assoc`
help: consider constraining the associated type `<T as impl_trait::Trait>::Assoc` to `()`
|
LL | fn foo_fail<T: Trait<Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
| ++++++++++++

error[E0760]: `impl Trait` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
--> $DIR/bound-normalization-fail.rs:42:41
--> $DIR/bound-normalization-fail.rs:41:41
|
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output = T::Assoc> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`
--> $DIR/bound-normalization-fail.rs:42:41
--> $DIR/bound-normalization-fail.rs:41:41
|
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output = T::Assoc> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`
Expand All @@ -63,31 +40,7 @@ help: consider constraining the associated type `<T as lifetimes::Trait<'static>
LL | fn foo2_fail<'a, T: Trait<'a, Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
| ++++++++++++

error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`
--> $DIR/bound-normalization-fail.rs:42:73
|
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output = T::Assoc> {
| _________________________________________________________________________^
LL | |
LL | |
LL | |
LL | | Foo(())
LL | | }
| |_____^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`
|
note: expected this to be `()`
--> $DIR/bound-normalization-fail.rs:14:19
|
LL | type Output = T;
| ^
= note: expected unit type `()`
found associated type `<T as lifetimes::Trait<'static>>::Assoc`
help: consider constraining the associated type `<T as lifetimes::Trait<'static>>::Assoc` to `()`
|
LL | fn foo2_fail<'a, T: Trait<'a, Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
| ++++++++++++

error: aborting due to 5 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0271, E0760.
For more information about an error, try `rustc --explain E0271`.
6 changes: 3 additions & 3 deletions src/test/ui/impl-trait/cross-return-site-inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ fn baa(b: bool) -> impl std::fmt::Debug {
}

fn muh() -> Result<(), impl std::fmt::Debug> {
Err("whoops")?; //~ ERROR `?` couldn't convert the error to `impl Debug`
Err("whoops")?; //~^ ERROR type annotations needed
Ok(())
}

fn muh2() -> Result<(), impl std::fmt::Debug> {
return Err(From::from("foo")); //~ ERROR the trait bound `impl Debug: From<&str>` is not satisfied
return Err(From::from("foo")); //~^ ERROR type annotations needed
Ok(())
}

fn muh3() -> Result<(), impl std::fmt::Debug> {
Err(From::from("foo")) //~ ERROR the trait bound `impl Debug: From<&str>` is not satisfied
Err(From::from("foo")) //~^ ERROR type annotations needed
}

fn main() {}
Loading

0 comments on commit 2ef5103

Please sign in to comment.