Skip to content

Commit ad3a598

Browse files
committed
Auto merge of #156113 - JonathanBrouwer:rollup-yXpNY1L, r=JonathanBrouwer
Rollup of 3 pull requests Successful merges: - #153536 (Add `const_param_ty_unchecked` gate) - #155528 (const-stabilize `char::is_control()`) - #156086 (VaList::next_arg: track_caller for better Miri errors)
2 parents 818811b + 06354f4 commit ad3a598

14 files changed

Lines changed: 202 additions & 19 deletions

File tree

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ declare_features! (
256256
(internal, cfg_target_has_reliable_f16_f128, "1.88.0", None),
257257
/// Allows identifying the `compiler_builtins` crate.
258258
(internal, compiler_builtins, "1.13.0", None),
259+
/// Allows skipping `ConstParamTy_` trait implementation checks
260+
(internal, const_param_ty_unchecked, "CURRENT_RUSTC_VERSION", None),
259261
/// Allows writing custom MIR
260262
(internal, custom_mir, "1.65.0", None),
261263
/// Implementation details of externally implementable items

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,12 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er
856856
let span = tcx.def_span(param.def_id);
857857
let def_id = param.def_id.expect_local();
858858

859-
if tcx.features().adt_const_params() || tcx.features().min_adt_const_params() {
859+
if tcx.features().const_param_ty_unchecked() {
860+
enter_wf_checking_ctxt(tcx, tcx.local_parent(def_id), |wfcx| {
861+
wfcx.register_wf_obligation(span, None, ty.into());
862+
Ok(())
863+
})
864+
} else if tcx.features().adt_const_params() || tcx.features().min_adt_const_params() {
860865
enter_wf_checking_ctxt(tcx, tcx.local_parent(def_id), |wfcx| {
861866
wfcx.register_bound(
862867
ObligationCause::new(span, def_id, ObligationCauseCode::ConstParam(ty)),
@@ -1363,12 +1368,14 @@ pub(super) fn check_type_const<'tcx>(
13631368
let tcx = wfcx.tcx();
13641369
let span = tcx.def_span(def_id);
13651370

1366-
wfcx.register_bound(
1367-
ObligationCause::new(span, def_id, ObligationCauseCode::ConstParam(item_ty)),
1368-
wfcx.param_env,
1369-
item_ty,
1370-
tcx.require_lang_item(LangItem::ConstParamTy, span),
1371-
);
1371+
if !tcx.features().const_param_ty_unchecked() {
1372+
wfcx.register_bound(
1373+
ObligationCause::new(span, def_id, ObligationCauseCode::ConstParam(item_ty)),
1374+
wfcx.param_env,
1375+
item_ty,
1376+
tcx.require_lang_item(LangItem::ConstParamTy, span),
1377+
);
1378+
}
13721379

13731380
if has_value {
13741381
let raw_ct = tcx.const_of_item(def_id).instantiate_identity();

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E
184184
return Ok(());
185185
}
186186

187+
if tcx.features().const_param_ty_unchecked() {
188+
return Ok(());
189+
}
190+
187191
if !tcx.features().adt_const_params() {
188192
match *self_type.kind() {
189193
ty::Adt(adt, _) if adt.is_struct() => {

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ symbols! {
680680
const_panic,
681681
const_panic_fmt,
682682
const_param_ty,
683+
const_param_ty_unchecked,
683684
const_precise_live_drops,
684685
const_ptr_cast,
685686
const_raw_ptr_deref,

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
574574
if self.tcx().is_lang_item(def_id, LangItem::Sized) {
575575
return Default::default();
576576
}
577+
if self.tcx().is_lang_item(def_id, LangItem::ConstParamTy)
578+
&& self.tcx().features().const_param_ty_unchecked()
579+
{
580+
return Default::default();
581+
}
577582

578583
let predicates = self.tcx().predicates_of(def_id);
579584
let mut origins = vec![def_id; predicates.predicates.len()];

library/core/src/char/methods.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,9 @@ impl char {
10501050
/// ```
10511051
#[must_use]
10521052
#[stable(feature = "rust1", since = "1.0.0")]
1053+
#[rustc_const_stable(feature = "const_is_control", since = "CURRENT_RUSTC_VERSION")]
10531054
#[inline]
1054-
pub fn is_control(self) -> bool {
1055+
pub const fn is_control(self) -> bool {
10551056
// According to
10561057
// https://www.unicode.org/policies/stability_policy.html#Property_Value,
10571058
// the set of codepoints in `Cc` will never change.

library/core/src/ffi/va_list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ impl<'f> VaList<'f> {
422422
/// [`c_void`]: core::ffi::c_void
423423
#[inline] // Avoid codegen when not used to help backends that don't support VaList.
424424
#[rustc_const_unstable(feature = "const_c_variadic", issue = "151787")]
425+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
425426
pub const unsafe fn next_arg<T: VaArgSafe>(&mut self) -> T {
426427
// SAFETY: the caller must uphold the safety contract for `va_arg`.
427428
unsafe { va_arg(self) }

src/tools/miri/tests/fail/c-variadic.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#![feature(c_variadic)]
22

3-
//@error-in-other-file: Undefined Behavior: more C-variadic arguments read than were passed
4-
53
fn read_too_many() {
64
unsafe extern "C" fn variadic(mut ap: ...) {
7-
ap.next_arg::<i32>();
5+
ap.next_arg::<i32>(); //~ERROR: more C-variadic arguments read than were passed
86
}
97

108
unsafe { variadic() };

src/tools/miri/tests/fail/c-variadic.stderr

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
error: Undefined Behavior: more C-variadic arguments read than were passed
2-
--> RUSTLIB/core/src/ffi/va_list.rs:LL:CC
2+
--> tests/fail/c-variadic.rs:LL:CC
33
|
4-
LL | unsafe { va_arg(self) }
5-
| ^^^^^^^^^^^^ Undefined Behavior occurred here
4+
LL | ap.next_arg::<i32>();
5+
| ^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= note: stack backtrace:
10-
0: std::ffi::VaList::<'_>::next_arg
11-
at RUSTLIB/core/src/ffi/va_list.rs:LL:CC
12-
1: read_too_many::variadic
10+
0: read_too_many::variadic
1311
at tests/fail/c-variadic.rs:LL:CC
14-
2: read_too_many
12+
1: read_too_many
1513
at tests/fail/c-variadic.rs:LL:CC
16-
3: main
14+
2: main
1715
at tests/fail/c-variadic.rs:LL:CC
1816

1917
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Ensure we don't allow Vec<[u8]> as const parameter even with
2+
//! `const_param_ty_unchecked` feature.
3+
#![allow(incomplete_features)]
4+
#![feature(adt_const_params, const_param_ty_unchecked, const_param_ty_trait)]
5+
use std::marker::ConstParamTy_;
6+
7+
struct VectorOfBytes {
8+
a: Vec<[u8]>
9+
//~^ ERROR: the size for values of type `[u8]` cannot be known at compilation time [E0277]
10+
}
11+
impl ConstParamTy_ for VectorOfBytes {}
12+
13+
fn bar<const N: VectorOfBytes>() {}
14+
fn foo<const N: Vec<[u8]>>() {}
15+
//~^ ERROR: the size for values of type `[u8]` cannot be known at compilation time [E0277]
16+
//~| ERROR: the size for values of type `[u8]` cannot be known at compilation time [E0277]
17+
18+
19+
fn main() {}

0 commit comments

Comments
 (0)