Skip to content

Commit c5d21c2

Browse files
committed
review comments: do not always point at init expr
1 parent acff39f commit c5d21c2

20 files changed

+14
-98
lines changed

compiler/rustc_hir_typeck/src/demand.rs

+3
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
355355
}
356356
}
357357
}
358+
if span_labels.len() < 2 {
359+
return false;
360+
}
358361
for (sp, label) in span_labels {
359362
err.span_label(sp, &label);
360363
}

src/test/ui/argument-suggestions/two-mismatch-notes.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: arguments to this function are incorrect
22
--> $DIR/two-mismatch-notes.rs:10:5
33
|
4-
LL | let w = Wrapper::<isize>(1isize);
5-
| ------------------------ here the type of `w` is inferred to be `Wrapper<isize>`
64
LL | foo(f, w);
75
| ^^^
86
|

src/test/ui/async-await/dont-suggest-missing-await.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/dont-suggest-missing-await.rs:14:18
33
|
4-
LL | let x = make_u32();
5-
| ---------- here the type of `x` is inferred to be `impl Future<Output = u32>`
64
LL | take_u32(x)
75
| -------- ^ expected `u32`, found opaque type
86
| |

src/test/ui/async-await/suggest-missing-await-closure.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/suggest-missing-await-closure.rs:16:18
33
|
4-
LL | let x = make_u32();
5-
| ---------- here the type of `x` is inferred to be `impl Future<Output = u32>`
64
LL | take_u32(x)
75
| -------- ^ expected `u32`, found opaque type
86
| |

src/test/ui/async-await/suggest-missing-await.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/suggest-missing-await.rs:12:14
33
|
4-
LL | let x = make_u32();
5-
| ---------- here the type of `x` is inferred to be `impl Future<Output = u32>`
64
LL | take_u32(x)
75
| -------- ^ expected `u32`, found opaque type
86
| |

src/test/ui/closures/closure-return-type-mismatch.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/closure-return-type-mismatch.rs:7:9
33
|
4-
LL | let a = true;
5-
| ---- here the type of `a` is inferred to be `bool`
64
LL | a
75
| ^ expected `&str`, found `bool`
86
|

src/test/ui/coercion/coerce-to-bang.stderr

-9
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ LL | fn foo(x: usize, y: !, z: usize) { }
3333
error[E0308]: mismatched types
3434
--> $DIR/coerce-to-bang.rs:26:12
3535
|
36-
LL | let b = 22;
37-
| -- here the type of `b` is inferred to be `{integer}`
38-
LL | let c = 44;
3936
LL | foo(a, b, c); // ... and hence a reference to `a` is expected to diverge.
4037
| --- ^ expected `!`, found integer
4138
| |
@@ -52,9 +49,6 @@ LL | fn foo(x: usize, y: !, z: usize) { }
5249
error[E0308]: mismatched types
5350
--> $DIR/coerce-to-bang.rs:36:12
5451
|
55-
LL | let b = 22;
56-
| -- here the type of `b` is inferred to be `{integer}`
57-
LL | let c = 44;
5852
LL | foo(a, b, c);
5953
| --- ^ expected `!`, found integer
6054
| |
@@ -71,9 +65,6 @@ LL | fn foo(x: usize, y: !, z: usize) { }
7165
error[E0308]: mismatched types
7266
--> $DIR/coerce-to-bang.rs:45:12
7367
|
74-
LL | let b = 22;
75-
| -- here the type of `b` is inferred to be `{integer}`
76-
LL | let c = 44;
7768
LL | foo(a, b, c);
7869
| --- ^ expected `!`, found integer
7970
| |

src/test/ui/generic-associated-types/collections-project-default.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ error[E0308]: mismatched types
44
LL | fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
55
| ------------------------------------ expected `<C as Collection<i32>>::Sibling<f32>` because of return type
66
...
7-
LL | let mut res = <C::Family as CollectionFamily>::Member::<f32>::empty();
8-
| ------------------------------------------------------- here the type of `res` is inferred to be `<<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>`
9-
...
107
LL | res
118
| ^^^ expected Collection::Sibling, found CollectionFamily::Member
129
|

src/test/ui/issues/issue-15783.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/issue-15783.rs:8:19
33
|
4-
LL | let x = Some(&[name]);
5-
| ------------- here the type of `x` is inferred to be `Option<&[&str; 1]>`
64
LL | let msg = foo(x);
75
| --- ^ expected slice `[&str]`, found array `[&str; 1]`
86
| |

