Skip to content

Commit 1716678

Browse files
authored
Rollup merge of #64280 - V1shvesh:master, r=Centril
Factor out pluralisation into syntax::errors Fixes #64238.
2 parents 7cfad41 + 7457ef8 commit 1716678

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

src/librustc/ty/error.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::borrow::Cow;
44
use std::fmt;
55
use rustc_target::spec::abi;
66
use syntax::ast;
7+
use syntax::errors::pluralise;
78
use errors::{Applicability, DiagnosticBuilder};
89
use syntax_pos::Span;
910

@@ -82,12 +83,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
8283
}
8384
};
8485

85-
macro_rules! pluralise {
86-
($x:expr) => {
87-
if $x != 1 { "s" } else { "" }
88-
};
89-
}
90-
9186
match *self {
9287
CyclicTy(_) => write!(f, "cyclic type of infinite size"),
9388
Mismatch => write!(f, "types differ"),

src/librustc_errors/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -845,3 +845,10 @@ impl Level {
845845
}
846846
}
847847
}
848+
849+
#[macro_export]
850+
macro_rules! pluralise {
851+
($x:expr) => {
852+
if $x != 1 { "s" } else { "" }
853+
};
854+
}

src/librustc_typeck/astconv.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use rustc_target::spec::abi;
2323
use crate::require_c_abi_if_c_variadic;
2424
use smallvec::SmallVec;
2525
use syntax::ast;
26+
use syntax::errors::pluralise;
2627
use syntax::feature_gate::{GateIssue, emit_feature_err};
2728
use syntax::util::lev_distance::find_best_match_for_name;
2829
use syntax::symbol::sym;
@@ -377,7 +378,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
377378
quantifier,
378379
bound,
379380
kind,
380-
if bound != 1 { "s" } else { "" },
381+
pluralise!(bound),
381382
))
382383
};
383384

src/librustc_typeck/check/compare_method.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc::util::common::ErrorReported;
1010
use errors::{Applicability, DiagnosticId};
1111

1212
use syntax_pos::Span;
13+
use syntax::errors::pluralise;
1314

1415
use super::{Inherited, FnCtxt, potentially_plural_count};
1516

@@ -648,9 +649,9 @@ fn compare_number_of_generics<'tcx>(
648649
declaration has {} {kind} parameter{}",
649650
trait_.ident,
650651
impl_count,
651-
if impl_count != 1 { "s" } else { "" },
652+
pluralise!(impl_count),
652653
trait_count,
653-
if trait_count != 1 { "s" } else { "" },
654+
pluralise!(trait_count),
654655
kind = kind,
655656
),
656657
DiagnosticId::Error("E0049".into()),
@@ -665,7 +666,7 @@ fn compare_number_of_generics<'tcx>(
665666
"expected {} {} parameter{}",
666667
trait_count,
667668
kind,
668-
if trait_count != 1 { "s" } else { "" },
669+
pluralise!(trait_count),
669670
));
670671
}
671672
for span in spans {
@@ -680,7 +681,7 @@ fn compare_number_of_generics<'tcx>(
680681
"found {} {} parameter{}{}",
681682
impl_count,
682683
kind,
683-
if impl_count != 1 { "s" } else { "" },
684+
pluralise!(impl_count),
684685
suffix.unwrap_or_else(|| String::new()),
685686
));
686687
}

0 commit comments

Comments
 (0)