Skip to content

Commit

Permalink
convert to fluent, make plurals work
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 28, 2023
1 parent d1ab6c2 commit 8745ae2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 18 deletions.
10 changes: 10 additions & 0 deletions compiler/rustc_trait_selection/messages.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
trait_selection_adjust_signature_borrow = consider adjusting the signature so it borrows its {$len ->
[one] argument
*[other] arguments
}
trait_selection_adjust_signature_remove_borrow = consider adjusting the signature so it does not borrow its {$len ->
[one] argument
*[other] arguments
}
trait_selection_dump_vtable_entries = vtable entries for `{$trait_ref}`: {$entries}
trait_selection_empty_on_clause_in_rustc_on_unimplemented = empty `on`-clause in `#[rustc_on_unimplemented]`
Expand Down
36 changes: 35 additions & 1 deletion compiler/rustc_trait_selection/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::fluent_generated as fluent;
use rustc_errors::{ErrorGuaranteed, Handler, IntoDiagnostic};
use rustc_errors::{
AddToDiagnostic, Applicability, Diagnostic, ErrorGuaranteed, Handler, IntoDiagnostic,
SubdiagnosticMessage,
};
use rustc_macros::Diagnostic;
use rustc_middle::ty::{self, PolyTraitRef, Ty};
use rustc_span::{Span, Symbol};
Expand Down Expand Up @@ -97,3 +100,34 @@ pub struct InherentProjectionNormalizationOverflow {
pub span: Span,
pub ty: String,
}

pub enum AdjustSignatureBorrow {
Borrow { to_borrow: Vec<(Span, String)> },
RemoveBorrow { remove_borrow: Vec<(Span, String)> },
}

impl AddToDiagnostic for AdjustSignatureBorrow {
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
where
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
{
match self {
AdjustSignatureBorrow::Borrow { to_borrow } => {
diag.set_arg("len", to_borrow.len());
diag.multipart_suggestion_verbose(
fluent::trait_selection_adjust_signature_borrow,
to_borrow,
Applicability::MaybeIncorrect,
);
}
AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
diag.set_arg("len", remove_borrow.len());
diag.multipart_suggestion_verbose(
fluent::trait_selection_adjust_signature_remove_borrow,
remove_borrow,
Applicability::MaybeIncorrect,
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::{
PredicateObligation,
};

use crate::errors;
use crate::infer::InferCtxt;
use crate::traits::{NormalizeExt, ObligationCtxt};

Expand Down Expand Up @@ -4032,19 +4033,11 @@ fn hint_missing_borrow<'tcx>(
}

if !to_borrow.is_empty() {
err.multipart_suggestion_verbose(
"consider adjusting the signature so it borrows its argument",
to_borrow,
Applicability::MaybeIncorrect,
);
err.subdiagnostic(errors::AdjustSignatureBorrow::Borrow { to_borrow });
}

if !remove_borrow.is_empty() {
err.multipart_suggestion_verbose(
"consider adjusting the signature so it does not borrow its argument",
remove_borrow,
Applicability::MaybeIncorrect,
);
err.subdiagnostic(errors::AdjustSignatureBorrow::RemoveBorrow { remove_borrow });
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/ui/anonymous-higher-ranked-lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ note: required by a bound in `f1`
|
LL | fn f1<F>(_: F) where F: Fn(&(), &()) {}
| ^^^^^^^^^^^^ required by this bound in `f1`
help: consider adjusting the signature so it borrows its argument
help: consider adjusting the signature so it borrows its arguments
|
LL | f1(|_: &(), _: &()| {});
| + +
Expand All @@ -33,7 +33,7 @@ note: required by a bound in `f2`
|
LL | fn f2<F>(_: F) where F: for<'a> Fn(&'a (), &()) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f2`
help: consider adjusting the signature so it borrows its argument
help: consider adjusting the signature so it borrows its arguments
|
LL | f2(|_: &(), _: &()| {});
| + +
Expand All @@ -53,7 +53,7 @@ note: required by a bound in `f3`
|
LL | fn f3<'a, F>(_: F) where F: Fn(&'a (), &()) {}
| ^^^^^^^^^^^^^^^ required by this bound in `f3`
help: consider adjusting the signature so it borrows its argument
help: consider adjusting the signature so it borrows its arguments
|
LL | f3(|_: &(), _: &()| {});
| + +
Expand All @@ -73,7 +73,7 @@ note: required by a bound in `f4`
|
LL | fn f4<F>(_: F) where F: for<'r> Fn(&(), &'r ()) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f4`
help: consider adjusting the signature so it borrows its argument
help: consider adjusting the signature so it borrows its arguments
|
LL | f4(|_: &(), _: &()| {});
| + +
Expand All @@ -93,7 +93,7 @@ note: required by a bound in `f5`
|
LL | fn f5<F>(_: F) where F: for<'r> Fn(&'r (), &'r ()) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f5`
help: consider adjusting the signature so it borrows its argument
help: consider adjusting the signature so it borrows its arguments
|
LL | f5(|_: &(), _: &()| {});
| + +
Expand Down Expand Up @@ -193,7 +193,7 @@ note: required by a bound in `h1`
|
LL | fn h1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>, &(), fn(&(), &())) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h1`
help: consider adjusting the signature so it borrows its argument
help: consider adjusting the signature so it borrows its arguments
|
LL | h1(|_: &(), _: (), _: &(), _: ()| {});
| + +
Expand All @@ -213,7 +213,7 @@ note: required by a bound in `h2`
|
LL | fn h2<F>(_: F) where F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(), &())) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h2`
help: consider adjusting the signature so it borrows its argument
help: consider adjusting the signature so it borrows its arguments
|
LL | h2(|_: &(), _: (), _: &(), _: ()| {});
| + +
Expand Down

0 comments on commit 8745ae2

Please sign in to comment.