Skip to content

Commit 2c0b32a

Browse files
committed
Auto merge of #156140 - jhpratt:rollup-tW55BUD, r=jhpratt
Rollup of 6 pull requests Successful merges: - #155543 (docs(unstable-book): Document const generics features) - #156043 (c-variadic: gate `va_arg` on `c_variadic_experimental_arch`) - #156082 (Move tests associated types) - #156092 (Clean up `TyCtxt::needs_crate_hash` usage and rename it to `needs_hir_hash`.) - #156104 (Relax `T: Sized` bound on `try_as_dyn` / `try_as_dyn_mut`) - #156128 (.mailmap: prefer matching just based on commit emails)
2 parents 1d72d7e + 561cac7 commit 2c0b32a

45 files changed

Lines changed: 621 additions & 28 deletions

File tree

Some content is hidden

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

.mailmap

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,9 @@ Gregor Peach <gregorpeach@gmail.com>
259259
Grzegorz Bartoszek <grzegorz.bartoszek@thaumatec.com>
260260
Guanqun Lu <guanqun.lu@gmail.com>
261261
Guillaume Gomez <contact@guillaume-gomez.fr>
262-
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <guillaume1.gomez@gmail.com>
263-
Guillaume Gomez <contact@guillaume-gomez.fr> ggomez <guillaume1.gomez@gmail.com>
264-
Guillaume Gomez <contact@guillaume-gomez.fr> ggomez <ggomez@ggo.ifr.lan>
265-
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <ggomez@ggo.ifr.lan>
266-
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <guillaume.gomez@huawei.com>
262+
Guillaume Gomez <contact@guillaume-gomez.fr> <guillaume1.gomez@gmail.com>
263+
Guillaume Gomez <contact@guillaume-gomez.fr> <ggomez@ggo.ifr.lan>
264+
Guillaume Gomez <contact@guillaume-gomez.fr> <guillaume.gomez@huawei.com>
267265
gnzlbg <gonzalobg88@gmail.com> <gnzlbg@users.noreply.github.com>
268266
hamidreza kalbasi <hamidrezakalbasi@protonmail.com>
269267
Hanna Kruppe <hanna.kruppe@gmail.com> <robin.kruppe@gmail.com>

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
562562

563563
// Don't hash unless necessary, because it's expensive.
564564
let opt_hir_hash =
565-
if tcx.needs_crate_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
565+
if tcx.needs_hir_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
566566

567567
let delayed_resolver = Steal::new((resolver, krate));
568568
mid_hir::Crate::new(owners, delayed_ids, delayed_resolver, opt_hir_hash)

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::ffi::c_uint;
33
use std::{assert_matches, iter, ptr};
44

