Skip to content

Commit 680a4b2

Browse files
committed
Auto merge of rust-lang#72935 - Dylan-DPC:rollup-60g3ab6, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#72704 (Remote testing fixes) - rust-lang#72820 (InstCombine: Don't optimize `&mut *x` into `x`) - rust-lang#72848 (Correct generic parameter ordering in error note for E0747) - rust-lang#72902 (Add a test to ensure Fuse stays covariant) - rust-lang#72921 (Add assert to Vec with_capacity docs) Failed merges: r? @ghost
2 parents fe10f1a + ba3d982 commit 680a4b2

File tree

13 files changed

+83
-31
lines changed

13 files changed

+83
-31
lines changed

src/liballoc/vec.rs

+2
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,11 @@ impl<T> Vec<T> {
348348
/// for i in 0..10 {
349349
/// vec.push(i);
350350
/// }
351+
/// assert_eq!(vec.capacity(), 10);
351352
///
352353
/// // ...but this may make the vector reallocate
353354
/// vec.push(11);
355+
/// assert!(vec.capacity() >= 11);
354356
/// ```
355357
#[inline]
356358
#[stable(feature = "rust1", since = "1.0.0")]

src/librustc_mir/transform/instcombine.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! Performs various peephole optimizations.
22
33
use crate::transform::{MirPass, MirSource};
4-
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5+
use rustc_hir::Mutability;
56
use rustc_index::vec::Idx;
67
use rustc_middle::mir::visit::{MutVisitor, Visitor};
78
use rustc_middle::mir::{
8-
Body, Constant, Local, Location, Mutability, Operand, Place, PlaceRef, ProjectionElem, Rvalue,
9+
Body, Constant, Local, Location, Operand, Place, PlaceRef, ProjectionElem, Rvalue,
910
};
1011
use rustc_middle::ty::{self, TyCtxt};
1112
use std::mem;
@@ -39,7 +40,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
3940
}
4041

