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 Jun 12, 2024
1 parent 9762532 commit d01f14d
Show file tree
Hide file tree
Showing 24 changed files with 84 additions and 200 deletions.
7 changes: 4 additions & 3 deletions compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,10 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
.report_mismatched_types(&cause, method_self_ty, self_ty, terr)
.emit();
} else {
error!("{self_ty} was a subtype of {method_self_ty} but now is not?");
// This must already have errored elsewhere.
self.dcx().has_errors().unwrap();
self.dcx().span_delayed_bug(
self.self_expr.span,
format!("{self_ty} was a subtype of {method_self_ty} but now is not?"),
);
}
}
}
Expand Down
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 @@ -528,6 +528,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
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
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
42 changes: 0 additions & 42 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:19: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
5 changes: 2 additions & 3 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 @@ -15,10 +16,8 @@ impl<E, T: Fn() -> E> Parser<E> for T {
}

pub fn recursive_fn<E>() -> impl Parser<E> {
//[current]~^ ERROR: cycle detected
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
4 changes: 2 additions & 2 deletions tests/ui/issues/issue-20261.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0282]: type annotations needed
--> $DIR/issue-20261.rs:4:11
--> $DIR/issue-20261.rs:4:9
|
LL | i.clone();
| ^^^^^ cannot infer type
| ^^^^^^^^^ cannot infer type

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-2151.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed
LL | let x = panic!();
| ^
LL | x.clone();
| ----- type must be known at this point
| --------- type must be known at this point
|
help: consider giving `x` an explicit type
|
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/lazy-type-alias-impl-trait/branches3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/branches3.rs:8:10
|
LL | |s| s.len()
| ^ --- type must be known at this point
| ^ ------- type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand All @@ -13,7 +13,7 @@ error[E0282]: type annotations needed
--> $DIR/branches3.rs:15:10
|
LL | |s| s.len()
| ^ --- type must be known at this point
| ^ ------- type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand All @@ -24,7 +24,7 @@ error[E0282]: type annotations needed
--> $DIR/branches3.rs:23:10
|
LL | |s| s.len()
| ^ --- type must be known at this point
| ^ ------- type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
Expand All @@ -35,7 +35,7 @@ error[E0282]: type annotations needed
--> $DIR/branches3.rs:30:10
|
LL | |s| s.len()
| ^ --- 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ error[E0425]: cannot find function `consume` in this scope
|
LL | consume(right);
| ^^^^^^^ not found in this scope
|
help: use the `.` operator to call the method `BufRead::consume` on `&mut _`
|
LL - consume(right);
LL + right.consume();
|

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ LL | fn get<R: Deref<Target = Self>>(self: R) -> u32 {
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)

ERROR rustc_hir_typeck::method::confirm Foo was a subtype of &Foo but now is not?
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0658`.
Loading

0 comments on commit d01f14d

Please sign in to comment.