Skip to content

Commit c25af4a

Browse files
Rollup merge of rust-lang#152339 - JonatanLindh:fix-issue-152331, r=Urgau
diagnostics: fix ICE in closure signature mismatch Fixes rust-lang#152331 Fixes an ICE where `AdjustSignatureBorrow` caused a panic because it attempted to set the `len` argument which was already defined by the parent diagnostic. Both variants used `len` as argument name, but can both be present in a diagnostic. They now use different names for the argument.
2 parents f602fc8 + fb55b5d commit c25af4a

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

compiler/rustc_trait_selection/src/errors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ impl Subdiagnostic for AdjustSignatureBorrow {
153153
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
154154
match self {
155155
AdjustSignatureBorrow::Borrow { to_borrow } => {
156-
diag.arg("len", to_borrow.len());
156+
diag.arg("borrow_len", to_borrow.len());
157157
diag.multipart_suggestion_verbose(
158158
inline_fluent!(
159-
"consider adjusting the signature so it borrows its {$len ->
159+
"consider adjusting the signature so it borrows its {$borrow_len ->
160160
[one] argument
161161
*[other] arguments
162162
}"
@@ -166,10 +166,10 @@ impl Subdiagnostic for AdjustSignatureBorrow {
166166
);
167167
}
168168
AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
169-
diag.arg("len", remove_borrow.len());
169+
diag.arg("remove_borrow_len", remove_borrow.len());
170170
diag.multipart_suggestion_verbose(
171171
inline_fluent!(
172-
"consider adjusting the signature so it does not borrow its {$len ->
172+
"consider adjusting the signature so it does not borrow its {$remove_borrow_len ->
173173
[one] argument
174174
*[other] arguments
175175
}"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn main() {
2+
h2(|_: (), _: (), _: (), x: &_| {});
3+
//~^ ERROR type mismatch in closure arguments
4+
}
5+
6+
fn h2<F>(_: F)
7+
where
8+
F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(), &())),
9+
{
10+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0631]: type mismatch in closure arguments
2+
--> $DIR/closure-arg-borrow-ice-issue-152331.rs:2:5
3+
|
4+
LL | h2(|_: (), _: (), _: (), x: &_| {});
5+
| ^^^----------------------------^^^^
6+
| | |
7+
| | found signature defined here
8+
| expected due to this
9+
|
10+
= note: expected closure signature `for<'a, 't0> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'t0 (), for<'a, 'b> fn(&'a (), &'b ())) -> _`
11+
found closure signature `fn((), (), (), &_) -> _`
12+
note: required by a bound in `h2`
13+
--> $DIR/closure-arg-borrow-ice-issue-152331.rs:8:8
14+
|
15+
LL | fn h2<F>(_: F)
16+
| -- required by a bound in this function
17+
LL | where
18+
LL | F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(), &())),
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h2`
20+
help: consider adjusting the signature so it borrows its arguments
21+
|
22+
LL | h2(|_: &(), _: (), _: &(), x: &_| {});
23+
| + +
24+
help: consider adjusting the signature so it does not borrow its argument
25+
|
26+
LL - h2(|_: (), _: (), _: (), x: &_| {});
27+
LL + h2(|_: (), _: (), _: (), x: _| {});
28+
|
29+
30+
error: aborting due to 1 previous error
31+
32+
For more information about this error, try `rustc --explain E0631`.

0 commit comments

Comments
 (0)