diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index c58fe881c8a62..5467c9f9d5bf9 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -40,7 +40,7 @@ def v(*args): options.append(Option(*args, value=True)) -o("debug", "rust.debug", "debug mode; disables optimization unless `--enable-optimize` given") +o("debug", "rust.debug", "enables debugging environment; does not affect optimization of bootstrapped code (use `--disable-optimize` for that)") o("docs", "build.docs", "build standard library documentation") o("compiler-docs", "build.compiler-docs", "build compiler documentation") o("optimize-tests", "rust.optimize-tests", "build tests with optimizations") diff --git a/src/ci/docker/disabled/dist-powerpcspe-linux/Dockerfile b/src/ci/docker/disabled/dist-powerpcspe-linux/Dockerfile new file mode 100644 index 0000000000000..3227819dad54d --- /dev/null +++ b/src/ci/docker/disabled/dist-powerpcspe-linux/Dockerfile @@ -0,0 +1,26 @@ +FROM ubuntu:16.04 + +RUN apt-get update && apt-get install -y --no-install-recommends \ + g++ \ + make \ + file \ + curl \ + ca-certificates \ + python2.7 \ + git \ + cmake \ + sudo \ + gdb \ + xz-utils \ + g++-powerpc-linux-gnuspe \ + libssl-dev \ + pkg-config + + +COPY scripts/sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +ENV HOSTS=powerpc-unknown-linux-gnuspe + +ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs +ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index dc5f736172503..c5bcfd48cf39a 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -291,10 +291,8 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>, return true; } - // (To be) stable attribute for #[lang = "panic_impl"] - if attr::contains_name(attrs, "panic_implementation") || - attr::contains_name(attrs, "panic_handler") - { + // Stable attribute for #[lang = "panic_impl"] + if attr::contains_name(attrs, "panic_handler") { return true; } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index cce8081daf28e..55ffa50e7c896 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -204,9 +204,7 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> { if let Some(value) = attribute.value_str() { return Some((value, attribute.span)); } - } else if attribute.check_name("panic_implementation") || - attribute.check_name("panic_handler") - { + } else if attribute.check_name("panic_handler") { return Some((Symbol::intern("panic_impl"), attribute.span)) } else if attribute.check_name("alloc_error_handler") { return Some((Symbol::intern("oom"), attribute.span)) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index c662ed6a6bf06..36bc2edcf584e 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -506,25 +506,25 @@ pub enum BorrowKind { /// implicit closure bindings. It is needed when the closure is /// borrowing or mutating a mutable referent, e.g.: /// - /// let x: &mut isize = ...; - /// let y = || *x += 5; + /// let x: &mut isize = ...; + /// let y = || *x += 5; /// /// If we were to try to translate this closure into a more explicit /// form, we'd encounter an error with the code as written: /// - /// struct Env { x: & &mut isize } - /// let x: &mut isize = ...; - /// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn - /// fn fn_ptr(env: &mut Env) { **env.x += 5; } + /// struct Env { x: & &mut isize } + /// let x: &mut isize = ...; + /// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn + /// fn fn_ptr(env: &mut Env) { **env.x += 5; } /// /// This is then illegal because you cannot mutate an `&mut` found /// in an aliasable location. To solve, you'd have to translate with /// an `&mut` borrow: /// - /// struct Env { x: & &mut isize } - /// let x: &mut isize = ...; - /// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x - /// fn fn_ptr(env: &mut Env) { **env.x += 5; } + /// struct Env { x: & &mut isize } + /// let x: &mut isize = ...; + /// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x + /// fn fn_ptr(env: &mut Env) { **env.x += 5; } /// /// Now the assignment to `**env.x` is legal, but creating a /// mutable pointer to `x` is not because `x` is not mutable. We diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index f2ae5774da875..735ceef229a22 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -238,8 +238,8 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { is non-empty", pat_ty)); span_help!(&mut err, scrut.span, - "Please ensure that all possible cases are being handled; \ - possibly adding wildcards or more match arms."); + "ensure that all possible cases are being handled, \ + possibly by adding wildcards or more match arms"); err.emit(); } // If the type *is* uninhabited, it's vacuously exhaustive diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index bed938a534f4d..cb2a750f4e3b6 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -140,7 +140,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> "unchecked_shr" => BinOp::Shr, _ => bug!("Already checked for int ops") }; - let (val, overflowed) = self.binary_op_val(bin_op, l, r)?; + let (val, overflowed) = self.binary_op_imm(bin_op, l, r)?; if overflowed { let layout = self.layout_of(substs.type_at(0))?; let r_val = r.to_scalar()?.to_bits(layout.size)?; diff --git a/src/librustc_mir/interpret/operator.rs b/src/librustc_mir/interpret/operator.rs index 2c6b8732fdbb9..31824d5ec4a93 100644 --- a/src/librustc_mir/interpret/operator.rs +++ b/src/librustc_mir/interpret/operator.rs @@ -28,7 +28,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> right: ImmTy<'tcx, M::PointerTag>, dest: PlaceTy<'tcx, M::PointerTag>, ) -> EvalResult<'tcx> { - let (val, overflowed) = self.binary_op_val(op, left, right)?; + let (val, overflowed) = self.binary_op_imm(op, left, right)?; let val = Immediate::ScalarPair(val.into(), Scalar::from_bool(overflowed).into()); self.write_immediate(val, dest) } @@ -42,7 +42,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> right: ImmTy<'tcx, M::PointerTag>, dest: PlaceTy<'tcx, M::PointerTag>, ) -> EvalResult<'tcx> { - let (val, _overflowed) = self.binary_op_val(op, left, right)?; + let (val, _overflowed) = self.binary_op_imm(op, left, right)?; self.write_scalar(val, dest) } } @@ -283,9 +283,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> } /// Convenience wrapper that's useful when keeping the layout together with the - /// value. + /// immediate value. #[inline] - pub fn binary_op_val( + pub fn binary_op_imm( &self, bin_op: mir::BinOp, left: ImmTy<'tcx, M::PointerTag>, diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index 2c2bfc995e4d7..6dba020120f84 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -511,7 +511,7 @@ fn mono_item_visibility( // // * First is weak lang items. These are basically mechanisms for // libcore to forward-reference symbols defined later in crates like - // the standard library or `#[panic_implementation]` definitions. The + // the standard library or `#[panic_handler]` definitions. The // definition of these weak lang items needs to be referenceable by // libcore, so we're no longer a candidate for internalization. // Removal of these functions can't be done by LLVM but rather must be diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 52ef37ab40e57..4f92ba400481b 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -455,7 +455,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { })?; trace!("const evaluating {:?} for {:?} and {:?}", op, left, right); let (val, overflow) = self.use_ecx(source_info, |this| { - this.ecx.binary_op_val(op, l, r) + this.ecx.binary_op_imm(op, l, r) })?; let val = if let Rvalue::CheckedBinaryOp(..) = *rvalue { Immediate::ScalarPair( diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index d5f344346c2d1..43a5fdb7a025f 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -449,6 +449,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> { return Err(Determinacy::Determined); } } + Def::Err => { + return Err(Determinacy::Determined); + } _ => panic!("expected `Def::Macro` or `Def::NonMacroAttr`"), } diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 11448750618e2..637f3eaae9a6a 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -289,8 +289,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Trait must have a method named `m_name` and it should not have // type parameters or early-bound regions. let tcx = self.tcx; - let method_item = - self.associated_item(trait_def_id, m_name, Namespace::Value).unwrap(); + let method_item = match self.associated_item(trait_def_id, m_name, Namespace::Value) { + Some(method_item) => method_item, + None => { + tcx.sess.delay_span_bug(span, + "operator trait does not have corresponding operator method"); + return None; + } + }; let def_id = method_item.def_id; let generics = tcx.generics_of(def_id); assert_eq!(generics.params.len(), 0); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 791b5a0bdd92a..7dfdb926c60ef 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1167,7 +1167,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, } } - // Check that a function marked as `#[panic_implementation]` has signature `fn(&PanicInfo) -> !` + // Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !` if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() { if panic_impl_did == fcx.tcx.hir.local_def_id(fn_id) { if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() { diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 017949291bcf1..49012a7d34196 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1755,12 +1755,19 @@ pub fn canonicalize>(path: P) -> io::Result { /// /// [changes]: ../io/index.html#platform-specific-behavior /// +/// **NOTE**: If a parent of the given path doesn't exist, this function will +/// return an error. To create a directory and all its missing parents at the +/// same time, use the [`create_dir_all`] function. +/// /// # Errors /// /// This function will return an error in the following situations, but is not /// limited to just these cases: /// /// * User lacks permissions to create directory at `path`. +/// * A parent of the given path doesn't exist. (To create a directory and all +/// its missing parents at the same time, use the [`create_dir_all`] +/// function.) /// * `path` already exists. /// /// # Examples diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index ccbead7cc2f77..4df4751117244 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -146,13 +146,13 @@ macro_rules! thread_local { // process multiple declarations ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => ( - __thread_local_inner!($(#[$attr])* $vis $name, $t, $init); - thread_local!($($rest)*); + $crate::__thread_local_inner!($(#[$attr])* $vis $name, $t, $init); + $crate::thread_local!($($rest)*); ); // handle a single declaration ($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => ( - __thread_local_inner!($(#[$attr])* $vis $name, $t, $init); + $crate::__thread_local_inner!($(#[$attr])* $vis $name, $t, $init); ); } @@ -202,7 +202,7 @@ macro_rules! __thread_local_inner { }; ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $init:expr) => { $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> = - __thread_local_inner!(@key $(#[$attr])* $vis $name, $t, $init); + $crate::__thread_local_inner!(@key $(#[$attr])* $vis $name, $t, $init); } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 6abc506c07b73..cb15c517c1785 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -349,7 +349,7 @@ declare_features! ( (active, abi_thiscall, "1.19.0", None, None), // Allows a test to fail without failing the whole suite - (active, allow_fail, "1.19.0", Some(42219), None), + (active, allow_fail, "1.19.0", Some(46488), None), // Allows unsized tuple coercion. (active, unsized_tuple_coercion, "1.20.0", Some(42877), None), @@ -376,7 +376,7 @@ declare_features! ( (active, non_exhaustive, "1.22.0", Some(44109), None), // `crate` as visibility modifier, synonymous to `pub(crate)` - (active, crate_visibility_modifier, "1.23.0", Some(45388), None), + (active, crate_visibility_modifier, "1.23.0", Some(53120), None), // extern types (active, extern_types, "1.23.0", Some(43467), None), @@ -391,13 +391,13 @@ declare_features! ( (active, generic_associated_types, "1.23.0", Some(44265), None), // `extern` in paths - (active, extern_in_paths, "1.23.0", Some(44660), None), + (active, extern_in_paths, "1.23.0", Some(55600), None), // Use `?` as the Kleene "at most one" operator (active, macro_at_most_once_rep, "1.25.0", Some(48075), None), // Infer static outlives requirements; RFC 2093 - (active, infer_static_outlives_requirements, "1.26.0", Some(44493), None), + (active, infer_static_outlives_requirements, "1.26.0", Some(54185), None), // Multiple patterns with `|` in `if let` and `while let` (active, if_while_or_patterns, "1.26.0", Some(48215), None), @@ -448,9 +448,6 @@ declare_features! ( // Integer match exhaustiveness checking (active, exhaustive_integer_patterns, "1.30.0", Some(50907), None), - // RFC 2070: #[panic_implementation] / #[panic_handler] - (active, panic_implementation, "1.28.0", Some(44489), None), - // #[doc(keyword = "...")] (active, doc_keyword, "1.28.0", Some(51315), None), @@ -466,7 +463,7 @@ declare_features! ( (active, test_2018_feature, "1.31.0", Some(0), Some(Edition::Edition2018)), // Support for arbitrary delimited token streams in non-macro attributes - (active, unrestricted_attribute_tokens, "1.30.0", Some(44690), None), + (active, unrestricted_attribute_tokens, "1.30.0", Some(55208), None), // Allows `use x::y;` to resolve through `self::x`, not just `::x` (active, uniform_paths, "1.30.0", Some(53130), None), @@ -503,7 +500,7 @@ declare_features! ( (active, underscore_const_names, "1.31.0", Some(54912), None), // `extern crate foo as bar;` puts `bar` into extern prelude. - (active, extern_crate_item_prelude, "1.31.0", Some(54658), None), + (active, extern_crate_item_prelude, "1.31.0", Some(55599), None), // `reason = ` in lint attributes and `expect` lint attribute (active, lint_reasons, "1.31.0", Some(54503), None), @@ -541,6 +538,8 @@ declare_features! ( Some("subsumed by `#![feature(proc_macro_hygiene)]`")), (removed, proc_macro_gen, "1.27.0", Some(54727), None, Some("subsumed by `#![feature(proc_macro_hygiene)]`")), + (removed, panic_implementation, "1.28.0", Some(44489), None, + Some("subsumed by `#[panic_handler]`")), ); declare_features! ( @@ -1160,16 +1159,6 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG "infer 'static lifetime requirements", cfg_fn!(infer_static_outlives_requirements))), - // RFC 2070 (deprecated attribute name) - ("panic_implementation", - Normal, - Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/44489\ - #issuecomment-415140224", - Some("replace this attribute with `#[panic_handler]`")), - "panic_implementation", - "this attribute was renamed to `panic_handler`", - cfg_fn!(panic_implementation))), - // RFC 2070 ("panic_handler", Normal, Ungated), diff --git a/src/test/run-make/wasm-symbols-not-imported/foo.rs b/src/test/run-make/wasm-symbols-not-imported/foo.rs index 156db486a4767..dcc2f4f522300 100644 --- a/src/test/run-make/wasm-symbols-not-imported/foo.rs +++ b/src/test/run-make/wasm-symbols-not-imported/foo.rs @@ -9,8 +9,6 @@ // except according to those terms. #![crate_type = "cdylib"] - -#![feature(panic_implementation)] #![no_std] use core::panic::PanicInfo; @@ -20,7 +18,7 @@ pub extern fn foo() { panic!() } -#[panic_implementation] +#[panic_handler] fn panic(_info: &PanicInfo) -> ! { loop {} } diff --git a/src/test/ui/panic-implementation/panic-implementation-deprecated.rs b/src/test/run-pass/thread-local-not-in-prelude.rs similarity index 70% rename from src/test/ui/panic-implementation/panic-implementation-deprecated.rs rename to src/test/run-pass/thread-local-not-in-prelude.rs index c4bec01f6af61..0c365597b82a3 100644 --- a/src/test/ui/panic-implementation/panic-implementation-deprecated.rs +++ b/src/test/run-pass/thread-local-not-in-prelude.rs @@ -8,17 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags:-C panic=abort - -#![deny(deprecated)] -#![feature(panic_implementation)] #![no_std] -use core::panic::PanicInfo; +extern crate std; -#[panic_implementation] -fn panic(info: &PanicInfo) -> ! { - loop {} -} +std::thread_local!(static A: usize = 30); -fn main() {} +fn main() { +} diff --git a/src/test/ui/binop/binop-move-semantics.nll.stderr b/src/test/ui/binop/binop-move-semantics.nll.stderr index 545a60f6770d9..612375f904783 100644 --- a/src/test/ui/binop/binop-move-semantics.nll.stderr +++ b/src/test/ui/binop/binop-move-semantics.nll.stderr @@ -20,6 +20,29 @@ LL | x.clone(); //~ ERROR: use of moved value | = note: move occurs because `x` has type `T`, which does not implement the `Copy` trait +error[E0505]: cannot move out of `x` because it is borrowed + --> $DIR/binop-move-semantics.rs:31:5 + | +LL | let m = &x; + | -- borrow of `x` occurs here +... +LL | x //~ ERROR: cannot move out of `x` because it is borrowed + | ^ move out of `x` occurs here +... +LL | use_mut(n); use_imm(m); + | - borrow later used here + +error[E0505]: cannot move out of `y` because it is borrowed + --> $DIR/binop-move-semantics.rs:33:5 + | +LL | let n = &mut y; + | ------ borrow of `y` occurs here +... +LL | y; //~ ERROR: cannot move out of `y` because it is borrowed + | ^ move out of `y` occurs here +LL | use_mut(n); use_imm(m); + | - borrow later used here + error[E0507]: cannot move out of borrowed content --> $DIR/binop-move-semantics.rs:40:5 | @@ -62,7 +85,7 @@ LL | | &mut f; //~ ERROR: cannot borrow `f` as mutable because it is also b | | immutable borrow later used here | mutable borrow occurs here -error: aborting due to 6 previous errors +error: aborting due to 8 previous errors -Some errors occurred: E0382, E0502, E0507. +Some errors occurred: E0382, E0502, E0505, E0507. For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/ui/binop/binop-move-semantics.rs b/src/test/ui/binop/binop-move-semantics.rs index cff0064497aff..f6fad8b46dd9d 100644 --- a/src/test/ui/binop/binop-move-semantics.rs +++ b/src/test/ui/binop/binop-move-semantics.rs @@ -31,8 +31,8 @@ fn move_borrowed>(x: T, mut y: T) { x //~ ERROR: cannot move out of `x` because it is borrowed + y; //~ ERROR: cannot move out of `y` because it is borrowed + use_mut(n); use_imm(m); } - fn illegal_dereference>(mut x: T, y: T) { let m = &mut x; let n = &y; @@ -40,8 +40,8 @@ fn illegal_dereference>(mut x: T, y: T) { *m //~ ERROR: cannot move out of borrowed content + *n; //~ ERROR: cannot move out of borrowed content + use_imm(n); use_mut(m); } - struct Foo; impl<'a, 'b> Add<&'b Foo> for &'a mut Foo { @@ -73,3 +73,6 @@ fn immut_plus_mut() { } fn main() {} + +fn use_mut(_: &mut T) { } +fn use_imm(_: &T) { } diff --git a/src/test/ui/borrowck/borrowck-closures-mut-of-imm.nll.stderr b/src/test/ui/borrowck/borrowck-closures-mut-of-imm.nll.stderr index e8fae63a5d617..160a84c480cd3 100644 --- a/src/test/ui/borrowck/borrowck-closures-mut-of-imm.nll.stderr +++ b/src/test/ui/borrowck/borrowck-closures-mut-of-imm.nll.stderr @@ -1,15 +1,32 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference - --> $DIR/borrowck-closures-mut-of-imm.rs:23:21 + --> $DIR/borrowck-closures-mut-of-imm.rs:23:25 | -LL | let c1 = || set(&mut *x); - | ^^^^^^^ cannot borrow as mutable +LL | let mut c1 = || set(&mut *x); + | ^^^^^^^ cannot borrow as mutable error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference - --> $DIR/borrowck-closures-mut-of-imm.rs:25:21 + --> $DIR/borrowck-closures-mut-of-imm.rs:25:25 | -LL | let c2 = || set(&mut *x); - | ^^^^^^^ cannot borrow as mutable +LL | let mut c2 = || set(&mut *x); + | ^^^^^^^ cannot borrow as mutable -error: aborting due to 2 previous errors +error[E0524]: two closures require unique access to `x` at the same time + --> $DIR/borrowck-closures-mut-of-imm.rs:25:18 + | +LL | let mut c1 = || set(&mut *x); + | -- - first borrow occurs due to use of `x` in closure + | | + | first closure is constructed here +LL | //~^ ERROR cannot borrow +LL | let mut c2 = || set(&mut *x); + | ^^ - second borrow occurs due to use of `x` in closure + | | + | second closure is constructed here +... +LL | c2(); c1(); + | -- first borrow later used here + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0596`. +Some errors occurred: E0524, E0596. +For more information about an error, try `rustc --explain E0524`. diff --git a/src/test/ui/borrowck/borrowck-closures-mut-of-imm.rs b/src/test/ui/borrowck/borrowck-closures-mut-of-imm.rs index dc2f0e8395f08..3bf4f17fde1a8 100644 --- a/src/test/ui/borrowck/borrowck-closures-mut-of-imm.rs +++ b/src/test/ui/borrowck/borrowck-closures-mut-of-imm.rs @@ -20,11 +20,12 @@ fn set(x: &mut isize) { } fn a(x: &isize) { - let c1 = || set(&mut *x); + let mut c1 = || set(&mut *x); //~^ ERROR cannot borrow - let c2 = || set(&mut *x); + let mut c2 = || set(&mut *x); //~^ ERROR cannot borrow //~| ERROR two closures require unique access to `x` at the same time + c2(); c1(); } fn main() { diff --git a/src/test/ui/borrowck/borrowck-closures-mut-of-imm.stderr b/src/test/ui/borrowck/borrowck-closures-mut-of-imm.stderr index 87eb52b6aa605..c248595d57119 100644 --- a/src/test/ui/borrowck/borrowck-closures-mut-of-imm.stderr +++ b/src/test/ui/borrowck/borrowck-closures-mut-of-imm.stderr @@ -1,30 +1,30 @@ error[E0524]: two closures require unique access to `x` at the same time - --> $DIR/borrowck-closures-mut-of-imm.rs:25:14 + --> $DIR/borrowck-closures-mut-of-imm.rs:25:18 | -LL | let c1 = || set(&mut *x); - | -- - previous borrow occurs due to use of `x` in closure - | | - | first closure is constructed here +LL | let mut c1 = || set(&mut *x); + | -- - previous borrow occurs due to use of `x` in closure + | | + | first closure is constructed here LL | //~^ ERROR cannot borrow -LL | let c2 = || set(&mut *x); - | ^^ - borrow occurs due to use of `x` in closure - | | - | second closure is constructed here +LL | let mut c2 = || set(&mut *x); + | ^^ - borrow occurs due to use of `x` in closure + | | + | second closure is constructed here ... LL | } | - borrow from first closure ends here error[E0596]: cannot borrow immutable borrowed content `***x` as mutable - --> $DIR/borrowck-closures-mut-of-imm.rs:23:26 + --> $DIR/borrowck-closures-mut-of-imm.rs:23:30 | -LL | let c1 = || set(&mut *x); - | ^^ cannot borrow as mutable +LL | let mut c1 = || set(&mut *x); + | ^^ cannot borrow as mutable error[E0596]: cannot borrow immutable borrowed content `***x` as mutable - --> $DIR/borrowck-closures-mut-of-imm.rs:25:26 + --> $DIR/borrowck-closures-mut-of-imm.rs:25:30 | -LL | let c2 = || set(&mut *x); - | ^^ cannot borrow as mutable +LL | let mut c2 = || set(&mut *x); + | ^^ cannot borrow as mutable error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-closures-mut-of-mut.nll.stderr b/src/test/ui/borrowck/borrowck-closures-mut-of-mut.nll.stderr new file mode 100644 index 0000000000000..18f95f232cdd3 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-closures-mut-of-mut.nll.stderr @@ -0,0 +1,18 @@ +error[E0524]: two closures require unique access to `x` at the same time + --> $DIR/borrowck-closures-mut-of-mut.rs:14:18 + | +LL | let mut c1 = || set(&mut *x); + | -- - first borrow occurs due to use of `x` in closure + | | + | first closure is constructed here +LL | let mut c2 = || set(&mut *x); + | ^^ - second borrow occurs due to use of `x` in closure + | | + | second closure is constructed here +LL | //~^ ERROR two closures require unique access to `x` at the same time +LL | c2(); c1(); + | -- first borrow later used here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0524`. diff --git a/src/test/ui/borrowck/borrowck-closures-mut-of-mut.rs b/src/test/ui/borrowck/borrowck-closures-mut-of-mut.rs new file mode 100644 index 0000000000000..50c6f2c585ed9 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-closures-mut-of-mut.rs @@ -0,0 +1,20 @@ +// Tests that two closures cannot simultaneously both have mutable +// access to the variable. Related to issue #6801. + +fn get(x: &isize) -> isize { + *x +} + +fn set(x: &mut isize) { + *x = 4; +} + +fn a(x: &mut isize) { + let mut c1 = || set(&mut *x); + let mut c2 = || set(&mut *x); + //~^ ERROR two closures require unique access to `x` at the same time + c2(); c1(); +} + +fn main() { +} diff --git a/src/test/ui/borrowck/borrowck-closures-mut-of-mut.stderr b/src/test/ui/borrowck/borrowck-closures-mut-of-mut.stderr new file mode 100644 index 0000000000000..2c5587710a154 --- /dev/null +++ b/src/test/ui/borrowck/borrowck-closures-mut-of-mut.stderr @@ -0,0 +1,18 @@ +error[E0524]: two closures require unique access to `x` at the same time + --> $DIR/borrowck-closures-mut-of-mut.rs:14:18 + | +LL | let mut c1 = || set(&mut *x); + | -- - previous borrow occurs due to use of `x` in closure + | | + | first closure is constructed here +LL | let mut c2 = || set(&mut *x); + | ^^ - borrow occurs due to use of `x` in closure + | | + | second closure is constructed here +... +LL | } + | - borrow from first closure ends here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0524`. diff --git a/src/test/ui/borrowck/borrowck-lend-flow-loop.stderr b/src/test/ui/borrowck/borrowck-lend-flow-loop.ast.stderr similarity index 81% rename from src/test/ui/borrowck/borrowck-lend-flow-loop.stderr rename to src/test/ui/borrowck/borrowck-lend-flow-loop.ast.stderr index 534e30b564d7f..1844d8275999d 100644 --- a/src/test/ui/borrowck/borrowck-lend-flow-loop.stderr +++ b/src/test/ui/borrowck/borrowck-lend-flow-loop.ast.stderr @@ -4,7 +4,7 @@ error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mu LL | let mut x = &mut v; | - mutable borrow occurs here ... -LL | borrow(&*v); //~ ERROR cannot borrow +LL | borrow(&*v); //[ast]~ ERROR cannot borrow | ^^ immutable borrow occurs here LL | } LL | } @@ -16,7 +16,7 @@ error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mu LL | let mut x = &mut v; | - mutable borrow occurs here LL | for _ in 0..3 { -LL | borrow(&*v); //~ ERROR cannot borrow +LL | borrow(&*v); //[ast]~ ERROR cannot borrow | ^^ immutable borrow occurs here ... LL | } @@ -25,7 +25,7 @@ LL | } error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immutable --> $DIR/borrowck-lend-flow-loop.rs:57:25 | -LL | borrow_mut(&mut *v); //~ ERROR cannot borrow +LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow | ^^ mutable borrow occurs here LL | _x = &v; | - immutable borrow occurs here @@ -36,7 +36,7 @@ LL | } error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immutable --> $DIR/borrowck-lend-flow-loop.rs:69:25 | -LL | borrow_mut(&mut *v); //~ ERROR cannot borrow +LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow | ^^ mutable borrow occurs here LL | _x = &v; | - immutable borrow occurs here @@ -50,7 +50,7 @@ error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immu LL | _x = &v; | - immutable borrow occurs here ... -LL | borrow_mut(&mut *v); //~ ERROR cannot borrow +LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow | ^^ mutable borrow occurs here LL | } | - immutable borrow ends here @@ -61,7 +61,7 @@ error[E0502]: cannot borrow `*v` as mutable because `v` is also borrowed as immu LL | _x = &v; | - immutable borrow occurs here ... -LL | borrow_mut(&mut *v); //~ ERROR cannot borrow +LL | borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow | ^^ mutable borrow occurs here LL | } | - immutable borrow ends here @@ -69,19 +69,19 @@ LL | } error[E0502]: cannot borrow `*v` as immutable because `v` is also borrowed as mutable --> $DIR/borrowck-lend-flow-loop.rs:109:17 | -LL | borrow(&*v); //~ ERROR cannot borrow +LL | borrow(&*v); //[ast]~ ERROR cannot borrow | ^^ immutable borrow occurs here -LL | if cond2 { -LL | x = &mut v; //~ ERROR cannot borrow +... +LL | x = &mut v; //[ast]~ ERROR cannot borrow | - mutable borrow occurs here ... LL | } | - mutable borrow ends here error[E0499]: cannot borrow `v` as mutable more than once at a time - --> $DIR/borrowck-lend-flow-loop.rs:111:22 + --> $DIR/borrowck-lend-flow-loop.rs:112:22 | -LL | x = &mut v; //~ ERROR cannot borrow +LL | x = &mut v; //[ast]~ ERROR cannot borrow | ^ mutable borrow starts here in previous iteration of loop ... LL | } diff --git a/src/test/ui/borrowck/borrowck-lend-flow-loop.nll.stderr b/src/test/ui/borrowck/borrowck-lend-flow-loop.nll.stderr index 388fc9c5fa8ac..19de3582c8819 100644 --- a/src/test/ui/borrowck/borrowck-lend-flow-loop.nll.stderr +++ b/src/test/ui/borrowck/borrowck-lend-flow-loop.nll.stderr @@ -4,9 +4,9 @@ error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mut LL | let mut x = &mut v; | ------ mutable borrow occurs here LL | for _ in 0..3 { -LL | borrow(&*v); //~ ERROR cannot borrow +LL | borrow(&*v); //[ast]~ ERROR cannot borrow | ^^^ immutable borrow occurs here -LL | } +... LL | *x = box 5; | -- mutable borrow used here, in later iteration of loop @@ -15,10 +15,10 @@ error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mut | LL | **x += 1; | -------- mutable borrow used here, in later iteration of loop -LL | borrow(&*v); //~ ERROR cannot borrow +LL | borrow(&*v); //[ast]~ ERROR cannot borrow | ^^^ immutable borrow occurs here -LL | if cond2 { -LL | x = &mut v; //~ ERROR cannot borrow +... +LL | x = &mut v; //[ast]~ ERROR cannot borrow | ------ mutable borrow occurs here error: aborting due to 2 previous errors diff --git a/src/test/ui/borrowck/borrowck-lend-flow-loop.rs b/src/test/ui/borrowck/borrowck-lend-flow-loop.rs index f09e7ffd7e4b7..7008e5cef4b75 100644 --- a/src/test/ui/borrowck/borrowck-lend-flow-loop.rs +++ b/src/test/ui/borrowck/borrowck-lend-flow-loop.rs @@ -1,18 +1,18 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Note: the borrowck analysis is currently flow-insensitive. -// Therefore, some of these errors are marked as spurious and could be -// corrected by a simple change to the analysis. The others are -// either genuine or would require more advanced changes. The latter -// cases are noted. +// revisions: ast nll + +// Since we are testing nll migration explicitly as a separate +// revision, don't worry about the --compare-mode=nll on this test. + +// ignore-compare-mode-nll + +//[ast]compile-flags: -Z borrowck=ast +//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows + +// Note: the borrowck analysis was originally a flow-insensitive pass +// over the AST. Therefore, some of these (AST) errors are marked as +// spurious and are corrected by the flow-sensitive (NLL) analysis. +// The others are either genuine or would require more advanced +// changes. The latter cases are noted. #![feature(box_syntax)] @@ -32,7 +32,7 @@ fn loop_overarching_alias_mut() { let mut x = &mut v; **x += 1; loop { - borrow(&*v); //~ ERROR cannot borrow + borrow(&*v); //[ast]~ ERROR cannot borrow } } @@ -42,11 +42,11 @@ fn block_overarching_alias_mut() { let mut v: Box<_> = box 3; let mut x = &mut v; for _ in 0..3 { - borrow(&*v); //~ ERROR cannot borrow + borrow(&*v); //[ast]~ ERROR cannot borrow + //[nll]~^ ERROR cannot borrow } *x = box 5; } - fn loop_aliased_mut() { // In this instance, the borrow is carried through the loop. @@ -54,7 +54,7 @@ fn loop_aliased_mut() { let mut w: Box<_> = box 4; let mut _x = &w; loop { - borrow_mut(&mut *v); //~ ERROR cannot borrow + borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow _x = &v; } } @@ -66,7 +66,7 @@ fn while_aliased_mut() { let mut w: Box<_> = box 4; let mut _x = &w; while cond() { - borrow_mut(&mut *v); //~ ERROR cannot borrow + borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow _x = &v; } } @@ -83,7 +83,7 @@ fn loop_aliased_mut_break() { _x = &v; break; } - borrow_mut(&mut *v); //~ ERROR cannot borrow + borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow } fn while_aliased_mut_break() { @@ -97,7 +97,7 @@ fn while_aliased_mut_break() { _x = &v; break; } - borrow_mut(&mut *v); //~ ERROR cannot borrow + borrow_mut(&mut *v); //[ast]~ ERROR cannot borrow } fn while_aliased_mut_cond(cond: bool, cond2: bool) { @@ -106,13 +106,13 @@ fn while_aliased_mut_cond(cond: bool, cond2: bool) { let mut x = &mut w; while cond { **x += 1; - borrow(&*v); //~ ERROR cannot borrow + borrow(&*v); //[ast]~ ERROR cannot borrow + //[nll]~^ ERROR cannot borrow if cond2 { - x = &mut v; //~ ERROR cannot borrow + x = &mut v; //[ast]~ ERROR cannot borrow } } } - fn loop_break_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F) where F: FnMut(&'r mut usize) -> bool, { diff --git a/src/test/ui/borrowck/borrowck-overloaded-call.nll.stderr b/src/test/ui/borrowck/borrowck-overloaded-call.nll.stderr index dc8d731dede74..0c4f2fa9d718b 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-call.nll.stderr +++ b/src/test/ui/borrowck/borrowck-overloaded-call.nll.stderr @@ -1,3 +1,13 @@ +error[E0502]: cannot borrow `s` as immutable because it is also borrowed as mutable + --> $DIR/borrowck-overloaded-call.rs:69:5 + | +LL | let sp = &mut s; + | ------ mutable borrow occurs here +LL | s(3); //~ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable + | ^ immutable borrow occurs here +LL | use_mut(sp); + | -- mutable borrow later used here + error[E0596]: cannot borrow `s` as mutable, as it is not declared as mutable --> $DIR/borrowck-overloaded-call.rs:77:5 | @@ -17,7 +27,7 @@ LL | s(" world".to_string()); //~ ERROR use of moved value: `s` | = note: move occurs because `s` has type `SFnOnce`, which does not implement the `Copy` trait -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -Some errors occurred: E0382, E0596. +Some errors occurred: E0382, E0502, E0596. For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/ui/borrowck/borrowck-overloaded-call.rs b/src/test/ui/borrowck/borrowck-overloaded-call.rs index 41f3e472cd125..b2401fbbc042c 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-call.rs +++ b/src/test/ui/borrowck/borrowck-overloaded-call.rs @@ -67,8 +67,8 @@ fn f() { }; let sp = &mut s; s(3); //~ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable + use_mut(sp); } - fn g() { let s = SFnMut { x: 1, @@ -86,3 +86,5 @@ fn h() { } fn main() {} + +fn use_mut(_: &mut T) { } diff --git a/src/test/ui/borrowck/borrowck-overloaded-call.stderr b/src/test/ui/borrowck/borrowck-overloaded-call.stderr index fa2473adc2ffd..bb5bafbbc7b85 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-call.stderr +++ b/src/test/ui/borrowck/borrowck-overloaded-call.stderr @@ -5,6 +5,7 @@ LL | let sp = &mut s; | - mutable borrow occurs here LL | s(3); //~ ERROR cannot borrow `s` as immutable because it is also borrowed as mutable | ^ immutable borrow occurs here +LL | use_mut(sp); LL | } | - mutable borrow ends here diff --git a/src/test/ui/borrowck/borrowck-overloaded-index-move-index.nll.stderr b/src/test/ui/borrowck/borrowck-overloaded-index-move-index.nll.stderr index 824d8298ecbc6..198d086aa3be6 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-index-move-index.nll.stderr +++ b/src/test/ui/borrowck/borrowck-overloaded-index-move-index.nll.stderr @@ -1,3 +1,27 @@ +error[E0505]: cannot move out of `s` because it is borrowed + --> $DIR/borrowck-overloaded-index-move-index.rs:60:22 + | +LL | let rs = &mut s; + | ------ borrow of `s` occurs here +LL | +LL | println!("{}", f[s]); + | ^ move out of `s` occurs here +... +LL | use_mut(rs); + | -- borrow later used here + +error[E0505]: cannot move out of `s` because it is borrowed + --> $DIR/borrowck-overloaded-index-move-index.rs:63:7 + | +LL | let rs = &mut s; + | ------ borrow of `s` occurs here +... +LL | f[s] = 10; + | ^ move out of `s` occurs here +... +LL | use_mut(rs); + | -- borrow later used here + error[E0382]: use of moved value: `s` --> $DIR/borrowck-overloaded-index-move-index.rs:63:7 | @@ -9,6 +33,7 @@ LL | f[s] = 10; | = note: move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait -error: aborting due to previous error +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0382`. +Some errors occurred: E0382, E0505. +For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/ui/borrowck/borrowck-overloaded-index-move-index.rs b/src/test/ui/borrowck/borrowck-overloaded-index-move-index.rs index d8615d1905338..e95423a8e834d 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-index-move-index.rs +++ b/src/test/ui/borrowck/borrowck-overloaded-index-move-index.rs @@ -71,4 +71,8 @@ fn main() { let _j = &i; println!("{}", s[i]); // no error, i is copy println!("{}", s[i]); + + use_mut(rs); } + +fn use_mut(_: &mut T) { } diff --git a/src/test/ui/borrowck/borrowck-reborrow-from-mut.nll.stderr b/src/test/ui/borrowck/borrowck-reborrow-from-mut.nll.stderr index 4c81bb8eb3086..1b4f9e77da80b 100644 --- a/src/test/ui/borrowck/borrowck-reborrow-from-mut.nll.stderr +++ b/src/test/ui/borrowck/borrowck-reborrow-from-mut.nll.stderr @@ -1,3 +1,107 @@ +error[E0499]: cannot borrow `foo.bar1` as mutable more than once at a time + --> $DIR/borrowck-reborrow-from-mut.rs:23:17 + | +LL | let _bar1 = &mut foo.bar1; + | ------------- first mutable borrow occurs here +LL | let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow + | ^^^^^^^^^^^^^ second mutable borrow occurs here +LL | use_mut(_bar1); + | ----- first borrow later used here + +error[E0502]: cannot borrow `foo.bar1` as immutable because it is also borrowed as mutable + --> $DIR/borrowck-reborrow-from-mut.rs:28:17 + | +LL | let _bar1 = &mut foo.bar1; + | ------------- mutable borrow occurs here +LL | let _bar2 = &foo.bar1; //~ ERROR cannot borrow + | ^^^^^^^^^ immutable borrow occurs here +LL | use_mut(_bar1); + | ----- mutable borrow later used here + +error[E0502]: cannot borrow `foo.bar1` as mutable because it is also borrowed as immutable + --> $DIR/borrowck-reborrow-from-mut.rs:33:17 + | +LL | let _bar1 = &foo.bar1; + | --------- immutable borrow occurs here +LL | let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow + | ^^^^^^^^^^^^^ mutable borrow occurs here +LL | use_imm(_bar1); + | ----- immutable borrow later used here + +error[E0499]: cannot borrow `foo.bar1` as mutable more than once at a time + --> $DIR/borrowck-reborrow-from-mut.rs:55:21 + | +LL | let _bar1 = &mut foo.bar1; + | ------------- first mutable borrow occurs here +LL | match *foo { +LL | Foo { bar1: ref mut _bar1, bar2: _ } => {} + | ^^^^^^^^^^^^^ second mutable borrow occurs here +... +LL | use_mut(_bar1); + | ----- first borrow later used here + +error[E0502]: cannot borrow `foo.bar1` as immutable because it is also borrowed as mutable + --> $DIR/borrowck-reborrow-from-mut.rs:62:17 + | +LL | let _bar1 = &mut foo.bar1.int1; + | ------------------ mutable borrow occurs here +LL | let _foo1 = &foo.bar1; //~ ERROR cannot borrow + | ^^^^^^^^^ immutable borrow occurs here +LL | let _foo2 = &*foo; //~ ERROR cannot borrow +LL | use_mut(_bar1); + | ----- mutable borrow later used here + +error[E0502]: cannot borrow `*foo` as immutable because it is also borrowed as mutable + --> $DIR/borrowck-reborrow-from-mut.rs:63:17 + | +LL | let _bar1 = &mut foo.bar1.int1; + | ------------------ mutable borrow occurs here +LL | let _foo1 = &foo.bar1; //~ ERROR cannot borrow +LL | let _foo2 = &*foo; //~ ERROR cannot borrow + | ^^^^^ immutable borrow occurs here +LL | use_mut(_bar1); + | ----- mutable borrow later used here + +error[E0499]: cannot borrow `foo.bar1` as mutable more than once at a time + --> $DIR/borrowck-reborrow-from-mut.rs:68:17 + | +LL | let _bar1 = &mut foo.bar1.int1; + | ------------------ first mutable borrow occurs here +LL | let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow + | ^^^^^^^^^^^^^ second mutable borrow occurs here +LL | use_mut(_bar1); + | ----- first borrow later used here + +error[E0499]: cannot borrow `*foo` as mutable more than once at a time + --> $DIR/borrowck-reborrow-from-mut.rs:73:17 + | +LL | let _bar1 = &mut foo.bar1.int1; + | ------------------ first mutable borrow occurs here +LL | let _foo2 = &mut *foo; //~ ERROR cannot borrow + | ^^^^^^^^^ second mutable borrow occurs here +LL | use_mut(_bar1); + | ----- first borrow later used here + +error[E0502]: cannot borrow `foo.bar1` as mutable because it is also borrowed as immutable + --> $DIR/borrowck-reborrow-from-mut.rs:78:17 + | +LL | let _bar1 = &foo.bar1.int1; + | -------------- immutable borrow occurs here +LL | let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow + | ^^^^^^^^^^^^^ mutable borrow occurs here +LL | use_imm(_bar1); + | ----- immutable borrow later used here + +error[E0502]: cannot borrow `*foo` as mutable because it is also borrowed as immutable + --> $DIR/borrowck-reborrow-from-mut.rs:83:17 + | +LL | let _bar1 = &foo.bar1.int1; + | -------------- immutable borrow occurs here +LL | let _foo2 = &mut *foo; //~ ERROR cannot borrow + | ^^^^^^^^^ mutable borrow occurs here +LL | use_imm(_bar1); + | ----- immutable borrow later used here + error[E0596]: cannot borrow `foo.bar1` as mutable, as it is behind a `&` reference --> $DIR/borrowck-reborrow-from-mut.rs:98:17 | @@ -6,6 +110,7 @@ LL | fn borrow_mut_from_imm(foo: &Foo) { LL | let _bar1 = &mut foo.bar1; //~ ERROR cannot borrow | ^^^^^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be borrowed as mutable -error: aborting due to previous error +error: aborting due to 11 previous errors -For more information about this error, try `rustc --explain E0596`. +Some errors occurred: E0499, E0502, E0596. +For more information about an error, try `rustc --explain E0499`. diff --git a/src/test/ui/borrowck/borrowck-reborrow-from-mut.rs b/src/test/ui/borrowck/borrowck-reborrow-from-mut.rs index 6f5dfa67be50d..9235d900a7e79 100644 --- a/src/test/ui/borrowck/borrowck-reborrow-from-mut.rs +++ b/src/test/ui/borrowck/borrowck-reborrow-from-mut.rs @@ -21,79 +21,79 @@ struct Bar { fn borrow_same_field_twice_mut_mut(foo: &mut Foo) { let _bar1 = &mut foo.bar1; let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow + use_mut(_bar1); } - fn borrow_same_field_twice_mut_imm(foo: &mut Foo) { let _bar1 = &mut foo.bar1; let _bar2 = &foo.bar1; //~ ERROR cannot borrow + use_mut(_bar1); } - fn borrow_same_field_twice_imm_mut(foo: &mut Foo) { let _bar1 = &foo.bar1; let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow + use_imm(_bar1); } - fn borrow_same_field_twice_imm_imm(foo: &mut Foo) { let _bar1 = &foo.bar1; let _bar2 = &foo.bar1; + use_imm(_bar1); } - fn borrow_both_mut(foo: &mut Foo) { let _bar1 = &mut foo.bar1; let _bar2 = &mut foo.bar2; + use_mut(_bar1); } - fn borrow_both_mut_pattern(foo: &mut Foo) { match *foo { - Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } => {} + Foo { bar1: ref mut _bar1, bar2: ref mut _bar2 } => + { use_mut(_bar1); use_mut(_bar2); } } } - fn borrow_var_and_pattern(foo: &mut Foo) { let _bar1 = &mut foo.bar1; match *foo { Foo { bar1: ref mut _bar1, bar2: _ } => {} //~^ ERROR cannot borrow } + use_mut(_bar1); } - fn borrow_mut_and_base_imm(foo: &mut Foo) { let _bar1 = &mut foo.bar1.int1; let _foo1 = &foo.bar1; //~ ERROR cannot borrow let _foo2 = &*foo; //~ ERROR cannot borrow + use_mut(_bar1); } - fn borrow_mut_and_base_mut(foo: &mut Foo) { let _bar1 = &mut foo.bar1.int1; let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow + use_mut(_bar1); } - fn borrow_mut_and_base_mut2(foo: &mut Foo) { let _bar1 = &mut foo.bar1.int1; let _foo2 = &mut *foo; //~ ERROR cannot borrow + use_mut(_bar1); } - fn borrow_imm_and_base_mut(foo: &mut Foo) { let _bar1 = &foo.bar1.int1; let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow + use_imm(_bar1); } - fn borrow_imm_and_base_mut2(foo: &mut Foo) { let _bar1 = &foo.bar1.int1; let _foo2 = &mut *foo; //~ ERROR cannot borrow + use_imm(_bar1); } - fn borrow_imm_and_base_imm(foo: &mut Foo) { let _bar1 = &foo.bar1.int1; let _foo1 = &foo.bar1; let _foo2 = &*foo; + use_imm(_bar1); } - fn borrow_mut_and_imm(foo: &mut Foo) { let _bar1 = &mut foo.bar1; let _foo1 = &foo.bar2; + use_mut(_bar1); } - fn borrow_mut_from_imm(foo: &Foo) { let _bar1 = &mut foo.bar1; //~ ERROR cannot borrow } @@ -101,6 +101,9 @@ fn borrow_mut_from_imm(foo: &Foo) { fn borrow_long_path_both_mut(foo: &mut Foo) { let _bar1 = &mut foo.bar1.int1; let _foo1 = &mut foo.bar2.int2; + use_mut(_bar1); } - fn main() {} + +fn use_mut(_: &mut T) { } +fn use_imm(_: &T) { } diff --git a/src/test/ui/borrowck/borrowck-reborrow-from-mut.stderr b/src/test/ui/borrowck/borrowck-reborrow-from-mut.stderr index 00660ff84841b..1310e38cb3ee6 100644 --- a/src/test/ui/borrowck/borrowck-reborrow-from-mut.stderr +++ b/src/test/ui/borrowck/borrowck-reborrow-from-mut.stderr @@ -5,6 +5,7 @@ LL | let _bar1 = &mut foo.bar1; | -------- first mutable borrow occurs here LL | let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow | ^^^^^^^^ second mutable borrow occurs here +LL | use_mut(_bar1); LL | } | - first borrow ends here @@ -15,6 +16,7 @@ LL | let _bar1 = &mut foo.bar1; | -------- mutable borrow occurs here LL | let _bar2 = &foo.bar1; //~ ERROR cannot borrow | ^^^^^^^^ immutable borrow occurs here +LL | use_mut(_bar1); LL | } | - mutable borrow ends here @@ -25,6 +27,7 @@ LL | let _bar1 = &foo.bar1; | -------- immutable borrow occurs here LL | let _bar2 = &mut foo.bar1; //~ ERROR cannot borrow | ^^^^^^^^ mutable borrow occurs here +LL | use_imm(_bar1); LL | } | - immutable borrow ends here @@ -47,7 +50,7 @@ LL | let _bar1 = &mut foo.bar1.int1; | ------------- mutable borrow occurs here LL | let _foo1 = &foo.bar1; //~ ERROR cannot borrow | ^^^^^^^^ immutable borrow occurs here -LL | let _foo2 = &*foo; //~ ERROR cannot borrow +... LL | } | - mutable borrow ends here @@ -59,6 +62,7 @@ LL | let _bar1 = &mut foo.bar1.int1; LL | let _foo1 = &foo.bar1; //~ ERROR cannot borrow LL | let _foo2 = &*foo; //~ ERROR cannot borrow | ^^^^ immutable borrow occurs here +LL | use_mut(_bar1); LL | } | - mutable borrow ends here @@ -69,6 +73,7 @@ LL | let _bar1 = &mut foo.bar1.int1; | ------------- first mutable borrow occurs here LL | let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow | ^^^^^^^^ second mutable borrow occurs here +LL | use_mut(_bar1); LL | } | - first borrow ends here @@ -79,6 +84,7 @@ LL | let _bar1 = &mut foo.bar1.int1; | ------------- first mutable borrow occurs here LL | let _foo2 = &mut *foo; //~ ERROR cannot borrow | ^^^^ second mutable borrow occurs here +LL | use_mut(_bar1); LL | } | - first borrow ends here @@ -89,6 +95,7 @@ LL | let _bar1 = &foo.bar1.int1; | ------------- immutable borrow occurs here LL | let _foo1 = &mut foo.bar1; //~ ERROR cannot borrow | ^^^^^^^^ mutable borrow occurs here +LL | use_imm(_bar1); LL | } | - immutable borrow ends here @@ -99,6 +106,7 @@ LL | let _bar1 = &foo.bar1.int1; | ------------- immutable borrow occurs here LL | let _foo2 = &mut *foo; //~ ERROR cannot borrow | ^^^^ mutable borrow occurs here +LL | use_imm(_bar1); LL | } | - immutable borrow ends here diff --git a/src/test/ui/borrowck/borrowck-unboxed-closures.nll.stderr b/src/test/ui/borrowck/borrowck-unboxed-closures.nll.stderr index 3fbb747db24f1..ee5ad58290e9e 100644 --- a/src/test/ui/borrowck/borrowck-unboxed-closures.nll.stderr +++ b/src/test/ui/borrowck/borrowck-unboxed-closures.nll.stderr @@ -1,3 +1,13 @@ +error[E0502]: cannot borrow `f` as immutable because it is also borrowed as mutable + --> $DIR/borrowck-unboxed-closures.rs:13:5 + | +LL | let g = &mut f; + | ------ mutable borrow occurs here +LL | f(1, 2); //~ ERROR cannot borrow `f` as immutable + | ^ immutable borrow occurs here +LL | use_mut(g); + | - mutable borrow later used here + error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable --> $DIR/borrowck-unboxed-closures.rs:17:5 | @@ -16,7 +26,7 @@ LL | f(1, 2); //~ ERROR use of moved value | = note: move occurs because `f` has type `F`, which does not implement the `Copy` trait -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -Some errors occurred: E0382, E0596. +Some errors occurred: E0382, E0502, E0596. For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/ui/borrowck/borrowck-unboxed-closures.rs b/src/test/ui/borrowck/borrowck-unboxed-closures.rs index 4813b4b6a72cd..43f143a492fd6 100644 --- a/src/test/ui/borrowck/borrowck-unboxed-closures.rs +++ b/src/test/ui/borrowck/borrowck-unboxed-closures.rs @@ -11,8 +11,8 @@ fn a isize>(mut f: F) { let g = &mut f; f(1, 2); //~ ERROR cannot borrow `f` as immutable + use_mut(g); } - fn b isize>(f: F) { f(1, 2); //~ ERROR cannot borrow immutable argument } @@ -23,3 +23,5 @@ fn c isize>(f: F) { } fn main() {} + +fn use_mut(_: &mut T) { } diff --git a/src/test/ui/borrowck/borrowck-unboxed-closures.stderr b/src/test/ui/borrowck/borrowck-unboxed-closures.stderr index 0c067c47004cf..6ee1a6245a556 100644 --- a/src/test/ui/borrowck/borrowck-unboxed-closures.stderr +++ b/src/test/ui/borrowck/borrowck-unboxed-closures.stderr @@ -5,6 +5,7 @@ LL | let g = &mut f; | - mutable borrow occurs here LL | f(1, 2); //~ ERROR cannot borrow `f` as immutable | ^ immutable borrow occurs here +LL | use_mut(g); LL | } | - mutable borrow ends here diff --git a/src/test/ui/codemap_tests/overlapping_spans.nll.stderr b/src/test/ui/codemap_tests/overlapping_spans.nll.stderr deleted file mode 100644 index e334472f9d6e1..0000000000000 --- a/src/test/ui/codemap_tests/overlapping_spans.nll.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0509]: cannot move out of type `S`, which implements the `Drop` trait - --> $DIR/overlapping_spans.rs:20:11 - | -LL | match (S {f:"foo".to_string()}) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of here -LL | S {f:_s} => {} //~ ERROR cannot move out - | -- data moved here - | -note: move occurs because `_s` has type `std::string::String`, which does not implement the `Copy` trait - --> $DIR/overlapping_spans.rs:21:14 - | -LL | S {f:_s} => {} //~ ERROR cannot move out - | ^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0509`. diff --git a/src/test/ui/codemap_tests/overlapping_spans.rs b/src/test/ui/codemap_tests/overlapping_spans.rs deleted file mode 100644 index 467e90bd5a51b..0000000000000 --- a/src/test/ui/codemap_tests/overlapping_spans.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[derive(Debug)] -struct Foo { } - -struct S {f:String} -impl Drop for S { - fn drop(&mut self) { println!("{}", self.f); } -} - -fn main() { - match (S {f:"foo".to_string()}) { - S {f:_s} => {} //~ ERROR cannot move out - } -} diff --git a/src/test/ui/codemap_tests/overlapping_spans.stderr b/src/test/ui/codemap_tests/overlapping_spans.stderr deleted file mode 100644 index 62a4f08e15661..0000000000000 --- a/src/test/ui/codemap_tests/overlapping_spans.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0509]: cannot move out of type `S`, which implements the `Drop` trait - --> $DIR/overlapping_spans.rs:21:9 - | -LL | S {f:_s} => {} //~ ERROR cannot move out - | ^^^^^--^ - | | | - | | hint: to prevent move, use `ref _s` or `ref mut _s` - | cannot move out of here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0509`. diff --git a/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr b/src/test/ui/dropck/dropck-eyepatch-extern-crate.ast.stderr similarity index 97% rename from src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr rename to src/test/ui/dropck/dropck-eyepatch-extern-crate.ast.stderr index 35db46f4faeb1..31adb2f3f1471 100644 --- a/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr +++ b/src/test/ui/dropck/dropck-eyepatch-extern-crate.ast.stderr @@ -32,7 +32,7 @@ LL | } = note: values in a scope are dropped in the opposite order they are created error[E0597]: `c_shortest` does not live long enough - --> $DIR/dropck-eyepatch-extern-crate.rs:49:20 + --> $DIR/dropck-eyepatch-extern-crate.rs:50:20 | LL | dr = Dr("dr", &c_shortest); | ^^^^^^^^^^ borrowed value does not live long enough diff --git a/src/test/ui/dropck/dropck-eyepatch-extern-crate.rs b/src/test/ui/dropck/dropck-eyepatch-extern-crate.rs index 3e531d9fd6011..68065639398a5 100644 --- a/src/test/ui/dropck/dropck-eyepatch-extern-crate.rs +++ b/src/test/ui/dropck/dropck-eyepatch-extern-crate.rs @@ -1,12 +1,12 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. +// The behavior of AST-borrowck and NLL explcitly differ here due to +// NLL's increased precision; so we use revisions and do not worry +// about the --compare-mode=nll on this test. + +// revisions: ast nll +//[ast]compile-flags: -Z borrowck=ast +//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows + +// ignore-compare-mode-nll // aux-build:dropck_eyepatch_extern_crate.rs @@ -39,29 +39,32 @@ fn main() { #![rustc_error] // rust-lang/rust#49855 // Error: destructor order imprecisely modelled dt = Dt("dt", &c); - //~^ ERROR `c` does not live long enough + //[ast]~^ ERROR `c` does not live long enough dr = Dr("dr", &c); - //~^ ERROR `c` does not live long enough + //[ast]~^ ERROR `c` does not live long enough // Error: `c_shortest` dies too soon for the references in dtors to be valid. dt = Dt("dt", &c_shortest); - //~^ ERROR `c_shortest` does not live long enough + //[ast]~^ ERROR `c_shortest` does not live long enough + //[nll]~^^ ERROR `c_shortest` does not live long enough dr = Dr("dr", &c_shortest); - //~^ ERROR `c_shortest` does not live long enough - + //[ast]~^ ERROR `c_shortest` does not live long enough // No error: Drop impl asserts .1 (A and &'a _) are not accessed pt = Pt("pt", &c_shortest, &c_long); pr = Pr("pr", &c_shortest, &c_long); // Error: Drop impl's assertion does not apply to `B` nor `&'b _` pt = Pt("pt", &c_long, &c_shortest); - //~^ ERROR `c_shortest` does not live long enough + //[ast]~^ ERROR `c_shortest` does not live long enough pr = Pr("pr", &c_long, &c_shortest); - //~^ ERROR `c_shortest` does not live long enough + //[ast]~^ ERROR `c_shortest` does not live long enough // No error: St and Sr have no destructor. st = St("st", &c_shortest); sr = Sr("sr", &c_shortest); println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0)); + use_imm(sr.1); use_imm(st.1); use_imm(pr.1); use_imm(pt.1); use_imm(dr.1); use_imm(dt.1); } + +fn use_imm(_: &T) { } diff --git a/src/test/ui/dropck/dropck-eyepatch-reorder.stderr b/src/test/ui/dropck/dropck-eyepatch-reorder.ast.stderr similarity index 98% rename from src/test/ui/dropck/dropck-eyepatch-reorder.stderr rename to src/test/ui/dropck/dropck-eyepatch-reorder.ast.stderr index 9984a7b9409c4..ddd47e9743497 100644 --- a/src/test/ui/dropck/dropck-eyepatch-reorder.stderr +++ b/src/test/ui/dropck/dropck-eyepatch-reorder.ast.stderr @@ -32,7 +32,7 @@ LL | } = note: values in a scope are dropped in the opposite order they are created error[E0597]: `c_shortest` does not live long enough - --> $DIR/dropck-eyepatch-reorder.rs:66:20 + --> $DIR/dropck-eyepatch-reorder.rs:67:20 | LL | dr = Dr("dr", &c_shortest); | ^^^^^^^^^^ borrowed value does not live long enough diff --git a/src/test/ui/dropck/dropck-eyepatch-reorder.rs b/src/test/ui/dropck/dropck-eyepatch-reorder.rs index 1806dc7142452..16aaa26125768 100644 --- a/src/test/ui/dropck/dropck-eyepatch-reorder.rs +++ b/src/test/ui/dropck/dropck-eyepatch-reorder.rs @@ -1,12 +1,12 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. +// The behavior of AST-borrowck and NLL explcitly differ here due to +// NLL's increased precision; so we use revisions and do not worry +// about the --compare-mode=nll on this test. + +// revisions: ast nll +//[ast]compile-flags: -Z borrowck=ast +//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows + +// ignore-compare-mode-nll #![feature(dropck_eyepatch, rustc_attrs)] @@ -56,29 +56,32 @@ fn main() { #![rustc_error] // rust-lang/rust#49855 // Error: destructor order imprecisely modelled dt = Dt("dt", &c); - //~^ ERROR `c` does not live long enough + //[ast]~^ ERROR `c` does not live long enough dr = Dr("dr", &c); - //~^ ERROR `c` does not live long enough + //[ast]~^ ERROR `c` does not live long enough // Error: `c_shortest` dies too soon for the references in dtors to be valid. dt = Dt("dt", &c_shortest); - //~^ ERROR `c_shortest` does not live long enough + //[ast]~^ ERROR `c_shortest` does not live long enough + //[nll]~^^ ERROR `c_shortest` does not live long enough dr = Dr("dr", &c_shortest); - //~^ ERROR `c_shortest` does not live long enough - + //[ast]~^ ERROR `c_shortest` does not live long enough // No error: Drop impl asserts .1 (A and &'a _) are not accessed pt = Pt("pt", &c_shortest, &c_long); pr = Pr("pr", &c_shortest, &c_long); // Error: Drop impl's assertion does not apply to `B` nor `&'b _` pt = Pt("pt", &c_long, &c_shortest); - //~^ ERROR `c_shortest` does not live long enough + //[ast]~^ ERROR `c_shortest` does not live long enough pr = Pr("pr", &c_long, &c_shortest); - //~^ ERROR `c_shortest` does not live long enough + //[ast]~^ ERROR `c_shortest` does not live long enough // No error: St and Sr have no destructor. st = St("st", &c_shortest); sr = Sr("sr", &c_shortest); println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0)); + use_imm(sr.1); use_imm(st.1); use_imm(pr.1); use_imm(pt.1); use_imm(dr.1); use_imm(dt.1); } + +fn use_imm(_: &T) { } diff --git a/src/test/ui/dropck/dropck-eyepatch.stderr b/src/test/ui/dropck/dropck-eyepatch.ast.stderr similarity index 98% rename from src/test/ui/dropck/dropck-eyepatch.stderr rename to src/test/ui/dropck/dropck-eyepatch.ast.stderr index 7cdf645941d09..0952ed0d6b793 100644 --- a/src/test/ui/dropck/dropck-eyepatch.stderr +++ b/src/test/ui/dropck/dropck-eyepatch.ast.stderr @@ -32,7 +32,7 @@ LL | } = note: values in a scope are dropped in the opposite order they are created error[E0597]: `c_shortest` does not live long enough - --> $DIR/dropck-eyepatch.rs:89:20 + --> $DIR/dropck-eyepatch.rs:90:20 | LL | dr = Dr("dr", &c_shortest); | ^^^^^^^^^^ borrowed value does not live long enough diff --git a/src/test/ui/dropck/dropck-eyepatch.rs b/src/test/ui/dropck/dropck-eyepatch.rs index 40d3ff050e2aa..d7a671fd33c2c 100644 --- a/src/test/ui/dropck/dropck-eyepatch.rs +++ b/src/test/ui/dropck/dropck-eyepatch.rs @@ -1,12 +1,12 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. +// The behavior of AST-borrowck and NLL explcitly differ here due to +// NLL's increased precision; so we use revisions and do not worry +// about the --compare-mode=nll on this test. + +// revisions: ast nll +//[ast]compile-flags: -Z borrowck=ast +//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows + +// ignore-compare-mode-nll #![feature(dropck_eyepatch, rustc_attrs)] @@ -79,16 +79,16 @@ fn main() { #![rustc_error] // rust-lang/rust#49855 // Error: destructor order imprecisely modelled dt = Dt("dt", &c); - //~^ ERROR `c` does not live long enough + //[ast]~^ ERROR `c` does not live long enough dr = Dr("dr", &c); - //~^ ERROR `c` does not live long enough + //[ast]~^ ERROR `c` does not live long enough // Error: `c_shortest` dies too soon for the references in dtors to be valid. dt = Dt("dt", &c_shortest); - //~^ ERROR `c_shortest` does not live long enough + //[ast]~^ ERROR `c_shortest` does not live long enough + //[nll]~^^ ERROR `c_shortest` does not live long enough dr = Dr("dr", &c_shortest); - //~^ ERROR `c_shortest` does not live long enough - + //[ast]~^ ERROR `c_shortest` does not live long enough // No error: Drop impl asserts .1 (A and &'a _) are not accessed pt = Pt("pt", &c_shortest, &c_long); @@ -96,13 +96,16 @@ fn main() { #![rustc_error] // rust-lang/rust#49855 // Error: Drop impl's assertion does not apply to `B` nor `&'b _` pt = Pt("pt", &c_long, &c_shortest); - //~^ ERROR `c_shortest` does not live long enough + //[ast]~^ ERROR `c_shortest` does not live long enough pr = Pr("pr", &c_long, &c_shortest); - //~^ ERROR `c_shortest` does not live long enough + //[ast]~^ ERROR `c_shortest` does not live long enough // No error: St and Sr have no destructor. st = St("st", &c_shortest); sr = Sr("sr", &c_shortest); println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0)); + use_imm(sr.1); use_imm(st.1); use_imm(pr.1); use_imm(pt.1); use_imm(dr.1); use_imm(dt.1); } + +fn use_imm(_: &T) { } diff --git a/src/test/ui/error-codes/E0004-2.stderr b/src/test/ui/error-codes/E0004-2.stderr index 6a4392df35d8b..900812787bcf7 100644 --- a/src/test/ui/error-codes/E0004-2.stderr +++ b/src/test/ui/error-codes/E0004-2.stderr @@ -4,7 +4,7 @@ error[E0004]: non-exhaustive patterns: type std::option::Option is non-empt LL | match x { } //~ ERROR E0004 | ^ | -help: Please ensure that all possible cases are being handled; possibly adding wildcards or more match arms. +help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms --> $DIR/E0004-2.rs:14:11 | LL | match x { } //~ ERROR E0004 diff --git a/src/test/ui/feature-gates/feature-gate-allow_fail.stderr b/src/test/ui/feature-gates/feature-gate-allow_fail.stderr index 3f8ad32437df9..736fad44b8b58 100644 --- a/src/test/ui/feature-gates/feature-gate-allow_fail.stderr +++ b/src/test/ui/feature-gates/feature-gate-allow_fail.stderr @@ -1,4 +1,4 @@ -error[E0658]: allow_fail attribute is currently unstable (see issue #42219) +error[E0658]: allow_fail attribute is currently unstable (see issue #46488) --> $DIR/feature-gate-allow_fail.rs:13:1 | LL | #[allow_fail] //~ ERROR allow_fail attribute is currently unstable diff --git a/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr b/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr index d0ee40504fb21..e1c1dcbcd790c 100644 --- a/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr +++ b/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr @@ -1,4 +1,4 @@ -error[E0658]: `crate` visibility modifier is experimental (see issue #45388) +error[E0658]: `crate` visibility modifier is experimental (see issue #53120) --> $DIR/feature-gate-crate_visibility_modifier.rs:11:1 | LL | crate struct Bender { //~ ERROR `crate` visibility modifier is experimental diff --git a/src/test/ui/feature-gates/feature-gate-extern_crate_item_prelude.stderr b/src/test/ui/feature-gates/feature-gate-extern_crate_item_prelude.stderr index cabfb56d7a840..bbd4b630263a4 100644 --- a/src/test/ui/feature-gates/feature-gate-extern_crate_item_prelude.stderr +++ b/src/test/ui/feature-gates/feature-gate-extern_crate_item_prelude.stderr @@ -1,4 +1,4 @@ -error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658) +error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #55599) --> $DIR/feature-gate-extern_crate_item_prelude.rs:26:9 | LL | use alloc; @@ -6,7 +6,7 @@ LL | use alloc; | = help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable -error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658) +error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #55599) --> $DIR/feature-gate-extern_crate_item_prelude.rs:28:9 | LL | use alloc::boxed; @@ -14,7 +14,7 @@ LL | use alloc::boxed; | = help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable -error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658) +error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #55599) --> $DIR/feature-gate-extern_crate_item_prelude.rs:33:11 | LL | use ::alloc; @@ -22,7 +22,7 @@ LL | use ::alloc; | = help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable -error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658) +error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #55599) --> $DIR/feature-gate-extern_crate_item_prelude.rs:35:11 | LL | use ::alloc::boxed; @@ -30,7 +30,7 @@ LL | use ::alloc::boxed; | = help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable -error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658) +error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #55599) --> $DIR/feature-gate-extern_crate_item_prelude.rs:9:17 | LL | let v = alloc::vec![0]; @@ -38,7 +38,7 @@ LL | let v = alloc::vec![0]; | = help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable -error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658) +error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #55599) --> $DIR/feature-gate-extern_crate_item_prelude.rs:11:18 | LL | type A = alloc::boxed::Box; @@ -46,7 +46,7 @@ LL | type A = alloc::boxed::Box; | = help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable -error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658) +error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #55599) --> $DIR/feature-gate-extern_crate_item_prelude.rs:18:19 | LL | let v = ::alloc::vec![0]; @@ -54,7 +54,7 @@ LL | let v = ::alloc::vec![0]; | = help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable -error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658) +error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #55599) --> $DIR/feature-gate-extern_crate_item_prelude.rs:20:20 | LL | type A = ::alloc::boxed::Box; @@ -62,7 +62,7 @@ LL | type A = ::alloc::boxed::Box; | = help: add #![feature(extern_crate_item_prelude)] to the crate attributes to enable -error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #54658) +error[E0658]: use of extern prelude names introduced with `extern crate` items is unstable (see issue #55599) --> $DIR/feature-gate-extern_crate_item_prelude.rs:42:14 | LL | type A = core::boxed::Box; diff --git a/src/test/ui/feature-gates/feature-gate-extern_in_paths.stderr b/src/test/ui/feature-gates/feature-gate-extern_in_paths.stderr index 535ed94565c6d..a73533b617891 100644 --- a/src/test/ui/feature-gates/feature-gate-extern_in_paths.stderr +++ b/src/test/ui/feature-gates/feature-gate-extern_in_paths.stderr @@ -1,4 +1,4 @@ -error[E0658]: `extern` in paths is experimental (see issue #44660) +error[E0658]: `extern` in paths is experimental (see issue #55600) --> $DIR/feature-gate-extern_in_paths.rs:14:13 | LL | let _ = extern::std::vec::Vec::new(); //~ ERROR `extern` in paths is experimental diff --git a/src/test/ui/feature-gates/feature-gate-nll.nll.stderr b/src/test/ui/feature-gates/feature-gate-nll.nll.stderr deleted file mode 100644 index 81de0d14aa7d3..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-nll.nll.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: compilation successful - --> $DIR/feature-gate-nll.rs:13:1 - | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let mut x = 33; -LL | | -LL | | let p = &x; -LL | | x = 22; //~ ERROR cannot assign to `x` because it is borrowed [E0506] -LL | | } - | |_^ - -error: aborting due to previous error - diff --git a/src/test/ui/feature-gates/feature-gate-nll.rs b/src/test/ui/feature-gates/feature-gate-nll.rs index 752b1fa821f7f..14c48fb48a09b 100644 --- a/src/test/ui/feature-gates/feature-gate-nll.rs +++ b/src/test/ui/feature-gates/feature-gate-nll.rs @@ -1,16 +1,16 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -#![feature(rustc_attrs)] +// This is a test checking that if you do not opt into NLL then you +// should not get the effects of NLL applied to the test. + +// Don't use 2018 edition, since that turns on NLL (migration mode). +// edition:2015 + +// Don't use compare-mode=nll, since that turns on NLL. +// ignore-compare-mode-nll + + #![allow(dead_code)] -fn main() { #![rustc_error] // rust-lang/rust#49855 +fn main() { let mut x = 33; let p = &x; diff --git a/src/test/ui/feature-gates/feature-gate-panic-implementation.rs b/src/test/ui/feature-gates/feature-gate-panic-implementation.rs deleted file mode 100644 index ca51154884f12..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-panic-implementation.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// compile-flags:-C panic=abort - -#![no_std] -#![no_main] - -use core::panic::PanicInfo; - -#[panic_implementation] //~ ERROR this attribute was renamed to `panic_handler` (see issue #44489) -fn panic(info: &PanicInfo) -> ! { - loop {} -} diff --git a/src/test/ui/feature-gates/feature-gate-panic-implementation.stderr b/src/test/ui/feature-gates/feature-gate-panic-implementation.stderr deleted file mode 100644 index a54780468c42d..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-panic-implementation.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0658]: this attribute was renamed to `panic_handler` (see issue #44489) - --> $DIR/feature-gate-panic-implementation.rs:18:1 - | -LL | #[panic_implementation] //~ ERROR this attribute was renamed to `panic_handler` (see issue #44489) - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: add #![feature(panic_implementation)] to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/imports/issue-55457.rs b/src/test/ui/imports/issue-55457.rs new file mode 100644 index 0000000000000..9c6750fd48c26 --- /dev/null +++ b/src/test/ui/imports/issue-55457.rs @@ -0,0 +1,8 @@ +use NonExistent; //~ ERROR unresolved import `NonExistent` +use non_existent::non_existent; //~ ERROR unresolved import `non_existent` + +#[non_existent] //~ ERROR cannot determine resolution for the attribute macro `non_existent` +#[derive(NonExistent)] //~ ERROR cannot determine resolution for the derive macro `NonExistent` +struct S; + +fn main() {} diff --git a/src/test/ui/imports/issue-55457.stderr b/src/test/ui/imports/issue-55457.stderr new file mode 100644 index 0000000000000..363dec06237f4 --- /dev/null +++ b/src/test/ui/imports/issue-55457.stderr @@ -0,0 +1,31 @@ +error[E0432]: unresolved import `NonExistent` + --> $DIR/issue-55457.rs:1:5 + | +LL | use NonExistent; //~ ERROR unresolved import `NonExistent` + | ^^^^^^^^^^^ no `NonExistent` in the root. Did you mean to use `non_existent`? + +error[E0432]: unresolved import `non_existent` + --> $DIR/issue-55457.rs:2:5 + | +LL | use non_existent::non_existent; //~ ERROR unresolved import `non_existent` + | ^^^^^^^^^^^^ Maybe a missing `extern crate non_existent;`? + +error: cannot determine resolution for the derive macro `NonExistent` + --> $DIR/issue-55457.rs:5:10 + | +LL | #[derive(NonExistent)] //~ ERROR cannot determine resolution for the derive macro `NonExistent` + | ^^^^^^^^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +error: cannot determine resolution for the attribute macro `non_existent` + --> $DIR/issue-55457.rs:4:3 + | +LL | #[non_existent] //~ ERROR cannot determine resolution for the attribute macro `non_existent` + | ^^^^^^^^^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0432`. diff --git a/src/test/ui/issues/issue-17263.stderr b/src/test/ui/issues/issue-17263.ast.stderr similarity index 93% rename from src/test/ui/issues/issue-17263.stderr rename to src/test/ui/issues/issue-17263.ast.stderr index 4767fbbcfbbd5..3d42dcb52f5db 100644 --- a/src/test/ui/issues/issue-17263.stderr +++ b/src/test/ui/issues/issue-17263.ast.stderr @@ -16,7 +16,7 @@ LL | let (c, d) = (&mut foo.a, &foo.b); | ----- ^^^^^ immutable borrow occurs here (via `foo.b`) | | | mutable borrow occurs here (via `foo.a`) -LL | //~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable +... LL | } | - mutable borrow ends here diff --git a/src/test/ui/issues/issue-17263.nll.stderr b/src/test/ui/issues/issue-17263.nll.stderr index d6009e8078dce..cdb574b8b9f94 100644 --- a/src/test/ui/issues/issue-17263.nll.stderr +++ b/src/test/ui/issues/issue-17263.nll.stderr @@ -1,12 +1,12 @@ error: compilation successful --> $DIR/issue-17263.rs:15:1 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 +LL | / fn main() { //[nll]~ ERROR compilation successful LL | | let mut x: Box<_> = box Foo { a: 1, b: 2 }; LL | | let (a, b) = (&mut x.a, &mut x.b); -LL | | //~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time +LL | | //[ast]~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time ... | -LL | | //~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable +LL | | use_mut(a); LL | | } | |_^ diff --git a/src/test/ui/issues/issue-17263.rs b/src/test/ui/issues/issue-17263.rs index b251f9a415253..754f3b90aacf1 100644 --- a/src/test/ui/issues/issue-17263.rs +++ b/src/test/ui/issues/issue-17263.rs @@ -1,23 +1,35 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. +// This checks diagnostic quality for cases where AST-borrowck treated +// `Box` as other types (see rust-lang/rfcs#130). NLL again treats +// `Box` specially. We capture the differences via revisions. +// revisions: ast nll +//[ast]compile-flags: -Z borrowck=ast +//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows + +// don't worry about the --compare-mode=nll on this test. +// ignore-compare-mode-nll #![feature(box_syntax, rustc_attrs)] struct Foo { a: isize, b: isize } - -fn main() { #![rustc_error] // rust-lang/rust#49855 +#[rustc_error] // rust-lang/rust#49855 +fn main() { //[nll]~ ERROR compilation successful let mut x: Box<_> = box Foo { a: 1, b: 2 }; let (a, b) = (&mut x.a, &mut x.b); - //~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time + //[ast]~^ ERROR cannot borrow `x` (via `x.b`) as mutable more than once at a time let mut foo: Box<_> = box Foo { a: 1, b: 2 }; let (c, d) = (&mut foo.a, &foo.b); - //~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable + //[ast]~^ ERROR cannot borrow `foo` (via `foo.b`) as immutable + + // We explicitly use the references created above to illustrate + // that NLL is accepting this code *not* because of artificially + // short lifetimes, but rather because it understands that all the + // references are of disjoint parts of memory. + use_imm(d); + use_mut(c); + use_mut(b); + use_mut(a); } + +fn use_mut(_: &mut T) { } +fn use_imm(_: &T) { } diff --git a/src/test/ui/issues/issue-3096-1.stderr b/src/test/ui/issues/issue-3096-1.stderr index 783e831a2a523..b2bfe6b5e8c07 100644 --- a/src/test/ui/issues/issue-3096-1.stderr +++ b/src/test/ui/issues/issue-3096-1.stderr @@ -4,7 +4,7 @@ error[E0004]: non-exhaustive patterns: type () is non-empty LL | match () { } //~ ERROR non-exhaustive | ^^ | -help: Please ensure that all possible cases are being handled; possibly adding wildcards or more match arms. +help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms --> $DIR/issue-3096-1.rs:12:11 | LL | match () { } //~ ERROR non-exhaustive diff --git a/src/test/ui/issues/issue-3096-2.stderr b/src/test/ui/issues/issue-3096-2.stderr index 6031f25c03dff..bb9dfabe7be03 100644 --- a/src/test/ui/issues/issue-3096-2.stderr +++ b/src/test/ui/issues/issue-3096-2.stderr @@ -4,7 +4,7 @@ error[E0004]: non-exhaustive patterns: type *const bottom is non-empty LL | match x { } //~ ERROR non-exhaustive patterns | ^ | -help: Please ensure that all possible cases are being handled; possibly adding wildcards or more match arms. +help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms --> $DIR/issue-3096-2.rs:15:11 | LL | match x { } //~ ERROR non-exhaustive patterns diff --git a/src/test/ui/issues/issue-31076.rs b/src/test/ui/issues/issue-31076.rs new file mode 100644 index 0000000000000..e4531072e9be4 --- /dev/null +++ b/src/test/ui/issues/issue-31076.rs @@ -0,0 +1,17 @@ +#![feature(no_core, lang_items)] +#![no_core] + +#[lang="sized"] +trait Sized {} + +#[lang="add"] +trait Add {} + +impl Add for i32 {} + +fn main() { + let x = 5 + 6; + //~^ ERROR binary operation `+` cannot be applied to type `{integer}` + let y = 5i32 + 6i32; + //~^ ERROR binary operation `+` cannot be applied to type `i32` +} diff --git a/src/test/ui/issues/issue-31076.stderr b/src/test/ui/issues/issue-31076.stderr new file mode 100644 index 0000000000000..3a13f02d9f45f --- /dev/null +++ b/src/test/ui/issues/issue-31076.stderr @@ -0,0 +1,19 @@ +error[E0369]: binary operation `+` cannot be applied to type `{integer}` + --> $DIR/issue-31076.rs:13:13 + | +LL | let x = 5 + 6; + | ^^^^^ + | + = note: an implementation of `std::ops::Add` might be missing for `{integer}` + +error[E0369]: binary operation `+` cannot be applied to type `i32` + --> $DIR/issue-31076.rs:15:13 + | +LL | let y = 5i32 + 6i32; + | ^^^^^^^^^^^ + | + = note: an implementation of `std::ops::Add` might be missing for `i32` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/issues/issue-52126-assign-op-invariance.nll.stderr b/src/test/ui/issues/issue-52126-assign-op-invariance.nll.stderr index b25b063f3b6fb..2165d951102c2 100644 --- a/src/test/ui/issues/issue-52126-assign-op-invariance.nll.stderr +++ b/src/test/ui/issues/issue-52126-assign-op-invariance.nll.stderr @@ -3,9 +3,9 @@ error[E0597]: `line` does not live long enough | LL | let v: Vec<&str> = line.split_whitespace().collect(); | ^^^^ borrowed value does not live long enough -LL | //~^ ERROR `line` does not live long enough -LL | println!("accumulator before add_assign {:?}", acc.map); - | ------- borrow used here, in later iteration of loop +... +LL | acc += cnt2; + | --- borrow used here, in later iteration of loop ... LL | } | - `line` dropped here while still borrowed diff --git a/src/test/ui/issues/issue-52126-assign-op-invariance.rs b/src/test/ui/issues/issue-52126-assign-op-invariance.rs index b26ad9bc37dd1..1a353f9ea7cd3 100644 --- a/src/test/ui/issues/issue-52126-assign-op-invariance.rs +++ b/src/test/ui/issues/issue-52126-assign-op-invariance.rs @@ -43,7 +43,7 @@ pub fn panics() { for line in vec!["123456789".to_string(), "12345678".to_string()] { let v: Vec<&str> = line.split_whitespace().collect(); //~^ ERROR `line` does not live long enough - println!("accumulator before add_assign {:?}", acc.map); + // println!("accumulator before add_assign {:?}", acc.map); let mut map = HashMap::new(); for str_ref in v { let e = map.entry(str_ref); @@ -53,7 +53,7 @@ pub fn panics() { } let cnt2 = Counter{map}; acc += cnt2; - println!("accumulator after add_assign {:?}", acc.map); + // println!("accumulator after add_assign {:?}", acc.map); // line gets dropped here but references are kept in acc.map } } diff --git a/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr b/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr deleted file mode 100644 index fabfba94878f5..0000000000000 --- a/src/test/ui/panic-implementation/panic-implementation-deprecated.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: use of deprecated attribute `panic_implementation`: this attribute was renamed to `panic_handler`. See https://github.com/rust-lang/rust/issues/44489#issuecomment-415140224 - --> $DIR/panic-implementation-deprecated.rs:19:1 - | -LL | #[panic_implementation] - | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[panic_handler]` - | -note: lint level defined here - --> $DIR/panic-implementation-deprecated.rs:13:9 - | -LL | #![deny(deprecated)] - | ^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.nll.stderr b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.nll.stderr index 4a693a3b05d4e..389a1116c163a 100644 --- a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.nll.stderr +++ b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.nll.stderr @@ -14,6 +14,16 @@ LL | fn deref_extend_mut_field1(x: &Own) -> &mut isize { LL | &mut x.y //~ ERROR cannot borrow | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable +error[E0499]: cannot borrow `*x` as mutable more than once at a time + --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:88:19 + | +LL | let _x = &mut x.x; + | - first mutable borrow occurs here +LL | let _y = &mut x.y; //~ ERROR cannot borrow + | ^ second mutable borrow occurs here +LL | use_mut(_x); + | -- first borrow later used here + error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:98:5 | @@ -30,6 +40,16 @@ LL | fn assign_field2<'a>(x: &'a Own) { LL | x.y = 3; //~ ERROR cannot borrow | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable +error[E0499]: cannot borrow `*x` as mutable more than once at a time + --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:111:5 + | +LL | let _p: &mut Point = &mut **x; + | -- first mutable borrow occurs here +LL | x.y = 3; //~ ERROR cannot borrow + | ^ second mutable borrow occurs here +LL | use_mut(_p); + | -- first borrow later used here + error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:119:5 | @@ -62,6 +82,7 @@ LL | fn assign_method2<'a>(x: &'a Own) { LL | *x.y_mut() = 3; //~ ERROR cannot borrow | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors -For more information about this error, try `rustc --explain E0596`. +Some errors occurred: E0499, E0596. +For more information about an error, try `rustc --explain E0499`. diff --git a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs index 764d05be879b8..48eb2e239f7cd 100644 --- a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs +++ b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs @@ -86,8 +86,8 @@ fn deref_extend_mut_field3(x: &mut Own) { let _x = &mut x.x; let _y = &mut x.y; //~ ERROR cannot borrow + use_mut(_x); } - fn deref_extend_mut_field4<'a>(x: &'a mut Own) { let p = &mut **x; let _x = &mut p.x; @@ -109,8 +109,8 @@ fn assign_field3<'a>(x: &'a mut Own) { fn assign_field4<'a>(x: &'a mut Own) { let _p: &mut Point = &mut **x; x.y = 3; //~ ERROR cannot borrow + use_mut(_p); } - fn deref_imm_method(x: Own) { let __isize = x.get(); } @@ -148,3 +148,5 @@ fn assign_method3<'a>(x: &'a mut Own) { } pub fn main() {} + +fn use_mut(_: &mut T) {} diff --git a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr index d91ff6964237b..864357fee9f0c 100644 --- a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr +++ b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr @@ -21,6 +21,7 @@ LL | let _x = &mut x.x; | - first mutable borrow occurs here LL | let _y = &mut x.y; //~ ERROR cannot borrow | ^ second mutable borrow occurs here +LL | use_mut(_x); LL | } | - first borrow ends here @@ -47,6 +48,7 @@ LL | let _p: &mut Point = &mut **x; | -- first mutable borrow occurs here LL | x.y = 3; //~ ERROR cannot borrow | ^ second mutable borrow occurs here +LL | use_mut(_p); LL | } | - first borrow ends here diff --git a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr index d86ebda027efb..83fd736a997a9 100644 --- a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr +++ b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr @@ -10,7 +10,7 @@ error[E0004]: non-exhaustive patterns: type &Void is non-empty LL | let _ = match x {}; //~ ERROR non-exhaustive | ^ | -help: Please ensure that all possible cases are being handled; possibly adding wildcards or more match arms. +help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms --> $DIR/uninhabited-matches-feature-gated.rs:20:19 | LL | let _ = match x {}; //~ ERROR non-exhaustive @@ -22,7 +22,7 @@ error[E0004]: non-exhaustive patterns: type (Void,) is non-empty LL | let _ = match x {}; //~ ERROR non-exhaustive | ^ | -help: Please ensure that all possible cases are being handled; possibly adding wildcards or more match arms. +help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms --> $DIR/uninhabited-matches-feature-gated.rs:23:19 | LL | let _ = match x {}; //~ ERROR non-exhaustive @@ -34,7 +34,7 @@ error[E0004]: non-exhaustive patterns: type [Void; 1] is non-empty LL | let _ = match x {}; //~ ERROR non-exhaustive | ^ | -help: Please ensure that all possible cases are being handled; possibly adding wildcards or more match arms. +help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms --> $DIR/uninhabited-matches-feature-gated.rs:26:19 | LL | let _ = match x {}; //~ ERROR non-exhaustive diff --git a/src/test/ui/union/union-borrow-move-parent-sibling.nll.stderr b/src/test/ui/union/union-borrow-move-parent-sibling.nll.stderr index a4f5e41b5291c..6b18aff9f6b83 100644 --- a/src/test/ui/union/union-borrow-move-parent-sibling.nll.stderr +++ b/src/test/ui/union/union-borrow-move-parent-sibling.nll.stderr @@ -1,33 +1,64 @@ +error[E0502]: cannot borrow `u.y` as immutable because it is also borrowed as mutable + --> $DIR/union-borrow-move-parent-sibling.rs:25:13 + | +LL | let a = &mut u.x.0; + | ---------- mutable borrow occurs here +LL | let b = &u.y; //~ ERROR cannot borrow `u.y` + | ^^^^ immutable borrow occurs here +LL | use_borrow(a); + | - mutable borrow later used here + error[E0382]: use of moved value: `u` - --> $DIR/union-borrow-move-parent-sibling.rs:29:13 + --> $DIR/union-borrow-move-parent-sibling.rs:32:13 | LL | let a = u.x.0; | ----- value moved here -LL | let a = u.y; //~ ERROR use of moved value: `u.y` +LL | let b = u.y; //~ ERROR use of moved value: `u.y` | ^^^ value used here after move | = note: move occurs because `u` has type `U`, which does not implement the `Copy` trait +error[E0502]: cannot borrow `u.y` as immutable because it is also borrowed as mutable + --> $DIR/union-borrow-move-parent-sibling.rs:38:13 + | +LL | let a = &mut (u.x.0).0; + | -------------- mutable borrow occurs here +LL | let b = &u.y; //~ ERROR cannot borrow `u.y` + | ^^^^ immutable borrow occurs here +LL | use_borrow(a); + | - mutable borrow later used here + error[E0382]: use of moved value: `u` - --> $DIR/union-borrow-move-parent-sibling.rs:41:13 + --> $DIR/union-borrow-move-parent-sibling.rs:45:13 | LL | let a = (u.x.0).0; | --------- value moved here -LL | let a = u.y; //~ ERROR use of moved value: `u.y` +LL | let b = u.y; //~ ERROR use of moved value: `u.y` | ^^^ value used here after move | = note: move occurs because `u` has type `U`, which does not implement the `Copy` trait +error[E0502]: cannot borrow `u.x` as immutable because it is also borrowed as mutable + --> $DIR/union-borrow-move-parent-sibling.rs:51:13 + | +LL | let a = &mut *u.y; + | --------- mutable borrow occurs here +LL | let b = &u.x; //~ ERROR cannot borrow `u` (via `u.x`) + | ^^^^ immutable borrow occurs here +LL | use_borrow(a); + | - mutable borrow later used here + error[E0382]: use of moved value: `u` - --> $DIR/union-borrow-move-parent-sibling.rs:53:13 + --> $DIR/union-borrow-move-parent-sibling.rs:58:13 | LL | let a = *u.y; | ---- value moved here -LL | let a = u.x; //~ ERROR use of moved value: `u.x` +LL | let b = u.x; //~ ERROR use of moved value: `u.x` | ^^^ value used here after move | = note: move occurs because `u` has type `U`, which does not implement the `Copy` trait -error: aborting due to 3 previous errors +error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0382`. +Some errors occurred: E0382, E0502. +For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/ui/union/union-borrow-move-parent-sibling.rs b/src/test/ui/union/union-borrow-move-parent-sibling.rs index 5f504feabb266..99a073b838ca9 100644 --- a/src/test/ui/union/union-borrow-move-parent-sibling.rs +++ b/src/test/ui/union/union-borrow-move-parent-sibling.rs @@ -17,40 +17,45 @@ union U { y: Box>, } +fn use_borrow(_: &T) {} + unsafe fn parent_sibling_borrow() { let mut u = U { x: ((Vec::new(), Vec::new()), Vec::new()) }; let a = &mut u.x.0; - let a = &u.y; //~ ERROR cannot borrow `u.y` + let b = &u.y; //~ ERROR cannot borrow `u.y` + use_borrow(a); } unsafe fn parent_sibling_move() { let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) }; let a = u.x.0; - let a = u.y; //~ ERROR use of moved value: `u.y` + let b = u.y; //~ ERROR use of moved value: `u.y` } unsafe fn grandparent_sibling_borrow() { let mut u = U { x: ((Vec::new(), Vec::new()), Vec::new()) }; let a = &mut (u.x.0).0; - let a = &u.y; //~ ERROR cannot borrow `u.y` + let b = &u.y; //~ ERROR cannot borrow `u.y` + use_borrow(a); } unsafe fn grandparent_sibling_move() { let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) }; let a = (u.x.0).0; - let a = u.y; //~ ERROR use of moved value: `u.y` + let b = u.y; //~ ERROR use of moved value: `u.y` } unsafe fn deref_sibling_borrow() { let mut u = U { y: Box::default() }; let a = &mut *u.y; - let a = &u.x; //~ ERROR cannot borrow `u` (via `u.x`) + let b = &u.x; //~ ERROR cannot borrow `u` (via `u.x`) + use_borrow(a); } unsafe fn deref_sibling_move() { let u = U { x: ((Vec::new(), Vec::new()), Vec::new()) }; let a = *u.y; - let a = u.x; //~ ERROR use of moved value: `u.x` + let b = u.x; //~ ERROR use of moved value: `u.x` } diff --git a/src/test/ui/union/union-borrow-move-parent-sibling.stderr b/src/test/ui/union/union-borrow-move-parent-sibling.stderr index d855435416e5d..daf5a4f4fccaa 100644 --- a/src/test/ui/union/union-borrow-move-parent-sibling.stderr +++ b/src/test/ui/union/union-borrow-move-parent-sibling.stderr @@ -1,59 +1,62 @@ error[E0502]: cannot borrow `u.y` as immutable because `u.x.0` is also borrowed as mutable - --> $DIR/union-borrow-move-parent-sibling.rs:23:14 + --> $DIR/union-borrow-move-parent-sibling.rs:25:14 | LL | let a = &mut u.x.0; | ----- mutable borrow occurs here -LL | let a = &u.y; //~ ERROR cannot borrow `u.y` +LL | let b = &u.y; //~ ERROR cannot borrow `u.y` | ^^^ immutable borrow occurs here +LL | use_borrow(a); LL | } | - mutable borrow ends here error[E0382]: use of moved value: `u.y` - --> $DIR/union-borrow-move-parent-sibling.rs:29:9 + --> $DIR/union-borrow-move-parent-sibling.rs:32:9 | LL | let a = u.x.0; | - value moved here -LL | let a = u.y; //~ ERROR use of moved value: `u.y` +LL | let b = u.y; //~ ERROR use of moved value: `u.y` | ^ value used here after move | = note: move occurs because `u.y` has type `[type error]`, which does not implement the `Copy` trait error[E0502]: cannot borrow `u.y` as immutable because `u.x.0.0` is also borrowed as mutable - --> $DIR/union-borrow-move-parent-sibling.rs:35:14 + --> $DIR/union-borrow-move-parent-sibling.rs:38:14 | LL | let a = &mut (u.x.0).0; | --------- mutable borrow occurs here -LL | let a = &u.y; //~ ERROR cannot borrow `u.y` +LL | let b = &u.y; //~ ERROR cannot borrow `u.y` | ^^^ immutable borrow occurs here +LL | use_borrow(a); LL | } | - mutable borrow ends here error[E0382]: use of moved value: `u.y` - --> $DIR/union-borrow-move-parent-sibling.rs:41:9 + --> $DIR/union-borrow-move-parent-sibling.rs:45:9 | LL | let a = (u.x.0).0; | - value moved here -LL | let a = u.y; //~ ERROR use of moved value: `u.y` +LL | let b = u.y; //~ ERROR use of moved value: `u.y` | ^ value used here after move | = note: move occurs because `u.y` has type `[type error]`, which does not implement the `Copy` trait error[E0502]: cannot borrow `u` (via `u.x`) as immutable because `u` is also borrowed as mutable (via `*u.y`) - --> $DIR/union-borrow-move-parent-sibling.rs:47:14 + --> $DIR/union-borrow-move-parent-sibling.rs:51:14 | LL | let a = &mut *u.y; | ---- mutable borrow occurs here (via `*u.y`) -LL | let a = &u.x; //~ ERROR cannot borrow `u` (via `u.x`) +LL | let b = &u.x; //~ ERROR cannot borrow `u` (via `u.x`) | ^^^ immutable borrow occurs here (via `u.x`) +LL | use_borrow(a); LL | } | - mutable borrow ends here error[E0382]: use of moved value: `u.x` - --> $DIR/union-borrow-move-parent-sibling.rs:53:9 + --> $DIR/union-borrow-move-parent-sibling.rs:58:9 | LL | let a = *u.y; | - value moved here -LL | let a = u.x; //~ ERROR use of moved value: `u.x` +LL | let b = u.x; //~ ERROR use of moved value: `u.x` | ^ value used here after move | = note: move occurs because `u.x` has type `[type error]`, which does not implement the `Copy` trait diff --git a/src/test/ui/unop-move-semantics.nll.stderr b/src/test/ui/unop-move-semantics.nll.stderr index 111940aab2c32..bfc7736b2f32c 100644 --- a/src/test/ui/unop-move-semantics.nll.stderr +++ b/src/test/ui/unop-move-semantics.nll.stderr @@ -9,6 +9,29 @@ LL | x.clone(); //~ ERROR: use of moved value | = note: move occurs because `x` has type `T`, which does not implement the `Copy` trait +error[E0505]: cannot move out of `x` because it is borrowed + --> $DIR/unop-move-semantics.rs:25:6 + | +LL | let m = &x; + | -- borrow of `x` occurs here +... +LL | !x; //~ ERROR: cannot move out of `x` because it is borrowed + | ^ move out of `x` occurs here +... +LL | use_mut(n); use_imm(m); + | - borrow later used here + +error[E0505]: cannot move out of `y` because it is borrowed + --> $DIR/unop-move-semantics.rs:27:6 + | +LL | let n = &mut y; + | ------ borrow of `y` occurs here +... +LL | !y; //~ ERROR: cannot move out of `y` because it is borrowed + | ^ move out of `y` occurs here +LL | use_mut(n); use_imm(m); + | - borrow later used here + error[E0507]: cannot move out of borrowed content --> $DIR/unop-move-semantics.rs:34:6 | @@ -21,7 +44,7 @@ error[E0507]: cannot move out of borrowed content LL | !*n; //~ ERROR: cannot move out of borrowed content | ^^ cannot move out of borrowed content -error: aborting due to 3 previous errors +error: aborting due to 5 previous errors -Some errors occurred: E0382, E0507. +Some errors occurred: E0382, E0505, E0507. For more information about an error, try `rustc --explain E0382`. diff --git a/src/test/ui/unop-move-semantics.rs b/src/test/ui/unop-move-semantics.rs index 946566675981e..fcbbe546a3164 100644 --- a/src/test/ui/unop-move-semantics.rs +++ b/src/test/ui/unop-move-semantics.rs @@ -25,8 +25,8 @@ fn move_borrowed>(x: T, mut y: T) { !x; //~ ERROR: cannot move out of `x` because it is borrowed !y; //~ ERROR: cannot move out of `y` because it is borrowed + use_mut(n); use_imm(m); } - fn illegal_dereference>(mut x: T, y: T) { let m = &mut x; let n = &y; @@ -34,6 +34,9 @@ fn illegal_dereference>(mut x: T, y: T) { !*m; //~ ERROR: cannot move out of borrowed content !*n; //~ ERROR: cannot move out of borrowed content + use_imm(n); use_mut(m); } - fn main() {} + +fn use_mut(_: &mut T) { } +fn use_imm(_: &T) { }