Skip to content

Commit 3b2d0ec

Browse files
committed
Do not fail method_autoderef_steps on infer types. Let method resolution handle it
1 parent e16a007 commit 3b2d0ec

File tree

35 files changed

+173
-183
lines changed

35 files changed

+173
-183
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+1
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ fn method_autoderef_steps<'tcx>(
540540

541541
let final_ty = autoderef.final_ty(true);
542542
let opt_bad_ty = match final_ty.kind() {
543+
ty::Infer(ty::TyVar(_)) if !reached_raw_pointer => None,
543544
ty::Infer(ty::TyVar(_)) | ty::Error(_) => Some(MethodAutoderefBadTy {
544545
reached_raw_pointer,
545546
ty: infcx.make_query_response_ignoring_pending_obligations(inference_vars, final_ty),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! This test used to ICE #121613
2+
//! Using a generic parameter where there are none expected
3+
//! caused an ICE, hiding the important later errors.
4+
5+
#![feature(more_qualified_paths)]
6+
7+
fn main() {
8+
let _ = <Foo as A>::Assoc { br: 2 };
9+
10+
let <E>::V(..) = E::V(|a, b| a.cmp(b));
11+
//~^ ERROR: multiple applicable items in scope
12+
}
13+
14+
struct StructStruct {
15+
br: i8,
16+
}
17+
18+
struct Foo;
19+
20+
trait A {
21+
type Assoc;
22+
}
23+
24+
impl A for Foo {
25+
type Assoc = StructStruct;
26+
}
27+
28+
enum E {
29+
V(u8),
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0034]: multiple applicable items in scope
2+
--> $DIR/param_mismatch_on_associatedtype_constructor.rs:10:36
3+
|
4+
LL | let <E>::V(..) = E::V(|a, b| a.cmp(b));
5+
| ^^^ multiple `cmp` found
6+
|
7+
note: candidate #1 is defined in the trait `Iterator`
8+
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
9+
note: candidate #2 is defined in the trait `Ord`
10+
--> $SRC_DIR/core/src/cmp.rs:LL:COL
11+
help: disambiguate the method for candidate #1
12+
|
13+
LL | let <E>::V(..) = E::V(|a, b| Iterator::cmp(a, b));
14+
| ~~~~~~~~~~~~~~~~~~~
15+
help: disambiguate the method for candidate #2
16+
|
17+
LL | let <E>::V(..) = E::V(|a, b| Ord::cmp(&a, b));
18+
| ~~~~~~~~~~~~~~~
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0034`.

tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<F, R, A1, A2> Wrap<F> for Value<Rc<dyn Fn(A1, A2) -> R>> {
1919
}
2020
}
2121

22-
impl<F> Deref for Value<Rc<F>> {
22+
impl<F: ?Sized> Deref for Value<Rc<F>> {
2323
type Target = F;
2424

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

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

3433
// The combination of `Value: Wrap` obligation plus the autoderef steps
3534
// (caused by the `Deref` impl above) actually means that the self type
3635
// of the method fn below is constrained to be `Value<Rc<dyn Fn(?0, ?1) -> ?2>>`.
3736
// However, that's only known to us on the error path -- we still need
3837
// to emit an ambiguity error, though.
3938
let _ = var_fn.clone();
39+
//~^ ERROR type annotations needed
4040
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
error[E0282]: type annotations needed for `Value<Rc<_>>`
2-
--> $DIR/deref-ambiguity-becomes-nonambiguous.rs:31:9
1+
error[E0283]: type annotations needed
2+
--> $DIR/deref-ambiguity-becomes-nonambiguous.rs:38:9
33
|
4-
LL | let var_fn = Value::wrap();
5-
| ^^^^^^
6-
...
74
LL | let _ = var_fn.clone();
8-
| ----- type must be known at this point
5+
| ^ ------ ----- required by a bound introduced by this call
6+
| |
7+
| type must be known at this point
98
|
10-
help: consider giving `var_fn` an explicit type, where the placeholders `_` are specified
9+
= note: cannot satisfy `_: Clone`
10+
help: consider giving this pattern a type
1111
|
12-
LL | let var_fn: Value<Rc<_>> = Value::wrap();
13-
| ++++++++++++++
12+
LL | let _: /* Type */ = var_fn.clone();
13+
| ++++++++++++
1414

1515
error: aborting due to 1 previous error
1616

17-
For more information about this error, try `rustc --explain E0282`.
17+
For more information about this error, try `rustc --explain E0283`.

tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | needs_foo(|x| {
55
| ^
66
...
77
LL | x.to_string();
8-
| --------- type must be known at this point
8+
| ------------- type must be known at this point
99
|
1010
help: consider giving this closure parameter an explicit type
1111
|

tests/ui/impl-trait/call_method_ambiguous.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let mut iter = foo(n - 1, m);
55
| ^^^^^^^^
66
LL |
77
LL | assert_eq!(iter.get(), 1);
8-
| --- type must be known at this point
8+
| ---------- type must be known at this point
99
|
1010
help: consider giving `iter` an explicit type
1111
|

tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let x = my_foo();
55
| ^
66
LL |
77
LL | x.my_debug();
8-
| -------- type must be known at this point
8+
| ------------ type must be known at this point
99
|
1010
help: consider giving `x` an explicit type
1111
|

tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let x = &my_foo();
55
| ^
66
LL |
77
LL | x.my_debug();
8-
| -------- type must be known at this point
8+
| ------------ type must be known at this point
99
|
1010
help: consider giving `x` an explicit type, where the placeholders `_` are specified
1111
|

tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let x = my_foo();
55
| ^
66
LL |
77
LL | x.my_debug();
8-
| -------- type must be known at this point
8+
| ------------ type must be known at this point
99
|
1010
help: consider giving `x` an explicit type
1111
|
@@ -19,7 +19,7 @@ LL | let x = &my_bar();
1919
| ^
2020
LL |
2121
LL | x.my_debug();
22-
| -------- type must be known at this point
22+
| ------------ type must be known at this point
2323
|
2424
help: consider giving `x` an explicit type, where the placeholders `_` are specified
2525
|
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
1-
error[E0282]: type annotations needed
2-
--> $DIR/hidden-type-is-opaque-2.rs:10:17
1+
error[E0599]: no method named `reify_as` found for type `_` in the current scope
2+
--> $DIR/hidden-type-is-opaque-2.rs:11:14
33
|
4-
LL | Thunk::new(|mut cont| {
5-
| ^^^^^^^^
6-
LL |
74
LL | cont.reify_as();
8-
| -------- type must be known at this point
9-
|
10-
help: consider giving this closure parameter an explicit type
11-
|
12-
LL | Thunk::new(|mut cont: /* Type */| {
13-
| ++++++++++++
5+
| ^^^^^^^^ method not found in `_`
146

15-
error[E0282]: type annotations needed
16-
--> $DIR/hidden-type-is-opaque-2.rs:20:17
7+
error[E0599]: no method named `reify_as` found for type `_` in the current scope
8+
--> $DIR/hidden-type-is-opaque-2.rs:21:14
179
|
18-
LL | Thunk::new(|mut cont| {
19-
| ^^^^^^^^
20-
LL |
2110
LL | cont.reify_as();
22-
| -------- type must be known at this point
23-
|
24-
help: consider giving this closure parameter an explicit type
25-
|
26-
LL | Thunk::new(|mut cont: /* Type */| {
27-
| ++++++++++++
11+
| ^^^^^^^^ method not found in `_`
2812

2913
error: aborting due to 2 previous errors
3014

31-
For more information about this error, try `rustc --explain E0282`.
15+
For more information about this error, try `rustc --explain E0599`.
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
1-
error[E0282]: type annotations needed
2-
--> $DIR/hidden-type-is-opaque-2.rs:10:17
1+
error[E0599]: no method named `reify_as` found for type `_` in the current scope
2+
--> $DIR/hidden-type-is-opaque-2.rs:11:14
33
|
4-
LL | Thunk::new(|mut cont| {
5-
| ^^^^^^^^
6-
LL |
74
LL | cont.reify_as();
8-
| -------- type must be known at this point
9-
|
10-
help: consider giving this closure parameter an explicit type
11-
|
12-
LL | Thunk::new(|mut cont: /* Type */| {
13-
| ++++++++++++
5+
| ^^^^^^^^ method not found in `_`
146

15-
error[E0282]: type annotations needed
16-
--> $DIR/hidden-type-is-opaque-2.rs:20:17
7+
error[E0599]: no method named `reify_as` found for type `_` in the current scope
8+
--> $DIR/hidden-type-is-opaque-2.rs:21:14
179
|
18-
LL | Thunk::new(|mut cont| {
19-
| ^^^^^^^^
20-
LL |
2110
LL | cont.reify_as();
22-
| -------- type must be known at this point
23-
|
24-
help: consider giving this closure parameter an explicit type
25-
|
26-
LL | Thunk::new(|mut cont: /* Type */| {
27-
| ++++++++++++
11+
| ^^^^^^^^ method not found in `_`
2812

2913
error: aborting due to 2 previous errors
3014

31-
For more information about this error, try `rustc --explain E0282`.
15+
For more information about this error, try `rustc --explain E0599`.

tests/ui/impl-trait/hidden-type-is-opaque-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
fn reify_as() -> Thunk<impl FnOnce(Continuation) -> Continuation> {
1010
Thunk::new(|mut cont| {
11-
//~^ ERROR type annotations needed
1211
cont.reify_as();
12+
//~^ ERROR: no method named `reify_as` found for type `_`
1313
cont
1414
})
1515
}
@@ -18,8 +18,8 @@ type Tait = impl FnOnce(Continuation) -> Continuation;
1818

1919
fn reify_as_tait() -> Thunk<Tait> {
2020
Thunk::new(|mut cont| {
21-
//~^ ERROR type annotations needed
2221
cont.reify_as();
22+
//~^ ERROR: no method named `reify_as` found for type `_`
2323
cont
2424
})
2525
}

tests/ui/impl-trait/method-resolution4.next.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/method-resolution4.rs:13:20
2+
--> $DIR/method-resolution4.rs:13:9
33
|
44
LL | foo(false).next().unwrap();
5-
| ^^^^ cannot infer type
5+
| ^^^^^^^^^^^^^^^^^ cannot infer type
66

77
error: aborting due to 1 previous error
88

tests/ui/impl-trait/recursive-bound-eval.current.stderr

-9
This file was deleted.

tests/ui/impl-trait/recursive-bound-eval.next.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/recursive-bound-eval.rs:18:28
2+
--> $DIR/recursive-bound-eval.rs:19:13
33
|
44
LL | move || recursive_fn().parse()
5-
| ^^^^^ cannot infer type
5+
| ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
66

77
error: aborting due to 1 previous error
88

tests/ui/impl-trait/recursive-bound-eval.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
//@revisions: next current
55
//@[next] compile-flags: -Znext-solver
6+
//@[current] check-pass
67

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

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

2223
fn main() {}

tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr

-17
This file was deleted.

tests/ui/impl-trait/recursive-coroutine-boxed.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
//@ revisions: current next
22
//@ ignore-compare-mode-next-solver (explicit revisions)
3-
//@[current] check-pass
3+
//@ check-pass
44
//@[next] compile-flags: -Znext-solver
55
#![feature(coroutines, coroutine_trait)]
66

77
use std::ops::{Coroutine, CoroutineState};
88

99
fn foo() -> impl Coroutine<Yield = (), Return = ()> {
10-
// FIXME(-Znext-solver): this fails with a mismatched types as the
11-
// hidden type of the opaque ends up as {type error}. We should not
12-
// emit errors for such goals.
13-
#[coroutine] || {
10+
#[coroutine]
11+
|| {
1412
let mut gen = Box::pin(foo());
15-
//[next]~^ ERROR type annotations needed
1613
let mut r = gen.as_mut().resume(());
1714
while let CoroutineState::Yielded(v) = r {
1815
yield v;
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#![crate_name = "time"]
22
#![crate_type = "lib"]
33

4+
//@check-pass
5+
46
// This code compiled without error in Rust 1.79, but started failing in 1.80
57
// after the addition of several `impl FromIterator<_> for Box<str>`.
68

79
pub fn parse() -> Option<Vec<()>> {
810
let iter = std::iter::once(Some(())).map(|o| o.map(Into::into));
9-
let items = iter.collect::<Option<Box<_>>>()?; //~ ERROR E0282
10-
//~^ 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`
11+
let items = iter.collect::<Option<Box<_>>>()?;
1112
Some(items.into())
12-
//~^ NOTE type must be known at this point
1313
}

tests/ui/inference/detect-old-time-version-format_description-parse.stderr

-14
This file was deleted.

tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ fn f() {}
1919
fn main() {
2020
<Foo as A>::Assoc {};
2121
f(|a, b| a.cmp(b));
22-
//~^ ERROR: type annotations needed
22+
//~^ ERROR: multiple applicable items in scope
2323
//~| ERROR: this function takes 0 arguments but 1 argument was supplied
2424
}

0 commit comments

Comments
 (0)