auto merge of #14831 : alexcrichton/rust/format-intl, r=brson
* The select/plural methods from format strings are removed
* The # character no longer needs to be escaped
* The \-based escapes have been removed
* '{{' is now an escape for '{'
* '}}' is now an escape for '}'
Closes #14810
[breaking-change]
This commit is contained in:
commit
0422934e24
57 changed files with 736 additions and 1087 deletions
|
|
@ -108,6 +108,7 @@ struct Context<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Context<'a> {
|
||||
#[cfg(stage0)]
|
||||
fn gate_feature(&self, feature: &str, span: Span, explain: &str) {
|
||||
if !self.has_feature(feature) {
|
||||
self.sess.span_err(span, explain);
|
||||
|
|
@ -116,6 +117,15 @@ impl<'a> Context<'a> {
|
|||
feature).as_slice());
|
||||
}
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
fn gate_feature(&self, feature: &str, span: Span, explain: &str) {
|
||||
if !self.has_feature(feature) {
|
||||
self.sess.span_err(span, explain);
|
||||
self.sess.span_note(span, format!("add #![feature({})] to the \
|
||||
crate attributes to enable",
|
||||
feature).as_slice());
|
||||
}
|
||||
}
|
||||
|
||||
fn gate_box(&self, span: Span) {
|
||||
self.gate_feature("managed_boxes", span,
|
||||
|
|
|
|||
|
|
@ -63,12 +63,20 @@ struct StandardLibraryInjector<'a> {
|
|||
pub fn with_version(krate: &str) -> Option<(InternedString, ast::StrStyle)> {
|
||||
match option_env!("CFG_DISABLE_INJECT_STD_VERSION") {
|
||||
Some("1") => None,
|
||||
#[cfg(stage0)]
|
||||
_ => {
|
||||
Some((token::intern_and_get_ident(format!("{}\\#{}",
|
||||
krate,
|
||||
VERSION).as_slice()),
|
||||
ast::CookedStr))
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
_ => {
|
||||
Some((token::intern_and_get_ident(format!("{}#{}",
|
||||
krate,
|
||||
VERSION).as_slice()),
|
||||
ast::CookedStr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,8 +146,8 @@ impl<'a> Context<'a> {
|
|||
self.triple).as_slice());
|
||||
for (i, &CrateMismatch{ ref path, ref got }) in mismatches.enumerate() {
|
||||
self.sess.fileline_note(self.span,
|
||||
format!("crate `{}` path \\#{}, triple {}: {}",
|
||||
self.ident, i+1, got, path.display()).as_slice());
|
||||
format!("crate `{}` path {}{}, triple {}: {}",
|
||||
self.ident, "#", i+1, got, path.display()).as_slice());
|
||||
}
|
||||
}
|
||||
if self.rejected_via_hash.len() > 0 {
|
||||
|
|
@ -156,11 +156,12 @@ impl<'a> Context<'a> {
|
|||
let mismatches = self.rejected_via_hash.iter();
|
||||
for (i, &CrateMismatch{ ref path, .. }) in mismatches.enumerate() {
|
||||
self.sess.fileline_note(self.span,
|
||||
format!("crate `{}` path \\#{}: {}",
|
||||
self.ident, i+1, path.display()).as_slice());
|
||||
format!("crate `{}` path {}{}: {}",
|
||||
self.ident, "#", i+1, path.display()).as_slice());
|
||||
}
|
||||
match self.root {
|
||||
&None => {}
|
||||
#[cfg(stage0)]
|
||||
&Some(ref r) => {
|
||||
for (i, path) in r.paths().iter().enumerate() {
|
||||
self.sess.fileline_note(self.span,
|
||||
|
|
@ -168,6 +169,14 @@ impl<'a> Context<'a> {
|
|||
r.ident, i+1, path.display()).as_slice());
|
||||
}
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
&Some(ref r) => {
|
||||
for (i, path) in r.paths().iter().enumerate() {
|
||||
self.sess.fileline_note(self.span,
|
||||
format!("crate `{}` path #{}: {}",
|
||||
r.ident, i+1, path.display()).as_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.sess.abort_if_errors();
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ pub struct ty_abbrev {
|
|||
|
||||
pub type abbrev_map = RefCell<HashMap<ty::t, ty_abbrev>>;
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub fn enc_ty(w: &mut MemWriter, cx: &ctxt, t: ty::t) {
|
||||
match cx.abbrevs.borrow_mut().find(&t) {
|
||||
Some(a) => { w.write(a.s.as_bytes()); return; }
|
||||
|
|
@ -70,6 +71,30 @@ pub fn enc_ty(w: &mut MemWriter, cx: &ctxt, t: ty::t) {
|
|||
});
|
||||
}
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
pub fn enc_ty(w: &mut MemWriter, cx: &ctxt, t: ty::t) {
|
||||
match cx.abbrevs.borrow_mut().find(&t) {
|
||||
Some(a) => { w.write(a.s.as_bytes()); return; }
|
||||
None => {}
|
||||
}
|
||||
let pos = w.tell().unwrap();
|
||||
enc_sty(w, cx, &ty::get(t).sty);
|
||||
let end = w.tell().unwrap();
|
||||
let len = end - pos;
|
||||
fn estimate_sz(u: u64) -> u64 {
|
||||
let mut n = u;
|
||||
let mut len = 0;
|
||||
while n != 0 { len += 1; n = n >> 4; }
|
||||
return len;
|
||||
}
|
||||
let abbrev_len = 3 + estimate_sz(pos) + estimate_sz(len);
|
||||
if abbrev_len < len {
|
||||
// I.e. it's actually an abbreviation.
|
||||
cx.abbrevs.borrow_mut().insert(t, ty_abbrev {
|
||||
s: format!("#{:x}:{:x}#", pos, len)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn enc_mutability(w: &mut MemWriter, mt: ast::Mutability) {
|
||||
match mt {
|
||||
|
|
|
|||
|
|
@ -484,10 +484,16 @@ pub fn emit_lint(level: Level, src: LintSource, msg: &str, span: Span,
|
|||
|
||||
let mut note = None;
|
||||
let msg = match src {
|
||||
#[cfg(stage0)]
|
||||
Default => {
|
||||
format!("{}, \\#[{}({})] on by default", msg,
|
||||
level_to_str(level), lint_str)
|
||||
},
|
||||
#[cfg(not(stage0))]
|
||||
Default => {
|
||||
format!("{}, #[{}({})] on by default", msg,
|
||||
level_to_str(level), lint_str)
|
||||
},
|
||||
CommandLine => {
|
||||
format!("{} [-{} {}]", msg,
|
||||
match level {
|
||||
|
|
|
|||
|
|
@ -1253,6 +1253,7 @@ impl cmt_ {
|
|||
}
|
||||
|
||||
impl Repr for cmt_ {
|
||||
#[cfg(stage0)]
|
||||
fn repr(&self, tcx: &ty::ctxt) -> String {
|
||||
format!("\\{{} id:{} m:{:?} ty:{}\\}",
|
||||
self.cat.repr(tcx),
|
||||
|
|
@ -1260,6 +1261,14 @@ impl Repr for cmt_ {
|
|||
self.mutbl,
|
||||
self.ty.repr(tcx))
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
fn repr(&self, tcx: &ty::ctxt) -> String {
|
||||
format!("{{{} id:{} m:{:?} ty:{}}}",
|
||||
self.cat.repr(tcx),
|
||||
self.id,
|
||||
self.mutbl,
|
||||
self.ty.repr(tcx))
|
||||
}
|
||||
}
|
||||
|
||||
impl Repr for categorization {
|
||||
|
|
@ -1306,7 +1315,10 @@ impl Repr for InteriorKind {
|
|||
InteriorField(NamedField(fld)) => {
|
||||
token::get_name(fld).get().to_str()
|
||||
}
|
||||
#[cfg(stage0)]
|
||||
InteriorField(PositionalField(i)) => format!("\\#{:?}", i),
|
||||
#[cfg(not(stage0))]
|
||||
InteriorField(PositionalField(i)) => format!("#{:?}", i),
|
||||
InteriorElement(_) => "[]".to_string(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -642,8 +642,12 @@ impl<'a> PrivacyVisitor<'a> {
|
|||
let msg = match name {
|
||||
NamedField(name) => format!("field `{}` of {} is private",
|
||||
token::get_ident(name), struct_desc),
|
||||
#[cfg(stage0)]
|
||||
UnnamedField(idx) => format!("field \\#{} of {} is private",
|
||||
idx + 1, struct_desc),
|
||||
#[cfg(not(stage0))]
|
||||
UnnamedField(idx) => format!("field #{} of {} is private",
|
||||
idx + 1, struct_desc),
|
||||
};
|
||||
self.tcx.sess.span_err(span, msg.as_slice());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4079,6 +4079,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
for (&key, &binding_0) in map_0.iter() {
|
||||
match map_i.find(&key) {
|
||||
#[cfg(stage0)]
|
||||
None => {
|
||||
self.resolve_error(
|
||||
p.span,
|
||||
|
|
@ -4087,6 +4088,16 @@ impl<'a> Resolver<'a> {
|
|||
token::get_name(key),
|
||||
i + 1).as_slice());
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
None => {
|
||||
self.resolve_error(
|
||||
p.span,
|
||||
format!("variable `{}` from pattern #1 is \
|
||||
not bound in pattern #{}",
|
||||
token::get_name(key),
|
||||
i + 1).as_slice());
|
||||
}
|
||||
#[cfg(stage0)]
|
||||
Some(binding_i) => {
|
||||
if binding_0.binding_mode != binding_i.binding_mode {
|
||||
self.resolve_error(
|
||||
|
|
@ -4097,6 +4108,17 @@ impl<'a> Resolver<'a> {
|
|||
i + 1).as_slice());
|
||||
}
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
Some(binding_i) => {
|
||||
if binding_0.binding_mode != binding_i.binding_mode {
|
||||
self.resolve_error(
|
||||
binding_i.span,
|
||||
format!("variable `{}` is bound with different \
|
||||
mode in pattern #{} than in pattern #1",
|
||||
token::get_name(key),
|
||||
i + 1).as_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -4104,10 +4126,10 @@ impl<'a> Resolver<'a> {
|
|||
if !map_0.contains_key(&key) {
|
||||
self.resolve_error(
|
||||
binding.span,
|
||||
format!("variable `{}` from pattern \\#{} is \
|
||||
not bound in pattern \\#1",
|
||||
format!("variable `{}` from pattern {}{} is \
|
||||
not bound in pattern {}1",
|
||||
token::get_name(key),
|
||||
i + 1).as_slice());
|
||||
"#", i + 1, "#").as_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5094,6 +5116,7 @@ impl<'a> Resolver<'a> {
|
|||
// structs, which wouldn't result in this error.)
|
||||
match self.with_no_errors(|this|
|
||||
this.resolve_path(expr.id, path, TypeNS, false)) {
|
||||
#[cfg(stage0)]
|
||||
Some((DefTy(struct_id), _))
|
||||
if self.structs.contains_key(&struct_id) => {
|
||||
self.resolve_error(expr.span,
|
||||
|
|
@ -5107,6 +5130,21 @@ impl<'a> Resolver<'a> {
|
|||
`{} \\{ /* fields */ \\}`?",
|
||||
wrong_name).as_slice());
|
||||
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
Some((DefTy(struct_id), _))
|
||||
if self.structs.contains_key(&struct_id) => {
|
||||
self.resolve_error(expr.span,
|
||||
format!("`{}` is a structure name, but \
|
||||
this expression \
|
||||
uses it like a function name",
|
||||
wrong_name).as_slice());
|
||||
|
||||
self.session.span_note(expr.span,
|
||||
format!("Did you mean to write: \
|
||||
`{} {{ /* fields */ }}`?",
|
||||
wrong_name).as_slice());
|
||||
|
||||
}
|
||||
_ => {
|
||||
let mut method_scope = false;
|
||||
|
|
|
|||
|
|
@ -761,7 +761,8 @@ impl<'a> Builder<'a> {
|
|||
pub fn add_comment(&self, text: &str) {
|
||||
if self.ccx.sess().asm_comments() {
|
||||
let sanitized = text.replace("$", "");
|
||||
let comment_text = format!("\\# {}", sanitized.replace("\n", "\n\t# "));
|
||||
let comment_text = format!("{} {}", "#",
|
||||
sanitized.replace("\n", "\n\t# "));
|
||||
self.count_insn("inlineasm");
|
||||
let asm = comment_text.as_slice().with_c_str(|c| {
|
||||
unsafe {
|
||||
|
|
|
|||
|
|
@ -692,7 +692,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
|
|||
let foreign_index = next_foreign_arg(llforeign_arg_ty.pad.is_some());
|
||||
let mut llforeign_arg = llvm::LLVMGetParam(llwrapfn, foreign_index);
|
||||
|
||||
debug!("llforeign_arg \\#{}: {}",
|
||||
debug!("llforeign_arg {}{}: {}", "#",
|
||||
i, ccx.tn.val_to_str(llforeign_arg));
|
||||
debug!("rust_indirect = {}, foreign_indirect = {}",
|
||||
rust_indirect, foreign_indirect);
|
||||
|
|
@ -725,7 +725,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
|
|||
llvm::LLVMBuildLoad(builder, llforeign_arg, noname())
|
||||
};
|
||||
|
||||
debug!("llrust_arg \\#{}: {}",
|
||||
debug!("llrust_arg {}{}: {}", "#",
|
||||
i, ccx.tn.val_to_str(llrust_arg));
|
||||
llrust_args.push(llrust_arg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -391,12 +391,14 @@ pub fn trans_intrinsic(ccx: &CrateContext,
|
|||
};
|
||||
ccx.sess().span_fatal(sp,
|
||||
format!("transmute called on types with different sizes: \
|
||||
{intype} ({insize, plural, =1{# bit} other{# bits}}) to \
|
||||
{outtype} ({outsize, plural, =1{# bit} other{# bits}})",
|
||||
intype = ty_to_str(ccx.tcx(), in_type),
|
||||
insize = in_type_size as uint,
|
||||
outtype = ty_to_str(ccx.tcx(), out_type),
|
||||
outsize = out_type_size as uint).as_slice());
|
||||
{} ({} bit{}) to \
|
||||
{} ({} bit{})",
|
||||
ty_to_str(ccx.tcx(), in_type),
|
||||
in_type_size,
|
||||
if in_type_size == 1 {""} else {"s"},
|
||||
ty_to_str(ccx.tcx(), out_type),
|
||||
out_type_size,
|
||||
if out_type_size == 1 {""} else {"s"}).as_slice());
|
||||
}
|
||||
|
||||
if !return_type_is_void(ccx, out_type) {
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ pub struct VecTypes {
|
|||
}
|
||||
|
||||
impl VecTypes {
|
||||
#[cfg(stage0)]
|
||||
pub fn to_str(&self, ccx: &CrateContext) -> String {
|
||||
format!("VecTypes \\{unit_ty={}, llunit_ty={}, \
|
||||
llunit_size={}, llunit_alloc_size={}\\}",
|
||||
|
|
@ -81,6 +82,15 @@ impl VecTypes {
|
|||
ccx.tn.val_to_str(self.llunit_size),
|
||||
self.llunit_alloc_size)
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
pub fn to_str(&self, ccx: &CrateContext) -> String {
|
||||
format!("VecTypes {{unit_ty={}, llunit_ty={}, \
|
||||
llunit_size={}, llunit_alloc_size={}}}",
|
||||
ty_to_str(ccx.tcx(), self.unit_ty),
|
||||
ccx.tn.type_to_str(self.llunit_ty),
|
||||
ccx.tn.val_to_str(self.llunit_size),
|
||||
self.llunit_alloc_size)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trans_fixed_vstore<'a>(
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ pub fn llvm_type_name(cx: &CrateContext,
|
|||
if did.krate == 0 {
|
||||
format!("{}.{}", name, tstr)
|
||||
} else {
|
||||
format!("{}.{}[\\#{}]", name, tstr, did.krate)
|
||||
format!("{}.{}[{}{}]", name, tstr, "#", did.krate)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -884,9 +884,14 @@ impl Vid for TyVid {
|
|||
}
|
||||
|
||||
impl fmt::Show for TyVid {
|
||||
#[cfg(stage0)]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
|
||||
write!(f, "<generic \\#{}>", self.to_uint())
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
|
||||
write!(f, "<generic #{}>", self.to_uint())
|
||||
}
|
||||
}
|
||||
|
||||
impl Vid for IntVid {
|
||||
|
|
@ -894,9 +899,14 @@ impl Vid for IntVid {
|
|||
}
|
||||
|
||||
impl fmt::Show for IntVid {
|
||||
#[cfg(stage0)]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "<generic integer \\#{}>", self.to_uint())
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "<generic integer #{}>", self.to_uint())
|
||||
}
|
||||
}
|
||||
|
||||
impl Vid for FloatVid {
|
||||
|
|
@ -904,9 +914,14 @@ impl Vid for FloatVid {
|
|||
}
|
||||
|
||||
impl fmt::Show for FloatVid {
|
||||
#[cfg(stage0)]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "<generic float \\#{}>", self.to_uint())
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "<generic float #{}>", self.to_uint())
|
||||
}
|
||||
}
|
||||
|
||||
impl Vid for RegionVid {
|
||||
|
|
|
|||
|
|
@ -256,13 +256,13 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
|
|||
if arg_len > 0 {
|
||||
// N-ary variant.
|
||||
if arg_len != subpats_len {
|
||||
let s = format!("this pattern has \
|
||||
{npat, plural, =1{# field} other{# fields}}, \
|
||||
but the corresponding {kind} has \
|
||||
{narg, plural, =1{# field} other{# fields}}",
|
||||
npat = subpats_len,
|
||||
kind = kind_name,
|
||||
narg = arg_len);
|
||||
let s = format!("this pattern has {} field{}, \
|
||||
but the corresponding {} has {} field{}",
|
||||
subpats_len,
|
||||
if subpats_len == 1 {""} else {"s"},
|
||||
kind_name,
|
||||
arg_len,
|
||||
if arg_len == 1 {""} else {"s"});
|
||||
tcx.sess.span_err(pat.span, s.as_slice());
|
||||
error_happened = true;
|
||||
}
|
||||
|
|
@ -276,11 +276,11 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
|
|||
}
|
||||
} else if subpats_len > 0 {
|
||||
tcx.sess.span_err(pat.span,
|
||||
format!("this pattern has \
|
||||
{npat, plural, =1{# field} other{# fields}}, \
|
||||
but the corresponding {kind} has no fields",
|
||||
npat = subpats_len,
|
||||
kind = kind_name).as_slice());
|
||||
format!("this pattern has {} field{}, \
|
||||
but the corresponding {} has no fields",
|
||||
subpats_len,
|
||||
if subpats_len == 1 {""} else {"s"},
|
||||
kind_name).as_slice());
|
||||
error_happened = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1435,6 +1435,7 @@ impl<'a> LookupContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn report_static_candidate(&self, idx: uint, did: DefId) {
|
||||
let span = if did.krate == ast::LOCAL_CRATE {
|
||||
self.tcx().map.span(did.node)
|
||||
|
|
@ -1448,6 +1449,7 @@ impl<'a> LookupContext<'a> {
|
|||
ty::item_path_str(self.tcx(), did)).as_slice());
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn report_param_candidate(&self, idx: uint, did: DefId) {
|
||||
self.tcx().sess.span_note(
|
||||
self.span,
|
||||
|
|
@ -1456,6 +1458,7 @@ impl<'a> LookupContext<'a> {
|
|||
ty::item_path_str(self.tcx(), did)).as_slice());
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn report_trait_candidate(&self, idx: uint, did: DefId) {
|
||||
self.tcx().sess.span_note(
|
||||
self.span,
|
||||
|
|
@ -1465,6 +1468,39 @@ impl<'a> LookupContext<'a> {
|
|||
ty::item_path_str(self.tcx(), did)).as_slice());
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn report_static_candidate(&self, idx: uint, did: DefId) {
|
||||
let span = if did.krate == ast::LOCAL_CRATE {
|
||||
self.tcx().map.span(did.node)
|
||||
} else {
|
||||
self.span
|
||||
};
|
||||
self.tcx().sess.span_note(
|
||||
span,
|
||||
format!("candidate #{} is `{}`",
|
||||
idx + 1u,
|
||||
ty::item_path_str(self.tcx(), did)).as_slice());
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn report_param_candidate(&self, idx: uint, did: DefId) {
|
||||
self.tcx().sess.span_note(
|
||||
self.span,
|
||||
format!("candidate #{} derives from the bound `{}`",
|
||||
idx + 1u,
|
||||
ty::item_path_str(self.tcx(), did)).as_slice());
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
fn report_trait_candidate(&self, idx: uint, did: DefId) {
|
||||
self.tcx().sess.span_note(
|
||||
self.span,
|
||||
format!("candidate #{} derives from the type of the receiver, \
|
||||
which is the trait `{}`",
|
||||
idx + 1u,
|
||||
ty::item_path_str(self.tcx(), did)).as_slice());
|
||||
}
|
||||
|
||||
fn infcx(&'a self) -> &'a infer::InferCtxt<'a> {
|
||||
&self.fcx.inh.infcx
|
||||
}
|
||||
|
|
|
|||
|
|
@ -902,26 +902,26 @@ fn compare_impl_method(tcx: &ty::ctxt,
|
|||
if num_impl_m_type_params != num_trait_m_type_params {
|
||||
tcx.sess.span_err(
|
||||
impl_m_span,
|
||||
format!("method `{method}` has {nimpl, plural, =1{# type parameter} \
|
||||
other{# type parameters}}, \
|
||||
but its trait declaration has {ntrait, plural, =1{# type parameter} \
|
||||
other{# type parameters}}",
|
||||
method = token::get_ident(trait_m.ident),
|
||||
nimpl = num_impl_m_type_params,
|
||||
ntrait = num_trait_m_type_params).as_slice());
|
||||
format!("method `{}` has {} type parameter{} \
|
||||
but its trait declaration has {} type parameter{}",
|
||||
token::get_ident(trait_m.ident),
|
||||
num_impl_m_type_params,
|
||||
if num_impl_m_type_params == 1 {""} else {"s"},
|
||||
num_trait_m_type_params,
|
||||
if num_trait_m_type_params == 1 {""} else {"s"}).as_slice());
|
||||
return;
|
||||
}
|
||||
|
||||
if impl_m.fty.sig.inputs.len() != trait_m.fty.sig.inputs.len() {
|
||||
tcx.sess.span_err(
|
||||
impl_m_span,
|
||||
format!("method `{method}` has {nimpl, plural, =1{# parameter} \
|
||||
other{# parameters}} \
|
||||
but the declaration in trait `{trait}` has {ntrait}",
|
||||
method = token::get_ident(trait_m.ident),
|
||||
nimpl = impl_m.fty.sig.inputs.len(),
|
||||
trait = ty::item_path_str(tcx, trait_m.def_id),
|
||||
ntrait = trait_m.fty.sig.inputs.len()).as_slice());
|
||||
format!("method `{}` has {} parameter{} \
|
||||
but the declaration in trait `{}` has {}",
|
||||
token::get_ident(trait_m.ident),
|
||||
impl_m.fty.sig.inputs.len(),
|
||||
if impl_m.fty.sig.inputs.len() == 1 {""} else {"s"},
|
||||
ty::item_path_str(tcx, trait_m.def_id),
|
||||
trait_m.fty.sig.inputs.len()).as_slice());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -954,20 +954,19 @@ fn compare_impl_method(tcx: &ty::ctxt,
|
|||
if impl_param_def.bounds.trait_bounds.len() !=
|
||||
trait_param_def.bounds.trait_bounds.len()
|
||||
{
|
||||
let found = impl_param_def.bounds.trait_bounds.len();
|
||||
let expected = trait_param_def.bounds.trait_bounds.len();
|
||||
tcx.sess.span_err(
|
||||
impl_m_span,
|
||||
format!("in method `{method}`, \
|
||||
type parameter {typaram} has \
|
||||
{nimpl, plural, =1{# trait bound} other{# trait bounds}}, \
|
||||
but the corresponding type parameter in \
|
||||
the trait declaration has \
|
||||
{ntrait, plural, =1{# trait bound} other{# trait bounds}}",
|
||||
method = token::get_ident(trait_m.ident),
|
||||
typaram = i,
|
||||
nimpl = impl_param_def.bounds.trait_bounds.len(),
|
||||
ntrait = trait_param_def.bounds
|
||||
.trait_bounds
|
||||
.len()).as_slice());
|
||||
format!("in method `{}`, type parameter {} has {} trait \
|
||||
bound{}, but the corresponding type parameter in \
|
||||
the trait declaration has {} trait bound{}",
|
||||
token::get_ident(trait_m.ident),
|
||||
i,
|
||||
found,
|
||||
if found == 1 {""} else {"s"},
|
||||
expected,
|
||||
if expected == 1 {""} else {"s"}).as_slice());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -1526,13 +1525,12 @@ fn check_argument_types(fcx: &FnCtxt,
|
|||
ty::ty_tup(ref arg_types) => {
|
||||
if arg_types.len() != args.len() {
|
||||
let msg = format!(
|
||||
"this function takes \
|
||||
{nexpected, plural, =1{# parameter} \
|
||||
other{# parameters}} \
|
||||
but {nsupplied, plural, =1{# parameter was} \
|
||||
other{# parameters were}} supplied",
|
||||
nexpected = arg_types.len(),
|
||||
nsupplied = args.len());
|
||||
"this function takes {} parameter{} \
|
||||
but {} parameter{} supplied",
|
||||
arg_types.len(),
|
||||
if arg_types.len() == 1 {""} else {"s"},
|
||||
args.len(),
|
||||
if args.len() == 1 {" was"} else {"s were"});
|
||||
tcx.sess.span_err(sp, msg.as_slice());
|
||||
err_args(args.len())
|
||||
} else {
|
||||
|
|
@ -1543,9 +1541,9 @@ fn check_argument_types(fcx: &FnCtxt,
|
|||
if args.len() != 0 {
|
||||
let msg = format!(
|
||||
"this function takes 0 parameters \
|
||||
but {nsupplied, plural, =1{# parameter was} \
|
||||
other{# parameters were}} supplied",
|
||||
nsupplied = args.len());
|
||||
but {} parameter{} supplied",
|
||||
args.len(),
|
||||
if args.len() == 1 {" was"} else {"s were"});
|
||||
tcx.sess.span_err(sp, msg.as_slice());
|
||||
}
|
||||
Vec::new()
|
||||
|
|
@ -1566,12 +1564,12 @@ fn check_argument_types(fcx: &FnCtxt,
|
|||
fn_inputs.iter().map(|a| *a).collect()
|
||||
} else {
|
||||
let msg = format!(
|
||||
"this function takes at least {nexpected, plural, =1{# parameter} \
|
||||
other{# parameters}} \
|
||||
but {nsupplied, plural, =1{# parameter was} \
|
||||
other{# parameters were}} supplied",
|
||||
nexpected = expected_arg_count,
|
||||
nsupplied = supplied_arg_count);
|
||||
"this function takes at least {} parameter{} \
|
||||
but {} parameter{} supplied",
|
||||
expected_arg_count,
|
||||
if expected_arg_count == 1 {""} else {"s"},
|
||||
supplied_arg_count,
|
||||
if supplied_arg_count == 1 {" was"} else {"s were"});
|
||||
|
||||
tcx.sess.span_err(sp, msg.as_slice());
|
||||
|
||||
|
|
@ -1579,12 +1577,12 @@ fn check_argument_types(fcx: &FnCtxt,
|
|||
}
|
||||
} else {
|
||||
let msg = format!(
|
||||
"this function takes {nexpected, plural, =1{# parameter} \
|
||||
other{# parameters}} \
|
||||
but {nsupplied, plural, =1{# parameter was} \
|
||||
other{# parameters were}} supplied",
|
||||
nexpected = expected_arg_count,
|
||||
nsupplied = supplied_arg_count);
|
||||
"this function takes {} parameter{} \
|
||||
but {} parameter{} supplied",
|
||||
expected_arg_count,
|
||||
if expected_arg_count == 1 {""} else {"s"},
|
||||
supplied_arg_count,
|
||||
if supplied_arg_count == 1 {" was"} else {"s were"});
|
||||
|
||||
tcx.sess.span_err(sp, msg.as_slice());
|
||||
|
||||
|
|
@ -1932,12 +1930,14 @@ fn check_type_parameter_positions_in_path(function_context: &FnCtxt,
|
|||
function_context.tcx()
|
||||
.sess
|
||||
.span_err(path.span,
|
||||
format!("expected {nexpected, plural, =1{# lifetime parameter} \
|
||||
other{# lifetime parameters}}, \
|
||||
found {nsupplied, plural, =1{# lifetime parameter} \
|
||||
other{# lifetime parameters}}",
|
||||
nexpected = trait_region_parameter_count,
|
||||
nsupplied = supplied_region_parameter_count).as_slice());
|
||||
format!("expected {} lifetime parameter{} \
|
||||
found {} liftime parameter{}",
|
||||
trait_region_parameter_count,
|
||||
if trait_region_parameter_count == 1 {""}
|
||||
else {"s"},
|
||||
supplied_region_parameter_count,
|
||||
if supplied_region_parameter_count == 1 {""}
|
||||
else {"s"}).as_slice());
|
||||
}
|
||||
|
||||
// Make sure the number of type parameters supplied on the trait
|
||||
|
|
@ -1950,45 +1950,41 @@ fn check_type_parameter_positions_in_path(function_context: &FnCtxt,
|
|||
let supplied_ty_param_count = trait_segment.types.len();
|
||||
if supplied_ty_param_count < required_ty_param_count {
|
||||
let msg = if required_ty_param_count < generics.type_param_defs().len() {
|
||||
format!("the {trait_or_impl} referenced by this path needs at least \
|
||||
{nexpected, plural, =1{# type parameter} \
|
||||
other{# type parameters}}, \
|
||||
but {nsupplied, plural, =1{# type parameter} \
|
||||
other{# type parameters}} were supplied",
|
||||
trait_or_impl = name,
|
||||
nexpected = required_ty_param_count,
|
||||
nsupplied = supplied_ty_param_count)
|
||||
format!("the {} referenced by this path needs at least \
|
||||
{} type parameter{}, but {} type parameters were \
|
||||
supplied",
|
||||
name,
|
||||
required_ty_param_count,
|
||||
if required_ty_param_count == 1 {""} else {"s"},
|
||||
supplied_ty_param_count)
|
||||
} else {
|
||||
format!("the {trait_or_impl} referenced by this path needs \
|
||||
{nexpected, plural, =1{# type parameter} \
|
||||
other{# type parameters}}, \
|
||||
but {nsupplied, plural, =1{# type parameter} \
|
||||
other{# type parameters}} were supplied",
|
||||
trait_or_impl = name,
|
||||
nexpected = required_ty_param_count,
|
||||
nsupplied = supplied_ty_param_count)
|
||||
format!("the {} referenced by this path needs \
|
||||
{} type parameter{}, but {} type parameters were \
|
||||
supplied",
|
||||
name,
|
||||
required_ty_param_count,
|
||||
if required_ty_param_count == 1 {""} else {"s"},
|
||||
supplied_ty_param_count)
|
||||
};
|
||||
function_context.tcx().sess.span_err(path.span,
|
||||
msg.as_slice())
|
||||
} else if supplied_ty_param_count > formal_ty_param_count {
|
||||
let msg = if required_ty_param_count < generics.type_param_defs().len() {
|
||||
format!("the {trait_or_impl} referenced by this path needs at most \
|
||||
{nexpected, plural, =1{# type parameter} \
|
||||
other{# type parameters}}, \
|
||||
but {nsupplied, plural, =1{# type parameter} \
|
||||
other{# type parameters}} were supplied",
|
||||
trait_or_impl = name,
|
||||
nexpected = formal_ty_param_count,
|
||||
nsupplied = supplied_ty_param_count)
|
||||
format!("the {} referenced by this path needs at most \
|
||||
{} type parameter{}, but {} type parameters were \
|
||||
supplied",
|
||||
name,
|
||||
formal_ty_param_count,
|
||||
if formal_ty_param_count == 1 {""} else {"s"},
|
||||
supplied_ty_param_count)
|
||||
} else {
|
||||
format!("the {trait_or_impl} referenced by this path needs \
|
||||
{nexpected, plural, =1{# type parameter} \
|
||||
other{# type parameters}}, \
|
||||
but {nsupplied, plural, =1{# type parameter} \
|
||||
other{# type parameters}} were supplied",
|
||||
trait_or_impl = name,
|
||||
nexpected = formal_ty_param_count,
|
||||
nsupplied = supplied_ty_param_count)
|
||||
format!("the {} referenced by this path needs \
|
||||
{} type parameter{}, but {} type parameters were \
|
||||
supplied",
|
||||
name,
|
||||
formal_ty_param_count,
|
||||
if formal_ty_param_count == 1 {""} else {"s"},
|
||||
supplied_ty_param_count)
|
||||
};
|
||||
function_context.tcx().sess.span_err(path.span,
|
||||
msg.as_slice())
|
||||
|
|
@ -2670,8 +2666,8 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
|
|||
|
||||
tcx.sess.span_err(span,
|
||||
format!(
|
||||
"missing {nfields, plural, =1{field} other{fields}}: {fields}",
|
||||
nfields = missing_fields.len(),
|
||||
"missing field{}: {fields}",
|
||||
if missing_fields.len() == 1 {""} else {"s"},
|
||||
fields = missing_fields.connect(", ")).as_slice());
|
||||
}
|
||||
}
|
||||
|
|
@ -4021,12 +4017,12 @@ pub fn instantiate_path(fcx: &FnCtxt,
|
|||
if num_supplied_regions != 0 {
|
||||
fcx.ccx.tcx.sess.span_err(
|
||||
span,
|
||||
format!("expected {nexpected, plural, =1{# lifetime parameter} \
|
||||
other{# lifetime parameters}}, \
|
||||
found {nsupplied, plural, =1{# lifetime parameter} \
|
||||
other{# lifetime parameters}}",
|
||||
nexpected = num_expected_regions,
|
||||
nsupplied = num_supplied_regions).as_slice());
|
||||
format!("expected {} lifetime parameter{}, \
|
||||
found {} lifetime parameter{}",
|
||||
num_expected_regions,
|
||||
if num_expected_regions == 1 {""} else {"s"},
|
||||
num_supplied_regions,
|
||||
if num_supplied_regions == 1 {""} else {"s"}).as_slice());
|
||||
}
|
||||
|
||||
fcx.infcx().region_vars_for_defs(span, tpt.generics.region_param_defs.as_slice())
|
||||
|
|
@ -4296,10 +4292,16 @@ pub fn check_bounds_are_used(ccx: &CrateCtxt,
|
|||
|
||||
ty::walk_ty(ty, |t| {
|
||||
match ty::get(t).sty {
|
||||
#[cfg(stage0)]
|
||||
ty::ty_param(param_ty {idx, ..}) => {
|
||||
debug!("Found use of ty param \\#{}", idx);
|
||||
*tps_used.get_mut(idx) = true;
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
ty::ty_param(param_ty {idx, ..}) => {
|
||||
debug!("Found use of ty param #{}", idx);
|
||||
*tps_used.get_mut(idx) = true;
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -386,8 +386,8 @@ fn search_for_vtable(vcx: &VtableContext,
|
|||
// some value of U) with some_trait<T>. This would fail if T
|
||||
// and U weren't compatible.
|
||||
|
||||
debug!("(checking vtable) \\#2 relating trait \
|
||||
ty {} to of_trait_ref {}",
|
||||
debug!("(checking vtable) {}2 relating trait \
|
||||
ty {} to of_trait_ref {}", "#",
|
||||
vcx.infcx.trait_ref_to_str(&*trait_ref),
|
||||
vcx.infcx.trait_ref_to_str(&*of_trait_ref));
|
||||
|
||||
|
|
|
|||
|
|
@ -1323,7 +1323,7 @@ impl<'a> RegionVarBindings<'a> {
|
|||
while changed {
|
||||
changed = false;
|
||||
iteration += 1;
|
||||
debug!("---- {} Iteration \\#{}", tag, iteration);
|
||||
debug!("---- {} Iteration {}{}", "#", tag, iteration);
|
||||
for (constraint, _) in self.constraints.borrow().iter() {
|
||||
let edge_changed = body(constraint);
|
||||
if edge_changed {
|
||||
|
|
|
|||
|
|
@ -61,9 +61,14 @@ impl<V:InferStr> InferStr for Bound<V> {
|
|||
}
|
||||
|
||||
impl<T:InferStr> InferStr for Bounds<T> {
|
||||
#[cfg(stage0)]
|
||||
fn inf_str(&self, cx: &InferCtxt) -> String {
|
||||
format!("\\{{} <: {}\\}", self.lb.inf_str(cx), self.ub.inf_str(cx))
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
fn inf_str(&self, cx: &InferCtxt) -> String {
|
||||
format!("{{{} <: {}}}", self.lb.inf_str(cx), self.ub.inf_str(cx))
|
||||
}
|
||||
}
|
||||
|
||||
impl<V:Vid + ToStr,T:InferStr> InferStr for VarValue<V, T> {
|
||||
|
|
|
|||
|
|
@ -232,11 +232,18 @@ pub struct impl_res {
|
|||
}
|
||||
|
||||
impl Repr for impl_res {
|
||||
#[cfg(stage0)]
|
||||
fn repr(&self, tcx: &ty::ctxt) -> String {
|
||||
format!("impl_res \\{trait_vtables={}, self_vtables={}\\}",
|
||||
self.trait_vtables.repr(tcx),
|
||||
self.self_vtables.repr(tcx))
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
fn repr(&self, tcx: &ty::ctxt) -> String {
|
||||
format!("impl_res {{trait_vtables={}, self_vtables={}}}",
|
||||
self.trait_vtables.repr(tcx),
|
||||
self.self_vtables.repr(tcx))
|
||||
}
|
||||
}
|
||||
|
||||
pub type impl_vtable_map = RefCell<DefIdMap<impl_res>>;
|
||||
|
|
|
|||
|
|
@ -95,9 +95,14 @@ pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
|
|||
|
||||
ReFree(ref fr) => {
|
||||
let prefix = match fr.bound_region {
|
||||
#[cfg(stage0)]
|
||||
BrAnon(idx) => {
|
||||
format!("the anonymous lifetime \\#{} defined on", idx + 1)
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
BrAnon(idx) => {
|
||||
format!("the anonymous lifetime #{} defined on", idx + 1)
|
||||
}
|
||||
BrFresh(_) => "an anonymous lifetime defined on".to_string(),
|
||||
_ => {
|
||||
format!("the lifetime {} as defined on",
|
||||
|
|
@ -375,7 +380,10 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> String {
|
|||
Some(def) => token::get_ident(def.ident).get().to_string(),
|
||||
// This can only happen when a type mismatch error happens and
|
||||
// the actual type has more type parameters than the expected one.
|
||||
None => format!("<generic \\#{}>", id)
|
||||
#[cfg(stage0)]
|
||||
None => format!("<generic \\#{}>", id),
|
||||
#[cfg(not(stage0))]
|
||||
None => format!("<generic #{}>", id),
|
||||
};
|
||||
if !cx.sess.verbose() {
|
||||
ident
|
||||
|
|
@ -729,11 +737,18 @@ impl Repr for ast::DefId {
|
|||
}
|
||||
|
||||
impl Repr for ty::ty_param_bounds_and_ty {
|
||||
#[cfg(stage0)]
|
||||
fn repr(&self, tcx: &ctxt) -> String {
|
||||
format!("ty_param_bounds_and_ty \\{generics: {}, ty: {}\\}",
|
||||
self.generics.repr(tcx),
|
||||
self.ty.repr(tcx))
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
fn repr(&self, tcx: &ctxt) -> String {
|
||||
format!("ty_param_bounds_and_ty {{generics: {}, ty: {}}}",
|
||||
self.generics.repr(tcx),
|
||||
self.ty.repr(tcx))
|
||||
}
|
||||
}
|
||||
|
||||
impl Repr for ty::Generics {
|
||||
|
|
@ -800,12 +815,20 @@ impl Repr for ast::Visibility {
|
|||
}
|
||||
|
||||
impl Repr for ty::BareFnTy {
|
||||
#[cfg(stage0)]
|
||||
fn repr(&self, tcx: &ctxt) -> String {
|
||||
format!("BareFnTy \\{fn_style: {:?}, abi: {}, sig: {}\\}",
|
||||
self.fn_style,
|
||||
self.abi.to_str(),
|
||||
self.sig.repr(tcx))
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
fn repr(&self, tcx: &ctxt) -> String {
|
||||
format!("BareFnTy {{fn_style: {:?}, abi: {}, sig: {}}}",
|
||||
self.fn_style,
|
||||
self.abi.to_str(),
|
||||
self.sig.repr(tcx))
|
||||
}
|
||||
}
|
||||
|
||||
impl Repr for ty::FnSig {
|
||||
|
|
@ -815,12 +838,20 @@ impl Repr for ty::FnSig {
|
|||
}
|
||||
|
||||
impl Repr for typeck::MethodCallee {
|
||||
#[cfg(stage0)]
|
||||
fn repr(&self, tcx: &ctxt) -> String {
|
||||
format!("MethodCallee \\{origin: {}, ty: {}, {}\\}",
|
||||
self.origin.repr(tcx),
|
||||
self.ty.repr(tcx),
|
||||
self.substs.repr(tcx))
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
fn repr(&self, tcx: &ctxt) -> String {
|
||||
format!("MethodCallee {{origin: {}, ty: {}, {}}}",
|
||||
self.origin.repr(tcx),
|
||||
self.ty.repr(tcx),
|
||||
self.substs.repr(tcx))
|
||||
}
|
||||
}
|
||||
|
||||
impl Repr for typeck::MethodOrigin {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue