Skip to content

Commit 63faf88

Browse files
committed
Auto merge of #155373 - jhpratt:rollup-qjxAt4R, r=jhpratt
Rollup of 18 pull requests Successful merges: - #154595 (Emit fatal on invalid const args with nested defs) - #154599 (report the `varargs_without_pattern` lint in deps) - #154699 (`core::unicode`: Replace `Cased` table with `Lt`) - #155353 (resolve: Remove `inaccessible_ctor_reexport` resolver field) - #155357 (Add `--remap-path-scope` as unstable in rustdoc) - #150649 (clippy fix: non_canonical_clone_impl) - #154604 (abort in core) - #154616 (Add `--quiet` flag to x.py and bootstrap to suppress output) - #154970 (rustdoc: preserve `doc(cfg)` on locally re-exported type aliases) - #155215 (Clean up `AttributeLintKind` and refactor diagnostic attribute linting) - #155228 (Check diagnostic output in incremental `cpass` and `rpass` revisions) - #155266 (Adjust release notes for post-merge feedback) - #155326 (Disallow ZST allocations with `TypedArena`.) - #155334 (docs: Use `0b1` instead of `NonZero::MIN` in `NonZero::bit_width` doctests) - #155340 (Handle nonnull pattern types in size skeleton) - #155347 (Add push_mut and new Layout methods to release notes) - #155356 (remove calls to AliasTyKind::def_id) - #155364 (Reduce diagnostic type visibilities.)
2 parents e8e4541 + 837292d commit 63faf88

File tree

148 files changed

+1917
-1275
lines changed

Some content is hidden

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

148 files changed

+1917
-1275
lines changed

‎RELEASES.md‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Language
1818