src/test/ui/let-else/let-else-ref-bindings.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ LL | let Some(ref a): Option<&[u8]> = &some else { return };
1919
error[E0308]: mismatched types
2020
--> $DIR/let-else-ref-bindings.rs:24:34
2121
|
22-
LL | let some = Some(bytes);
23-
| ----------- here the type of `some` is inferred to be `Option<Vec<u8>>`
24-
...
2522
LL | let Some(a): Option<&[u8]> = some else { return };
2623
| ------------- ^^^^ expected `&[u8]`, found struct `Vec`
2724
| |
@@ -62,9 +59,6 @@ LL | let Some(ref mut a): Option<&mut [u8]> = &mut some else { return };
6259
error[E0308]: mismatched types
6360
--> $DIR/let-else-ref-bindings.rs:52:38
6461
|
65-
LL | let mut some = Some(bytes);
66-
| ----------- here the type of `some` is inferred to be `Option<Vec<u8>>`
67-
...
6862
LL | let Some(a): Option<&mut [u8]> = some else { return };
6963
| ----------------- ^^^^ expected `&mut [u8]`, found struct `Vec`
7064
| |

src/test/ui/methods/method-deref-to-same-trait-object-with-separate-params.stderr

-15
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ LL | #![feature(unsized_locals, unsized_fn_params)]
1010
error[E0308]: mismatched types
1111
--> $DIR/method-deref-to-same-trait-object-with-separate-params.rs:87:24
1212
|
13-
LL | let z = x.foo();
14-
| ------- here the type of `z` is inferred to be `u32`
15-
...
1613
LL | let _seetype: () = z;
1714
| -- ^ expected `()`, found `u32`
1815
| |
@@ -21,9 +18,6 @@ LL | let _seetype: () = z;
2118
error[E0308]: mismatched types
2219
--> $DIR/method-deref-to-same-trait-object-with-separate-params.rs:104:24
2320
|
24-
LL | let z = x.foo();
25-
| ------- here the type of `z` is inferred to be `u64`
26-
...
2721
LL | let _seetype: () = z;
2822
| -- ^ expected `()`, found `u64`
2923
| |
@@ -66,9 +60,6 @@ LL | let z = FinalFoo::foo(x);
6660
error[E0308]: mismatched types
6761
--> $DIR/method-deref-to-same-trait-object-with-separate-params.rs:139:24
6862
|
69-
LL | let z = x.foo();
70-
| ------- here the type of `z` is inferred to be `u8`
71-
...
7263
LL | let _seetype: () = z;
7364
| -- ^ expected `()`, found `u8`
7465
| |
@@ -77,9 +68,6 @@ LL | let _seetype: () = z;
7768
error[E0308]: mismatched types
7869
--> $DIR/method-deref-to-same-trait-object-with-separate-params.rs:157:24
7970
|
80-
LL | let z = x.foo();
81-
| ------- here the type of `z` is inferred to be `u32`
82-
...
8371
LL | let _seetype: () = z;
8472
| -- ^ expected `()`, found `u32`
8573
| |
@@ -88,9 +76,6 @@ LL | let _seetype: () = z;
8876
error[E0308]: mismatched types
8977
--> $DIR/method-deref-to-same-trait-object-with-separate-params.rs:174:24
9078
|
91-
LL | let z = x.foo();
92-
| ------- here the type of `z` is inferred to be `u32`
93-
...
9479
LL | let _seetype: () = z;
9580
| -- ^ expected `()`, found `u32`
9681
| |

src/test/ui/mismatched_types/abridged.stderr

