-.TH RUSTC "1" "August 2015" "rustc 1.2.0" "User Commands"
+.TH RUSTC "1" "August 2016" "rustc 1.12.0" "User Commands"
.SH NAME
rustc \- The Rust compiler
.SH SYNOPSIS
See https://github.com/rust\-lang/rust/issues for issues.
.SH "AUTHOR"
-See \fIAUTHORS.txt\fR in the Rust source distribution.
+See https://github.com/rust\-lang/rust/graphs/contributors or use `git log --all --format='%cN <%cE>' | sort -u` in the rust source distribution.
.SH "COPYRIGHT"
This work is dual\[hy]licensed under Apache\ 2.0 and MIT terms.
-.TH RUSTDOC "1" "August 2015" "rustdoc 1.2.0" "User Commands"
+.TH RUSTDOC "1" "August 2016" "rustdoc 1.12.0" "User Commands"
.SH NAME
rustdoc \- generate documentation from Rust source code
.SH SYNOPSIS
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
- pub fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
- where F: FnMut(&T) -> Ordering
+ pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
+ where F: FnMut(&'a T) -> Ordering
{
core_slice::SliceExt::binary_search_by(self, f)
}
/// ```
#[stable(feature = "slice_binary_search_by_key", since = "1.10.0")]
#[inline]
- pub fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
- where F: FnMut(&T) -> B,
+ pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<usize, usize>
+ where F: FnMut(&'a T) -> B,
B: Ord
{
core_slice::SliceExt::binary_search_by_key(self, b, f)
}
}
+#[stable(feature = "cow_str_from_iter", since = "1.12.0")]
+impl<'a> FromIterator<char> for Cow<'a, str> {
+ fn from_iter<I: IntoIterator<Item = char>>(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<I: IntoIterator<Item = &'b str>>(it: I) -> Cow<'a, str> {
+ Cow::Owned(FromIterator::from_iter(it))
+ }
+}
+
+#[stable(feature = "cow_str_from_iter", since = "1.12.0")]
+impl<'a> FromIterator<String> for Cow<'a, str> {
+ fn from_iter<I: IntoIterator<Item = String>>(it: I) -> Cow<'a, str> {
+ Cow::Owned(FromIterator::from_iter(it))
+ }
+}
+
#[stable(feature = "rust1", since = "1.0.0")]
impl Into<Vec<u8>> for String {
fn into(self) -> Vec<u8> {
/// 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
}
/// only designed to be used by unsafe code that needs to manipulate
/// the low-level details.
///
-/// There is no `Repr` implementation for `TraitObject` because there
-/// is no way to refer to all trait objects generically, so the only
+/// There is no way to refer to all trait objects generically, so the only
/// way to create values of this type is with functions like
-/// `std::mem::transmute`. Similarly, the only way to create a true
+/// [`std::mem::transmute`][transmute]. Similarly, the only way to create a true
/// trait object from a `TraitObject` value is with `transmute`.
///
+/// [transmute]: ../intrinsics/fn.transmute.html
+///
/// Synthesizing a trait object with mismatched types—one where the
/// vtable does not correspond to the type of the value to which the
/// data pointer points—is highly likely to lead to undefined
/// ```
/// #![feature(raw)]
///
-/// use std::mem;
-/// use std::raw;
+/// use std::{mem, raw};
///
/// // an example trait
/// trait Foo {
/// fn bar(&self) -> i32;
/// }
+///
/// impl Foo for i32 {
/// fn bar(&self) -> i32 {
/// *self + 1
/// // the data pointer is the address of `value`
/// assert_eq!(raw_object.data as *const i32, &value as *const _);
///
-///
/// let other_value: i32 = 456;
///
/// // construct a new object, pointing to a different `i32`, being
/// let synthesized: &Foo = unsafe {
/// mem::transmute(raw::TraitObject {
/// data: &other_value as *const _ as *mut (),
-/// vtable: raw_object.vtable
+/// vtable: raw_object.vtable,
/// })
/// };
///
-/// // it should work just like we constructed a trait object out of
+/// // it should work just as if we had constructed a trait object out of
/// // `other_value` directly
/// assert_eq!(synthesized.bar(), 457);
/// ```
fn binary_search(&self, x: &Self::Item) -> Result<usize, usize>
where Self::Item: Ord;
#[stable(feature = "core", since = "1.6.0")]
- fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
- where F: FnMut(&Self::Item) -> Ordering;
+ fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
+ where F: FnMut(&'a Self::Item) -> Ordering;
#[stable(feature = "slice_binary_search_by_key", since = "1.10.0")]
- fn binary_search_by_key<B, F>(&self, b: &B, f: F) -> Result<usize, usize>
- where F: FnMut(&Self::Item) -> B,
+ fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<usize, usize>
+ where F: FnMut(&'a Self::Item) -> B,
B: Ord;
#[stable(feature = "core", since = "1.6.0")]
fn len(&self) -> usize;
self as *const [T] as *const T
}
- fn binary_search_by<F>(&self, mut f: F) -> Result<usize, usize> where
- F: FnMut(&T) -> Ordering
+ fn binary_search_by<'a, F>(&'a self, mut f: F) -> Result<usize, usize>
+ where F: FnMut(&'a T) -> Ordering
{
let mut base = 0usize;
let mut s = self;
}
#[inline]
- fn binary_search_by_key<B, F>(&self, b: &B, mut f: F) -> Result<usize, usize>
- where F: FnMut(&Self::Item) -> B,
+ fn binary_search_by_key<'a, B, F>(&'a self, b: &B, mut f: F) -> Result<usize, usize>
+ where F: FnMut(&'a Self::Item) -> B,
B: Ord
{
self.binary_search_by(|k| f(k).cmp(b))
pub fn prohibit_projection(self, span: Span)
{
- span_err!(self.sess, span, E0229,
- "associated type bindings are not allowed here");
+ let mut err = struct_span_err!(self.sess, span, E0229,
+ "associated type bindings are not allowed here");
+ err.span_label(span, &format!("associate type not allowed here")).emit();
}
pub fn prim_ty_to_ty(self,
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,
but it borrows {}, \
which is owned by the current function",
cmt_path_or_string)
- .span_note(capture_span,
+ .span_label(capture_span,
&format!("{} is borrowed here",
cmt_path_or_string))
+ .span_label(err.span,
+ &format!("may outlive borrowed value {}",
+ cmt_path_or_string))
.span_suggestion(err.span,
&format!("to force the closure to take ownership of {} \
(and any other referenced variables), \
.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);
},
_ => ()
}
format!("`{}` and {} more", head.join("`, `"), tail.len())
}
};
- span_err!(cx.tcx.sess, sp, E0004,
+
+ let label_text = match pattern_strings.len(){
+ 1 => format!("pattern {} not covered", joined_patterns),
+ _ => format!("patterns {} not covered", joined_patterns)
+ };
+ struct_span_err!(cx.tcx.sess, sp, E0004,
"non-exhaustive patterns: {} not covered",
joined_patterns
- );
+ ).span_label(sp, &label_text).emit();
},
}
}
For example, the following `match` block has too many arms:
-```compile_fail
-match foo {
+```compile_fail,E0001
+match Some(0) {
Some(bar) => {/* ... */}
None => {/* ... */}
_ => {/* ... */} // All possible cases have already been handled
required in order to assign values to match expressions, or alternatively,
determine the flow of execution. Erroneous code example:
-```compile_fail
+```compile_fail,E0004
enum Terminator {
HastaLaVistaBaby,
TalkToMyHand,
Patterns used to bind names must be irrefutable, that is, they must guarantee
that a name will be extracted in all cases. Erroneous code example:
-```compile_fail
+```compile_fail,E0005
let x = Some(1);
let Some(y) = x;
// error: refutable pattern in local binding: `None` not covered
moved into a variable called `op_string` while simultaneously requiring the
inner `String` to be moved into a variable called `s`.
-```compile_fail
+```compile_fail,E0007
let x = Some("s".to_string());
match x {
referenced in the pattern guard code. Doing so however would prevent the name
from being available in the body of the match arm. Consider the following:
-```compile_fail
+```compile_fail,E0008
match Some("hi".to_string()) {
Some(s) if s.len() == 0 => {}, // use s.
_ => {},
Though this example seems innocuous and easy to solve, the problem becomes clear
when it encounters functions which consume the value:
-```compile_fail
+```compile_fail,E0008
struct A{}
impl A {
Erroneous code example:
-```compile_fail
+```compile_fail,E0009
struct X { x: (), }
let x = Some((X { x: () }, X { x: () }));
match was successful. If the match is irrefutable (when it cannot fail to
match), use a regular `let`-binding instead. For instance:
-```compile_fail
+```compile_fail,E0162
struct Irrefutable(i32);
let irr = Irrefutable(0);
// This fails to compile because the match is irrefutable.
if let Irrefutable(x) = irr {
// This body will always be executed.
- foo(x);
+ // ...
}
```
Try this instead:
-```ignore
+```
struct Irrefutable(i32);
let irr = Irrefutable(0);
let Irrefutable(x) = irr;
-foo(x);
+println!("{}", x);
```
"##,
match was successful. If the match is irrefutable (when it cannot fail to
match), use a regular `let`-binding inside a `loop` instead. For instance:
-```compile_fail
+```compile_fail,E0165
struct Irrefutable(i32);
let irr = Irrefutable(0);
loop variable, consider using a `match` or `if let` inside the loop body. For
instance:
-```compile_fail
+```compile_fail,E0297
let xs : Vec<Option<i32>> = vec!(Some(1), None);
// This fails because `None` is not covered.
exhaustive. For instance, the following would not match any arm if mutable
borrows were allowed:
-```compile_fail
+```compile_fail,E0301
match Some(()) {
None => { },
option if option.take().is_none() => {
exhaustive. For instance, the following would not match any arm if assignments
were allowed:
-```compile_fail
+```compile_fail,E0302
match Some(()) {
None => { },
- option if { option = None; false } { },
+ option if { option = None; false } => { },
Some(_) => { } // When the previous match failed, the option became `None`.
}
```
Updates to the borrow checker in a future version of Rust may remove this
restriction, but for now patterns must be rewritten without sub-bindings.
-```ignore
-// Before.
+Before:
+
+```compile_fail,E0303
match Some("hi".to_string()) {
ref op_string_ref @ Some(s) => {},
None => {},
}
+```
+
+After:
-// After.
+```
match Some("hi".to_string()) {
Some(ref s) => {
let op_string_ref = &Some(s);
constant expression that had to be evaluated. Attempting to divide by 0
or causing integer overflow are two ways to induce this error. For example:
-```compile_fail
+```compile_fail,E0080
enum Enum {
X = (1 << 500),
Y = (1 / 0)
In an array literal `[x; N]`, `N` is the number of elements in the array. This
must be an unsigned integer. Erroneous code example:
-```compile_fail
+```compile_fail,E0306
let x = [0i32; true]; // error: expected positive integer for repeat count,
// found boolean
```
Ok(val as usize)
},
Ok(const_val) => {
- span_err!(tcx.sess, count_expr.span, E0306,
- "expected usize for {}, found {}",
- reason,
- const_val.description());
+ struct_span_err!(tcx.sess, count_expr.span, E0306,
+ "expected `usize` for {}, found {}",
+ reason,
+ const_val.description())
+ .span_label(count_expr.span, &format!("expected `usize`"))
+ .emit();
+
Err(ErrorReported)
}
Err(err) => {
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();
}
}
self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name));
}
if label.name.as_str() == "'_" {
- self.session.add_lint(
- lint::builtin::LIFETIME_UNDERSCORE, id, span,
- format!("invalid label name `{}`", label.name)
- );
+ self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
+ id,
+ span,
+ format!("invalid label name `{}`", label.name));
}
}
fn invalid_visibility(&self, vis: &Visibility, span: Span, note: Option<&str>) {
if vis != &Visibility::Inherited {
- let mut err = struct_span_err!(self.session, span, E0449,
+ let mut err = struct_span_err!(self.session,
+ span,
+ E0449,
"unnecessary visibility qualifier");
if let Some(note) = note {
err.span_note(span, note);
impl<'a> Visitor for AstValidator<'a> {
fn visit_lifetime(&mut self, lt: &Lifetime) {
if lt.name.as_str() == "'_" {
- self.session.add_lint(
- lint::builtin::LIFETIME_UNDERSCORE, lt.id, lt.span,
- format!("invalid lifetime name `{}`", lt.name)
- );
+ self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
+ lt.id,
+ lt.span,
+ format!("invalid lifetime name `{}`", lt.name));
}
visit::walk_lifetime(self, lt)
fn visit_expr(&mut self, expr: &Expr) {
match expr.node {
- ExprKind::While(_, _, Some(ident)) | ExprKind::Loop(_, Some(ident)) |
- ExprKind::WhileLet(_, _, _, Some(ident)) | ExprKind::ForLoop(_, _, _, Some(ident)) |
- ExprKind::Break(Some(ident)) | ExprKind::Continue(Some(ident)) => {
+ ExprKind::While(_, _, Some(ident)) |
+ ExprKind::Loop(_, Some(ident)) |
+ ExprKind::WhileLet(_, _, _, Some(ident)) |
+ ExprKind::ForLoop(_, _, _, Some(ident)) |
+ ExprKind::Break(Some(ident)) |
+ ExprKind::Continue(Some(ident)) => {
self.check_label(ident.node, ident.span, expr.id);
}
_ => {}
match ty.node {
TyKind::BareFn(ref bfty) => {
self.check_decl_no_pat(&bfty.decl, |span, _| {
- let mut err = struct_span_err!(self.session, span, E0561,
- "patterns aren't allowed in function pointer types");
- err.span_note(span, "this is a recent error, see \
- issue #35203 for more details");
+ let mut err = struct_span_err!(self.session,
+ span,
+ E0561,
+ "patterns aren't allowed in function pointer \
+ types");
+ err.span_note(span,
+ "this is a recent error, see issue #35203 for more details");
err.emit();
});
}
if path.global && path.segments.len() > 0 {
let ident = path.segments[0].identifier;
if token::Ident(ident).is_path_segment_keyword() {
- self.session.add_lint(
- lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span,
- format!("global paths cannot start with `{}`", ident)
- );
+ self.session.add_lint(lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH,
+ id,
+ path.span,
+ format!("global paths cannot start with `{}`", ident));
}
}
ItemKind::Use(ref view_path) => {
let path = view_path.node.path();
if !path.segments.iter().all(|segment| segment.parameters.is_empty()) {
- self.err_handler().span_err(path.span, "type or lifetime parameters \
- in import path");
+ self.err_handler()
+ .span_err(path.span, "type or lifetime parameters in import path");
}
}
ItemKind::Impl(_, _, _, Some(..), _, ref impl_items) => {
}
}
ItemKind::Impl(_, _, _, None, _, _) => {
- self.invalid_visibility(&item.vis, item.span, Some("place qualifiers on individual \
- impl items instead"));
+ self.invalid_visibility(&item.vis,
+ item.span,
+ Some("place qualifiers on individual impl items instead"));
}
ItemKind::DefaultImpl(..) => {
self.invalid_visibility(&item.vis, item.span, None);
}
ItemKind::ForeignMod(..) => {
- self.invalid_visibility(&item.vis, item.span, Some("place qualifiers on individual \
- foreign items instead"));
+ self.invalid_visibility(&item.vis,
+ item.span,
+ Some("place qualifiers on individual foreign items \
+ instead"));
}
ItemKind::Enum(ref def, _) => {
for variant in &def.variants {
match fi.node {
ForeignItemKind::Fn(ref decl, _) => {
self.check_decl_no_pat(decl, |span, is_recent| {
- let mut err = struct_span_err!(self.session, span, E0130,
- "patterns aren't allowed in foreign function declarations");
+ let mut err = struct_span_err!(self.session,
+ span,
+ E0130,
+ "patterns aren't allowed in foreign function \
+ declarations");
if is_recent {
- err.span_note(span, "this is a recent error, see \
- issue #35203 for more details");
+ err.span_note(span,
+ "this is a recent error, see issue #35203 for more details");
}
err.emit();
});
visit::walk_foreign_item(self, fi)
}
- fn visit_variant_data(&mut self, vdata: &VariantData, _: Ident,
- _: &Generics, _: NodeId, span: Span) {
+ fn visit_variant_data(&mut self,
+ vdata: &VariantData,
+ _: Ident,
+ _: &Generics,
+ _: NodeId,
+ span: Span) {
if vdata.fields().is_empty() {
if vdata.is_tuple() {
- self.err_handler().struct_span_err(span, "empty tuple structs and enum variants \
- are not allowed, use unit structs and \
- enum variants instead")
- .span_help(span, "remove trailing `()` to make a unit \
- struct or unit enum variant")
- .emit();
+ self.err_handler()
+ .struct_span_err(span,
+ "empty tuple structs and enum variants are not allowed, use \
+ unit structs and enum variants instead")
+ .span_help(span,
+ "remove trailing `()` to make a unit struct or unit enum variant")
+ .emit();
}
}
fn visit_vis(&mut self, vis: &Visibility) {
match *vis {
- Visibility::Restricted{ref path, ..} => {
+ Visibility::Restricted { ref path, .. } => {
if !path.segments.iter().all(|segment| segment.parameters.is_empty()) {
- self.err_handler().span_err(path.span, "type or lifetime parameters \
- in visibility path");
+ self.err_handler()
+ .span_err(path.span, "type or lifetime parameters in visibility path");
}
}
_ => {}
// by borrowck::gather_loans
use rustc::dep_graph::DepNode;
-use rustc::ty::cast::{CastKind};
+use rustc::ty::cast::CastKind;
use rustc_const_eval::{ConstEvalErr, lookup_const_fn_by_id, compare_lit_exprs};
use rustc_const_eval::{eval_const_expr_partial, lookup_const_by_id};
use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal, MiscCatchAll, Math};
tcx: TyCtxt<'a, 'tcx, 'tcx>,
mode: Mode,
qualif: ConstQualif,
- rvalue_borrows: NodeMap<hir::Mutability>
+ rvalue_borrows: NodeMap<hir::Mutability>,
}
impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
- fn with_mode<F, R>(&mut self, mode: Mode, f: F) -> R where
- F: FnOnce(&mut CheckCrateVisitor<'a, 'gcx>) -> R,
+ fn with_mode<F, R>(&mut self, mode: Mode, f: F) -> R
+ where F: FnOnce(&mut CheckCrateVisitor<'a, 'gcx>) -> R
{
let (old_mode, old_qualif) = (self.mode, self.qualif);
self.mode = mode;
r
}
- fn with_euv<F, R>(&mut self, item_id: Option<ast::NodeId>, f: F) -> R where
- F: for<'b, 'tcx> FnOnce(&mut euv::ExprUseVisitor<'b, 'gcx, 'tcx>) -> R,
+ fn with_euv<F, R>(&mut self, item_id: Option<ast::NodeId>, f: F) -> R
+ where F: for<'b, 'tcx> FnOnce(&mut euv::ExprUseVisitor<'b, 'gcx, 'tcx>) -> R
{
let param_env = match item_id {
Some(item_id) => ty::ParameterEnvironment::for_item(self.tcx, item_id),
- None => self.tcx.empty_parameter_environment()
+ None => self.tcx.empty_parameter_environment(),
};
- self.tcx.infer_ctxt(None, Some(param_env), ProjectionMode::AnyFinal).enter(|infcx| {
- f(&mut euv::ExprUseVisitor::new(self, &infcx))
- })
+ self.tcx
+ .infer_ctxt(None, Some(param_env), ProjectionMode::AnyFinal)
+ .enter(|infcx| f(&mut euv::ExprUseVisitor::new(self, &infcx)))
}
fn global_expr(&mut self, mode: Mode, expr: &hir::Expr) -> ConstQualif {
}
if let Err(err) = eval_const_expr_partial(self.tcx, expr, ExprTypeChecked, None) {
match err.kind {
- UnimplementedConstVal(_) => {},
- IndexOpFeatureGated => {},
- ErroneousReferencedConstant(_) => {},
- _ => self.tcx.sess.add_lint(CONST_ERR, expr.id, expr.span,
- format!("constant evaluation error: {}. This will \
- become a HARD ERROR in the future",
- err.description().into_oneline())),
+ UnimplementedConstVal(_) => {}
+ IndexOpFeatureGated => {}
+ ErroneousReferencedConstant(_) => {}
+ _ => {
+ self.tcx.sess.add_lint(CONST_ERR,
+ expr.id,
+ expr.span,
+ format!("constant evaluation error: {}. This will \
+ become a HARD ERROR in the future",
+ err.description().into_oneline()))
+ }
}
}
self.with_mode(mode, |this| {
}
let mode = match fk {
- FnKind::ItemFn(_, _, _, hir::Constness::Const, _, _, _) => {
- Mode::ConstFn
- }
+ FnKind::ItemFn(_, _, _, hir::Constness::Const, _, _, _) => Mode::ConstFn,
FnKind::Method(_, m, _, _) => {
if m.constness == hir::Constness::Const {
Mode::ConstFn
Mode::Var
}
}
- _ => Mode::Var
+ _ => Mode::Var,
};
let qualif = self.with_mode(mode, |this| {
}
/// Returns true if the call is to a const fn or method.
- fn handle_const_fn_call(&mut self,
- _expr: &hir::Expr,
- def_id: DefId,
- ret_ty: Ty<'gcx>)
- -> bool {
+ fn handle_const_fn_call(&mut self, _expr: &hir::Expr, def_id: DefId, ret_ty: Ty<'gcx>) -> bool {
if let Some(fn_like) = lookup_const_fn_by_id(self.tcx, def_id) {
let qualif = self.fn_like(fn_like.kind(),
fn_like.decl(),
Ok(Ordering::Less) |
Ok(Ordering::Equal) => {}
Ok(Ordering::Greater) => {
- span_err!(self.tcx.sess, start.span, E0030,
- "lower range bound must be less than or equal to upper");
+ span_err!(self.tcx.sess,
+ start.span,
+ E0030,
+ "lower range bound must be less than or equal to upper");
}
Err(ErrorReported) => {}
}
}
- _ => intravisit::walk_pat(self, p)
+ _ => intravisit::walk_pat(self, p),
}
}
match stmt.node {
hir::StmtDecl(ref decl, _) => {
match decl.node {
- hir::DeclLocal(_) => {},
+ hir::DeclLocal(_) => {}
// Item statements are allowed
- hir::DeclItem(_) => continue
+ hir::DeclItem(_) => continue,
}
}
- hir::StmtExpr(_, _) => {},
- hir::StmtSemi(_, _) => {},
+ hir::StmtExpr(_, _) => {}
+ hir::StmtSemi(_, _) => {}
}
self.add_qualif(ConstQualif::NOT_CONST);
}
// The count is checked elsewhere (typeck).
let count = match node_ty.sty {
ty::TyArray(_, n) => n,
- _ => bug!()
+ _ => bug!(),
};
// [element; 0] is always zero-sized.
if count == 0 {
for pat in arms.iter().flat_map(|arm| &arm.pats) {
let pat_borrow = self.rvalue_borrows.remove(&pat.id);
match (borrow, pat_borrow) {
- (None, _) | (_, Some(hir::MutMutable)) => {
+ (None, _) |
+ (_, Some(hir::MutMutable)) => {
borrow = pat_borrow;
}
_ => {}
}
intravisit::walk_expr(self, ex);
}
- _ => intravisit::walk_expr(self, ex)
+ _ => intravisit::walk_expr(self, ex),
}
// Handle borrows on (or inside the autorefs of) this expression.
if self.mode == Mode::Var && !self.qualif.intersects(ConstQualif::NOT_CONST) {
match eval_const_expr_partial(self.tcx, ex, ExprTypeChecked, None) {
Ok(_) => {}
- Err(ConstEvalErr { kind: UnimplementedConstVal(_), ..}) |
- Err(ConstEvalErr { kind: MiscCatchAll, ..}) |
- Err(ConstEvalErr { kind: MiscBinaryOp, ..}) |
- Err(ConstEvalErr { kind: NonConstPath, ..}) |
- Err(ConstEvalErr { kind: UnresolvedPath, ..}) |
- Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), ..}) |
- Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), ..}) |
- Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), ..}) |
- Err(ConstEvalErr { kind: IndexOpFeatureGated, ..}) => {},
+ Err(ConstEvalErr { kind: UnimplementedConstVal(_), .. }) |
+ Err(ConstEvalErr { kind: MiscCatchAll, .. }) |
+ Err(ConstEvalErr { kind: MiscBinaryOp, .. }) |
+ Err(ConstEvalErr { kind: NonConstPath, .. }) |
+ Err(ConstEvalErr { kind: UnresolvedPath, .. }) |
+ Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), .. }) |
+ Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), .. }) |
+ Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), .. }) |
+ Err(ConstEvalErr { kind: IndexOpFeatureGated, .. }) => {}
Err(msg) => {
- self.tcx.sess.add_lint(CONST_ERR, ex.id,
+ self.tcx.sess.add_lint(CONST_ERR,
+ ex.id,
msg.span,
msg.description().into_oneline().into_owned())
}
/// every nested expression. If the expression is not part
/// of a const/static item, it is qualified for promotion
/// instead of producing errors.
-fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
- e: &hir::Expr, node_ty: Ty<'tcx>) {
+fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node_ty: Ty<'tcx>) {
match node_ty.sty {
ty::TyStruct(def, _) |
ty::TyEnum(def, _) if def.has_dtor() => {
Some(&ty::adjustment::AdjustUnsafeFnPointer) |
Some(&ty::adjustment::AdjustMutToConstPointer) => {}
- Some(&ty::adjustment::AdjustDerefRef(
- ty::adjustment::AutoDerefRef { autoderefs, .. }
- )) => {
- if (0..autoderefs as u32).any(|autoderef| {
- v.tcx.is_overloaded_autoderef(e.id, autoderef)
- }) {
+ Some(&ty::adjustment::AdjustDerefRef(ty::adjustment::AutoDerefRef { autoderefs, .. })) => {
+ if (0..autoderefs as u32)
+ .any(|autoderef| v.tcx.is_overloaded_autoderef(e.id, autoderef)) {
v.add_qualif(ConstQualif::NOT_CONST);
}
}
}
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
- tcx.visit_all_items_in_krate(DepNode::CheckConst, &mut CheckCrateVisitor {
- tcx: tcx,
- mode: Mode::Var,
- qualif: ConstQualif::NOT_CONST,
- rvalue_borrows: NodeMap()
- });
+ tcx.visit_all_items_in_krate(DepNode::CheckConst,
+ &mut CheckCrateVisitor {
+ tcx: tcx,
+ mode: Mode::Var,
+ qualif: ConstQualif::NOT_CONST,
+ rvalue_borrows: NodeMap(),
+ });
tcx.sess.abort_if_errors();
}
Categorization::Rvalue(..) |
Categorization::Upvar(..) |
- Categorization::Local(..) => break
+ Categorization::Local(..) => break,
}
}
}
cmt: mc::cmt<'tcx>,
_loan_region: ty::Region,
bk: ty::BorrowKind,
- loan_cause: euv::LoanCause)
- {
+ loan_cause: euv::LoanCause) {
// Kind of hacky, but we allow Unsafe coercions in constants.
// These occur when we convert a &T or *T to a *U, as well as
// when making a thin pointer (e.g., `*T`) into a fat pointer
euv::LoanCause::AutoUnsafe => {
return;
}
- _ => { }
+ _ => {}
}
let mut cur = &cmt;
// type of the expression. `&mut [1]` has exactly the
// same representation as &mut 1.
match cmt.ty.sty {
- ty::TyArray(_, _) | ty::TySlice(_) => break,
+ ty::TyArray(_, _) |
+ ty::TySlice(_) => break,
_ => {}
}
}
}
Categorization::Upvar(..) |
- Categorization::Local(..) => break
+ Categorization::Local(..) => break,
}
}
}
- fn decl_without_init(&mut self,
- _id: ast::NodeId,
- _span: Span) {}
+ fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) {}
fn mutate(&mut self,
_assignment_id: ast::NodeId,
_assignment_span: Span,
_assignee_cmt: mc::cmt,
- _mode: euv::MutateMode) {}
+ _mode: euv::MutateMode) {
+ }
- fn matched_pat(&mut self,
- _: &hir::Pat,
- _: mc::cmt,
- _: euv::MatchMode) {}
+ fn matched_pat(&mut self, _: &hir::Pat, _: mc::cmt, _: euv::MatchMode) {}
- fn consume_pat(&mut self,
- _consume_pat: &hir::Pat,
- _cmt: mc::cmt,
- _mode: euv::ConsumeMode) {}
+ fn consume_pat(&mut self, _consume_pat: &hir::Pat, _cmt: mc::cmt, _mode: euv::ConsumeMode) {}
}
For example, neither of the following can be sensibly compiled:
-```compile_fail
+```compile_fail,E0265
const X: u32 = X;
```
-```compile_fail
+```compile_fail,E0265
const X: u32 = Y;
const Y: u32 = X;
```
This error indicates the use of a loop keyword (`break` or `continue`) inside a
closure but outside of any loop. Erroneous code example:
-```compile_fail
+```compile_fail,E0267
let w = || { break; }; // error: `break` inside of a closure
```
of a loop. Without a loop to break out of or continue in, no sensible action can
be taken. Erroneous code example:
-```compile_fail
+```compile_fail,E0268
fn some_func() {
break; // error: `break` outside of loop
}
#![feature(rustc_private)]
extern crate core;
-#[macro_use] extern crate rustc;
+#[macro_use]
+extern crate rustc;
extern crate rustc_const_eval;
extern crate rustc_const_math;
-#[macro_use] extern crate log;
-#[macro_use] extern crate syntax;
+#[macro_use]
+extern crate log;
+#[macro_use]
+extern crate syntax;
extern crate syntax_pos;
extern crate rustc_errors as errors;
#[derive(Clone, Copy, PartialEq)]
enum Context {
- Normal, Loop, Closure
+ Normal,
+ Loop,
+ Closure,
}
#[derive(Copy, Clone)]
struct CheckLoopVisitor<'a> {
sess: &'a Session,
- cx: Context
+ cx: Context,
}
pub fn check_crate(sess: &Session, map: &Map) {
let _task = map.dep_graph.in_task(DepNode::CheckLoops);
let krate = map.krate();
- krate.visit_all_items(&mut CheckLoopVisitor { sess: sess, cx: Normal });
+ krate.visit_all_items(&mut CheckLoopVisitor {
+ sess: sess,
+ cx: Normal,
+ });
}
impl<'a, 'v> Visitor<'v> for CheckLoopVisitor<'a> {
}
hir::ExprBreak(_) => self.require_loop("break", e.span),
hir::ExprAgain(_) => self.require_loop("continue", e.span),
- _ => intravisit::walk_expr(self, e)
+ _ => intravisit::walk_expr(self, e),
}
}
}
impl<'a> CheckLoopVisitor<'a> {
- fn with_context<F>(&mut self, cx: Context, f: F) where
- F: FnOnce(&mut CheckLoopVisitor<'a>),
+ fn with_context<F>(&mut self, cx: Context, f: F)
+ where F: FnOnce(&mut CheckLoopVisitor<'a>)
{
let old_cx = self.cx;
self.cx = cx;
match self.cx {
Loop => {}
Closure => {
- span_err!(self.sess, span, E0267,
- "`{}` inside of a closure", name);
+ span_err!(self.sess, span, E0267, "`{}` inside of a closure", name);
}
Normal => {
- span_err!(self.sess, span, E0268,
- "`{}` outside of loop", name);
+ span_err!(self.sess, span, E0268, "`{}` outside of loop", name);
}
}
}
use syntax::visit;
pub fn check_crate(sess: &Session, krate: &ast::Crate) {
- if sess.target.target.options.allow_asm { return; }
+ if sess.target.target.options.allow_asm {
+ return;
+ }
- visit::walk_crate(&mut CheckNoAsm { sess: sess, }, krate);
+ visit::walk_crate(&mut CheckNoAsm { sess: sess }, krate);
}
#[derive(Copy, Clone)]
impl<'a> Visitor for CheckNoAsm<'a> {
fn visit_expr(&mut self, e: &ast::Expr) {
match e.node {
- ast::ExprKind::InlineAsm(_) => span_err!(self.sess, e.span, E0472,
- "asm! is unsupported on this target"),
- _ => {},
+ ast::ExprKind::InlineAsm(_) => {
+ span_err!(self.sess,
+ e.span,
+ E0472,
+ "asm! is unsupported on this target")
+ }
+ _ => {}
}
visit::walk_expr(self, e)
}
use rustc::dep_graph::DepNode;
use rustc::hir::map as ast_map;
-use rustc::session::{Session, CompileResult};
+use rustc::session::{CompileResult, Session};
use rustc::hir::def::{Def, DefMap};
use rustc::util::nodemap::NodeMap;
-use syntax::{ast};
+use syntax::ast;
use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax_pos::Span;
use rustc::hir::intravisit::{self, Visitor};
match it.node {
hir::ItemStatic(..) |
hir::ItemConst(..) => {
- let mut recursion_visitor =
- CheckItemRecursionVisitor::new(self, &it.span);
+ let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &it.span);
recursion_visitor.visit_item(it);
- },
+ }
hir::ItemEnum(ref enum_def, ref generics) => {
// We could process the whole enum, but handling the variants
// with discriminant expressions one by one gives more specific,
// less redundant output.
for variant in &enum_def.variants {
if let Some(_) = variant.node.disr_expr {
- let mut recursion_visitor =
- CheckItemRecursionVisitor::new(self, &variant.span);
+ let mut recursion_visitor = CheckItemRecursionVisitor::new(self,
+ &variant.span);
recursion_visitor.populate_enum_discriminants(enum_def);
recursion_visitor.visit_variant(variant, generics, it.id);
}
match ti.node {
hir::ConstTraitItem(_, ref default) => {
if let Some(_) = *default {
- let mut recursion_visitor =
- CheckItemRecursionVisitor::new(self, &ti.span);
+ let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ti.span);
recursion_visitor.visit_trait_item(ti);
}
}
fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
match ii.node {
hir::ImplItemKind::Const(..) => {
- let mut recursion_visitor =
- CheckItemRecursionVisitor::new(self, &ii.span);
+ let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ii.span);
recursion_visitor.visit_impl_item(ii);
}
_ => {}
}
impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
- fn new(v: &'a CheckCrateVisitor<'a, 'ast>, span: &'a Span)
+ fn new(v: &'a CheckCrateVisitor<'a, 'ast>,
+ span: &'a Span)
-> CheckItemRecursionVisitor<'a, 'ast> {
CheckItemRecursionVisitor {
root_span: span,
}
}
fn with_item_id_pushed<F>(&mut self, id: ast::NodeId, f: F)
- where F: Fn(&mut Self) {
+ where F: Fn(&mut Self)
+ {
if self.idstack.iter().any(|&x| x == id) {
let any_static = self.idstack.iter().any(|&x| {
if let ast_map::NodeItem(item) = self.ast_map.get(x) {
if !self.sess.features.borrow().static_recursion {
emit_feature_err(&self.sess.parse_sess.span_diagnostic,
"static_recursion",
- *self.root_span, GateIssue::Language, "recursive static");
+ *self.root_span,
+ GateIssue::Language,
+ "recursive static");
}
} else {
span_err!(self.sess, *self.root_span, E0265, "recursive constant");
// has no variants.
let mut discriminant_map = self.discriminant_map.borrow_mut();
match enum_definition.variants.first() {
- None => { return; }
+ None => {
+ return;
+ }
Some(variant) if discriminant_map.contains_key(&variant.node.data.id()) => {
return;
}
self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it));
}
- fn visit_enum_def(&mut self, enum_definition: &'ast hir::EnumDef,
- generics: &'ast hir::Generics, item_id: ast::NodeId, _: Span) {
+ fn visit_enum_def(&mut self,
+ enum_definition: &'ast hir::EnumDef,
+ generics: &'ast hir::Generics,
+ item_id: ast::NodeId,
+ _: Span) {
self.populate_enum_discriminants(enum_definition);
intravisit::walk_enum_def(self, enum_definition, generics, item_id);
}
- fn visit_variant(&mut self, variant: &'ast hir::Variant,
- _: &'ast hir::Generics, _: ast::NodeId) {
+ fn visit_variant(&mut self,
+ variant: &'ast hir::Variant,
+ _: &'ast hir::Generics,
+ _: ast::NodeId) {
let variant_id = variant.node.data.id();
let maybe_expr;
if let Some(get_expr) = self.discriminant_map.borrow().get(&variant_id) {
Some(Def::Const(def_id)) => {
if let Some(node_id) = self.ast_map.as_local_node_id(def_id) {
match self.ast_map.get(node_id) {
- ast_map::NodeItem(item) =>
- self.visit_item(item),
- ast_map::NodeTraitItem(item) =>
- self.visit_trait_item(item),
- ast_map::NodeImplItem(item) =>
- self.visit_impl_item(item),
- ast_map::NodeForeignItem(_) => {},
+ ast_map::NodeItem(item) => self.visit_item(item),
+ ast_map::NodeTraitItem(item) => self.visit_trait_item(item),
+ ast_map::NodeImplItem(item) => self.visit_impl_item(item),
+ ast_map::NodeForeignItem(_) => {}
_ => {
- span_bug!(
- e.span,
- "expected item, found {}",
- self.ast_map.node_to_string(node_id));
+ span_bug!(e.span,
+ "expected item, found {}",
+ self.ast_map.node_to_string(node_id));
}
}
}
// might be (if any).
Some(Def::Variant(enum_id, variant_id)) => {
if let Some(enum_node_id) = self.ast_map.as_local_node_id(enum_id) {
- if let hir::ItemEnum(ref enum_def, ref generics) =
- self.ast_map.expect_item(enum_node_id).node
- {
+ if let hir::ItemEnum(ref enum_def, ref generics) = self.ast_map
+ .expect_item(enum_node_id)
+ .node {
self.populate_enum_discriminants(enum_def);
let enum_id = self.ast_map.as_local_node_id(enum_id).unwrap();
let variant_id = self.ast_map.as_local_node_id(variant_id).unwrap();
}
}
}
- _ => ()
+ _ => (),
}
- },
- _ => ()
+ }
+ _ => (),
}
intravisit::walk_expr(self, e);
}
}
use foo::MyTrait::do_something;
+// error: `do_something` is not directly importable
fn main() {}
```
It's invalid to directly import methods belonging to a trait or concrete type.
"##,
+E0254: r##"
+Attempt was made to import an item whereas an extern crate with this name has
+already been imported.
+
+Erroneous code example:
+
+```compile_fail,E0254
+extern crate collections;
+
+mod foo {
+ pub trait collections {
+ fn do_something();
+ }
+}
+
+use foo::collections; // error: an extern crate named `collections` has already
+ // been imported in this module
+
+fn main() {}
+```
+
+To fix issue issue, you have to rename at least one of the two imports.
+Example:
+
+```ignore
+extern crate collections as libcollections; // ok!
+
+mod foo {
+ pub trait collections {
+ fn do_something();
+ }
+}
+
+use foo::collections;
+
+fn main() {}
+```
+"##,
+
E0255: r##"
You can't import a value whose name is the same as another value defined in the
module.
register_diagnostics! {
// E0153, unused error code
// E0157, unused error code
- E0254, // import conflicts with imported crate in this module
// E0257,
// E0258,
E0402, // cannot use an outer type parameter in this context
(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));
None => match rscope.anon_regions(default_span, 1) {
Ok(rs) => rs[0],
Err(params) => {
- let mut err = struct_span_err!(self.tcx().sess, default_span, E0106,
- "missing lifetime specifier");
+ let ampersand_span = Span { hi: default_span.lo, ..default_span};
+
+ let mut err = struct_span_err!(self.tcx().sess, ampersand_span, E0106,
+ "missing lifetime specifier");
+ err.span_label(ampersand_span, &format!("expected lifetime parameter"));
+
if let Some(params) = params {
report_elision_failure(&mut err, params);
}
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
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 =
} 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();
}
}
fn report_lifetime_number_error(tcx: TyCtxt, span: Span, number: usize, expected: usize) {
- span_err!(tcx.sess, span, E0107,
- "wrong number of lifetime parameters: expected {}, found {}",
- expected, number);
+ let label = if number < expected {
+ if expected == 1 {
+ format!("expected {} lifetime parameter", expected)
+ } else {
+ format!("expected {} lifetime parameters", expected)
+ }
+ } else {
+ let additional = number - expected;
+ if additional == 1 {
+ "unexpected lifetime parameter".to_string()
+ } else {
+ format!("{} unexpected lifetime parameters", additional)
+ }
+ };
+ struct_span_err!(tcx.sess, span, E0107,
+ "wrong number of lifetime parameters: expected {}, found {}",
+ expected, number)
+ .span_label(span, &label)
+ .emit();
}
// A helper struct for conveniently grouping a set of bounds which we pass to
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;
}
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();
}
}
}
/// 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();
}
}
(&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;
}
_ => {
},
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
- };
-
- 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 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);
+
+ 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;
+ }
}
}
}
// good
}
hir::Constness::Const => {
- span_err!(ccx.tcx.sess, span, E0379, "trait fns cannot be declared const");
+ struct_span_err!(ccx.tcx.sess, span, E0379, "trait fns cannot be declared const")
+ .span_label(span, &format!("trait fns cannot be const"))
+ .emit()
}
}
}
// Check existing impl methods to see if they are both present in trait
// and compatible with trait signature
for impl_item in impl_items {
- let ty_impl_item = ccx.tcx.impl_or_trait_item(ccx.tcx.map.local_def_id(impl_item.id));
+ let ty_impl_item = tcx.impl_or_trait_item(tcx.map.local_def_id(impl_item.id));
let ty_trait_item = trait_items.iter()
.find(|ac| ac.name() == ty_impl_item.name());
trait_const,
&impl_trait_ref);
} else {
- span_err!(tcx.sess, impl_item.span, E0323,
+ let mut err = struct_span_err!(tcx.sess, impl_item.span, E0323,
"item `{}` is an associated const, \
which doesn't match its trait `{:?}`",
impl_const.name,
- impl_trait_ref)
+ impl_trait_ref);
+ err.span_label(impl_item.span, &format!("does not match trait"));
+ // We can only get the spans from local trait definition
+ // Same for E0324 and E0325
+ if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) {
+ err.span_label(trait_span, &format!("original trait requirement"));
+ }
+ err.emit()
}
}
hir::ImplItemKind::Method(ref sig, ref body) => {
&trait_method,
&impl_trait_ref);
} else {
- span_err!(tcx.sess, impl_item.span, E0324,
+ let mut err = struct_span_err!(tcx.sess, impl_item.span, E0324,
"item `{}` is an associated method, \
which doesn't match its trait `{:?}`",
impl_method.name,
- impl_trait_ref)
+ impl_trait_ref);
+ err.span_label(impl_item.span, &format!("does not match trait"));
+ if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) {
+ err.span_label(trait_span, &format!("original trait requirement"));
+ }
+ err.emit()
}
}
hir::ImplItemKind::Type(_) => {
overridden_associated_type = Some(impl_item);
}
} else {
- span_err!(tcx.sess, impl_item.span, E0325,
+ let mut err = struct_span_err!(tcx.sess, impl_item.span, E0325,
"item `{}` is an associated type, \
which doesn't match its trait `{:?}`",
impl_type.name,
- impl_trait_ref)
+ impl_trait_ref);
+ err.span_label(impl_item.span, &format!("does not match trait"));
+ if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) {
+ err.span_label(trait_span, &format!("original trait requirement"));
+ }
+ err.emit()
}
}
}
}
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() {
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();
- span_note!(&mut err, ccx.tcx.map.span(variant_i_node_id),
- "conflicting discriminant here");
+ 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();
}
disr_vals.push(current_disr_val);
// FIXME(#32730) propagate obligations
.map(|InferOk { obligations, .. }| assert!(obligations.is_empty()));
if eq_result.is_err() {
- span_err!(tcx.sess, expr.span, E0069,
- "`return;` in a function whose return type is not `()`");
+ struct_span_err!(tcx.sess, expr.span, E0069,
+ "`return;` in a function whose return type is not `()`")
+ .span_label(expr.span, &format!("return type is not ()"))
+ .emit();
}
}
}
if let Some(ref e) = *expr_opt {
self.check_expr(&e);
}
- span_err!(tcx.sess, expr.span, E0166,
- "`return` in a function declared as diverging");
+ struct_span_err!(tcx.sess, expr.span, E0166,
+ "`return` in a function declared as diverging")
+ .span_label(expr.span, &format!("diverging function cannot return"))
+ .emit();
}
}
self.write_ty(id, self.next_diverging_ty_var());
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) => {
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,
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();
}
}
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 {}",
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;
}
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)) => {
_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
}
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) => {
kind: &str,
name: &str)
{
- span_err!(ccx.tcx.sess, span, E0207,
- "the {} parameter `{}` is not constrained by the \
- impl trait, self type, or predicates",
- kind, name);
+ struct_span_err!(
+ ccx.tcx.sess, span, E0207,
+ "the {} parameter `{}` is not constrained by the \
+ impl trait, self type, or predicates",
+ kind, name)
+ .span_label(span, &format!("unconstrained lifetime parameter"))
+ .emit();
+
}
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;
+ }
}
_ => ()
}
/// 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 }
}
#[cfg(any(target_os = "linux", target_os = "emscripten"))]
use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64};
#[cfg(target_os = "android")]
-use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off64_t, lseek64,
+use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, lseek64,
dirent as dirent64, open as open64};
#[cfg(not(any(target_os = "linux",
target_os = "emscripten",
pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
let (whence, pos) = match pos {
- SeekFrom::Start(off) => (libc::SEEK_SET, off as off64_t),
- SeekFrom::End(off) => (libc::SEEK_END, off as off64_t),
- SeekFrom::Current(off) => (libc::SEEK_CUR, off as off64_t),
+ // Casting to `i64` is fine, too large values will end up as
+ // negative which will cause an error in `lseek64`.
+ SeekFrom::Start(off) => (libc::SEEK_SET, off as i64),
+ SeekFrom::End(off) => (libc::SEEK_END, off),
+ SeekFrom::Current(off) => (libc::SEEK_CUR, off),
};
let n = cvt(unsafe { lseek64(self.0.raw(), pos, whence) })?;
Ok(n as u64)
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",
// the implementation allows recursive locking. The POSIX standard
// doesn't require recursivly locking a rwlock to deadlock, but we can't
// allow that because it could lead to aliasing issues.
- if r == libc::EDEADLK || *self.write_locked.get() {
+ if r == libc::EAGAIN {
+ panic!("rwlock maximum reader count exceeded");
+ } else if r == libc::EDEADLK || *self.write_locked.get() {
if r == 0 {
self.raw_unlock();
}
pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
let (whence, pos) = match pos {
+ // Casting to `i64` is fine, `SetFilePointerEx` reinterprets this
+ // integer as `u64`.
SeekFrom::Start(n) => (c::FILE_BEGIN, n as i64),
SeekFrom::End(n) => (c::FILE_END, n),
SeekFrom::Current(n) => (c::FILE_CURRENT, n),
#![feature(box_syntax)]
const CON : Box<i32> = box 0; //~ ERROR E0010
+ //~| NOTE allocation not allowed in
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`
}
}
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
_ => {}
}
}
fn main() {
let mut x = Foo { x: -7 };
- x.drop(); //~ ERROR E0040
+ x.drop();
+ //~^ ERROR E0040
+ //~| NOTE call to destructor method
}
struct Bar;
-impl Foo for Bar {} //~ ERROR E0046
+impl Foo for Bar {}
+//~^ ERROR E0046
+//~| NOTE missing `foo` in implementation
fn main() {
}
// except according to those terms.
fn foo() -> u8 {
- return; //~ ERROR E0069
+ return;
+ //~^ ERROR `return;` in a function whose return type is not `()`
+ //~| NOTE return type is not ()
}
fn main() {
// except according to those terms.
fn main() {
- let x = |_| {}; //~ ERROR E0101
+ let x = |_| {};
+ //~^ ERROR E0101
+ //~| NOTE cannot resolve type of expression
}
// except according to those terms.
fn main() {
- let x = []; //~ ERROR E0102
+ let x = [];
+ //~^ ERROR E0102
+ //~| NOTE cannot resolve type of variable
}
// except according to those terms.
struct Foo {
- x: &bool, //~ ERROR E0106
+ x: &bool,
+ //~^ ERROR E0106
+ //~| NOTE expected lifetime parameter
}
enum Bar {
A(u8),
- B(&bool), //~ ERROR E0106
+ B(&bool),
+ //~^ ERROR E0106
+ //~| NOTE expected lifetime parameter
}
-type MyStr = &str; //~ ERROR E0106
+type MyStr = &str;
+ //~^ ERROR E0106
+ //~| NOTE expected lifetime parameter
fn main() {
}
// except according to those terms.
struct Foo<'a>(&'a str);
+struct Buzz<'a, 'b>(&'a str, &'b str);
enum Bar {
A,
C,
}
-struct Baz<'a> {
- foo: Foo, //~ ERROR E0107
- bar: Bar<'a>, //~ ERROR E0107
+struct Baz<'a, 'b, 'c> {
+ foo: Foo,
+ //~^ ERROR E0107
+ //~| expected 1 lifetime parameter
+ buzz: Buzz<'a>,
+ //~^ ERROR E0107
+ //~| expected 2 lifetime parameters
+ bar: Bar<'a>,
+ //~^ ERROR E0107
+ //~| unexpected lifetime parameter
+ foo2: Foo<'a, 'b, 'c>,
+ //~^ ERROR E0107
+ //~| 2 unexpected lifetime parameters
}
fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-impl Vec<u8> {} //~ ERROR E0116
+impl Vec<u8> {}
+//~^ ERROR E0116
+//~| NOTE impl for type defined outside of crate.
+//~| NOTE define and implement a trait or new type instead
fn main() {
}
// 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() {
}
// 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()
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn main<T>() { //~ ERROR E0131
+fn main<T>() {
+ //~^ ERROR E0131
+ //~| NOTE main cannot have type parameters
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn foo() -> ! { return; } //~ ERROR E0166
+fn foo() -> ! { return; }
+ //~^ ERROR E0166
+ //~| NOTE diverging function cannot return
fn main() {
}
// 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() {
// 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() {
foo: Vec<u32>,
}
-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,
}
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,
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() {
}
struct Foo;
impl<T: Default> Foo { //~ ERROR E0207
+ //~| NOTE unconstrained lifetime parameter
fn get(&self) -> T {
<T as Default>::default()
}
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 `<Type as MyTrait>::X`
}
// except according to those terms.
fn main() {
- let _: Box<std::io::Read + std::io::Write>; //~ ERROR E0225
+ let _: Box<std::io::Read + std::io::Write>;
+ //~^ ERROR only the builtin traits can be used as closure or object bounds [E0225]
+ //~| NOTE non-builtin trait used as bounds
}
fn boo(&self) -> usize { 42 }
}
-fn baz<I>(x: &<I as Foo<A=Bar>>::A) {} //~ ERROR E0229
+fn baz<I>(x: &<I as Foo<A=Bar>>::A) {}
+//~^ ERROR associated type bindings are not allowed here [E0229]
+//~| NOTE associate type not allowed here
fn main() {
}
// except according to those terms.
struct Foo<T> { x: T }
-struct Bar { x: Foo } //~ ERROR E0243
+struct Bar { x: Foo }
+ //~^ ERROR E0243
+ //~| NOTE expected 1 type arguments, found 0
fn main() {
}
// except according to those terms.
struct Foo { x: bool }
-struct Bar<S, T> { x: Foo<S, T> } //~ ERROR E0244
+struct Bar<S, T> { x: Foo<S, T> }
+ //~^ ERROR E0244
+ //~| NOTE expected no type arguments, found 2
+
fn main() {
}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+mod foo {
+ pub trait MyTrait {
+ fn do_something();
+ }
+}
+
+use foo::MyTrait::do_something; //~ ERROR E0253
+
+fn main() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+extern crate collections;
+
+mod foo {
+ pub trait collections {
+ fn do_something();
+ }
+}
+
+use foo::collections; //~ ERROR E0254
+
+fn main() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use bar::foo;
+
+fn foo() {} //~ ERROR E0255
+
+mod bar {
+ pub fn foo() {}
+}
+
+fn main() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+extern crate collections;
+extern crate libc as collections; //~ ERROR E0259
+
+fn main() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+extern crate collections;
+
+mod collections { //~ ERROR E0260
+ pub trait MyTrait {
+ fn do_something();
+ }
+}
+
+fn main() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn foo(x: &'a str) { } //~ ERROR E0261
+
+struct Foo {
+ x: &'a str, //~ ERROR E0261
+}
+
+fn main() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn foo<'static>(x: &'static str) { } //~ ERROR E0262
+
+fn main() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { } //~ ERROR E0263
+
+fn main() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(lang_items)]
+
+extern "C" {
+ #[lang = "cake"]
+ fn cake(); //~ ERROR E0264
+}
+
+fn main() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+ let w = || { break; }; //~ ERROR E0267
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+ break; //~ ERROR E0268
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait Trait { type AssociatedType; }
+
+fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
+ println!("in foo");
+}
+
+impl Trait for i8 { type AssociatedType = &'static str; }
+
+fn main() {
+ foo(3_i8); //~ ERROR E0271
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait Foo {}
+
+struct Bar<T>(T);
+
+impl<T> Foo for T where Bar<T>: Foo {} //~ ERROR E0275
+
+fn main() {
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait Foo {
+ fn foo<T>(x: T);
+}
+
+impl Foo for bool {
+ fn foo<T>(x: T) where T: Copy {} //~ ERROR E0276
+}
+
+fn main() {
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait Foo {
+ fn bar(&self);
+}
+
+fn some_func<T: Foo>(foo: T) {
+ foo.bar();
+}
+
+fn main() {
+ some_func(5i32); //~ ERROR E0277
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn foo<F: Fn()>(x: F) { }
+
+fn main() {
+ foo(|y| { }); //~ ERROR E0281
+ //~^ ERROR E0281
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+ let x = "hello".chars().rev().collect(); //~ ERROR E0282
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait Generator {
+ fn create() -> u32;
+}
+
+struct Impl;
+
+impl Generator for Impl {
+ fn create() -> u32 { 1 }
+}
+
+struct AnotherImpl;
+
+impl Generator for AnotherImpl {
+ fn create() -> u32 { 2 }
+}
+
+fn main() {
+ let cont: u32 = Generator::create(); //~ ERROR E0283
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![recursion_limit] //~ ERROR E0296
+
+fn main() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+ let xs : Vec<Option<i32>> = vec!(Some(1), None);
+
+ for Some(x) in xs {} //~ ERROR E0297
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+ match Some(()) {
+ None => { },
+ option if option.take().is_none() => {}, //~ ERROR E0301
+ Some(_) => { }
+ }
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+ match Some(()) {
+ None => { },
+ option if { option = None; false } => { }, //~ ERROR E0302
+ Some(_) => { }
+ }
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+ match Some("hi".to_string()) {
+ ref op_string_ref @ Some(s) => {}, //~ ERROR E0303
+ //~^ ERROR E0009
+ None => {},
+ }
+}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-const A: [u32; "hello"] = []; //~ ERROR E0306
-const B: [u32; true] = []; //~ ERROR E0306
-const C: [u32; 0.0] = []; //~ ERROR E0306
+const A: [u32; "hello"] = [];
+//~^ ERROR expected `usize` for array length, found string literal [E0306]
+//~| NOTE expected `usize`
+
+const B: [u32; true] = [];
+//~^ ERROR expected `usize` for array length, found boolean [E0306]
+//~| NOTE expected `usize`
+
+const C: [u32; 0.0] = [];
+//~^ ERROR expected `usize` for array length, found float [E0306]
+//~| NOTE expected `usize`
fn main() {
}
fn get<T:Get,U:Get>(x: T, y: U) -> Get::Value {}
//~^ ERROR ambiguous associated type
+//~| NOTE ambiguous associated type
+//~| NOTE specify the type using the syntax `<Type as Get>::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 `<Type as Grab>::Value`
}
type X = std::ops::Deref::Target;
//~^ ERROR ambiguous associated type
+//~| NOTE ambiguous associated type
+//~| NOTE specify the type using the syntax `<Type as std::ops::Deref>::Target`
fn main() {
}
// Tests that a function with a ! annotation always actually fails
fn bad_bang(i: usize) -> ! {
- return 7; //~ ERROR `return` in a function declared as diverging [E0166]
+ return 7;
+ //~^ ERROR `return` in a function declared as diverging [E0166]
+ //~| NOTE diverging function cannot return
}
fn main() { bad_bang(5); }
let mut books = vec![1,2,3];
spawn(|| books.push(4));
//~^ ERROR E0373
+ //~| NOTE `books` is borrowed here
+ //~| NOTE may outlive borrowed value `books`
}
let mut books = vec![1,2,3];
Box::new(|| books.push(4))
//~^ ERROR E0373
+ //~| NOTE `books` is borrowed here
+ //~| NOTE may outlive borrowed value `books`
}
fn main() { }
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() {
}
}
impl Foo for u32 {
- const fn f() -> u32 { 22 } //~ ERROR E0379
+ const fn f() -> u32 { 22 }
+ //~^ ERROR E0379
+ //~| NOTE trait fns cannot be const
}
fn main() { }
const ARR3: [i32; X3] = [99; 6]; //~ NOTE: for array length here
const Y: usize = 42.0 == 42.0;
-const ARRR: [i32; Y] = [99; 1]; //~ ERROR: expected usize for array length
+const ARRR: [i32; Y] = [99; 1];
+//~^ ERROR: expected `usize` for array length, found boolean [E0306]
+//~| NOTE expected `usize`
+
const Y1: usize = 42.0 >= 42.0;
-const ARRR1: [i32; Y] = [99; 1]; //~ ERROR: expected usize for array length
+const ARRR1: [i32; Y] = [99; 1];
+//~^ ERROR: expected `usize` for array length, found boolean [E0306]
+//~| NOTE expected `usize`
+
const Y2: usize = 42.0 <= 42.0;
-const ARRR2: [i32; Y] = [99; 1]; //~ ERROR: expected usize for array length
+const ARRR2: [i32; Y] = [99; 1];
+//~^ ERROR: expected `usize` for array length, found boolean [E0306]
+//~| NOTE expected `usize`
+
const Y3: usize = 42.0 > 42.0;
-const ARRR3: [i32; Y] = [99; 0]; //~ ERROR: expected usize for array length
+const ARRR3: [i32; Y] = [99; 0];
+//~^ ERROR: expected `usize` for array length, found boolean [E0306]
+//~| NOTE expected `usize`
+
const Y4: usize = 42.0 < 42.0;
-const ARRR4: [i32; Y] = [99; 0]; //~ ERROR: expected usize for array length
+const ARRR4: [i32; Y] = [99; 0];
+//~^ ERROR: expected `usize` for array length, found boolean [E0306]
+//~| NOTE expected `usize`
+
const Y5: usize = 42.0 != 42.0;
-const ARRR5: [i32; Y] = [99; 0]; //~ ERROR: expected usize for array length
+const ARRR5: [i32; Y] = [99; 0];
+//~^ ERROR: expected `usize` for array length, found boolean [E0306]
+//~| NOTE expected `usize`
+
fn main() {
let _ = ARR;
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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.
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() {}
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
}
fn main() {
let _: Vec<isize, Heap, bool>;
- //~^ ERROR wrong number of type arguments: expected at most 2, found 3
+ //~^ ERROR E0244
+ //~| NOTE expected at most 2 type arguments, found 3
}
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() {}
struct Holder { x: String }
impl<'a> Fun for Holder { //~ ERROR E0207
+ //~| NOTE unconstrained lifetime parameter
type Output = &'a str;
fn call<'b>(&'b self) -> &'b str {
&self.x[..]
trait Foo {
fn bar(&self);
- const MY_CONST: u32;
+ //~^ NOTE original trait requirement
+ //~| NOTE original trait requirement
+ const MY_CONST: u32; //~ NOTE original trait requirement
}
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
const MY_CONST: u32 = 1;
}
impl Foo for FooMethodForConst {
//~^ ERROR E0046
+ //~| NOTE missing `MY_CONST` in implementation
fn bar(&self) {}
fn MY_CONST() {}
//~^ ERROR E0324
+ //~| NOTE does not match trait
}
pub struct FooTypeForMethod;
impl Foo for FooTypeForMethod {
//~^ ERROR E0046
+ //~| NOTE missing `bar` in implementation
type bar = u64;
//~^ ERROR E0325
+ //~| NOTE does not match trait
const MY_CONST: u32 = 1;
}
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
}
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
}
// 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() {}
enum Foo {
A = 1,
- B = 1, //~ ERROR discriminant value `1isize` already exists
- //~^^ NOTE conflicting
+ //~^ NOTE first use
+ //~| NOTE first use
+ //~| NOTE first use
+ B = 1, //~ ERROR discriminant value
+ //~^ NOTE enum already
C = 0,
- D, //~ ERROR discriminant value `1isize` already exists
- //~^^^^^ NOTE conflicting
- E = N, //~ ERROR discriminant value `1isize` already exists
- //~^^^^^^^ NOTE conflicting
+ D, //~ ERROR discriminant value
+ //~^ NOTE enum already
+
+ E = N, //~ ERROR discriminant value
+ //~^ NOTE enum already
+
}
fn main() {}
struct Newtype(Option<Box<usize>>);
impl<'a> Iterator for Newtype { //~ ERROR E0207
+ //~| NOTE unconstrained lifetime parameter
type Item = &'a Box<usize>;
fn next(&mut self) -> Option<&Box<usize>> {
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`)
}
fn bar(x:i32) ->i32 { 3*x };
let b:Box<Any> = Box::new(bar as fn(_)->_);
b.downcast_ref::<fn(_)->_>(); //~ ERROR E0282
+ //~| NOTE cannot infer type for `_`
+ //~| NOTE type annotations or generic parameter binding required
}
fn f<T>(self)
where T<Bogus = Foo>: A;
//~^ ERROR associated type bindings are not allowed here [E0229]
+ //~| NOTE associate type not allowed here
}
fn main() {}
fn f<T>(self)
where T<Bogus = Self::AlsoBogus>: A;
//~^ ERROR associated type bindings are not allowed here [E0229]
+ //~| NOTE associate type not allowed here
}
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<u64> {
if self.pos < 2 {
}
impl<C: Component> 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,))
}
// 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 }
}
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() {
}
//~| expected type `usize`
//~| found type `S`
//~| expected usize, found struct `S`
- //~| ERROR expected usize for repeat count, found struct
+ //~| ERROR expected `usize` for repeat count, found struct [E0306]
+ //~| expected `usize`
}
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() {}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::ops::Deref;
+
+struct Obj<F> 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`
+}
fn bug(l: S) {
match l {
S::B{ } => { },
- //~^ ERROR ambiguous associated type; specify the type using the syntax `<S as Trait>::B`
+ //~^ ERROR ambiguous associated type
+ //~| NOTE ambiguous associated type
+ //~| NOTE specify the type using the syntax `<S as Trait>::B`
}
}
pub struct MTFn;
impl<'a> MethodType for MTFn { //~ ERROR E0207
+ //~| NOTE unconstrained lifetime parameter
type GetProp = fmt::Debug + 'a;
}
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
id(Box::new(|| *v))
//~^ ERROR E0373
- //~| ERROR cannot move out of borrowed content
+ //~| NOTE `v` is borrowed here
+ //~| NOTE may outlive borrowed value `v`
+ //~| ERROR E0507
+ //~| NOTE cannot move out of borrowed content
}
fn main() {
// 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]
fn main() {
// Unconstrained type:
format!("{:?}", None);
- //~^ ERROR type annotations or generic parameter binding required
+ //~^ ERROR unable to infer enough type information about `_` [E0282]
}
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
}
fn foo(b: bool) -> Result<bool,String> {
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() {
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() {
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
}
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();
}
fn struct_with_a_nested_enum_and_vector() {
match (Foo { first: true, second: None }) {
//~^ ERROR non-exhaustive patterns: `Foo { first: false, second: Some([_, _, _, _]) }` not covered
+//~| NOTE pattern `Foo { first: false, second: Some([_, _, _, _]) }` not covered
Foo { first: true, second: None } => (),
Foo { first: true, second: Some(_) } => (),
Foo { first: false, second: None } => (),
fn enum_with_single_missing_variant() {
match Color::Red {
//~^ ERROR non-exhaustive patterns: `Red` not covered
+ //~| NOTE pattern `Red` not covered
Color::CustomRGBA { .. } => (),
Color::Green => ()
}
fn enum_with_multiple_missing_variants() {
match Direction::North {
//~^ ERROR non-exhaustive patterns: `East`, `South` and `West` not covered
+ //~| NOTE patterns `East`, `South` and `West` not covered
Direction::North => ()
}
}
fn enum_with_excessive_missing_variants() {
match ExcessiveEnum::First {
//~^ ERROR `Second`, `Third`, `Fourth` and 8 more not covered
+ //~| NOTE patterns `Second`, `Third`, `Fourth` and 8 more not covered
ExcessiveEnum::First => ()
}
fn enum_struct_variant() {
match Color::Red {
//~^ ERROR non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered
+ //~| NOTE pattern `CustomRGBA { a: true, .. }` not covered
Color::Red => (),
Color::Green => (),
Color::CustomRGBA { a: false, r: _, g: _, b: 0 } => (),
let x: &'static [Enum] = &[Enum::First, Enum::Second(false)];
match *x {
//~^ ERROR non-exhaustive patterns: `[Second(true), Second(false)]` not covered
+ //~| NOTE pattern `[Second(true), Second(false)]` not covered
[] => (),
[_] => (),
[Enum::First, _] => (),
fn missing_nil() {
match ((), false) {
//~^ ERROR non-exhaustive patterns: `((), false)` not covered
+ //~| NOTE pattern `((), false)` not covered
((), true) => ()
}
}
fn f<T>() {}
}
-type A = <S as Tr>::A::f<u8>; //~ ERROR type parameters are not allowed on this type
-//~^ ERROR ambiguous associated type; specify the type using the syntax `<<S as Tr>::A as Trait>::f`
+type A = <S as Tr>::A::f<u8>;
+//~^ 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 `<<S as Tr>::A as Trait>::f`
fn main() {}
fn escaping_borrow_of_closure_params_1() {
let g = |x: usize, y:usize| {
+ //~^ NOTE reference must be valid for the scope of call-site for function
+ //~| NOTE ...but borrowed value is only valid for the scope of function body
+ //~| NOTE reference must be valid for the scope of call-site for function
+ //~| NOTE ...but borrowed value is only valid for the scope of function body
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
//~^ ERROR `x` does not live long enough
//~| ERROR `y` does not live long enough
fn escaping_borrow_of_closure_params_2() {
let g = |x: usize, y:usize| {
+ //~^ NOTE reference must be valid for the scope of call-site for function
+ //~| NOTE ...but borrowed value is only valid for the scope of function body
+ //~| NOTE reference must be valid for the scope of call-site for function
+ //~| NOTE ...but borrowed value is only valid for the scope of function body
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
//~^ ERROR `x` does not live long enough
//~| ERROR `y` does not live long enough
fn g<'a>(x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
//~^ ERROR E0373
+ //~| NOTE `x` is borrowed here
+ //~| NOTE may outlive borrowed value `x`
//~| ERROR E0373
+ //~| NOTE `y` is borrowed here
+ //~| NOTE may outlive borrowed value `y`
return Box::new(f);
};
fn g<'a>(x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
//~^ ERROR E0373
+ //~| NOTE `x` is borrowed here
+ //~| NOTE may outlive borrowed value `x`
//~| ERROR E0373
+ //~| NOTE `y` is borrowed here
+ //~| NOTE may outlive borrowed value `y`
Box::new(f)
};
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
//~^ ERROR E0373
+ //~| NOTE `x` is borrowed here
+ //~| NOTE may outlive borrowed value `x`
//~| ERROR E0373
+ //~| NOTE `y` is borrowed here
+ //~| NOTE may outlive borrowed value `y`
return Box::new(f);
}
}
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
//~^ ERROR E0373
+ //~| NOTE `x` is borrowed here
+ //~| NOTE may outlive borrowed value `x`
//~| ERROR E0373
+ //~| NOTE `y` is borrowed here
+ //~| NOTE may outlive borrowed value `y`
Box::new(f)
}
}
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
//~^ ERROR E0373
+ //~| NOTE `x` is borrowed here
+ //~| NOTE may outlive borrowed value `x`
//~| ERROR E0373
+ //~| NOTE `y` is borrowed here
+ //~| NOTE may outlive borrowed value `y`
return Box::new(f);
}
}
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
//~^ ERROR E0373
+ //~| NOTE `x` is borrowed here
+ //~| NOTE may outlive borrowed value `x`
//~| ERROR E0373
+ //~| NOTE `y` is borrowed here
+ //~| NOTE may outlive borrowed value `y`
Box::new(f)
}
}
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
//~^ ERROR E0373
+ //~| NOTE `x` is borrowed here
+ //~| NOTE may outlive borrowed value `x`
//~| ERROR E0373
+ //~| NOTE `y` is borrowed here
+ //~| NOTE may outlive borrowed value `y`
return Box::new(f);
}
}
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
//~^ ERROR E0373
+ //~| NOTE `x` is borrowed here
+ //~| NOTE may outlive borrowed value `x`
//~| ERROR E0373
+ //~| NOTE `y` is borrowed here
+ //~| NOTE may outlive borrowed value `y`
Box::new(f)
}
}
fn nested() {
let y = 3;
ignore(
- |z| { //~ ERROR E0373
+ |z| {
+ //~^ ERROR E0373
+ //~| NOTE may outlive borrowed value `y`
if false { &y } else { z }
+ //~^ NOTE `y` is borrowed here
});
}
//~| expected type `usize`
//~| found type `()`
//~| expected usize, found ()
- //~| ERROR expected usize for repeat count, found tuple [E0306]
+ //~| ERROR expected `usize` for repeat count, found tuple [E0306]
+ //~| expected `usize`
let c = [0; true];
//~^ ERROR mismatched types
//~| expected usize, found bool
- //~| ERROR expected usize for repeat count, found boolean [E0306]
+ //~| ERROR expected `usize` for repeat count, found boolean [E0306]
+ //~| expected `usize`
let d = [0; 0.5];
//~^ ERROR mismatched types
//~| expected type `usize`
//~| found type `{float}`
//~| expected usize, found floating-point variable
- //~| ERROR expected usize for repeat count, found float [E0306]
+ //~| ERROR expected `usize` for repeat count, found float [E0306]
+ //~| expected `usize`
let e = [0; "foo"];
//~^ ERROR mismatched types
//~| expected type `usize`
//~| found type `&'static str`
//~| expected usize, found &-ptr
- //~| ERROR expected usize for repeat count, found string literal [E0306]
+ //~| ERROR expected `usize` for repeat count, found string literal [E0306]
+ //~| expected `usize`
let f = [0; -4_isize];
//~^ ERROR constant evaluation error
//~| expected usize, found isize
//~| expected type `usize`
//~| found type `main::G`
//~| expected usize, found struct `main::G`
- //~| ERROR expected usize for repeat count, found struct [E0306]
+ //~| ERROR expected `usize` for repeat count, found struct [E0306]
+ //~| expected `usize`
}
impl Bar {
fn f() {
let _: <Self>::Baz = true;
-//~^ERROR: ambiguous associated type; specify the type using the syntax `<Bar as Trait>::Baz`
+ //~^ ERROR ambiguous associated type
+ //~| NOTE ambiguous associated type
+ //~| NOTE specify the type using the syntax `<Bar as Trait>::Baz`
let _: Self::Baz = true;
-//~^ERROR: ambiguous associated type; specify the type using the syntax `<Bar as Trait>::Baz`
+ //~^ ERROR ambiguous associated type
+ //~| NOTE ambiguous associated type
+ //~| NOTE specify the type using the syntax `<Bar as Trait>::Baz`
}
}
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() {}
// except according to those terms.
fn foo1<T:Copy<U>, 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<Send> {}
-//~^ ERROR: wrong number of type arguments: expected 0, found 1
+//~^ ERROR E0244
+//~| NOTE expected no type arguments, found 1
struct MyStruct1<T: Copy<T>>;
-//~^ 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() {
}
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
}
}
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
}
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
}
trait Trait {}
fn f<F:Trait(isize) -> 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() {}
// 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
}
}
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
}
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};
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
}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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));
+}
--- /dev/null
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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));
+}