Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 42c4373

Browse files
Make note_source_of_type_mismatch_constraint simpler
1 parent 4087dea commit 42c4373

13 files changed

+94
-241
lines changed

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 81 additions & 195 deletions
Large diffs are not rendered by default.

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -807,24 +807,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
807807
full_call_span,
808808
format!("arguments to this {} are incorrect", call_name),
809809
);
810-
if let (Some(callee_ty), hir::ExprKind::MethodCall(_, rcvr, _, _)) =
811-
(callee_ty, &call_expr.kind)
812-
{
813-
// Type that would have accepted this argument if it hadn't been inferred earlier.
814-
// FIXME: We leave an inference variable for now, but it'd be nice to get a more
815-
// specific type to increase the accuracy of the diagnostic.
816-
let expected = self.infcx.next_ty_var(TypeVariableOrigin {
817-
kind: TypeVariableOriginKind::MiscVariable,
818-
span: full_call_span,
819-
});
820-
self.point_at_expr_source_of_inferred_type(
821-
&mut err,
822-
rcvr,
823-
expected,
824-
callee_ty,
825-
provided_arg_span,
826-
);
827-
}
810+
811+
// TODO: We would like to point out when the rcvr was constrained
812+
// such that the arg mismatch occurs.
813+
828814
// Call out where the function is defined
829815
self.label_fn_like(
830816
&mut err,

tests/ui/type/type-check/assignment-in-if.stderr

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ LL | x == 5
6767
error[E0308]: mismatched types
6868
--> $DIR/assignment-in-if.rs:44:18
6969
|
70-
LL | if y = (Foo { foo: x }) {
71-
| - here the type of `x` is inferred to be `usize`
72-
...
7370
LL | if x == x && x = x && x == x {
7471
| ------ ^ expected `bool`, found `usize`
7572
| |
@@ -78,9 +75,6 @@ LL | if x == x && x = x && x == x {
7875
error[E0308]: mismatched types
7976
--> $DIR/assignment-in-if.rs:44:22
8077
|
81-
LL | if y = (Foo { foo: x }) {
82-
| - here the type of `x` is inferred to be `usize`
83-
...
8478
LL | if x == x && x = x && x == x {
8579
| ^ expected `bool`, found `usize`
8680

@@ -98,9 +92,6 @@ LL | if x == x && x == x && x == x {
9892
error[E0308]: mismatched types
9993
--> $DIR/assignment-in-if.rs:51:28
10094
|
101-
LL | if y = (Foo { foo: x }) {
102-
| - here the type of `x` is inferred to be `usize`
103-
...
10495
LL | if x == x && x == x && x = x {
10596
| ---------------- ^ expected `bool`, found `usize`
10697
| |

tests/ui/type/type-check/point-at-inference-3.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
fn main() {
33
let mut v = Vec::new();
44
v.push(0i32);
5-
//~^ NOTE this is of type `i32`, which causes `v` to be inferred as `Vec<i32>`
65
v.push(0);
76
v.push(1i32); //~ ERROR mismatched types
87
//~^ NOTE expected `i32`, found `u32`

tests/ui/type/type-check/point-at-inference-3.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
fn main() {
33
let mut v = Vec::new();
44
v.push(0i32);
5-
//~^ NOTE this is of type `i32`, which causes `v` to be inferred as `Vec<i32>`
65
v.push(0);
76
v.push(1u32); //~ ERROR mismatched types
87
//~^ NOTE expected `i32`, found `u32`

tests/ui/type/type-check/point-at-inference-3.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error[E0308]: mismatched types
2-
--> $DIR/point-at-inference-3.rs:7:12
2+
--> $DIR/point-at-inference-3.rs:6:12
33
|
4-
LL | v.push(0i32);
5-
| ---- this is of type `i32`, which causes `v` to be inferred as `Vec<i32>`
6-
...
74
LL | v.push(1u32);
85
| ---- ^^^^ expected `i32`, found `u32`
96
| |

tests/ui/type/type-check/point-at-inference-4.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fn main() {
1111
let s = S(None);
1212
s.infer(0i32);
1313
//~^ ERROR this method takes 2 arguments but 1 argument was supplied
14+
//~| NOTE here the type of `s` is inferred to be `S<i32, _>`
1415
//~| NOTE an argument is missing
1516
//~| HELP provide the argument
1617
let t: S<u32, _> = s;

tests/ui/type/type-check/point-at-inference-4.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ LL | s.infer(0i32, /* b */);
1515
| ~~~~~~~~~~~~~~~
1616

1717
error[E0308]: mismatched types
18-
--> $DIR/point-at-inference-4.rs:16:24
18+
--> $DIR/point-at-inference-4.rs:17:24
1919
|
20+
LL | s.infer(0i32);
21+
| - here the type of `s` is inferred to be `S<i32, _>`
22+
...
2023
LL | let t: S<u32, _> = s;
2124
| --------- ^ expected `S<u32, _>`, found `S<i32, _>`
2225
| |

tests/ui/type/type-check/point-at-inference.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66
let mut foo = vec![];
77
baz(&foo);
88
for i in &v {
9-
foo.push(*i);
9+
foo.push(i);
1010
}
1111
baz(&foo);
1212
bar(foo); //~ ERROR E0308

tests/ui/type/type-check/point-at-inference.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/point-at-inference.rs:12:9
33
|
44
LL | foo.push(i);
5-
| - this is of type `&{integer}`, which causes `foo` to be inferred as `Vec<&{integer}>`
5+
| --- here the type of `foo` is inferred to be `Vec<&{integer}>`
66
...
77
LL | bar(foo);
88
| --- ^^^ expected `Vec<i32>`, found `Vec<&{integer}>`
@@ -16,10 +16,6 @@ note: function defined here
1616
|
1717
LL | fn bar(_: Vec<i32>) {}
1818
| ^^^ -----------
19-
help: consider dereferencing the borrow
20-
|
21-
LL | foo.push(*i);
22-
| +
2319

2420
error: aborting due to previous error
2521

tests/ui/typeck/bad-type-in-vec-contains.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | primes.contains(3);
77
| | expected `&_`, found integer
88
| | help: consider borrowing here: `&3`
99
| arguments to this method are incorrect
10-
| here the type of `primes` is inferred to be `[_]`
1110
|
1211
= note: expected reference `&_`
1312
found type `{integer}`

tests/ui/typeck/bad-type-in-vec-push.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/bad-type-in-vec-push.rs:11:17
33
|
4-
LL | vector.sort();
5-
| ------ here the type of `vector` is inferred to be `Vec<_>`
64
LL | result.push(vector);
75
| ---- ^^^^^^ expected integer, found `Vec<_>`
86
| |

tests/ui/typeck/issue-107775.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-107775.rs:35:16
33
|
44
LL | map.insert(1, Struct::do_something);
5-
| - -------------------- this is of type `fn(u8) -> Pin<Box<dyn Future<Output = ()> + Send>> {<Struct as Trait>::do_something::<'_>}`, which causes `map` to be inferred as `HashMap<{integer}, fn(u8) -> Pin<Box<dyn Future<Output = ()> + Send>> {<Struct as Trait>::do_something::<'_>}>`
6-
| |
7-
| this is of type `{integer}`, which causes `map` to be inferred as `HashMap<{integer}, fn(u8) -> Pin<Box<dyn Future<Output = ()> + Send>> {<Struct as Trait>::do_something::<'_>}>`
5+
| --- here the type of `map` is inferred to be `HashMap<{integer}, fn(u8) -> Pin<Box<dyn Future<Output = ()> + Send>> {<Struct as Trait>::do_something::<'_>}>`
86
LL | Self { map }
97
| ^^^ expected `HashMap<u16, fn(u8) -> Pin<...>>`, found `HashMap<{integer}, ...>`
108
|

0 commit comments

Comments
 (0)