Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not eagerly reject inference vars when trying to resolve method calls. #126316

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
@@ -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)
{
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
@@ -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),
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
@@ -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()))
})?;
Original file line number Diff line number Diff line change
@@ -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 _ = <Foo as A>::Assoc { br: 2 };

let <E>::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),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0034]: multiple applicable items in scope
--> $DIR/param_mismatch_on_associatedtype_constructor.rs:10:36
|
LL | let <E>::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 <E>::V(..) = E::V(|a, b| Iterator::cmp(a, b));
| ~~~~~~~~~~~~~~~~~~~
help: disambiguate the method for candidate #2
|
LL | let <E>::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`.
19 changes: 19 additions & 0 deletions tests/ui/auto-traits/opaque_type_candidate_selection.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0119]: conflicting implementations of trait `Trait<_>`
--> $DIR/opaque_type_candidate_selection.rs:28:1
|
LL | impl<T> Trait<T> for T {
| ---------------------- first implementation here
...
LL | impl<T> Trait<T> for defining_scope::Alias<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error[E0282]: type annotations needed
--> $DIR/opaque_type_candidate_selection.rs:11:23
|
LL | pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
| ^^^^^^^^^^^^^^^^^^^^^^ 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`.
12 changes: 12 additions & 0 deletions tests/ui/auto-traits/opaque_type_candidate_selection.old.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0119]: conflicting implementations of trait `Trait<_>`
--> $DIR/opaque_type_candidate_selection.rs:28:1
|
LL | impl<T> Trait<T> for T {
| ---------------------- first implementation here
...
LL | impl<T> Trait<T> for defining_scope::Alias<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
33 changes: 33 additions & 0 deletions tests/ui/auto-traits/opaque_type_candidate_selection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//@revisions: old next
//@[next] compile-flags: -Znext-solver

//! used to ICE: #119272

#![feature(type_alias_impl_trait)]
mod defining_scope {
use super::*;
pub type Alias<T> = impl Sized;

pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
//[next]~^ ERROR: type annotations needed
x
}
}

struct Container<T: Trait<U>, U> {
x: <T as Trait<U>>::Assoc,
}

trait Trait<T> {
type Assoc;
}

impl<T> Trait<T> for T {
type Assoc = Box<u32>;
}
impl<T> Trait<T> for defining_scope::Alias<T> {
//~^ ERROR: conflicting implementations
type Assoc = usize;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ impl<F, R, A1, A2> Wrap<F> for Value<Rc<dyn Fn(A1, A2) -> R>> {
}
}

impl<F> Deref for Value<Rc<F>> {
impl<F: ?Sized> Deref for Value<Rc<F>> {
type Target = F;

fn deref(&self) -> &Self::Target {
@@ -29,12 +29,12 @@ impl<F> Deref for Value<Rc<F>> {

fn main() {
let var_fn = Value::wrap();
//~^ ERROR type annotations needed for `Value<Rc<_>>`

// The combination of `Value: Wrap` obligation plus the autoderef steps
// (caused by the `Deref` impl above) actually means that the self type
// of the method fn below is constrained to be `Value<Rc<dyn Fn(?0, ?1) -> ?2>>`.
// 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
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0282]: type annotations needed for `Value<Rc<_>>`
--> $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<Rc<_>> = 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`.
Original file line number Diff line number Diff line change
@@ -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
|
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/call_method_ambiguous.next.stderr
Original file line number Diff line number Diff line change
@@ -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
|
Original file line number Diff line number Diff line change
@@ -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
|

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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();
| ^
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
|
Original file line number Diff line number Diff line change
@@ -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`
}
()
}
Original file line number Diff line number Diff line change
@@ -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
|
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/equality.rs
Original file line number Diff line number Diff line change
@@ -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 `<u32 as Add<impl Foo>>::Output == i32`
}
}

