Skip to content

Commit 1c38218

Browse files
committed
Do not fail method_autoderef_steps on infer types. Let method resolution handle it
1 parent a401aa7 commit 1c38218

29 files changed

+115
-239
lines changed

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,10 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
510510
.report_mismatched_types(&cause, method_self_ty, self_ty, terr)
511511
.emit();
512512
} else {
513-
error!("{self_ty} was a subtype of {method_self_ty} but now is not?");
514-
// This must already have errored elsewhere.
515-
self.dcx().has_errors().unwrap();
513+
self.dcx().span_delayed_bug(
514+
self.self_expr.span,
515+
format!("{self_ty} was a subtype of {method_self_ty} but now is not?"),
516+
);
516517
}
517518
}
518519
}

compiler/rustc_hir_typeck/src/method/probe.rs

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

529529
let final_ty = autoderef.final_ty(true);
530530
let opt_bad_ty = match final_ty.kind() {
531+
ty::Infer(ty::TyVar(_)) if !reached_raw_pointer => None,
531532
ty::Infer(ty::TyVar(_)) | ty::Error(_) => Some(MethodAutoderefBadTy {
532533
reached_raw_pointer,
533534
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
|
Lines changed: 7 additions & 23 deletions
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`.
Lines changed: 7 additions & 23 deletions
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`.

0 commit comments

Comments
 (0)