Skip to content

Commit

Permalink
Auto merge of rust-lang#35469 - jonathandturner:rollup, r=jonathandtu…
Browse files Browse the repository at this point in the history
  • Loading branch information
bors authored Aug 7, 2016
2 parents f5e7a59 + 995eeb0 commit 1744c46
Show file tree
Hide file tree
Showing 67 changed files with 345 additions and 126 deletions.
2 changes: 1 addition & 1 deletion src/libcore/iter/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ pub trait ExactSizeIterator: Iterator {
/// assert_eq!(one_element.next(), None);
/// ```
#[inline]
#[unstable(feature = "exact_size_is_empty", issue = "0")]
#[unstable(feature = "exact_size_is_empty", issue = "35428")]
fn is_empty(&self) -> bool {
self.len() == 0
}
Expand Down
10 changes: 6 additions & 4 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {


fn need_type_info(&self, span: Span, ty: Ty<'tcx>) {
span_err!(self.tcx.sess, span, E0282,
"unable to infer enough type information about `{}`; \
type annotations or generic parameter binding required",
ty);
let mut err = struct_span_err!(self.tcx.sess, span, E0282,
"unable to infer enough type information about `{}`",
ty);
err.note("type annotations or generic parameter binding required");
err.span_label(span, &format!("cannot infer type for `{}`", ty));
err.emit()
}

fn note_obligation_cause<T>(&self,
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
Rvalue::Box(_) => {
self.add(Qualif::NOT_CONST);
if self.mode != Mode::Fn {
span_err!(self.tcx.sess, self.span, E0010,
"allocations are not allowed in {}s", self.mode);
struct_span_err!(self.tcx.sess, self.span, E0010,
"allocations are not allowed in {}s", self.mode)
.span_label(self.span, &format!("allocation not allowed in {}s", self.mode))
.emit();
}
}

Expand Down
46 changes: 29 additions & 17 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,10 +1215,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
type_str: &str,
trait_str: &str,
name: &str) {
span_err!(self.tcx().sess, span, E0223,
"ambiguous associated type; specify the type using the syntax \
`<{} as {}>::{}`",
type_str, trait_str, name);
struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type")
.span_label(span, &format!("ambiguous associated type"))
.note(&format!("specify the type using the syntax `<{} as {}>::{}`",
type_str, trait_str, name))
.emit();

}

// Search for a bound on a type parameter which includes the associated item
Expand Down Expand Up @@ -2095,8 +2097,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {

if !trait_bounds.is_empty() {
let b = &trait_bounds[0];
span_err!(self.tcx().sess, b.trait_ref.path.span, E0225,
"only the builtin traits can be used as closure or object bounds");
let span = b.trait_ref.path.span;
struct_span_err!(self.tcx().sess, span, E0225,
"only the builtin traits can be used as closure or object bounds")
.span_label(span, &format!("non-builtin trait used as bounds"))
.emit();
}

let region_bound =
Expand Down Expand Up @@ -2255,20 +2260,27 @@ fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
} else {
"expected"
};
span_err!(tcx.sess, span, E0243,
"wrong number of type arguments: {} {}, found {}",
expected, required, supplied);
struct_span_err!(tcx.sess, span, E0243, "wrong number of type arguments")
.span_label(
span,
&format!("{} {} type arguments, found {}", expected, required, supplied)
)
.emit();
} else if supplied > accepted {
let expected = if required < accepted {
"expected at most"
let expected = if required == 0 {
"expected no".to_string()
} else if required < accepted {
format!("expected at most {}", accepted)
} else {
"expected"
format!("expected {}", accepted)
};
span_err!(tcx.sess, span, E0244,
"wrong number of type arguments: {} {}, found {}",
expected,
accepted,
supplied);

struct_span_err!(tcx.sess, span, E0244, "wrong number of type arguments")
.span_label(
span,
&format!("{} type arguments, found {}", expected, supplied)
)
.emit();
}
}

Expand Down
21 changes: 11 additions & 10 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
end.span
};

// Note: spacing here is intentional, we want a space before "start" and "end".
span_err!(tcx.sess, span, E0029,
"only char and numeric types are allowed in range patterns\n \
start type: {}\n end type: {}",
self.ty_to_string(lhs_ty),
self.ty_to_string(rhs_ty)
);
struct_span_err!(tcx.sess, span, E0029,
"only char and numeric types are allowed in range patterns")
.span_label(span, &format!("ranges require char or numeric types"))
.note(&format!("start type: {}", self.ty_to_string(lhs_ty)))
.note(&format!("end type: {}", self.ty_to_string(rhs_ty)))
.emit();
return;
}