15 changes: 4 additions & 11 deletions tests/ui/impl-trait/equality.stderr
Original file line number Diff line number Diff line change
@@ -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 `<u32 as Add<impl Foo>>::Output == i32`
--> $DIR/equality.rs:24:11
|
LL | n + sum_to(n - 1)
| ^ no implementation for `u32 + impl Foo`
|
= help: the trait `Add<impl Foo>` is not implemented for `u32`
= help: the following other types implement trait `Add<Rhs>`:
`&u32` implements `Add<u32>`
`&u32` implements `Add`
`u32` implements `Add<&u32>`
`u32` implements `Add`
| ^ cannot satisfy `<u32 as Add<impl Foo>>::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`.
30 changes: 7 additions & 23 deletions tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr
Original file line number Diff line number Diff line change
@@ -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`.
30 changes: 7 additions & 23 deletions tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors like this are pretty useless and should be fixed before landing the PR

--> $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`.
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/hidden-type-is-opaque-2.rs
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@

fn reify_as() -> Thunk<impl FnOnce(Continuation) -> 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<Tait> {
Thunk::new(|mut cont| {
//~^ ERROR type annotations needed
cont.reify_as();
//~^ ERROR: no method named `reify_as` found for type `_`
cont
})
}
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/method-resolution4.next.stderr
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/method-resolution4.rs:13:9
|
LL | foo(false).next().unwrap();
| ^^^^^^^^^^ cannot infer type
| ^^^^^^^^^^^^^^^^^ cannot infer type

error: aborting due to 1 previous error

4 changes: 2 additions & 2 deletions tests/ui/impl-trait/nested_impl_trait.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ fn fine(x: impl Into<u32>) -> impl Into<u32> { x }

fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
//~^ ERROR nested `impl Trait` is not allowed
//~| ERROR the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
//~| ERROR the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied

fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
//~^ ERROR nested `impl Trait` is not allowed
@@ -18,7 +18,7 @@ struct X;
impl X {
fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
//~^ ERROR nested `impl Trait` is not allowed
//~| ERROR the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
//~| ERROR the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
}

