Skip to content

Commit

Permalink
Auto merge of #35592 - jonathandturner:rollup, r=jonathandturner
Browse files Browse the repository at this point in the history
Rollup of 23 pull requests

- Successful merges: #35279, #35331, #35358, #35375, #35445, #35448, #35482, #35486, #35505, #35528, #35530, #35532, #35536, #35537, #35541, #35552, #35554, #35555, #35557, #35562, #35565, #35569, #35576
- Failed merges: #35395, #35415, #35563
  • Loading branch information
bors authored Aug 11, 2016
2 parents 11f8805 + d3af9a3 commit 8787a12
Show file tree
Hide file tree
Showing 64 changed files with 543 additions and 376 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ __pycache__/
.project
.settings/
.valgrindrc
.vscode/
/*-*-*-*/
/*-*-*/
/Makefile
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ impl String {
#[inline]
#[unstable(feature = "insert_str",
reason = "recent addition",
issue = "0")]
issue = "35553")]
pub fn insert_str(&mut self, idx: usize, string: &str) {
let len = self.len();
assert!(idx <= len);
Expand Down
45 changes: 37 additions & 8 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,28 @@ macro_rules! try {
})
}

/// Use the `format!` syntax to write data into a buffer.
/// Write formatted data into a buffer
///
/// This macro is typically used with a buffer of `&mut `[`Write`][write].
/// This macro accepts any value with `write_fmt` method as a writer, a format string, and a list
/// of arguments to format.
///
/// `write_fmt` method usually comes from an implementation of [`std::fmt::Write`][fmt_write] or
/// [`std::io::Write`][io_write] traits. These are sometimes called 'writers'.
///
/// Passed arguments will be formatted according to the specified format string and the resulting
/// string will be passed to the writer.
///
/// See [`std::fmt`][fmt] for more information on format syntax.
///
/// Return value is completely dependent on the 'write_fmt' method.
///
/// Common return values are: [`Result`][enum_result], [`io::Result`][type_result]
///
/// [fmt]: ../std/fmt/index.html
/// [write]: ../std/io/trait.Write.html
/// [fmt_write]: ../std/fmt/trait.Write.html
/// [io_write]: ../std/io/trait.Write.html
/// [enum_result]: ../std/result/enum.Result.html
/// [type_result]: ../std/io/type.Result.html
///
/// # Examples
///
Expand All @@ -255,16 +269,31 @@ macro_rules! write {
($dst:expr, $($arg:tt)*) => ($dst.write_fmt(format_args!($($arg)*)))
}

