Skip to content

Commit 6a6cd65

Browse files
committed
Auto merge of #122803 - jhpratt:rollup-nmgs79k, r=jhpratt
Rollup of 8 pull requests Successful merges: - #122545 (Ignore paths from expansion in `unused_qualifications`) - #122729 (Relax SeqCst ordering in standard library.) - #122740 (use more accurate terminology) - #122749 (make `type_flags(ReError) & HAS_ERROR`) - #122764 (coverage: Remove incorrect assertions from counter allocation) - #122765 (Add `usize::MAX` arg tests for Vec) - #122776 (Rename `hir::Let` into `hir::LetExpr`) - #122786 (compiletest: Introduce `remove_and_create_dir_all()` helper) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6ec953c + f25397a commit 6a6cd65

File tree

90 files changed

+410
-759
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+410
-759
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
157157
hir::ExprKind::AddrOf(*k, *m, ohs)
158158
}
159159
ExprKind::Let(pat, scrutinee, span, is_recovered) => {
160-
hir::ExprKind::Let(self.arena.alloc(hir::Let {
160+
hir::ExprKind::Let(self.arena.alloc(hir::LetExpr {
161161
span: self.lower_span(*span),
162162
pat: self.lower_pat(pat),
163163
ty: None,

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

-4
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,6 @@ fn check_opaque_type_parameter_valid(
434434
// Only check the parent generics, which will ignore any of the
435435
// duplicated lifetime args that come from reifying late-bounds.
436436
for (i, arg) in opaque_type_key.args.iter().take(parent_generics.count()).enumerate() {
437-
if let Err(guar) = arg.error_reported() {
438-
return Err(guar);
439-
}
440-
441437
let arg_is_param = match arg.unpack() {
442438
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
443439
GenericArgKind::Lifetime(lt) if is_ty_alias => {

compiler/rustc_hir/src/hir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ pub struct Arm<'hir> {
12591259
/// In an `if let`, imagine it as `if (let <pat> = <expr>) { ... }`; in a let-else, it is part of
12601260
/// the desugaring to if-let. Only let-else supports the type annotation at present.
12611261
#[derive(Debug, Clone, Copy, HashStable_Generic)]
1262-
pub struct Let<'hir> {
1262+
pub struct LetExpr<'hir> {
12631263
pub span: Span,
12641264
pub pat: &'hir Pat<'hir>,
12651265
pub ty: Option<&'hir Ty<'hir>>,
@@ -1852,7 +1852,7 @@ pub enum ExprKind<'hir> {
18521852
///
18531853
/// These are not `Local` and only occur as expressions.
18541854
/// The `let Some(x) = foo()` in `if let Some(x) = foo()` is an example of `Let(..)`.
1855-
Let(&'hir Let<'hir>),
1855+
Let(&'hir LetExpr<'hir>),
18561856
/// An `if` block, with an optional else block.
18571857
///
18581858
/// I.e., `if <expr> { <expr> } else { <expr> }`.

compiler/rustc_hir/src/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
753753
ExprKind::DropTemps(ref subexpression) => {
754754
try_visit!(visitor.visit_expr(subexpression));
755755
}
756-
ExprKind::Let(Let { span: _, pat, ty, init, is_recovered: _ }) => {
756+
ExprKind::Let(LetExpr { span: _, pat, ty, init, is_recovered: _ }) => {
757757
// match the visit order in walk_local
758758
try_visit!(visitor.visit_expr(init));
759759
try_visit!(visitor.visit_pat(pat));

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ impl<'a> State<'a> {
13871387
// Print `}`:
13881388
self.bclose_maybe_open(expr.span, true);
13891389
}
1390-
hir::ExprKind::Let(&hir::Let { pat, ty, init, .. }) => {
1390+
hir::ExprKind::Let(&hir::LetExpr { pat, ty, init, .. }) => {
13911391
self.print_let(pat, ty, init);
13921392
}
13931393
hir::ExprKind::If(test, blk, elseopt) => {

compiler/rustc_hir_typeck/src/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
317317
err.note("`if` expressions without `else` evaluate to `()`");
318318
err.help("consider adding an `else` block that evaluates to the expected type");
319319
*error = true;
320-
if let ExprKind::Let(hir::Let { span, pat, init, .. }) = cond_expr.kind
320+
if let ExprKind::Let(hir::LetExpr { span, pat, init, .. }) = cond_expr.kind
321321
&& let ExprKind::Block(block, _) = then_expr.kind
322322
// Refutability checks occur on the MIR, so we approximate it here by checking
323323
// if we have an enum with a single variant or a struct in the pattern.

compiler/rustc_hir_typeck/src/expr.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12611261
}
12621262
}
12631263

1264-
pub(super) fn check_expr_let(&self, let_expr: &'tcx hir::Let<'tcx>, hir_id: HirId) -> Ty<'tcx> {
1264+
pub(super) fn check_expr_let(
1265+
&self,
1266+
let_expr: &'tcx hir::LetExpr<'tcx>,
1267+
hir_id: HirId,
1268+
) -> Ty<'tcx> {
12651269
// for let statements, this is done in check_stmt
12661270
let init = let_expr.init;
12671271
self.warn_if_unreachable(init.hir_id, init.span, "block in `let` expression");

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
245245
}
246246
}
247247

248-
hir::ExprKind::Let(hir::Let { pat, init, .. }) => {
248+
hir::ExprKind::Let(hir::LetExpr { pat, init, .. }) => {
249249
self.walk_local(init, pat, None, |t| t.borrow_expr(init, ty::ImmBorrow))
250250
}
251251

compiler/rustc_hir_typeck/src/gather_locals.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'a> DeclOrigin<'a> {
2929
}
3030
}
3131

32-
/// A declaration is an abstraction of [hir::Local] and [hir::Let].
32+
/// A declaration is an abstraction of [hir::Local] and [hir::LetExpr].
3333
///
3434
/// It must have a hir_id, as this is how we connect gather_locals to the check functions.
3535
pub(super) struct Declaration<'a> {
@@ -48,9 +48,9 @@ impl<'a> From<&'a hir::Local<'a>> for Declaration<'a> {
4848
}
4949
}
5050

51-
impl<'a> From<(&'a hir::Let<'a>, hir::HirId)> for Declaration<'a> {
52-
fn from((let_expr, hir_id): (&'a hir::Let<'a>, hir::HirId)) -> Self {
53-
let hir::Let { pat, ty, span, init, is_recovered: _ } = *let_expr;
51+
impl<'a> From<(&'a hir::LetExpr<'a>, hir::HirId)> for Declaration<'a> {
52+
fn from((let_expr, hir_id): (&'a hir::LetExpr<'a>, hir::HirId)) -> Self {
53+
let hir::LetExpr { pat, ty, span, init, is_recovered: _ } = *let_expr;
5454
Declaration { hir_id, pat, ty, span, init: Some(init), origin: DeclOrigin::LetExpr }
5555
}
5656
}

compiler/rustc_infer/src/infer/opaque_types/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ impl<'tcx> InferCtxt<'tcx> {
9494
cause: &ObligationCause<'tcx>,
9595
param_env: ty::ParamEnv<'tcx>,
9696
) -> InferResult<'tcx, ()> {
97-
if a.references_error() || b.references_error() {
98-
return Ok(InferOk { value: (), obligations: vec![] });
99-
}
10097
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
10198
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
10299
let def_id = def_id.expect_local();

compiler/rustc_middle/src/ty/region.rs

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ impl<'tcx> Region<'tcx> {
251251
}
252252
ty::ReError(_) => {
253253
flags = flags | TypeFlags::HAS_FREE_REGIONS;
254+
flags = flags | TypeFlags::HAS_ERROR;
254255
}
255256
}
256257

compiler/rustc_mir_transform/src/coverage/counters.rs

+4-35
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
use std::fmt::{self, Debug};
2+
13
use rustc_data_structures::captures::Captures;
24
use rustc_data_structures::fx::FxHashMap;
35
use rustc_data_structures::graph::WithNumNodes;
4-
use rustc_index::bit_set::BitSet;
56
use rustc_index::IndexVec;
6-
use rustc_middle::mir::coverage::*;
7+
use rustc_middle::mir::coverage::{CounterId, CovTerm, Expression, ExpressionId, Op};
78

8-
use super::graph::{BasicCoverageBlock, CoverageGraph, TraverseCoverageGraphWithLoops};
9-
10-
use std::fmt::{self, Debug};
9+
use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph, TraverseCoverageGraphWithLoops};
1110

1211
/// The coverage counter or counter expression associated with a particular
1312
/// BCB node or BCB edge.
@@ -18,10 +17,6 @@ pub(super) enum BcbCounter {
1817
}
1918

2019
impl BcbCounter {
21-
fn is_expression(&self) -> bool {
22-
matches!(self, Self::Expression { .. })
23-
}
24-
2520
pub(super) fn as_term(&self) -> CovTerm {
2621
match *self {
2722
BcbCounter::Counter { id, .. } => CovTerm::Counter(id),
@@ -60,10 +55,6 @@ pub(super) struct CoverageCounters {
6055
/// We currently don't iterate over this map, but if we do in the future,
6156
/// switch it back to `FxIndexMap` to avoid query stability hazards.
6257
bcb_edge_counters: FxHashMap<(BasicCoverageBlock, BasicCoverageBlock), BcbCounter>,
63-
/// Tracks which BCBs have a counter associated with some incoming edge.
64-
/// Only used by assertions, to verify that BCBs with incoming edge
65-
/// counters do not have their own physical counters (expressions are allowed).
66-
bcb_has_incoming_edge_counters: BitSet<BasicCoverageBlock>,
6758
/// Table of expression data, associating each expression ID with its
6859
/// corresponding operator (+ or -) and its LHS/RHS operands.
6960
expressions: IndexVec<ExpressionId, Expression>,
@@ -83,7 +74,6 @@ impl CoverageCounters {
8374
counter_increment_sites: IndexVec::new(),
8475
bcb_counters: IndexVec::from_elem_n(None, num_bcbs),
8576
bcb_edge_counters: FxHashMap::default(),
86-
bcb_has_incoming_edge_counters: BitSet::new_empty(num_bcbs),
8777
expressions: IndexVec::new(),
8878
};
8979

@@ -122,14 +112,6 @@ impl CoverageCounters {
122112
}
123113

124114
fn set_bcb_counter(&mut self, bcb: BasicCoverageBlock, counter_kind: BcbCounter) -> BcbCounter {
125-
assert!(
126-
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
127-
// have an expression (to be injected into an existing `BasicBlock` represented by this
128-
// `BasicCoverageBlock`).
129-
counter_kind.is_expression() || !self.bcb_has_incoming_edge_counters.contains(bcb),
130-
"attempt to add a `Counter` to a BCB target with existing incoming edge counters"
131-
);
132-
133115
if let Some(replaced) = self.bcb_counters[bcb].replace(counter_kind) {
134116
bug!(
135117
"attempt to set a BasicCoverageBlock coverage counter more than once; \
@@ -146,19 +128,6 @@ impl CoverageCounters {
146128
to_bcb: BasicCoverageBlock,
147129
counter_kind: BcbCounter,
148130
) -> BcbCounter {
149-
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
150-
// have an expression (to be injected into an existing `BasicBlock` represented by this
151-
// `BasicCoverageBlock`).
152-
if let Some(node_counter) = self.bcb_counter(to_bcb)
153-
&& !node_counter.is_expression()
154-
{
155-
bug!(
156-
"attempt to add an incoming edge counter from {from_bcb:?} \
157-
when the target BCB already has {node_counter:?}"
158-
);
159-
}
160-
161-
self.bcb_has_incoming_edge_counters.insert(to_bcb);
162131
if let Some(replaced) = self.bcb_edge_counters.insert((from_bcb, to_bcb), counter_kind) {
163132
bug!(
164133
"attempt to set an edge counter more than once; from_bcb: \

compiler/rustc_resolve/src/late.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4672,7 +4672,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
46724672
return;
46734673
}
46744674

4675-
if path.iter().any(|seg| seg.ident.span.from_expansion()) {
4675+
if finalize.path_span.from_expansion()
4676+
|| path.iter().any(|seg| seg.ident.span.from_expansion())
4677+
{
46764678
return;
46774679
}
46784680

compiler/rustc_type_ir/src/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ bitflags! {
8585
| TypeFlags::HAS_TY_INHERENT.bits()
8686
| TypeFlags::HAS_CT_PROJECTION.bits();
8787

88-
/// Is an error type/const reachable?
88+
/// Is an error type/lifetime/const reachable?
8989
const HAS_ERROR = 1 << 15;
9090

9191
/// Does this have any region that "appears free" in the type?

config.example.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,6 @@
915915
# Available options: fast, balanced, best
916916
#compression-profile = "fast"
917917

918-
# Copy the linker, DLLs, and various libraries from MinGW into the rustc toolchain.
918+
# Copy the linker, DLLs, and various libraries from MinGW into the Rust toolchain.
919919
# Only applies when the host or target is pc-windows-gnu.
920920
#include-mingw-linker = true

library/alloc/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ macro_rules! acquire {
233233
/// let val = Arc::clone(&val);
234234
///
235235
/// thread::spawn(move || {
236-
/// let v = val.fetch_add(1, Ordering::SeqCst);
236+
/// let v = val.fetch_add(1, Ordering::Relaxed);
237237
/// println!("{v:?}");
238238
/// });
239239
/// }

library/alloc/tests/vec.rs

+41
Original file line numberDiff line numberDiff line change
@@ -2643,3 +2643,44 @@ fn test_vec_from_array_ref() {
26432643
fn test_vec_from_array_mut_ref() {
26442644
assert_eq!(Vec::from(&mut [1, 2, 3]), vec![1, 2, 3]);
26452645
}
2646+
2647+
/// This assortment of tests, in combination with miri, verifies we handle UB on fishy arguments
2648+
/// in the stdlib. Draining and extending the allocation are fairly well-tested earlier, but
2649+
/// `vec.insert(usize::MAX, val)` once slipped by!
2650+
///
2651+
/// All code that manipulates the collection types should be tested with "trivially wrong" args.
2652+
#[test]
2653+
fn max_dont_panic() {
2654+
let mut v = vec![0];
2655+
let _ = v.get(usize::MAX);
2656+
v.shrink_to(usize::MAX);
2657+
v.truncate(usize::MAX);
2658+
}
2659+
2660+
#[test]
2661+
#[should_panic]
2662+
fn max_insert() {
2663+
let mut v = vec![0];
2664+
v.insert(usize::MAX, 1);
2665+
}
2666+
2667+
#[test]
2668+
#[should_panic]
2669+
fn max_remove() {
2670+
let mut v = vec![0];
2671+
v.remove(usize::MAX);
2672+
}
2673+
2674+
#[test]
2675+
#[should_panic]
2676+
fn max_splice() {
2677+
let mut v = vec![0];
2678+
v.splice(usize::MAX.., core::iter::once(1));
2679+
}
2680+
2681+
#[test]
2682+
#[should_panic]
2683+
fn max_swap_remove() {
2684+
let mut v = vec![0];
2685+
v.swap_remove(usize::MAX);
2686+
}

library/core/src/alloc/global.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ use crate::ptr;
2424
/// use std::alloc::{GlobalAlloc, Layout};
2525
/// use std::cell::UnsafeCell;
2626
/// use std::ptr::null_mut;
27-
/// use std::sync::atomic::{
28-
/// AtomicUsize,
29-
/// Ordering::{Acquire, SeqCst},
30-
/// };
27+
/// use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
3128
///
3229
/// const ARENA_SIZE: usize = 128 * 1024;
3330
/// const MAX_SUPPORTED_ALIGN: usize = 4096;
@@ -61,7 +58,7 @@ use crate::ptr;
6158
/// let mut allocated = 0;
6259
/// if self
6360
/// .remaining
64-
/// .fetch_update(SeqCst, SeqCst, |mut remaining| {
61+
/// .fetch_update(Relaxed, Relaxed, |mut remaining| {
6562
/// if size > remaining {
6663
/// return None;
6764
/// }
@@ -81,7 +78,7 @@ use crate::ptr;
8178
///
8279
/// fn main() {
8380
/// let _s = format!("allocating a string!");
84-
/// let currently = ALLOCATOR.remaining.load(Acquire);
81+
/// let currently = ALLOCATOR.remaining.load(Relaxed);
8582
/// println!("allocated so far: {}", ARENA_SIZE - currently);
8683
/// }
8784
/// ```

library/panic_unwind/src/emcc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
8484
super::__rust_foreign_exception();
8585
}
8686

87-
let was_caught = (*adjusted_ptr).caught.swap(true, Ordering::SeqCst);
87+
let was_caught = (*adjusted_ptr).caught.swap(true, Ordering::Relaxed);
8888
if was_caught {
8989
// Since cleanup() isn't allowed to panic, we just abort instead.
9090
intrinsics::abort();

library/proc_macro/src/bridge/handle.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ impl<T> OwnedStore<T> {
2121
pub(super) fn new(counter: &'static AtomicU32) -> Self {
2222
// Ensure the handle counter isn't 0, which would panic later,
2323
// when `NonZero::new` (aka `Handle::new`) is called in `alloc`.
24-
assert_ne!(counter.load(Ordering::SeqCst), 0);
24+
assert_ne!(counter.load(Ordering::Relaxed), 0);
2525

2626
OwnedStore { counter, data: BTreeMap::new() }
2727
}
2828
}
2929

3030
impl<T> OwnedStore<T> {
3131
pub(super) fn alloc(&mut self, x: T) -> Handle {
32-
let counter = self.counter.fetch_add(1, Ordering::SeqCst);
32+
let counter = self.counter.fetch_add(1, Ordering::Relaxed);
3333
let handle = Handle::new(counter).expect("`proc_macro` handle counter overflowed");
3434
assert!(self.data.insert(handle, x).is_none());
3535
handle

library/std/src/alloc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
329329
/// ```
330330
#[unstable(feature = "alloc_error_hook", issue = "51245")]
331331
pub fn set_alloc_error_hook(hook: fn(Layout)) {
332-
HOOK.store(hook as *mut (), Ordering::SeqCst);
332+
HOOK.store(hook as *mut (), Ordering::Release);
333333
}
334334

335335
/// Unregisters the current allocation error hook, returning it.
@@ -339,7 +339,7 @@ pub fn set_alloc_error_hook(hook: fn(Layout)) {
339339
/// If no custom hook is registered, the default hook will be returned.
340340
#[unstable(feature = "alloc_error_hook", issue = "51245")]
341341
pub fn take_alloc_error_hook() -> fn(Layout) {
342-
let hook = HOOK.swap(ptr::null_mut(), Ordering::SeqCst);
342+
let hook = HOOK.swap(ptr::null_mut(), Ordering::Acquire);
343343
if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }
344344
}
345345

@@ -362,7 +362,7 @@ fn default_alloc_error_hook(layout: Layout) {
362362
#[alloc_error_handler]
363363
#[unstable(feature = "alloc_internals", issue = "none")]
364364
pub fn rust_oom(layout: Layout) -> ! {
365-
let hook = HOOK.load(Ordering::SeqCst);
365+
let hook = HOOK.load(Ordering::Acquire);
366366
let hook: fn(Layout) =
367367
if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } };
368368
hook(layout);

library/std/src/net/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use crate::sync::atomic::{AtomicUsize, Ordering};
77
static PORT: AtomicUsize = AtomicUsize::new(0);
88

99
pub fn next_test_ip4() -> SocketAddr {
10-
let port = PORT.fetch_add(1, Ordering::SeqCst) as u16 + base_port();
10+
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port();
1111
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port))
1212
}
1313

1414
pub fn next_test_ip6() -> SocketAddr {
15-
let port = PORT.fetch_add(1, Ordering::SeqCst) as u16 + base_port();
15+
let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port();
1616
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), port, 0, 0))
1717
}
1818

library/std/src/panicking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn default_hook(info: &PanicInfo<'_>) {
272272
drop(backtrace::print(err, crate::backtrace_rs::PrintFmt::Full))
273273
}
274274
Some(BacktraceStyle::Off) => {
275-
if FIRST_PANIC.swap(false, Ordering::SeqCst) {
275+
if FIRST_PANIC.swap(false, Ordering::Relaxed) {
276276
let _ = writeln!(
277277
err,
278278
"note: run with `RUST_BACKTRACE=1` environment variable to display a \

0 commit comments

Comments
 (0)