Skip to content

Commit 0b79504

Browse files
committed
Auto merge of rust-lang#111493 - matthiaskrgr:rollup-iw1z59b, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#111179 (Fix instrument-coverage tests by using Python to sort instantiation groups) - rust-lang#111393 (bump windows crate 0.46 -> 0.48) - rust-lang#111441 (Verify copies of mutable pointers in 2 stages in ReferencePropagation) - rust-lang#111456 (Update cargo) - rust-lang#111490 (Don't ICE in layout computation for placeholder types) - rust-lang#111492 (use by ref TokenTree iterator to avoid a few clones) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 699a862 + 9039de6 commit 0b79504

31 files changed

+475
-138
lines changed

Cargo.lock

+7-16
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ dependencies = [
741741
"tracing-subscriber",
742742
"unified-diff",
743743
"walkdir",
744-
"windows 0.46.0",
744+
"windows",
745745
]
746746

747747
[[package]]
@@ -1647,7 +1647,7 @@ dependencies = [
16471647
"iana-time-zone-haiku",
16481648
"js-sys",
16491649
"wasm-bindgen",
1650-
"windows 0.48.0",
1650+
"windows",
16511651
]
16521652

16531653
[[package]]
@@ -3259,7 +3259,7 @@ dependencies = [
32593259
"tempfile",
32603260
"thorin-dwp",
32613261
"tracing",
3262-
"windows 0.46.0",
3262+
"windows",
32633263
]
32643264

32653265
[[package]]
@@ -3315,7 +3315,7 @@ dependencies = [
33153315
"tempfile",
33163316
"thin-vec",
33173317
"tracing",
3318-
"windows 0.46.0",
3318+
"windows",
33193319
]
33203320

33213321
[[package]]
@@ -3376,7 +3376,7 @@ dependencies = [
33763376
"rustc_ty_utils",
33773377
"serde_json",
33783378
"tracing",
3379-
"windows 0.46.0",
3379+
"windows",
33803380
]
33813381

33823382
[[package]]
@@ -3426,7 +3426,7 @@ dependencies = [
34263426
"termize",
34273427
"tracing",
34283428
"unicode-width",
3429-
"windows 0.46.0",
3429+
"windows",
34303430
]
34313431

34323432
[[package]]
@@ -4096,7 +4096,7 @@ dependencies = [
40964096
"smallvec",
40974097
"termize",
40984098
"tracing",
4099-
"windows 0.46.0",
4099+
"windows",
41004100
]
41014101

41024102
[[package]]
@@ -5498,15 +5498,6 @@ version = "0.4.0"
54985498
source = "registry+https://github.com/rust-lang/crates.io-index"
54995499
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
55005500

5501-
[[package]]
5502-
name = "windows"
5503-
version = "0.46.0"
5504-
source = "registry+https://github.com/rust-lang/crates.io-index"
5505-
checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25"
5506-
dependencies = [
5507-
"windows-targets 0.42.2",
5508-
]
5509-
55105501
[[package]]
55115502
name = "windows"
55125503
version = "0.48.0"

compiler/rustc_builtin_macros/src/concat_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn expand_concat_idents<'cx>(
1919
}
2020

2121
let mut res_str = String::new();
22-
for (i, e) in tts.into_trees().enumerate() {
22+
for (i, e) in tts.trees().enumerate() {
2323
if i & 1 == 1 {
2424
match e {
2525
TokenTree::Token(Token { kind: token::Comma, .. }, _) => {}

compiler/rustc_builtin_macros/src/trace_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub fn expand_trace_macros(
88
sp: Span,
99
tt: TokenStream,
1010
) -> Box<dyn base::MacResult + 'static> {
11-
let mut cursor = tt.into_trees();
11+
let mut cursor = tt.trees();
1212
let mut err = false;
1313
let value = match &cursor.next() {
1414
Some(TokenTree::Token(token, _)) if token.is_keyword(kw::True) => true,

compiler/rustc_codegen_ssa/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ default-features = false
5151
features = ["read_core", "elf", "macho", "pe", "unaligned", "archive", "write"]
5252

5353
[target.'cfg(windows)'.dependencies.windows]
54-
version = "0.46.0"
54+
version = "0.48.0"
5555
features = ["Win32_Globalization"]

compiler/rustc_data_structures/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ itertools = "0.10.1"
3737
version = "0.11"
3838

3939
[target.'cfg(windows)'.dependencies.windows]
40-
version = "0.46.0"
40+
version = "0.48.0"
4141
features = [
4242
"Win32_Foundation",
4343
"Win32_Storage_FileSystem",

compiler/rustc_data_structures/src/profiling.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -865,14 +865,16 @@ cfg_if! {
865865
use std::mem;
866866

867867
use windows::{
868-
Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},
868+
// FIXME: change back to K32GetProcessMemoryInfo when windows crate
869+
// updated to 0.49.0+ to drop dependency on psapi.dll
870+
Win32::System::ProcessStatus::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},
869871
Win32::System::Threading::GetCurrentProcess,
870872
};
871873

872874
let mut pmc = PROCESS_MEMORY_COUNTERS::default();
873875
let pmc_size = mem::size_of_val(&pmc);
874876
unsafe {
875-
K32GetProcessMemoryInfo(
877+
GetProcessMemoryInfo(
876878
GetCurrentProcess(),
877879
&mut pmc,
878880
pmc_size as u32,

compiler/rustc_driver_impl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ rustc_mir_transform = { path = "../rustc_mir_transform" }
5757
libc = "0.2"
5858

5959
[target.'cfg(windows)'.dependencies.windows]
60-
version = "0.46.0"
60+
version = "0.48.0"
6161
features = [
6262
"Win32_System_Diagnostics_Debug",
6363
]

compiler/rustc_errors/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ serde = { version = "1.0.125", features = [ "derive" ] }
2727
serde_json = "1.0.59"
2828

2929
[target.'cfg(windows)'.dependencies.windows]
30-
version = "0.46.0"
30+
version = "0.48.0"
3131
features = [
3232
"Win32_Foundation",
3333
"Win32_Security",
3434
"Win32_System_Threading",
35-
"Win32_System_WindowsProgramming",
3635
]
3736

3837
[features]

compiler/rustc_errors/src/lock.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ pub fn acquire_global_lock(name: &str) -> Box<dyn Any> {
1919
use windows::{
2020
core::PCSTR,
2121
Win32::Foundation::{CloseHandle, HANDLE, WAIT_ABANDONED, WAIT_OBJECT_0},
22-
Win32::System::Threading::{CreateMutexA, ReleaseMutex, WaitForSingleObject},
23-
Win32::System::WindowsProgramming::INFINITE,
22+
Win32::System::Threading::{CreateMutexA, ReleaseMutex, WaitForSingleObject, INFINITE},
2423
};
2524

2625
struct Handle(HANDLE);

compiler/rustc_lint/src/builtin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1882,8 +1882,8 @@ declare_lint_pass!(
18821882
struct UnderMacro(bool);
18831883

18841884
impl KeywordIdents {
1885-
fn check_tokens(&mut self, cx: &EarlyContext<'_>, tokens: TokenStream) {
1886-
for tt in tokens.into_trees() {
1885+
fn check_tokens(&mut self, cx: &EarlyContext<'_>, tokens: &TokenStream) {
1886+
for tt in tokens.trees() {
18871887
match tt {
18881888
// Only report non-raw idents.
18891889
TokenTree::Token(token, _) => {
@@ -1944,10 +1944,10 @@ impl KeywordIdents {
19441944

19451945
impl EarlyLintPass for KeywordIdents {
19461946
fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac_def: &ast::MacroDef) {
1947-
self.check_tokens(cx, mac_def.body.tokens.clone());
1947+
self.check_tokens(cx, &mac_def.body.tokens);
19481948
}
19491949
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::MacCall) {
1950-
self.check_tokens(cx, mac.args.tokens.clone());
1950+
self.check_tokens(cx, &mac.args.tokens);
19511951
}
19521952
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) {
19531953
self.check_ident_token(cx, UnderMacro(false), ident);

compiler/rustc_middle/src/ty/sty.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2366,13 +2366,11 @@ impl<'tcx> Ty<'tcx> {
23662366

23672367
ty::Adt(def, _substs) => def.sized_constraint(tcx).0.is_empty(),
23682368

2369-
ty::Alias(..) | ty::Param(_) => false,
2369+
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => false,
23702370

23712371
ty::Infer(ty::TyVar(_)) => false,
23722372

2373-
ty::Bound(..)
2374-
| ty::Placeholder(..)
2375-
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
2373+
ty::Bound(..) | ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
23762374
bug!("`is_trivially_sized` applied to unexpected type: {:?}", self)
23772375
}
23782376
}

compiler/rustc_mir_transform/src/ref_prop.rs

+60-30
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
8585
let ssa = SsaLocals::new(body);
8686

8787
let mut replacer = compute_replacement(tcx, body, &ssa);
88-
debug!(?replacer.targets, ?replacer.allowed_replacements, ?replacer.storage_to_remove);
88+
debug!(?replacer.targets);
89+
debug!(?replacer.allowed_replacements);
90+
debug!(?replacer.storage_to_remove);
8991

9092
replacer.visit_body_preserves_cfg(body);
9193

@@ -190,8 +192,11 @@ fn compute_replacement<'tcx>(
190192
continue;
191193
}
192194

195+
// Whether the current local is subject to the uniqueness rule.
196+
let needs_unique = ty.is_mutable_ptr();
197+
193198
// If this a mutable reference that we cannot fully replace, mark it as unknown.
194-
if ty.is_mutable_ptr() && !fully_replacable_locals.contains(local) {
199+
if needs_unique && !fully_replacable_locals.contains(local) {
195200
debug!("not fully replaceable");
196201
continue;
197202
}
@@ -203,32 +208,33 @@ fn compute_replacement<'tcx>(
203208
// have been visited before.
204209
Rvalue::Use(Operand::Copy(place) | Operand::Move(place))
205210
| Rvalue::CopyForDeref(place) => {
206-
if let Some(rhs) = place.as_local() {
211+
if let Some(rhs) = place.as_local() && ssa.is_ssa(rhs) {
207212
let target = targets[rhs];
208-
if matches!(target, Value::Pointer(..)) {
213+
// Only see through immutable reference and pointers, as we do not know yet if
214+
// mutable references are fully replaced.
215+
if !needs_unique && matches!(target, Value::Pointer(..)) {
209216
targets[local] = target;
210-
} else if ssa.is_ssa(rhs) {
211-
let refmut = body.local_decls[rhs].ty.is_mutable_ptr();
212-
targets[local] = Value::Pointer(tcx.mk_place_deref(rhs.into()), refmut);
217+
} else {
218+
targets[local] = Value::Pointer(tcx.mk_place_deref(rhs.into()), needs_unique);
213219
}
214220
}
215221
}
216222
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
217223
let mut place = *place;
218224
// Try to see through `place` in order to collapse reborrow chains.
219225
if place.projection.first() == Some(&PlaceElem::Deref)
220-
&& let Value::Pointer(target, refmut) = targets[place.local]
226+
&& let Value::Pointer(target, inner_needs_unique) = targets[place.local]
221227
// Only see through immutable reference and pointers, as we do not know yet if
222228
// mutable references are fully replaced.
223-
&& !refmut
229+
&& !inner_needs_unique
224230
// Only collapse chain if the pointee is definitely live.
225231
&& can_perform_opt(target, location)
226232
{
227233
place = target.project_deeper(&place.projection[1..], tcx);
228234
}
229235
assert_ne!(place.local, local);
230236
if is_constant_place(place) {
231-
targets[local] = Value::Pointer(place, ty.is_mutable_ptr());
237+
targets[local] = Value::Pointer(place, needs_unique);
232238
}
233239
}
234240
// We do not know what to do, so keep as not-a-pointer.
@@ -276,16 +282,35 @@ fn compute_replacement<'tcx>(
276282
return;
277283
}
278284

279-
if let Value::Pointer(target, refmut) = self.targets[place.local]
280-
&& place.projection.first() == Some(&PlaceElem::Deref)
281-
{
282-
let perform_opt = (self.can_perform_opt)(target, loc);
283-
if perform_opt {
284-
self.allowed_replacements.insert((target.local, loc));
285-
} else if refmut {
286-
// This mutable reference is not fully replacable, so drop it.
287-
self.targets[place.local] = Value::Unknown;
285+
if place.projection.first() != Some(&PlaceElem::Deref) {
286+
// This is not a dereference, nothing to do.
287+
return;
288+
}
289+
290+
let mut place = place.as_ref();
291+
loop {
292+
if let Value::Pointer(target, needs_unique) = self.targets[place.local] {
293+
let perform_opt = (self.can_perform_opt)(target, loc);
294+
debug!(?place, ?target, ?needs_unique, ?perform_opt);
295+
296+
// This a reborrow chain, recursively allow the replacement.
297+
//
298+
// This also allows to detect cases where `target.local` is not replacable,
299+
// and mark it as such.
300+
if let &[PlaceElem::Deref] = &target.projection[..] {
301+
assert!(perform_opt);
302+
self.allowed_replacements.insert((target.local, loc));
303+
place.local = target.local;
304+
continue;
305+
} else if perform_opt {
306+
self.allowed_replacements.insert((target.local, loc));
307+
} else if needs_unique {
308+
// This mutable reference is not fully replacable, so drop it.
309+
self.targets[place.local] = Value::Unknown;
310+
}
288311
}
312+
313+
break;
289314
}
290315
}
291316
}
@@ -326,18 +351,23 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
326351
}
327352

328353
fn visit_place(&mut self, place: &mut Place<'tcx>, ctxt: PlaceContext, loc: Location) {
329-
if let Value::Pointer(target, _) = self.targets[place.local]
330-
&& place.projection.first() == Some(&PlaceElem::Deref)
331-
{
332-
let perform_opt = matches!(ctxt, PlaceContext::NonUse(_))
333-
|| self.allowed_replacements.contains(&(target.local, loc));
334-
335-
if perform_opt {
336-
*place = target.project_deeper(&place.projection[1..], self.tcx);
337-
self.any_replacement = true;
354+
if place.projection.first() != Some(&PlaceElem::Deref) {
355+
return;
356+
}
357+
358+
loop {
359+
if let Value::Pointer(target, _) = self.targets[place.local] {
360+
let perform_opt = matches!(ctxt, PlaceContext::NonUse(_))
361+
|| self.allowed_replacements.contains(&(target.local, loc));
362+
363+
if perform_opt {
364+
*place = target.project_deeper(&place.projection[1..], self.tcx);
365+
self.any_replacement = true;
366+
continue;
367+
}
338368
}
339-
} else {
340-
self.super_place(place, ctxt, loc);
369+
370+
break;
341371
}
342372
}
343373

compiler/rustc_session/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ termize = "0.1.1"
2525
libc = "0.2"
2626

2727
[target.'cfg(windows)'.dependencies.windows]
28-
version = "0.46.0"
28+
version = "0.48.0"
2929
features = [
3030
"Win32_Foundation",
3131
"Win32_System_LibraryLoader",

compiler/rustc_session/src/filesearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ fn current_dll_path() -> Result<PathBuf, String> {
135135

136136
use windows::{
137137
core::PCWSTR,
138-
Win32::Foundation::HINSTANCE,
138+
Win32::Foundation::HMODULE,
139139
Win32::System::LibraryLoader::{
140140
GetModuleFileNameW, GetModuleHandleExW, GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
141141
},
142142
};
143143

144-
let mut module = HINSTANCE::default();
144+
let mut module = HMODULE::default();
145145
unsafe {
146146
GetModuleHandleExW(
147147
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,

src/tools/compiletest/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ libc = "0.2"
2828
miow = "0.5"
2929

3030
[target.'cfg(windows)'.dependencies.windows]
31-
version = "0.46.0"
31+
version = "0.48.0"
3232
features = [
3333
"Win32_Foundation",
3434
"Win32_System_Diagnostics_Debug",

0 commit comments

Comments
 (0)