diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 42fb1f8c737b3..22d43468771b4 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -348,9 +348,11 @@ impl Vec { /// for i in 0..10 { /// vec.push(i); /// } + /// assert_eq!(vec.capacity(), 10); /// /// // ...but this may make the vector reallocate /// vec.push(11); + /// assert!(vec.capacity() >= 11); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index a016892d982d1..7967137e01e54 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -1,11 +1,12 @@ //! Performs various peephole optimizations. use crate::transform::{MirPass, MirSource}; -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_hir::Mutability; use rustc_index::vec::Idx; use rustc_middle::mir::visit::{MutVisitor, Visitor}; use rustc_middle::mir::{ - Body, Constant, Local, Location, Mutability, Operand, Place, PlaceRef, ProjectionElem, Rvalue, + Body, Constant, Local, Location, Operand, Place, PlaceRef, ProjectionElem, Rvalue, }; use rustc_middle::ty::{self, TyCtxt}; use std::mem; @@ -39,7 +40,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> { } fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) { - if let Some(mtbl) = self.optimizations.and_stars.remove(&location) { + if self.optimizations.and_stars.remove(&location) { debug!("replacing `&*`: {:?}", rvalue); let new_place = match rvalue { Rvalue::Ref(_, _, place) => { @@ -57,10 +58,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> { } _ => bug!("Detected `&*` but didn't find `&*`!"), }; - *rvalue = Rvalue::Use(match mtbl { - Mutability::Mut => Operand::Move(new_place), - Mutability::Not => Operand::Copy(new_place), - }); + *rvalue = Rvalue::Use(Operand::Copy(new_place)) } if let Some(constant) = self.optimizations.arrays_lengths.remove(&location) { @@ -93,8 +91,8 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> { { // The dereferenced place must have type `&_`. let ty = Place::ty_from(local, proj_base, self.body, self.tcx).ty; - if let ty::Ref(_, _, mtbl) = ty.kind { - self.optimizations.and_stars.insert(location, mtbl); + if let ty::Ref(_, _, Mutability::Not) = ty.kind { + self.optimizations.and_stars.insert(location); } } } @@ -114,6 +112,6 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> { #[derive(Default)] struct OptimizationList<'tcx> { - and_stars: FxHashMap, + and_stars: FxHashSet, arrays_lengths: FxHashMap>, } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index ab9db159038af..f1dc7e5390629 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -8,6 +8,7 @@ use crate::collect::PlaceholderHirTyCollector; use crate::middle::resolve_lifetime as rl; use crate::require_c_abi_if_c_variadic; +use rustc_ast::ast::ParamKindOrd; use rustc_ast::util::lev_distance::find_best_match_for_name; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::ErrorReported; @@ -483,8 +484,25 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { arg.descr(), kind, ); + + let kind_ord = match kind { + "lifetime" => ParamKindOrd::Lifetime, + "type" => ParamKindOrd::Type, + "constant" => ParamKindOrd::Const, + // It's more concise to match on the string representation, though it means + // the match is non-exhaustive. + _ => bug!("invalid generic parameter kind {}", kind), + }; + let arg_ord = match arg { + GenericArg::Lifetime(_) => ParamKindOrd::Lifetime, + GenericArg::Type(_) => ParamKindOrd::Type, + GenericArg::Const(_) => ParamKindOrd::Const, + }; + // This note will be true as long as generic parameters are strictly ordered by their kind. - err.note(&format!("{} arguments must be provided before {} arguments", kind, arg.descr())); + let (first, last) = + if kind_ord < arg_ord { (kind, arg.descr()) } else { (arg.descr(), kind) }; + err.note(&format!("{} arguments must be provided before {} arguments", first, last)); err.emit(); } diff --git a/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.a.Inline.after.mir b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.a.Inline.after.mir index 8751469d265a2..44f412c2e2674 100644 --- a/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.a.Inline.after.mir +++ b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.a.Inline.after.mir @@ -8,6 +8,7 @@ fn a(_1: &mut [T]) -> &mut [T] { let mut _4: &mut [T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6 scope 1 { debug self => _4; // in scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + let mut _5: &mut [T]; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15 } bb0: { @@ -15,7 +16,10 @@ fn a(_1: &mut [T]) -> &mut [T] { StorageLive(_3); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15 StorageLive(_4); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6 _4 = &mut (*_1); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6 - _3 = move _4; // scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + StorageLive(_5); // scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + _5 = &mut (*_4); // scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + _3 = &mut (*_5); // scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + StorageDead(_5); // scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL _2 = &mut (*_3); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15 StorageDead(_4); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:14: 3:15 _0 = &mut (*_2); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15 diff --git a/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.b.Inline.after.mir b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.b.Inline.after.mir index 743da27a049f9..48e48f989bd94 100644 --- a/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.b.Inline.after.mir +++ b/src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.b.Inline.after.mir @@ -9,6 +9,7 @@ fn b(_1: &mut std::boxed::Box) -> &mut T { scope 1 { debug self => _4; // in scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL let mut _5: &mut T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 + let mut _6: &mut T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 } bb0: { @@ -17,8 +18,11 @@ fn b(_1: &mut std::boxed::Box) -> &mut T { StorageLive(_4); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6 _4 = &mut (*_1); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6 StorageLive(_5); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL - _5 = &mut (*(*_4)); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL - _3 = move _5; // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL + StorageLive(_6); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL + _6 = &mut (*(*_4)); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL + _5 = &mut (*_6); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL + _3 = &mut (*_5); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL + StorageDead(_6); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL StorageDead(_5); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL _2 = &mut (*_3); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15 StorageDead(_4); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:14: 8:15 diff --git a/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff b/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff index 79d92897cb572..4511470f3a50f 100644 --- a/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff +++ b/src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff @@ -26,12 +26,17 @@ // + span: $DIR/nrvo-simple.rs:3:20: 3:21 // + literal: Const { ty: u8, val: Value(Scalar(0x00)) } StorageLive(_3); // scope 1 at $DIR/nrvo-simple.rs:4:5: 4:19 + StorageLive(_5); // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18 + StorageLive(_6); // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18 - _6 = &mut _2; // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18 + _6 = &mut _0; // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18 - _3 = move _1(move _6) -> bb1; // scope 1 at $DIR/nrvo-simple.rs:4:5: 4:19 + _5 = &mut (*_6); // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18 + _3 = move _1(move _5) -> bb1; // scope 1 at $DIR/nrvo-simple.rs:4:5: 4:19 } bb1: { + StorageDead(_5); // scope 1 at $DIR/nrvo-simple.rs:4:18: 4:19 + StorageDead(_6); // scope 1 at $DIR/nrvo-simple.rs:4:19: 4:20 StorageDead(_3); // scope 1 at $DIR/nrvo-simple.rs:4:19: 4:20 - _0 = _2; // scope 1 at $DIR/nrvo-simple.rs:5:5: 5:8 - StorageDead(_2); // scope 0 at $DIR/nrvo-simple.rs:6:1: 6:2 diff --git a/src/test/ui-fulldeps/compiler-calls.rs b/src/test/ui-fulldeps/compiler-calls.rs index bd9113c7079ea..e97dcab6ae560 100644 --- a/src/test/ui-fulldeps/compiler-calls.rs +++ b/src/test/ui-fulldeps/compiler-calls.rs @@ -3,6 +3,7 @@ // ignore-cross-compile // ignore-stage1 +// ignore-remote #![feature(rustc_private)] diff --git a/src/test/ui-fulldeps/mod_dir_path_canonicalized.rs b/src/test/ui-fulldeps/mod_dir_path_canonicalized.rs index 3c5738f574c26..ff7bbafe7c212 100644 --- a/src/test/ui-fulldeps/mod_dir_path_canonicalized.rs +++ b/src/test/ui-fulldeps/mod_dir_path_canonicalized.rs @@ -1,6 +1,7 @@ // run-pass // Testing that a librustc_ast can parse modules with canonicalized base path // ignore-cross-compile +// ignore-remote #![feature(rustc_private)] diff --git a/src/test/ui/suggestions/suggest-move-types.stderr b/src/test/ui/suggestions/suggest-move-types.stderr index 3bb6fd6e4f423..96f1656bae4ac 100644 --- a/src/test/ui/suggestions/suggest-move-types.stderr +++ b/src/test/ui/suggestions/suggest-move-types.stderr @@ -124,7 +124,7 @@ error[E0747]: lifetime provided when a type was expected LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime> { | ^^ | - = note: type arguments must be provided before lifetime arguments + = note: lifetime arguments must be provided before type arguments error[E0747]: lifetime provided when a type was expected --> $DIR/suggest-move-types.rs:82:56 @@ -132,7 +132,7 @@ error[E0747]: lifetime provided when a type was expected LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime> { | ^^ | - = note: type arguments must be provided before lifetime arguments + = note: lifetime arguments must be provided before type arguments error: aborting due to 12 previous errors diff --git a/src/test/ui/variance-iterators-in-libcore.rs b/src/test/ui/variance-iterators-in-libcore.rs index 2ab3a8ab5c129..a542e44d517a7 100644 --- a/src/test/ui/variance-iterators-in-libcore.rs +++ b/src/test/ui/variance-iterators-in-libcore.rs @@ -1,9 +1,10 @@ // run-pass -#![allow(warnings)] +#![allow(dead_code)] -use std::iter::Zip; +use std::iter::{Fuse, Zip}; +fn fuse_covariant<'a, I>(iter: Fuse<&'static I>) -> Fuse<&'a I> { iter } fn zip_covariant<'a, A, B>(iter: Zip<&'static A, &'static B>) -> Zip<&'a A, &'a B> { iter } fn main() { } diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index cb648db8830ef..9d1940dd4d6c2 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -853,6 +853,7 @@ impl Config { name == util::get_pointer_width(&self.target) || // pointer width name == self.stage_id.split('-').next().unwrap() || // stage (self.target != self.host && name == "cross-compile") || + (self.remote_test_client.is_some() && name == "remote") || match self.compare_mode { Some(CompareMode::Nll) => name == "compare-mode-nll", Some(CompareMode::Polonius) => name == "compare-mode-polonius", diff --git a/src/tools/remote-test-client/src/main.rs b/src/tools/remote-test-client/src/main.rs index 259477e9a1c36..efc29163455be 100644 --- a/src/tools/remote-test-client/src/main.rs +++ b/src/tools/remote-test-client/src/main.rs @@ -224,7 +224,7 @@ fn run(support_lib_count: usize, exe: String, all_args: Vec) { // by the client. for (k, v) in env::vars() { match &k[..] { - "PATH" | "LD_LIBRARY_PATH" | "PWD" => continue, + "PATH" | "LD_LIBRARY_PATH" | "PWD" | "RUST_TEST_TMPDIR" => continue, _ => {} } t!(client.write_all(k.as_bytes())); diff --git a/src/tools/remote-test-server/src/main.rs b/src/tools/remote-test-server/src/main.rs index e7eff35e55725..8c56910e2dfad 100644 --- a/src/tools/remote-test-server/src/main.rs +++ b/src/tools/remote-test-server/src/main.rs @@ -41,6 +41,7 @@ macro_rules! t { static TEST: AtomicUsize = AtomicUsize::new(0); +#[derive(Copy, Clone)] struct Config { pub remote: bool, pub verbose: bool, @@ -71,6 +72,12 @@ impl Config { } } +fn print_verbose(s: &str, conf: Config) { + if conf.verbose { + println!("{}", s); + } +} + fn main() { println!("starting test server"); @@ -83,16 +90,19 @@ fn main() { }; let listener = t!(TcpListener::bind(bind_addr)); - let work: PathBuf = if cfg!(target_os = "android") { - "/data/tmp/work".into() + let (work, tmp): (PathBuf, PathBuf) = if cfg!(target_os = "android") { + ("/data/tmp/work".into(), "/data/tmp/work/tmp".into()) } else { - let mut temp_dir = env::temp_dir(); - temp_dir.push("work"); - temp_dir + let mut work_dir = env::temp_dir(); + work_dir.push("work"); + let mut tmp_dir = work_dir.clone(); + tmp_dir.push("tmp"); + (work_dir, tmp_dir) }; - println!("listening!"); + println!("listening on {}!", bind_addr); t!(fs::create_dir_all(&work)); + t!(fs::create_dir_all(&tmp)); let lock = Arc::new(Mutex::new(())); @@ -103,22 +113,25 @@ fn main() { continue; } if &buf[..] == b"ping" { + print_verbose("Received ping", config); t!(socket.write_all(b"pong")); } else if &buf[..] == b"push" { - handle_push(socket, &work); + handle_push(socket, &work, config); } else if &buf[..] == b"run " { let lock = lock.clone(); let work = work.clone(); - thread::spawn(move || handle_run(socket, &work, &lock)); + let tmp = tmp.clone(); + thread::spawn(move || handle_run(socket, &work, &tmp, &lock, config)); } else { panic!("unknown command {:?}", buf); } } } -fn handle_push(socket: TcpStream, work: &Path) { +fn handle_push(socket: TcpStream, work: &Path, config: Config) { let mut reader = BufReader::new(socket); - recv(&work, &mut reader); + let dst = recv(&work, &mut reader); + print_verbose(&format!("push {:#?}", dst), config); let mut socket = reader.into_inner(); t!(socket.write_all(b"ack ")); @@ -134,7 +147,7 @@ impl Drop for RemoveOnDrop<'_> { } } -fn handle_run(socket: TcpStream, work: &Path, lock: &Mutex<()>) { +fn handle_run(socket: TcpStream, work: &Path, tmp: &Path, lock: &Mutex<()>, config: Config) { let mut arg = Vec::new(); let mut reader = BufReader::new(socket); @@ -201,6 +214,7 @@ fn handle_run(socket: TcpStream, work: &Path, lock: &Mutex<()>) { // binary is and then we'll download it all to the exe path we calculated // earlier. let exe = recv(&path, &mut reader); + print_verbose(&format!("run {:#?}", exe), config); let mut cmd = Command::new(&exe); cmd.args(args); @@ -226,6 +240,9 @@ fn handle_run(socket: TcpStream, work: &Path, lock: &Mutex<()>) { cmd.env("LD_LIBRARY_PATH", format!("{}:{}", work.display(), path.display())); } + // Some tests assume RUST_TEST_TMPDIR exists + cmd.env("RUST_TEST_TMPDIR", tmp.to_owned()); + // Spawn the child and ferry over stdout/stderr to the socket in a framed // fashion (poor man's style) let mut child =