Skip to content

Commit 7fd53c3

Browse files
committed
Do not fail method_autoderef_steps on infer types. Let method resolution handle it
1 parent e889ab3 commit 7fd53c3

31 files changed

+118
-213
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ fn method_autoderef_steps<'tcx>(
556556

557557
let final_ty = autoderef.final_ty(true);
558558
let opt_bad_ty = match final_ty.kind() {
559+
ty::Infer(ty::TyVar(_)) if !reached_raw_pointer => None,
559560
ty::Infer(ty::TyVar(_)) | ty::Error(_) => Some(MethodAutoderefBadTy {
560561
reached_raw_pointer,
561562
ty: infcx.make_query_response_ignoring_pending_obligations(inference_vars, final_ty),

tests/crashes/121613-2.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/crashes/121613.rs renamed to tests/ui/associated-types/param_mismatch_on_associatedtype_constructor.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
//@ known-bug: #121613
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+
27
fn main() {
38
let _ = <Foo as A>::Assoc { br: 2 };
49

510
let <E>::V(..) = E::V(|a, b| a.cmp(b));
11+
//~^ ERROR: multiple applicable items in scope
612
}
713

814
struct StructStruct {
Lines changed: 22 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: the size for values of type `dyn Fn(_, _) -> _` cannot be known
4040
}
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
error[E0282]: type annotations needed for `Value<Rc<_>>`
2-
--> $DIR/deref-ambiguity-becomes-nonambiguous.rs:31:9
1+
error[E0277]: the size for values of type `dyn Fn(_, _) -> _` cannot be known at compilation time
2+
--> $DIR/deref-ambiguity-becomes-nonambiguous.rs:38:13
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+
| ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
96
|
10-
help: consider giving `var_fn` an explicit type, where the placeholders `_` are specified
7+
= help: the trait `Sized` is not implemented for `dyn Fn(_, _) -> _`, which is required by `Value<Rc<_>>: Deref`
8+
note: required for `Value<Rc<dyn Fn(_, _) -> _>>` to implement `Deref`
9+
--> $DIR/deref-ambiguity-becomes-nonambiguous.rs:22:9
1110
|
12-
LL | let var_fn: Value<Rc<_>> = Value::wrap();
13-
| ++++++++++++++
11+
LL | impl<F> Deref for Value<Rc<F>> {
12+
| - ^^^^^ ^^^^^^^^^^^^
13+
| |
14+
| unsatisfied trait bound introduced here
1415

1516
error: aborting due to 1 previous error
1617

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

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `&_`
44
LL | let x = &my_foo();
55
| ^
66
LL | x.my_debug();
7-
| -------- type must be known at this point
7+
| ------------ type must be known at this point
88
|
99
help: consider giving `x` an explicit type, where the placeholders `_` are specified
1010
|

0 commit comments

Comments
 (0)