1919
Compiler
2020
--------
21-
- [Stabilize `--remap-path-scope` for controlling the scoping of how paths get remapped in the resulting binary](https://github.com/rust-lang/rust/pull/147611)
2221

22+
- [Stabilize `--remap-path-scope` for controlling the scoping of how paths get remapped in the resulting binary](https://github.com/rust-lang/rust/pull/147611)
23+
- [Apply patches for CVE-2026-6042 and CVE-2026-40200 to vendored musl](https://github.com/rust-lang/rust/pull/155171)
2324

2425
<a id="1.95-Platform-Support"></a>
2526

@@ -78,25 +79,31 @@ Stabilized APIs
7879
- [`<*const T>::as_ref_unchecked`](https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.as_ref_unchecked)
7980
- [`<*mut T>::as_ref_unchecked`](https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.as_ref_unchecked-1)
8081
- [`<*mut T>::as_mut_unchecked`](https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.as_mut_unchecked)
81-
82+
- [`Vec::push_mut`](https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.push_mut)
83+
- [`Vec::insert_mut`](https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.insert_mut)
84+
- [`VecDeque::push_front_mut`](https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.push_front_mut)
85+
- [`VecDeque::push_back_mut`](https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.push_back_mut)
86+
- [`VecDeque::insert_mut`](https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.insert_mut)
87+
- [`LinkedList::push_front_mut`](https://doc.rust-lang.org/stable/std/collections/struct.LinkedList.html#method.push_front_mut)
88+
- [`LinkedList::push_back_mut`](https://doc.rust-lang.org/stable/std/collections/struct.LinkedList.html#method.push_back_mut)
89+
- [`Layout::dangling_ptr`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.dangling_ptr)
90+
- [`Layout::repeat`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.repeat)
91+
- [`Layout::repeat_packed`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.repeat_packed)
92+
- [`Layout::extend_packed`](https://doc.rust-lang.org/stable/std/alloc/struct.Layout.html#method.extend_packed)
8293

8394
These previously stable APIs are now stable in const contexts:
8495

8596
- [`fmt::from_fn`](https://doc.rust-lang.org/stable/std/fmt/fn.from_fn.html)
8697
- [`ControlFlow::is_break`](https://doc.rust-lang.org/stable/core/ops/enum.ControlFlow.html#method.is_break)
8798
- [`ControlFlow::is_continue`](https://doc.rust-lang.org/stable/core/ops/enum.ControlFlow.html#method.is_continue)
8899

89-
90-
<a id="1.95-Cargo"></a>
91-
92-
Cargo
93-
-----
94-
- [docs(report): enhance man pages for `cargo report *`](https://github.com/rust-lang/cargo/pull/16430/)<a id="1.95-Rustdoc"></a>
100+
<a id="1.95-Rustdoc"></a>
95101

96102
Rustdoc
97103
-----
98104
- [In search results, rank unstable items lower](https://github.com/rust-lang/rust/pull/149460)
99105
- [Add new "hide deprecated items" setting in rustdoc](https://github.com/rust-lang/rust/pull/151091)
106+
100107
<a id="1.95-Compatibility-Notes"></a>
101108

102109
Compatibility Notes
@@ -116,7 +123,6 @@ Compatibility Notes
116123
- [JSON target specs](https://doc.rust-lang.org/rustc/targets/custom.html) have been destabilized and now require `-Z unstable-options` to use. Previously, they could not be used without the standard library, which has no stable build mechanism. In preparation for the `build-std` project adding that support, JSON target specs are being proactively gated to ensure they remain unstable even if `build-std` is stabilized. Cargo now includes the `-Z json-target-spec` CLI flag to automatically pass `-Z unstable-options` to the compiler when needed. See [#150151](https://github.com/rust-lang/rust/pull/150151), [#151534](https://github.com/rust-lang/rust/pull/150151), and [rust-lang/cargo#16557](https://github.com/rust-lang/cargo/pull/16557).
117124
- [The arguments of `#[feature]` attributes on invalid targets are now checked](https://github.com/rust-lang/rust/issues/153764)
118125

119-
120126
<a id="1.95-Internal-Changes"></a>
121127

122128
Internal Changes

‎compiler/rustc_arena/src/lib.rs‎

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,19 @@ impl<T> TypedArena<T> {
140140
/// Allocates an object in the `TypedArena`, returning a reference to it.
141141
#[inline]
142142
pub fn alloc(&self, object: T) -> &mut T {
143+
assert!(size_of::<T>() != 0);
144+
143145
if self.ptr == self.end {
144146
self.grow(1)
145147
}
146148

147149
unsafe {
148-
if size_of::<T>() == 0 {
149-
self.ptr.set(self.ptr.get().wrapping_byte_add(1));
150-
let ptr = ptr::NonNull::<T>::dangling().as_ptr();
151-
// Don't drop the object. This `write` is equivalent to `forget`.
152-
ptr::write(ptr, object);
153-
&mut *ptr
154-
} else {
155-
let ptr = self.ptr.get();
156-
// Advance the pointer.
157-
self.ptr.set(self.ptr.get().add(1));
158-
// Write into uninitialized memory.
159-
ptr::write(ptr, object);
160-
&mut *ptr
161-
}
150+
let ptr = self.ptr.get();
151+
// Advance the pointer.
152+
self.ptr.set(self.ptr.get().add(1));
153+
// Write into uninitialized memory.
154+
ptr::write(ptr, object);
155+
&mut *ptr
162156
}
163157
}
164158

@@ -302,16 +296,10 @@ impl<T> TypedArena<T> {
302296
let end = self.ptr.get().addr();
303297
// We then calculate the number of elements to be dropped in the last chunk,
304298
// which is the filled area's length.
305-
let diff = if size_of::<T>() == 0 {
306-
// `T` is ZST. It can't have a drop flag, so the value here doesn't matter. We get
307-
// the number of zero-sized values in the last and only chunk, just out of caution.
308-
// Recall that `end` was incremented for each allocated value.
309-
end - start
310-
} else {
311-
// FIXME: this should *likely* use `offset_from`, but more
312-
// investigation is needed (including running tests in miri).
313-
(end - start) / size_of::<T>()
314-
};
299+
assert_ne!(size_of::<T>(), 0);
300+
// FIXME: this should *likely* use `offset_from`, but more
301+
// investigation is needed (including running tests in miri).
302+
let diff = (end - start) / size_of::<T>();
315303
// Pass that to the `destroy` method.
316304
unsafe {
317305
last_chunk.destroy(diff);

‎compiler/rustc_arena/src/tests.rs‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ impl<T> TypedArena<T> {
2222
if let Some(last_chunk) = chunks_borrow.last_mut() {
2323
self.clear_last_chunk(last_chunk);
2424
let len = chunks_borrow.len();
25-
// If `T` is ZST, code below has no effect.
2625
for mut chunk in chunks_borrow.drain(..len - 1) {
2726
chunk.destroy(chunk.entries);
2827
}
@@ -117,18 +116,6 @@ fn test_noncopy() {
117116
}
118117
}
119118

120-
#[test]
121-
fn test_typed_arena_zero_sized() {
122-
let arena = TypedArena::default();
123-
#[cfg(not(miri))]
124-
const N: usize = 100000;
125-
#[cfg(miri)]
126-
const N: usize = 1000;
127-
for _ in 0..N {
128-
arena.alloc(());
129-
}
130-
}
131-
132119
#[test]
133120
fn test_typed_arena_clear() {
134121
let mut arena = TypedArena::default();
@@ -207,7 +194,8 @@ thread_local! {
207194
static DROP_COUNTER: Cell<u32> = Cell::new(0)
208195
}
209196

210-
struct SmallDroppable;
197+
#[allow(unused)]
198+
struct SmallDroppable(u8);
211199

212200
impl Drop for SmallDroppable {
213201
fn drop(&mut self) {
@@ -222,7 +210,7 @@ fn test_typed_arena_drop_small_count() {
222210
let arena: TypedArena<SmallDroppable> = TypedArena::default();
223211
for _ in 0..100 {
224212
// Allocate something with drop glue to make sure it doesn't leak.
225-
arena.alloc(SmallDroppable);
213+
arena.alloc(SmallDroppable(0));
226214
}
227215
// dropping
228216
};

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use super::{
2929
use crate::errors::{InvalidLegacyConstGenericArg, UseConstGenericArg, YieldInClosure};
3030
use crate::{AllowReturnTypeNotation, FnDeclKind, ImplTraitPosition, TryBlockScope};
3131

32-
struct WillCreateDefIdsVisitor {}
32+
pub(super) struct WillCreateDefIdsVisitor;
3333

3434
impl<'v> rustc_ast::visit::Visitor<'v> for WillCreateDefIdsVisitor {
3535
type Result = ControlFlow<Span>;
@@ -479,18 +479,18 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
479479
DefPathData::LateAnonConst,
480480
f.span,
481481
);
482-
let mut visitor = WillCreateDefIdsVisitor {};
483-
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
484-
Box::new(Expr {
485-
id: self.next_node_id(),
486-
kind: ExprKind::Err(invalid_expr_error(self.tcx, span)),
487-
span: f.span,
488-
attrs: [].into(),
489-
tokens: None,
490-
})
491-
} else {
492-
arg
493-
};
482+
let const_value =
483+
if let ControlFlow::Break(span) = WillCreateDefIdsVisitor.visit_expr(&arg) {
484+
Box::new(Expr {
485+
id: self.next_node_id(),
486+
kind: ExprKind::Err(invalid_expr_error(self.tcx, span)),
487+
span: f.span,
488+
attrs: [].into(),
489+
tokens: None,
490+
})
491+
} else {
492+
arg
493+
};
494494

495495
let anon_const = AnonConst {
496496
id: node_id,

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use std::mem;
3939
use std::sync::Arc;
4040

4141
use rustc_ast::node_id::NodeMap;
42+
use rustc_ast::visit::Visitor;
4243
use rustc_ast::{self as ast, *};
4344
use rustc_attr_parsing::{AttributeParser, Late, OmitDoc};
4445
use rustc_data_structures::fingerprint::Fingerprint;
@@ -2219,14 +2220,22 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
22192220
// since later compiler stages cannot handle them (and shouldn't need to be able to).
22202221
let default = default
22212222
.as_ref()
2222-
.filter(|_| match source {
2223+
.filter(|anon_const| match source {
22232224
hir::GenericParamSource::Generics => true,
22242225
hir::GenericParamSource::Binder => {
2225-
self.dcx().emit_err(errors::GenericParamDefaultInBinder {
2226-
span: param.span(),
2227-
});
2228-
2229-
false
2226+
let err = errors::GenericParamDefaultInBinder { span: param.span() };
2227+
if expr::WillCreateDefIdsVisitor
2228+
.visit_expr(&anon_const.value)
2229+
.is_break()
2230+
{
2231+
// FIXME(mgca): make this non-fatal once we have a better way
2232+
// to handle nested items in anno const from binder
2233+
// Issue: https://github.com/rust-lang/rust/issues/123629
2234+
self.dcx().emit_fatal(err)
2235+
} else {
2236+
self.dcx().emit_err(err);
2237+
false
2238+
}
22302239
}
22312240
})
22322241
.map(|def| self.lower_anon_const_to_const_arg_and_alloc(def));
@@ -2563,12 +2572,17 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
25632572
let span = self.lower_span(expr.span);
25642573

25652574
let overly_complex_const = |this: &mut Self| {
2566-
let e = this.dcx().struct_span_err(
2567-
expr.span,
2568-
"complex const arguments must be placed inside of a `const` block",
2569-
);
2575+
let msg = "complex const arguments must be placed inside of a `const` block";
2576+
let e = if expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break() {
2577+
// FIXME(mgca): make this non-fatal once we have a better way to handle
2578+
// nested items in const args
2579+
// Issue: https://github.com/rust-lang/rust/issues/154539
2580+
this.dcx().struct_span_fatal(expr.span, msg).emit()
2581+
} else {
2582+
this.dcx().struct_span_err(expr.span, msg).emit()
2583+
};
25702584

2571-
ConstArg { hir_id: this.next_id(), kind: hir::ConstArgKind::Error(e.emit()), span }
2585+
ConstArg { hir_id: this.next_id(), kind: hir::ConstArgKind::Error(e), span }
25722586
};
25732587

25742588
match &expr.kind {

0 commit comments

Comments
 (0)