fn allowed_in_assoc_type() -> impl Iterator<Item=impl Fn()> {
24 changes: 12 additions & 12 deletions tests/ui/impl-trait/nested_impl_trait.stderr
Original file line number Diff line number Diff line change
@@ -42,27 +42,27 @@ LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods

error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
--> $DIR/nested_impl_trait.rs:6:46
|
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| ^^^^^^^^^^^^^^^^^^^^^ - return type was inferred to be `impl Into<u32>` here
| |
| the trait `From<impl Into<u32>>` is not implemented for `impl Debug`
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into<u32>`
|
= help: the trait `Into<U>` is implemented for `T`
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`
help: consider further restricting this bound
|
LL | fn bad_in_ret_position(x: impl Into<u32> + std::fmt::Debug) -> impl Into<impl Debug> { x }
| +++++++++++++++++

error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
--> $DIR/nested_impl_trait.rs:19:34
|
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| ^^^^^^^^^^^^^^^^^^^^^ - return type was inferred to be `impl Into<u32>` here
| |
| the trait `From<impl Into<u32>>` is not implemented for `impl Debug`
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `impl Into<u32>`
|
help: consider further restricting this bound
|
= help: the trait `Into<U>` is implemented for `T`
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`
LL | fn bad(x: impl Into<u32> + std::fmt::Debug) -> impl Into<impl Debug> { x }
| +++++++++++++++++

error: aborting due to 7 previous errors

2 changes: 1 addition & 1 deletion tests/ui/impl-trait/recursive-bound-eval.next.stderr
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
--> $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

17 changes: 0 additions & 17 deletions tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr

This file was deleted.

9 changes: 3 additions & 6 deletions tests/ui/impl-trait/recursive-coroutine-boxed.rs
Original file line number Diff line number Diff line change
@@ -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<Yield = (), Return = ()> {
// 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;
Original file line number Diff line number Diff line change
@@ -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
}

Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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<str>`.

pub fn parse() -> Option<Vec<()>> {
let iter = std::iter::once(Some(())).map(|o| o.map(Into::into));
let items = iter.collect::<Option<Box<_>>>()?; //~ 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::<Option<Box<_>>>()?;
Some(items.into())
//~^ NOTE type must be known at this point
}
Comment on lines 9 to 13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fixes the time inference regression caused by #99969

I can see how that happens, but it's best effort, as with most inference errors or fixes we can't make long term guarantees...

This file was deleted.

Original file line number Diff line number Diff line change
@@ -19,6 +19,6 @@ fn f() {}
fn main() {
<Foo as A>::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
}
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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`.
4 changes: 2 additions & 2 deletions tests/ui/issues/issue-20261.stderr
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion tests/ui/issues/issue-2151.stderr
Original file line number Diff line number Diff line change
@@ -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
|
8 changes: 4 additions & 4 deletions tests/ui/lazy-type-alias-impl-trait/branches3.stderr
Original file line number Diff line number Diff line change
@@ -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
|
18 changes: 6 additions & 12 deletions tests/ui/span/issue-42234-unknown-receiver-type.full.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +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::<T>;
| +++++
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`
|

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`.
18 changes: 6 additions & 12 deletions tests/ui/span/issue-42234-unknown-receiver-type.generic_arg.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
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::<T>;
| +++++
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`
@@ -24,4 +17,5 @@ LL | .sum::<S>()

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`.
3 changes: 2 additions & 1 deletion tests/ui/span/issue-42234-unknown-receiver-type.rs
Original file line number Diff line number Diff line change
@@ -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 `_`
}
Comment on lines 8 to 12
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per the comment above, this diagnostic needs to be fixed again


fn courier_to_des_moines_and_points_west(data: &[u32]) -> String {
4 changes: 2 additions & 2 deletions tests/ui/type-alias-impl-trait/closures_in_branches.stderr
Original file line number Diff line number Diff line change
@@ -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
|

This file was deleted.

3 changes: 1 addition & 2 deletions tests/ui/type-alias-impl-trait/constrain_in_projection.rs
Original file line number Diff line number Diff line change
@@ -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 = <Foo as Trait<Bar>>::Assoc::default();
//[current]~^ `Foo: Trait<Bar>` is not satisfied
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
error[E0277]: the trait bound `Foo: Trait<Bar>` is not satisfied
error[E0283]: type annotations needed: cannot satisfy `Foo: Trait<Bar>`
--> $DIR/constrain_in_projection2.rs:27:14
|
LL | let x = <Foo as Trait<Bar>>::Assoc::default();
| ^^^ the trait `Trait<Bar>` is not implemented for `Foo`
| ^^^ help: use the fully qualified path to an implementation: `<Type as Trait>::Assoc`
|
= help: the following other types implement trait `Trait<T>`:
`Foo` implements `Trait<()>`
`Foo` implements `Trait<u32>`
note: multiple `impl`s satisfying `Foo: Trait<Bar>` found
--> $DIR/constrain_in_projection2.rs:18:1
|
LL | impl Trait<()> for Foo {
| ^^^^^^^^^^^^^^^^^^^^^^
...
LL | impl Trait<u32> 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`.
3 changes: 1 addition & 2 deletions tests/ui/type-alias-impl-trait/constrain_in_projection2.rs
Original file line number Diff line number Diff line change
@@ -25,8 +25,7 @@ impl Trait<u32> for Foo {

fn bop(_: Bar) {
let x = <Foo as Trait<Bar>>::Assoc::default();
//[next]~^ ERROR: cannot satisfy `Foo: Trait<Bar>`
//[current]~^^ ERROR: `Foo: Trait<Bar>` is not satisfied
//~^ ERROR: cannot satisfy `Foo: Trait<Bar>`
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
error[E0119]: conflicting implementations of trait `Trait<Bar, _>`
--> $DIR/issue-84660-unsoundness.rs:29:1
--> $DIR/issue-84660-unsoundness.rs:28:1
|
LL | impl<In, Out> Trait<Bar, In> for Out {
| ------------------------------------ first implementation here
...
LL | impl<In, Out> 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`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0119]: conflicting implementations of trait `Trait<Bar, _>`
--> $DIR/issue-84660-unsoundness.rs:29:1
--> $DIR/issue-84660-unsoundness.rs:28:1
|
LL | impl<In, Out> Trait<Bar, In> 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 == _`
1 change: 0 additions & 1 deletion tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ impl<In, Out> Trait<Bar, In> 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!();
}
}
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
--> $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

This file was deleted.

4 changes: 1 addition & 3 deletions tests/ui/type-alias-impl-trait/nested-tait-inference.rs
Original file line number Diff line number Diff line change
@@ -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<A> {}
impl Foo<()> for () {}

fn foo() -> impl Foo<FooX> {
//[current]~^ ERROR: the trait bound `(): Foo<FooX>` is not satisfied
// FIXME(type-alias-impl-trait): We could probably make this work.
()
}

Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
error[E0277]: the trait bound `(): Foo<FooX>` is not satisfied
error[E0283]: type annotations needed: cannot satisfy `(): Foo<FooX>`
--> $DIR/nested-tait-inference2.rs:17:13
|
LL | fn foo() -> impl Foo<FooX> {
| ^^^^^^^^^^^^^^ the trait `Foo<FooX>` is not implemented for `()`
| ^^^^^^^^^^^^^^
LL |
LL | ()
| -- return type was inferred to be `()` here
|
= help: the following other types implement trait `Foo<A>`:
`()` implements `Foo<()>`
`()` implements `Foo<u32>`
note: multiple `impl`s satisfying `(): Foo<FooX>` found
--> $DIR/nested-tait-inference2.rs:14:1
|
LL | impl Foo<()> for () {}
| ^^^^^^^^^^^^^^^^^^^
LL | impl Foo<u32> 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`.
2 changes: 1 addition & 1 deletion tests/ui/type-alias-impl-trait/nested-tait-inference2.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ impl Foo<()> for () {}
impl Foo<u32> for () {}

fn foo() -> impl Foo<FooX> {
//[current]~^ ERROR: the trait bound `(): Foo<FooX>` is not satisfied
//[current]~^ ERROR: cannot satisfy `(): Foo<FooX>`
()
//[next]~^ ERROR: cannot satisfy `impl Foo<FooX> == ()`
}
Original file line number Diff line number Diff line change
@@ -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::<u8>(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 `<u8 as Trait>::Gat<'_>` to `()` or calling a method that returns `<u8 as Trait>::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(<u8 as Trait>::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`.
14 changes: 0 additions & 14 deletions tests/ui/type-alias-impl-trait/self-referential-2.current.stderr

This file was deleted.

4 changes: 2 additions & 2 deletions tests/ui/type-alias-impl-trait/self-referential-2.rs
Original file line number Diff line number Diff line change
@@ -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<Foo>;

fn bar() -> Bar {
42_i32 //[current]~^ ERROR can't compare `i32` with `Foo`
42_i32
}

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/type-alias-impl-trait/self-referential-3.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
type Bar<'a, 'b> = impl PartialEq<Bar<'a, 'b>> + 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
}

12 changes: 4 additions & 8 deletions tests/ui/type-alias-impl-trait/self-referential-3.stderr
Original file line number Diff line number Diff line change
@@ -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<Bar<'a, 'b>>` 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`.
2 changes: 1 addition & 1 deletion tests/ui/typeck/issue-13853.rs
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ impl Node for Stuff {

fn iterate<N: Node, G: Graph<N>>(graph: &G) {
for node in graph.iter() { //~ ERROR no method named `iter` found
node.zomg();
node.zomg(); //~ ERROR no method named `zomg` found for type `_`
}
}

18 changes: 17 additions & 1 deletion tests/ui/typeck/issue-13853.stderr
Original file line number Diff line number Diff line change
@@ -17,6 +17,22 @@ 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[E0599]: no method named `zomg` found for type `_` in the current scope
--> $DIR/issue-13853.rs:28:14
|
LL | node.zomg();
| -----^^^^--
| | |
| | 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
|
@@ -37,7 +53,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`.