+10-26
Original file line numberDiff line numberDiff line change
@@ -53,39 +53,23 @@ LL | Ok(Foo { bar: 1 })
5353
error[E0308]: mismatched types
5454
--> $DIR/abridged.rs:39:5
5555
|
56-
LL | fn d() -> X<X<String, String>, String> {
57-
| ---------------------------- expected `X<X<String, String>, String>` because of return type
58-
LL | let x = X {
59-
| _____________-
60-
LL | | x: X {
61-
LL | | x: "".to_string(),
62-
LL | | y: 2,
63-
LL | | },
64-
LL | | y: 3,
65-
LL | | };
66-
| |_____- here the type of `x` is inferred to be `X<X<String, {integer}>, {integer}>`
67-
LL | x
68-
| ^ expected struct `String`, found integer
56+
LL | fn d() -> X<X<String, String>, String> {
57+
| ---------------------------- expected `X<X<String, String>, String>` because of return type
58+
...
59+
LL | x
60+
| ^ expected struct `String`, found integer
6961
|
7062
= note: expected struct `X<X<_, String>, String>`
7163
found struct `X<X<_, {integer}>, {integer}>`
7264

7365
error[E0308]: mismatched types
7466
--> $DIR/abridged.rs:50:5
7567
|
76-
LL | fn e() -> X<X<String, String>, String> {
77-
| ---------------------------- expected `X<X<String, String>, String>` because of return type
78-
LL | let x = X {
79-
| _____________-
80-
LL | | x: X {
81-
LL | | x: "".to_string(),
82-
LL | | y: 2,
83-
LL | | },
84-
LL | | y: "".to_string(),
85-
LL | | };
86-
| |_____- here the type of `x` is inferred to be `X<X<String, {integer}>, String>`
87-
LL | x
88-
| ^ expected struct `String`, found integer
68+
LL | fn e() -> X<X<String, String>, String> {
69+
| ---------------------------- expected `X<X<String, String>, String>` because of return type
70+
...
71+
LL | x
72+
| ^ expected struct `String`, found integer
8973
|
9074
= note: expected struct `X<X<_, String>, _>`
9175
found struct `X<X<_, {integer}>, _>`

src/test/ui/parser/struct-literal-variant-in-if.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ LL | if x == E::V { field } {}
5151
error[E0308]: mismatched types
5252
--> $DIR/struct-literal-variant-in-if.rs:10:20
5353
|
54-
LL | let field = true;
55-
| ---- here the type of `field` is inferred to be `bool`
5654
LL | if x == E::V { field } {}
5755
| ---------------^^^^^--
5856
| | |

src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ LL | let Some(n) = opt && let another = n else {
100100
error[E0308]: mismatched types
101101
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:9:19
102102
|
103-
LL | let opt = Some(1i32);
104-
| ---------- here the type of `opt` is inferred to be `Option<i32>`
105-
...
106103
LL | let Some(n) = opt && n == 1 else {
107104
| ^^^ expected `bool`, found enum `Option`
108105
|
@@ -123,9 +120,6 @@ LL | let Some(n) = opt && n == 1 else {
123120
error[E0308]: mismatched types
124121
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:15:19
125122
|
126-
LL | let opt = Some(1i32);
127-
| ---------- here the type of `opt` is inferred to be `Option<i32>`
128-
...
129123
LL | let Some(n) = opt && let another = n else {
130124
| ^^^ expected `bool`, found enum `Option`
131125
|

src/test/ui/structs/struct-base-wrong-type.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ LL | static foo_i: Foo = Foo { a: 2, ..4 };
1313
error[E0308]: mismatched types
1414
--> $DIR/struct-base-wrong-type.rs:12:27
1515
|
16-
LL | let b = Bar { x: 5 };
17-
| ------------ here the type of `b` is inferred to be `Bar`
1816
LL | let f = Foo { a: 2, ..b };
1917
| ^ expected struct `Foo`, found struct `Bar`
2018

src/test/ui/suggestions/call-boxed.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ error[E0308]: mismatched types
44
LL | let mut x = 1i32;
55
| ---- expected due to this value
66
LL | let y = Box::new(|| 1);
7-
| --------------
8-
| | |
9-
| | the found closure
10-
| here the type of `y` is inferred to be `Box<[[email protected]:3:22]>`
7+
| -- the found closure
118
LL | x = y;
129
| ^ expected `i32`, found struct `Box`
1310
|

src/test/ui/suggestions/issue-86100-tuple-paren-comma.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ LL | let _s = S { _s: ("abc".to_string(),) };
4949
error[E0308]: mismatched types
5050
--> $DIR/issue-86100-tuple-paren-comma.rs:23:22
5151
|
52-
LL | let t = (1, 2);
53-
| ------ here the type of `t` is inferred to be `({integer}, {integer})`
5452
LL | let _x: (i32,) = (t);
5553
| ------ ^^^ expected a tuple with 1 element, found one with 2 elements
5654
| |

src/test/ui/traits/issue-52893.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ error[E0308]: mismatched types
44
LL | impl<F, Name, P> AddClass<Name, F> for Class<P>
55
| - this type parameter
66
...
7-
LL | let output = builder.to_ref();
8-
| ---------------- here the type of `output` is inferred to be `Class<P>`
97
LL | builder.push(output);
108
| ---- ^^^^^^ expected type parameter `F`, found struct `Class`
119
| |

src/test/ui/tuple/wrong_argument_ice-3.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error[E0061]: this function takes 1 argument but 2 arguments were supplied
22
--> $DIR/wrong_argument_ice-3.rs:9:16
33
|
4-
LL | let new_group = vec![String::new()];
5-
| ------------------- here the type of `new_group` is inferred to be `Vec<String>`
6-
...
74
LL | groups.push(new_group, vec![process]);
85
| ^^^^ ------------- argument of type `Vec<&Process>` unexpected
96
|

src/test/ui/type/type-mismatch-same-crate-name.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/type-mismatch-same-crate-name.rs:16:20
33
|
4-
LL | let foo2 = {extern crate crate_a2 as a; a::Foo};
5-
| ------------------------------------ here the type of `foo2` is inferred to be `Foo`
6-
...
74
LL | a::try_foo(foo2);
85
| ---------- ^^^^ expected struct `main::a::Foo`, found a different struct `main::a::Foo`
96
| |
@@ -30,9 +27,6 @@ LL | pub fn try_foo(x: Foo){}
3027
error[E0308]: mismatched types
3128
--> $DIR/type-mismatch-same-crate-name.rs:20:20
3229
|
33-
LL | let bar2 = {extern crate crate_a2 as a; a::bar()};
34-
| -------------------------------------- here the type of `bar2` is inferred to be `Box<dyn Bar>`
35-
...
3630
LL | a::try_bar(bar2);
3731
| ---------- ^^^^ expected trait `main::a::Bar`, found a different trait `main::a::Bar`
3832
| |

0 commit comments

Comments
 (0)