Skip to content

Commit 6dbf494

Browse files
committed
add const_param_ty_unchecked gate
1 parent ea5573a commit 6dbf494

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ declare_features! (
229229
(internal, cfg_target_has_reliable_f16_f128, "1.88.0", None),
230230
/// Allows identifying the `compiler_builtins` crate.
231231
(internal, compiler_builtins, "1.13.0", None),
232+
/// Allows skipping `ConstParamTy_` trait implementation checks
233+
(internal, const_param_ty_unchecked, "CURRENT_RUSTC_VERSION", None),
232234
/// Allows writing custom MIR
233235
(internal, custom_mir, "1.65.0", None),
234236
/// Implementation details of externally implementable items

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
let cause = traits::ObligationCause::misc(DUMMY_SP, impl_did);
188192
match type_allowed_to_implement_const_param_ty(tcx, param_env, self_type, cause) {
189193
Ok(()) => Ok(()),

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ symbols! {
676676
const_panic,
677677
const_panic_fmt,
678678
const_param_ty,
679+
const_param_ty_unchecked,
679680
const_precise_live_drops,
680681
const_ptr_cast,
681682
const_raw_ptr_deref,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@check-pass
2+
//! Ensure that const_param_ty_unchecked gate allow
3+
//! bypassing `ConstParamTy_` implementation check
4+
5+
#![allow(incomplete_features)]
6+
//FIXME: change to const_param_ty_trait gate when it will be merged
7+
#![feature(unsized_const_params, adt_const_params)]
8+
#![feature(const_param_ty_unchecked)]
9+
10+
use std::marker::ConstParamTy_;
11+
12+
#[derive(PartialEq, Eq)]
13+
struct Miow; // Miow does not implement ConstParamTy_.
14+
15+
#[derive(PartialEq, Eq)]
16+
struct Meoww(Miow);
17+
18+
impl ConstParamTy_ for Meoww {}
19+
20+
fn main() {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// gate-test-const_param_ty_unchecked
2+
//! Ensure this fails when const_param_ty_unchecked isn't used
3+
4+
#![allow(incomplete_features)]
5+
//FIXME: change to const_param_ty_trait gate when it will be merged
6+
#![feature(unsized_const_params, adt_const_params)]
7+
8+
use std::marker::ConstParamTy_;
9+
10+
#[derive(PartialEq, Eq)]
11+
struct Miow; // Miow does not implement ConstParamTy_.
12+
13+
#[derive(PartialEq, Eq)]
14+
struct Meoww(Miow);
15+
16+
impl ConstParamTy_ for Meoww {}
17+
//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type [E0204]
18+
19+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
2+
--> $DIR/const_param_ty_unchecked_fail.rs:16:24
3+
|
4+
LL | struct Meoww(Miow);
5+
| ---- this field does not implement `ConstParamTy_`
6+
LL |
7+
LL | impl ConstParamTy_ for Meoww {}
8+
| ^^^^^
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0204`.

0 commit comments

Comments
 (0)