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 Jul 25, 2024
1 parent e0faa7b commit e889ab3
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 28 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 @@ -1339,7 +1339,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
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/call_method_ambiguous.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let mut iter = foo(n - 1, m);
| ^^^^^^^^
LL |
LL | assert_eq!(iter.get(), 1);
| ---- type must be known at this point
| --- type must be known at this point
|
help: consider giving `iter` an explicit type
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let x = my_foo();
| ^
LL |
LL | x.my_debug();
| - type must be known at this point
| -------- type must be known at this point
|
help: consider giving `x` an explicit type
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let x = my_foo();
| ^
LL |
LL | x.my_debug();
| - type must be known at this point
| -------- type must be known at this point
|
help: consider giving `x` 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/method-resolution4.next.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0282]: type annotations needed
--> $DIR/method-resolution4.rs:13:9
--> $DIR/method-resolution4.rs:13:20
|
LL | foo(false).next().unwrap();
| ^^^^^^^^^^ cannot infer type
| ^^^^ cannot infer type

error[E0308]: mismatched types
--> $DIR/method-resolution4.rs:16:5
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:18:13
--> $DIR/recursive-bound-eval.rs:18: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
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0282]: type annotations needed
--> $DIR/method_resolution_trait_method_from_opaque.rs:26:9
--> $DIR/method_resolution_trait_method_from_opaque.rs:26:18
|
LL | self.bar.next().unwrap();
| ^^^^^^^^ cannot infer type
| ^^^^ cannot infer type

error: aborting due to 1 previous error

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 e889ab3

Please sign in to comment.