Skip to content

Commit

Permalink
Leave error reporting of method calls on inference variables to metho…
Browse files Browse the repository at this point in the history
…d call checks
  • Loading branch information
oli-obk committed Jun 13, 2024
1 parent 0f7668d commit ff98818
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 23 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> Ty<'tcx> {
let rcvr_t = self.check_expr(rcvr);
// no need to check for bot/err -- callee does that
let rcvr_t = self.structurally_resolve_type(rcvr.span, rcvr_t);
let rcvr_t = self.try_structurally_resolve_type(rcvr.span, rcvr_t);

let method = match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args)
{
Expand Down
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
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | Thunk::new(|mut cont| {
| ^^^^^^^^
LL |
LL | cont.reify_as();
| ---- 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 @@ -19,7 +19,7 @@ LL | Thunk::new(|mut cont| {
| ^^^^^^^^
LL |
LL | cont.reify_as();
| ---- 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
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | Thunk::new(|mut cont| {
| ^^^^^^^^
LL |
LL | cont.reify_as();
| ---- 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 @@ -19,7 +19,7 @@ LL | Thunk::new(|mut cont| {
| ^^^^^^^^
LL |
LL | cont.reify_as();
| ---- 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
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:13
--> $DIR/recursive-bound-eval.rs:19:28
|
LL | move || recursive_fn().parse()
| ^^^^^^^^^^^^^^ 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
1 change: 1 addition & 0 deletions tests/ui/issues/issue-7092.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn foo(x: Whatever) {
//~| expected enum `Whatever`
//~| found enum `Option<_>`
field.access(),
//~^ ERROR: type annotations needed
}
}

Expand Down
11 changes: 9 additions & 2 deletions tests/ui/issues/issue-7092.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ LL | Some(field) =>
= note: expected enum `Whatever`
found enum `Option<_>`

error: aborting due to 1 previous error
error[E0282]: type annotations needed
--> $DIR/issue-7092.rs:11:19
|
LL | field.access(),
| ^^^^^^ cannot infer type

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0282, E0308.
For more information about an error, try `rustc --explain E0282`.
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
4 changes: 3 additions & 1 deletion tests/ui/span/issue-42234-unknown-receiver-type.full.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: Option<_> = None;
| ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
LL | x.unwrap().method_that_could_exist_on_some_type();
| ---------- type must be known at this point
| ------------------------------------ type must be known at this point
|
help: consider specifying the generic argument
|
Expand All @@ -16,6 +16,8 @@ error[E0282]: type annotations needed
|
LL | .sum::<_>()
| ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
LL | .to_string()
| --------- type must be known at this point
|
help: consider specifying the generic argument
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0282]: type annotations needed
LL | let x: Option<_> = None;
| ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
LL | x.unwrap().method_that_could_exist_on_some_type();
| ---------- type must be known at this point
| ------------------------------------ type must be known at this point
|
help: consider specifying the generic argument
|
Expand All @@ -16,6 +16,8 @@ error[E0282]: type annotations needed
|
LL | .sum::<_>()
| ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
LL | .to_string()
| --------- type must be known at this point
|
help: consider specifying the generic argument
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/type-alias-impl-trait/closures_in_branches.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0282]: type annotations needed
--> $DIR/closures_in_branches.rs:7:10
|
LL | |x| x.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/closures_in_branches.rs:21:10
|
LL | |x| x.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
2 changes: 1 addition & 1 deletion tests/ui/typeck/issue-13853.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Node for Stuff {

fn iterate<N: Node, G: Graph<N>>(graph: &G) {
for node in graph.iter() { //~ ERROR no method named `iter` found
node.zomg();
node.zomg(); //~ ERROR type annotations needed
}
}

Expand Down
12 changes: 9 additions & 3 deletions tests/ui/typeck/issue-13853.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ error[E0599]: no method named `iter` found for reference `&G` in the current sco
LL | for node in graph.iter() {
| ^^^^ method not found in `&G`

error[E0282]: type annotations needed
--> $DIR/issue-13853.rs:28:14
|
LL | node.zomg();
| ^^^^ cannot infer type

error[E0308]: mismatched types
--> $DIR/issue-13853.rs:37:13
|
Expand All @@ -37,7 +43,7 @@ help: consider borrowing here
LL | iterate(&graph);
| +

error: aborting due to 3 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0308, E0599.
For more information about an error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0282, E0308, E0599.
For more information about an error, try `rustc --explain E0282`.

0 comments on commit ff98818

Please sign in to comment.