4142
fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) {
42-
if let Some(mtbl) = self.optimizations.and_stars.remove(&location) {
43+
if self.optimizations.and_stars.remove(&location) {
4344
debug!("replacing `&*`: {:?}", rvalue);
4445
let new_place = match rvalue {
4546
Rvalue::Ref(_, _, place) => {
@@ -57,10 +58,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
5758
}
5859
_ => bug!("Detected `&*` but didn't find `&*`!"),
5960
};
60-
*rvalue = Rvalue::Use(match mtbl {
61-
Mutability::Mut => Operand::Move(new_place),
62-
Mutability::Not => Operand::Copy(new_place),
63-
});
61+
*rvalue = Rvalue::Use(Operand::Copy(new_place))
6462
}
6563

6664
if let Some(constant) = self.optimizations.arrays_lengths.remove(&location) {
@@ -93,8 +91,8 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
9391
{
9492
// The dereferenced place must have type `&_`.
9593
let ty = Place::ty_from(local, proj_base, self.body, self.tcx).ty;
96-
if let ty::Ref(_, _, mtbl) = ty.kind {
97-
self.optimizations.and_stars.insert(location, mtbl);
94+
if let ty::Ref(_, _, Mutability::Not) = ty.kind {
95+
self.optimizations.and_stars.insert(location);
9896
}
9997
}
10098
}
@@ -114,6 +112,6 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> {
114112

115113
#[derive(Default)]
116114
struct OptimizationList<'tcx> {
117-
and_stars: FxHashMap<Location, Mutability>,
115+
and_stars: FxHashSet<Location>,
118116
arrays_lengths: FxHashMap<Location, Constant<'tcx>>,
119117
}

src/librustc_typeck/astconv.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use crate::collect::PlaceholderHirTyCollector;
99
use crate::middle::resolve_lifetime as rl;
1010
use crate::require_c_abi_if_c_variadic;
11+
use rustc_ast::ast::ParamKindOrd;
1112
use rustc_ast::util::lev_distance::find_best_match_for_name;
1213
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1314
use rustc_errors::ErrorReported;
@@ -483,8 +484,25 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
483484
arg.descr(),
484485
kind,
485486
);
487+
488+
let kind_ord = match kind {
489+
"lifetime" => ParamKindOrd::Lifetime,
490+
"type" => ParamKindOrd::Type,
491+
"constant" => ParamKindOrd::Const,
492+
// It's more concise to match on the string representation, though it means
493+
// the match is non-exhaustive.
494+
_ => bug!("invalid generic parameter kind {}", kind),
495+
};
496+
let arg_ord = match arg {
497+
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
498+
GenericArg::Type(_) => ParamKindOrd::Type,
499+
GenericArg::Const(_) => ParamKindOrd::Const,
500+
};
501+
486502
// This note will be true as long as generic parameters are strictly ordered by their kind.
487-
err.note(&format!("{} arguments must be provided before {} arguments", kind, arg.descr()));
503+
let (first, last) =
504+
if kind_ord < arg_ord { (kind, arg.descr()) } else { (arg.descr(), kind) };
505+
err.note(&format!("{} arguments must be provided before {} arguments", first, last));
488506
err.emit();
489507
}
490508

src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.a.Inline.after.mir

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ fn a(_1: &mut [T]) -> &mut [T] {
88
let mut _4: &mut [T]; // in scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6
99
scope 1 {
1010
debug self => _4; // in scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
11+
let mut _5: &mut [T]; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
1112
}
1213

1314
bb0: {
1415
StorageLive(_2); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
1516
StorageLive(_3); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
1617
StorageLive(_4); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6
1718
_4 = &mut (*_1); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:6
18-
_3 = move _4; // scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
19+
StorageLive(_5); // scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
20+
_5 = &mut (*_4); // scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
21+
_3 = &mut (*_5); // scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
22+
StorageDead(_5); // scope 1 at $SRC_DIR/libcore/convert/mod.rs:LL:COL
1923
_2 = &mut (*_3); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15
2024
StorageDead(_4); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:14: 3:15
2125
_0 = &mut (*_2); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:3:5: 3:15

src/test/mir-opt/inline/issue-58867-inline-as-ref-as-mut/rustc.b.Inline.after.mir

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn b(_1: &mut std::boxed::Box<T>) -> &mut T {
99
scope 1 {
1010
debug self => _4; // in scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
1111
let mut _5: &mut T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
12+
let mut _6: &mut T; // in scope 1 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
1213
}
1314

1415
bb0: {
@@ -17,8 +18,11 @@ fn b(_1: &mut std::boxed::Box<T>) -> &mut T {
1718
StorageLive(_4); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6
1819
_4 = &mut (*_1); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:6
1920
StorageLive(_5); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
20-
_5 = &mut (*(*_4)); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
21-
_3 = move _5; // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
21+
StorageLive(_6); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
22+
_6 = &mut (*(*_4)); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
23+
_5 = &mut (*_6); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
24+
_3 = &mut (*_5); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
25+
StorageDead(_6); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
2226
StorageDead(_5); // scope 1 at $SRC_DIR/liballoc/boxed.rs:LL:COL
2327
_2 = &mut (*_3); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:5: 8:15
2428
StorageDead(_4); // scope 0 at $DIR/issue-58867-inline-as-ref-as-mut.rs:8:14: 8:15

src/test/mir-opt/nrvo-simple/rustc.nrvo.RenameReturnPlace.diff

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@
2626
// + span: $DIR/nrvo-simple.rs:3:20: 3:21
2727
// + literal: Const { ty: u8, val: Value(Scalar(0x00)) }
2828
StorageLive(_3); // scope 1 at $DIR/nrvo-simple.rs:4:5: 4:19
29+
StorageLive(_5); // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18
30+
StorageLive(_6); // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18
2931
- _6 = &mut _2; // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18
3032
+ _6 = &mut _0; // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18
31-
_3 = move _1(move _6) -> bb1; // scope 1 at $DIR/nrvo-simple.rs:4:5: 4:19
33+
_5 = &mut (*_6); // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18
34+
_3 = move _1(move _5) -> bb1; // scope 1 at $DIR/nrvo-simple.rs:4:5: 4:19
3235
}
3336

3437
bb1: {
38+
StorageDead(_5); // scope 1 at $DIR/nrvo-simple.rs:4:18: 4:19
39+
StorageDead(_6); // scope 1 at $DIR/nrvo-simple.rs:4:19: 4:20
3540
StorageDead(_3); // scope 1 at $DIR/nrvo-simple.rs:4:19: 4:20
3641
- _0 = _2; // scope 1 at $DIR/nrvo-simple.rs:5:5: 5:8
3742
- StorageDead(_2); // scope 0 at $DIR/nrvo-simple.rs:6:1: 6:2

src/test/ui-fulldeps/compiler-calls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// ignore-cross-compile
55
// ignore-stage1
6+
// ignore-remote
67

78
#![feature(rustc_private)]
89

src/test/ui-fulldeps/mod_dir_path_canonicalized.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-pass
22
// Testing that a librustc_ast can parse modules with canonicalized base path
33
// ignore-cross-compile
4+
// ignore-remote
45

56
#![feature(rustc_private)]
67

src/test/ui/suggestions/suggest-move-types.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ error[E0747]: lifetime provided when a type was expected
124124
LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
125125
| ^^
126126
|
127-
= note: type arguments must be provided before lifetime arguments
127+
= note: lifetime arguments must be provided before type arguments
128128

129129
error[E0747]: lifetime provided when a type was expected
130130
--> $DIR/suggest-move-types.rs:82:56
131131
|
132132
LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
133133
| ^^
134134
|
135-
= note: type arguments must be provided before lifetime arguments
135+
= note: lifetime arguments must be provided before type arguments
136136

137137
error: aborting due to 12 previous errors
138138

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// run-pass
22

3-
#![allow(warnings)]
3+
#![allow(dead_code)]
44

5-
use std::iter::Zip;
5+
use std::iter::{Fuse, Zip};
66

7+
fn fuse_covariant<'a, I>(iter: Fuse<&'static I>) -> Fuse<&'a I> { iter }
78
fn zip_covariant<'a, A, B>(iter: Zip<&'static A, &'static B>) -> Zip<&'a A, &'a B> { iter }
89

910
fn main() { }

src/tools/compiletest/src/header.rs

+1
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ impl Config {
853853
name == util::get_pointer_width(&self.target) || // pointer width
854854
name == self.stage_id.split('-').next().unwrap() || // stage
855855
(self.target != self.host && name == "cross-compile") ||
856+
(self.remote_test_client.is_some() && name == "remote") ||
856857
match self.compare_mode {
857858
Some(CompareMode::Nll) => name == "compare-mode-nll",
858859
Some(CompareMode::Polonius) => name == "compare-mode-polonius",

src/tools/remote-test-client/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn run(support_lib_count: usize, exe: String, all_args: Vec<String>) {
224224
// by the client.
225225
for (k, v) in env::vars() {
226226
match &k[..] {
227-
"PATH" | "LD_LIBRARY_PATH" | "PWD" => continue,
227+
"PATH" | "LD_LIBRARY_PATH" | "PWD" | "RUST_TEST_TMPDIR" => continue,
228228
_ => {}
229229
}
230230
t!(client.write_all(k.as_bytes()));

src/tools/remote-test-server/src/main.rs

+28-11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ macro_rules! t {
4141

4242
static TEST: AtomicUsize = AtomicUsize::new(0);
4343

44+
#[derive(Copy, Clone)]
4445
struct Config {
4546
pub remote: bool,
4647
pub verbose: bool,
@@ -71,6 +72,12 @@ impl Config {
7172
}
7273
}
7374

75+
fn print_verbose(s: &str, conf: Config) {
76+
if conf.verbose {
77+
println!("{}", s);
78+
}
79+
}
80+
7481
fn main() {
7582
println!("starting test server");
7683

@@ -83,16 +90,19 @@ fn main() {
8390
};
8491

8592
let listener = t!(TcpListener::bind(bind_addr));
86-
let work: PathBuf = if cfg!(target_os = "android") {
87-
"/data/tmp/work".into()
93+
let (work, tmp): (PathBuf, PathBuf) = if cfg!(target_os = "android") {
94+
("/data/tmp/work".into(), "/data/tmp/work/tmp".into())
8895
} else {
89-
let mut temp_dir = env::temp_dir();
90-
temp_dir.push("work");
91-
temp_dir
96+
let mut work_dir = env::temp_dir();
97+
work_dir.push("work");
98+
let mut tmp_dir = work_dir.clone();
99+
tmp_dir.push("tmp");
100+
(work_dir, tmp_dir)
92101
};
93-
println!("listening!");
102+
println!("listening on {}!", bind_addr);
94103

95104
t!(fs::create_dir_all(&work));
105+
t!(fs::create_dir_all(&tmp));
96106

97107
let lock = Arc::new(Mutex::new(()));
98108

@@ -103,22 +113,25 @@ fn main() {
103113
continue;
104114
}
105115
if &buf[..] == b"ping" {
116+
print_verbose("Received ping", config);
106117
t!(socket.write_all(b"pong"));
107118
} else if &buf[..] == b"push" {
108-
handle_push(socket, &work);
119+
handle_push(socket, &work, config);
109120
} else if &buf[..] == b"run " {
110121
let lock = lock.clone();
111122
let work = work.clone();
112-
thread::spawn(move || handle_run(socket, &work, &lock));
123+
let tmp = tmp.clone();
124+
thread::spawn(move || handle_run(socket, &work, &tmp, &lock, config));
113125
} else {
114126
panic!("unknown command {:?}", buf);
115127
}
116128
}
117129
}
118130

119-
fn handle_push(socket: TcpStream, work: &Path) {
131+
fn handle_push(socket: TcpStream, work: &Path, config: Config) {
120132
let mut reader = BufReader::new(socket);
121-
recv(&work, &mut reader);
133+
let dst = recv(&work, &mut reader);
134+
print_verbose(&format!("push {:#?}", dst), config);
122135

123136
let mut socket = reader.into_inner();
124137
t!(socket.write_all(b"ack "));
@@ -134,7 +147,7 @@ impl Drop for RemoveOnDrop<'_> {
134147
}
135148
}
136149

137-
fn handle_run(socket: TcpStream, work: &Path, lock: &Mutex<()>) {
150+
fn handle_run(socket: TcpStream, work: &Path, tmp: &Path, lock: &Mutex<()>, config: Config) {
138151
let mut arg = Vec::new();
139152
let mut reader = BufReader::new(socket);
140153

@@ -201,6 +214,7 @@ fn handle_run(socket: TcpStream, work: &Path, lock: &Mutex<()>) {
201214
// binary is and then we'll download it all to the exe path we calculated
202215
// earlier.
203216
let exe = recv(&path, &mut reader);
217+
print_verbose(&format!("run {:#?}", exe), config);
204218

205219
let mut cmd = Command::new(&exe);
206220
cmd.args(args);
@@ -226,6 +240,9 @@ fn handle_run(socket: TcpStream, work: &Path, lock: &Mutex<()>) {
226240
cmd.env("LD_LIBRARY_PATH", format!("{}:{}", work.display(), path.display()));
227241
}
228242

243+
// Some tests assume RUST_TEST_TMPDIR exists
244+
cmd.env("RUST_TEST_TMPDIR", tmp.to_owned());
245+
229246
// Spawn the child and ferry over stdout/stderr to the socket in a framed
230247
// fashion (poor man's style)
231248
let mut child =

0 commit comments

Comments
 (0)