Skip to content

Commit

Permalink
Rollup merge of #64280 - V1shvesh:master, r=Centril
Browse files Browse the repository at this point in the history
Factor out pluralisation into syntax::errors

Fixes #64238.
  • Loading branch information
Centril committed Sep 8, 2019
2 parents 7cfad41 + 7457ef8 commit 1716678
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
7 changes: 1 addition & 6 deletions src/librustc/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::borrow::Cow;
use std::fmt;
use rustc_target::spec::abi;
use syntax::ast;
use syntax::errors::pluralise;
use errors::{Applicability, DiagnosticBuilder};
use syntax_pos::Span;

Expand Down Expand Up @@ -82,12 +83,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
}
};

macro_rules! pluralise {
($x:expr) => {
if $x != 1 { "s" } else { "" }
};
}

match *self {
CyclicTy(_) => write!(f, "cyclic type of infinite size"),
Mismatch => write!(f, "types differ"),
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,3 +845,10 @@ impl Level {
}
}
}

#[macro_export]
macro_rules! pluralise {
($x:expr) => {
if $x != 1 { "s" } else { "" }
};
}
3 changes: 2 additions & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use rustc_target::spec::abi;
use crate::require_c_abi_if_c_variadic;
use smallvec::SmallVec;
use syntax::ast;
use syntax::errors::pluralise;
use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax::util::lev_distance::find_best_match_for_name;
use syntax::symbol::sym;
Expand Down Expand Up @@ -377,7 +378,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
quantifier,
bound,
kind,
if bound != 1 { "s" } else { "" },
pluralise!(bound),
))
};

Expand Down
9 changes: 5 additions & 4 deletions src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc::util::common::ErrorReported;
use errors::{Applicability, DiagnosticId};

use syntax_pos::Span;
use syntax::errors::pluralise;

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

Expand Down Expand Up @@ -648,9 +649,9 @@ fn compare_number_of_generics<'tcx>(
declaration has {} {kind} parameter{}",
trait_.ident,
impl_count,
if impl_count != 1 { "s" } else { "" },
pluralise!(impl_count),
trait_count,
if trait_count != 1 { "s" } else { "" },
pluralise!(trait_count),
kind = kind,
),
DiagnosticId::Error("E0049".into()),
Expand All @@ -665,7 +666,7 @@ fn compare_number_of_generics<'tcx>(
"expected {} {} parameter{}",
trait_count,
kind,
if trait_count != 1 { "s" } else { "" },
pluralise!(trait_count),
));
}
for span in spans {
Expand All @@ -680,7 +681,7 @@ fn compare_number_of_generics<'tcx>(
"found {} {} parameter{}{}",
impl_count,
kind,
if impl_count != 1 { "s" } else { "" },
pluralise!(impl_count),
suffix.unwrap_or_else(|| String::new()),
));
}
Expand Down

0 comments on commit 1716678

Please sign in to comment.