Skip to content

Commit 8745ae2

Browse files
convert to fluent, make plurals work
1 parent d1ab6c2 commit 8745ae2

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

compiler/rustc_trait_selection/messages.ftl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
trait_selection_adjust_signature_borrow = consider adjusting the signature so it borrows its {$len ->
2+
[one] argument
3+
*[other] arguments
4+
}
5+
6+
trait_selection_adjust_signature_remove_borrow = consider adjusting the signature so it does not borrow its {$len ->
7+
[one] argument
8+
*[other] arguments
9+
}
10+
111
trait_selection_dump_vtable_entries = vtable entries for `{$trait_ref}`: {$entries}
212
313
trait_selection_empty_on_clause_in_rustc_on_unimplemented = empty `on`-clause in `#[rustc_on_unimplemented]`

compiler/rustc_trait_selection/src/errors.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::fluent_generated as fluent;
2-
use rustc_errors::{ErrorGuaranteed, Handler, IntoDiagnostic};
2+
use rustc_errors::{
3+
AddToDiagnostic, Applicability, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic,
4+
SubdiagnosticMessage,
5+
};
36
use rustc_macros::Diagnostic;
47
use rustc_middle::ty::{self, PolyTraitRef, Ty};
58
use rustc_span::{Span, Symbol};
@@ -97,3 +100,34 @@ pub struct InherentProjectionNormalizationOverflow {
97100
pub span: Span,
98101
pub ty: String,
99102
}
103+
104+
pub enum AdjustSignatureBorrow {
105+
Borrow { to_borrow: Vec<(Span, String)> },
106+
RemoveBorrow { remove_borrow: Vec<(Span, String)> },
107+
}
108+
109+
impl AddToDiagnostic for AdjustSignatureBorrow {
110+
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
111+
where
112+
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
113+
{
114+
match self {
115+
AdjustSignatureBorrow::Borrow { to_borrow } => {
116+
diag.set_arg("len", to_borrow.len());
117+
diag.multipart_suggestion_verbose(
118+
fluent::trait_selection_adjust_signature_borrow,
119+
to_borrow,
120+
Applicability::MaybeIncorrect,
121+
);
122+
}
123+
AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
124+
diag.set_arg("len", remove_borrow.len());
125+
diag.multipart_suggestion_verbose(
126+
fluent::trait_selection_adjust_signature_remove_borrow,
127+
remove_borrow,
128+
Applicability::MaybeIncorrect,
129+
);
130+
}
131+
}
132+
}
133+
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::{
55
PredicateObligation,
66
};
77

8+
use crate::errors;
89
use crate::infer::InferCtxt;
910
use crate::traits::{NormalizeExt, ObligationCtxt};
1011

@@ -4032,19 +4033,11 @@ fn hint_missing_borrow<'tcx>(
40324033
}
40334034

40344035
if !to_borrow.is_empty() {
4035-
err.multipart_suggestion_verbose(
4036-
"consider adjusting the signature so it borrows its argument",
4037-
to_borrow,
4038-
Applicability::MaybeIncorrect,
4039-
);
4036+
err.subdiagnostic(errors::AdjustSignatureBorrow::Borrow { to_borrow });
40404037
}
40414038

40424039
if !remove_borrow.is_empty() {
4043-
err.multipart_suggestion_verbose(
4044-
"consider adjusting the signature so it does not borrow its argument",
4045-
remove_borrow,
4046-
Applicability::MaybeIncorrect,
4047-
);
4040+
err.subdiagnostic(errors::AdjustSignatureBorrow::RemoveBorrow { remove_borrow });
40484041
}
40494042
}
40504043

tests/ui/anonymous-higher-ranked-lifetime.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ note: required by a bound in `f1`
1313
|
1414
LL | fn f1<F>(_: F) where F: Fn(&(), &()) {}
1515
| ^^^^^^^^^^^^ required by this bound in `f1`
16-
help: consider adjusting the signature so it borrows its argument
16+
help: consider adjusting the signature so it borrows its arguments
1717
|
1818
LL | f1(|_: &(), _: &()| {});
1919
| + +
@@ -33,7 +33,7 @@ note: required by a bound in `f2`
3333
|
3434
LL | fn f2<F>(_: F) where F: for<'a> Fn(&'a (), &()) {}
3535
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f2`
36-
help: consider adjusting the signature so it borrows its argument
36+
help: consider adjusting the signature so it borrows its arguments
3737
|
3838
LL | f2(|_: &(), _: &()| {});
3939
| + +
@@ -53,7 +53,7 @@ note: required by a bound in `f3`
5353
|
5454
LL | fn f3<'a, F>(_: F) where F: Fn(&'a (), &()) {}
5555
| ^^^^^^^^^^^^^^^ required by this bound in `f3`
56-
help: consider adjusting the signature so it borrows its argument
56+
help: consider adjusting the signature so it borrows its arguments
5757
|
5858
LL | f3(|_: &(), _: &()| {});
5959
| + +
@@ -73,7 +73,7 @@ note: required by a bound in `f4`
7373
|
7474
LL | fn f4<F>(_: F) where F: for<'r> Fn(&(), &'r ()) {}
7575
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f4`
76-
help: consider adjusting the signature so it borrows its argument
76+
help: consider adjusting the signature so it borrows its arguments
7777
|
7878
LL | f4(|_: &(), _: &()| {});
7979
| + +
@@ -93,7 +93,7 @@ note: required by a bound in `f5`
9393
|
9494
LL | fn f5<F>(_: F) where F: for<'r> Fn(&'r (), &'r ()) {}
9595
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f5`
96-
help: consider adjusting the signature so it borrows its argument
96+
help: consider adjusting the signature so it borrows its arguments
9797
|
9898
LL | f5(|_: &(), _: &()| {});
9999
| + +
@@ -193,7 +193,7 @@ note: required by a bound in `h1`
193193
|
194194
LL | fn h1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>, &(), fn(&(), &())) {}
195195
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h1`
196-
help: consider adjusting the signature so it borrows its argument
196+
help: consider adjusting the signature so it borrows its arguments
197197
|
198198
LL | h1(|_: &(), _: (), _: &(), _: ()| {});
199199
| + +
@@ -213,7 +213,7 @@ note: required by a bound in `h2`
213213
|
214214
LL | fn h2<F>(_: F) where F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(), &())) {}
215215
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h2`
216-
help: consider adjusting the signature so it borrows its argument
216+
help: consider adjusting the signature so it borrows its arguments
217217
|
218218
LL | h2(|_: &(), _: (), _: &(), _: ()| {});
219219
| + +

0 commit comments

Comments
 (0)