From 0baacd78ca287830617ec641355323457b3ad001 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 11 Jun 2024 07:03:10 +0000 Subject: [PATCH 1/4] Revert "Revert "When checking whether an impl applies, constrain hidden types of opaque types."" This reverts commit ad008683cf5361045deac6d7506caebf18c2c508. --- .../src/traits/select/mod.rs | 2 +- .../opaque_type_candidate_selection.rs | 29 +++++++++++++++++++ .../opaque_type_candidate_selection.stderr | 12 ++++++++ ...inherent_impl_on_rigid_type.current.stderr | 16 ---------- ...on_inherent_impl_on_rigid_type.next.stderr | 2 +- ...l_method_on_inherent_impl_on_rigid_type.rs | 2 +- tests/ui/impl-trait/equality.rs | 2 +- tests/ui/impl-trait/equality.stderr | 15 +++------- tests/ui/impl-trait/nested_impl_trait.rs | 4 +-- tests/ui/impl-trait/nested_impl_trait.stderr | 24 +++++++-------- .../recursive-bound-eval.current.stderr | 9 ++++++ .../recursive-bound-eval.next.stderr | 2 +- tests/ui/impl-trait/recursive-bound-eval.rs | 4 +-- ...rsive-type-alias-impl-trait-declaration.rs | 2 +- ...e-type-alias-impl-trait-declaration.stderr | 12 ++------ .../constrain_in_projection.current.stderr | 12 -------- .../constrain_in_projection.rs | 3 +- .../constrain_in_projection2.current.stderr | 18 ++++++++---- .../constrain_in_projection2.rs | 3 +- .../issue-84660-unsoundness.current.stderr | 17 ++--------- .../issue-84660-unsoundness.next.stderr | 3 +- .../issue-84660-unsoundness.rs | 1 - .../nested-tait-inference.current.stderr | 15 ---------- .../nested-tait-inference.rs | 4 +-- .../nested-tait-inference2.current.stderr | 16 ++++++---- .../nested-tait-inference2.rs | 2 +- .../normalize-hidden-types.current.stderr | 21 +++++--------- .../self-referential-2.current.stderr | 14 --------- .../self-referential-2.rs | 4 +-- .../self-referential-3.rs | 2 +- .../self-referential-3.stderr | 12 +++----- 31 files changed, 122 insertions(+), 162 deletions(-) create mode 100644 tests/ui/auto-traits/opaque_type_candidate_selection.rs create mode 100644 tests/ui/auto-traits/opaque_type_candidate_selection.stderr delete mode 100644 tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.stderr create mode 100644 tests/ui/impl-trait/recursive-bound-eval.current.stderr delete mode 100644 tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr delete mode 100644 tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr delete mode 100644 tests/ui/type-alias-impl-trait/self-referential-2.current.stderr diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 41a35c31fe432..4fca6761fdee7 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2543,7 +2543,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { let InferOk { obligations, .. } = self .infcx .at(&cause, obligation.param_env) - .eq(DefineOpaqueTypes::No, placeholder_obligation_trait_ref, impl_trait_ref) + .eq(DefineOpaqueTypes::Yes, placeholder_obligation_trait_ref, impl_trait_ref) .map_err(|e| { debug!("match_impl: failed eq_trait_refs due to `{}`", e.to_string(self.tcx())) })?; diff --git a/tests/ui/auto-traits/opaque_type_candidate_selection.rs b/tests/ui/auto-traits/opaque_type_candidate_selection.rs new file mode 100644 index 0000000000000..520ca9c3beec9 --- /dev/null +++ b/tests/ui/auto-traits/opaque_type_candidate_selection.rs @@ -0,0 +1,29 @@ +//! used to ICE: #119272 + +#![feature(type_alias_impl_trait)] +mod defining_scope { + use super::*; + pub type Alias = impl Sized; + + pub fn cast(x: Container, T>) -> Container { + x + } +} + +struct Container, U> { + x: >::Assoc, +} + +trait Trait { + type Assoc; +} + +impl Trait for T { + type Assoc = Box; +} +impl Trait for defining_scope::Alias { + //~^ ERROR: conflicting implementations + type Assoc = usize; +} + +fn main() {} diff --git a/tests/ui/auto-traits/opaque_type_candidate_selection.stderr b/tests/ui/auto-traits/opaque_type_candidate_selection.stderr new file mode 100644 index 0000000000000..3f1242a95af71 --- /dev/null +++ b/tests/ui/auto-traits/opaque_type_candidate_selection.stderr @@ -0,0 +1,12 @@ +error[E0119]: conflicting implementations of trait `Trait<_>` + --> $DIR/opaque_type_candidate_selection.rs:24:1 + | +LL | impl Trait for T { + | ---------------------- first implementation here +... +LL | impl Trait for defining_scope::Alias { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.stderr deleted file mode 100644 index 6ecb2b05fc56b..0000000000000 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0599]: no method named `my_debug` found for reference `&impl Debug` in the current scope - --> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:16:11 - | -LL | x.my_debug(); - | ^^^^^^^^ method not found in `&impl Debug` - | - = help: items from traits can only be used if the trait is implemented and in scope -note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it - --> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:4:1 - | -LL | trait MyDebug { - | ^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr index 5fb0b8f1d14b2..e60f1bfb361c3 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed for `&_` - --> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:14:13 + --> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:15:13 | LL | let x = &my_foo(); | ^ diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs index 7fb2ff3b2bcc6..22ada7f1bea8a 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs @@ -1,5 +1,6 @@ //@ revisions: current next //@[next] compile-flags: -Znext-solver +//@[current] check-pass trait MyDebug { fn my_debug(&self); @@ -14,7 +15,6 @@ fn my_foo() -> impl std::fmt::Debug { let x = &my_foo(); //[next]~^ ERROR: type annotations needed x.my_debug(); - //[current]~^ ERROR: no method named `my_debug` } () } diff --git a/tests/ui/impl-trait/equality.rs b/tests/ui/impl-trait/equality.rs index 828b5aac896be..5e518a9832b5b 100644 --- a/tests/ui/impl-trait/equality.rs +++ b/tests/ui/impl-trait/equality.rs @@ -22,7 +22,7 @@ fn sum_to(n: u32) -> impl Foo { 0 } else { n + sum_to(n - 1) - //~^ ERROR cannot add `impl Foo` to `u32` + //~^ ERROR cannot satisfy `>::Output == i32` } } diff --git a/tests/ui/impl-trait/equality.stderr b/tests/ui/impl-trait/equality.stderr index fd6f4b34241aa..c9ba1a5ba32d1 100644 --- a/tests/ui/impl-trait/equality.stderr +++ b/tests/ui/impl-trait/equality.stderr @@ -22,20 +22,13 @@ help: change the type of the numeric literal from `u32` to `i32` LL | 0_i32 | ~~~ -error[E0277]: cannot add `impl Foo` to `u32` +error[E0284]: type annotations needed: cannot satisfy `>::Output == i32` --> $DIR/equality.rs:24:11 | LL | n + sum_to(n - 1) - | ^ no implementation for `u32 + impl Foo` - | - = help: the trait `Add` is not implemented for `u32` - = help: the following other types implement trait `Add`: - `&u32` implements `Add` - `&u32` implements `Add` - `u32` implements `Add<&u32>` - `u32` implements `Add` + | ^ cannot satisfy `>::Output == i32` error: aborting due to 2 previous errors; 1 warning emitted -Some errors have detailed explanations: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0284, E0308. +For more information about an error, try `rustc --explain E0284`. diff --git a/tests/ui/impl-trait/nested_impl_trait.rs b/tests/ui/impl-trait/nested_impl_trait.rs index 760102794c34e..502b2af2bc660 100644 --- a/tests/ui/impl-trait/nested_impl_trait.rs +++ b/tests/ui/impl-trait/nested_impl_trait.rs @@ -5,7 +5,7 @@ fn fine(x: impl Into) -> impl Into { x } fn bad_in_ret_position(x: impl Into) -> impl Into { x } //~^ ERROR nested `impl Trait` is not allowed -//~| ERROR the trait bound `impl Debug: From>` is not satisfied +//~| ERROR the trait bound `impl Into: Into` is not satisfied fn bad_in_fn_syntax(x: fn() -> impl Into) {} //~^ ERROR nested `impl Trait` is not allowed @@ -18,7 +18,7 @@ struct X; impl X { fn bad(x: impl Into) -> impl Into { x } //~^ ERROR nested `impl Trait` is not allowed - //~| ERROR the trait bound `impl Debug: From>` is not satisfied + //~| ERROR the trait bound `impl Into: Into` is not satisfied } fn allowed_in_assoc_type() -> impl Iterator { diff --git a/tests/ui/impl-trait/nested_impl_trait.stderr b/tests/ui/impl-trait/nested_impl_trait.stderr index d01c5961e819e..f7c708a1dfae8 100644 --- a/tests/ui/impl-trait/nested_impl_trait.stderr +++ b/tests/ui/impl-trait/nested_impl_trait.stderr @@ -42,27 +42,27 @@ LL | fn bad_in_fn_syntax(x: fn() -> impl Into) {} | = note: `impl Trait` is only allowed in arguments and return types of functions and methods -error[E0277]: the trait bound `impl Debug: From>` is not satisfied +error[E0277]: the trait bound `impl Into: Into` is not satisfied --> $DIR/nested_impl_trait.rs:6:46 | LL | fn bad_in_ret_position(x: impl Into) -> impl Into { x } - | ^^^^^^^^^^^^^^^^^^^^^ - return type was inferred to be `impl Into` here - | | - | the trait `From>` is not implemented for `impl Debug` + | ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into` | - = help: the trait `Into` is implemented for `T` - = note: required for `impl Into` to implement `Into` +help: consider further restricting this bound + | +LL | fn bad_in_ret_position(x: impl Into + std::fmt::Debug) -> impl Into { x } + | +++++++++++++++++ -error[E0277]: the trait bound `impl Debug: From>` is not satisfied +error[E0277]: the trait bound `impl Into: Into` is not satisfied --> $DIR/nested_impl_trait.rs:19:34 | LL | fn bad(x: impl Into) -> impl Into { x } - | ^^^^^^^^^^^^^^^^^^^^^ - return type was inferred to be `impl Into` here - | | - | the trait `From>` is not implemented for `impl Debug` + | ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into` + | +help: consider further restricting this bound | - = help: the trait `Into` is implemented for `T` - = note: required for `impl Into` to implement `Into` +LL | fn bad(x: impl Into + std::fmt::Debug) -> impl Into { x } + | +++++++++++++++++ error: aborting due to 7 previous errors diff --git a/tests/ui/impl-trait/recursive-bound-eval.current.stderr b/tests/ui/impl-trait/recursive-bound-eval.current.stderr new file mode 100644 index 0000000000000..8435b3375bb02 --- /dev/null +++ b/tests/ui/impl-trait/recursive-bound-eval.current.stderr @@ -0,0 +1,9 @@ +error[E0282]: type annotations needed + --> $DIR/recursive-bound-eval.rs:18:28 + | +LL | move || recursive_fn().parse() + | ^^^^^ cannot infer type + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/impl-trait/recursive-bound-eval.next.stderr b/tests/ui/impl-trait/recursive-bound-eval.next.stderr index 4bab290d71c3c..fc37b5fa14ef6 100644 --- a/tests/ui/impl-trait/recursive-bound-eval.next.stderr +++ b/tests/ui/impl-trait/recursive-bound-eval.next.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/recursive-bound-eval.rs:20:13 + --> $DIR/recursive-bound-eval.rs:18:13 | LL | move || recursive_fn().parse() | ^^^^^^^^^^^^^^ cannot infer type diff --git a/tests/ui/impl-trait/recursive-bound-eval.rs b/tests/ui/impl-trait/recursive-bound-eval.rs index 7859c8983fc89..5f6247fc851fa 100644 --- a/tests/ui/impl-trait/recursive-bound-eval.rs +++ b/tests/ui/impl-trait/recursive-bound-eval.rs @@ -4,8 +4,6 @@ //@revisions: next current //@[next] compile-flags: -Znext-solver -//@[current] check-pass - pub trait Parser { fn parse(&self) -> E; } @@ -18,7 +16,7 @@ impl E> Parser for T { pub fn recursive_fn() -> impl Parser { move || recursive_fn().parse() - //[next]~^ ERROR: type annotations needed + //~^ ERROR: type annotations needed } fn main() {} diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.rs b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.rs index aab10be2de27a..7874a21f3aec5 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.rs +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.rs @@ -11,7 +11,7 @@ impl PartialEq<(Bar, i32)> for Bar { } fn foo() -> Foo { - //~^ ERROR can't compare `Bar` with `(Foo, i32)` + //~^ ERROR overflow evaluating the requirement `Bar: PartialEq<(Foo, i32)>` Bar } diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.stderr b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.stderr index bc810c0f88f3d..2d4707f8a2799 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.stderr +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.stderr @@ -1,15 +1,9 @@ -error[E0277]: can't compare `Bar` with `(Foo, i32)` +error[E0275]: overflow evaluating the requirement `Bar: PartialEq<(Foo, i32)>` --> $DIR/recursive-type-alias-impl-trait-declaration.rs:13:13 | LL | fn foo() -> Foo { - | ^^^ no implementation for `Bar == (Foo, i32)` -LL | -LL | Bar - | --- return type was inferred to be `Bar` here - | - = help: the trait `PartialEq<(Foo, i32)>` is not implemented for `Bar` - = help: the trait `PartialEq<(Bar, i32)>` is implemented for `Bar` + | ^^^ error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr b/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr deleted file mode 100644 index d96c86a2e6f16..0000000000000 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0277]: the trait bound `Foo: Trait` is not satisfied - --> $DIR/constrain_in_projection.rs:24:14 - | -LL | let x = >::Assoc::default(); - | ^^^ the trait `Trait` is not implemented for `Foo` - | - = help: the trait `Trait` is not implemented for `Foo` - but trait `Trait<()>` is implemented for it - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection.rs b/tests/ui/type-alias-impl-trait/constrain_in_projection.rs index 7d7d16361ae6d..2a246900106cb 100644 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection.rs +++ b/tests/ui/type-alias-impl-trait/constrain_in_projection.rs @@ -4,7 +4,7 @@ //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) //@[next] compile-flags: -Znext-solver -//@[next]check-pass +//@check-pass #![feature(type_alias_impl_trait)] @@ -22,7 +22,6 @@ impl Trait<()> for Foo { fn bop(_: Bar) { let x = >::Assoc::default(); - //[current]~^ `Foo: Trait` is not satisfied } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection2.current.stderr b/tests/ui/type-alias-impl-trait/constrain_in_projection2.current.stderr index 909f1f6d61cbe..0d6eac4216bae 100644 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection2.current.stderr +++ b/tests/ui/type-alias-impl-trait/constrain_in_projection2.current.stderr @@ -1,13 +1,19 @@ -error[E0277]: the trait bound `Foo: Trait` is not satisfied +error[E0283]: type annotations needed: cannot satisfy `Foo: Trait` --> $DIR/constrain_in_projection2.rs:27:14 | LL | let x = >::Assoc::default(); - | ^^^ the trait `Trait` is not implemented for `Foo` + | ^^^ help: use the fully qualified path to an implementation: `::Assoc` | - = help: the following other types implement trait `Trait`: - `Foo` implements `Trait<()>` - `Foo` implements `Trait` +note: multiple `impl`s satisfying `Foo: Trait` found + --> $DIR/constrain_in_projection2.rs:18:1 + | +LL | impl Trait<()> for Foo { + | ^^^^^^^^^^^^^^^^^^^^^^ +... +LL | impl Trait for Foo { + | ^^^^^^^^^^^^^^^^^^^^^^^ + = note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection2.rs b/tests/ui/type-alias-impl-trait/constrain_in_projection2.rs index af222f6c15347..0066131f0155f 100644 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection2.rs +++ b/tests/ui/type-alias-impl-trait/constrain_in_projection2.rs @@ -25,8 +25,7 @@ impl Trait for Foo { fn bop(_: Bar) { let x = >::Assoc::default(); - //[next]~^ ERROR: cannot satisfy `Foo: Trait` - //[current]~^^ ERROR: `Foo: Trait` is not satisfied + //~^ ERROR: cannot satisfy `Foo: Trait` } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr index ec7b9e0e12b3f..a7ff097e8bf38 100644 --- a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr +++ b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Trait` - --> $DIR/issue-84660-unsoundness.rs:29:1 + --> $DIR/issue-84660-unsoundness.rs:28:1 | LL | impl Trait for Out { | ------------------------------------ first implementation here @@ -7,19 +7,6 @@ LL | impl Trait for Out { LL | impl Trait<(), In> for Out { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation -error: item does not constrain `Bar::{opaque#0}`, but has it in its signature - --> $DIR/issue-84660-unsoundness.rs:22:8 - | -LL | fn convert(_i: In) -> Self::Out { - | ^^^^^^^ - | - = note: consider moving the opaque type's declaration and defining uses into a separate module -note: this opaque type is in the signature - --> $DIR/issue-84660-unsoundness.rs:12:12 - | -LL | type Bar = impl Foo; - | ^^^^^^^^ - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr index e33102f687c53..b22e8fd5092e8 100644 --- a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr +++ b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Trait` - --> $DIR/issue-84660-unsoundness.rs:29:1 + --> $DIR/issue-84660-unsoundness.rs:28:1 | LL | impl Trait for Out { | ------------------------------------ first implementation here @@ -13,7 +13,6 @@ error[E0284]: type annotations needed: cannot satisfy `Bar == _` LL | fn convert(_i: In) -> Self::Out { | _____________________________________^ LL | | -LL | | LL | | unreachable!(); LL | | } | |_____^ cannot satisfy `Bar == _` diff --git a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs index f3234bafd1153..f5ff73c7eeadd 100644 --- a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs +++ b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs @@ -21,7 +21,6 @@ impl Trait for Out { type Out = Out; fn convert(_i: In) -> Self::Out { //[next]~^ ERROR: cannot satisfy `Bar == _` - //[current]~^^ ERROR: item does not constrain `Bar::{opaque#0}`, but has it in its signature unreachable!(); } } diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr deleted file mode 100644 index 915432bbe675f..0000000000000 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0277]: the trait bound `(): Foo` is not satisfied - --> $DIR/nested-tait-inference.rs:17:13 - | -LL | fn foo() -> impl Foo { - | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()` -... -LL | () - | -- return type was inferred to be `()` here - | - = help: the trait `Foo` is not implemented for `()` - but trait `Foo<()>` is implemented for it - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference.rs b/tests/ui/type-alias-impl-trait/nested-tait-inference.rs index 50d51c7faf91b..70495c44706a7 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference.rs +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference.rs @@ -4,7 +4,7 @@ //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) //@[next] compile-flags: -Znext-solver -//@[next] check-pass +//@check-pass use std::fmt::Debug; @@ -15,8 +15,6 @@ trait Foo {} impl Foo<()> for () {} fn foo() -> impl Foo { - //[current]~^ ERROR: the trait bound `(): Foo` is not satisfied - // FIXME(type-alias-impl-trait): We could probably make this work. () } diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference2.current.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference2.current.stderr index 9da3926ac7081..387cbd0f926e8 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference2.current.stderr +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference2.current.stderr @@ -1,16 +1,20 @@ -error[E0277]: the trait bound `(): Foo` is not satisfied +error[E0283]: type annotations needed: cannot satisfy `(): Foo` --> $DIR/nested-tait-inference2.rs:17:13 | LL | fn foo() -> impl Foo { - | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()` + | ^^^^^^^^^^^^^^ LL | LL | () | -- return type was inferred to be `()` here | - = help: the following other types implement trait `Foo`: - `()` implements `Foo<()>` - `()` implements `Foo` +note: multiple `impl`s satisfying `(): Foo` found + --> $DIR/nested-tait-inference2.rs:14:1 + | +LL | impl Foo<()> for () {} + | ^^^^^^^^^^^^^^^^^^^ +LL | impl Foo for () {} + | ^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference2.rs b/tests/ui/type-alias-impl-trait/nested-tait-inference2.rs index 28d72b0cbeede..fe2f76e552ad7 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference2.rs +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference2.rs @@ -15,7 +15,7 @@ impl Foo<()> for () {} impl Foo for () {} fn foo() -> impl Foo { - //[current]~^ ERROR: the trait bound `(): Foo` is not satisfied + //[current]~^ ERROR: cannot satisfy `(): Foo` () //[next]~^ ERROR: cannot satisfy `impl Foo == ()` } diff --git a/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr b/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr index a40dac06a01c3..eff29303bf18e 100644 --- a/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr +++ b/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr @@ -22,21 +22,17 @@ note: previous use here LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) } | ^^^^^^^^^^^^^^^^^ -error[E0308]: mismatched types +error: concrete type differs from previous defining opaque type use --> $DIR/normalize-hidden-types.rs:43:25 | -LL | type Opaque = impl Sized; - | ---------- the expected opaque type -... LL | let _: Opaque = dyn_hoops::(0); - | ------ ^^^^^^^^^^^^^^^^^^ expected opaque type, found `*const dyn FnOnce(())` - | | - | expected due to this - | - = note: expected opaque type `typeck::Opaque` - found raw pointer `*const (dyn FnOnce(()) + 'static)` - = help: consider constraining the associated type `::Gat<'_>` to `()` or calling a method that returns `::Gat<'_>` - = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + | ^^^^^^^^^^^^^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(::Gat<'a>)` + | +note: previous use here + --> $DIR/normalize-hidden-types.rs:44:9 + | +LL | None + | ^^^^ error: concrete type differs from previous defining opaque type use --> $DIR/normalize-hidden-types.rs:52:25 @@ -52,4 +48,3 @@ LL | None error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr b/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr deleted file mode 100644 index e4399f2d8f4d3..0000000000000 --- a/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0277]: can't compare `i32` with `Foo` - --> $DIR/self-referential-2.rs:10:13 - | -LL | fn bar() -> Bar { - | ^^^ no implementation for `i32 == Foo` -LL | 42_i32 - | ------ return type was inferred to be `i32` here - | - = help: the trait `PartialEq` is not implemented for `i32` - but trait `PartialEq` is implemented for it - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/type-alias-impl-trait/self-referential-2.rs b/tests/ui/type-alias-impl-trait/self-referential-2.rs index f96364ccfcddf..f4102f2e2cb71 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-2.rs +++ b/tests/ui/type-alias-impl-trait/self-referential-2.rs @@ -1,14 +1,14 @@ //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) //@[next] compile-flags: -Znext-solver -//@[next] check-pass +//@ check-pass #![feature(type_alias_impl_trait)] type Foo = impl std::fmt::Debug; type Bar = impl PartialEq; fn bar() -> Bar { - 42_i32 //[current]~^ ERROR can't compare `i32` with `Foo` + 42_i32 } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/self-referential-3.rs b/tests/ui/type-alias-impl-trait/self-referential-3.rs index b33051da2d779..3b015ab322aca 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-3.rs +++ b/tests/ui/type-alias-impl-trait/self-referential-3.rs @@ -5,7 +5,7 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { - //~^ ERROR can't compare `&i32` with `Bar<'a, 'b>` + //~^ ERROR overflow normalizing the type alias `Bar<'a, 'b>` i } diff --git a/tests/ui/type-alias-impl-trait/self-referential-3.stderr b/tests/ui/type-alias-impl-trait/self-referential-3.stderr index 32eac622e5181..caa9f9691dda5 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-3.stderr +++ b/tests/ui/type-alias-impl-trait/self-referential-3.stderr @@ -1,15 +1,11 @@ -error[E0277]: can't compare `&i32` with `Bar<'a, 'b>` +error[E0275]: overflow normalizing the type alias `Bar<'a, 'b>` --> $DIR/self-referential-3.rs:7:31 | LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { - | ^^^^^^^^^^^ no implementation for `&i32 == Bar<'a, 'b>` -LL | -LL | i - | - return type was inferred to be `&i32` here + | ^^^^^^^^^^^ | - = help: the trait `PartialEq>` is not implemented for `&i32` - = help: the trait `PartialEq` is implemented for `i32` + = note: in case this is a recursive type alias, consider using a struct, enum, or union instead error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0275`. From 0b401c16d869bbdfb47facbdb234a76b01ed0b61 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 11 Jun 2024 09:22:28 +0000 Subject: [PATCH 2/4] Leave error reporting of method calls on inference variables to method call checks --- compiler/rustc_hir_typeck/src/expr.rs | 2 +- .../obligation-with-leaking-placeholders.next.stderr | 2 +- .../ui/impl-trait/call_method_ambiguous.next.stderr | 2 +- .../call_method_on_inherent_impl.next.stderr | 2 +- .../call_method_on_inherent_impl_ref.next.stderr | 2 +- .../hidden-type-is-opaque-2.default.stderr | 4 ++-- .../impl-trait/hidden-type-is-opaque-2.next.stderr | 4 ++-- tests/ui/impl-trait/method-resolution4.next.stderr | 4 ++-- tests/ui/impl-trait/recursive-bound-eval.next.stderr | 4 ++-- .../incompat-call-after-qualified-path-0.stderr | 2 +- .../incompat-call-after-qualified-path-1.stderr | 2 +- tests/ui/issues/issue-2151.stderr | 2 +- tests/ui/lazy-type-alias-impl-trait/branches3.stderr | 8 ++++---- .../issue-42234-unknown-receiver-type.full.stderr | 4 +++- ...ue-42234-unknown-receiver-type.generic_arg.stderr | 4 +++- .../closures_in_branches.stderr | 4 ++-- ...d_resolution_trait_method_from_opaque.next.stderr | 4 ++-- tests/ui/typeck/issue-13853.rs | 2 +- tests/ui/typeck/issue-13853.stderr | 12 +++++++++--- 19 files changed, 40 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 4699b342cec28..98b28f2b6f90c 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1567,7 +1567,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Ty<'tcx> { let rcvr_t = self.check_expr(rcvr); // no need to check for bot/err -- callee does that - let rcvr_t = self.structurally_resolve_type(rcvr.span, rcvr_t); + let rcvr_t = self.try_structurally_resolve_type(rcvr.span, rcvr_t); let method = match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args) { diff --git a/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr b/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr index 3d667f12371ab..4bb9047b3035d 100644 --- a/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr +++ b/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr @@ -5,7 +5,7 @@ LL | needs_foo(|x| { | ^ ... LL | x.to_string(); - | - type must be known at this point + | --------- type must be known at this point | help: consider giving this closure parameter an explicit type | diff --git a/tests/ui/impl-trait/call_method_ambiguous.next.stderr b/tests/ui/impl-trait/call_method_ambiguous.next.stderr index 5251555f57421..0def594daf1cc 100644 --- a/tests/ui/impl-trait/call_method_ambiguous.next.stderr +++ b/tests/ui/impl-trait/call_method_ambiguous.next.stderr @@ -5,7 +5,7 @@ LL | let mut iter = foo(n - 1, m); | ^^^^^^^^ LL | LL | assert_eq!(iter.get(), 1); - | ---- type must be known at this point + | --- type must be known at this point | help: consider giving `iter` an explicit type | diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr index 271051f120abc..7bbf5f5153a59 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr @@ -5,7 +5,7 @@ LL | let x = my_foo(); | ^ LL | LL | x.my_debug(); - | - type must be known at this point + | -------- type must be known at this point | help: consider giving `x` an explicit type | diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr index 7202cb6f90a6f..5dea3a715e9bc 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr @@ -5,7 +5,7 @@ LL | let x = my_foo(); | ^ LL | LL | x.my_debug(); - | - type must be known at this point + | -------- type must be known at this point | help: consider giving `x` an explicit type | diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr b/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr index 01c5a553dc502..554979408aba8 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr +++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr @@ -5,7 +5,7 @@ LL | Thunk::new(|mut cont| { | ^^^^^^^^ LL | LL | cont.reify_as(); - | ---- type must be known at this point + | -------- type must be known at this point | help: consider giving this closure parameter an explicit type | @@ -19,7 +19,7 @@ LL | Thunk::new(|mut cont| { | ^^^^^^^^ LL | LL | cont.reify_as(); - | ---- type must be known at this point + | -------- type must be known at this point | help: consider giving this closure parameter an explicit type | diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr b/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr index 01c5a553dc502..554979408aba8 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr +++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr @@ -5,7 +5,7 @@ LL | Thunk::new(|mut cont| { | ^^^^^^^^ LL | LL | cont.reify_as(); - | ---- type must be known at this point + | -------- type must be known at this point | help: consider giving this closure parameter an explicit type | @@ -19,7 +19,7 @@ LL | Thunk::new(|mut cont| { | ^^^^^^^^ LL | LL | cont.reify_as(); - | ---- type must be known at this point + | -------- type must be known at this point | help: consider giving this closure parameter an explicit type | diff --git a/tests/ui/impl-trait/method-resolution4.next.stderr b/tests/ui/impl-trait/method-resolution4.next.stderr index 0524f49f98e58..47a9aac19ecc3 100644 --- a/tests/ui/impl-trait/method-resolution4.next.stderr +++ b/tests/ui/impl-trait/method-resolution4.next.stderr @@ -1,8 +1,8 @@ error[E0282]: type annotations needed - --> $DIR/method-resolution4.rs:13:9 + --> $DIR/method-resolution4.rs:13:20 | LL | foo(false).next().unwrap(); - | ^^^^^^^^^^ cannot infer type + | ^^^^ cannot infer type error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/recursive-bound-eval.next.stderr b/tests/ui/impl-trait/recursive-bound-eval.next.stderr index fc37b5fa14ef6..8435b3375bb02 100644 --- a/tests/ui/impl-trait/recursive-bound-eval.next.stderr +++ b/tests/ui/impl-trait/recursive-bound-eval.next.stderr @@ -1,8 +1,8 @@ error[E0282]: type annotations needed - --> $DIR/recursive-bound-eval.rs:18:13 + --> $DIR/recursive-bound-eval.rs:18:28 | LL | move || recursive_fn().parse() - | ^^^^^^^^^^^^^^ cannot infer type + | ^^^^^ cannot infer type error: aborting due to 1 previous error diff --git a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr index 10056bdf3d4f4..ba1c81c4518a7 100644 --- a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr +++ b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/incompat-call-after-qualified-path-0.rs:21:6 | LL | f(|a, b| a.cmp(b)); - | ^ - type must be known at this point + | ^ --- type must be known at this point | help: consider giving this closure parameter an explicit type | diff --git a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr index 632a9b99f84ef..93bba3625b540 100644 --- a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr +++ b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/incompat-call-after-qualified-path-1.rs:25:6 | LL | f(|a, b| a.cmp(b)); - | ^ - type must be known at this point + | ^ --- type must be known at this point | help: consider giving this closure parameter an explicit type | diff --git a/tests/ui/issues/issue-2151.stderr b/tests/ui/issues/issue-2151.stderr index b130f162414d0..59fef42eb5e8b 100644 --- a/tests/ui/issues/issue-2151.stderr +++ b/tests/ui/issues/issue-2151.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | let x = panic!(); | ^ LL | x.clone(); - | - type must be known at this point + | ----- type must be known at this point | help: consider giving `x` an explicit type | diff --git a/tests/ui/lazy-type-alias-impl-trait/branches3.stderr b/tests/ui/lazy-type-alias-impl-trait/branches3.stderr index fe2631f947420..270fbfa81bb89 100644 --- a/tests/ui/lazy-type-alias-impl-trait/branches3.stderr +++ b/tests/ui/lazy-type-alias-impl-trait/branches3.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/branches3.rs:8:10 | LL | |s| s.len() - | ^ - type must be known at this point + | ^ --- type must be known at this point | help: consider giving this closure parameter an explicit type | @@ -13,7 +13,7 @@ error[E0282]: type annotations needed --> $DIR/branches3.rs:15:10 | LL | |s| s.len() - | ^ - type must be known at this point + | ^ --- type must be known at this point | help: consider giving this closure parameter an explicit type | @@ -24,7 +24,7 @@ error[E0282]: type annotations needed --> $DIR/branches3.rs:23:10 | LL | |s| s.len() - | ^ - type must be known at this point + | ^ --- type must be known at this point | help: consider giving this closure parameter an explicit type | @@ -35,7 +35,7 @@ error[E0282]: type annotations needed --> $DIR/branches3.rs:30:10 | LL | |s| s.len() - | ^ - type must be known at this point + | ^ --- type must be known at this point | help: consider giving this closure parameter an explicit type | diff --git a/tests/ui/span/issue-42234-unknown-receiver-type.full.stderr b/tests/ui/span/issue-42234-unknown-receiver-type.full.stderr index 6559845c23ec5..c2c6f2b99bc24 100644 --- a/tests/ui/span/issue-42234-unknown-receiver-type.full.stderr +++ b/tests/ui/span/issue-42234-unknown-receiver-type.full.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | let x: Option<_> = None; | ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option` LL | x.unwrap().method_that_could_exist_on_some_type(); - | ---------- type must be known at this point + | ------------------------------------ type must be known at this point | help: consider specifying the generic argument | @@ -16,6 +16,8 @@ error[E0282]: type annotations needed | LL | .sum::<_>() | ^^^ cannot infer type of the type parameter `S` declared on the method `sum` +LL | .to_string() + | --------- type must be known at this point | error: aborting due to 2 previous errors diff --git a/tests/ui/span/issue-42234-unknown-receiver-type.generic_arg.stderr b/tests/ui/span/issue-42234-unknown-receiver-type.generic_arg.stderr index a4b6525657406..74c46f6471237 100644 --- a/tests/ui/span/issue-42234-unknown-receiver-type.generic_arg.stderr +++ b/tests/ui/span/issue-42234-unknown-receiver-type.generic_arg.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | let x: Option<_> = None; | ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option` LL | x.unwrap().method_that_could_exist_on_some_type(); - | ---------- type must be known at this point + | ------------------------------------ type must be known at this point | help: consider specifying the generic argument | @@ -16,6 +16,8 @@ error[E0282]: type annotations needed | LL | .sum::<_>() | ^^^ cannot infer type of the type parameter `S` declared on the method `sum` +LL | .to_string() + | --------- type must be known at this point | help: consider specifying the generic argument | diff --git a/tests/ui/type-alias-impl-trait/closures_in_branches.stderr b/tests/ui/type-alias-impl-trait/closures_in_branches.stderr index 9cc15f14a991d..d6defe35866c5 100644 --- a/tests/ui/type-alias-impl-trait/closures_in_branches.stderr +++ b/tests/ui/type-alias-impl-trait/closures_in_branches.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/closures_in_branches.rs:7:10 | LL | |x| x.len() - | ^ - type must be known at this point + | ^ --- type must be known at this point | help: consider giving this closure parameter an explicit type | @@ -13,7 +13,7 @@ error[E0282]: type annotations needed --> $DIR/closures_in_branches.rs:21:10 | LL | |x| x.len() - | ^ - type must be known at this point + | ^ --- type must be known at this point | help: consider giving this closure parameter an explicit type | diff --git a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr index 2617ce124c105..870938032e579 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr @@ -1,8 +1,8 @@ error[E0282]: type annotations needed - --> $DIR/method_resolution_trait_method_from_opaque.rs:26:9 + --> $DIR/method_resolution_trait_method_from_opaque.rs:26:18 | LL | self.bar.next().unwrap(); - | ^^^^^^^^ cannot infer type + | ^^^^ cannot infer type error: aborting due to 1 previous error diff --git a/tests/ui/typeck/issue-13853.rs b/tests/ui/typeck/issue-13853.rs index ac9886d2e7249..ed44d5062614f 100644 --- a/tests/ui/typeck/issue-13853.rs +++ b/tests/ui/typeck/issue-13853.rs @@ -25,7 +25,7 @@ impl Node for Stuff { fn iterate>(graph: &G) { for node in graph.iter() { //~ ERROR no method named `iter` found - node.zomg(); + node.zomg(); //~ ERROR type annotations needed } } diff --git a/tests/ui/typeck/issue-13853.stderr b/tests/ui/typeck/issue-13853.stderr index 45363c87d29df..9b8698d6ed2c0 100644 --- a/tests/ui/typeck/issue-13853.stderr +++ b/tests/ui/typeck/issue-13853.stderr @@ -17,6 +17,12 @@ error[E0599]: no method named `iter` found for reference `&G` in the current sco LL | for node in graph.iter() { | ^^^^ method not found in `&G` +error[E0282]: type annotations needed + --> $DIR/issue-13853.rs:28:14 + | +LL | node.zomg(); + | ^^^^ cannot infer type + error[E0308]: mismatched types --> $DIR/issue-13853.rs:37:13 | @@ -37,7 +43,7 @@ help: consider borrowing here LL | iterate(&graph); | + -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0308, E0599. -For more information about an error, try `rustc --explain E0308`. +Some errors have detailed explanations: E0282, E0308, E0599. +For more information about an error, try `rustc --explain E0282`. From 193ac2bd061cdb49e5c42afa439e792d1cb20f70 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 11 Jun 2024 13:11:58 +0000 Subject: [PATCH 3/4] Do not fail `method_autoderef_steps` on infer types. Let method resolution handle it --- compiler/rustc_hir_typeck/src/method/probe.rs | 1 + ..._mismatch_on_associatedtype_constructor.rs | 30 +++++++++++++++++++ ...match_on_associatedtype_constructor.stderr | 22 ++++++++++++++ .../deref-ambiguity-becomes-nonambiguous.rs | 4 +-- ...eref-ambiguity-becomes-nonambiguous.stderr | 20 ++++++------- ...tion-with-leaking-placeholders.next.stderr | 2 +- .../call_method_ambiguous.next.stderr | 2 +- .../call_method_on_inherent_impl.next.stderr | 2 +- ...on_inherent_impl_on_rigid_type.next.stderr | 2 +- ...ll_method_on_inherent_impl_ref.next.stderr | 4 +-- .../hidden-type-is-opaque-2.default.stderr | 30 +++++-------------- .../hidden-type-is-opaque-2.next.stderr | 30 +++++-------------- .../ui/impl-trait/hidden-type-is-opaque-2.rs | 4 +-- .../impl-trait/method-resolution4.next.stderr | 4 +-- .../recursive-bound-eval.current.stderr | 9 ------ .../recursive-bound-eval.next.stderr | 4 +-- tests/ui/impl-trait/recursive-bound-eval.rs | 4 ++- .../recursive-coroutine-boxed.next.stderr | 17 ----------- .../impl-trait/recursive-coroutine-boxed.rs | 9 ++---- ...d-time-version-format_description-parse.rs | 6 ++-- ...me-version-format_description-parse.stderr | 14 --------- .../incompat-call-after-qualified-path-0.rs | 2 +- ...ncompat-call-after-qualified-path-0.stderr | 24 ++++++++++----- .../incompat-call-after-qualified-path-1.rs | 2 +- ...ncompat-call-after-qualified-path-1.stderr | 24 ++++++++++----- tests/ui/issues/issue-20261.stderr | 4 +-- tests/ui/issues/issue-2151.stderr | 2 +- .../branches3.stderr | 8 ++--- ...ue-42234-unknown-receiver-type.full.stderr | 20 ++++--------- ...4-unknown-receiver-type.generic_arg.stderr | 20 ++++--------- .../span/issue-42234-unknown-receiver-type.rs | 3 +- .../closures_in_branches.stderr | 4 +-- ...ution_trait_method_from_opaque.next.stderr | 4 +-- tests/ui/typeck/issue-13853.rs | 2 +- tests/ui/typeck/issue-13853.stderr | 18 ++++++++--- 35 files changed, 174 insertions(+), 183 deletions(-) create mode 100644 tests/ui/associated-types/param_mismatch_on_associatedtype_constructor.rs create mode 100644 tests/ui/associated-types/param_mismatch_on_associatedtype_constructor.stderr delete mode 100644 tests/ui/impl-trait/recursive-bound-eval.current.stderr delete mode 100644 tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr delete mode 100644 tests/ui/inference/detect-old-time-version-format_description-parse.stderr diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 039c117c09995..62dfb5d59fc6a 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -540,6 +540,7 @@ fn method_autoderef_steps<'tcx>( let final_ty = autoderef.final_ty(true); let opt_bad_ty = match final_ty.kind() { + ty::Infer(ty::TyVar(_)) if !reached_raw_pointer => None, ty::Infer(ty::TyVar(_)) | ty::Error(_) => Some(MethodAutoderefBadTy { reached_raw_pointer, ty: infcx.make_query_response_ignoring_pending_obligations(inference_vars, final_ty), diff --git a/tests/ui/associated-types/param_mismatch_on_associatedtype_constructor.rs b/tests/ui/associated-types/param_mismatch_on_associatedtype_constructor.rs new file mode 100644 index 0000000000000..be3adfe8665fe --- /dev/null +++ b/tests/ui/associated-types/param_mismatch_on_associatedtype_constructor.rs @@ -0,0 +1,30 @@ +//! This test used to ICE #121613 +//! Using a generic parameter where there are none expected +//! caused an ICE, hiding the important later errors. + +#![feature(more_qualified_paths)] + +fn main() { + let _ = ::Assoc { br: 2 }; + + let ::V(..) = E::V(|a, b| a.cmp(b)); + //~^ ERROR: multiple applicable items in scope +} + +struct StructStruct { + br: i8, +} + +struct Foo; + +trait A { + type Assoc; +} + +impl A for Foo { + type Assoc = StructStruct; +} + +enum E { + V(u8), +} diff --git a/tests/ui/associated-types/param_mismatch_on_associatedtype_constructor.stderr b/tests/ui/associated-types/param_mismatch_on_associatedtype_constructor.stderr new file mode 100644 index 0000000000000..babb350f62915 --- /dev/null +++ b/tests/ui/associated-types/param_mismatch_on_associatedtype_constructor.stderr @@ -0,0 +1,22 @@ +error[E0034]: multiple applicable items in scope + --> $DIR/param_mismatch_on_associatedtype_constructor.rs:10:36 + | +LL | let ::V(..) = E::V(|a, b| a.cmp(b)); + | ^^^ multiple `cmp` found + | +note: candidate #1 is defined in the trait `Iterator` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL +note: candidate #2 is defined in the trait `Ord` + --> $SRC_DIR/core/src/cmp.rs:LL:COL +help: disambiguate the method for candidate #1 + | +LL | let ::V(..) = E::V(|a, b| Iterator::cmp(a, b)); + | ~~~~~~~~~~~~~~~~~~~ +help: disambiguate the method for candidate #2 + | +LL | let ::V(..) = E::V(|a, b| Ord::cmp(&a, b)); + | ~~~~~~~~~~~~~~~ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0034`. diff --git a/tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.rs b/tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.rs index d8034d57e8d56..489b9b7ac51a8 100644 --- a/tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.rs +++ b/tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.rs @@ -19,7 +19,7 @@ impl Wrap for Value R>> { } } -impl Deref for Value> { +impl Deref for Value> { type Target = F; fn deref(&self) -> &Self::Target { @@ -29,7 +29,6 @@ impl Deref for Value> { fn main() { let var_fn = Value::wrap(); - //~^ ERROR type annotations needed for `Value>` // The combination of `Value: Wrap` obligation plus the autoderef steps // (caused by the `Deref` impl above) actually means that the self type @@ -37,4 +36,5 @@ fn main() { // However, that's only known to us on the error path -- we still need // to emit an ambiguity error, though. let _ = var_fn.clone(); + //~^ ERROR type annotations needed } diff --git a/tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.stderr b/tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.stderr index 19c3c64181985..529485f030414 100644 --- a/tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.stderr +++ b/tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.stderr @@ -1,17 +1,17 @@ -error[E0282]: type annotations needed for `Value>` - --> $DIR/deref-ambiguity-becomes-nonambiguous.rs:31:9 +error[E0283]: type annotations needed + --> $DIR/deref-ambiguity-becomes-nonambiguous.rs:38:9 | -LL | let var_fn = Value::wrap(); - | ^^^^^^ -... LL | let _ = var_fn.clone(); - | ----- type must be known at this point + | ^ ------ ----- required by a bound introduced by this call + | | + | type must be known at this point | -help: consider giving `var_fn` an explicit type, where the placeholders `_` are specified + = note: cannot satisfy `_: Clone` +help: consider giving this pattern a type | -LL | let var_fn: Value> = Value::wrap(); - | ++++++++++++++ +LL | let _: /* Type */ = var_fn.clone(); + | ++++++++++++ error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr b/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr index 4bb9047b3035d..481a0889a0662 100644 --- a/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr +++ b/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr @@ -5,7 +5,7 @@ LL | needs_foo(|x| { | ^ ... LL | x.to_string(); - | --------- type must be known at this point + | ------------- type must be known at this point | help: consider giving this closure parameter an explicit type | diff --git a/tests/ui/impl-trait/call_method_ambiguous.next.stderr b/tests/ui/impl-trait/call_method_ambiguous.next.stderr index 0def594daf1cc..41589dacba767 100644 --- a/tests/ui/impl-trait/call_method_ambiguous.next.stderr +++ b/tests/ui/impl-trait/call_method_ambiguous.next.stderr @@ -5,7 +5,7 @@ LL | let mut iter = foo(n - 1, m); | ^^^^^^^^ LL | LL | assert_eq!(iter.get(), 1); - | --- type must be known at this point + | ---------- type must be known at this point | help: consider giving `iter` an explicit type | diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr index 7bbf5f5153a59..323c8e85f963f 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr @@ -5,7 +5,7 @@ LL | let x = my_foo(); | ^ LL | LL | x.my_debug(); - | -------- type must be known at this point + | ------------ type must be known at this point | help: consider giving `x` an explicit type | diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr index e60f1bfb361c3..2e6b1d8aeba5b 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr @@ -5,7 +5,7 @@ LL | let x = &my_foo(); | ^ LL | LL | x.my_debug(); - | -------- type must be known at this point + | ------------ type must be known at this point | help: consider giving `x` an explicit type, where the placeholders `_` are specified | diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr index 5dea3a715e9bc..774796a60ab2d 100644 --- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr +++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr @@ -5,7 +5,7 @@ LL | let x = my_foo(); | ^ LL | LL | x.my_debug(); - | -------- type must be known at this point + | ------------ type must be known at this point | help: consider giving `x` an explicit type | @@ -19,7 +19,7 @@ LL | let x = &my_bar(); | ^ LL | LL | x.my_debug(); - | -------- type must be known at this point + | ------------ type must be known at this point | help: consider giving `x` an explicit type, where the placeholders `_` are specified | diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr b/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr index 554979408aba8..41281b22895a4 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr +++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr @@ -1,31 +1,15 @@ -error[E0282]: type annotations needed - --> $DIR/hidden-type-is-opaque-2.rs:10:17 +error[E0599]: no method named `reify_as` found for type `_` in the current scope + --> $DIR/hidden-type-is-opaque-2.rs:11:14 | -LL | Thunk::new(|mut cont| { - | ^^^^^^^^ -LL | LL | cont.reify_as(); - | -------- type must be known at this point - | -help: consider giving this closure parameter an explicit type - | -LL | Thunk::new(|mut cont: /* Type */| { - | ++++++++++++ + | ^^^^^^^^ method not found in `_` -error[E0282]: type annotations needed - --> $DIR/hidden-type-is-opaque-2.rs:20:17 +error[E0599]: no method named `reify_as` found for type `_` in the current scope + --> $DIR/hidden-type-is-opaque-2.rs:21:14 | -LL | Thunk::new(|mut cont| { - | ^^^^^^^^ -LL | LL | cont.reify_as(); - | -------- type must be known at this point - | -help: consider giving this closure parameter an explicit type - | -LL | Thunk::new(|mut cont: /* Type */| { - | ++++++++++++ + | ^^^^^^^^ method not found in `_` error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr b/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr index 554979408aba8..41281b22895a4 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr +++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr @@ -1,31 +1,15 @@ -error[E0282]: type annotations needed - --> $DIR/hidden-type-is-opaque-2.rs:10:17 +error[E0599]: no method named `reify_as` found for type `_` in the current scope + --> $DIR/hidden-type-is-opaque-2.rs:11:14 | -LL | Thunk::new(|mut cont| { - | ^^^^^^^^ -LL | LL | cont.reify_as(); - | -------- type must be known at this point - | -help: consider giving this closure parameter an explicit type - | -LL | Thunk::new(|mut cont: /* Type */| { - | ++++++++++++ + | ^^^^^^^^ method not found in `_` -error[E0282]: type annotations needed - --> $DIR/hidden-type-is-opaque-2.rs:20:17 +error[E0599]: no method named `reify_as` found for type `_` in the current scope + --> $DIR/hidden-type-is-opaque-2.rs:21:14 | -LL | Thunk::new(|mut cont| { - | ^^^^^^^^ -LL | LL | cont.reify_as(); - | -------- type must be known at this point - | -help: consider giving this closure parameter an explicit type - | -LL | Thunk::new(|mut cont: /* Type */| { - | ++++++++++++ + | ^^^^^^^^ method not found in `_` error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.rs b/tests/ui/impl-trait/hidden-type-is-opaque-2.rs index 78ac8363ba930..bc5945c6d120d 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque-2.rs +++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.rs @@ -8,8 +8,8 @@ fn reify_as() -> Thunk Continuation> { Thunk::new(|mut cont| { - //~^ ERROR type annotations needed cont.reify_as(); + //~^ ERROR: no method named `reify_as` found for type `_` cont }) } @@ -18,8 +18,8 @@ type Tait = impl FnOnce(Continuation) -> Continuation; fn reify_as_tait() -> Thunk { Thunk::new(|mut cont| { - //~^ ERROR type annotations needed cont.reify_as(); + //~^ ERROR: no method named `reify_as` found for type `_` cont }) } diff --git a/tests/ui/impl-trait/method-resolution4.next.stderr b/tests/ui/impl-trait/method-resolution4.next.stderr index 47a9aac19ecc3..b1bef77781296 100644 --- a/tests/ui/impl-trait/method-resolution4.next.stderr +++ b/tests/ui/impl-trait/method-resolution4.next.stderr @@ -1,8 +1,8 @@ error[E0282]: type annotations needed - --> $DIR/method-resolution4.rs:13:20 + --> $DIR/method-resolution4.rs:13:9 | LL | foo(false).next().unwrap(); - | ^^^^ cannot infer type + | ^^^^^^^^^^^^^^^^^ cannot infer type error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/recursive-bound-eval.current.stderr b/tests/ui/impl-trait/recursive-bound-eval.current.stderr deleted file mode 100644 index 8435b3375bb02..0000000000000 --- a/tests/ui/impl-trait/recursive-bound-eval.current.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/recursive-bound-eval.rs:18:28 - | -LL | move || recursive_fn().parse() - | ^^^^^ cannot infer type - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/impl-trait/recursive-bound-eval.next.stderr b/tests/ui/impl-trait/recursive-bound-eval.next.stderr index 8435b3375bb02..d2c1e82b9b100 100644 --- a/tests/ui/impl-trait/recursive-bound-eval.next.stderr +++ b/tests/ui/impl-trait/recursive-bound-eval.next.stderr @@ -1,8 +1,8 @@ error[E0282]: type annotations needed - --> $DIR/recursive-bound-eval.rs:18:28 + --> $DIR/recursive-bound-eval.rs:20:13 | LL | move || recursive_fn().parse() - | ^^^^^ cannot infer type + | ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/recursive-bound-eval.rs b/tests/ui/impl-trait/recursive-bound-eval.rs index 5f6247fc851fa..7859c8983fc89 100644 --- a/tests/ui/impl-trait/recursive-bound-eval.rs +++ b/tests/ui/impl-trait/recursive-bound-eval.rs @@ -4,6 +4,8 @@ //@revisions: next current //@[next] compile-flags: -Znext-solver +//@[current] check-pass + pub trait Parser { fn parse(&self) -> E; } @@ -16,7 +18,7 @@ impl E> Parser for T { pub fn recursive_fn() -> impl Parser { move || recursive_fn().parse() - //~^ ERROR: type annotations needed + //[next]~^ ERROR: type annotations needed } fn main() {} diff --git a/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr b/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr deleted file mode 100644 index 132f7de4ef230..0000000000000 --- a/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/recursive-coroutine-boxed.rs:14:23 - | -LL | let mut gen = Box::pin(foo()); - | ^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `Box` -LL | -LL | let mut r = gen.as_mut().resume(()); - | ------ type must be known at this point - | -help: consider specifying the generic argument - | -LL | let mut gen = Box::::pin(foo()); - | +++++ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/impl-trait/recursive-coroutine-boxed.rs b/tests/ui/impl-trait/recursive-coroutine-boxed.rs index 8d38e6aed1246..12b29b82ccd5f 100644 --- a/tests/ui/impl-trait/recursive-coroutine-boxed.rs +++ b/tests/ui/impl-trait/recursive-coroutine-boxed.rs @@ -1,18 +1,15 @@ //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) -//@[current] check-pass +//@ check-pass //@[next] compile-flags: -Znext-solver #![feature(coroutines, coroutine_trait)] use std::ops::{Coroutine, CoroutineState}; fn foo() -> impl Coroutine { - // FIXME(-Znext-solver): this fails with a mismatched types as the - // hidden type of the opaque ends up as {type error}. We should not - // emit errors for such goals. - #[coroutine] || { + #[coroutine] + || { let mut gen = Box::pin(foo()); - //[next]~^ ERROR type annotations needed let mut r = gen.as_mut().resume(()); while let CoroutineState::Yielded(v) = r { yield v; diff --git a/tests/ui/inference/detect-old-time-version-format_description-parse.rs b/tests/ui/inference/detect-old-time-version-format_description-parse.rs index 386b2a3bf3c8a..312a402708a95 100644 --- a/tests/ui/inference/detect-old-time-version-format_description-parse.rs +++ b/tests/ui/inference/detect-old-time-version-format_description-parse.rs @@ -1,13 +1,13 @@ #![crate_name = "time"] #![crate_type = "lib"] +//@check-pass + // This code compiled without error in Rust 1.79, but started failing in 1.80 // after the addition of several `impl FromIterator<_> for Box`. pub fn parse() -> Option> { let iter = std::iter::once(Some(())).map(|o| o.map(Into::into)); - let items = iter.collect::>>()?; //~ ERROR E0282 - //~^ NOTE this is an inference error on crate `time` caused by an API change in Rust 1.80.0; update `time` to version `>=0.3.35` + let items = iter.collect::>>()?; Some(items.into()) - //~^ NOTE type must be known at this point } diff --git a/tests/ui/inference/detect-old-time-version-format_description-parse.stderr b/tests/ui/inference/detect-old-time-version-format_description-parse.stderr deleted file mode 100644 index a70ce9dd2681c..0000000000000 --- a/tests/ui/inference/detect-old-time-version-format_description-parse.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0282]: type annotations needed for `Box<_>` - --> $DIR/detect-old-time-version-format_description-parse.rs:9:9 - | -LL | let items = iter.collect::>>()?; - | ^^^^^ -LL | -LL | Some(items.into()) - | ---- type must be known at this point - | - = note: this is an inference error on crate `time` caused by an API change in Rust 1.80.0; update `time` to version `>=0.3.35` by calling `cargo update` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.rs b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.rs index 830a6390fce6d..82b2749117a72 100644 --- a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.rs +++ b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.rs @@ -19,6 +19,6 @@ fn f() {} fn main() { ::Assoc {}; f(|a, b| a.cmp(b)); - //~^ ERROR: type annotations needed + //~^ ERROR: multiple applicable items in scope //~| ERROR: this function takes 0 arguments but 1 argument was supplied } diff --git a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr index ba1c81c4518a7..7ebf4b0221d87 100644 --- a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr +++ b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr @@ -1,13 +1,21 @@ -error[E0282]: type annotations needed - --> $DIR/incompat-call-after-qualified-path-0.rs:21:6 +error[E0034]: multiple applicable items in scope + --> $DIR/incompat-call-after-qualified-path-0.rs:21:14 | LL | f(|a, b| a.cmp(b)); - | ^ --- type must be known at this point + | ^^^ multiple `cmp` found | -help: consider giving this closure parameter an explicit type +note: candidate #1 is defined in the trait `Iterator` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL +note: candidate #2 is defined in the trait `Ord` + --> $SRC_DIR/core/src/cmp.rs:LL:COL +help: disambiguate the method for candidate #1 | -LL | f(|a: /* Type */, b| a.cmp(b)); - | ++++++++++++ +LL | f(|a, b| Iterator::cmp(a, b)); + | ~~~~~~~~~~~~~~~~~~~ +help: disambiguate the method for candidate #2 + | +LL | f(|a, b| Ord::cmp(&a, b)); + | ~~~~~~~~~~~~~~~ error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/incompat-call-after-qualified-path-0.rs:21:3 @@ -28,5 +36,5 @@ LL + f(); error: aborting due to 2 previous errors -Some errors have detailed explanations: E0061, E0282. -For more information about an error, try `rustc --explain E0061`. +Some errors have detailed explanations: E0034, E0061. +For more information about an error, try `rustc --explain E0034`. diff --git a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.rs b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.rs index 6b786332a8f43..0831920f5ed41 100644 --- a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.rs +++ b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.rs @@ -23,6 +23,6 @@ fn main() { a: 1 }; f(|a, b| a.cmp(b)); - //~^ ERROR: type annotations needed + //~^ ERROR: multiple applicable items in scope //~| ERROR: this function takes 0 arguments but 1 argument was supplied } diff --git a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr index 93bba3625b540..975d8c6b0b924 100644 --- a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr +++ b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr @@ -1,13 +1,21 @@ -error[E0282]: type annotations needed - --> $DIR/incompat-call-after-qualified-path-1.rs:25:6 +error[E0034]: multiple applicable items in scope + --> $DIR/incompat-call-after-qualified-path-1.rs:25:14 | LL | f(|a, b| a.cmp(b)); - | ^ --- type must be known at this point + | ^^^ multiple `cmp` found | -help: consider giving this closure parameter an explicit type +note: candidate #1 is defined in the trait `Iterator` + --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL +note: candidate #2 is defined in the trait `Ord` + --> $SRC_DIR/core/src/cmp.rs:LL:COL +help: disambiguate the method for candidate #1 | -LL | f(|a: /* Type */, b| a.cmp(b)); - | ++++++++++++ +LL | f(|a, b| Iterator::cmp(a, b)); + | ~~~~~~~~~~~~~~~~~~~ +help: disambiguate the method for candidate #2 + | +LL | f(|a, b| Ord::cmp(&a, b)); + | ~~~~~~~~~~~~~~~ error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/incompat-call-after-qualified-path-1.rs:25:3 @@ -28,5 +36,5 @@ LL + f(); error: aborting due to 2 previous errors -Some errors have detailed explanations: E0061, E0282. -For more information about an error, try `rustc --explain E0061`. +Some errors have detailed explanations: E0034, E0061. +For more information about an error, try `rustc --explain E0034`. diff --git a/tests/ui/issues/issue-20261.stderr b/tests/ui/issues/issue-20261.stderr index 6738708ca225d..02c2ac124a603 100644 --- a/tests/ui/issues/issue-20261.stderr +++ b/tests/ui/issues/issue-20261.stderr @@ -1,8 +1,8 @@ error[E0282]: type annotations needed - --> $DIR/issue-20261.rs:4:11 + --> $DIR/issue-20261.rs:4:9 | LL | i.clone(); - | ^^^^^ cannot infer type + | ^^^^^^^^^ cannot infer type error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-2151.stderr b/tests/ui/issues/issue-2151.stderr index 59fef42eb5e8b..b739f4a627c24 100644 --- a/tests/ui/issues/issue-2151.stderr +++ b/tests/ui/issues/issue-2151.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | let x = panic!(); | ^ LL | x.clone(); - | ----- type must be known at this point + | --------- type must be known at this point | help: consider giving `x` an explicit type | diff --git a/tests/ui/lazy-type-alias-impl-trait/branches3.stderr b/tests/ui/lazy-type-alias-impl-trait/branches3.stderr index 270fbfa81bb89..79a95553994a9 100644 --- a/tests/ui/lazy-type-alias-impl-trait/branches3.stderr +++ b/tests/ui/lazy-type-alias-impl-trait/branches3.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/branches3.rs:8:10 | LL | |s| s.len() - | ^ --- type must be known at this point + | ^ ------- type must be known at this point | help: consider giving this closure parameter an explicit type | @@ -13,7 +13,7 @@ error[E0282]: type annotations needed --> $DIR/branches3.rs:15:10 | LL | |s| s.len() - | ^ --- type must be known at this point + | ^ ------- type must be known at this point | help: consider giving this closure parameter an explicit type | @@ -24,7 +24,7 @@ error[E0282]: type annotations needed --> $DIR/branches3.rs:23:10 | LL | |s| s.len() - | ^ --- type must be known at this point + | ^ ------- type must be known at this point | help: consider giving this closure parameter an explicit type | @@ -35,7 +35,7 @@ error[E0282]: type annotations needed --> $DIR/branches3.rs:30:10 | LL | |s| s.len() - | ^ --- type must be known at this point + | ^ ------- type must be known at this point | help: consider giving this closure parameter an explicit type | diff --git a/tests/ui/span/issue-42234-unknown-receiver-type.full.stderr b/tests/ui/span/issue-42234-unknown-receiver-type.full.stderr index c2c6f2b99bc24..44ca78b624d90 100644 --- a/tests/ui/span/issue-42234-unknown-receiver-type.full.stderr +++ b/tests/ui/span/issue-42234-unknown-receiver-type.full.stderr @@ -1,25 +1,17 @@ -error[E0282]: type annotations needed - --> $DIR/issue-42234-unknown-receiver-type.rs:9:24 +error[E0599]: no method named `method_that_could_exist_on_some_type` found for type `_` in the current scope + --> $DIR/issue-42234-unknown-receiver-type.rs:10:16 | -LL | let x: Option<_> = None; - | ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option` LL | x.unwrap().method_that_could_exist_on_some_type(); - | ------------------------------------ type must be known at this point - | -help: consider specifying the generic argument - | -LL | let x: Option<_> = None::; - | +++++ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `_` error[E0282]: type annotations needed - --> $DIR/issue-42234-unknown-receiver-type.rs:15:10 + --> $DIR/issue-42234-unknown-receiver-type.rs:16:10 | LL | .sum::<_>() | ^^^ cannot infer type of the type parameter `S` declared on the method `sum` -LL | .to_string() - | --------- type must be known at this point | error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0282`. +Some errors have detailed explanations: E0282, E0599. +For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/span/issue-42234-unknown-receiver-type.generic_arg.stderr b/tests/ui/span/issue-42234-unknown-receiver-type.generic_arg.stderr index 74c46f6471237..8177b21904fa0 100644 --- a/tests/ui/span/issue-42234-unknown-receiver-type.generic_arg.stderr +++ b/tests/ui/span/issue-42234-unknown-receiver-type.generic_arg.stderr @@ -1,23 +1,14 @@ -error[E0282]: type annotations needed - --> $DIR/issue-42234-unknown-receiver-type.rs:9:24 +error[E0599]: no method named `method_that_could_exist_on_some_type` found for type `_` in the current scope + --> $DIR/issue-42234-unknown-receiver-type.rs:10:16 | -LL | let x: Option<_> = None; - | ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option` LL | x.unwrap().method_that_could_exist_on_some_type(); - | ------------------------------------ type must be known at this point - | -help: consider specifying the generic argument - | -LL | let x: Option<_> = None::; - | +++++ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `_` error[E0282]: type annotations needed - --> $DIR/issue-42234-unknown-receiver-type.rs:15:10 + --> $DIR/issue-42234-unknown-receiver-type.rs:16:10 | LL | .sum::<_>() | ^^^ cannot infer type of the type parameter `S` declared on the method `sum` -LL | .to_string() - | --------- type must be known at this point | help: consider specifying the generic argument | @@ -26,4 +17,5 @@ LL | .sum::() error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0282`. +Some errors have detailed explanations: E0282, E0599. +For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/span/issue-42234-unknown-receiver-type.rs b/tests/ui/span/issue-42234-unknown-receiver-type.rs index 53d1e3eed820e..3712305e8f16c 100644 --- a/tests/ui/span/issue-42234-unknown-receiver-type.rs +++ b/tests/ui/span/issue-42234-unknown-receiver-type.rs @@ -6,8 +6,9 @@ // the fix of which this tests). fn shines_a_beacon_through_the_darkness() { - let x: Option<_> = None; //~ ERROR type annotations needed + let x: Option<_> = None; x.unwrap().method_that_could_exist_on_some_type(); + //~^ ERROR no method named `method_that_could_exist_on_some_type` found for type `_` } fn courier_to_des_moines_and_points_west(data: &[u32]) -> String { diff --git a/tests/ui/type-alias-impl-trait/closures_in_branches.stderr b/tests/ui/type-alias-impl-trait/closures_in_branches.stderr index d6defe35866c5..1df9ad9354fe7 100644 --- a/tests/ui/type-alias-impl-trait/closures_in_branches.stderr +++ b/tests/ui/type-alias-impl-trait/closures_in_branches.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/closures_in_branches.rs:7:10 | LL | |x| x.len() - | ^ --- type must be known at this point + | ^ ------- type must be known at this point | help: consider giving this closure parameter an explicit type | @@ -13,7 +13,7 @@ error[E0282]: type annotations needed --> $DIR/closures_in_branches.rs:21:10 | LL | |x| x.len() - | ^ --- type must be known at this point + | ^ ------- type must be known at this point | help: consider giving this closure parameter an explicit type | diff --git a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr index 870938032e579..e6853c932c0ab 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr @@ -1,8 +1,8 @@ error[E0282]: type annotations needed - --> $DIR/method_resolution_trait_method_from_opaque.rs:26:18 + --> $DIR/method_resolution_trait_method_from_opaque.rs:26:9 | LL | self.bar.next().unwrap(); - | ^^^^ cannot infer type + | ^^^^^^^^^^^^^^^ cannot infer type error: aborting due to 1 previous error diff --git a/tests/ui/typeck/issue-13853.rs b/tests/ui/typeck/issue-13853.rs index ed44d5062614f..dc3bc556ddbfb 100644 --- a/tests/ui/typeck/issue-13853.rs +++ b/tests/ui/typeck/issue-13853.rs @@ -25,7 +25,7 @@ impl Node for Stuff { fn iterate>(graph: &G) { for node in graph.iter() { //~ ERROR no method named `iter` found - node.zomg(); //~ ERROR type annotations needed + node.zomg(); //~ ERROR no method named `zomg` found for type `_` } } diff --git a/tests/ui/typeck/issue-13853.stderr b/tests/ui/typeck/issue-13853.stderr index 9b8698d6ed2c0..a61308579e25a 100644 --- a/tests/ui/typeck/issue-13853.stderr +++ b/tests/ui/typeck/issue-13853.stderr @@ -17,11 +17,21 @@ error[E0599]: no method named `iter` found for reference `&G` in the current sco LL | for node in graph.iter() { | ^^^^ method not found in `&G` -error[E0282]: type annotations needed +error[E0599]: no method named `zomg` found for type `_` in the current scope --> $DIR/issue-13853.rs:28:14 | LL | node.zomg(); - | ^^^^ cannot infer type + | -----^^^^-- + | | | + | | this is an associated function, not a method + | help: use associated function syntax instead: `_::zomg()` + | + = note: found the following associated functions; to be used as methods, functions must have a `self` parameter +note: the candidate is defined in the trait `Node` + --> $DIR/issue-13853.rs:2:5 + | +LL | fn zomg(); + | ^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/issue-13853.rs:37:13 @@ -45,5 +55,5 @@ LL | iterate(&graph); error: aborting due to 4 previous errors -Some errors have detailed explanations: E0282, E0308, E0599. -For more information about an error, try `rustc --explain E0282`. +Some errors have detailed explanations: E0308, E0599. +For more information about an error, try `rustc --explain E0308`. From d6c0560fe79ca3a753d2ed9650241ba4b60458b9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 25 Jul 2024 10:32:18 +0000 Subject: [PATCH 4/4] Show that a test fails on the new solver, too --- ...paque_type_candidate_selection.next.stderr | 19 +++++++++++++++++++ ...paque_type_candidate_selection.old.stderr} | 2 +- .../opaque_type_candidate_selection.rs | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/ui/auto-traits/opaque_type_candidate_selection.next.stderr rename tests/ui/auto-traits/{opaque_type_candidate_selection.stderr => opaque_type_candidate_selection.old.stderr} (88%) diff --git a/tests/ui/auto-traits/opaque_type_candidate_selection.next.stderr b/tests/ui/auto-traits/opaque_type_candidate_selection.next.stderr new file mode 100644 index 0000000000000..5635b429ea36f --- /dev/null +++ b/tests/ui/auto-traits/opaque_type_candidate_selection.next.stderr @@ -0,0 +1,19 @@ +error[E0119]: conflicting implementations of trait `Trait<_>` + --> $DIR/opaque_type_candidate_selection.rs:28:1 + | +LL | impl Trait for T { + | ---------------------- first implementation here +... +LL | impl Trait for defining_scope::Alias { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation + +error[E0282]: type annotations needed + --> $DIR/opaque_type_candidate_selection.rs:11:23 + | +LL | pub fn cast(x: Container, T>) -> Container { + | ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0119, E0282. +For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/auto-traits/opaque_type_candidate_selection.stderr b/tests/ui/auto-traits/opaque_type_candidate_selection.old.stderr similarity index 88% rename from tests/ui/auto-traits/opaque_type_candidate_selection.stderr rename to tests/ui/auto-traits/opaque_type_candidate_selection.old.stderr index 3f1242a95af71..e5fd7aabaf6c6 100644 --- a/tests/ui/auto-traits/opaque_type_candidate_selection.stderr +++ b/tests/ui/auto-traits/opaque_type_candidate_selection.old.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Trait<_>` - --> $DIR/opaque_type_candidate_selection.rs:24:1 + --> $DIR/opaque_type_candidate_selection.rs:28:1 | LL | impl Trait for T { | ---------------------- first implementation here diff --git a/tests/ui/auto-traits/opaque_type_candidate_selection.rs b/tests/ui/auto-traits/opaque_type_candidate_selection.rs index 520ca9c3beec9..6bab1267b805e 100644 --- a/tests/ui/auto-traits/opaque_type_candidate_selection.rs +++ b/tests/ui/auto-traits/opaque_type_candidate_selection.rs @@ -1,3 +1,6 @@ +//@revisions: old next +//@[next] compile-flags: -Znext-solver + //! used to ICE: #119272 #![feature(type_alias_impl_trait)] @@ -6,6 +9,7 @@ mod defining_scope { pub type Alias = impl Sized; pub fn cast(x: Container, T>) -> Container { + //[next]~^ ERROR: type annotations needed x } }