Skip to content

Commit 5333b87

Browse files
committed
Auto merge of rust-lang#116356 - tmandry:rollup-trfidc8, r=tmandry
Rollup of 5 pull requests Successful merges: - rust-lang#114453 (Print GHA log groups to stdout instead of stderr) - rust-lang#114454 (Replace `HashMap` with `IndexMap` in pattern binding resolve ) - rust-lang#116289 (Add missing #[inline] on AsFd impl for sys::unix::fs::File) - rust-lang#116349 (ensure the parent path's existence on `x install`) - rust-lang#116350 (Improve wording of `hint::black_box` docs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8e47113 + 132e383 commit 5333b87

File tree

8 files changed

+106
-107
lines changed

8 files changed

+106
-107
lines changed

compiler/rustc_resolve/src/late.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ type Res = def::Res<NodeId>;
4141

4242
type IdentMap<T> = FxHashMap<Ident, T>;
4343

44-
/// Map from the name in a pattern to its binding mode.
45-
type BindingMap = IdentMap<BindingInfo>;
46-
4744
use diagnostics::{
4845
ElisionFnParameter, LifetimeElisionCandidate, MissingLifetime, MissingLifetimeKind,
4946
};
@@ -3164,8 +3161,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
31643161
/// this is done hygienically. This could arise for a macro
31653162
/// that expands into an or-pattern where one 'x' was from the
31663163
/// user and one 'x' came from the macro.
3167-
fn binding_mode_map(&mut self, pat: &Pat) -> BindingMap {
3168-
let mut binding_map = FxHashMap::default();
3164+
fn binding_mode_map(&mut self, pat: &Pat) -> FxIndexMap<Ident, BindingInfo> {
3165+
let mut binding_map = FxIndexMap::default();
31693166

31703167
pat.walk(&mut |pat| {
31713168
match pat.kind {
@@ -3200,22 +3197,28 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
32003197

32013198
/// Checks that all of the arms in an or-pattern have exactly the
32023199
/// same set of bindings, with the same binding modes for each.
3203-
fn check_consistent_bindings(&mut self, pats: &[P<Pat>]) -> Vec<BindingMap> {
3204-
let mut missing_vars = FxHashMap::default();
3205-
let mut inconsistent_vars = FxHashMap::default();
3200+
fn check_consistent_bindings(
3201+
&mut self,
3202+
pats: &[P<Pat>],
3203+
) -> Vec<FxIndexMap<Ident, BindingInfo>> {
3204+
// pats is consistent.
3205+
let mut missing_vars = FxIndexMap::default();
3206+
let mut inconsistent_vars = FxIndexMap::default();
32063207

32073208
// 1) Compute the binding maps of all arms.
32083209
let maps = pats.iter().map(|pat| self.binding_mode_map(pat)).collect::<Vec<_>>();
32093210

32103211
// 2) Record any missing bindings or binding mode inconsistencies.
3211-
for (map_outer, pat_outer) in pats.iter().enumerate().map(|(idx, pat)| (&maps[idx], pat)) {
3212+
for (map_outer, pat_outer) in maps.iter().zip(pats.iter()) {
32123213
// Check against all arms except for the same pattern which is always self-consistent.
3213-
let inners = pats
3214+
let inners = maps
32143215
.iter()
3215-
.enumerate()
3216+
.zip(pats.iter())
32163217
.filter(|(_, pat)| pat.id != pat_outer.id)
3217-
.flat_map(|(idx, _)| maps[idx].iter())
3218-
.map(|(key, binding)| (key.name, map_outer.get(&key), binding));
3218+
.flat_map(|(map, _)| map)
3219+
.map(|(key, binding)| (key.name, map_outer.get(key), binding));
3220+
3221+
let inners = inners.collect::<Vec<_>>();
32193222

32203223
for (name, info, &binding_inner) in inners {
32213224
match info {
@@ -3244,10 +3247,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
32443247
}
32453248

32463249
// 3) Report all missing variables we found.
3247-
let mut missing_vars = missing_vars.into_iter().collect::<Vec<_>>();
3248-
missing_vars.sort_by_key(|&(sym, ref _err)| sym);
3249-
3250-
for (name, mut v) in missing_vars.into_iter() {
3250+
for (name, mut v) in missing_vars {
32513251
if inconsistent_vars.contains_key(&name) {
32523252
v.could_be_path = false;
32533253
}
@@ -3258,10 +3258,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
32583258
}
32593259

32603260
// 4) Report all inconsistencies in binding modes we found.
3261-
let mut inconsistent_vars = inconsistent_vars.iter().collect::<Vec<_>>();
3262-
inconsistent_vars.sort();
32633261
for (name, v) in inconsistent_vars {
3264-
self.report_error(v.0, ResolutionError::VariableBoundWithDifferentMode(*name, v.1));
3262+
self.report_error(v.0, ResolutionError::VariableBoundWithDifferentMode(name, v.1));
32653263
}
32663264

32673265
// 5) Finally bubble up all the binding maps.

library/core/src/hint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub fn spin_loop() {
277277
/// - Treats the call to `contains` and its result as volatile: the body of `benchmark` cannot
278278
/// optimize this away
279279
///
280-
/// This makes our benchmark much more realistic to how the function would be used in situ, where
280+
/// This makes our benchmark much more realistic to how the function would actually be used, where
281281
/// arguments are usually not known at compile time and the result is used in some way.
282282
#[inline]
283283
#[stable(feature = "bench_black_box", since = "1.66.0")]

library/std/src/sys/unix/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,7 @@ impl FromInner<FileDesc> for File {
13911391
}
13921392

13931393
impl AsFd for File {
1394+
#[inline]
13941395
fn as_fd(&self) -> BorrowedFd<'_> {
13951396
self.0.as_fd()
13961397
}

src/bootstrap/install.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ fn sanitize_sh(path: &Path) -> String {
4646
}
4747

4848
fn is_dir_writable_for_user(dir: &PathBuf) -> bool {
49-
let tmp_file = dir.join(".tmp");
50-
match fs::File::create(&tmp_file) {
49+
let tmp = dir.join(".tmp");
50+
match fs::create_dir_all(&tmp) {
5151
Ok(_) => {
52-
fs::remove_file(tmp_file).unwrap();
52+
fs::remove_dir_all(tmp).unwrap();
5353
true
5454
}
5555
Err(e) => {

src/tools/build_helper/src/ci.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ pub mod gha {
8282

8383
fn start_group(name: impl std::fmt::Display) {
8484
if is_in_gha() {
85-
eprintln!("::group::{name}");
85+
println!("::group::{name}");
8686
} else {
87-
eprintln!("{name}")
87+
println!("{name}")
8888
}
8989
}
9090

9191
fn end_group() {
9292
if is_in_gha() {
93-
eprintln!("::endgroup::");
93+
println!("::endgroup::");
9494
}
9595
}
9696

tests/ui/or-patterns/missing-bindings.stderr

+42-42
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,6 @@ LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
103103
| |
104104
| variable not in all patterns
105105

106-
error[E0408]: variable `c` is not bound in all patterns
107-
--> $DIR/missing-bindings.rs:45:33
108-
|
109-
LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
110-
| - ^^^^ pattern doesn't bind `c`
111-
| |
112-
| variable not in all patterns
113-
114-
error[E0408]: variable `d` is not bound in all patterns
115-
--> $DIR/missing-bindings.rs:45:33
116-
|
117-
LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
118-
| - ^^^^ pattern doesn't bind `d`
119-
| |
120-
| variable not in all patterns
121-
122106
error[E0408]: variable `e` is not bound in all patterns
123107
--> $DIR/missing-bindings.rs:45:10
124108
|
@@ -143,6 +127,22 @@ LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
143127
| |
144128
| variable not in all patterns
145129

130+
error[E0408]: variable `c` is not bound in all patterns
131+
--> $DIR/missing-bindings.rs:45:33
132+
|
133+
LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
134+
| - ^^^^ pattern doesn't bind `c`
135+
| |
136+
| variable not in all patterns
137+
138+
error[E0408]: variable `d` is not bound in all patterns
139+
--> $DIR/missing-bindings.rs:45:33
140+
|
141+
LL | let (A(A(a, b) | B(c), d) | B(e)) = Y;
142+
| - ^^^^ pattern doesn't bind `d`
143+
| |
144+
| variable not in all patterns
145+
146146
error[E0408]: variable `a` is not bound in all patterns
147147
--> $DIR/missing-bindings.rs:61:29
148148
|
@@ -151,14 +151,6 @@ LL | Ok(a) | Err(_),
151151
| |
152152
| variable not in all patterns
153153

154-
error[E0408]: variable `a` is not bound in all patterns
155-
--> $DIR/missing-bindings.rs:69:21
156-
|
157-
LL | A(_, a) |
158-
| - variable not in all patterns
159-
LL | B(b),
160-
| ^^^^ pattern doesn't bind `a`
161-
162154
error[E0408]: variable `b` is not bound in all patterns
163155
--> $DIR/missing-bindings.rs:68:21
164156
|
@@ -167,6 +159,14 @@ LL | A(_, a) |
167159
LL | B(b),
168160
| - variable not in all patterns
169161

162+
error[E0408]: variable `a` is not bound in all patterns
163+
--> $DIR/missing-bindings.rs:69:21
164+
|
165+
LL | A(_, a) |
166+
| - variable not in all patterns
167+
LL | B(b),
168+
| ^^^^ pattern doesn't bind `a`
169+
170170
error[E0408]: variable `a` is not bound in all patterns
171171
--> $DIR/missing-bindings.rs:72:17
172172
|
@@ -185,6 +185,24 @@ LL | B(b),
185185
LL | B(_)
186186
| ^^^^ pattern doesn't bind `b`
187187

188+
error[E0408]: variable `b` is not bound in all patterns
189+
--> $DIR/missing-bindings.rs:57:13
190+
|
191+
LL | / V1(
192+
LL | |
193+
LL | |
194+
LL | | A(
195+
... |
196+
LL | | B(Ok(a) | Err(a))
197+
LL | | ) |
198+
| |_____________^ pattern doesn't bind `b`
199+
...
200+
LL | B(b),
201+
| - variable not in all patterns
202+
...
203+
LL | V3(c),
204+
| ^^^^^ pattern doesn't bind `b`
205+
188206
error[E0408]: variable `c` is not bound in all patterns
189207
--> $DIR/missing-bindings.rs:57:13
190208
|
@@ -219,24 +237,6 @@ LL | A(_, a) |
219237
LL | V3(c),
220238
| ^^^^^ pattern doesn't bind `a`
221239

222-
error[E0408]: variable `b` is not bound in all patterns
223-
--> $DIR/missing-bindings.rs:57:13
224-
|
225-
LL | / V1(
226-
LL | |
227-
LL | |
228-
LL | | A(
229-
... |
230-
LL | | B(Ok(a) | Err(a))
231-
LL | | ) |
232-
| |_____________^ pattern doesn't bind `b`
233-
...
234-
LL | B(b),
235-
| - variable not in all patterns
236-
...
237-
LL | V3(c),
238-
| ^^^^^ pattern doesn't bind `b`
239-
240240
error: aborting due to 26 previous errors
241241

242242
For more information about this error, try `rustc --explain E0408`.

tests/ui/resolve/resolve-inconsistent-names.stderr

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
error[E0408]: variable `a` is not bound in all patterns
2-
--> $DIR/resolve-inconsistent-names.rs:13:12
3-
|
4-
LL | a | b => {}
5-
| - ^ pattern doesn't bind `a`
6-
| |
7-
| variable not in all patterns
8-
91
error[E0408]: variable `b` is not bound in all patterns
102
--> $DIR/resolve-inconsistent-names.rs:13:8
113
|
@@ -14,6 +6,14 @@ LL | a | b => {}
146
| |
157
| pattern doesn't bind `b`
168

9+
error[E0408]: variable `a` is not bound in all patterns
10+
--> $DIR/resolve-inconsistent-names.rs:13:12
11+
|
12+
LL | a | b => {}
13+
| - ^ pattern doesn't bind `a`
14+
| |
15+
| variable not in all patterns
16+
1717
error[E0408]: variable `c` is not bound in all patterns
1818
--> $DIR/resolve-inconsistent-names.rs:19:9
1919
|
@@ -54,6 +54,19 @@ LL | (A, B) | (ref B, c) | (c, A) => ()
5454
| |
5555
| first binding
5656

57+
error[E0408]: variable `Const2` is not bound in all patterns
58+
--> $DIR/resolve-inconsistent-names.rs:31:9
59+
|
60+
LL | (CONST1, _) | (_, Const2) => ()
61+
| ^^^^^^^^^^^ ------ variable not in all patterns
62+
| |
63+
| pattern doesn't bind `Const2`
64+
|
65+
help: if you meant to match on constant `m::Const2`, use the full path in the pattern
66+
|
67+
LL | (CONST1, _) | (_, m::Const2) => ()
68+
| ~~~~~~~~~
69+
5770
error[E0408]: variable `CONST1` is not bound in all patterns
5871
--> $DIR/resolve-inconsistent-names.rs:31:23
5972
|
@@ -68,19 +81,6 @@ note: you might have meant to match on constant `m::CONST1`, which exists but is
6881
LL | const CONST1: usize = 10;
6982
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible
7083

71-
error[E0408]: variable `Const2` is not bound in all patterns
72-
--> $DIR/resolve-inconsistent-names.rs:31:9
73-
|
74-
LL | (CONST1, _) | (_, Const2) => ()
75-
| ^^^^^^^^^^^ ------ variable not in all patterns
76-
| |
77-
| pattern doesn't bind `Const2`
78-
|
79-
help: if you meant to match on constant `m::Const2`, use the full path in the pattern
80-
|
81-
LL | (CONST1, _) | (_, m::Const2) => ()
82-
| ~~~~~~~~~
83-
8484
error[E0308]: mismatched types
8585
--> $DIR/resolve-inconsistent-names.rs:19:19
8686
|

tests/ui/span/issue-39698.stderr

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
error[E0408]: variable `b` is not bound in all patterns
2+
--> $DIR/issue-39698.rs:10:9
3+
|
4+
LL | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
5+
| ^^^^^^^^^^^ - ^^^^^^^^ ^^^^^^^^ pattern doesn't bind `b`
6+
| | | |
7+
| | | pattern doesn't bind `b`
8+
| | variable not in all patterns
9+
| pattern doesn't bind `b`
10+
111
error[E0408]: variable `c` is not bound in all patterns
212
--> $DIR/issue-39698.rs:10:9
313
|
@@ -8,16 +18,6 @@ LL | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}
818
| | pattern doesn't bind `c`
919
| pattern doesn't bind `c`
1020

11-
error[E0408]: variable `d` is not bound in all patterns
12-
--> $DIR/issue-39698.rs:10:37
13-
|
14-
LL | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
15-
| - - ^^^^^^^^ ^^^^^^^^ pattern doesn't bind `d`
16-
| | | |
17-
| | | pattern doesn't bind `d`
18-
| | variable not in all patterns
19-
| variable not in all patterns
20-
2121
error[E0408]: variable `a` is not bound in all patterns
2222
--> $DIR/issue-39698.rs:10:23
2323
|
@@ -28,15 +28,15 @@ LL | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}
2828
| | pattern doesn't bind `a`
2929
| variable not in all patterns
3030

31-
error[E0408]: variable `b` is not bound in all patterns
32-
--> $DIR/issue-39698.rs:10:9
31+
error[E0408]: variable `d` is not bound in all patterns
32+
--> $DIR/issue-39698.rs:10:37
3333
|
3434
LL | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
35-
| ^^^^^^^^^^^ - ^^^^^^^^ ^^^^^^^^ pattern doesn't bind `b`
36-
| | | |
37-
| | | pattern doesn't bind `b`
38-
| | variable not in all patterns
39-
| pattern doesn't bind `b`
35+
| - - ^^^^^^^^ ^^^^^^^^ pattern doesn't bind `d`
36+
| | | |
37+
| | | pattern doesn't bind `d`
38+
| | variable not in all patterns
39+
| variable not in all patterns
4040

4141
error: aborting due to 4 previous errors
4242

0 commit comments

Comments
 (0)