diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index ff2b8cdea227..5cdf4ee88c00 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -973,8 +973,8 @@ impl [T] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn binary_search_by(&self, f: F) -> Result - where F: FnMut(&T) -> Ordering + pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result + where F: FnMut(&'a T) -> Ordering { core_slice::SliceExt::binary_search_by(self, f) } @@ -1009,8 +1009,8 @@ impl [T] { /// ``` #[stable(feature = "slice_binary_search_by_key", since = "1.10.0")] #[inline] - pub fn binary_search_by_key(&self, b: &B, f: F) -> Result - where F: FnMut(&T) -> B, + pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result + where F: FnMut(&'a T) -> B, B: Ord { core_slice::SliceExt::binary_search_by_key(self, b, f) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 06952253ef3b..70b514afd035 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1874,6 +1874,27 @@ impl<'a> From for Cow<'a, str> { } } +#[stable(feature = "cow_str_from_iter", since = "1.12.0")] +impl<'a> FromIterator for Cow<'a, str> { + fn from_iter>(it: I) -> Cow<'a, str> { + Cow::Owned(FromIterator::from_iter(it)) + } +} + +#[stable(feature = "cow_str_from_iter", since = "1.12.0")] +impl<'a, 'b> FromIterator<&'b str> for Cow<'a, str> { + fn from_iter>(it: I) -> Cow<'a, str> { + Cow::Owned(FromIterator::from_iter(it)) + } +} + +#[stable(feature = "cow_str_from_iter", since = "1.12.0")] +impl<'a> FromIterator for Cow<'a, str> { + fn from_iter>(it: I) -> Cow<'a, str> { + Cow::Owned(FromIterator::from_iter(it)) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Into> for String { fn into(self) -> Vec { diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 06af200e4783..434084d3af86 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -147,10 +147,13 @@ use clone::Clone; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; use default::Default; -use marker::{Copy, Send, Sync, Sized, Unsize}; +use fmt::{self, Debug, Display}; +use marker::{Copy, PhantomData, Send, Sync, Sized, Unsize}; use ops::{Deref, DerefMut, Drop, FnOnce, CoerceUnsized}; use option::Option; use option::Option::{None, Some}; +use result::Result; +use result::Result::{Ok, Err}; /// A mutable memory location that admits only `Copy` data. /// @@ -347,6 +350,46 @@ pub enum BorrowState { Unused, } +/// An error returned by [`RefCell::try_borrow`](struct.RefCell.html#method.try_borrow). +#[unstable(feature = "try_borrow", issue = "35070")] +pub struct BorrowError<'a, T: 'a + ?Sized> { + marker: PhantomData<&'a RefCell>, +} + +#[unstable(feature = "try_borrow", issue = "35070")] +impl<'a, T: ?Sized> Debug for BorrowError<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("BorrowError").finish() + } +} + +#[unstable(feature = "try_borrow", issue = "35070")] +impl<'a, T: ?Sized> Display for BorrowError<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Display::fmt("already mutably borrowed", f) + } +} + +/// An error returned by [`RefCell::try_borrow_mut`](struct.RefCell.html#method.try_borrow_mut). +#[unstable(feature = "try_borrow", issue = "35070")] +pub struct BorrowMutError<'a, T: 'a + ?Sized> { + marker: PhantomData<&'a RefCell>, +} + +#[unstable(feature = "try_borrow", issue = "35070")] +impl<'a, T: ?Sized> Debug for BorrowMutError<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("BorrowMutError").finish() + } +} + +#[unstable(feature = "try_borrow", issue = "35070")] +impl<'a, T: ?Sized> Display for BorrowMutError<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Display::fmt("already borrowed", f) + } +} + // Values [1, MAX-1] represent the number of `Ref` active // (will not outgrow its range since `usize` is the size of the address space) type BorrowFlag = usize; @@ -432,7 +475,8 @@ impl RefCell { /// /// # Panics /// - /// Panics if the value is currently mutably borrowed. + /// Panics if the value is currently mutably borrowed. For a non-panicking variant, use + /// [`try_borrow`](#method.try_borrow). /// /// # Examples /// @@ -463,12 +507,45 @@ impl RefCell { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn borrow(&self) -> Ref { + self.try_borrow().expect("already mutably borrowed") + } + + /// Immutably borrows the wrapped value, returning an error if the value is currently mutably + /// borrowed. + /// + /// The borrow lasts until the returned `Ref` exits scope. Multiple immutable borrows can be + /// taken out at the same time. + /// + /// This is the non-panicking variant of [`borrow`](#method.borrow). + /// + /// # Examples + /// + /// ``` + /// #![feature(try_borrow)] + /// + /// use std::cell::RefCell; + /// + /// let c = RefCell::new(5); + /// + /// { + /// let m = c.borrow_mut(); + /// assert!(c.try_borrow().is_err()); + /// } + /// + /// { + /// let m = c.borrow(); + /// assert!(c.try_borrow().is_ok()); + /// } + /// ``` + #[unstable(feature = "try_borrow", issue = "35070")] + #[inline] + pub fn try_borrow(&self) -> Result, BorrowError> { match BorrowRef::new(&self.borrow) { - Some(b) => Ref { + Some(b) => Ok(Ref { value: unsafe { &*self.value.get() }, borrow: b, - }, - None => panic!("RefCell already mutably borrowed"), + }), + None => Err(BorrowError { marker: PhantomData }), } } @@ -479,7 +556,8 @@ impl RefCell { /// /// # Panics /// - /// Panics if the value is currently borrowed. + /// Panics if the value is currently borrowed. For a non-panicking variant, use + /// [`try_borrow_mut`](#method.try_borrow_mut). /// /// # Examples /// @@ -511,12 +589,41 @@ impl RefCell { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn borrow_mut(&self) -> RefMut { + self.try_borrow_mut().expect("already borrowed") + } + + /// Mutably borrows the wrapped value, returning an error if the value is currently borrowed. + /// + /// The borrow lasts until the returned `RefMut` exits scope. The value cannot be borrowed + /// while this borrow is active. + /// + /// This is the non-panicking variant of [`borrow_mut`](#method.borrow_mut). + /// + /// # Examples + /// + /// ``` + /// #![feature(try_borrow)] + /// + /// use std::cell::RefCell; + /// + /// let c = RefCell::new(5); + /// + /// { + /// let m = c.borrow(); + /// assert!(c.try_borrow_mut().is_err()); + /// } + /// + /// assert!(c.try_borrow_mut().is_ok()); + /// ``` + #[unstable(feature = "try_borrow", issue = "35070")] + #[inline] + pub fn try_borrow_mut(&self) -> Result, BorrowMutError> { match BorrowRefMut::new(&self.borrow) { - Some(b) => RefMut { + Some(b) => Ok(RefMut { value: unsafe { &mut *self.value.get() }, borrow: b, - }, - None => panic!("RefCell already borrowed"), + }), + None => Err(BorrowMutError { marker: PhantomData }), } } diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index 292d72dd362a..4cbabe3f5eda 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -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 } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index d8a11581c3b6..3141c289e931 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -105,11 +105,11 @@ pub trait SliceExt { fn binary_search(&self, x: &Self::Item) -> Result where Self::Item: Ord; #[stable(feature = "core", since = "1.6.0")] - fn binary_search_by(&self, f: F) -> Result - where F: FnMut(&Self::Item) -> Ordering; + fn binary_search_by<'a, F>(&'a self, f: F) -> Result + where F: FnMut(&'a Self::Item) -> Ordering; #[stable(feature = "slice_binary_search_by_key", since = "1.10.0")] - fn binary_search_by_key(&self, b: &B, f: F) -> Result - where F: FnMut(&Self::Item) -> B, + fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result + where F: FnMut(&'a Self::Item) -> B, B: Ord; #[stable(feature = "core", since = "1.6.0")] fn len(&self) -> usize; @@ -301,8 +301,8 @@ impl SliceExt for [T] { self as *const [T] as *const T } - fn binary_search_by(&self, mut f: F) -> Result where - F: FnMut(&T) -> Ordering + fn binary_search_by<'a, F>(&'a self, mut f: F) -> Result + where F: FnMut(&'a T) -> Ordering { let mut base = 0usize; let mut s = self; @@ -514,8 +514,8 @@ impl SliceExt for [T] { } #[inline] - fn binary_search_by_key(&self, b: &B, mut f: F) -> Result - where F: FnMut(&Self::Item) -> B, + fn binary_search_by_key<'a, B, F>(&'a self, b: &B, mut f: F) -> Result + where F: FnMut(&'a Self::Item) -> B, B: Ord { self.binary_search_by(|k| f(k).cmp(b)) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 67ad887530eb..9950560b13a5 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -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(&self, diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index 2fe4ae627c1d..599e3ec871a8 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -235,7 +235,12 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) { .flat_map(|arm| &arm.0) .map(|pat| vec![wrap_pat(cx, &pat)]) .collect(); - check_exhaustive(cx, ex.span, &matrix, source); + 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); }, _ => () } diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 1d00938fb25e..5455ca62ea46 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -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(); } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index befe32859112..9f1f07004f4a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -3375,7 +3375,11 @@ impl<'a> Resolver<'a> { (true, _) | (_, true) => struct_span_err!(self.session, span, E0260, "{}", msg), _ => match (old_binding.is_import(), binding.is_import()) { (false, false) => struct_span_err!(self.session, span, E0428, "{}", msg), - (true, true) => struct_span_err!(self.session, span, E0252, "{}", msg), + (true, true) => { + let mut e = struct_span_err!(self.session, span, E0252, "{}", msg); + e.span_label(span, &format!("already imported")); + e + }, _ => { let mut e = struct_span_err!(self.session, span, E0255, "{}", msg); e.span_label(span, &format!("`{}` was already imported", name)); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 50ffa52e88ba..b4e9fb5c65bb 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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 @@ -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 = @@ -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(); } } diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index aae6e3ad36df..fe68690d4e97 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -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; } @@ -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(); } } } diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index bd2c05ba66d4..e73c3aa352b5 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -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(); } } diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 9844377d0bd3..b971ae02cd0b 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -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; } _ => { diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 346449d0a513..54521782474f 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -162,26 +162,34 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }, rcvr_ty); - // If the item has the name of a field, give a help note - if let (&ty::TyStruct(def, substs), Some(expr)) = (&rcvr_ty.sty, rcvr_expr) { - if let Some(field) = def.struct_variant().find_field_named(item_name) { - let expr_string = match tcx.sess.codemap().span_to_snippet(expr.span) { - Ok(expr_string) => expr_string, - _ => "s".into() // Default to a generic placeholder for the - // expression when we can't generate a string - // snippet - }; + // If the method name is the name of a field with a function or closure type, + // give a helping note that it has to be called as (x.f)(...). + if let Some(expr) = rcvr_expr { + for (ty, _) in self.autoderef(span, rcvr_ty) { + if let ty::TyStruct(def, substs) = ty.sty { + if let Some(field) = def.struct_variant().find_field_named(item_name) { + let snippet = tcx.sess.codemap().span_to_snippet(expr.span); + let expr_string = match snippet { + Ok(expr_string) => expr_string, + _ => "s".into() // Default to a generic placeholder for the + // expression when we can't generate a + // string snippet + }; - let field_ty = field.ty(tcx, substs); + let field_ty = field.ty(tcx, substs); - if self.is_fn_ty(&field_ty, span) { - err.span_note(span, - &format!("use `({0}.{1})(...)` if you meant to call \ - the function stored in the `{1}` field", - expr_string, item_name)); - } else { - err.span_note(span, &format!("did you mean to write `{0}.{1}`?", - expr_string, item_name)); + if self.is_fn_ty(&field_ty, span) { + err.span_note(span, &format!( + "use `({0}.{1})(...)` if you meant to call the function \ + stored in the `{1}` field", + expr_string, item_name)); + } else { + err.span_note(span, &format!( + "did you mean to write `{0}.{1}`?", + expr_string, item_name)); + } + break; + } } } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 8da061208730..4bb36aa639c5 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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::>().join("`, `")) + .span_label(impl_span, &format!("missing `{}` in implementation", + missing_items.iter() + .map(|name| name.to_string()) + .collect::>().join("`, `")) + ).emit(); } if !invalidated_items.is_empty() { diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 9786132dc537..42893e40024e 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -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) => { diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 2d14b0dacf24..cdf2ca14d4c7 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -311,24 +311,36 @@ 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, - "the trait `Copy` may not be implemented \ - for this type; type is not a structure or \ - enumeration") + let item = tcx.map.expect_item(impl_node_id); + let span = if let ItemImpl(_, _, _, _, ref ty, _) = item.node { + ty.span + } else { + span + }; + + struct_span_err!(tcx.sess, span, E0206, + "the trait `Copy` may not be implemented for this type") + .span_label(span, &format!("type is not a structure or enumeration")) + .emit(); } Err(CopyImplementationError::HasDestructor) => { span_err!(tcx.sess, span, E0184, diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 15d4026254fa..e426f0cb643b 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -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(); } } @@ -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 {}", @@ -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; } @@ -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)) => { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 92b91028b98b..9b1a6c78335f 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -367,8 +367,13 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> { _substs: Option<&mut Substs<'tcx>>, _space: Option, 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 } @@ -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) => { diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 6f0892cdcdf1..65e00705121a 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -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; + } } _ => () } diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 1459420cdc00..914599271aca 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -49,6 +49,7 @@ use any::TypeId; use boxed::Box; +use cell; use char; use fmt::{self, Debug, Display}; use marker::{Send, Sync, Reflect}; @@ -289,6 +290,20 @@ impl Error for fmt::Error { } } +#[unstable(feature = "try_borrow", issue = "35070")] +impl<'a, T: ?Sized + Reflect> Error for cell::BorrowError<'a, T> { + fn description(&self) -> &str { + "already mutably borrowed" + } +} + +#[unstable(feature = "try_borrow", issue = "35070")] +impl<'a, T: ?Sized + Reflect> Error for cell::BorrowMutError<'a, T> { + fn description(&self) -> &str { + "already borrowed" + } +} + // copied from any.rs impl Error + 'static { /// Returns true if the boxed type is the same as `T` diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index f800a6e228e9..e0501f9cc61d 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -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 { self.1 } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 865d067cdb6d..c6272012d66d 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -269,6 +269,7 @@ #![feature(str_utf16)] #![feature(test, rustc_private)] #![feature(thread_local)] +#![feature(try_borrow)] #![feature(try_from)] #![feature(unboxed_closures)] #![feature(unicode)] diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 4c3558f91f5f..9c57f25dfcce 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -21,6 +21,7 @@ use fmt; use io; use iter; use libc::{self, c_int, c_char, c_void}; +use marker::PhantomData; use mem; use memchr; use path::{self, PathBuf}; @@ -37,6 +38,7 @@ static ENV_LOCK: Mutex = Mutex::new(); extern { + #[cfg(not(target_os = "dragonfly"))] #[cfg_attr(any(target_os = "linux", target_os = "emscripten"), link_name = "__errno_location")] #[cfg_attr(any(target_os = "bitrig", @@ -304,7 +306,7 @@ pub fn current_exe() -> io::Result { pub struct Args { iter: vec::IntoIter, - _dont_send_or_sync_me: *mut (), + _dont_send_or_sync_me: PhantomData<*mut ()>, } impl Iterator for Args { @@ -342,7 +344,7 @@ pub fn args() -> Args { }; Args { iter: vec.into_iter(), - _dont_send_or_sync_me: ptr::null_mut(), + _dont_send_or_sync_me: PhantomData, } } @@ -399,7 +401,7 @@ pub fn args() -> Args { } } - Args { iter: res.into_iter(), _dont_send_or_sync_me: ptr::null_mut() } + Args { iter: res.into_iter(), _dont_send_or_sync_me: PhantomData } } #[cfg(any(target_os = "linux", @@ -418,12 +420,12 @@ pub fn args() -> Args { let v: Vec = bytes.into_iter().map(|v| { OsStringExt::from_vec(v) }).collect(); - Args { iter: v.into_iter(), _dont_send_or_sync_me: ptr::null_mut() } + Args { iter: v.into_iter(), _dont_send_or_sync_me: PhantomData } } pub struct Env { iter: vec::IntoIter<(OsString, OsString)>, - _dont_send_or_sync_me: *mut (), + _dont_send_or_sync_me: PhantomData<*mut ()>, } impl Iterator for Env { @@ -464,7 +466,7 @@ pub fn env() -> Env { } let ret = Env { iter: result.into_iter(), - _dont_send_or_sync_me: ptr::null_mut(), + _dont_send_or_sync_me: PhantomData, }; ENV_LOCK.unlock(); return ret diff --git a/src/test/compile-fail/E0010.rs b/src/test/compile-fail/E0010.rs index 9ae9e795466d..8a666168c86f 100644 --- a/src/test/compile-fail/E0010.rs +++ b/src/test/compile-fail/E0010.rs @@ -11,5 +11,6 @@ #![feature(box_syntax)] const CON : Box = box 0; //~ ERROR E0010 + //~| NOTE allocation not allowed in fn main() {} diff --git a/src/test/compile-fail/E0027.rs b/src/test/compile-fail/E0027.rs index b2f20442b77a..ca496a24701f 100644 --- a/src/test/compile-fail/E0027.rs +++ b/src/test/compile-fail/E0027.rs @@ -17,6 +17,8 @@ fn main() { let d = Dog { name: "Rusty".to_string(), age: 8 }; match d { - Dog { age: x } => {} //~ ERROR E0027 + Dog { age: x } => {} + //~^ ERROR pattern does not mention field `name` + //~| NOTE missing field `name` } } diff --git a/src/test/compile-fail/E0029.rs b/src/test/compile-fail/E0029.rs index 9cbdec995205..ec84e2a3f8a3 100644 --- a/src/test/compile-fail/E0029.rs +++ b/src/test/compile-fail/E0029.rs @@ -12,7 +12,11 @@ fn main() { let s = "hoho"; match s { - "hello" ... "world" => {} //~ ERROR E0029 + "hello" ... "world" => {} + //~^ ERROR only char and numeric types are allowed in range patterns + //~| NOTE ranges require char or numeric types + //~| NOTE start type: &'static str + //~| NOTE end type: &'static str _ => {} } } diff --git a/src/test/compile-fail/E0040.rs b/src/test/compile-fail/E0040.rs index f998778a50d6..80ff57c36359 100644 --- a/src/test/compile-fail/E0040.rs +++ b/src/test/compile-fail/E0040.rs @@ -20,5 +20,7 @@ impl Drop for Foo { fn main() { let mut x = Foo { x: -7 }; - x.drop(); //~ ERROR E0040 + x.drop(); + //~^ ERROR E0040 + //~| NOTE call to destructor method } diff --git a/src/test/compile-fail/E0046.rs b/src/test/compile-fail/E0046.rs index 63bd0a5ca285..a8b56b2b9ab3 100644 --- a/src/test/compile-fail/E0046.rs +++ b/src/test/compile-fail/E0046.rs @@ -14,7 +14,9 @@ trait Foo { struct Bar; -impl Foo for Bar {} //~ ERROR E0046 +impl Foo for Bar {} +//~^ ERROR E0046 +//~| NOTE missing `foo` in implementation fn main() { } diff --git a/src/test/compile-fail/E0101.rs b/src/test/compile-fail/E0101.rs index 7651626d44f8..0005da048e4a 100644 --- a/src/test/compile-fail/E0101.rs +++ b/src/test/compile-fail/E0101.rs @@ -9,5 +9,7 @@ // except according to those terms. fn main() { - let x = |_| {}; //~ ERROR E0101 + let x = |_| {}; + //~^ ERROR E0101 + //~| NOTE cannot resolve type of expression } diff --git a/src/test/compile-fail/E0102.rs b/src/test/compile-fail/E0102.rs index c4ddbab3e861..1d64798bb838 100644 --- a/src/test/compile-fail/E0102.rs +++ b/src/test/compile-fail/E0102.rs @@ -9,5 +9,7 @@ // except according to those terms. fn main() { - let x = []; //~ ERROR E0102 + let x = []; + //~^ ERROR E0102 + //~| NOTE cannot resolve type of variable } diff --git a/src/test/compile-fail/E0116.rs b/src/test/compile-fail/E0116.rs index 4020aa9475aa..f885241eec4c 100644 --- a/src/test/compile-fail/E0116.rs +++ b/src/test/compile-fail/E0116.rs @@ -8,7 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -impl Vec {} //~ ERROR E0116 +impl Vec {} +//~^ ERROR E0116 +//~| NOTE impl for type defined outside of crate. +//~| NOTE define and implement a trait or new type instead fn main() { } diff --git a/src/test/compile-fail/E0117.rs b/src/test/compile-fail/E0117.rs index 16d713bba92a..e9375e673253 100644 --- a/src/test/compile-fail/E0117.rs +++ b/src/test/compile-fail/E0117.rs @@ -9,6 +9,8 @@ // except according to those terms. impl Drop for u32 {} //~ ERROR E0117 +//~^ NOTE impl doesn't use types inside crate +//~| NOTE the impl does not reference any types defined in this crate fn main() { } diff --git a/src/test/compile-fail/E0118.rs b/src/test/compile-fail/E0118.rs index d37ff34b861f..3fc478f1e403 100644 --- a/src/test/compile-fail/E0118.rs +++ b/src/test/compile-fail/E0118.rs @@ -9,6 +9,8 @@ // except according to those terms. impl (u8, u8) { //~ ERROR E0118 +//~^ NOTE impl requires a base type +//~| NOTE either implement a trait on it or create a newtype to wrap it instead fn get_state(&self) -> String { String::new() } diff --git a/src/test/compile-fail/E0131.rs b/src/test/compile-fail/E0131.rs index aa11577ccdf1..e6e924e2d966 100644 --- a/src/test/compile-fail/E0131.rs +++ b/src/test/compile-fail/E0131.rs @@ -8,5 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn main() { //~ ERROR E0131 +fn main() { + //~^ ERROR E0131 + //~| NOTE main cannot have type parameters } diff --git a/src/test/compile-fail/E0185.rs b/src/test/compile-fail/E0185.rs index 0e33687a84df..be54c3754ea1 100644 --- a/src/test/compile-fail/E0185.rs +++ b/src/test/compile-fail/E0185.rs @@ -9,13 +9,14 @@ // except according to those terms. trait Foo { - fn foo(); + fn foo(); //~ trait declared without `&self` } struct Bar; impl Foo for Bar { fn foo(&self) {} //~ ERROR E0185 + //~^ `&self` used in impl } fn main() { diff --git a/src/test/compile-fail/E0186.rs b/src/test/compile-fail/E0186.rs index aa0a38bedcb5..55a3490cac4a 100644 --- a/src/test/compile-fail/E0186.rs +++ b/src/test/compile-fail/E0186.rs @@ -9,13 +9,14 @@ // except according to those terms. trait Foo { - fn foo(&self); + fn foo(&self); //~ `&self` used in trait } struct Bar; impl Foo for Bar { fn foo() {} //~ ERROR E0186 + //~^ expected `&self` in impl } fn main() { diff --git a/src/test/compile-fail/E0204.rs b/src/test/compile-fail/E0204.rs index 2fa2afa12eb4..0f108a17c95d 100644 --- a/src/test/compile-fail/E0204.rs +++ b/src/test/compile-fail/E0204.rs @@ -12,9 +12,14 @@ struct Foo { foo: Vec, } -impl Copy for Foo { } //~ ERROR E0204 +impl Copy for Foo { } +//~^ ERROR E0204 +//~| NOTE field `foo` does not implement `Copy` -#[derive(Copy)] //~ ERROR E0204 +#[derive(Copy)] +//~^ ERROR E0204 +//~| NOTE field `ty` does not implement `Copy` +//~| NOTE in this expansion of #[derive(Copy)] struct Foo2<'a> { ty: &'a mut bool, } diff --git a/src/test/compile-fail/E0205.rs b/src/test/compile-fail/E0205.rs index e4781bba08aa..37ac57af524a 100644 --- a/src/test/compile-fail/E0205.rs +++ b/src/test/compile-fail/E0205.rs @@ -13,9 +13,14 @@ enum Foo { Baz, } -impl Copy for Foo { } //~ ERROR E0205 +impl Copy for Foo { } +//~^ ERROR E0205 +//~| NOTE variant `Bar` does not implement `Copy` -#[derive(Copy)] //~ ERROR E0205 +#[derive(Copy)] +//~^ ERROR E0205 +//~| NOTE variant `Bar` does not implement `Copy` +//~| NOTE in this expansion of #[derive(Copy)] enum Foo2<'a> { Bar(&'a mut bool), Baz, diff --git a/src/test/compile-fail/E0206.rs b/src/test/compile-fail/E0206.rs index 31b01da3d75b..888e42ed3a18 100644 --- a/src/test/compile-fail/E0206.rs +++ b/src/test/compile-fail/E0206.rs @@ -10,13 +10,19 @@ type Foo = i32; -impl Copy for Foo { } //~ ERROR E0206 - //~^ ERROR E0117 +impl Copy for Foo { } +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration +//~| ERROR only traits defined in the current crate can be implemented for arbitrary types +//~| NOTE impl doesn't use types inside crate +//~| NOTE the impl does not reference any types defined in this crate #[derive(Copy, Clone)] struct Bar; -impl Copy for &'static Bar { } //~ ERROR E0206 +impl Copy for &'static Bar { } +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration fn main() { } diff --git a/src/test/compile-fail/E0223.rs b/src/test/compile-fail/E0223.rs index bbf7d762ef00..56057b372599 100644 --- a/src/test/compile-fail/E0223.rs +++ b/src/test/compile-fail/E0223.rs @@ -11,5 +11,8 @@ trait MyTrait { type X; } fn main() { - let foo: MyTrait::X; //~ ERROR E0223 + let foo: MyTrait::X; + //~^ ERROR ambiguous associated type + //~| NOTE ambiguous associated type + //~| NOTE specify the type using the syntax `::X` } diff --git a/src/test/compile-fail/E0225.rs b/src/test/compile-fail/E0225.rs index 190350c5a557..b013788ceff8 100644 --- a/src/test/compile-fail/E0225.rs +++ b/src/test/compile-fail/E0225.rs @@ -9,5 +9,7 @@ // except according to those terms. fn main() { - let _: Box; //~ ERROR E0225 + let _: Box; + //~^ ERROR only the builtin traits can be used as closure or object bounds [E0225] + //~| NOTE non-builtin trait used as bounds } diff --git a/src/test/compile-fail/E0243.rs b/src/test/compile-fail/E0243.rs index 8cc245c10cbe..77c9856c261f 100644 --- a/src/test/compile-fail/E0243.rs +++ b/src/test/compile-fail/E0243.rs @@ -9,7 +9,9 @@ // except according to those terms. struct Foo { x: T } -struct Bar { x: Foo } //~ ERROR E0243 +struct Bar { x: Foo } + //~^ ERROR E0243 + //~| NOTE expected 1 type arguments, found 0 fn main() { } diff --git a/src/test/compile-fail/E0244.rs b/src/test/compile-fail/E0244.rs index 4c5744710929..5678a7fd450d 100644 --- a/src/test/compile-fail/E0244.rs +++ b/src/test/compile-fail/E0244.rs @@ -9,7 +9,10 @@ // except according to those terms. struct Foo { x: bool } -struct Bar { x: Foo } //~ ERROR E0244 +struct Bar { x: Foo } + //~^ ERROR E0244 + //~| NOTE expected no type arguments, found 2 + fn main() { } diff --git a/src/test/compile-fail/associated-types-in-ambiguous-context.rs b/src/test/compile-fail/associated-types-in-ambiguous-context.rs index becbc27138b7..ff886e63dc59 100644 --- a/src/test/compile-fail/associated-types-in-ambiguous-context.rs +++ b/src/test/compile-fail/associated-types-in-ambiguous-context.rs @@ -15,15 +15,21 @@ trait Get { fn get(x: T, y: U) -> Get::Value {} //~^ ERROR ambiguous associated type +//~| NOTE ambiguous associated type +//~| NOTE specify the type using the syntax `::Value` trait Grab { type Value; fn grab(&self) -> Grab::Value; //~^ ERROR ambiguous associated type + //~| NOTE ambiguous associated type + //~| NOTE specify the type using the syntax `::Value` } type X = std::ops::Deref::Target; //~^ ERROR ambiguous associated type +//~| NOTE ambiguous associated type +//~| NOTE specify the type using the syntax `::Target` fn main() { } diff --git a/src/test/compile-fail/coherence-impls-copy.rs b/src/test/compile-fail/coherence-impls-copy.rs index 9c210c132a31..f686a146042c 100644 --- a/src/test/compile-fail/coherence-impls-copy.rs +++ b/src/test/compile-fail/coherence-impls-copy.rs @@ -27,23 +27,34 @@ impl Clone for TestE { fn clone(&self) -> Self { *self } } impl Copy for MyType {} impl Copy for &'static mut MyType {} -//~^ ERROR E0206 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration impl Clone for MyType { fn clone(&self) -> Self { *self } } impl Copy for (MyType, MyType) {} -//~^ ERROR E0206 -//~| ERROR E0117 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration +//~| ERROR only traits defined in the current crate can be implemented for arbitrary types +//~| NOTE impl doesn't use types inside crate +//~| NOTE the impl does not reference any types defined in this crate impl Copy for &'static NotSync {} -//~^ ERROR E0206 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration impl Copy for [MyType] {} -//~^ ERROR E0206 -//~| ERROR E0117 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration +//~| ERROR only traits defined in the current crate can be implemented for arbitrary types +//~| NOTE impl doesn't use types inside crate +//~| NOTE the impl does not reference any types defined in this crate impl Copy for &'static [NotSync] {} -//~^ ERROR E0206 -//~| ERROR E0117 +//~^ ERROR the trait `Copy` may not be implemented for this type +//~| NOTE type is not a structure or enumeration +//~| ERROR only traits defined in the current crate can be implemented for arbitrary types +//~| NOTE impl doesn't use types inside crate +//~| NOTE the impl does not reference any types defined in this crate fn main() { } diff --git a/src/test/compile-fail/double-import.rs b/src/test/compile-fail/double-import.rs index 7b915647884f..bd190a6df8e3 100644 --- a/src/test/compile-fail/double-import.rs +++ b/src/test/compile-fail/double-import.rs @@ -7,8 +7,6 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(no_core)] -#![no_core] // This tests that conflicting imports shows both `use` lines // when reporting the error. @@ -23,5 +21,6 @@ mod sub2 { use sub1::foo; //~ NOTE previous import of `foo` here use sub2::foo; //~ ERROR a value named `foo` has already been imported in this module [E0252] + //~| NOTE already imported fn main() {} diff --git a/src/test/compile-fail/generic-type-less-params-with-defaults.rs b/src/test/compile-fail/generic-type-less-params-with-defaults.rs index 37737fda4749..d9ac715fa954 100644 --- a/src/test/compile-fail/generic-type-less-params-with-defaults.rs +++ b/src/test/compile-fail/generic-type-less-params-with-defaults.rs @@ -16,5 +16,7 @@ struct Vec( marker::PhantomData<(T,A)>); fn main() { - let _: Vec; //~ ERROR wrong number of type arguments: expected at least 1, found 0 + let _: Vec; + //~^ ERROR E0243 + //~| NOTE expected at least 1 type arguments, found 0 } diff --git a/src/test/compile-fail/generic-type-more-params-with-defaults.rs b/src/test/compile-fail/generic-type-more-params-with-defaults.rs index ad7e4f190c5b..8f733ddfce18 100644 --- a/src/test/compile-fail/generic-type-more-params-with-defaults.rs +++ b/src/test/compile-fail/generic-type-more-params-with-defaults.rs @@ -17,5 +17,6 @@ struct Vec( fn main() { let _: Vec; - //~^ ERROR wrong number of type arguments: expected at most 2, found 3 + //~^ ERROR E0244 + //~| NOTE expected at most 2 type arguments, found 3 } diff --git a/src/test/compile-fail/impl-duplicate-methods.rs b/src/test/compile-fail/impl-duplicate-methods.rs index 981eddc9dd96..f6e9ab2d614b 100644 --- a/src/test/compile-fail/impl-duplicate-methods.rs +++ b/src/test/compile-fail/impl-duplicate-methods.rs @@ -12,7 +12,9 @@ struct Foo; impl Foo { fn orange(&self) {} //~ NOTE previous definition of `orange` here - fn orange(&self) {} //~ ERROR duplicate definitions with name `orange` + fn orange(&self) {} + //~^ ERROR duplicate definition + //~| NOTE duplicate definition } fn main() {} diff --git a/src/test/compile-fail/impl-wrong-item-for-trait.rs b/src/test/compile-fail/impl-wrong-item-for-trait.rs index 6452e50d0893..e0ea1a4cac58 100644 --- a/src/test/compile-fail/impl-wrong-item-for-trait.rs +++ b/src/test/compile-fail/impl-wrong-item-for-trait.rs @@ -21,6 +21,7 @@ pub struct FooConstForMethod; impl Foo for FooConstForMethod { //~^ ERROR E0046 + //~| NOTE missing `bar` in implementation const bar: u64 = 1; //~^ ERROR E0323 //~| NOTE does not match trait @@ -31,6 +32,7 @@ pub struct FooMethodForConst; impl Foo for FooMethodForConst { //~^ ERROR E0046 + //~| NOTE missing `MY_CONST` in implementation fn bar(&self) {} fn MY_CONST() {} //~^ ERROR E0324 @@ -41,6 +43,7 @@ pub struct FooTypeForMethod; impl Foo for FooTypeForMethod { //~^ ERROR E0046 + //~| NOTE missing `bar` in implementation type bar = u64; //~^ ERROR E0325 //~| NOTE does not match trait diff --git a/src/test/compile-fail/issue-12187-1.rs b/src/test/compile-fail/issue-12187-1.rs index 5322966ae2ea..001e4b51bebc 100644 --- a/src/test/compile-fail/issue-12187-1.rs +++ b/src/test/compile-fail/issue-12187-1.rs @@ -14,5 +14,7 @@ fn new() -> &'static T { fn main() { let &v = new(); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/issue-12187-2.rs b/src/test/compile-fail/issue-12187-2.rs index dabc0acba370..7cbee402b368 100644 --- a/src/test/compile-fail/issue-12187-2.rs +++ b/src/test/compile-fail/issue-12187-2.rs @@ -14,5 +14,7 @@ fn new<'r, T>() -> &'r T { fn main() { let &v = new(); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/issue-14092.rs b/src/test/compile-fail/issue-14092.rs index c87dcb8ae79b..dd02fa7ac151 100644 --- a/src/test/compile-fail/issue-14092.rs +++ b/src/test/compile-fail/issue-14092.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn fn1(0: Box) {} //~ ERROR: wrong number of type arguments: expected 1, found 0 +fn fn1(0: Box) {} + //~^ ERROR E0243 + //~| NOTE expected 1 type arguments, found 0 fn main() {} diff --git a/src/test/compile-fail/issue-23024.rs b/src/test/compile-fail/issue-23024.rs index df2a70160f86..e266f004317e 100644 --- a/src/test/compile-fail/issue-23024.rs +++ b/src/test/compile-fail/issue-23024.rs @@ -18,6 +18,6 @@ fn main() vfnfer.push(box h); println!("{:?}",(vfnfer[0] as Fn)(3)); //~^ ERROR the precise format of `Fn`-family traits' - //~| ERROR wrong number of type arguments: expected 1, found 0 + //~| ERROR E0243 //~| ERROR the value of the associated type `Output` (from the trait `std::ops::FnOnce`) } diff --git a/src/test/compile-fail/issue-23041.rs b/src/test/compile-fail/issue-23041.rs index 1a9bb4c29f3e..1be082ba9bbb 100644 --- a/src/test/compile-fail/issue-23041.rs +++ b/src/test/compile-fail/issue-23041.rs @@ -14,4 +14,6 @@ fn main() fn bar(x:i32) ->i32 { 3*x }; let b:Box = Box::new(bar as fn(_)->_); b.downcast_ref::_>(); //~ ERROR E0282 + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding required } diff --git a/src/test/compile-fail/issue-23729.rs b/src/test/compile-fail/issue-23729.rs index f98cf6575d6e..b1047ce18ccc 100644 --- a/src/test/compile-fail/issue-23729.rs +++ b/src/test/compile-fail/issue-23729.rs @@ -18,7 +18,8 @@ fn main() { } impl Iterator for Recurrence { - //~^ ERROR not all trait items implemented, missing: `Item` [E0046] + //~^ ERROR E0046 + //~| NOTE missing `Item` in implementation #[inline] fn next(&mut self) -> Option { if self.pos < 2 { diff --git a/src/test/compile-fail/issue-23827.rs b/src/test/compile-fail/issue-23827.rs index 6c42c88bee6d..2062e2373129 100644 --- a/src/test/compile-fail/issue-23827.rs +++ b/src/test/compile-fail/issue-23827.rs @@ -34,7 +34,8 @@ impl FnMut<(C,)> for Prototype { } impl FnOnce<(C,)> for Prototype { - //~^ ERROR not all trait items implemented, missing: `Output` [E0046] + //~^ ERROR E0046 + //~| NOTE missing `Output` in implementation extern "rust-call" fn call_once(self, (comp,): (C,)) -> Prototype { Fn::call(&self, (comp,)) } diff --git a/src/test/compile-fail/issue-24356.rs b/src/test/compile-fail/issue-24356.rs index ede81bea32ae..d39fd539dceb 100644 --- a/src/test/compile-fail/issue-24356.rs +++ b/src/test/compile-fail/issue-24356.rs @@ -28,7 +28,8 @@ fn main() { // Causes ICE impl Deref for Thing { - //~^ ERROR not all trait items implemented, missing: `Target` [E0046] + //~^ ERROR E0046 + //~| NOTE missing `Target` in implementation fn deref(&self) -> i8 { self.0 } } diff --git a/src/test/compile-fail/issue-26886.rs b/src/test/compile-fail/issue-26886.rs index c849716f21a3..46e82363c8bd 100644 --- a/src/test/compile-fail/issue-26886.rs +++ b/src/test/compile-fail/issue-26886.rs @@ -11,7 +11,9 @@ use std::sync::{self, Arc}; //~ NOTE previous import //~^ NOTE previous import use std::sync::Arc; //~ ERROR a type named + //~| NOTE already imported use std::sync; //~ ERROR a module named + //~| NOTE already imported fn main() { } diff --git a/src/test/compile-fail/issue-27340.rs b/src/test/compile-fail/issue-27340.rs index 6a97ae82ddf3..ce3fa487d4e0 100644 --- a/src/test/compile-fail/issue-27340.rs +++ b/src/test/compile-fail/issue-27340.rs @@ -10,7 +10,7 @@ struct Foo; #[derive(Copy, Clone)] -//~^ ERROR the trait `Copy` may not be implemented for this type; field `0` does not implement +//~^ ERROR the trait `Copy` may not be implemented for this type struct Bar(Foo); fn main() {} diff --git a/src/test/compile-fail/issue-33784.rs b/src/test/compile-fail/issue-33784.rs new file mode 100644 index 000000000000..4229be29473d --- /dev/null +++ b/src/test/compile-fail/issue-33784.rs @@ -0,0 +1,46 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::ops::Deref; + +struct Obj where F: FnMut() -> u32 { + fn_ptr: fn() -> (), + closure: F, +} + +struct C { + c_fn_ptr: fn() -> (), +} + +struct D(C); + +impl Deref for D { + type Target = C; + fn deref(&self) -> &C { + &self.0 + } +} + + +fn empty() {} + +fn main() { + let o = Obj { fn_ptr: empty, closure: || 42 }; + let p = &o; + p.closure(); //~ ERROR no method named `closure` found + //~^ NOTE use `(p.closure)(...)` if you meant to call the function stored in the `closure` field + let q = &p; + q.fn_ptr(); //~ ERROR no method named `fn_ptr` found + //~^ NOTE use `(q.fn_ptr)(...)` if you meant to call the function stored in the `fn_ptr` field + let r = D(C { c_fn_ptr: empty }); + let s = &r; + s.c_fn_ptr(); //~ ERROR no method named `c_fn_ptr` found + //~^ NOTE use `(s.c_fn_ptr)(...)` if you meant to call the function stored in the `c_fn_ptr` +} diff --git a/src/test/compile-fail/issue-34209.rs b/src/test/compile-fail/issue-34209.rs index 6fae18dec10a..5e3b777cc0b6 100644 --- a/src/test/compile-fail/issue-34209.rs +++ b/src/test/compile-fail/issue-34209.rs @@ -15,7 +15,9 @@ enum S { fn bug(l: S) { match l { S::B{ } => { }, - //~^ ERROR ambiguous associated type; specify the type using the syntax `::B` + //~^ ERROR ambiguous associated type + //~| NOTE ambiguous associated type + //~| NOTE specify the type using the syntax `::B` } } diff --git a/src/test/compile-fail/issue-5062.rs b/src/test/compile-fail/issue-5062.rs index 392d38a6144f..f5aa4fadbed8 100644 --- a/src/test/compile-fail/issue-5062.rs +++ b/src/test/compile-fail/issue-5062.rs @@ -9,4 +9,4 @@ // except according to those terms. fn main() { format!("{:?}", None); } - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] diff --git a/src/test/compile-fail/issue-6458-2.rs b/src/test/compile-fail/issue-6458-2.rs index acf1d766b6a1..71f280545791 100644 --- a/src/test/compile-fail/issue-6458-2.rs +++ b/src/test/compile-fail/issue-6458-2.rs @@ -11,5 +11,5 @@ fn main() { // Unconstrained type: format!("{:?}", None); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] } diff --git a/src/test/compile-fail/issue-6458-3.rs b/src/test/compile-fail/issue-6458-3.rs index 3f81e51efe2e..e397805565bb 100644 --- a/src/test/compile-fail/issue-6458-3.rs +++ b/src/test/compile-fail/issue-6458-3.rs @@ -12,5 +12,7 @@ use std::mem; fn main() { mem::transmute(0); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/issue-6458-4.rs b/src/test/compile-fail/issue-6458-4.rs index 7f408be9c02d..c3f3a718ad0e 100644 --- a/src/test/compile-fail/issue-6458-4.rs +++ b/src/test/compile-fail/issue-6458-4.rs @@ -10,7 +10,9 @@ fn foo(b: bool) -> Result { Err("bar".to_string()); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } fn main() { diff --git a/src/test/compile-fail/issue-6458.rs b/src/test/compile-fail/issue-6458.rs index c1f9dd6a4b89..a64522a0e5b7 100644 --- a/src/test/compile-fail/issue-6458.rs +++ b/src/test/compile-fail/issue-6458.rs @@ -17,7 +17,9 @@ pub fn foo(_: TypeWithState) {} pub fn bar() { foo(TypeWithState(marker::PhantomData)); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } fn main() { diff --git a/src/test/compile-fail/issue-7813.rs b/src/test/compile-fail/issue-7813.rs index 327fb6adf1d5..e3cb1d0c7daa 100644 --- a/src/test/compile-fail/issue-7813.rs +++ b/src/test/compile-fail/issue-7813.rs @@ -10,5 +10,7 @@ fn main() { let v = &[]; - let it = v.iter(); //~ ERROR type annotations or generic parameter binding required + let it = v.iter(); //~ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs b/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs index 59d75c5a787a..4f86909765ef 100644 --- a/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs +++ b/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs @@ -32,7 +32,7 @@ impl foo for Vec { fn m1() { // we couldn't infer the type of the vector just based on calling foo()... let mut x = Vec::new(); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] x.foo(); } diff --git a/src/test/compile-fail/qualified-path-params-2.rs b/src/test/compile-fail/qualified-path-params-2.rs index 5c661bfcdc0c..e685ebc27209 100644 --- a/src/test/compile-fail/qualified-path-params-2.rs +++ b/src/test/compile-fail/qualified-path-params-2.rs @@ -25,7 +25,11 @@ impl S { fn f() {} } -type A = ::A::f; //~ ERROR type parameters are not allowed on this type -//~^ ERROR ambiguous associated type; specify the type using the syntax `<::A as Trait>::f` +type A = ::A::f; +//~^ ERROR type parameters are not allowed on this type +//~| NOTE type parameter not allowed +//~| ERROR ambiguous associated type +//~| NOTE ambiguous associated type +//~| NOTE specify the type using the syntax `<::A as Trait>::f` fn main() {} diff --git a/src/test/compile-fail/self-impl.rs b/src/test/compile-fail/self-impl.rs index d058c6a5a3b9..860e69fcaec4 100644 --- a/src/test/compile-fail/self-impl.rs +++ b/src/test/compile-fail/self-impl.rs @@ -31,9 +31,13 @@ impl SuperFoo for Bar { impl Bar { fn f() { let _: ::Baz = true; -//~^ERROR: ambiguous associated type; specify the type using the syntax `::Baz` + //~^ ERROR ambiguous associated type + //~| NOTE ambiguous associated type + //~| NOTE specify the type using the syntax `::Baz` let _: Self::Baz = true; -//~^ERROR: ambiguous associated type; specify the type using the syntax `::Baz` + //~^ ERROR ambiguous associated type + //~| NOTE ambiguous associated type + //~| NOTE specify the type using the syntax `::Baz` } } diff --git a/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs b/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs index c77494912bc7..e6545063dbd4 100644 --- a/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs +++ b/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs @@ -34,7 +34,9 @@ where T : Convert fn a() { test(22, std::default::Default::default()); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } fn main() {} diff --git a/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs b/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs index fb6c43a19059..41242a44f58b 100644 --- a/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs +++ b/src/test/compile-fail/typeck-builtin-bound-type-parameters.rs @@ -9,20 +9,27 @@ // except according to those terms. fn foo1, U>(x: T) {} -//~^ ERROR: wrong number of type arguments: expected 0, found 1 +//~^ ERROR E0244 +//~| NOTE expected no type arguments, found 1 trait Trait: Copy {} -//~^ ERROR: wrong number of type arguments: expected 0, found 1 +//~^ ERROR E0244 +//~| NOTE expected no type arguments, found 1 struct MyStruct1>; -//~^ ERROR wrong number of type arguments: expected 0, found 1 +//~^ ERROR E0244 +//~| NOTE expected no type arguments, found 1 struct MyStruct2<'a, T: Copy<'a>>; //~^ ERROR: wrong number of lifetime parameters: expected 0, found 1 +//~| NOTE unexpected lifetime parameter + fn foo2<'a, T:Copy<'a, U>, U>(x: T) {} -//~^ ERROR: wrong number of type arguments: expected 0, found 1 -//~^^ ERROR: wrong number of lifetime parameters: expected 0, found 1 +//~^ ERROR E0244 +//~| NOTE expected no type arguments, found 1 +//~| ERROR: wrong number of lifetime parameters: expected 0, found 1 +//~| NOTE unexpected lifetime parameter fn main() { } diff --git a/src/test/compile-fail/typeck_type_placeholder_item.rs b/src/test/compile-fail/typeck_type_placeholder_item.rs index d4f3cdfd8b7e..42db3b47a04f 100644 --- a/src/test/compile-fail/typeck_type_placeholder_item.rs +++ b/src/test/compile-fail/typeck_type_placeholder_item.rs @@ -13,107 +13,141 @@ fn test() -> _ { 5 } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures fn test2() -> (_, _) { (5, 5) } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures +//~| NOTE not allowed in type signatures static TEST3: _ = "test"; //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures static TEST4: _ = 145; //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures static TEST5: (_, _) = (1, 2); //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures +//~| NOTE not allowed in type signatures fn test6(_: _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures fn test7(x: _) { let _x: usize = x; } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures fn test8(_f: fn() -> _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures +//~| NOTE not allowed in type signatures struct Test9; impl Test9 { fn test9(&self) -> _ { () } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn test10(&self, _x : _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures } impl Clone for Test9 { fn clone(&self) -> _ { Test9 } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn clone_from(&mut self, other: _) { *self = Test9; } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures } struct Test10 { a: _, //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures b: (_, _), //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures + //~| NOTE not allowed in type signatures } pub fn main() { fn fn_test() -> _ { 5 } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn fn_test2() -> (_, _) { (5, 5) } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures + //~| NOTE not allowed in type signatures static FN_TEST3: _ = "test"; //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures static FN_TEST4: _ = 145; //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures static FN_TEST5: (_, _) = (1, 2); //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures + //~| NOTE not allowed in type signatures fn fn_test6(_: _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn fn_test7(x: _) { let _x: usize = x; } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn fn_test8(_f: fn() -> _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures struct FnTest9; impl FnTest9 { fn fn_test9(&self) -> _ { () } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn fn_test10(&self, _x : _) { } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures } impl Clone for FnTest9 { fn clone(&self) -> _ { FnTest9 } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures fn clone_from(&mut self, other: _) { *self = FnTest9; } //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures } struct FnTest10 { a: _, //~^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures b: (_, _), //~^ ERROR the type placeholder `_` is not allowed within types on item signatures //~^^ ERROR the type placeholder `_` is not allowed within types on item signatures + //~| NOTE not allowed in type signatures + //~| NOTE not allowed in type signatures } } diff --git a/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs b/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs index 2cb46cc352be..f60d925a7486 100644 --- a/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs +++ b/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs @@ -17,5 +17,6 @@ struct Foo<'a, T:'a> { pub fn main() { let c: Foo<_, _> = Foo { r: &5 }; - //~^ ERROR wrong number of type arguments: expected 1, found 2 + //~^ ERROR E0244 + //~| NOTE expected 1 type arguments, found 2 } diff --git a/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs b/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs index 8178335de593..ec2675ece74b 100644 --- a/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs +++ b/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs @@ -17,5 +17,6 @@ struct Foo<'a, T:'a> { pub fn main() { let c: Foo<_, usize> = Foo { r: &5 }; - //~^ ERROR wrong number of type arguments: expected 1, found 2 + //~^ ERROR E0244 + //~| NOTE expected 1 type arguments, found 2 } diff --git a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs index 04bbfc445ede..120975761025 100644 --- a/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs +++ b/src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs @@ -13,7 +13,8 @@ trait Trait {} fn f isize>(x: F) {} -//~^ ERROR wrong number of type arguments: expected 0, found 1 +//~^ ERROR E0244 +//~| NOTE expected no type arguments, found 1 //~| ERROR associated type `Output` not found fn main() {} diff --git a/src/test/compile-fail/unconstrained-none.rs b/src/test/compile-fail/unconstrained-none.rs index c14de98e03f1..380cdd266cd6 100644 --- a/src/test/compile-fail/unconstrained-none.rs +++ b/src/test/compile-fail/unconstrained-none.rs @@ -11,5 +11,7 @@ // Issue #5062 fn main() { - None; //~ ERROR type annotations or generic parameter binding required + None; //~ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/unconstrained-ref.rs b/src/test/compile-fail/unconstrained-ref.rs index 02a3f2b9ab8d..ba94bf613d21 100644 --- a/src/test/compile-fail/unconstrained-ref.rs +++ b/src/test/compile-fail/unconstrained-ref.rs @@ -13,5 +13,7 @@ struct S<'a, T:'a> { } fn main() { - S { o: &None }; //~ ERROR type annotations or generic parameter binding required + S { o: &None }; //~ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/compile-fail/use-mod.rs b/src/test/compile-fail/use-mod.rs index bbb063770c14..6be878dce1fb 100644 --- a/src/test/compile-fail/use-mod.rs +++ b/src/test/compile-fail/use-mod.rs @@ -15,7 +15,8 @@ use foo::bar::{ Bar, self //~^ NOTE another `self` import appears here -//~^^ ERROR a module named `bar` has already been imported in this module +//~| ERROR a module named `bar` has already been imported in this module +//~| NOTE already imported }; use {self}; diff --git a/src/test/compile-fail/vector-no-ann.rs b/src/test/compile-fail/vector-no-ann.rs index 419b8c4e1b01..25709f35246e 100644 --- a/src/test/compile-fail/vector-no-ann.rs +++ b/src/test/compile-fail/vector-no-ann.rs @@ -11,5 +11,7 @@ fn main() { let _foo = Vec::new(); - //~^ ERROR type annotations or generic parameter binding required + //~^ ERROR unable to infer enough type information about `_` [E0282] + //~| NOTE cannot infer type for `_` + //~| NOTE type annotations or generic parameter binding } diff --git a/src/test/run-pass/issue-20847.rs b/src/test/run-pass/issue-20847.rs new file mode 100644 index 000000000000..d2c335605458 --- /dev/null +++ b/src/test/run-pass/issue-20847.rs @@ -0,0 +1,21 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(fn_traits)] + +use std::ops::Fn; + +fn say(x: u32, y: u32) { + println!("{} {}", x, y); +} + +fn main() { + Fn::call(&say, (1, 2)); +} diff --git a/src/test/run-pass/slice_binary_search.rs b/src/test/run-pass/slice_binary_search.rs new file mode 100644 index 000000000000..80b370d58fc5 --- /dev/null +++ b/src/test/run-pass/slice_binary_search.rs @@ -0,0 +1,29 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test binary_search_by_key lifetime. Issue #34683 + +#[derive(Debug)] +struct Assignment { + topic: String, + partition: i32, +} + +fn main() { + let xs = vec![ + Assignment { topic: "abc".into(), partition: 1 }, + Assignment { topic: "def".into(), partition: 2 }, + Assignment { topic: "ghi".into(), partition: 3 }, + ]; + + let key: &str = "def"; + let r = xs.binary_search_by_key(&key, |e| &e.topic); + assert_eq!(Ok(1), r.map(|i| i)); +}