55
use rustc_abi::{
6-
AddressSpace, Align, BackendRepr, Float, HasDataLayout, Integer, NumScalableVectors, Primitive,
7-
Size, WrappingRange,
6+
AddressSpace, Align, BackendRepr, CVariadicStatus, Float, HasDataLayout, Integer,
7+
NumScalableVectors, Primitive, Size, WrappingRange,
88
};
99
use rustc_codegen_ssa::base::{compare_simd_types, wants_msvc_seh, wants_wasm_eh};
1010
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
@@ -23,6 +23,7 @@ use rustc_middle::ty::{
2323
};
2424
use rustc_middle::{bug, span_bug};
2525
use rustc_session::config::CrateType;
26+
use rustc_session::errors::feature_err;
2627
use rustc_session::lint::builtin::DEPRECATED_LLVM_INTRINSIC;
2728
use rustc_span::{Span, Symbol, sym};
2829
use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate};
@@ -288,6 +289,16 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
288289
}
289290
sym::breakpoint => self.call_intrinsic("llvm.debugtrap", &[], &[]),
290291
sym::va_arg => {
292+
let target = &self.cx.tcx.sess.target;
293+
let stability = target.supports_c_variadic_definitions();
294+
if let CVariadicStatus::Unstable { feature } = stability
295+
&& !self.tcx.features().enabled(feature)
296+
{
297+
let msg =
298+
format!("C-variadic function definitions on this target are unstable");
299+
feature_err(&*self.sess(), feature, span, msg).emit();
300+
}
301+
291302
let BackendRepr::Scalar(scalar) = result.layout.backend_repr else {
292303
bug!("the va_arg intrinsic does not support non-scalar types")
293304
};

compiler/rustc_feature/src/unstable.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,9 @@ declare_features! (
563563
/// Allows defining gen blocks and `gen fn`.
564564
(unstable, gen_blocks, "1.75.0", Some(117078)),
565565
/// Allows using generics in more complex const expressions, based on definitional equality.
566-
(unstable, generic_const_args, "1.95.0", Some(151972)),
567-
/// Allows non-trivial generic constants which have to have wfness manually propagated to callers
566+
(incomplete, generic_const_args, "1.95.0", Some(151972)),
567+
/// Allows non-trivial generic constants which have to be shown to successfully evaluate
568+
/// to a value by being part of an item signature.
568569
(incomplete, generic_const_exprs, "1.56.0", Some(76560)),
569570
/// Allows generic parameters and where-clauses on free & associated const items.
570571
(incomplete, generic_const_items, "1.73.0", Some(113521)),
@@ -626,7 +627,8 @@ declare_features! (
626627
/// Allows additional const parameter types, such as [u8; 10] or user defined types.
627628
/// User defined types must not have fields more private than the type itself.
628629
(unstable, min_adt_const_params, "1.96.0", Some(154042)),
629-
/// Enables the generic const args MVP (only bare paths, not arbitrary computation).
630+
/// Enables the generic const args MVP (paths to type const items and constructors
631+
/// for ADTs and primitives).
630632
(incomplete, min_generic_const_args, "1.84.0", Some(132980)),
631633
/// A minimal, sound subset of specialization intended to be used by the
632634
/// standard library until the soundness issues with specialization

compiler/rustc_interface/src/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Linker {
3636
Linker {
3737
dep_graph: tcx.dep_graph.clone(),
3838
output_filenames: Arc::clone(tcx.output_filenames(())),
39-
crate_hash: if tcx.needs_crate_hash() {
39+
crate_hash: if tcx.sess.opts.incremental.is_some() {
4040
Some(tcx.crate_hash(LOCAL_CRATE))
4141
} else {
4242
None

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'tcx> TyCtxt<'tcx> {
237237
attrs: &SortedMap<ItemLocalId, &[Attribute]>,
238238
define_opaque: Option<&[(Span, LocalDefId)]>,
239239
) -> Hashes {
240-
if !self.needs_crate_hash() {
240+
if !self.needs_hir_hash() {
241241
return Hashes { opt_hash_including_bodies: None, attrs_hash: None };
242242
}
243243

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,12 +1127,12 @@ impl<'tcx> TyCtxt<'tcx> {
11271127
})
11281128
}
11291129

1130-
pub fn needs_crate_hash(self) -> bool {
1131-
// Why is the crate hash needed for these configurations?
1130+
pub fn needs_hir_hash(self) -> bool {
1131+
// Why is the hir hash needed for these configurations?
11321132
// - debug_assertions: for the "fingerprint the result" check in
11331133
// `rustc_query_impl::execution::execute_job`.
11341134
// - incremental: for query lookups.
1135-
// - needs_metadata: for putting into crate metadata.
1135+
// - needs_metadata: it is included in the crate metadata through the crate_hash query
11361136
// - instrument_coverage: for putting into coverage data (see
11371137
// `hash_mir_source`).
11381138
// - metrics_dir: metrics use the strict version hash in the filenames

library/core/src/any.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,18 +1007,23 @@ pub const fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str {
10071007
#[must_use]
10081008
#[unstable(feature = "try_as_dyn", issue = "144361")]
10091009
pub const fn try_as_dyn<
1010-
T: Any + 'static,
1010+
T: Any + ?Sized + 'static,
10111011
U: ptr::Pointee<Metadata = ptr::DynMetadata<U>> + ?Sized + 'static,
10121012
>(
10131013
t: &T,
10141014
) -> Option<&U> {
1015+
// For unsized `T`, `trait_info_of` always returns `None` (vtable lookup is
1016+
// only supported for sized types). The function therefore unconditionally
1017+
// returns `None` in that case.
10151018
let vtable: Option<ptr::DynMetadata<U>> =
10161019
const { TypeId::of::<T>().trait_info_of::<U>().as_ref().map(TraitImpl::get_vtable) };
10171020
match vtable {
10181021
Some(dyn_metadata) => {
1019-
let pointer = ptr::from_raw_parts(t, dyn_metadata);
1022+
let pointer = ptr::from_raw_parts(t as *const T as *const (), dyn_metadata);
10201023
// SAFETY: `t` is a reference to a type, so we know it is valid.
10211024
// `dyn_metadata` is a vtable for T, implementing the trait of `U`.
1025+
// `T` is sized here because `trait_info_of` only returns `Some` for sized types,
1026+
// so the thin data pointer fully describes the value.
10221027
Some(unsafe { &*pointer })
10231028
}
10241029
None => None,
@@ -1061,18 +1066,23 @@ pub const fn try_as_dyn<
10611066
#[must_use]
10621067
#[unstable(feature = "try_as_dyn", issue = "144361")]
10631068
pub const fn try_as_dyn_mut<
1064-
T: Any + 'static,
1069+
T: Any + ?Sized + 'static,
10651070
U: ptr::Pointee<Metadata = ptr::DynMetadata<U>> + ?Sized + 'static,
10661071
>(
10671072
t: &mut T,
10681073
) -> Option<&mut U> {
1074+
// For unsized `T`, `trait_info_of` always returns `None` (vtable lookup is
1075+
// only supported for sized types). The function therefore unconditionally
1076+
// returns `None` in that case.
10691077
let vtable: Option<ptr::DynMetadata<U>> =
10701078
const { TypeId::of::<T>().trait_info_of::<U>().as_ref().map(TraitImpl::get_vtable) };
10711079
match vtable {
10721080
Some(dyn_metadata) => {
1073-
let pointer = ptr::from_raw_parts_mut(t, dyn_metadata);
1081+
let pointer = ptr::from_raw_parts_mut(t as *mut T as *mut (), dyn_metadata);
10741082
// SAFETY: `t` is a reference to a type, so we know it is valid.
10751083
// `dyn_metadata` is a vtable for T, implementing the trait of `U`.
1084+
// `T` is sized here because `trait_info_of` only returns `Some` for sized types,
1085+
// so the thin data pointer fully describes the value.
10761086
Some(unsafe { &mut *pointer })
10771087
}
10781088
None => None,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# generic_const_args
2+
3+
Allows using generics in more complex const expressions, based on definitional equality.
4+
5+
The tracking issue for this feature is: [#151972]
6+
7+
[#151972]: https://github.com/rust-lang/rust/issues/151972
8+
9+
------------------------
10+
11+
Warning: This feature is incomplete; its design and syntax may change.
12+
13+
This feature enables many of the same use cases supported by [generic_const_exprs],
14+
but based on the machinery developed for [min_generic_const_args]. In a way, it is
15+
meant to be an interim successor for GCE (though it might not currently support all
16+
the valid cases that supported by GCE).
17+
18+
See also: [generic_const_items]
19+
20+
[min_generic_const_args]: min-generic-const-args.md
21+
[generic_const_exprs]: generic-const-exprs.md
22+
[generic_const_items]: generic-const-items.md
23+
24+
## Examples
25+
26+
```rust
27+
#![feature(generic_const_items)]
28+
#![feature(min_generic_const_args)]
29+
#![feature(generic_const_args)]
30+
#![expect(incomplete_features)]
31+
32+
type const ADD1<const N: usize>: usize = const { N + 1 };
33+
34+
type const INC<const N: usize>: usize = ADD1::<N>;
35+
36+
const ARR: [(); ADD1::<0>] = [(); INC::<0>];
37+
```
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# generic_const_exprs
2+
3+
Allows non-trivial generic constants which have to be shown to successfully evaluate
4+
to a value by being part of an item signature.
5+
6+
The tracking issue for this feature is: [#76560]
7+
8+
9+
[#76560]: https://github.com/rust-lang/rust/issues/76560
10+
11+
------------------------
12+
13+
Warning: This feature is incomplete; its design and syntax may change.
14+
15+
See also: [min_generic_const_args], [generic_const_args]
16+
17+
[min_generic_const_args]: min-generic-const-args.md
18+
[generic_const_args]: generic-const-args.md
19+
20+
## Examples
21+
22+
```rust
23+
#![allow(incomplete_features)]
24+
#![feature(generic_const_exprs)]
25+
26+
// Use parameters that depend on a generic argument.
27+
struct Foo<const N: usize>
28+
where
29+
[(); N + 1]:,
30+
{
31+
array: [usize; N + 1],
32+
}
33+
34+
// Use generic parameters in const operations.
35+
trait Bar {
36+
const X: usize;
37+
const Y: usize;
38+
}
39+
40+
// Note `B::X * B::Y`.
41+
const fn baz<B: Bar>(x: [usize; B::X], y: [usize; B::Y]) -> [usize; B::X * B::Y] {
42+
let mut out = [0; B::X * B::Y];
43+
let mut i = 0;
44+
while i < B::Y {
45+
let mut j = 0;
46+
while j < B::X {
47+
out[i * B::X + j] = y[i].saturating_mul(x[j]);
48+
j += 1;
49+
}
50+
i += 1;
51+
}
52+
out
53+
}
54+
55+
56+
// Create a new type based on a generic argument.
57+
pub struct Grow<const N: usize> {
58+
arr: [usize; N],
59+
}
60+
61+
impl<const N: usize> Grow<N> {
62+
pub const fn grow(self, val: usize) -> Grow<{ N + 1 }> {
63+
let mut new_arr = [0; { N + 1 }];
64+
let mut idx = 0;
65+
while idx < N {
66+
new_arr[idx] = self.arr[idx];
67+
idx += 1;
68+
}
69+
new_arr[N] = val;
70+
Grow { arr: new_arr }
71+
}
72+
}
73+
```

0 commit comments

Comments
 (0)