Expand Down Expand Up @@ -700,9 +699,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
for field in variant.fields
.iter()
.filter(|field| !used_fields.contains_key(&field.name)) {
span_err!(tcx.sess, span, E0027,
"pattern does not mention field `{}`",
field.name);
struct_span_err!(tcx.sess, span, E0027,
"pattern does not mention field `{}`",
field.name)
.span_label(span, &format!("missing field `{}`", field.name))
.emit();
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_typeck/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use rustc::hir;
/// method that is called)
pub fn check_legal_trait_for_method_call(ccx: &CrateCtxt, span: Span, trait_id: DefId) {
if ccx.tcx.lang_items.drop_trait() == Some(trait_id) {
span_err!(ccx.tcx.sess, span, E0040, "explicit use of destructor method");
struct_span_err!(ccx.tcx.sess, span, E0040, "explicit use of destructor method")
.span_label(span, &format!("call to destructor method"))
.emit();
}
}

Expand Down
18 changes: 16 additions & 2 deletions src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,33 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
(&ty::ExplicitSelfCategory::Static,
&ty::ExplicitSelfCategory::Static) => {}
(&ty::ExplicitSelfCategory::Static, _) => {
span_err!(tcx.sess, impl_m_span, E0185,
let mut err = struct_span_err!(tcx.sess, impl_m_span, E0185,
"method `{}` has a `{}` declaration in the impl, \
but not in the trait",
trait_m.name,
impl_m.explicit_self);
err.span_label(impl_m_span, &format!("`{}` used in impl",
impl_m.explicit_self));
if let Some(span) = tcx.map.span_if_local(trait_m.def_id) {
err.span_label(span, &format!("trait declared without `{}`",
impl_m.explicit_self));
}
err.emit();
return;
}
(_, &ty::ExplicitSelfCategory::Static) => {
span_err!(tcx.sess, impl_m_span, E0186,
let mut err = struct_span_err!(tcx.sess, impl_m_span, E0186,
"method `{}` has a `{}` declaration in the trait, \
but not in the impl",
trait_m.name,
trait_m.explicit_self);
err.span_label(impl_m_span, &format!("expected `{}` in impl",
trait_m.explicit_self));
if let Some(span) = tcx.map.span_if_local(trait_m.def_id) {
err.span_label(span, & format!("`{}` used in trait",
trait_m.explicit_self));
}
err.emit();
return;
}
_ => {
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,11 +1136,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
}

if !missing_items.is_empty() {
span_err!(tcx.sess, impl_span, E0046,
struct_span_err!(tcx.sess, impl_span, E0046,
"not all trait items implemented, missing: `{}`",
missing_items.iter()
.map(|name| name.to_string())
.collect::<Vec<_>>().join("`, `"))
.span_label(impl_span, &format!("missing `{}` in implementation",
missing_items.iter()
.map(|name| name.to_string())
.collect::<Vec<_>>().join("`, `"))
).emit();
}

if !invalidated_items.is_empty() {
Expand Down
14 changes: 10 additions & 4 deletions src/librustc_typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,19 @@ impl<'cx, 'gcx, 'tcx> Resolver<'cx, 'gcx, 'tcx> {
if !self.tcx.sess.has_errors() {
match self.reason {
ResolvingExpr(span) => {
span_err!(self.tcx.sess, span, E0101,
"cannot determine a type for this expression: {}", e);
struct_span_err!(
self.tcx.sess, span, E0101,
"cannot determine a type for this expression: {}", e)
.span_label(span, &format!("cannot resolve type of expression"))
.emit();
}

ResolvingLocal(span) => {
span_err!(self.tcx.sess, span, E0102,
"cannot determine a type for this local variable: {}", e);
struct_span_err!(
self.tcx.sess, span, E0102,
"cannot determine a type for this local variable: {}", e)
.span_label(span, &format!("cannot resolve type of variable"))
.emit();
}

ResolvingPattern(span) => {
Expand Down
21 changes: 13 additions & 8 deletions src/librustc_typeck/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,23 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
match param_env.can_type_implement_copy(tcx, self_type, span) {
Ok(()) => {}
Err(CopyImplementationError::InfrigingField(name)) => {
span_err!(tcx.sess, span, E0204,
"the trait `Copy` may not be \
implemented for this type; field \
`{}` does not implement `Copy`",
name)
struct_span_err!(tcx.sess, span, E0204,
"the trait `Copy` may not be implemented for \
this type")
.span_label(span, &format!(
"field `{}` does not implement `Copy`", name)
)
.emit()

}
Err(CopyImplementationError::InfrigingVariant(name)) => {
span_err!(tcx.sess, span, E0205,
struct_span_err!(tcx.sess, span, E0205,
"the trait `Copy` may not be \
implemented for this type; variant \
implemented for this type")
.span_label(span, &format!("variant \
`{}` does not implement `Copy`",
name)
name))
.emit()
}
Err(CopyImplementationError::NotAnAdt) => {
span_err!(tcx.sess, span, E0206,
Expand Down
30 changes: 17 additions & 13 deletions src/librustc_typeck/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ struct OrphanChecker<'cx, 'tcx:'cx> {
impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
fn check_def_id(&self, item: &hir::Item, def_id: DefId) {
if def_id.krate != LOCAL_CRATE {
span_err!(self.tcx.sess, item.span, E0116,
struct_span_err!(self.tcx.sess, item.span, E0116,
"cannot define inherent `impl` for a type outside of the \
crate where the type is defined; define and implement \
a trait or new type instead");
crate where the type is defined")
.span_label(item.span, &format!("impl for type defined outside of crate."))
.span_note(item.span, &format!("define and implement a trait or new type instead"))
.emit();
}
}

Expand Down Expand Up @@ -66,7 +68,7 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
fn check_item(&self, item: &hir::Item) {
let def_id = self.tcx.map.local_def_id(item.id);
match item.node {
hir::ItemImpl(_, _, _, None, _, _) => {
hir::ItemImpl(_, _, _, None, ref ty, _) => {
// For inherent impls, self type must be a nominal type
// defined in this crate.
debug!("coherence2::orphan check: inherent impl {}",
Expand Down Expand Up @@ -209,11 +211,11 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
return;
}
_ => {
struct_span_err!(self.tcx.sess, item.span, E0118,
struct_span_err!(self.tcx.sess, ty.span, E0118,
"no base type found for inherent implementation")
.span_help(item.span,
"either implement a trait on it or create a newtype to wrap it \
instead")
.span_label(ty.span, &format!("impl requires a base type"))
.note(&format!("either implement a trait on it or create a newtype \
to wrap it instead"))
.emit();
return;
}
Expand All @@ -228,12 +230,14 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
match traits::orphan_check(self.tcx, def_id) {
Ok(()) => { }
Err(traits::OrphanCheckErr::NoLocalInputType) => {
span_err!(
struct_span_err!(
self.tcx.sess, item.span, E0117,
"the impl does not reference any \
types defined in this crate; \
only traits defined in the current crate can be \
implemented for arbitrary types");
"only traits defined in the current crate can be \
implemented for arbitrary types")
.span_label(item.span, &format!("impl doesn't use types inside crate"))
.note(&format!("the impl does not reference any \
types defined in this crate"))
.emit();
return;
}
Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => {
Expand Down
16 changes: 11 additions & 5 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,13 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
_substs: Option<&mut Substs<'tcx>>,
_space: Option<ParamSpace>,
span: Span) -> Ty<'tcx> {
span_err!(self.tcx().sess, span, E0121,
"the type placeholder `_` is not allowed within types on item signatures");
struct_span_err!(
self.tcx().sess,
span,
E0121,
"the type placeholder `_` is not allowed within types on item signatures"
).span_label(span, &format!("not allowed in type signatures"))
.emit();
self.tcx().types.err
}

Expand Down Expand Up @@ -770,9 +775,10 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0201,
"duplicate definitions with name `{}`:",
impl_item.name);
span_note!(&mut err, *entry.get(),
"previous definition of `{}` here",
impl_item.name);
err.span_label(*entry.get(),
&format!("previous definition of `{}` here",
impl_item.name));
err.span_label(impl_item.span, &format!("duplicate definition"));
err.emit();
}
Vacant(entry) => {
Expand Down
14 changes: 9 additions & 5 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
match tcx.map.find(main_id) {
Some(hir_map::NodeItem(it)) => {
match it.node {
hir::ItemFn(_, _, _, _, ref ps, _)
if ps.is_parameterized() => {
span_err!(ccx.tcx.sess, main_span, E0131,
"main function is not allowed to have type parameters");
return;
hir::ItemFn(_, _, _, _, ref generics, _) => {
if let Some(gen_span) = generics.span() {
struct_span_err!(ccx.tcx.sess, gen_span, E0131,
"main function is not allowed to have type parameters")
.span_label(gen_span,
&format!("main cannot have type parameters"))
.emit();
return;
}
}
_ => ()
}
Expand Down
9 changes: 9 additions & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ impl NulError {

/// Consumes this error, returning the underlying vector of bytes which
/// generated the error in the first place.
///
/// # Examples
///
/// ```
/// use std::ffi::CString;
///
/// let nul_error = CString::new("foo\0bar").unwrap_err();
/// assert_eq!(nul_error.into_vec(), b"foo\0bar");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_vec(self) -> Vec<u8> { self.1 }
}
Expand Down
Loading

0 comments on commit 1744c46

Please sign in to comment.