Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 96265ca

Browse files
committedJun 14, 2024
Do not fail method_autoderef_steps on infer types. Let method resolution handle it
1 parent 1490fae commit 96265ca

29 files changed

+115
-239
lines changed
 

‎compiler/rustc_hir_typeck/src/method/confirm.rs

+4-3
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

+1
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

-28
This file was deleted.

‎tests/crashes/121613.rs ‎tests/ui/associated-types/param_mismatch_on_associatedtype_constructor.rs

+7-1
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 {
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

+1-1
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
}
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

+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
|
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/recursive-bound-eval.current.stderr

-42
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:19: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-3
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;
@@ -15,10 +16,8 @@ impl<E, T: Fn() -> E> Parser<E> for T {
1516
}
1617

1718
pub fn recursive_fn<E>() -> impl Parser<E> {
18-
//[current]~^ ERROR: cycle detected
1919
move || recursive_fn().parse()
20-
//~^ ERROR: type annotations needed
21-
//[current]~^^ ERROR: no method named `parse` found for opaque type
20+
//[next]~^ ERROR: type annotations needed
2221
}
2322

2423
fn main() {}

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

-40
This file was deleted.

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +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.
1310

14-
#[coroutine] || { //[next]~ ERROR mismatched types
11+
#[coroutine] || {
1512
let mut gen = Box::pin(foo());
16-
//[next]~^ ERROR type annotations needed
1713
let mut r = gen.as_mut().resume(());
1814
while let CoroutineState::Yielded(v) = r {
1915
yield v;

‎tests/ui/issues/issue-20261.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/issue-20261.rs:4:11
2+
--> $DIR/issue-20261.rs:4:9
33
|
44
LL | i.clone();
5-
| ^^^^^ cannot infer type
5+
| ^^^^^^^^^ cannot infer type
66

77
error: aborting due to 1 previous error
88

‎tests/ui/issues/issue-2151.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | let x = panic!();
55
| ^
66
LL | x.clone();
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
1010
|
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.