/// Use the `format!` syntax to write data into a buffer, appending a newline.
/// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`)
/// alone (no additional CARRIAGE RETURN (`\r`/`U+000D`).
/// Write formatted data into a buffer, with appending a newline.
///
/// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone
/// (no additional CARRIAGE RETURN (`\r`/`U+000D`).
///
/// This macro is typically used with a buffer of `&mut `[`Write`][write].
/// This macro accepts any value with `write_fmt` method as a writer, a format string, and a list
/// of arguments to format.
///
/// `write_fmt` method usually comes from an implementation of [`std::fmt::Write`][fmt_write] or
/// [`std::io::Write`][io_write] traits. These are sometimes called 'writers'.
///
/// Passed arguments will be formatted according to the specified format string and the resulting
/// string will be passed to the writer.
///
/// See [`std::fmt`][fmt] for more information on format syntax.
///
/// Return value is completely dependent on the 'write_fmt' method.
///
/// Common return values are: [`Result`][enum_result], [`io::Result`][type_result]
///
/// [fmt]: ../std/fmt/index.html
/// [write]: ../std/io/trait.Write.html
/// [fmt_write]: ../std/fmt/trait.Write.html
/// [io_write]: ../std/io/trait.Write.html
/// [enum_result]: ../std/result/enum.Result.html
/// [type_result]: ../std/io/type.Result.html
///
/// # Examples
///
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ impl<T, E> Result<T, E> {
/// ```
/// fn mutate(r: &mut Result<i32, i32>) {
/// match r.as_mut() {
/// Ok(&mut ref mut v) => *v = 42,
/// Err(&mut ref mut e) => *e = 0,
/// Ok(v) => *v = 42,
/// Err(e) => *e = 0,
/// }
/// }
///
Expand Down
8 changes: 5 additions & 3 deletions src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> {
match self.unsafe_context.root {
SafeContext => {
// Report an error.
span_err!(self.tcx.sess, span, E0133,
"{} requires unsafe function or block",
description);
struct_span_err!(
self.tcx.sess, span, E0133,
"{} requires unsafe function or block", description)
.span_label(span, &format!("unsafe call requires unsafe function or block"))
.emit();
}
UnsafeBlock(block_id) => {
// OK, but record this.
Expand Down
12 changes: 8 additions & 4 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let lifetime_j = &lifetimes[j];

if lifetime_i.lifetime.name == lifetime_j.lifetime.name {
span_err!(self.sess, lifetime_j.lifetime.span, E0263,
"lifetime name `{}` declared twice in \
the same scope",
lifetime_j.lifetime.name);
struct_span_err!(self.sess, lifetime_j.lifetime.span, E0263,
"lifetime name `{}` declared twice in the same scope",
lifetime_j.lifetime.name)
.span_label(lifetime_j.lifetime.span,
&format!("declared twice"))
.span_label(lifetime_i.lifetime.span,
&format!("previous declaration here"))
.emit();
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let mut err = struct_span_err!(self.sess, span, E0072,
"recursive type `{}` has infinite size",
self.item_path_str(type_def_id));
err.span_label(span, &format!("recursive type has infinite size"));
err.help(&format!("insert indirection (e.g., a `Box`, `Rc`, or `&`) \
at some point to make `{}` representable",
self.item_path_str(type_def_id)));
Expand All @@ -670,10 +671,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let mut err = match warning_node_id {
Some(_) => None,
None => {
Some(struct_span_err!(
self.sess, span, E0038,
"the trait `{}` cannot be made into an object",
self.item_path_str(trait_def_id)))
let trait_str = self.item_path_str(trait_def_id);
let mut db = struct_span_err!(
self.sess, span, E0038,
"the trait `{}` cannot be made into an object",
trait_str);
db.span_label(span,
&format!("the trait `{}` cannot be made \
into an object", trait_str));
Some(db)
}
};

Expand Down
12 changes: 8 additions & 4 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,12 +760,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
lp: &LoanPath<'tcx>,
assign:
&move_data::Assignment) {
struct_span_err!(
let mut err = struct_span_err!(
self.tcx.sess, span, E0384,
"re-assignment of immutable variable `{}`",
self.loan_path_to_string(lp))
.span_note(assign.span, "prior assignment occurs here")
.emit();
self.loan_path_to_string(lp));
err.span_label(span, &format!("re-assignment of immutable variable"));
if span != assign.span {
err.span_label(assign.span, &format!("first assignment to `{}`",
self.loan_path_to_string(lp)));
}
err.emit();
}

pub fn span_err(&self, s: Span, m: &str) {
Expand Down
17 changes: 9 additions & 8 deletions src/librustc_const_eval/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
.flat_map(|arm| &arm.0)
.map(|pat| vec![wrap_pat(cx, &pat)])
.collect();
let match_span = Span {
lo: ex.span.lo,
hi: scrut.span.hi,
expn_id: ex.span.expn_id
};
check_exhaustive(cx, match_span, &matrix, source);
check_exhaustive(cx, scrut.span, &matrix, source);
},
_ => ()
}
Expand Down Expand Up @@ -1115,9 +1110,15 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,

// x @ Foo(..) is legal, but x @ Foo(y) isn't.
if sub.map_or(false, |p| pat_contains_bindings(&p)) {
span_err!(cx.tcx.sess, p.span, E0007, "cannot bind by-move with sub-bindings");
struct_span_err!(cx.tcx.sess, p.span, E0007,
"cannot bind by-move with sub-bindings")
.span_label(p.span, &format!("binds an already bound by-move value by moving it"))
.emit();
} else if has_guard {
span_err!(cx.tcx.sess, p.span, E0008, "cannot bind by-move into a pattern guard");
struct_span_err!(cx.tcx.sess, p.span, E0008,
"cannot bind by-move into a pattern guard")
.span_label(p.span, &format!("moves value into pattern guard"))
.emit();
} else if by_ref_span.is_some() {
let mut err = struct_span_err!(cx.tcx.sess, p.span, E0009,
"cannot bind by-move and by-ref in the same pattern");
Expand Down
9 changes: 6 additions & 3 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
if !allow {
self.add(Qualif::NOT_CONST);
if self.mode != Mode::Fn {
span_err!(self.tcx.sess, self.span, E0017,
"references in {}s may only refer \
to immutable values", self.mode);
struct_span_err!(self.tcx.sess, self.span, E0017,
"references in {}s may only refer \
to immutable values", self.mode)
.span_label(self.span, &format!("{}s require immutable values",
self.mode))
.emit();
}
}
} else {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl<'a> Visitor for AstValidator<'a> {
E0130,
"patterns aren't allowed in foreign function \
declarations");
err.span_label(span, &format!("pattern not allowed in foreign function"));
if is_recent {
err.span_note(span,
"this is a recent error, see issue #35203 for more details");
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,10 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
struct_span_err!(resolver.session, span, E0432, "{}", msg)
}
ResolutionError::FailedToResolve(msg) => {
struct_span_err!(resolver.session, span, E0433, "failed to resolve. {}", msg)
let mut err = struct_span_err!(resolver.session, span, E0433,
"failed to resolve. {}", msg);
err.span_label(span, &msg);
err
}
ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => {
struct_span_err!(resolver.session,
Expand Down
24 changes: 23 additions & 1 deletion src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use rustc::ty;
use rustc::traits::{self, ProjectionMode};
use rustc::ty::error::ExpectedFound;
use rustc::ty::subst::{self, Subst, Substs, VecPerParamSpace};
use rustc::hir::map::Node;
use rustc::hir::{ImplItemKind, TraitItem_};

use syntax::ast;
use syntax_pos::Span;
Expand Down Expand Up @@ -461,7 +463,7 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
// Compute skolemized form of impl and trait const tys.
let impl_ty = impl_c.ty.subst(tcx, impl_to_skol_substs);
let trait_ty = trait_c.ty.subst(tcx, &trait_to_skol_substs);
let origin = TypeOrigin::Misc(impl_c_span);
let mut origin = TypeOrigin::Misc(impl_c_span);

let err = infcx.commit_if_ok(|_| {
// There is no "body" here, so just pass dummy id.
Expand Down Expand Up @@ -496,11 +498,31 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
debug!("checking associated const for compatibility: impl ty {:?}, trait ty {:?}",
impl_ty,
trait_ty);

// Locate the Span containing just the type of the offending impl
if let Some(impl_trait_node) = tcx.map.get_if_local(impl_c.def_id) {
if let Node::NodeImplItem(impl_trait_item) = impl_trait_node {
if let ImplItemKind::Const(ref ty, _) = impl_trait_item.node {
origin = TypeOrigin::Misc(ty.span);
}
}
}

let mut diag = struct_span_err!(
tcx.sess, origin.span(), E0326,
"implemented const `{}` has an incompatible type for trait",
trait_c.name
);

// Add a label to the Span containing just the type of the item
if let Some(orig_trait_node) = tcx.map.get_if_local(trait_c.def_id) {
if let Node::NodeTraitItem(orig_trait_item) = orig_trait_node {
if let TraitItem_::ConstTraitItem(ref ty, _) = orig_trait_item.node {
diag.span_label(ty.span, &format!("original trait requirement"));
}
}
}

infcx.note_type_err(
&mut diag, origin,
Some(infer::ValuePairs::Types(ExpectedFound {
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_typeck/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &hir::ForeignItem) {
(0, Vec::new(), tcx.mk_nil())
}
op => {
span_err!(tcx.sess, it.span, E0092,
"unrecognized atomic operation function: `{}`", op);
struct_span_err!(tcx.sess, it.span, E0092,
"unrecognized atomic operation function: `{}`", op)
.span_label(it.span, &format!("unrecognized atomic operation"))
.emit();
return;
}
};
Expand Down
26 changes: 18 additions & 8 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,13 +1272,21 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,

// Check for duplicate discriminant values
if let Some(i) = disr_vals.iter().position(|&x| x == current_disr_val) {
let mut err = struct_span_err!(ccx.tcx.sess, v.span, E0081,
"discriminant value `{}` already exists", disr_vals[i]);
let variant_i_node_id = ccx.tcx.map.as_local_node_id(variants[i].did).unwrap();
err.span_label(ccx.tcx.map.span(variant_i_node_id),
&format!("first use of `{}`", disr_vals[i]));
err.span_label(v.span , &format!("enum already has `{}`", disr_vals[i]));
err.emit();
let variant_i = ccx.tcx.map.expect_variant(variant_i_node_id);
let i_span = match variant_i.node.disr_expr {
Some(ref expr) => expr.span,
None => ccx.tcx.map.span(variant_i_node_id)
};
let span = match v.node.disr_expr {
Some(ref expr) => expr.span,
None => v.span
};
struct_span_err!(ccx.tcx.sess, span, E0081,
"discriminant value `{}` already exists", disr_vals[i])
.span_label(i_span, &format!("first use of `{}`", disr_vals[i]))
.span_label(span , &format!("enum already has `{}`", disr_vals[i]))
.emit();
}
disr_vals.push(current_disr_val);
}
Expand Down Expand Up @@ -4640,9 +4648,11 @@ pub fn check_bounds_are_used<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,

for (i, b) in tps_used.iter().enumerate() {
if !*b {
span_err!(ccx.tcx.sess, tps[i].span, E0091,
struct_span_err!(ccx.tcx.sess, tps[i].span, E0091,
"type parameter `{}` is unused",
tps[i].name);
tps[i].name)
.span_label(tps[i].span, &format!("unused type parameter"))
.emit();
}
}
}
9 changes: 6 additions & 3 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,9 +1903,12 @@ fn convert_default_type_parameter<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
for leaf_ty in ty.walk() {
if let ty::TyParam(p) = leaf_ty.sty {
if p.space == space && p.idx >= index {
span_err!(ccx.tcx.sess, path.span, E0128,
"type parameters with a default cannot use \
forward declared identifiers");
struct_span_err!(ccx.tcx.sess, path.span, E0128,
"type parameters with a default cannot use \
forward declared identifiers")
.span_label(path.span, &format!("defaulted type parameters \
cannot be forward declared"))
.emit();

return ccx.tcx.types.err
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ fn require_c_abi_if_variadic(tcx: TyCtxt,
abi: Abi,
span: Span) {
if decl.variadic && abi != Abi::C {
span_err!(tcx.sess, span, E0045,
let mut err = struct_span_err!(tcx.sess, span, E0045,
"variadic function must have C calling convention");
err.span_label(span, &("variadics require C calling conventions").to_string())
.emit();
}
}

Expand Down
Loading

0 comments on commit 8787a12

Please sign in to comment.