Skip to content

Commit

Permalink
Do not fail method_autoderef_steps on infer types. Let method resol…
Browse files Browse the repository at this point in the history
…ution handle it
  • Loading branch information
oli-obk committed Dec 3, 2024
1 parent e16a007 commit 3b2d0ec
Show file tree
Hide file tree
Showing 35 changed files with 173 additions and 183 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Up @@ -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
|
Expand Down
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
Expand Up @@ -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
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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
|
Expand Down
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
--> $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
Expand Up @@ -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
})
}
Expand All @@ -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
})
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/method-resolution4.next.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 0 additions & 9 deletions tests/ui/impl-trait/recursive-bound-eval.current.stderr

This file was deleted.

4 changes: 2 additions & 2 deletions tests/ui/impl-trait/recursive-bound-eval.next.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0282]: type annotations needed
--> $DIR/recursive-bound-eval.rs:18:28
--> $DIR/recursive-bound-eval.rs:19:13
|
LL | move || recursive_fn().parse()
| ^^^^^ cannot infer type
| ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type

error: aborting due to 1 previous error

Expand Down
3 changes: 2 additions & 1 deletion tests/ui/impl-trait/recursive-bound-eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//@revisions: next current
//@[next] compile-flags: -Znext-solver
//@[current] check-pass

pub trait Parser<E> {
fn parse(&self) -> E;
Expand All @@ -16,7 +17,7 @@ impl<E, T: Fn() -> E> Parser<E> for T {

pub fn recursive_fn<E>() -> impl Parser<E> {
move || recursive_fn().parse()
//~^ ERROR: type annotations needed
//[next]~^ ERROR: type annotations needed
}

fn main() {}
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;
Expand Down
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
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading

0 comments on commit 3b2d0ec

Please sign in to comment.