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 Jul 25, 2024
1 parent e889ab3 commit 7fd53c3
Show file tree
Hide file tree
Showing 31 changed files with 118 additions and 213 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 @@ -556,6 +556,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
28 changes: 0 additions & 28 deletions tests/crashes/121613-2.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
//@ known-bug: #121613
//! 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 {
Expand Down
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 @@ -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: the size for values of type `dyn Fn(_, _) -> _` cannot be known
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
error[E0282]: type annotations needed for `Value<Rc<_>>`
--> $DIR/deref-ambiguity-becomes-nonambiguous.rs:31:9
error[E0277]: the size for values of type `dyn Fn(_, _) -> _` cannot be known at compilation time
--> $DIR/deref-ambiguity-becomes-nonambiguous.rs:38:13
|
LL | let var_fn = Value::wrap();
| ^^^^^^
...
LL | let _ = var_fn.clone();
| ----- type must be known at this point
| ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
help: consider giving `var_fn` an explicit type, where the placeholders `_` are specified
= help: the trait `Sized` is not implemented for `dyn Fn(_, _) -> _`, which is required by `Value<Rc<_>>: Deref`
note: required for `Value<Rc<dyn Fn(_, _) -> _>>` to implement `Deref`
--> $DIR/deref-ambiguity-becomes-nonambiguous.rs:22:9
|
LL | let var_fn: Value<Rc<_>> = Value::wrap();
| ++++++++++++++
LL | impl<F> Deref for Value<Rc<F>> {
| - ^^^^^ ^^^^^^^^^^^^
| |
| unsatisfied trait bound introduced here

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 E0277`.
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 @@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `&_`
LL | let x = &my_foo();
| ^
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[E0308]: mismatched types
--> $DIR/method-resolution4.rs:16:5
Expand Down
22 changes: 0 additions & 22 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
4 changes: 2 additions & 2 deletions 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,8 +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
//[current]~^^ ERROR: no method named `parse` found for opaque type
//[next]~^ ERROR: type annotations needed
}

fn main() {}
40 changes: 0 additions & 40 deletions tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr

This file was deleted.

8 changes: 2 additions & 6 deletions tests/ui/impl-trait/recursive-coroutine-boxed.rs
Original file line number Diff line number Diff line change
@@ -1,19 +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] || { //[next]~ ERROR mismatched types
#[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
Loading

0 comments on commit 7fd53c3

Please sign in to comment.