Auto merge of #35407 - eddyb:rollup, r=eddyb
Rollup of 21 pull requests - Successful merges: #33951, #34916, #35287, #35288, #35351, #35353, #35356, #35362, #35363, #35364, #35366, #35368, #35370, #35372, #35373, #35374, #35375, #35376, #35380, #35393, #35394 - Failed merges: #35331, #35395
This commit is contained in:
commit
444ff9fbfb
56 changed files with 701 additions and 260 deletions
|
@ -1,4 +1,4 @@
|
|||
.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
|
||||
|
@ -299,7 +299,7 @@ To build an executable with debug info:
|
|||
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.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.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
|
||||
|
|
|
@ -34,12 +34,13 @@
|
|||
/// 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
|
||||
|
@ -50,13 +51,13 @@
|
|||
/// ```
|
||||
/// #![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
|
||||
|
@ -74,7 +75,6 @@
|
|||
/// // 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
|
||||
|
@ -82,11 +82,11 @@
|
|||
/// 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);
|
||||
/// ```
|
||||
|
|
|
@ -47,8 +47,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
|
||||
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,
|
||||
|
|
|
@ -942,9 +942,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
|||
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), \
|
||||
|
|
|
@ -424,10 +424,15 @@ fn check_exhaustive<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>,
|
|||
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();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1337,10 +1337,13 @@ pub fn eval_length<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
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) => {
|
||||
|
|
|
@ -38,16 +38,18 @@ impl<'a> AstValidator<'a> {
|
|||
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);
|
||||
|
@ -71,10 +73,10 @@ impl<'a> AstValidator<'a> {
|
|||
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)
|
||||
|
@ -82,9 +84,12 @@ impl<'a> Visitor for AstValidator<'a> {
|
|||
|
||||
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);
|
||||
}
|
||||
_ => {}
|
||||
|
@ -97,10 +102,13 @@ impl<'a> Visitor for AstValidator<'a> {
|
|||
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();
|
||||
});
|
||||
}
|
||||
|
@ -114,10 +122,10 @@ impl<'a> Visitor for AstValidator<'a> {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,8 +137,8 @@ impl<'a> Visitor for AstValidator<'a> {
|
|||
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) => {
|
||||
|
@ -140,15 +148,18 @@ impl<'a> Visitor for AstValidator<'a> {
|
|||
}
|
||||
}
|
||||
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 {
|
||||
|
@ -167,11 +178,14 @@ impl<'a> Visitor for AstValidator<'a> {
|
|||
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();
|
||||
});
|
||||
|
@ -182,16 +196,21 @@ impl<'a> Visitor for AstValidator<'a> {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,10 +219,10 @@ impl<'a> Visitor for AstValidator<'a> {
|
|||
|
||||
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");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
// 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};
|
||||
|
@ -71,12 +71,12 @@ struct CheckCrateVisitor<'a, 'tcx: 'a> {
|
|||
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;
|
||||
|
@ -87,17 +87,17 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
|
|||
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 {
|
||||
|
@ -111,13 +111,17 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
|
|||
}
|
||||
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| {
|
||||
|
@ -143,9 +147,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -153,7 +155,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
|
|||
Mode::Var
|
||||
}
|
||||
}
|
||||
_ => Mode::Var
|
||||
_ => Mode::Var,
|
||||
};
|
||||
|
||||
let qualif = self.with_mode(mode, |this| {
|
||||
|
@ -175,11 +177,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
|
|||
}
|
||||
|
||||
/// 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(),
|
||||
|
@ -285,13 +283,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
|
|||
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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,13 +301,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
|
|||
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);
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
|
|||
// 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 {
|
||||
|
@ -354,7 +354,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
|
|||
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;
|
||||
}
|
||||
_ => {}
|
||||
|
@ -365,7 +366,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
|
|||
}
|
||||
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.
|
||||
|
@ -405,17 +406,18 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
|
|||
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())
|
||||
}
|
||||
|
@ -434,8 +436,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
|
|||
/// 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() => {
|
||||
|
@ -635,12 +636,9 @@ fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Exp
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
@ -648,12 +646,13 @@ fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Exp
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -675,7 +674,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
|
|||
|
||||
Categorization::Rvalue(..) |
|
||||
Categorization::Upvar(..) |
|
||||
Categorization::Local(..) => break
|
||||
Categorization::Local(..) => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -685,8 +684,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
|
|||
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
|
||||
|
@ -695,7 +693,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
|
|||
euv::LoanCause::AutoUnsafe => {
|
||||
return;
|
||||
}
|
||||
_ => { }
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let mut cur = &cmt;
|
||||
|
@ -715,7 +713,8 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
|
|||
// 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,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -732,27 +731,20 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> {
|
|||
}
|
||||
|
||||
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) {}
|
||||
}
|
||||
|
|
|
@ -121,11 +121,11 @@ All statics and constants need to resolve to a value in an acyclic manner.
|
|||
|
||||
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;
|
||||
```
|
||||
|
@ -135,7 +135,7 @@ E0267: r##"
|
|||
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
|
||||
```
|
||||
|
||||
|
@ -159,7 +159,7 @@ This error indicates the use of a loop keyword (`break` or `continue`) outside
|
|||
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
|
||||
}
|
||||
|
|
|
@ -28,12 +28,15 @@
|
|||
#![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;
|
||||
|
||||
|
|
|
@ -19,19 +19,24 @@ use syntax_pos::Span;
|
|||
|
||||
#[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> {
|
||||
|
@ -53,14 +58,14 @@ 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;
|
||||
|
@ -72,12 +77,10 @@ impl<'a> CheckLoopVisitor<'a> {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,11 @@ use syntax::visit::Visitor;
|
|||
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)]
|
||||
|
@ -32,9 +34,13 @@ struct CheckNoAsm<'a> {
|
|||
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)
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
|
||||
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};
|
||||
|
@ -41,18 +41,17 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> {
|
|||
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);
|
||||
}
|
||||
|
@ -67,8 +66,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
@ -80,8 +78,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> {
|
|||
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);
|
||||
}
|
||||
_ => {}
|
||||
|
@ -117,7 +114,8 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
|
|||
}
|
||||
|
||||
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,
|
||||
|
@ -129,7 +127,8 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
|
|||
}
|
||||
}
|
||||
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) {
|
||||
|
@ -146,7 +145,9 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
|
|||
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");
|
||||
|
@ -170,7 +171,9 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
|
|||
// 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;
|
||||
}
|
||||
|
@ -203,14 +206,19 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
|
|||
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) {
|
||||
|
@ -246,18 +254,14 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
|
|||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -268,9 +272,9 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
|
|||
// 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();
|
||||
|
@ -283,10 +287,10 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
_ => (),
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
intravisit::walk_expr(self, e);
|
||||
}
|
||||
|
|
|
@ -146,6 +146,7 @@ mod foo {
|
|||
}
|
||||
|
||||
use foo::MyTrait::do_something;
|
||||
// error: `do_something` is not directly importable
|
||||
|
||||
fn main() {}
|
||||
```
|
||||
|
@ -153,6 +154,45 @@ 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.
|
||||
|
@ -1237,7 +1277,6 @@ impl Foo for i32 {}
|
|||
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
|
||||
|
|
|
@ -310,8 +310,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
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);
|
||||
}
|
||||
|
@ -2269,9 +2273,25 @@ fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
|
|||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -847,7 +847,9 @@ fn check_trait_fn_not_const<'a,'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
// 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -993,7 +995,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
// 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());
|
||||
|
||||
|
@ -1014,11 +1016,18 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
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) => {
|
||||
|
@ -1037,11 +1046,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
&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(_) => {
|
||||
|
@ -1055,11 +1069,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
|||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1251,8 +1270,9 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
|
|||
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);
|
||||
|
@ -3406,8 +3426,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3415,8 +3437,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
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());
|
||||
|
|
|
@ -2317,8 +2317,12 @@ fn report_unused_parameter(ccx: &CrateCtxt,
|
|||
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();
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ use sys_common::{AsInner, FromInner};
|
|||
#[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",
|
||||
|
@ -485,9 +485,11 @@ impl File {
|
|||
|
||||
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)
|
||||
|
|
|
@ -324,6 +324,8 @@ impl File {
|
|||
|
||||
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),
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
// 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() {
|
||||
|
|
|
@ -9,13 +9,19 @@
|
|||
// 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() {
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
struct Foo<'a>(&'a str);
|
||||
struct Buzz<'a, 'b>(&'a str, &'b str);
|
||||
|
||||
enum Bar {
|
||||
A,
|
||||
|
@ -16,9 +17,19 @@ enum Bar {
|
|||
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() {
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
// 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() {
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
struct Foo;
|
||||
|
||||
impl<T: Default> Foo { //~ ERROR E0207
|
||||
//~| NOTE unconstrained lifetime parameter
|
||||
fn get(&self) -> T {
|
||||
<T as Default>::default()
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ impl Foo for isize {
|
|||
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() {
|
||||
}
|
||||
|
|
19
src/test/compile-fail/E0253.rs
Normal file
19
src/test/compile-fail/E0253.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// 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() {}
|
21
src/test/compile-fail/E0254.rs
Normal file
21
src/test/compile-fail/E0254.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <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() {}
|
19
src/test/compile-fail/E0255.rs
Normal file
19
src/test/compile-fail/E0255.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// 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() {}
|
14
src/test/compile-fail/E0259.rs
Normal file
14
src/test/compile-fail/E0259.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// 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() {}
|
19
src/test/compile-fail/E0260.rs
Normal file
19
src/test/compile-fail/E0260.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// 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() {}
|
17
src/test/compile-fail/E0261.rs
Normal file
17
src/test/compile-fail/E0261.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
// 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() {}
|
13
src/test/compile-fail/E0262.rs
Normal file
13
src/test/compile-fail/E0262.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
// 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() {}
|
13
src/test/compile-fail/E0263.rs
Normal file
13
src/test/compile-fail/E0263.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
// 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() {}
|
18
src/test/compile-fail/E0264.rs
Normal file
18
src/test/compile-fail/E0264.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
// 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() {}
|
13
src/test/compile-fail/E0267.rs
Normal file
13
src/test/compile-fail/E0267.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
// 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
|
||||
}
|
13
src/test/compile-fail/E0268.rs
Normal file
13
src/test/compile-fail/E0268.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
// 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
|
||||
}
|
|
@ -8,9 +8,17 @@
|
|||
// 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() {
|
||||
}
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
// 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); }
|
||||
|
|
|
@ -22,4 +22,6 @@ fn main() {
|
|||
let mut books = vec![1,2,3];
|
||||
spawn(|| books.push(4));
|
||||
//~^ ERROR E0373
|
||||
//~| NOTE `books` is borrowed here
|
||||
//~| NOTE may outlive borrowed value `books`
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ fn foo<'a>(x: &'a i32) -> Box<FnMut()+'a> {
|
|||
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() { }
|
||||
|
|
|
@ -20,7 +20,9 @@ trait Foo {
|
|||
}
|
||||
|
||||
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() { }
|
||||
|
|
|
@ -25,17 +25,35 @@ const X3: usize = -42 && -39; //~ ERROR E0080
|
|||
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;
|
||||
|
|
|
@ -19,6 +19,7 @@ trait Fun {
|
|||
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[..]
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
|
||||
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;
|
||||
|
@ -21,6 +23,7 @@ impl Foo for FooConstForMethod {
|
|||
//~^ ERROR E0046
|
||||
const bar: u64 = 1;
|
||||
//~^ ERROR E0323
|
||||
//~| NOTE does not match trait
|
||||
const MY_CONST: u32 = 1;
|
||||
}
|
||||
|
||||
|
@ -31,6 +34,7 @@ impl Foo for FooMethodForConst {
|
|||
fn bar(&self) {}
|
||||
fn MY_CONST() {}
|
||||
//~^ ERROR E0324
|
||||
//~| NOTE does not match trait
|
||||
}
|
||||
|
||||
pub struct FooTypeForMethod;
|
||||
|
@ -39,6 +43,7 @@ impl Foo for FooTypeForMethod {
|
|||
//~^ ERROR E0046
|
||||
type bar = u64;
|
||||
//~^ ERROR E0325
|
||||
//~| NOTE does not match trait
|
||||
const MY_CONST: u32 = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,13 +12,18 @@ const N: isize = 1;
|
|||
|
||||
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() {}
|
||||
|
|
|
@ -21,6 +21,7 @@ fn crash_please() {
|
|||
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>> {
|
||||
|
|
|
@ -16,6 +16,7 @@ pub trait D {
|
|||
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() {}
|
||||
|
|
|
@ -14,6 +14,7 @@ pub trait D {
|
|||
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() {}
|
||||
|
|
|
@ -16,5 +16,6 @@ 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`
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ pub trait MethodType {
|
|||
pub struct MTFn;
|
||||
|
||||
impl<'a> MethodType for MTFn { //~ ERROR E0207
|
||||
//~| NOTE unconstrained lifetime parameter
|
||||
type GetProp = fmt::Debug + 'a;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,10 @@ fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> {
|
|||
// 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() {
|
||||
|
|
|
@ -19,6 +19,7 @@ struct 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 } => (),
|
||||
|
@ -35,6 +36,7 @@ enum Color {
|
|||
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 => ()
|
||||
}
|
||||
|
@ -47,6 +49,7 @@ enum Direction {
|
|||
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 => ()
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +61,7 @@ enum ExcessiveEnum {
|
|||
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 => ()
|
||||
}
|
||||
|
@ -66,6 +70,7 @@ fn enum_with_excessive_missing_variants() {
|
|||
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 } => (),
|
||||
|
@ -82,6 +87,7 @@ fn vectors_with_nested_enums() {
|
|||
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, _] => (),
|
||||
|
@ -95,6 +101,7 @@ fn vectors_with_nested_enums() {
|
|||
fn missing_nil() {
|
||||
match ((), false) {
|
||||
//~^ ERROR non-exhaustive patterns: `((), false)` not covered
|
||||
//~| NOTE pattern `((), false)` not covered
|
||||
((), true) => ()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
|
||||
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
|
||||
|
@ -31,6 +35,10 @@ fn escaping_borrow_of_closure_params_1() {
|
|||
|
||||
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
|
||||
|
@ -64,7 +72,11 @@ fn escaping_borrow_of_fn_params_1() {
|
|||
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);
|
||||
};
|
||||
|
||||
|
@ -75,7 +87,11 @@ fn escaping_borrow_of_fn_params_2() {
|
|||
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)
|
||||
};
|
||||
|
||||
|
@ -99,7 +115,11 @@ fn escaping_borrow_of_method_params_1() {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +133,11 @@ fn escaping_borrow_of_method_params_2() {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +165,11 @@ fn escaping_borrow_of_trait_impl_params_1() {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +184,11 @@ fn escaping_borrow_of_trait_impl_params_2() {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +216,11 @@ fn escaping_borrow_of_trait_default_params_1() {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +234,11 @@ fn escaping_borrow_of_trait_default_params_2() {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,11 @@ fn ignore<F>(_f: F) where F: for<'z> FnOnce(&'z isize) -> &'z isize {}
|
|||
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
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -20,23 +20,27 @@ fn main() {
|
|||
//~| 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
|
||||
|
@ -55,5 +59,6 @@ fn main() {
|
|||
//~| 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`
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue