Skip to content

Commit 61e1603

Browse files
committed
Auto merge of rust-lang#137747 - cuviper:beta-next, r=cuviper
[beta] backports - Pass vendored sources from bootstrap to generate-copyright rust-lang#137020 - Fix `-win7-windows-msvc` target since 26eeac1* rust-lang#137270 - skip submodule updating logics on tarballs rust-lang#137338 - Improve behavior of `IF_LET_RESCOPE` around temporaries and place expressions rust-lang#137444 - downgrade bootstrap `cc` rust-lang#137460 - Remove latest Windows SDK from 32-bit CI rust-lang#137753 - [beta-1.86] Ensure we can package directories ending with '.rs' (rust-lang/cargo#15248) rust-lang#137842 r? cuviper
2 parents 42212a5 + 4746aaf commit 61e1603

File tree

21 files changed

+284
-173
lines changed

21 files changed

+284
-173
lines changed

.github/workflows/ci.yml

+14
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,20 @@ jobs:
173173
- name: ensure the stable version number is correct
174174
run: src/ci/scripts/verify-stable-version-number.sh
175175

176+
# Temporary fix to unblock CI
177+
# Remove the latest Windows SDK for 32-bit Windows MSVC builds.
178+
# See issue https://github.com/rust-lang/rust/issues/137733 for more details.
179+
- name: Remove Windows SDK 10.0.26100.0
180+
shell: powershell
181+
if: ${{ matrix.name == 'i686-msvc-1' || matrix.name == 'i686-msvc-2' || matrix.name == 'dist-i686-msvc' }}
182+
run: |
183+
$kits = (Get-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots').KitsRoot10
184+
$sdk_version = "10.0.26100.0"
185+
186+
foreach ($kind in 'Bin', 'Lib', 'Include') {
187+
Remove-Item -Force -Recurse $kits\$kind\$sdk_version -ErrorAction Continue
188+
}
189+
176190
- name: run the build
177191
# Redirect stderr to stdout to avoid reordering the two streams in the GHA logs.
178192
run: src/ci/scripts/run-build-from-ci.sh 2>&1

compiler/rustc_lint/src/if_let_rescope.rs

+79-77
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use std::iter::repeat;
22
use std::ops::ControlFlow;
33

4-
use hir::intravisit::Visitor;
4+
use hir::intravisit::{self, Visitor};
55
use rustc_ast::Recovered;
66
use rustc_errors::{
77
Applicability, Diag, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic, SuggestionStyle,
88
};
99
use rustc_hir::{self as hir, HirIdSet};
1010
use rustc_macros::LintDiagnostic;
1111
use rustc_middle::ty::TyCtxt;
12+
use rustc_middle::ty::adjustment::Adjust;
1213
use rustc_session::lint::{FutureIncompatibilityReason, LintId};
1314
use rustc_session::{declare_lint, impl_lint_pass};
1415
use rustc_span::Span;
@@ -160,7 +161,7 @@ impl IfLetRescope {
160161
let lifetime_end = source_map.end_point(conseq.span);
161162

162163
if let ControlFlow::Break(significant_dropper) =
163-
(FindSignificantDropper { cx }).visit_expr(init)
164+
(FindSignificantDropper { cx }).check_if_let_scrutinee(init)
164165
{
165166
first_if_to_lint = first_if_to_lint.or_else(|| Some((span, expr.hir_id)));
166167
significant_droppers.push(significant_dropper);
@@ -363,96 +364,97 @@ enum SingleArmMatchBegin {
363364
WithoutOpenBracket(Span),
364365
}
365366

366-
struct FindSignificantDropper<'tcx, 'a> {
367+
struct FindSignificantDropper<'a, 'tcx> {
367368
cx: &'a LateContext<'tcx>,
368369
}
369370

370-
impl<'tcx, 'a> Visitor<'tcx> for FindSignificantDropper<'tcx, 'a> {
371-
type Result = ControlFlow<Span>;
371+
impl<'tcx> FindSignificantDropper<'_, 'tcx> {
372+
/// Check the scrutinee of an `if let` to see if it promotes any temporary values
373+
/// that would change drop order in edition 2024. Specifically, it checks the value
374+
/// of the scrutinee itself, and also recurses into the expression to find any ref
375+
/// exprs (or autoref) which would promote temporaries that would be scoped to the
376+
/// end of this `if`.
377+
fn check_if_let_scrutinee(&mut self, init: &'tcx hir::Expr<'tcx>) -> ControlFlow<Span> {
378+
self.check_promoted_temp_with_drop(init)?;
379+
self.visit_expr(init)
380+
}
372381

373-
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Self::Result {
374-
if self
382+
/// Check that an expression is not a promoted temporary with a significant
383+
/// drop impl.
384+
///
385+
/// An expression is a promoted temporary if it has an addr taken (i.e. `&expr` or autoref)
386+
/// or is the scrutinee of the `if let`, *and* the expression is not a place
387+
/// expr, and it has a significant drop.
388+
fn check_promoted_temp_with_drop(&self, expr: &'tcx hir::Expr<'tcx>) -> ControlFlow<Span> {
389+
if !expr.is_place_expr(|base| {
390+
self.cx
391+
.typeck_results()
392+
.adjustments()
393+
.get(base.hir_id)
394+
.is_some_and(|x| x.iter().any(|adj| matches!(adj.kind, Adjust::Deref(_))))
395+
}) && self
375396
.cx
376397
.typeck_results()
377398
.expr_ty(expr)
378399
.has_significant_drop(self.cx.tcx, self.cx.typing_env())
379400
{
380-
return ControlFlow::Break(expr.span);
401+
ControlFlow::Break(expr.span)
402+
} else {
403+
ControlFlow::Continue(())
381404
}
382-
match expr.kind {
383-
hir::ExprKind::ConstBlock(_)
384-
| hir::ExprKind::Lit(_)
385-
| hir::ExprKind::Path(_)
386-
| hir::ExprKind::Assign(_, _, _)
387-
| hir::ExprKind::AssignOp(_, _, _)
388-
| hir::ExprKind::Break(_, _)
389-
| hir::ExprKind::Continue(_)
390-
| hir::ExprKind::Ret(_)
391-
| hir::ExprKind::Become(_)
392-
| hir::ExprKind::InlineAsm(_)
393-
| hir::ExprKind::OffsetOf(_, _)
394-
| hir::ExprKind::Repeat(_, _)
395-
| hir::ExprKind::Err(_)
396-
| hir::ExprKind::Struct(_, _, _)
397-
| hir::ExprKind::Closure(_)
398-
| hir::ExprKind::Block(_, _)
399-
| hir::ExprKind::DropTemps(_)
400-
| hir::ExprKind::Loop(_, _, _, _) => ControlFlow::Continue(()),
405+
}
406+
}
401407

402-
hir::ExprKind::Tup(exprs) | hir::ExprKind::Array(exprs) => {
403-
for expr in exprs {
404-
self.visit_expr(expr)?;
405-
}
406-
ControlFlow::Continue(())
407-
}
408-
hir::ExprKind::Call(callee, args) => {
409-
self.visit_expr(callee)?;
410-
for expr in args {
411-
self.visit_expr(expr)?;
412-
}
413-
ControlFlow::Continue(())
414-
}
415-
hir::ExprKind::MethodCall(_, receiver, args, _) => {
416-
self.visit_expr(receiver)?;
417-
for expr in args {
418-
self.visit_expr(expr)?;
408+
impl<'tcx> Visitor<'tcx> for FindSignificantDropper<'_, 'tcx> {
409+
type Result = ControlFlow<Span>;
410+
411+
fn visit_block(&mut self, b: &'tcx hir::Block<'tcx>) -> Self::Result {
412+
// Blocks introduce temporary terminating scope for all of its
413+
// statements, so just visit the tail expr, skipping over any
414+
// statements. This prevents false positives like `{ let x = &Drop; }`.
415+
if let Some(expr) = b.expr { self.visit_expr(expr) } else { ControlFlow::Continue(()) }
416+
}
417+
418+
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Self::Result {
419+
// Check for promoted temporaries from autoref, e.g.
420+
// `if let None = TypeWithDrop.as_ref() {} else {}`
421+
// where `fn as_ref(&self) -> Option<...>`.
422+
for adj in self.cx.typeck_results().expr_adjustments(expr) {
423+
match adj.kind {
424+
// Skip when we hit the first deref expr.
425+
Adjust::Deref(_) => break,
426+
Adjust::Borrow(_) => {
427+
self.check_promoted_temp_with_drop(expr)?;
419428
}
420-
ControlFlow::Continue(())
421-
}
422-
hir::ExprKind::Index(left, right, _) | hir::ExprKind::Binary(_, left, right) => {
423-
self.visit_expr(left)?;
424-
self.visit_expr(right)
429+
_ => {}
425430
}
426-
hir::ExprKind::Unary(_, expr)
427-
| hir::ExprKind::Cast(expr, _)
428-
| hir::ExprKind::Type(expr, _)
429-
| hir::ExprKind::UnsafeBinderCast(_, expr, _)
430-
| hir::ExprKind::Yield(expr, _)
431-
| hir::ExprKind::AddrOf(_, _, expr)
432-
| hir::ExprKind::Match(expr, _, _)
433-
| hir::ExprKind::Field(expr, _)
434-
| hir::ExprKind::Let(&hir::LetExpr {
435-
init: expr,
436-
span: _,
437-
pat: _,
438-
ty: _,
439-
recovered: Recovered::No,
440-
}) => self.visit_expr(expr),
441-
hir::ExprKind::Let(_) => ControlFlow::Continue(()),
431+
}
442432

443-
hir::ExprKind::If(cond, _, _) => {
444-
if let hir::ExprKind::Let(hir::LetExpr {
445-
init,
446-
span: _,
447-
pat: _,
448-
ty: _,
449-
recovered: Recovered::No,
450-
}) = cond.kind
451-
{
452-
self.visit_expr(init)?;
453-
}
454-
ControlFlow::Continue(())
433+
match expr.kind {
434+
// Account for cases like `if let None = Some(&Drop) {} else {}`.
435+
hir::ExprKind::AddrOf(_, _, expr) => {
436+
self.check_promoted_temp_with_drop(expr)?;
437+
intravisit::walk_expr(self, expr)
438+
}
439+
// `(Drop, ()).1` introduces a temporary and then moves out of
440+
// part of it, therefore we should check it for temporaries.
441+
// FIXME: This may have false positives if we move the part
442+
// that actually has drop, but oh well.
443+
hir::ExprKind::Index(expr, _, _) | hir::ExprKind::Field(expr, _) => {
444+
self.check_promoted_temp_with_drop(expr)?;
445+
intravisit::walk_expr(self, expr)
455446
}
447+
// If always introduces a temporary terminating scope for its cond and arms,
448+
// so don't visit them.
449+
hir::ExprKind::If(..) => ControlFlow::Continue(()),
450+
// Match introduces temporary terminating scopes for arms, so don't visit
451+
// them, and only visit the scrutinee to account for cases like:
452+
// `if let None = match &Drop { _ => Some(1) } {} else {}`.
453+
hir::ExprKind::Match(scrut, _, _) => self.visit_expr(scrut),
454+
// Self explanatory.
455+
hir::ExprKind::DropTemps(_) => ControlFlow::Continue(()),
456+
// Otherwise, walk into the expr's parts.
457+
_ => intravisit::walk_expr(self, expr),
456458
}
457459
}
458460
}

library/std/src/sys/pal/windows/c.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ compat_fn_with_fallback! {
204204
pub fn NtReleaseKeyedEvent(
205205
EventHandle: HANDLE,
206206
Key: *const c_void,
207-
Alertable: BOOLEAN,
207+
Alertable: bool,
208208
Timeout: *mut i64
209209
) -> NTSTATUS {
210210
panic!("keyed events not available")
@@ -213,7 +213,7 @@ compat_fn_with_fallback! {
213213
pub fn NtWaitForKeyedEvent(
214214
EventHandle: HANDLE,
215215
Key: *const c_void,
216-
Alertable: BOOLEAN,
216+
Alertable: bool,
217217
Timeout: *mut i64
218218
) -> NTSTATUS {
219219
panic!("keyed events not available")

library/std/src/sys/random/windows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn fill_bytes(mut bytes: &mut [u8]) {
1414
while !bytes.is_empty() {
1515
let len = bytes.len().try_into().unwrap_or(u32::MAX);
1616
let ret = unsafe { c::RtlGenRandom(bytes.as_mut_ptr().cast(), len) };
17-
assert_ne!(ret, 0, "failed to generate random data");
17+
assert!(ret, "failed to generate random data");
1818
bytes = &mut bytes[len as usize..];
1919
}
2020
}

library/std/src/sys/sync/mutex/windows7.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Mutex {
4444

4545
#[inline]
4646
pub fn try_lock(&self) -> bool {
47-
unsafe { c::TryAcquireSRWLockExclusive(raw(self)) != 0 }
47+
unsafe { c::TryAcquireSRWLockExclusive(raw(self)) }
4848
}
4949

5050
#[inline]

library/std/src/sys/sync/thread_parking/windows7.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ mod keyed_events {
195195

196196
pub unsafe fn park(parker: Pin<&Parker>) {
197197
// Wait for unpark() to produce this event.
198-
c::NtWaitForKeyedEvent(keyed_event_handle(), parker.ptr(), 0, ptr::null_mut());
198+
c::NtWaitForKeyedEvent(keyed_event_handle(), parker.ptr(), false, ptr::null_mut());
199199
// Set the state back to EMPTY (from either PARKED or NOTIFIED).
200200
// Note that we don't just write EMPTY, but use swap() to also
201201
// include an acquire-ordered read to synchronize with unpark()'s
@@ -218,7 +218,7 @@ mod keyed_events {
218218

219219
// Wait for unpark() to produce this event.
220220
let unparked =
221-
c::NtWaitForKeyedEvent(handle, parker.ptr(), 0, &mut timeout) == c::STATUS_SUCCESS;
221+
c::NtWaitForKeyedEvent(handle, parker.ptr(), false, &mut timeout) == c::STATUS_SUCCESS;
222222

223223
// Set the state back to EMPTY (from either PARKED or NOTIFIED).
224224
let prev_state = parker.state.swap(EMPTY, Acquire);
@@ -228,7 +228,7 @@ mod keyed_events {
228228
// was set to NOTIFIED, which means we *just* missed an
229229
// unpark(), which is now blocked on us to wait for it.
230230
// Wait for it to consume the event and unblock that thread.
231-
c::NtWaitForKeyedEvent(handle, parker.ptr(), 0, ptr::null_mut());
231+
c::NtWaitForKeyedEvent(handle, parker.ptr(), false, ptr::null_mut());
232232
}
233233
}
234234
pub unsafe fn unpark(parker: Pin<&Parker>) {
@@ -239,7 +239,7 @@ mod keyed_events {
239239
// To prevent this thread from blocking indefinitely in that case,
240240
// park_impl() will, after seeing the state set to NOTIFIED after
241241
// waking up, call NtWaitForKeyedEvent again to unblock us.
242-
c::NtReleaseKeyedEvent(keyed_event_handle(), parker.ptr(), 0, ptr::null_mut());
242+
c::NtReleaseKeyedEvent(keyed_event_handle(), parker.ptr(), false, ptr::null_mut());
243243
}
244244

245245
fn keyed_event_handle() -> c::HANDLE {

src/bootstrap/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ dependencies = [
8888

8989
[[package]]
9090
name = "cc"
91-
version = "1.2.0"
91+
version = "1.1.22"
9292
source = "registry+https://github.com/rust-lang/crates.io-index"
93-
checksum = "1aeb932158bd710538c73702db6945cb68a8fb08c519e6e12706b94263b36db8"
93+
checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0"
9494
dependencies = [
9595
"shlex",
9696
]

src/bootstrap/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ test = false
3737
# Most of the time updating these dependencies requires modifications to the
3838
# bootstrap codebase(e.g., https://github.com/rust-lang/rust/issues/124565);
3939
# otherwise, some targets will fail. That's why these dependencies are explicitly pinned.
40-
cc = "=1.2.0"
40+
#
41+
# Do not upgrade this crate unless https://github.com/rust-lang/cc-rs/issues/1317 is fixed.
42+
cc = "=1.1.22"
4143
cmake = "=0.1.48"
4244

4345
build_helper = { path = "../build_helper" }

src/bootstrap/src/core/build_steps/dist.rs

+9-19
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use object::read::archive::ArchiveFile;
1919

2020
use crate::core::build_steps::doc::DocumentationFormat;
2121
use crate::core::build_steps::tool::{self, Tool};
22-
use crate::core::build_steps::vendor::default_paths_to_vendor;
22+
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor};
2323
use crate::core::build_steps::{compile, llvm};
2424
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2525
use crate::core::config::TargetSelection;
@@ -1050,19 +1050,6 @@ impl Step for PlainSourceTarball {
10501050
if builder.config.dist_vendor {
10511051
builder.require_and_update_all_submodules();
10521052

1053-
// Vendor all Cargo dependencies
1054-
let mut cmd = command(&builder.initial_cargo);
1055-
cmd.arg("vendor").arg("--versioned-dirs");
1056-
1057-
for (p, _) in default_paths_to_vendor(builder) {
1058-
cmd.arg("--sync").arg(p);
1059-
}
1060-
1061-
cmd
1062-
// Will read the libstd Cargo.toml which uses the unstable `public-dependency` feature.
1063-
.env("RUSTC_BOOTSTRAP", "1")
1064-
.current_dir(plain_dst_src);
1065-
10661053
// Vendor packages that are required by opt-dist to collect PGO profiles.
10671054
let pkgs_for_pgo_training = build_helper::LLVM_PGO_CRATES
10681055
.iter()
@@ -1074,15 +1061,18 @@ impl Step for PlainSourceTarball {
10741061
manifest_path.push("Cargo.toml");
10751062
manifest_path
10761063
});
1077-
for manifest_path in pkgs_for_pgo_training {
1078-
cmd.arg("--sync").arg(manifest_path);
1079-
}
10801064

1081-
let config = cmd.run_capture(builder).stdout();
1065+
// Vendor all Cargo dependencies
1066+
let vendor = builder.ensure(Vendor {
1067+
sync_args: pkgs_for_pgo_training.collect(),
1068+
versioned_dirs: true,
1069+
root_dir: plain_dst_src.into(),
1070+
output_dir: VENDOR_DIR.into(),
1071+
});
10821072

10831073
let cargo_config_dir = plain_dst_src.join(".cargo");
10841074
builder.create_dir(&cargo_config_dir);
1085-
builder.create(&cargo_config_dir.join("config.toml"), &config);
1075+
builder.create(&cargo_config_dir.join("config.toml"), &vendor.config);
10861076
}
10871077

10881078
// Delete extraneous directories

0 commit comments

Comments
 (0)