Auto merge of #127722 - BoxyUwU:new_adt_const_params_limitations, r=compiler-errors
Forbid borrows and unsized types from being used as the type of a const generic under `adt_const_params` Fixes #112219 Fixes #112124 Fixes #112125 ### Motivation Currently the `adt_const_params` feature allows writing `Foo<const N: [u8]>` this is entirely useless as it is not possible to write an expression which evaluates to a type that is not `Sized`. In order to actually use unsized types in const generics they are typically written as `const N: &[u8]` which *is* possible to provide a value of. Unfortunately allowing the types of const parameters to contain references is non trivial (#120961) as it introduces a number of difficult questions about how equality of references in the type system should behave. References in the types of const generics is largely only useful for using unsized types in const generics. This PR introduces a new feature gate `unsized_const_parameters` and moves support for `const N: [u8]` and `const N: &...` from `adt_const_params` into it. The goal here hopefully is to experiment with allowing `const N: [u8]` to work without references and then eventually completely forbid references in const generics. Splitting this out into a new feature gate means that stabilization of `adt_const_params` does not have to resolve #120961 which is the only remaining "big" blocker for the feature. Remaining issues after this are a few ICEs and naming bikeshed for `ConstParamTy`. ### Implementation The implementation is slightly subtle here as we would like to ensure that a stabilization of `adt_const_params` is forwards compatible with any outcome of `unsized_const_parameters`. This is inherently tricky as we do not support unstable trait implementations and we determine whether a type is valid as the type of a const parameter via a trait bound. There are a few constraints here: - We would like to *allow for the possibility* of adding a `Sized` supertrait to `ConstParamTy` in the event that we wind up opting to not support unsized types and instead requiring people to write the 'sized version', e.g. `const N: [u8; M]` instead of `const N: [u8]`. - Crates should be able to enable `unsized_const_parameters` and write trait implementations of `ConstParamTy` for `!Sized` types without downstream crates that only enable `adt_const_params` being able to observe this (required for std to be able to `impl<T> ConstParamTy for [T]` Ultimately the way this is accomplished is via having two traits (sad), `ConstParamTy` and `UnsizedConstParamTy`. Depending on whether `unsized_const_parameters` is enabled or not we change which trait is used to check whether a type is allowed to be a const parameter. Long term (when stabilizing `UnsizedConstParamTy`) it should be possible to completely merge these traits (and derive macros), only having a single `trait ConstParamTy` and `macro ConstParamTy`. Under `adt_const_params` it is now illegal to directly refer to `ConstParamTy` it is only used as an internal impl detail by `derive(ConstParamTy)` and checking const parameters are well formed. This is necessary in order to ensure forwards compatibility with all possible future directions for `feature(unsized_const_parameters)`. Generally the intuition here should be that `ConstParamTy` is the stable trait that everything uses, and `UnsizedConstParamTy` is that plus unstable implementations (well, I suppose `ConstParamTy` isn't stable yet :P).
This commit is contained in:
commit
9629b90b3f
141 changed files with 1242 additions and 543 deletions
|
@ -38,7 +38,44 @@ pub(crate) fn expand_deriving_const_param_ty(
|
||||||
) {
|
) {
|
||||||
let trait_def = TraitDef {
|
let trait_def = TraitDef {
|
||||||
span,
|
span,
|
||||||
path: path_std!(marker::ConstParamTy),
|
path: path_std!(marker::ConstParamTy_),
|
||||||
|
skip_path_as_bound: false,
|
||||||
|
needs_copy_as_bound_if_packed: false,
|
||||||
|
additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))],
|
||||||
|
supports_unions: false,
|
||||||
|
methods: Vec::new(),
|
||||||
|
associated_types: Vec::new(),
|
||||||
|
is_const,
|
||||||
|
};
|
||||||
|
|
||||||
|
trait_def.expand(cx, mitem, item, push);
|
||||||
|
|
||||||
|
let trait_def = TraitDef {
|
||||||
|
span,
|
||||||
|
path: path_std!(marker::UnsizedConstParamTy),
|
||||||
|
skip_path_as_bound: false,
|
||||||
|
needs_copy_as_bound_if_packed: false,
|
||||||
|
additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))],
|
||||||
|
supports_unions: false,
|
||||||
|
methods: Vec::new(),
|
||||||
|
associated_types: Vec::new(),
|
||||||
|
is_const,
|
||||||
|
};
|
||||||
|
|
||||||
|
trait_def.expand(cx, mitem, item, push);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn expand_deriving_unsized_const_param_ty(
|
||||||
|
cx: &ExtCtxt<'_>,
|
||||||
|
span: Span,
|
||||||
|
mitem: &MetaItem,
|
||||||
|
item: &Annotatable,
|
||||||
|
push: &mut dyn FnMut(Annotatable),
|
||||||
|
is_const: bool,
|
||||||
|
) {
|
||||||
|
let trait_def = TraitDef {
|
||||||
|
span,
|
||||||
|
path: path_std!(marker::UnsizedConstParamTy),
|
||||||
skip_path_as_bound: false,
|
skip_path_as_bound: false,
|
||||||
needs_copy_as_bound_if_packed: false,
|
needs_copy_as_bound_if_packed: false,
|
||||||
additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))],
|
additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))],
|
||||||
|
|
|
@ -118,6 +118,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
|
||||||
Clone: clone::expand_deriving_clone,
|
Clone: clone::expand_deriving_clone,
|
||||||
Copy: bounds::expand_deriving_copy,
|
Copy: bounds::expand_deriving_copy,
|
||||||
ConstParamTy: bounds::expand_deriving_const_param_ty,
|
ConstParamTy: bounds::expand_deriving_const_param_ty,
|
||||||
|
UnsizedConstParamTy: bounds::expand_deriving_unsized_const_param_ty,
|
||||||
Debug: debug::expand_deriving_debug,
|
Debug: debug::expand_deriving_debug,
|
||||||
Default: default::expand_deriving_default,
|
Default: default::expand_deriving_default,
|
||||||
Eq: eq::expand_deriving_eq,
|
Eq: eq::expand_deriving_eq,
|
||||||
|
|
|
@ -6,7 +6,7 @@ allowed.
|
||||||
Erroneous code example:
|
Erroneous code example:
|
||||||
|
|
||||||
```compile_fail,E0770
|
```compile_fail,E0770
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
|
||||||
fn function_with_str<'a, const STRING: &'a str>() {} // error!
|
fn function_with_str<'a, const STRING: &'a str>() {} // error!
|
||||||
```
|
```
|
||||||
|
@ -15,7 +15,7 @@ To fix this issue, the lifetime in the const generic need to be changed to
|
||||||
`'static`:
|
`'static`:
|
||||||
|
|
||||||
```
|
```
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
|
||||||
fn function_with_str<const STRING: &'static str>() {} // ok!
|
fn function_with_str<const STRING: &'static str>() {} // ok!
|
||||||
```
|
```
|
||||||
|
|
|
@ -339,8 +339,8 @@ declare_features! (
|
||||||
(unstable, abi_riscv_interrupt, "1.73.0", Some(111889)),
|
(unstable, abi_riscv_interrupt, "1.73.0", Some(111889)),
|
||||||
/// Allows `extern "x86-interrupt" fn()`.
|
/// Allows `extern "x86-interrupt" fn()`.
|
||||||
(unstable, abi_x86_interrupt, "1.17.0", Some(40180)),
|
(unstable, abi_x86_interrupt, "1.17.0", Some(40180)),
|
||||||
/// Allows additional const parameter types, such as `&'static str` or user defined types
|
/// Allows additional const parameter types, such as `[u8; 10]` or user defined types
|
||||||
(incomplete, adt_const_params, "1.56.0", Some(95174)),
|
(unstable, adt_const_params, "1.56.0", Some(95174)),
|
||||||
/// Allows defining an `#[alloc_error_handler]`.
|
/// Allows defining an `#[alloc_error_handler]`.
|
||||||
(unstable, alloc_error_handler, "1.29.0", Some(51540)),
|
(unstable, alloc_error_handler, "1.29.0", Some(51540)),
|
||||||
/// Allows trait methods with arbitrary self types.
|
/// Allows trait methods with arbitrary self types.
|
||||||
|
@ -630,6 +630,9 @@ declare_features! (
|
||||||
(unstable, unsafe_attributes, "1.80.0", Some(123757)),
|
(unstable, unsafe_attributes, "1.80.0", Some(123757)),
|
||||||
/// Allows unsafe on extern declarations and safety qualifiers over internal items.
|
/// Allows unsafe on extern declarations and safety qualifiers over internal items.
|
||||||
(unstable, unsafe_extern_blocks, "1.80.0", Some(123743)),
|
(unstable, unsafe_extern_blocks, "1.80.0", Some(123743)),
|
||||||
|
/// Allows const generic parameters to be defined with types that
|
||||||
|
/// are not `Sized`, e.g. `fn foo<const N: [u8]>() {`.
|
||||||
|
(incomplete, unsized_const_params, "CURRENT_RUSTC_VERSION", Some(95174)),
|
||||||
/// Allows unsized fn parameters.
|
/// Allows unsized fn parameters.
|
||||||
(internal, unsized_fn_params, "1.49.0", Some(48055)),
|
(internal, unsized_fn_params, "1.49.0", Some(48055)),
|
||||||
/// Allows unsized rvalues at arguments and parameters.
|
/// Allows unsized rvalues at arguments and parameters.
|
||||||
|
|
|
@ -358,6 +358,7 @@ language_item_table! {
|
||||||
PointerLike, sym::pointer_like, pointer_like, Target::Trait, GenericRequirement::Exact(0);
|
PointerLike, sym::pointer_like, pointer_like, Target::Trait, GenericRequirement::Exact(0);
|
||||||
|
|
||||||
ConstParamTy, sym::const_param_ty, const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0);
|
ConstParamTy, sym::const_param_ty, const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||||
|
UnsizedConstParamTy, sym::unsized_const_param_ty, unsized_const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||||
|
|
||||||
Poll, sym::Poll, poll, Target::Enum, GenericRequirement::None;
|
Poll, sym::Poll, poll, Target::Enum, GenericRequirement::None;
|
||||||
PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None;
|
PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None;
|
||||||
|
|
|
@ -99,6 +99,10 @@ hir_analysis_const_param_ty_impl_on_non_adt =
|
||||||
the trait `ConstParamTy` may not be implemented for this type
|
the trait `ConstParamTy` may not be implemented for this type
|
||||||
.label = type is not a structure or enumeration
|
.label = type is not a structure or enumeration
|
||||||
|
|
||||||
|
hir_analysis_const_param_ty_impl_on_unsized =
|
||||||
|
the trait `ConstParamTy` may not be implemented for this type
|
||||||
|
.label = type is not `Sized`
|
||||||
|
|
||||||
hir_analysis_const_specialize = cannot specialize on const impl with non-const impl
|
hir_analysis_const_specialize = cannot specialize on const impl with non-const impl
|
||||||
|
|
||||||
hir_analysis_copy_impl_on_non_adt =
|
hir_analysis_copy_impl_on_non_adt =
|
||||||
|
|
|
@ -922,10 +922,8 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
|
||||||
} => {
|
} => {
|
||||||
let ty = tcx.type_of(param.def_id).instantiate_identity();
|
let ty = tcx.type_of(param.def_id).instantiate_identity();
|
||||||
|
|
||||||
if tcx.features().adt_const_params {
|
if tcx.features().unsized_const_params {
|
||||||
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
|
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
|
||||||
let trait_def_id =
|
|
||||||
tcx.require_lang_item(LangItem::ConstParamTy, Some(hir_ty.span));
|
|
||||||
wfcx.register_bound(
|
wfcx.register_bound(
|
||||||
ObligationCause::new(
|
ObligationCause::new(
|
||||||
hir_ty.span,
|
hir_ty.span,
|
||||||
|
@ -934,7 +932,21 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
|
||||||
),
|
),
|
||||||
wfcx.param_env,
|
wfcx.param_env,
|
||||||
ty,
|
ty,
|
||||||
trait_def_id,
|
tcx.require_lang_item(LangItem::UnsizedConstParamTy, Some(hir_ty.span)),
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
} else if tcx.features().adt_const_params {
|
||||||
|
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
|
||||||
|
wfcx.register_bound(
|
||||||
|
ObligationCause::new(
|
||||||
|
hir_ty.span,
|
||||||
|
param.def_id,
|
||||||
|
ObligationCauseCode::ConstParam(ty),
|
||||||
|
),
|
||||||
|
wfcx.param_env,
|
||||||
|
ty,
|
||||||
|
tcx.require_lang_item(LangItem::ConstParamTy, Some(hir_ty.span)),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
|
@ -958,14 +970,29 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
|
||||||
diag.note("the only supported types are integers, `bool` and `char`");
|
diag.note("the only supported types are integers, `bool` and `char`");
|
||||||
|
|
||||||
let cause = ObligationCause::misc(hir_ty.span, param.def_id);
|
let cause = ObligationCause::misc(hir_ty.span, param.def_id);
|
||||||
|
let adt_const_params_feature_string =
|
||||||
|
" more complex and user defined types".to_string();
|
||||||
let may_suggest_feature = match type_allowed_to_implement_const_param_ty(
|
let may_suggest_feature = match type_allowed_to_implement_const_param_ty(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.param_env(param.def_id),
|
tcx.param_env(param.def_id),
|
||||||
ty,
|
ty,
|
||||||
|
LangItem::ConstParamTy,
|
||||||
cause,
|
cause,
|
||||||
) {
|
) {
|
||||||
// Can never implement `ConstParamTy`, don't suggest anything.
|
// Can never implement `ConstParamTy`, don't suggest anything.
|
||||||
Err(ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed) => false,
|
Err(
|
||||||
|
ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed
|
||||||
|
| ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(..),
|
||||||
|
) => None,
|
||||||
|
Err(ConstParamTyImplementationError::UnsizedConstParamsFeatureRequired) => {
|
||||||
|
Some(vec![
|
||||||
|
(adt_const_params_feature_string, sym::adt_const_params),
|
||||||
|
(
|
||||||
|
" references to implement the `ConstParamTy` trait".into(),
|
||||||
|
sym::unsized_const_params,
|
||||||
|
),
|
||||||
|
])
|
||||||
|
}
|
||||||
// May be able to implement `ConstParamTy`. Only emit the feature help
|
// May be able to implement `ConstParamTy`. Only emit the feature help
|
||||||
// if the type is local, since the user may be able to fix the local type.
|
// if the type is local, since the user may be able to fix the local type.
|
||||||
Err(ConstParamTyImplementationError::InfrigingFields(..)) => {
|
Err(ConstParamTyImplementationError::InfrigingFields(..)) => {
|
||||||
|
@ -985,20 +1012,16 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ty_is_local(ty)
|
ty_is_local(ty).then_some(vec![(
|
||||||
|
adt_const_params_feature_string,
|
||||||
|
sym::adt_const_params,
|
||||||
|
)])
|
||||||
}
|
}
|
||||||
// Implments `ConstParamTy`, suggest adding the feature to enable.
|
// Implments `ConstParamTy`, suggest adding the feature to enable.
|
||||||
Ok(..) => true,
|
Ok(..) => Some(vec![(adt_const_params_feature_string, sym::adt_const_params)]),
|
||||||
};
|
};
|
||||||
if may_suggest_feature {
|
if let Some(features) = may_suggest_feature {
|
||||||
tcx.disabled_nightly_features(
|
tcx.disabled_nightly_features(&mut diag, Some(param.hir_id), features);
|
||||||
&mut diag,
|
|
||||||
Some(param.hir_id),
|
|
||||||
[(
|
|
||||||
" more complex and user defined types".to_string(),
|
|
||||||
sym::adt_const_params,
|
|
||||||
)],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(diag.emit())
|
Err(diag.emit())
|
||||||
|
|
|
@ -36,9 +36,13 @@ pub(super) fn check_trait<'tcx>(
|
||||||
let checker = Checker { tcx, trait_def_id, impl_def_id, impl_header };
|
let checker = Checker { tcx, trait_def_id, impl_def_id, impl_header };
|
||||||
let mut res = checker.check(lang_items.drop_trait(), visit_implementation_of_drop);
|
let mut res = checker.check(lang_items.drop_trait(), visit_implementation_of_drop);
|
||||||
res = res.and(checker.check(lang_items.copy_trait(), visit_implementation_of_copy));
|
res = res.and(checker.check(lang_items.copy_trait(), visit_implementation_of_copy));
|
||||||
res = res.and(
|
res = res.and(checker.check(lang_items.const_param_ty_trait(), |checker| {
|
||||||
checker.check(lang_items.const_param_ty_trait(), visit_implementation_of_const_param_ty),
|
visit_implementation_of_const_param_ty(checker, LangItem::ConstParamTy)
|
||||||
);
|
}));
|
||||||
|
res = res.and(checker.check(lang_items.unsized_const_param_ty_trait(), |checker| {
|
||||||
|
visit_implementation_of_const_param_ty(checker, LangItem::UnsizedConstParamTy)
|
||||||
|
}));
|
||||||
|
|
||||||
res = res.and(
|
res = res.and(
|
||||||
checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized),
|
checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized),
|
||||||
);
|
);
|
||||||
|
@ -103,7 +107,13 @@ fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaran
|
||||||
Ok(()) => Ok(()),
|
Ok(()) => Ok(()),
|
||||||
Err(CopyImplementationError::InfringingFields(fields)) => {
|
Err(CopyImplementationError::InfringingFields(fields)) => {
|
||||||
let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span;
|
let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span;
|
||||||
Err(infringing_fields_error(tcx, fields, LangItem::Copy, impl_did, span))
|
Err(infringing_fields_error(
|
||||||
|
tcx,
|
||||||
|
fields.into_iter().map(|(field, ty, reason)| (tcx.def_span(field.did), ty, reason)),
|
||||||
|
LangItem::Copy,
|
||||||
|
impl_did,
|
||||||
|
span,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
Err(CopyImplementationError::NotAnAdt) => {
|
Err(CopyImplementationError::NotAnAdt) => {
|
||||||
let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span;
|
let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span;
|
||||||
|
@ -116,7 +126,12 @@ fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaran
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
|
fn visit_implementation_of_const_param_ty(
|
||||||
|
checker: &Checker<'_>,
|
||||||
|
kind: LangItem,
|
||||||
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
|
assert!(matches!(kind, LangItem::ConstParamTy | LangItem::UnsizedConstParamTy));
|
||||||
|
|
||||||
let tcx = checker.tcx;
|
let tcx = checker.tcx;
|
||||||
let header = checker.impl_header;
|
let header = checker.impl_header;
|
||||||
let impl_did = checker.impl_def_id;
|
let impl_did = checker.impl_def_id;
|
||||||
|
@ -125,21 +140,41 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E
|
||||||
|
|
||||||
let param_env = tcx.param_env(impl_did);
|
let param_env = tcx.param_env(impl_did);
|
||||||
|
|
||||||
if let ty::ImplPolarity::Negative = header.polarity {
|
if let ty::ImplPolarity::Negative | ty::ImplPolarity::Reservation = header.polarity {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let cause = traits::ObligationCause::misc(DUMMY_SP, impl_did);
|
let cause = traits::ObligationCause::misc(DUMMY_SP, impl_did);
|
||||||
match type_allowed_to_implement_const_param_ty(tcx, param_env, self_type, cause) {
|
match type_allowed_to_implement_const_param_ty(tcx, param_env, self_type, kind, cause) {
|
||||||
Ok(()) => Ok(()),
|
Ok(()) => Ok(()),
|
||||||
Err(ConstParamTyImplementationError::InfrigingFields(fields)) => {
|
Err(ConstParamTyImplementationError::InfrigingFields(fields)) => {
|
||||||
let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span;
|
let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span;
|
||||||
Err(infringing_fields_error(tcx, fields, LangItem::ConstParamTy, impl_did, span))
|
Err(infringing_fields_error(
|
||||||
|
tcx,
|
||||||
|
fields.into_iter().map(|(field, ty, reason)| (tcx.def_span(field.did), ty, reason)),
|
||||||
|
LangItem::ConstParamTy,
|
||||||
|
impl_did,
|
||||||
|
span,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
Err(ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed) => {
|
Err(ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed) => {
|
||||||
let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span;
|
let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span;
|
||||||
Err(tcx.dcx().emit_err(errors::ConstParamTyImplOnNonAdt { span }))
|
Err(tcx.dcx().emit_err(errors::ConstParamTyImplOnNonAdt { span }))
|
||||||
}
|
}
|
||||||
|
Err(ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(infringing_tys)) => {
|
||||||
|
let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span;
|
||||||
|
Err(infringing_fields_error(
|
||||||
|
tcx,
|
||||||
|
infringing_tys.into_iter().map(|(ty, reason)| (span, ty, reason)),
|
||||||
|
LangItem::ConstParamTy,
|
||||||
|
impl_did,
|
||||||
|
span,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
Err(ConstParamTyImplementationError::UnsizedConstParamsFeatureRequired) => {
|
||||||
|
let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span;
|
||||||
|
Err(tcx.dcx().emit_err(errors::ConstParamTyImplOnUnsized { span }))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,9 +536,9 @@ pub fn coerce_unsized_info<'tcx>(
|
||||||
Ok(CoerceUnsizedInfo { custom_kind: kind })
|
Ok(CoerceUnsizedInfo { custom_kind: kind })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn infringing_fields_error(
|
fn infringing_fields_error<'tcx>(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'tcx>,
|
||||||
fields: Vec<(&ty::FieldDef, Ty<'_>, InfringingFieldsReason<'_>)>,
|
infringing_tys: impl Iterator<Item = (Span, Ty<'tcx>, InfringingFieldsReason<'tcx>)>,
|
||||||
lang_item: LangItem,
|
lang_item: LangItem,
|
||||||
impl_did: LocalDefId,
|
impl_did: LocalDefId,
|
||||||
impl_span: Span,
|
impl_span: Span,
|
||||||
|
@ -521,13 +556,13 @@ fn infringing_fields_error(
|
||||||
|
|
||||||
let mut label_spans = Vec::new();
|
let mut label_spans = Vec::new();
|
||||||
|
|
||||||
for (field, ty, reason) in fields {
|
for (span, ty, reason) in infringing_tys {
|
||||||
// Only report an error once per type.
|
// Only report an error once per type.
|
||||||
if !seen_tys.insert(ty) {
|
if !seen_tys.insert(ty) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
label_spans.push(tcx.def_span(field.did));
|
label_spans.push(span);
|
||||||
|
|
||||||
match reason {
|
match reason {
|
||||||
InfringingFieldsReason::Fulfill(fulfillment_errors) => {
|
InfringingFieldsReason::Fulfill(fulfillment_errors) => {
|
||||||
|
|
|
@ -278,6 +278,14 @@ pub struct CopyImplOnNonAdt {
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(hir_analysis_const_param_ty_impl_on_unsized)]
|
||||||
|
pub struct ConstParamTyImplOnUnsized {
|
||||||
|
#[primary_span]
|
||||||
|
#[label]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(hir_analysis_const_param_ty_impl_on_non_adt)]
|
#[diag(hir_analysis_const_param_ty_impl_on_non_adt)]
|
||||||
pub struct ConstParamTyImplOnNonAdt {
|
pub struct ConstParamTyImplOnNonAdt {
|
||||||
|
|
|
@ -177,6 +177,7 @@ symbols! {
|
||||||
CoerceUnsized,
|
CoerceUnsized,
|
||||||
Command,
|
Command,
|
||||||
ConstParamTy,
|
ConstParamTy,
|
||||||
|
ConstParamTy_,
|
||||||
Context,
|
Context,
|
||||||
Continue,
|
Continue,
|
||||||
Copy,
|
Copy,
|
||||||
|
@ -336,6 +337,7 @@ symbols! {
|
||||||
TyKind,
|
TyKind,
|
||||||
Unknown,
|
Unknown,
|
||||||
Unsize,
|
Unsize,
|
||||||
|
UnsizedConstParamTy,
|
||||||
Upvars,
|
Upvars,
|
||||||
Vec,
|
Vec,
|
||||||
VecDeque,
|
VecDeque,
|
||||||
|
@ -2001,6 +2003,8 @@ symbols! {
|
||||||
unsafe_no_drop_flag,
|
unsafe_no_drop_flag,
|
||||||
unsafe_pin_internals,
|
unsafe_pin_internals,
|
||||||
unsize,
|
unsize,
|
||||||
|
unsized_const_param_ty,
|
||||||
|
unsized_const_params,
|
||||||
unsized_fn_params,
|
unsized_fn_params,
|
||||||
unsized_locals,
|
unsized_locals,
|
||||||
unsized_tuple_coercion,
|
unsized_tuple_coercion,
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::regions::InferCtxtRegionExt;
|
||||||
use crate::traits::{self, FulfillmentError, ObligationCause};
|
use crate::traits::{self, FulfillmentError, ObligationCause};
|
||||||
|
|
||||||
use hir::LangItem;
|
use hir::LangItem;
|
||||||
|
use rustc_ast::Mutability;
|
||||||
use rustc_data_structures::fx::FxIndexSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||||
|
@ -19,6 +20,8 @@ pub enum CopyImplementationError<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ConstParamTyImplementationError<'tcx> {
|
pub enum ConstParamTyImplementationError<'tcx> {
|
||||||
|
UnsizedConstParamsFeatureRequired,
|
||||||
|
InvalidInnerTyOfBuiltinTy(Vec<(Ty<'tcx>, InfringingFieldsReason<'tcx>)>),
|
||||||
InfrigingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>),
|
InfrigingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>),
|
||||||
NotAnAdtOrBuiltinAllowed,
|
NotAnAdtOrBuiltinAllowed,
|
||||||
}
|
}
|
||||||
|
@ -77,9 +80,9 @@ pub fn type_allowed_to_implement_copy<'tcx>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks that the fields of the type (an ADT) all implement `ConstParamTy`.
|
/// Checks that the fields of the type (an ADT) all implement `(Unsized?)ConstParamTy`.
|
||||||
///
|
///
|
||||||
/// If fields don't implement `ConstParamTy`, return an error containing a list of
|
/// If fields don't implement `(Unsized?)ConstParamTy`, return an error containing a list of
|
||||||
/// those violating fields.
|
/// those violating fields.
|
||||||
///
|
///
|
||||||
/// If it's not an ADT, int ty, `bool` or `char`, returns `Err(NotAnAdtOrBuiltinAllowed)`.
|
/// If it's not an ADT, int ty, `bool` or `char`, returns `Err(NotAnAdtOrBuiltinAllowed)`.
|
||||||
|
@ -87,35 +90,95 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
self_type: Ty<'tcx>,
|
self_type: Ty<'tcx>,
|
||||||
|
lang_item: LangItem,
|
||||||
parent_cause: ObligationCause<'tcx>,
|
parent_cause: ObligationCause<'tcx>,
|
||||||
) -> Result<(), ConstParamTyImplementationError<'tcx>> {
|
) -> Result<(), ConstParamTyImplementationError<'tcx>> {
|
||||||
let (adt, args) = match self_type.kind() {
|
assert!(matches!(lang_item, LangItem::ConstParamTy | LangItem::UnsizedConstParamTy));
|
||||||
// `core` provides these impls.
|
|
||||||
ty::Uint(_)
|
|
||||||
| ty::Int(_)
|
|
||||||
| ty::Bool
|
|
||||||
| ty::Char
|
|
||||||
| ty::Str
|
|
||||||
| ty::Array(..)
|
|
||||||
| ty::Slice(_)
|
|
||||||
| ty::Ref(.., hir::Mutability::Not)
|
|
||||||
| ty::Tuple(_) => return Ok(()),
|
|
||||||
|
|
||||||
&ty::Adt(adt, args) => (adt, args),
|
let inner_tys: Vec<_> = match *self_type.kind() {
|
||||||
|
// Trivially okay as these types are all:
|
||||||
|
// - Sized
|
||||||
|
// - Contain no nested types
|
||||||
|
// - Have structural equality
|
||||||
|
ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Char => return Ok(()),
|
||||||
|
|
||||||
|
// Handle types gated under `feature(unsized_const_params)`
|
||||||
|
// FIXME(unsized_const_params): Make `const N: [u8]` work then forbid references
|
||||||
|
ty::Slice(inner_ty) | ty::Ref(_, inner_ty, Mutability::Not)
|
||||||
|
if lang_item == LangItem::UnsizedConstParamTy =>
|
||||||
|
{
|
||||||
|
vec![inner_ty]
|
||||||
|
}
|
||||||
|
ty::Str if lang_item == LangItem::UnsizedConstParamTy => {
|
||||||
|
vec![Ty::new_slice(tcx, tcx.types.u8)]
|
||||||
|
}
|
||||||
|
ty::Str | ty::Slice(..) | ty::Ref(_, _, Mutability::Not) => {
|
||||||
|
return Err(ConstParamTyImplementationError::UnsizedConstParamsFeatureRequired);
|
||||||
|
}
|
||||||
|
|
||||||
|
ty::Array(inner_ty, _) => vec![inner_ty],
|
||||||
|
|
||||||
|
// `str` morally acts like a newtype around `[u8]`
|
||||||
|
ty::Tuple(inner_tys) => inner_tys.into_iter().collect(),
|
||||||
|
|
||||||
|
ty::Adt(adt, args) if adt.is_enum() || adt.is_struct() => {
|
||||||
|
all_fields_implement_trait(
|
||||||
|
tcx,
|
||||||
|
param_env,
|
||||||
|
self_type,
|
||||||
|
adt,
|
||||||
|
args,
|
||||||
|
parent_cause.clone(),
|
||||||
|
lang_item,
|
||||||
|
)
|
||||||
|
.map_err(ConstParamTyImplementationError::InfrigingFields)?;
|
||||||
|
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
|
||||||
_ => return Err(ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed),
|
_ => return Err(ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed),
|
||||||
};
|
};
|
||||||
|
|
||||||
all_fields_implement_trait(
|
let mut infringing_inner_tys = vec![];
|
||||||
tcx,
|
for inner_ty in inner_tys {
|
||||||
param_env,
|
// We use an ocx per inner ty for better diagnostics
|
||||||
self_type,
|
let infcx = tcx.infer_ctxt().build();
|
||||||
adt,
|
let ocx = traits::ObligationCtxt::new_with_diagnostics(&infcx);
|
||||||
args,
|
|
||||||
parent_cause,
|
ocx.register_bound(
|
||||||
hir::LangItem::ConstParamTy,
|
parent_cause.clone(),
|
||||||
)
|
param_env,
|
||||||
.map_err(ConstParamTyImplementationError::InfrigingFields)?;
|
inner_ty,
|
||||||
|
tcx.require_lang_item(lang_item, Some(parent_cause.span)),
|
||||||
|
);
|
||||||
|
|
||||||
|
let errors = ocx.select_all_or_error();
|
||||||
|
if !errors.is_empty() {
|
||||||
|
infringing_inner_tys.push((inner_ty, InfringingFieldsReason::Fulfill(errors)));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check regions assuming the self type of the impl is WF
|
||||||
|
let outlives_env = OutlivesEnvironment::with_bounds(
|
||||||
|
param_env,
|
||||||
|
infcx.implied_bounds_tys(
|
||||||
|
param_env,
|
||||||
|
parent_cause.body_id,
|
||||||
|
&FxIndexSet::from_iter([self_type]),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
let errors = infcx.resolve_regions(&outlives_env);
|
||||||
|
if !errors.is_empty() {
|
||||||
|
infringing_inner_tys.push((inner_ty, InfringingFieldsReason::Regions(errors)));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !infringing_inner_tys.is_empty() {
|
||||||
|
return Err(ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(
|
||||||
|
infringing_inner_tys,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,6 +248,7 @@
|
||||||
#![feature(transparent_unions)]
|
#![feature(transparent_unions)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
|
#![feature(unsized_const_params)]
|
||||||
#![feature(unsized_fn_params)]
|
#![feature(unsized_fn_params)]
|
||||||
#![feature(with_negative_coherence)]
|
#![feature(with_negative_coherence)]
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
|
|
|
@ -975,31 +975,73 @@ pub trait PointerLike {}
|
||||||
/// that all fields are also `ConstParamTy`, which implies that recursively, all fields
|
/// that all fields are also `ConstParamTy`, which implies that recursively, all fields
|
||||||
/// are `StructuralPartialEq`.
|
/// are `StructuralPartialEq`.
|
||||||
#[lang = "const_param_ty"]
|
#[lang = "const_param_ty"]
|
||||||
#[unstable(feature = "adt_const_params", issue = "95174")]
|
#[unstable(feature = "unsized_const_params", issue = "95174")]
|
||||||
#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
|
#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
|
||||||
#[allow(multiple_supertrait_upcastable)]
|
#[allow(multiple_supertrait_upcastable)]
|
||||||
pub trait ConstParamTy: StructuralPartialEq + Eq {}
|
// We name this differently than the derive macro so that the `adt_const_params` can
|
||||||
|
// be used independently of `unsized_const_params` without requiring a full path
|
||||||
|
// to the derive macro every time it is used. This should be renamed on stabilization.
|
||||||
|
pub trait ConstParamTy_: UnsizedConstParamTy + StructuralPartialEq + Eq {}
|
||||||
|
|
||||||
/// Derive macro generating an impl of the trait `ConstParamTy`.
|
/// Derive macro generating an impl of the trait `ConstParamTy`.
|
||||||
#[rustc_builtin_macro]
|
#[rustc_builtin_macro]
|
||||||
|
#[allow_internal_unstable(unsized_const_params)]
|
||||||
#[unstable(feature = "adt_const_params", issue = "95174")]
|
#[unstable(feature = "adt_const_params", issue = "95174")]
|
||||||
pub macro ConstParamTy($item:item) {
|
pub macro ConstParamTy($item:item) {
|
||||||
/* compiler built-in */
|
/* compiler built-in */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(not(bootstrap), lang = "unsized_const_param_ty")]
|
||||||
|
#[unstable(feature = "unsized_const_params", issue = "95174")]
|
||||||
|
#[diagnostic::on_unimplemented(message = "`{Self}` can't be used as a const parameter type")]
|
||||||
|
/// A marker for types which can be used as types of `const` generic parameters.
|
||||||
|
///
|
||||||
|
/// Equivalent to [`ConstParamTy_`] except that this is used by
|
||||||
|
/// the `unsized_const_params` to allow for fake unstable impls.
|
||||||
|
pub trait UnsizedConstParamTy: StructuralPartialEq + Eq {}
|
||||||
|
|
||||||
|
/// Derive macro generating an impl of the trait `ConstParamTy`.
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
|
#[cfg_attr(not(bootstrap), rustc_builtin_macro)]
|
||||||
|
#[cfg_attr(not(bootstrap), allow_internal_unstable(unsized_const_params))]
|
||||||
|
#[cfg_attr(not(bootstrap), unstable(feature = "unsized_const_params", issue = "95174"))]
|
||||||
|
pub macro UnsizedConstParamTy($item:item) {
|
||||||
|
/* compiler built-in */
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME(adt_const_params): handle `ty::FnDef`/`ty::Closure`
|
// FIXME(adt_const_params): handle `ty::FnDef`/`ty::Closure`
|
||||||
marker_impls! {
|
marker_impls! {
|
||||||
#[unstable(feature = "adt_const_params", issue = "95174")]
|
#[unstable(feature = "adt_const_params", issue = "95174")]
|
||||||
ConstParamTy for
|
ConstParamTy_ for
|
||||||
usize, u8, u16, u32, u64, u128,
|
usize, u8, u16, u32, u64, u128,
|
||||||
isize, i8, i16, i32, i64, i128,
|
isize, i8, i16, i32, i64, i128,
|
||||||
bool,
|
bool,
|
||||||
char,
|
char,
|
||||||
str /* Technically requires `[u8]: ConstParamTy` */,
|
|
||||||
(),
|
(),
|
||||||
{T: ConstParamTy, const N: usize} [T; N],
|
{T: ConstParamTy_, const N: usize} [T; N],
|
||||||
{T: ConstParamTy} [T],
|
}
|
||||||
{T: ?Sized + ConstParamTy} &T,
|
#[cfg(bootstrap)]
|
||||||
|
marker_impls! {
|
||||||
|
#[unstable(feature = "adt_const_params", issue = "95174")]
|
||||||
|
ConstParamTy_ for
|
||||||
|
str,
|
||||||
|
{T: ConstParamTy_} [T],
|
||||||
|
{T: ConstParamTy_ + ?Sized} &T,
|
||||||
|
}
|
||||||
|
|
||||||
|
marker_impls! {
|
||||||
|
#[unstable(feature = "unsized_const_params", issue = "95174")]
|
||||||
|
UnsizedConstParamTy for
|
||||||
|
usize, u8, u16, u32, u64, u128,
|
||||||
|
isize, i8, i16, i32, i64, i128,
|
||||||
|
bool,
|
||||||
|
char,
|
||||||
|
(),
|
||||||
|
{T: UnsizedConstParamTy, const N: usize} [T; N],
|
||||||
|
|
||||||
|
str,
|
||||||
|
{T: UnsizedConstParamTy} [T],
|
||||||
|
{T: UnsizedConstParamTy + ?Sized} &T,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A common trait implemented by all function pointers.
|
/// A common trait implemented by all function pointers.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::marker::ConstParamTy;
|
use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
|
||||||
|
|
||||||
/// Are values of a type transmutable into values of another type?
|
/// Are values of a type transmutable into values of another type?
|
||||||
///
|
///
|
||||||
|
@ -39,7 +39,9 @@ pub struct Assume {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "transmutability", issue = "99571")]
|
#[unstable(feature = "transmutability", issue = "99571")]
|
||||||
impl ConstParamTy for Assume {}
|
impl ConstParamTy_ for Assume {}
|
||||||
|
#[unstable(feature = "transmutability", issue = "99571")]
|
||||||
|
impl UnsizedConstParamTy for Assume {}
|
||||||
|
|
||||||
impl Assume {
|
impl Assume {
|
||||||
/// Do not assume that *you* have ensured any safety properties are met.
|
/// Do not assume that *you* have ensured any safety properties are met.
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// See core/src/primitive_docs.rs for documentation.
|
// See core/src/primitive_docs.rs for documentation.
|
||||||
|
|
||||||
use crate::cmp::Ordering::{self, *};
|
use crate::cmp::Ordering::{self, *};
|
||||||
use crate::marker::ConstParamTy;
|
use crate::marker::ConstParamTy_;
|
||||||
use crate::marker::StructuralPartialEq;
|
use crate::marker::StructuralPartialEq;
|
||||||
|
use crate::marker::UnsizedConstParamTy;
|
||||||
|
|
||||||
// Recursive macro for implementing n-ary tuple functions and operations
|
// Recursive macro for implementing n-ary tuple functions and operations
|
||||||
//
|
//
|
||||||
|
@ -49,8 +50,15 @@ macro_rules! tuple_impls {
|
||||||
|
|
||||||
maybe_tuple_doc! {
|
maybe_tuple_doc! {
|
||||||
$($T)+ @
|
$($T)+ @
|
||||||
#[unstable(feature = "structural_match", issue = "31434")]
|
#[unstable(feature = "adt_const_params", issue = "95174")]
|
||||||
impl<$($T: ConstParamTy),+> ConstParamTy for ($($T,)+)
|
impl<$($T: ConstParamTy_),+> ConstParamTy_ for ($($T,)+)
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
|
||||||
|
maybe_tuple_doc! {
|
||||||
|
$($T)+ @
|
||||||
|
#[unstable(feature = "unsized_const_params", issue = "95174")]
|
||||||
|
impl<$($T: UnsizedConstParamTy),+> UnsizedConstParamTy for ($($T,)+)
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
//@ known-bug: #119299
|
|
||||||
#![feature(adt_const_params)]
|
|
||||||
#![allow(incomplete_features)]
|
|
||||||
|
|
||||||
use std::marker::ConstParamTy;
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq)]
|
|
||||||
struct ConstStrU(*const u8, usize);
|
|
||||||
|
|
||||||
impl ConstParamTy for &'static ConstStrU {}
|
|
||||||
|
|
||||||
impl ConstStrU {
|
|
||||||
const fn from_bytes(bytes: &'static [u8]) -> Self {
|
|
||||||
Self(bytes.as_ptr(), bytes.len())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn chars_s<const S: &'static ConstStrU>() -> [char; 3] {
|
|
||||||
['a','b','c']
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
const A: &'static ConstStrU = &ConstStrU::from_bytes(b"abc");
|
|
||||||
chars_s::<A>();
|
|
||||||
}
|
|
|
@ -3,7 +3,7 @@
|
||||||
//@ compile-flags: -Zmir-enable-passes=+RemoveZsts
|
//@ compile-flags: -Zmir-enable-passes=+RemoveZsts
|
||||||
// Verify that we can pretty print invalid constants.
|
// Verify that we can pretty print invalid constants.
|
||||||
|
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// skip-filecheck
|
// skip-filecheck
|
||||||
// EMIT_MIR_FOR_EACH_BIT_WIDTH
|
// EMIT_MIR_FOR_EACH_BIT_WIDTH
|
||||||
|
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
|
pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![crate_name = "foo"]
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
use std::marker::ConstParamTy;
|
use std::marker::ConstParamTy;
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
|
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
//~^ WARN the feature `adt_const_params` is incomplete
|
//~^ WARN the feature `unsized_const_params` is incomplete
|
||||||
#![feature(with_negative_coherence, negative_impls)]
|
#![feature(with_negative_coherence, negative_impls)]
|
||||||
|
|
||||||
pub trait A<const K: &'static str> {}
|
pub trait A<const K: &'static str> {}
|
||||||
pub trait C {}
|
pub trait C {}
|
||||||
|
|
||||||
|
|
||||||
struct W<T>(T);
|
struct W<T>(T);
|
||||||
|
|
||||||
// Negative coherence:
|
// Negative coherence:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||||
--> $DIR/regions-in-canonical.rs:3:12
|
--> $DIR/regions-in-canonical.rs:3:30
|
||||||
|
|
|
|
||||||
LL | #![feature(adt_const_params)]
|
LL | #![feature(adt_const_params, unsized_const_params)]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
#![feature(adt_const_params, lazy_type_alias)]
|
#![feature(adt_const_params, lazy_type_alias)]
|
||||||
//~^ WARN: the feature `adt_const_params` is incomplete
|
//~^ WARN: the feature `lazy_type_alias` is incomplete
|
||||||
//~| WARN: the feature `lazy_type_alias` is incomplete
|
|
||||||
|
|
||||||
pub type Matrix = [usize; 1];
|
pub type Matrix = [usize; 1];
|
||||||
const EMPTY_MATRIX: Matrix = [0; 1];
|
const EMPTY_MATRIX: Matrix = [0; 1];
|
||||||
|
|
|
@ -1,12 +1,3 @@
|
||||||
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
|
||||||
--> $DIR/alias_const_param_ty-1.rs:2:12
|
|
||||||
|
|
|
||||||
LL | #![feature(adt_const_params, lazy_type_alias)]
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
|
||||||
|
|
||||||
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
|
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||||
--> $DIR/alias_const_param_ty-1.rs:2:30
|
--> $DIR/alias_const_param_ty-1.rs:2:30
|
||||||
|
|
|
|
||||||
|
@ -14,6 +5,7 @@ LL | #![feature(adt_const_params, lazy_type_alias)]
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
|
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
|
||||||
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
||||||
warning: 2 warnings emitted
|
warning: 1 warning emitted
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params)]
|
||||||
//~^ WARN: the feature `adt_const_params` is incomplete
|
|
||||||
|
|
||||||
const EMPTY_MATRIX: <Type as Trait>::Matrix = [0; 1];
|
const EMPTY_MATRIX: <Type as Trait>::Matrix = [0; 1];
|
||||||
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
|
||||||
--> $DIR/alias_const_param_ty-2.rs:2:12
|
|
||||||
|
|
|
||||||
LL | #![feature(adt_const_params)]
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
|
||||||
|
|
||||||
warning: 1 warning emitted
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
|
||||||
|
#[derive(std::marker::UnsizedConstParamTy, Eq, PartialEq)]
|
||||||
|
pub struct Foo([u8]);
|
||||||
|
|
||||||
|
#[derive(std::marker::ConstParamTy, Eq, PartialEq)]
|
||||||
|
pub struct GenericNotUnsizedParam<T>(T);
|
|
@ -1,13 +1,13 @@
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
|
||||||
fn check(_: impl std::marker::ConstParamTy) {}
|
fn check(_: impl std::marker::UnsizedConstParamTy) {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
check(main); //~ error: `fn() {main}` can't be used as a const parameter type
|
check(main); //~ error: `fn() {main}` can't be used as a const parameter type
|
||||||
check(|| {}); //~ error: `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` can't be used as a const parameter type
|
check(|| {}); //~ error: `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` can't be used as a const parameter type
|
||||||
check(main as fn()); //~ error: `fn()` can't be used as a const parameter type
|
check(main as fn()); //~ error: `fn()` can't be used as a const parameter type
|
||||||
check(&mut ()); //~ error: `&mut ()` can't be used as a const parameter type
|
check(&mut ()); //~ error: `&mut ()` can't be used as a const parameter type
|
||||||
check(&mut () as *mut ()); //~ error: `*mut ()` can't be used as a const parameter type
|
check(&mut () as *mut ()); //~ error: `*mut ()` can't be used as a const parameter type
|
||||||
check(&() as *const ()); //~ error: `*const ()` can't be used as a const parameter type
|
check(&() as *const ()); //~ error: `*const ()` can't be used as a const parameter type
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,15 @@ error[E0277]: `fn() {main}` can't be used as a const parameter type
|
||||||
--> $DIR/const_param_ty_bad.rs:7:11
|
--> $DIR/const_param_ty_bad.rs:7:11
|
||||||
|
|
|
|
||||||
LL | check(main);
|
LL | check(main);
|
||||||
| ----- ^^^^ the trait `ConstParamTy` is not implemented for fn item `fn() {main}`
|
| ----- ^^^^ the trait `UnsizedConstParamTy` is not implemented for fn item `fn() {main}`
|
||||||
| |
|
| |
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
note: required by a bound in `check`
|
note: required by a bound in `check`
|
||||||
--> $DIR/const_param_ty_bad.rs:4:18
|
--> $DIR/const_param_ty_bad.rs:4:18
|
||||||
|
|
|
|
||||||
LL | fn check(_: impl std::marker::ConstParamTy) {}
|
LL | fn check(_: impl std::marker::UnsizedConstParamTy) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||||
help: use parentheses to call this function
|
help: use parentheses to call this function
|
||||||
|
|
|
|
||||||
LL | check(main());
|
LL | check(main());
|
||||||
|
@ -20,15 +20,15 @@ error[E0277]: `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` can't be used as
|
||||||
--> $DIR/const_param_ty_bad.rs:8:11
|
--> $DIR/const_param_ty_bad.rs:8:11
|
||||||
|
|
|
|
||||||
LL | check(|| {});
|
LL | check(|| {});
|
||||||
| ----- ^^^^^ the trait `ConstParamTy` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}`
|
| ----- ^^^^^ the trait `UnsizedConstParamTy` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}`
|
||||||
| |
|
| |
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
note: required by a bound in `check`
|
note: required by a bound in `check`
|
||||||
--> $DIR/const_param_ty_bad.rs:4:18
|
--> $DIR/const_param_ty_bad.rs:4:18
|
||||||
|
|
|
|
||||||
LL | fn check(_: impl std::marker::ConstParamTy) {}
|
LL | fn check(_: impl std::marker::UnsizedConstParamTy) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||||
help: use parentheses to call this closure
|
help: use parentheses to call this closure
|
||||||
|
|
|
|
||||||
LL | check(|| {}());
|
LL | check(|| {}());
|
||||||
|
@ -38,15 +38,15 @@ error[E0277]: `fn()` can't be used as a const parameter type
|
||||||
--> $DIR/const_param_ty_bad.rs:9:11
|
--> $DIR/const_param_ty_bad.rs:9:11
|
||||||
|
|
|
|
||||||
LL | check(main as fn());
|
LL | check(main as fn());
|
||||||
| ----- ^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `fn()`
|
| ----- ^^^^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `fn()`
|
||||||
| |
|
| |
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
note: required by a bound in `check`
|
note: required by a bound in `check`
|
||||||
--> $DIR/const_param_ty_bad.rs:4:18
|
--> $DIR/const_param_ty_bad.rs:4:18
|
||||||
|
|
|
|
||||||
LL | fn check(_: impl std::marker::ConstParamTy) {}
|
LL | fn check(_: impl std::marker::UnsizedConstParamTy) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||||
help: use parentheses to call this function pointer
|
help: use parentheses to call this function pointer
|
||||||
|
|
|
|
||||||
LL | check(main as fn()());
|
LL | check(main as fn()());
|
||||||
|
@ -56,16 +56,16 @@ error[E0277]: `&mut ()` can't be used as a const parameter type
|
||||||
--> $DIR/const_param_ty_bad.rs:10:11
|
--> $DIR/const_param_ty_bad.rs:10:11
|
||||||
|
|
|
|
||||||
LL | check(&mut ());
|
LL | check(&mut ());
|
||||||
| ----- ^^^^^^^ the trait `ConstParamTy` is not implemented for `&mut ()`
|
| ----- ^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `&mut ()`
|
||||||
| |
|
| |
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
= note: `ConstParamTy` is implemented for `&()`, but not for `&mut ()`
|
= note: `UnsizedConstParamTy` is implemented for `&()`, but not for `&mut ()`
|
||||||
note: required by a bound in `check`
|
note: required by a bound in `check`
|
||||||
--> $DIR/const_param_ty_bad.rs:4:18
|
--> $DIR/const_param_ty_bad.rs:4:18
|
||||||
|
|
|
|
||||||
LL | fn check(_: impl std::marker::ConstParamTy) {}
|
LL | fn check(_: impl std::marker::UnsizedConstParamTy) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||||
help: consider removing the leading `&`-reference
|
help: consider removing the leading `&`-reference
|
||||||
|
|
|
|
||||||
LL - check(&mut ());
|
LL - check(&mut ());
|
||||||
|
@ -76,31 +76,31 @@ error[E0277]: `*mut ()` can't be used as a const parameter type
|
||||||
--> $DIR/const_param_ty_bad.rs:11:11
|
--> $DIR/const_param_ty_bad.rs:11:11
|
||||||
|
|
|
|
||||||
LL | check(&mut () as *mut ());
|
LL | check(&mut () as *mut ());
|
||||||
| ----- ^^^^^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `*mut ()`
|
| ----- ^^^^^^^^^^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `*mut ()`
|
||||||
| |
|
| |
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
= help: the trait `ConstParamTy` is implemented for `()`
|
= help: the trait `UnsizedConstParamTy` is implemented for `()`
|
||||||
note: required by a bound in `check`
|
note: required by a bound in `check`
|
||||||
--> $DIR/const_param_ty_bad.rs:4:18
|
--> $DIR/const_param_ty_bad.rs:4:18
|
||||||
|
|
|
|
||||||
LL | fn check(_: impl std::marker::ConstParamTy) {}
|
LL | fn check(_: impl std::marker::UnsizedConstParamTy) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||||
|
|
||||||
error[E0277]: `*const ()` can't be used as a const parameter type
|
error[E0277]: `*const ()` can't be used as a const parameter type
|
||||||
--> $DIR/const_param_ty_bad.rs:12:11
|
--> $DIR/const_param_ty_bad.rs:12:11
|
||||||
|
|
|
|
||||||
LL | check(&() as *const ());
|
LL | check(&() as *const ());
|
||||||
| ----- ^^^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `*const ()`
|
| ----- ^^^^^^^^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `*const ()`
|
||||||
| |
|
| |
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
= help: the trait `ConstParamTy` is implemented for `()`
|
= help: the trait `UnsizedConstParamTy` is implemented for `()`
|
||||||
note: required by a bound in `check`
|
note: required by a bound in `check`
|
||||||
--> $DIR/const_param_ty_bad.rs:4:18
|
--> $DIR/const_param_ty_bad.rs:4:18
|
||||||
|
|
|
|
||||||
LL | fn check(_: impl std::marker::ConstParamTy) {}
|
LL | fn check(_: impl std::marker::UnsizedConstParamTy) {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
struct NotParam;
|
struct NotParam;
|
||||||
|
|
||||||
fn check<T: std::marker::ConstParamTy>() {}
|
fn check<T: std::marker::ConstParamTy_>() {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
check::<[NotParam; 0]>();
|
check::<[NotParam; 0]>();
|
||||||
|
|
|
@ -2,14 +2,14 @@ error[E0277]: `NotParam` can't be used as a const parameter type
|
||||||
--> $DIR/const_param_ty_bad_empty_array.rs:10:13
|
--> $DIR/const_param_ty_bad_empty_array.rs:10:13
|
||||||
|
|
|
|
||||||
LL | check::<[NotParam; 0]>();
|
LL | check::<[NotParam; 0]>();
|
||||||
| ^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`, which is required by `[NotParam; 0]: ConstParamTy`
|
| ^^^^^^^^^^^^^ the trait `ConstParamTy_` is not implemented for `NotParam`, which is required by `[NotParam; 0]: ConstParamTy_`
|
||||||
|
|
|
|
||||||
= note: required for `[NotParam; 0]` to implement `ConstParamTy`
|
= note: required for `[NotParam; 0]` to implement `ConstParamTy_`
|
||||||
note: required by a bound in `check`
|
note: required by a bound in `check`
|
||||||
--> $DIR/const_param_ty_bad_empty_array.rs:7:13
|
--> $DIR/const_param_ty_bad_empty_array.rs:7:13
|
||||||
|
|
|
|
||||||
LL | fn check<T: std::marker::ConstParamTy>() {}
|
LL | fn check<T: std::marker::ConstParamTy_>() {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
struct NotParam;
|
struct NotParam;
|
||||||
|
|
||||||
fn check<T: std::marker::ConstParamTy + ?Sized>() {}
|
fn check<T: std::marker::UnsizedConstParamTy + ?Sized>() {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
check::<&NotParam>(); //~ error: `NotParam` can't be used as a const parameter type
|
check::<&NotParam>(); //~ error: `NotParam` can't be used as a const parameter type
|
||||||
check::<[NotParam]>(); //~ error: `NotParam` can't be used as a const parameter type
|
check::<[NotParam]>(); //~ error: `NotParam` can't be used as a const parameter type
|
||||||
check::<[NotParam; 17]>(); //~ error: `NotParam` can't be used as a const parameter type
|
check::<[NotParam; 17]>(); //~ error: `NotParam` can't be used as a const parameter type
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,40 +2,40 @@ error[E0277]: `NotParam` can't be used as a const parameter type
|
||||||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:10:13
|
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:10:13
|
||||||
|
|
|
|
||||||
LL | check::<&NotParam>();
|
LL | check::<&NotParam>();
|
||||||
| ^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`, which is required by `&NotParam: ConstParamTy`
|
| ^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `NotParam`, which is required by `&NotParam: UnsizedConstParamTy`
|
||||||
|
|
|
|
||||||
= note: required for `&NotParam` to implement `ConstParamTy`
|
= note: required for `&NotParam` to implement `UnsizedConstParamTy`
|
||||||
note: required by a bound in `check`
|
note: required by a bound in `check`
|
||||||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
|
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
|
||||||
|
|
|
|
||||||
LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {}
|
LL | fn check<T: std::marker::UnsizedConstParamTy + ?Sized>() {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||||
|
|
||||||
error[E0277]: `NotParam` can't be used as a const parameter type
|
error[E0277]: `NotParam` can't be used as a const parameter type
|
||||||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:11:13
|
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:11:13
|
||||||
|
|
|
|
||||||
LL | check::<[NotParam]>();
|
LL | check::<[NotParam]>();
|
||||||
| ^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`, which is required by `[NotParam]: ConstParamTy`
|
| ^^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `NotParam`, which is required by `[NotParam]: UnsizedConstParamTy`
|
||||||
|
|
|
|
||||||
= note: required for `[NotParam]` to implement `ConstParamTy`
|
= note: required for `[NotParam]` to implement `UnsizedConstParamTy`
|
||||||
note: required by a bound in `check`
|
note: required by a bound in `check`
|
||||||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
|
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
|
||||||
|
|
|
|
||||||
LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {}
|
LL | fn check<T: std::marker::UnsizedConstParamTy + ?Sized>() {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||||
|
|
||||||
error[E0277]: `NotParam` can't be used as a const parameter type
|
error[E0277]: `NotParam` can't be used as a const parameter type
|
||||||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:12:13
|
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:12:13
|
||||||
|
|
|
|
||||||
LL | check::<[NotParam; 17]>();
|
LL | check::<[NotParam; 17]>();
|
||||||
| ^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`, which is required by `[NotParam; 17]: ConstParamTy`
|
| ^^^^^^^^^^^^^^ the trait `UnsizedConstParamTy` is not implemented for `NotParam`, which is required by `[NotParam; 17]: UnsizedConstParamTy`
|
||||||
|
|
|
|
||||||
= note: required for `[NotParam; 17]` to implement `ConstParamTy`
|
= note: required for `[NotParam; 17]` to implement `UnsizedConstParamTy`
|
||||||
note: required by a bound in `check`
|
note: required by a bound in `check`
|
||||||
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
|
--> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
|
||||||
|
|
|
|
||||||
LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {}
|
LL | fn check<T: std::marker::UnsizedConstParamTy + ?Sized>() {}
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
|
|
||||||
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(adt_const_params)]
|
|
||||||
use std::marker::ConstParamTy;
|
use std::marker::UnsizedConstParamTy;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
struct S<T> {
|
struct S<T> {
|
||||||
|
@ -9,16 +11,15 @@ struct S<T> {
|
||||||
gen: T,
|
gen: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ConstParamTy> ConstParamTy for S<T> {}
|
impl<T: UnsizedConstParamTy> UnsizedConstParamTy for S<T> {}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, ConstParamTy)]
|
#[derive(PartialEq, Eq, UnsizedConstParamTy)]
|
||||||
struct D<T> {
|
struct D<T> {
|
||||||
field: u8,
|
field: u8,
|
||||||
gen: T,
|
gen: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check<T: UnsizedConstParamTy + ?Sized>() {}
|
||||||
fn check<T: ConstParamTy + ?Sized>() {}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
check::<u8>();
|
check::<u8>();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
struct NotParam;
|
struct NotParam;
|
||||||
|
@ -7,11 +7,11 @@ struct NotParam;
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
struct CantParam(NotParam);
|
struct CantParam(NotParam);
|
||||||
|
|
||||||
impl std::marker::ConstParamTy for CantParam {}
|
impl std::marker::UnsizedConstParamTy for CantParam {}
|
||||||
//~^ error: the trait `ConstParamTy` cannot be implemented for this type
|
//~^ error: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
|
||||||
#[derive(std::marker::ConstParamTy, Eq, PartialEq)]
|
#[derive(std::marker::UnsizedConstParamTy, Eq, PartialEq)]
|
||||||
//~^ error: the trait `ConstParamTy` cannot be implemented for this type
|
//~^ error: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
struct CantParamDerive(NotParam);
|
struct CantParamDerive(NotParam);
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
error[E0204]: the trait `ConstParamTy` cannot be implemented for this type
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
--> $DIR/const_param_ty_impl_bad_field.rs:10:36
|
--> $DIR/const_param_ty_impl_bad_field.rs:10:43
|
||||||
|
|
|
|
||||||
LL | struct CantParam(NotParam);
|
LL | struct CantParam(NotParam);
|
||||||
| -------- this field does not implement `ConstParamTy`
|
| -------- this field does not implement `ConstParamTy_`
|
||||||
LL |
|
LL |
|
||||||
LL | impl std::marker::ConstParamTy for CantParam {}
|
LL | impl std::marker::UnsizedConstParamTy for CantParam {}
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error[E0204]: the trait `ConstParamTy` cannot be implemented for this type
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
--> $DIR/const_param_ty_impl_bad_field.rs:13:10
|
--> $DIR/const_param_ty_impl_bad_field.rs:13:10
|
||||||
|
|
|
|
||||||
LL | #[derive(std::marker::ConstParamTy, Eq, PartialEq)]
|
LL | #[derive(std::marker::UnsizedConstParamTy, Eq, PartialEq)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
LL |
|
LL |
|
||||||
LL | struct CantParamDerive(NotParam);
|
LL | struct CantParamDerive(NotParam);
|
||||||
| -------- this field does not implement `ConstParamTy`
|
| -------- this field does not implement `ConstParamTy_`
|
||||||
|
|
|
|
||||||
= note: this error originates in the derive macro `std::marker::ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `std::marker::UnsizedConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
struct ImplementsConstParamTy;
|
struct ImplementsConstParamTy;
|
||||||
impl std::marker::ConstParamTy for ImplementsConstParamTy {}
|
impl std::marker::UnsizedConstParamTy for ImplementsConstParamTy {}
|
||||||
|
|
||||||
struct CantParam(ImplementsConstParamTy);
|
struct CantParam(ImplementsConstParamTy);
|
||||||
|
|
||||||
impl std::marker::ConstParamTy for CantParam {}
|
impl std::marker::UnsizedConstParamTy for CantParam {}
|
||||||
//~^ error: the type `CantParam` does not `#[derive(PartialEq)]`
|
//~^ error: the type `CantParam` does not `#[derive(PartialEq)]`
|
||||||
//~| the trait bound `CantParam: Eq` is not satisfied
|
//~| the trait bound `CantParam: Eq` is not satisfied
|
||||||
|
|
||||||
#[derive(std::marker::ConstParamTy)]
|
#[derive(std::marker::UnsizedConstParamTy)]
|
||||||
//~^ error: the type `CantParamDerive` does not `#[derive(PartialEq)]`
|
//~^ error: the type `CantParamDerive` does not `#[derive(PartialEq)]`
|
||||||
//~| the trait bound `CantParamDerive: Eq` is not satisfied
|
//~| the trait bound `CantParamDerive: Eq` is not satisfied
|
||||||
struct CantParamDerive(ImplementsConstParamTy);
|
struct CantParamDerive(ImplementsConstParamTy);
|
||||||
|
|
||||||
fn check<T: std::marker::ConstParamTy>() {}
|
fn check<T: std::marker::UnsizedConstParamTy>() {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
check::<ImplementsConstParamTy>();
|
check::<ImplementsConstParamTy>();
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
error[E0277]: the trait bound `CantParam: Eq` is not satisfied
|
error[E0277]: the trait bound `CantParam: Eq` is not satisfied
|
||||||
--> $DIR/const_param_ty_impl_no_structural_eq.rs:10:36
|
--> $DIR/const_param_ty_impl_no_structural_eq.rs:10:43
|
||||||
|
|
|
|
||||||
LL | impl std::marker::ConstParamTy for CantParam {}
|
LL | impl std::marker::UnsizedConstParamTy for CantParam {}
|
||||||
| ^^^^^^^^^ the trait `Eq` is not implemented for `CantParam`
|
| ^^^^^^^^^ the trait `Eq` is not implemented for `CantParam`
|
||||||
|
|
|
|
||||||
note: required by a bound in `ConstParamTy`
|
note: required by a bound in `UnsizedConstParamTy`
|
||||||
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
||||||
help: consider annotating `CantParam` with `#[derive(Eq)]`
|
help: consider annotating `CantParam` with `#[derive(Eq)]`
|
||||||
|
|
|
|
||||||
|
@ -13,23 +13,23 @@ LL | struct CantParam(ImplementsConstParamTy);
|
||||||
|
|
|
|
||||||
|
|
||||||
error[E0277]: the type `CantParam` does not `#[derive(PartialEq)]`
|
error[E0277]: the type `CantParam` does not `#[derive(PartialEq)]`
|
||||||
--> $DIR/const_param_ty_impl_no_structural_eq.rs:10:36
|
--> $DIR/const_param_ty_impl_no_structural_eq.rs:10:43
|
||||||
|
|
|
|
||||||
LL | impl std::marker::ConstParamTy for CantParam {}
|
LL | impl std::marker::UnsizedConstParamTy for CantParam {}
|
||||||
| ^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `CantParam`
|
| ^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `CantParam`
|
||||||
|
|
|
|
||||||
note: required by a bound in `ConstParamTy`
|
note: required by a bound in `UnsizedConstParamTy`
|
||||||
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
||||||
|
|
||||||
error[E0277]: the trait bound `CantParamDerive: Eq` is not satisfied
|
error[E0277]: the trait bound `CantParamDerive: Eq` is not satisfied
|
||||||
--> $DIR/const_param_ty_impl_no_structural_eq.rs:14:10
|
--> $DIR/const_param_ty_impl_no_structural_eq.rs:14:10
|
||||||
|
|
|
|
||||||
LL | #[derive(std::marker::ConstParamTy)]
|
LL | #[derive(std::marker::UnsizedConstParamTy)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq` is not implemented for `CantParamDerive`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq` is not implemented for `CantParamDerive`
|
||||||
|
|
|
|
||||||
note: required by a bound in `ConstParamTy`
|
note: required by a bound in `UnsizedConstParamTy`
|
||||||
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
||||||
= note: this error originates in the derive macro `std::marker::ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `std::marker::UnsizedConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
help: consider annotating `CantParamDerive` with `#[derive(Eq)]`
|
help: consider annotating `CantParamDerive` with `#[derive(Eq)]`
|
||||||
|
|
|
|
||||||
LL + #[derive(Eq)]
|
LL + #[derive(Eq)]
|
||||||
|
@ -39,12 +39,12 @@ LL | struct CantParamDerive(ImplementsConstParamTy);
|
||||||
error[E0277]: the type `CantParamDerive` does not `#[derive(PartialEq)]`
|
error[E0277]: the type `CantParamDerive` does not `#[derive(PartialEq)]`
|
||||||
--> $DIR/const_param_ty_impl_no_structural_eq.rs:14:10
|
--> $DIR/const_param_ty_impl_no_structural_eq.rs:14:10
|
||||||
|
|
|
|
||||||
LL | #[derive(std::marker::ConstParamTy)]
|
LL | #[derive(std::marker::UnsizedConstParamTy)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `CantParamDerive`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `CantParamDerive`
|
||||||
|
|
|
|
||||||
note: required by a bound in `ConstParamTy`
|
note: required by a bound in `UnsizedConstParamTy`
|
||||||
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
||||||
= note: this error originates in the derive macro `std::marker::ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `std::marker::UnsizedConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
|
||||||
union Union {
|
union Union {
|
||||||
a: u8,
|
a: u8,
|
||||||
|
@ -12,10 +12,10 @@ impl PartialEq for Union {
|
||||||
}
|
}
|
||||||
impl Eq for Union {}
|
impl Eq for Union {}
|
||||||
|
|
||||||
impl std::marker::ConstParamTy for Union {}
|
impl std::marker::UnsizedConstParamTy for Union {}
|
||||||
//~^ ERROR the type `Union` does not `#[derive(PartialEq)]`
|
//~^ ERROR the trait `ConstParamTy` may not be implemented for this type
|
||||||
|
|
||||||
#[derive(std::marker::ConstParamTy)]
|
#[derive(std::marker::UnsizedConstParamTy)]
|
||||||
//~^ ERROR this trait cannot be derived for unions
|
//~^ ERROR this trait cannot be derived for unions
|
||||||
union UnionDerive {
|
union UnionDerive {
|
||||||
a: u8,
|
a: u8,
|
||||||
|
@ -28,5 +28,4 @@ impl PartialEq for UnionDerive {
|
||||||
}
|
}
|
||||||
impl Eq for UnionDerive {}
|
impl Eq for UnionDerive {}
|
||||||
|
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
error: this trait cannot be derived for unions
|
error: this trait cannot be derived for unions
|
||||||
--> $DIR/const_param_ty_impl_union.rs:18:10
|
--> $DIR/const_param_ty_impl_union.rs:18:10
|
||||||
|
|
|
|
||||||
LL | #[derive(std::marker::ConstParamTy)]
|
LL | #[derive(std::marker::UnsizedConstParamTy)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0277]: the type `Union` does not `#[derive(PartialEq)]`
|
error: the trait `ConstParamTy` may not be implemented for this type
|
||||||
--> $DIR/const_param_ty_impl_union.rs:15:36
|
--> $DIR/const_param_ty_impl_union.rs:15:43
|
||||||
|
|
|
|
||||||
LL | impl std::marker::ConstParamTy for Union {}
|
LL | impl std::marker::UnsizedConstParamTy for Union {}
|
||||||
| ^^^^^ the trait `StructuralPartialEq` is not implemented for `Union`
|
| ^^^^^ type is not a structure or enumeration
|
||||||
|
|
|
||||||
note: required by a bound in `ConstParamTy`
|
|
||||||
--> $SRC_DIR/core/src/marker.rs:LL:COL
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0277`.
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
use std::marker::{ConstParamTy_, UnsizedConstParamTy};
|
||||||
|
|
||||||
|
fn foo(a: &dyn ConstParamTy_) {}
|
||||||
|
//~^ ERROR: the trait `ConstParamTy_`
|
||||||
|
|
||||||
|
fn bar(a: &dyn UnsizedConstParamTy) {}
|
||||||
|
//~^ ERROR: the trait `UnsizedConstParamTy`
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,33 @@
|
||||||
|
error[E0038]: the trait `ConstParamTy_` cannot be made into an object
|
||||||
|
--> $DIR/const_param_ty_object_safety.rs:6:12
|
||||||
|
|
|
||||||
|
LL | fn foo(a: &dyn ConstParamTy_) {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^ `ConstParamTy_` cannot be made into an object
|
||||||
|
|
|
||||||
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||||
|
--> $SRC_DIR/core/src/cmp.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the trait cannot be made into an object because it uses `Self` as a type parameter
|
||||||
|
help: consider using an opaque type instead
|
||||||
|
|
|
||||||
|
LL | fn foo(a: &impl ConstParamTy_) {}
|
||||||
|
| ~~~~
|
||||||
|
|
||||||
|
error[E0038]: the trait `UnsizedConstParamTy` cannot be made into an object
|
||||||
|
--> $DIR/const_param_ty_object_safety.rs:9:12
|
||||||
|
|
|
||||||
|
LL | fn bar(a: &dyn UnsizedConstParamTy) {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^ `UnsizedConstParamTy` cannot be made into an object
|
||||||
|
|
|
||||||
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||||
|
--> $SRC_DIR/core/src/cmp.rs:LL:COL
|
||||||
|
|
|
||||||
|
= note: the trait cannot be made into an object because it uses `Self` as a type parameter
|
||||||
|
help: consider using an opaque type instead
|
||||||
|
|
|
||||||
|
LL | fn bar(a: &impl UnsizedConstParamTy) {}
|
||||||
|
| ~~~~
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0038`.
|
|
@ -1,18 +1,30 @@
|
||||||
// issue: rust-lang/rust/#83993
|
// issue: rust-lang/rust/#83993
|
||||||
|
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params)]
|
||||||
//~^ WARN the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
|
||||||
fn bug<'a>()
|
fn bug<'a>()
|
||||||
where
|
where
|
||||||
for<'b> [(); {
|
for<'b> [(); {
|
||||||
let x: &'b ();
|
let x: &'b ();
|
||||||
//~^ ERROR generic parameters may not be used in const operations
|
//~^ ERROR generic parameters may not be used in const operations
|
||||||
0
|
0
|
||||||
}]:
|
}]:,
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
fn bad() where for<'b> [();{let _:&'b (); 0}]: Sized { }
|
fn bad()
|
||||||
//~^ ERROR generic parameters may not be used in const operations
|
where
|
||||||
fn good() where for<'b> [();{0}]: Sized { }
|
for<'b> [(); {
|
||||||
|
let _: &'b ();
|
||||||
|
//~^ ERROR generic parameters may not be used in const operations
|
||||||
|
0
|
||||||
|
}]: Sized,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
fn good()
|
||||||
|
where
|
||||||
|
for<'b> [(); { 0 }]: Sized,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
pub fn main() {}
|
pub fn main() {}
|
||||||
|
|
|
@ -8,22 +8,13 @@ LL | let x: &'b ();
|
||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/index-oob-ice-83993.rs:14:36
|
--> $DIR/index-oob-ice-83993.rs:18:17
|
||||||
|
|
|
|
||||||
LL | fn bad() where for<'b> [();{let _:&'b (); 0}]: Sized { }
|
LL | let _: &'b ();
|
||||||
| ^^ cannot perform const operation using `'b`
|
| ^^ cannot perform const operation using `'b`
|
||||||
|
|
|
|
||||||
= note: lifetime parameters may not be used in const expressions
|
= note: lifetime parameters may not be used in const expressions
|
||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
error: aborting due to 2 previous errors
|
||||||
--> $DIR/index-oob-ice-83993.rs:3:12
|
|
||||||
|
|
|
||||||
LL | #![feature(adt_const_params)]
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors; 1 warning emitted
|
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,18 @@
|
||||||
use std::marker::ConstParamTy;
|
use std::marker::ConstParamTy;
|
||||||
|
|
||||||
#[derive(ConstParamTy)]
|
#[derive(ConstParamTy)]
|
||||||
//~^ the trait `ConstParamTy` cannot be implemented for this ty
|
//~^ the trait `ConstParamTy_` cannot be implemented for this ty
|
||||||
|
//~| the trait `ConstParamTy_` cannot be implemented for this ty
|
||||||
struct Foo([*const u8; 1]);
|
struct Foo([*const u8; 1]);
|
||||||
|
|
||||||
#[derive(ConstParamTy)]
|
#[derive(ConstParamTy)]
|
||||||
//~^ the trait `ConstParamTy` cannot be implemented for this ty
|
//~^ the trait `ConstParamTy_` cannot be implemented for this ty
|
||||||
|
//~| the trait `ConstParamTy_` cannot be implemented for this ty
|
||||||
struct Foo2([*mut u8; 1]);
|
struct Foo2([*mut u8; 1]);
|
||||||
|
|
||||||
#[derive(ConstParamTy)]
|
#[derive(ConstParamTy)]
|
||||||
//~^ the trait `ConstParamTy` cannot be implemented for this ty
|
//~^ the trait `ConstParamTy_` cannot be implemented for this ty
|
||||||
|
//~| the trait `ConstParamTy_` cannot be implemented for this ty
|
||||||
struct Foo3([fn(); 1]);
|
struct Foo3([fn(); 1]);
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,51 +1,99 @@
|
||||||
error[E0204]: the trait `ConstParamTy` cannot be implemented for this type
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
--> $DIR/nested_bad_const_param_ty.rs:6:10
|
--> $DIR/nested_bad_const_param_ty.rs:6:10
|
||||||
|
|
|
|
||||||
LL | #[derive(ConstParamTy)]
|
LL | #[derive(ConstParamTy)]
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
LL |
|
...
|
||||||
LL | struct Foo([*const u8; 1]);
|
LL | struct Foo([*const u8; 1]);
|
||||||
| -------------- this field does not implement `ConstParamTy`
|
| -------------- this field does not implement `ConstParamTy_`
|
||||||
|
|
|
|
||||||
note: the `ConstParamTy` impl for `[*const u8; 1]` requires that `*const u8: ConstParamTy`
|
note: the `ConstParamTy_` impl for `[*const u8; 1]` requires that `*const u8: ConstParamTy_`
|
||||||
--> $DIR/nested_bad_const_param_ty.rs:8:12
|
--> $DIR/nested_bad_const_param_ty.rs:9:12
|
||||||
|
|
|
|
||||||
LL | struct Foo([*const u8; 1]);
|
LL | struct Foo([*const u8; 1]);
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0204]: the trait `ConstParamTy` cannot be implemented for this type
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
--> $DIR/nested_bad_const_param_ty.rs:10:10
|
--> $DIR/nested_bad_const_param_ty.rs:11:10
|
||||||
|
|
|
|
||||||
LL | #[derive(ConstParamTy)]
|
LL | #[derive(ConstParamTy)]
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
LL |
|
...
|
||||||
LL | struct Foo2([*mut u8; 1]);
|
LL | struct Foo2([*mut u8; 1]);
|
||||||
| ------------ this field does not implement `ConstParamTy`
|
| ------------ this field does not implement `ConstParamTy_`
|
||||||
|
|
|
|
||||||
note: the `ConstParamTy` impl for `[*mut u8; 1]` requires that `*mut u8: ConstParamTy`
|
note: the `ConstParamTy_` impl for `[*mut u8; 1]` requires that `*mut u8: ConstParamTy_`
|
||||||
--> $DIR/nested_bad_const_param_ty.rs:12:13
|
--> $DIR/nested_bad_const_param_ty.rs:14:13
|
||||||
|
|
|
|
||||||
LL | struct Foo2([*mut u8; 1]);
|
LL | struct Foo2([*mut u8; 1]);
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0204]: the trait `ConstParamTy` cannot be implemented for this type
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
--> $DIR/nested_bad_const_param_ty.rs:14:10
|
--> $DIR/nested_bad_const_param_ty.rs:16:10
|
||||||
|
|
|
|
||||||
LL | #[derive(ConstParamTy)]
|
LL | #[derive(ConstParamTy)]
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
LL |
|
...
|
||||||
LL | struct Foo3([fn(); 1]);
|
LL | struct Foo3([fn(); 1]);
|
||||||
| --------- this field does not implement `ConstParamTy`
|
| --------- this field does not implement `ConstParamTy_`
|
||||||
|
|
|
|
||||||
note: the `ConstParamTy` impl for `[fn(); 1]` requires that `fn(): ConstParamTy`
|
note: the `ConstParamTy_` impl for `[fn(); 1]` requires that `fn(): ConstParamTy_`
|
||||||
--> $DIR/nested_bad_const_param_ty.rs:16:13
|
--> $DIR/nested_bad_const_param_ty.rs:19:13
|
||||||
|
|
|
|
||||||
LL | struct Foo3([fn(); 1]);
|
LL | struct Foo3([fn(); 1]);
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
--> $DIR/nested_bad_const_param_ty.rs:6:10
|
||||||
|
|
|
||||||
|
LL | #[derive(ConstParamTy)]
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
...
|
||||||
|
LL | struct Foo([*const u8; 1]);
|
||||||
|
| -------------- this field does not implement `ConstParamTy_`
|
||||||
|
|
|
||||||
|
note: the `ConstParamTy_` impl for `[*const u8; 1]` requires that `*const u8: UnsizedConstParamTy`
|
||||||
|
--> $DIR/nested_bad_const_param_ty.rs:9:12
|
||||||
|
|
|
||||||
|
LL | struct Foo([*const u8; 1]);
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
--> $DIR/nested_bad_const_param_ty.rs:11:10
|
||||||
|
|
|
||||||
|
LL | #[derive(ConstParamTy)]
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
...
|
||||||
|
LL | struct Foo2([*mut u8; 1]);
|
||||||
|
| ------------ this field does not implement `ConstParamTy_`
|
||||||
|
|
|
||||||
|
note: the `ConstParamTy_` impl for `[*mut u8; 1]` requires that `*mut u8: UnsizedConstParamTy`
|
||||||
|
--> $DIR/nested_bad_const_param_ty.rs:14:13
|
||||||
|
|
|
||||||
|
LL | struct Foo2([*mut u8; 1]);
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
--> $DIR/nested_bad_const_param_ty.rs:16:10
|
||||||
|
|
|
||||||
|
LL | #[derive(ConstParamTy)]
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
...
|
||||||
|
LL | struct Foo3([fn(); 1]);
|
||||||
|
| --------- this field does not implement `ConstParamTy_`
|
||||||
|
|
|
||||||
|
note: the `ConstParamTy_` impl for `[fn(); 1]` requires that `fn(): UnsizedConstParamTy`
|
||||||
|
--> $DIR/nested_bad_const_param_ty.rs:19:13
|
||||||
|
|
|
||||||
|
LL | struct Foo3([fn(); 1]);
|
||||||
|
| ^^^^^^^^^
|
||||||
|
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0204`.
|
For more information about this error, try `rustc --explain E0204`.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// issues rust-lang/rust#111911
|
// issues rust-lang/rust#111911
|
||||||
// test for ICE opaque type with non-universal region substs
|
// test for ICE opaque type with non-universal region substs
|
||||||
|
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
pub async fn foo<const X: &'static str>() {}
|
pub async fn foo<const X: &'static str>() {}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
use std::marker::UnsizedConstParamTy;
|
||||||
|
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
impl UnsizedConstParamTy for &'static Foo {}
|
||||||
|
//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,9 @@
|
||||||
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
--> $DIR/reference_pointee_is_const_param-1.rs:8:30
|
||||||
|
|
|
||||||
|
LL | impl UnsizedConstParamTy for &'static Foo {}
|
||||||
|
| ^^^^^^^^^^^^ this field does not implement `ConstParamTy_`
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0204`.
|
|
@ -0,0 +1,27 @@
|
||||||
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
// Regression test for #119299
|
||||||
|
|
||||||
|
use std::marker::UnsizedConstParamTy;
|
||||||
|
|
||||||
|
#[derive(Eq, PartialEq)]
|
||||||
|
struct ConstStrU(*const u8, usize);
|
||||||
|
|
||||||
|
impl UnsizedConstParamTy for &'static ConstStrU {}
|
||||||
|
//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
|
||||||
|
impl ConstStrU {
|
||||||
|
const fn from_bytes(bytes: &'static [u8]) -> Self {
|
||||||
|
Self(bytes.as_ptr(), bytes.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn chars_s<const S: &'static ConstStrU>() -> [char; 3] {
|
||||||
|
['a', 'b', 'c']
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
const A: &'static ConstStrU = &ConstStrU::from_bytes(b"abc");
|
||||||
|
chars_s::<A>();
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
--> $DIR/reference_pointee_is_const_param-2.rs:11:30
|
||||||
|
|
|
||||||
|
LL | impl UnsizedConstParamTy for &'static ConstStrU {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^ this field does not implement `ConstParamTy_`
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0204`.
|
|
@ -8,9 +8,8 @@ fn uwu_0<const N: &'static mut ()>() {}
|
||||||
//~| HELP: add `#![feature(adt_const_params)]`
|
//~| HELP: add `#![feature(adt_const_params)]`
|
||||||
//~| HELP: add `#![feature(adt_const_params)]`
|
//~| HELP: add `#![feature(adt_const_params)]`
|
||||||
//~| HELP: add `#![feature(adt_const_params)]`
|
//~| HELP: add `#![feature(adt_const_params)]`
|
||||||
//~| HELP: add `#![feature(adt_const_params)]`
|
//~| HELP: add `#![feature(unsized_const_params)]`
|
||||||
//~| HELP: add `#![feature(adt_const_params)]`
|
//~| HELP: add `#![feature(unsized_const_params)]`
|
||||||
//~| HELP: add `#![feature(adt_const_params)]`
|
|
||||||
|
|
||||||
// Needs the feature but can be used, so suggest adding the feature.
|
// Needs the feature but can be used, so suggest adding the feature.
|
||||||
fn owo_0<const N: &'static u32>() {}
|
fn owo_0<const N: &'static u32>() {}
|
||||||
|
|
|
@ -7,7 +7,7 @@ LL | fn uwu_0<const N: &'static mut ()>() {}
|
||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
|
|
||||||
error: `&'static u32` is forbidden as the type of a const generic parameter
|
error: `&'static u32` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/suggest_feature_only_when_possible.rs:16:19
|
--> $DIR/suggest_feature_only_when_possible.rs:15:19
|
||||||
|
|
|
|
||||||
LL | fn owo_0<const N: &'static u32>() {}
|
LL | fn owo_0<const N: &'static u32>() {}
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
@ -17,9 +17,13 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: `Meow` is forbidden as the type of a const generic parameter
|
error: `Meow` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/suggest_feature_only_when_possible.rs:24:20
|
--> $DIR/suggest_feature_only_when_possible.rs:23:20
|
||||||
|
|
|
|
||||||
LL | fn meow_0<const N: Meow>() {}
|
LL | fn meow_0<const N: Meow>() {}
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
@ -31,7 +35,7 @@ LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
|
||||||
error: `&'static Meow` is forbidden as the type of a const generic parameter
|
error: `&'static Meow` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/suggest_feature_only_when_possible.rs:26:20
|
--> $DIR/suggest_feature_only_when_possible.rs:25:20
|
||||||
|
|
|
|
||||||
LL | fn meow_1<const N: &'static Meow>() {}
|
LL | fn meow_1<const N: &'static Meow>() {}
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
@ -41,45 +45,37 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: `[Meow; 100]` is forbidden as the type of a const generic parameter
|
error: `[Meow; 100]` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/suggest_feature_only_when_possible.rs:28:20
|
--> $DIR/suggest_feature_only_when_possible.rs:27:20
|
||||||
|
|
|
|
||||||
LL | fn meow_2<const N: [Meow; 100]>() {}
|
LL | fn meow_2<const N: [Meow; 100]>() {}
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
|
||||||
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error: `(Meow, u8)` is forbidden as the type of a const generic parameter
|
error: `(Meow, u8)` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/suggest_feature_only_when_possible.rs:30:20
|
--> $DIR/suggest_feature_only_when_possible.rs:29:20
|
||||||
|
|
|
|
||||||
LL | fn meow_3<const N: (Meow, u8)>() {}
|
LL | fn meow_3<const N: (Meow, u8)>() {}
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
|
||||||
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error: `(Meow, String)` is forbidden as the type of a const generic parameter
|
error: `(Meow, String)` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/suggest_feature_only_when_possible.rs:35:20
|
--> $DIR/suggest_feature_only_when_possible.rs:34:20
|
||||||
|
|
|
|
||||||
LL | fn meow_4<const N: (Meow, String)>() {}
|
LL | fn meow_4<const N: (Meow, String)>() {}
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
|
||||||
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
|
||||||
|
|
|
||||||
|
|
||||||
error: `String` is forbidden as the type of a const generic parameter
|
error: `String` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/suggest_feature_only_when_possible.rs:39:19
|
--> $DIR/suggest_feature_only_when_possible.rs:38:19
|
||||||
|
|
|
|
||||||
LL | fn nya_0<const N: String>() {}
|
LL | fn nya_0<const N: String>() {}
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
@ -87,7 +83,7 @@ LL | fn nya_0<const N: String>() {}
|
||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
|
|
||||||
error: `Vec<u32>` is forbidden as the type of a const generic parameter
|
error: `Vec<u32>` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/suggest_feature_only_when_possible.rs:41:19
|
--> $DIR/suggest_feature_only_when_possible.rs:40:19
|
||||||
|
|
|
|
||||||
LL | fn nya_1<const N: Vec<u32>>() {}
|
LL | fn nya_1<const N: Vec<u32>>() {}
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
use std::marker::UnsizedConstParamTy;
|
||||||
|
|
||||||
|
trait Trait {}
|
||||||
|
|
||||||
|
impl UnsizedConstParamTy for dyn Trait {}
|
||||||
|
//~^ ERROR: the trait `ConstParamTy` may not be implemented for this type
|
||||||
|
|
||||||
|
fn foo<const N: dyn Trait>() {}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,8 @@
|
||||||
|
error: the trait `ConstParamTy` may not be implemented for this type
|
||||||
|
--> $DIR/trait_objects_as_a_const_generic.rs:8:30
|
||||||
|
|
|
||||||
|
LL | impl UnsizedConstParamTy for dyn Trait {}
|
||||||
|
| ^^^^^^^^^ type is not a structure or enumeration
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
20
tests/ui/const-generics/adt_const_params/unsized_field-1.rs
Normal file
20
tests/ui/const-generics/adt_const_params/unsized_field-1.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
//@ aux-build:unsized_const_param.rs
|
||||||
|
#![feature(adt_const_params)]
|
||||||
|
|
||||||
|
extern crate unsized_const_param;
|
||||||
|
|
||||||
|
use std::marker::ConstParamTy;
|
||||||
|
|
||||||
|
#[derive(ConstParamTy, Eq, PartialEq)]
|
||||||
|
//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
struct A([u8]);
|
||||||
|
|
||||||
|
#[derive(ConstParamTy, Eq, PartialEq)]
|
||||||
|
//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
struct B(&'static [u8]);
|
||||||
|
|
||||||
|
#[derive(ConstParamTy, Eq, PartialEq)]
|
||||||
|
//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
struct C(unsized_const_param::Foo);
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,36 @@
|
||||||
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
--> $DIR/unsized_field-1.rs:8:10
|
||||||
|
|
|
||||||
|
LL | #[derive(ConstParamTy, Eq, PartialEq)]
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
LL |
|
||||||
|
LL | struct A([u8]);
|
||||||
|
| ---- this field does not implement `ConstParamTy_`
|
||||||
|
|
|
||||||
|
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
--> $DIR/unsized_field-1.rs:12:10
|
||||||
|
|
|
||||||
|
LL | #[derive(ConstParamTy, Eq, PartialEq)]
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
LL |
|
||||||
|
LL | struct B(&'static [u8]);
|
||||||
|
| ------------- this field does not implement `ConstParamTy_`
|
||||||
|
|
|
||||||
|
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
--> $DIR/unsized_field-1.rs:16:10
|
||||||
|
|
|
||||||
|
LL | #[derive(ConstParamTy, Eq, PartialEq)]
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
LL |
|
||||||
|
LL | struct C(unsized_const_param::Foo);
|
||||||
|
| ------------------------ this field does not implement `ConstParamTy_`
|
||||||
|
|
|
||||||
|
= note: this error originates in the derive macro `ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0204`.
|
14
tests/ui/const-generics/adt_const_params/unsized_field-2.rs
Normal file
14
tests/ui/const-generics/adt_const_params/unsized_field-2.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
//@ aux-build:unsized_const_param.rs
|
||||||
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
//~^ WARN: the feature `unsized_const_params` is incomplete
|
||||||
|
|
||||||
|
extern crate unsized_const_param;
|
||||||
|
|
||||||
|
#[derive(std::marker::ConstParamTy, Eq, PartialEq)]
|
||||||
|
//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
struct A(unsized_const_param::GenericNotUnsizedParam<&'static [u8]>);
|
||||||
|
|
||||||
|
#[derive(std::marker::UnsizedConstParamTy, Eq, PartialEq)]
|
||||||
|
struct B(unsized_const_param::GenericNotUnsizedParam<&'static [u8]>);
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,28 @@
|
||||||
|
warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||||
|
--> $DIR/unsized_field-2.rs:2:30
|
||||||
|
|
|
||||||
|
LL | #![feature(adt_const_params, unsized_const_params)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
||||||
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
||||||
|
error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type
|
||||||
|
--> $DIR/unsized_field-2.rs:7:10
|
||||||
|
|
|
||||||
|
LL | #[derive(std::marker::ConstParamTy, Eq, PartialEq)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
LL |
|
||||||
|
LL | struct A(unsized_const_param::GenericNotUnsizedParam<&'static [u8]>);
|
||||||
|
| ---------------------------------------------------------- this field does not implement `ConstParamTy_`
|
||||||
|
|
|
||||||
|
note: the `ConstParamTy_` impl for `GenericNotUnsizedParam<&'static [u8]>` requires that `&'static [u8]: ConstParamTy_`
|
||||||
|
--> $DIR/unsized_field-2.rs:9:10
|
||||||
|
|
|
||||||
|
LL | struct A(unsized_const_param::GenericNotUnsizedParam<&'static [u8]>);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
= note: this error originates in the derive macro `std::marker::ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error; 1 warning emitted
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0204`.
|
|
@ -39,6 +39,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: `&u8` is forbidden as the type of a const generic parameter
|
error: `&u8` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/const-param-elided-lifetime.rs:14:15
|
--> $DIR/const-param-elided-lifetime.rs:14:15
|
||||||
|
@ -51,6 +55,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: `&u8` is forbidden as the type of a const generic parameter
|
error: `&u8` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/const-param-elided-lifetime.rs:22:15
|
--> $DIR/const-param-elided-lifetime.rs:22:15
|
||||||
|
@ -63,6 +71,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: `&u8` is forbidden as the type of a const generic parameter
|
error: `&u8` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/const-param-elided-lifetime.rs:26:17
|
--> $DIR/const-param-elided-lifetime.rs:26:17
|
||||||
|
@ -75,6 +87,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: `&u8` is forbidden as the type of a const generic parameter
|
error: `&u8` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/const-param-elided-lifetime.rs:17:21
|
--> $DIR/const-param-elided-lifetime.rs:17:21
|
||||||
|
@ -87,6 +103,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 10 previous errors
|
error: aborting due to 10 previous errors
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// elided lifetimes within the type of a const generic parameters to be 'static, like elided
|
// elided lifetimes within the type of a const generic parameters to be 'static, like elided
|
||||||
// lifetimes within const/static items.
|
// lifetimes within const/static items.
|
||||||
//@ revisions: full min
|
//@ revisions: full min
|
||||||
#![cfg_attr(full, feature(adt_const_params))]
|
#![cfg_attr(full, feature(adt_const_params, unsized_const_params))]
|
||||||
#![cfg_attr(full, allow(incomplete_features))]
|
#![cfg_attr(full, allow(incomplete_features))]
|
||||||
|
|
||||||
struct A<const N: &u8>;
|
struct A<const N: &u8>;
|
||||||
|
@ -12,8 +12,8 @@ struct A<const N: &u8>;
|
||||||
trait B {}
|
trait B {}
|
||||||
|
|
||||||
impl<const N: &u8> A<N> {
|
impl<const N: &u8> A<N> {
|
||||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||||
//[min]~^^ ERROR `&u8` is forbidden
|
//[min]~^^ ERROR `&u8` is forbidden
|
||||||
fn foo<const M: &u8>(&self) {}
|
fn foo<const M: &u8>(&self) {}
|
||||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||||
//[min]~^^ ERROR `&u8` is forbidden
|
//[min]~^^ ERROR `&u8` is forbidden
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
use std::marker::ConstParamTy;
|
use std::marker::UnsizedConstParamTy;
|
||||||
|
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(Eq, PartialEq)]
|
||||||
struct Foo<T>(T);
|
struct Foo<T>(T);
|
||||||
|
|
||||||
trait Other {}
|
trait Other {}
|
||||||
|
|
||||||
impl<T> ConstParamTy for Foo<T> where T: Other + ConstParamTy {}
|
impl<T> UnsizedConstParamTy for Foo<T> where T: Other + UnsizedConstParamTy {}
|
||||||
|
|
||||||
fn foo<const N: Foo<u8>>() {}
|
fn foo<const N: Foo<u8>>() {}
|
||||||
//~^ ERROR `Foo<u8>` must implement `ConstParamTy` to be used as the type of a const generic parameter
|
//~^ ERROR `Foo<u8>` must implement `ConstParamTy` to be used as the type of a const generic parameter
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0741]: `f32` is forbidden as the type of a const generic parameter
|
error[E0741]: `f32` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/float-generic.rs:5:17
|
--> $DIR/float-generic.rs:7:17
|
||||||
|
|
|
|
||||||
LL | fn foo<const F: f32>() {}
|
LL | fn foo<const F: f32>() {}
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
9
tests/ui/const-generics/float-generic.full.stderr
Normal file
9
tests/ui/const-generics/float-generic.full.stderr
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
error[E0741]: `f32` is forbidden as the type of a const generic parameter
|
||||||
|
--> $DIR/float-generic.rs:7:17
|
||||||
|
|
|
||||||
|
LL | fn foo<const F: f32>() {}
|
||||||
|
| ^^^
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0741`.
|
|
@ -1,4 +1,6 @@
|
||||||
//@ revisions: simple adt_const_params
|
//@ revisions: simple adt_const_params full
|
||||||
|
#![cfg_attr(full, feature(adt_const_params, unsized_const_params))]
|
||||||
|
#![cfg_attr(full, allow(incomplete_features))]
|
||||||
#![cfg_attr(adt_const_params, feature(adt_const_params))]
|
#![cfg_attr(adt_const_params, feature(adt_const_params))]
|
||||||
#![cfg_attr(adt_const_params, allow(incomplete_features))]
|
#![cfg_attr(adt_const_params, allow(incomplete_features))]
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: `f32` is forbidden as the type of a const generic parameter
|
error: `f32` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/float-generic.rs:5:17
|
--> $DIR/float-generic.rs:7:17
|
||||||
|
|
|
|
||||||
LL | fn foo<const F: f32>() {}
|
LL | fn foo<const F: f32>() {}
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
error[E0741]: using function pointers as const generic parameters is forbidden
|
||||||
|
--> $DIR/fn-const-param-call.rs:13:25
|
||||||
|
|
|
||||||
|
LL | struct Wrapper<const F: fn() -> u32>;
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
|
error[E0741]: using function pointers as const generic parameters is forbidden
|
||||||
|
--> $DIR/fn-const-param-call.rs:15:15
|
||||||
|
|
|
||||||
|
LL | impl<const F: fn() -> u32> Wrapper<F> {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0741`.
|
|
@ -1,11 +1,11 @@
|
||||||
error[E0741]: using function pointers as const generic parameters is forbidden
|
error[E0741]: using function pointers as const generic parameters is forbidden
|
||||||
--> $DIR/fn-const-param-call.rs:11:25
|
--> $DIR/fn-const-param-call.rs:13:25
|
||||||
|
|
|
|
||||||
LL | struct Wrapper<const F: fn() -> u32>;
|
LL | struct Wrapper<const F: fn() -> u32>;
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0741]: using function pointers as const generic parameters is forbidden
|
error[E0741]: using function pointers as const generic parameters is forbidden
|
||||||
--> $DIR/fn-const-param-call.rs:13:15
|
--> $DIR/fn-const-param-call.rs:15:15
|
||||||
|
|
|
|
||||||
LL | impl<const F: fn() -> u32> Wrapper<F> {
|
LL | impl<const F: fn() -> u32> Wrapper<F> {
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: using function pointers as const generic parameters is forbidden
|
error: using function pointers as const generic parameters is forbidden
|
||||||
--> $DIR/fn-const-param-call.rs:11:25
|
--> $DIR/fn-const-param-call.rs:13:25
|
||||||
|
|
|
|
||||||
LL | struct Wrapper<const F: fn() -> u32>;
|
LL | struct Wrapper<const F: fn() -> u32>;
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
@ -7,7 +7,7 @@ LL | struct Wrapper<const F: fn() -> u32>;
|
||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
|
|
||||||
error: using function pointers as const generic parameters is forbidden
|
error: using function pointers as const generic parameters is forbidden
|
||||||
--> $DIR/fn-const-param-call.rs:13:15
|
--> $DIR/fn-const-param-call.rs:15:15
|
||||||
|
|
|
|
||||||
LL | impl<const F: fn() -> u32> Wrapper<F> {
|
LL | impl<const F: fn() -> u32> Wrapper<F> {
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
// Check that functions cannot be used as const parameters.
|
// Check that functions cannot be used as const parameters.
|
||||||
//@ revisions: full min
|
//@ revisions: min adt_const_params full
|
||||||
|
|
||||||
#![cfg_attr(full, feature(adt_const_params))]
|
#![cfg_attr(full, feature(adt_const_params, unsized_const_params))]
|
||||||
#![cfg_attr(full, allow(incomplete_features))]
|
#![cfg_attr(full, allow(incomplete_features))]
|
||||||
|
#![cfg_attr(adt_const_params, feature(adt_const_params))]
|
||||||
|
#![cfg_attr(adt_const_params, allow(incomplete_features))]
|
||||||
|
|
||||||
fn function() -> u32 {
|
fn function() -> u32 {
|
||||||
17
|
17
|
||||||
|
@ -11,7 +13,7 @@ fn function() -> u32 {
|
||||||
struct Wrapper<const F: fn() -> u32>; //~ ERROR: using function pointers as const generic parameters
|
struct Wrapper<const F: fn() -> u32>; //~ ERROR: using function pointers as const generic parameters
|
||||||
|
|
||||||
impl<const F: fn() -> u32> Wrapper<F> {
|
impl<const F: fn() -> u32> Wrapper<F> {
|
||||||
//~^ ERROR: using function pointers as const generic parameters
|
//~^ ERROR: using function pointers as const generic parameters
|
||||||
fn call() -> u32 {
|
fn call() -> u32 {
|
||||||
F()
|
F()
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
error[E0741]: using function pointers as const generic parameters is forbidden
|
||||||
|
--> $DIR/fn-const-param-infer.rs:8:25
|
||||||
|
|
|
||||||
|
LL | struct Checked<const F: fn(usize) -> bool>;
|
||||||
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/fn-const-param-infer.rs:33:25
|
||||||
|
|
|
||||||
|
LL | let _ = Checked::<{ generic_arg::<u32> }>;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
|
||||||
|
|
|
||||||
|
= note: expected fn pointer `fn(usize) -> _`
|
||||||
|
found fn item `fn(u32) -> _ {generic_arg::<u32>}`
|
||||||
|
|
||||||
|
error[E0282]: type annotations needed
|
||||||
|
--> $DIR/fn-const-param-infer.rs:35:23
|
||||||
|
|
|
||||||
|
LL | let _ = Checked::<generic>;
|
||||||
|
| ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic`
|
||||||
|
|
|
||||||
|
help: consider specifying the generic argument
|
||||||
|
|
|
||||||
|
LL | let _ = Checked::<generic::<T>>;
|
||||||
|
| +++++
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0282, E0308, E0741.
|
||||||
|
For more information about an error, try `rustc --explain E0282`.
|
|
@ -1,20 +1,20 @@
|
||||||
error[E0741]: using function pointers as const generic parameters is forbidden
|
error[E0741]: using function pointers as const generic parameters is forbidden
|
||||||
--> $DIR/fn-const-param-infer.rs:6:25
|
--> $DIR/fn-const-param-infer.rs:8:25
|
||||||
|
|
|
|
||||||
LL | struct Checked<const F: fn(usize) -> bool>;
|
LL | struct Checked<const F: fn(usize) -> bool>;
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/fn-const-param-infer.rs:23:24
|
--> $DIR/fn-const-param-infer.rs:33:25
|
||||||
|
|
|
|
||||||
LL | let _ = Checked::<{generic_arg::<u32>}>;
|
LL | let _ = Checked::<{ generic_arg::<u32> }>;
|
||||||
| ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
|
| ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
|
||||||
|
|
|
|
||||||
= note: expected fn pointer `fn(usize) -> _`
|
= note: expected fn pointer `fn(usize) -> _`
|
||||||
found fn item `fn(u32) -> _ {generic_arg::<u32>}`
|
found fn item `fn(u32) -> _ {generic_arg::<u32>}`
|
||||||
|
|
||||||
error[E0282]: type annotations needed
|
error[E0282]: type annotations needed
|
||||||
--> $DIR/fn-const-param-infer.rs:25:23
|
--> $DIR/fn-const-param-infer.rs:35:23
|
||||||
|
|
|
|
||||||
LL | let _ = Checked::<generic>;
|
LL | let _ = Checked::<generic>;
|
||||||
| ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic`
|
| ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic`
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: using function pointers as const generic parameters is forbidden
|
error: using function pointers as const generic parameters is forbidden
|
||||||
--> $DIR/fn-const-param-infer.rs:6:25
|
--> $DIR/fn-const-param-infer.rs:8:25
|
||||||
|
|
|
|
||||||
LL | struct Checked<const F: fn(usize) -> bool>;
|
LL | struct Checked<const F: fn(usize) -> bool>;
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
@ -7,16 +7,16 @@ LL | struct Checked<const F: fn(usize) -> bool>;
|
||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/fn-const-param-infer.rs:23:24
|
--> $DIR/fn-const-param-infer.rs:33:25
|
||||||
|
|
|
|
||||||
LL | let _ = Checked::<{generic_arg::<u32>}>;
|
LL | let _ = Checked::<{ generic_arg::<u32> }>;
|
||||||
| ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
|
| ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
|
||||||
|
|
|
|
||||||
= note: expected fn pointer `fn(usize) -> _`
|
= note: expected fn pointer `fn(usize) -> _`
|
||||||
found fn item `fn(u32) -> _ {generic_arg::<u32>}`
|
found fn item `fn(u32) -> _ {generic_arg::<u32>}`
|
||||||
|
|
||||||
error[E0282]: type annotations needed
|
error[E0282]: type annotations needed
|
||||||
--> $DIR/fn-const-param-infer.rs:25:23
|
--> $DIR/fn-const-param-infer.rs:35:23
|
||||||
|
|
|
|
||||||
LL | let _ = Checked::<generic>;
|
LL | let _ = Checked::<generic>;
|
||||||
| ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic`
|
| ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic`
|
||||||
|
|
|
@ -1,17 +1,27 @@
|
||||||
//@ revisions: full min
|
//@ revisions: min adt_const_params full
|
||||||
|
|
||||||
#![cfg_attr(full, feature(adt_const_params))]
|
#![cfg_attr(full, feature(adt_const_params, unsized_const_params))]
|
||||||
#![cfg_attr(full, allow(incomplete_features))]
|
#![cfg_attr(full, allow(incomplete_features))]
|
||||||
|
#![cfg_attr(adt_const_params, feature(adt_const_params))]
|
||||||
|
#![cfg_attr(adt_const_params, allow(incomplete_features))]
|
||||||
|
|
||||||
struct Checked<const F: fn(usize) -> bool>;
|
struct Checked<const F: fn(usize) -> bool>;
|
||||||
//~^ ERROR: using function pointers as const generic parameters
|
//~^ ERROR: using function pointers as const generic parameters
|
||||||
|
|
||||||
fn not_one(val: usize) -> bool { val != 1 }
|
fn not_one(val: usize) -> bool {
|
||||||
fn not_two(val: usize) -> bool { val != 2 }
|
val != 1
|
||||||
|
}
|
||||||
|
fn not_two(val: usize) -> bool {
|
||||||
|
val != 2
|
||||||
|
}
|
||||||
|
|
||||||
fn generic_arg<T>(val: T) -> bool { true }
|
fn generic_arg<T>(val: T) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn generic<T>(val: usize) -> bool { val != 1 }
|
fn generic<T>(val: usize) -> bool {
|
||||||
|
val != 1
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _: Option<Checked<not_one>> = None;
|
let _: Option<Checked<not_one>> = None;
|
||||||
|
@ -19,11 +29,11 @@ fn main() {
|
||||||
let _: Checked<not_one> = Checked::<not_two>;
|
let _: Checked<not_one> = Checked::<not_two>;
|
||||||
|
|
||||||
let _ = Checked::<generic_arg>;
|
let _ = Checked::<generic_arg>;
|
||||||
let _ = Checked::<{generic_arg::<usize>}>;
|
let _ = Checked::<{ generic_arg::<usize> }>;
|
||||||
let _ = Checked::<{generic_arg::<u32>}>; //~ ERROR: mismatched types
|
let _ = Checked::<{ generic_arg::<u32> }>; //~ ERROR: mismatched types
|
||||||
|
|
||||||
let _ = Checked::<generic>; //~ ERROR: type annotations needed
|
let _ = Checked::<generic>; //~ ERROR: type annotations needed
|
||||||
let _ = Checked::<{generic::<u16>}>;
|
let _ = Checked::<{ generic::<u16> }>;
|
||||||
let _: Checked<{generic::<u16>}> = Checked::<{generic::<u16>}>;
|
let _: Checked<{ generic::<u16> }> = Checked::<{ generic::<u16> }>;
|
||||||
let _: Checked<{generic::<u32>}> = Checked::<{generic::<u16>}>;
|
let _: Checked<{ generic::<u32> }> = Checked::<{ generic::<u16> }>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
// (this requires debug assertions)
|
// (this requires debug assertions)
|
||||||
|
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
fn foo<const B: &'static bool>(arg: &'static bool) -> bool {
|
fn foo<const B: &'static bool>(arg: &'static bool) -> bool {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
// (this requires debug assertions)
|
// (this requires debug assertions)
|
||||||
|
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
pub const BAR: () = ice::<"">();
|
pub const BAR: () = ice::<"">();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
|
|
||||||
#![feature(adt_const_params, generic_const_exprs)]
|
#![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
|
||||||
//~^ WARN the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
//~^ WARN the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
||||||
//~^^ WARN the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
//~^^ WARN the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
||||||
|
|
||||||
pub struct Changes<const CHANGES: &'static [&'static str]>
|
pub struct Changes<const CHANGES: &'static [&'static str]>
|
||||||
|
@ -16,9 +16,7 @@ where
|
||||||
[(); CHANGES.len()]:,
|
[(); CHANGES.len()]:,
|
||||||
{
|
{
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self { changes: [0; CHANGES.len()] }
|
||||||
changes: [0; CHANGES.len()],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||||
--> $DIR/issue-97047-ice-1.rs:3:12
|
--> $DIR/issue-97047-ice-1.rs:3:30
|
||||||
|
|
|
|
||||||
LL | #![feature(adt_const_params, generic_const_exprs)]
|
LL | #![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
||||||
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
|
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||||
--> $DIR/issue-97047-ice-1.rs:3:30
|
--> $DIR/issue-97047-ice-1.rs:3:52
|
||||||
|
|
|
|
||||||
LL | #![feature(adt_const_params, generic_const_exprs)]
|
LL | #![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
|
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
|
|
||||||
#![feature(adt_const_params, generic_const_exprs)]
|
#![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
|
||||||
//~^ WARN the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
//~^ WARN the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
||||||
//~^^ WARN the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
//~^^ WARN the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
||||||
|
|
||||||
pub struct Changes<const CHANGES: &'static [&'static str]>
|
pub struct Changes<const CHANGES: &'static [&'static str]>
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||||
--> $DIR/issue-97047-ice-2.rs:3:12
|
--> $DIR/issue-97047-ice-2.rs:3:30
|
||||||
|
|
|
|
||||||
LL | #![feature(adt_const_params, generic_const_exprs)]
|
LL | #![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
= note: `#[warn(incomplete_features)]` on by default
|
||||||
|
|
||||||
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
|
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||||
--> $DIR/issue-97047-ice-2.rs:3:30
|
--> $DIR/issue-97047-ice-2.rs:3:52
|
||||||
|
|
|
|
||||||
LL | #![feature(adt_const_params, generic_const_exprs)]
|
LL | #![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
|
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/intrinsics-type_name-as-const-argument.rs:15:44
|
--> $DIR/intrinsics-type_name-as-const-argument.rs:14:45
|
||||||
|
|
|
|
||||||
LL | T: Trait<{std::intrinsics::type_name::<T>()}>
|
LL | T: Trait<{ std::intrinsics::type_name::<T>() }>,
|
||||||
| ^ cannot perform const operation using `T`
|
| ^ cannot perform const operation using `T`
|
||||||
|
|
|
|
||||||
= note: type parameters may not be used in const expressions
|
= note: type parameters may not be used in const expressions
|
||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error: `&'static str` is forbidden as the type of a const generic parameter
|
error: `&'static str` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/intrinsics-type_name-as-const-argument.rs:10:22
|
--> $DIR/intrinsics-type_name-as-const-argument.rs:9:22
|
||||||
|
|
|
|
||||||
LL | trait Trait<const S: &'static str> {}
|
LL | trait Trait<const S: &'static str> {}
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
@ -18,6 +18,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
//@ revisions: full min
|
//@ revisions: full min
|
||||||
|
|
||||||
#![cfg_attr(full, allow(incomplete_features))]
|
#![cfg_attr(full, allow(incomplete_features))]
|
||||||
#![cfg_attr(full, feature(adt_const_params, generic_const_exprs))]
|
#![cfg_attr(full, feature(adt_const_params, unsized_const_params, generic_const_exprs))]
|
||||||
|
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
#![feature(const_type_name)]
|
#![feature(const_type_name)]
|
||||||
|
|
||||||
|
@ -12,10 +11,10 @@ trait Trait<const S: &'static str> {}
|
||||||
|
|
||||||
struct Bug<T>
|
struct Bug<T>
|
||||||
where
|
where
|
||||||
T: Trait<{std::intrinsics::type_name::<T>()}>
|
T: Trait<{ std::intrinsics::type_name::<T>() }>,
|
||||||
//[min]~^ ERROR generic parameters may not be used in const operations
|
//[min]~^ ERROR generic parameters may not be used in const operations
|
||||||
{
|
{
|
||||||
t: T
|
t: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,30 +1,20 @@
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
use std::marker::ConstParamTy;
|
use std::marker::UnsizedConstParamTy;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, ConstParamTy)]
|
#[derive(Debug, PartialEq, Eq, UnsizedConstParamTy)]
|
||||||
struct Foo {
|
struct Foo {
|
||||||
value: i32,
|
value: i32,
|
||||||
nested: &'static Bar<i32>,
|
nested: &'static Bar<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, ConstParamTy)]
|
#[derive(Debug, PartialEq, Eq, UnsizedConstParamTy)]
|
||||||
struct Bar<T>(T);
|
struct Bar<T>(T);
|
||||||
|
|
||||||
struct Test<const F: Foo>;
|
struct Test<const F: Foo>;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: Test<{
|
let x: Test<{ Foo { value: 3, nested: &Bar(4) } }> = Test;
|
||||||
Foo {
|
let y: Test<{ Foo { value: 3, nested: &Bar(5) } }> = x; //~ ERROR mismatched types
|
||||||
value: 3,
|
|
||||||
nested: &Bar(4),
|
|
||||||
}
|
|
||||||
}> = Test;
|
|
||||||
let y: Test<{
|
|
||||||
Foo {
|
|
||||||
value: 3,
|
|
||||||
nested: &Bar(5),
|
|
||||||
}
|
|
||||||
}> = x; //~ ERROR mismatched types
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/issue-66451.rs:29:10
|
--> $DIR/issue-66451.rs:19:58
|
||||||
|
|
|
|
||||||
LL | let y: Test<{
|
LL | let y: Test<{ Foo { value: 3, nested: &Bar(5) } }> = x;
|
||||||
| ____________-
|
| ------------------------------------------- ^ expected `Foo { value: 3, nested: &Bar::<i32>(5) }`, found `Foo { value: 3, nested: &Bar::<i32>(4) }`
|
||||||
LL | | Foo {
|
| |
|
||||||
LL | | value: 3,
|
| expected due to this
|
||||||
LL | | nested: &Bar(5),
|
|
||||||
LL | | }
|
|
||||||
LL | | }> = x;
|
|
||||||
| | - ^ expected `Foo { value: 3, nested: &Bar::<i32>(5) }`, found `Foo { value: 3, nested: &Bar::<i32>(4) }`
|
|
||||||
| |______|
|
|
||||||
| expected due to this
|
|
||||||
|
|
|
|
||||||
= note: expected struct `Test<Foo { value: 3, nested: &Bar::<i32>(5) }>`
|
= note: expected struct `Test<Foo { value: 3, nested: &Bar::<i32>(5) }>`
|
||||||
found struct `Test<Foo { value: 3, nested: &Bar::<i32>(4) }>`
|
found struct `Test<Foo { value: 3, nested: &Bar::<i32>(4) }>`
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//@ build-pass
|
//@ build-pass
|
||||||
|
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
|
pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params)]
|
||||||
//~^ WARN the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
enum Nat {
|
enum Nat {
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
|
|
||||||
--> $DIR/issue-80471.rs:1:12
|
|
||||||
|
|
|
||||||
LL | #![feature(adt_const_params)]
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
|
|
||||||
= note: `#[warn(incomplete_features)]` on by default
|
|
||||||
|
|
||||||
error[E0741]: `Nat` must implement `ConstParamTy` to be used as the type of a const generic parameter
|
error[E0741]: `Nat` must implement `ConstParamTy` to be used as the type of a const generic parameter
|
||||||
--> $DIR/issue-80471.rs:10:17
|
--> $DIR/issue-80471.rs:9:17
|
||||||
|
|
|
|
||||||
LL | fn foo<const N: Nat>() {}
|
LL | fn foo<const N: Nat>() {}
|
||||||
| ^^^
|
| ^^^
|
||||||
|
@ -19,6 +10,6 @@ LL + #[derive(ConstParamTy)]
|
||||||
LL | enum Nat {
|
LL | enum Nat {
|
||||||
|
|
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error; 1 warning emitted
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0741`.
|
For more information about this error, try `rustc --explain E0741`.
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(const_mut_refs)]
|
#![feature(const_mut_refs)]
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
|
||||||
struct T<const B: &'static bool>;
|
struct T<const B: &'static bool>;
|
||||||
|
|
||||||
impl <const B: &'static bool> T<B> {
|
impl<const B: &'static bool> T<B> {
|
||||||
const fn set_false(&self) {
|
const fn set_false(&self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
*(B as *const bool as *mut bool) = false;
|
*(B as *const bool as *mut bool) = false;
|
||||||
|
@ -14,7 +14,7 @@ impl <const B: &'static bool> T<B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const _: () = {
|
const _: () = {
|
||||||
let x = T::<{&true}>;
|
let x = T::<{ &true }>;
|
||||||
x.set_false();
|
x.set_false();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// a failing test, we just started masking the bug.
|
// a failing test, we just started masking the bug.
|
||||||
|
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![feature(adt_const_params, generic_const_exprs)]
|
#![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
const fn catone<const M: usize>(_a: &[u8; M]) -> [u8; M + 1]
|
const fn catone<const M: usize>(_a: &[u8; M]) -> [u8; M + 1]
|
||||||
|
|
|
@ -17,6 +17,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Regression test for https://github.com/rust-lang/rust/issues/56445#issuecomment-518402995.
|
// Regression test for https://github.com/rust-lang/rust/issues/56445#issuecomment-518402995.
|
||||||
//@ revisions: full min
|
//@ revisions: full min
|
||||||
#![cfg_attr(full, feature(adt_const_params))]
|
#![cfg_attr(full, feature(adt_const_params, unsized_const_params))]
|
||||||
#![cfg_attr(full, allow(incomplete_features))]
|
#![cfg_attr(full, allow(incomplete_features))]
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ error[E0741]: `&'static (dyn A + 'static)` can't be used as a const parameter ty
|
||||||
LL | fn test<const T: &'static dyn A>() {
|
LL | fn test<const T: &'static dyn A>() {
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `(dyn A + 'static)` must implement `ConstParamTy`, but it does not
|
= note: `(dyn A + 'static)` must implement `UnsizedConstParamTy`, but it does not
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//@ revisions: full min
|
//@ revisions: full min
|
||||||
#![cfg_attr(full, feature(adt_const_params))]
|
#![cfg_attr(full, feature(adt_const_params, unsized_const_params))]
|
||||||
#![cfg_attr(full, allow(incomplete_features))]
|
#![cfg_attr(full, allow(incomplete_features))]
|
||||||
|
|
||||||
trait A {}
|
trait A {}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
|
||||||
trait Trait<const NAME: &'static str> {
|
trait Trait<const NAME: &'static str> {
|
||||||
type Assoc;
|
type Assoc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
|
|
||||||
#![feature(adt_const_params)]
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
pub trait GetType<const N: &'static str> {
|
pub trait GetType<const N: &'static str> {
|
||||||
|
|
|
@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
|
|
|
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
help: add `#![feature(unsized_const_params)]` to the crate attributes to enable references to implement the `ConstParamTy` trait
|
||||||
|
|
|
||||||
|
LL + #![feature(unsized_const_params)]
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
//@ revisions: full min
|
//@ revisions: full min
|
||||||
//@[full]check-pass
|
//@[full]check-pass
|
||||||
|
|
||||||
#![cfg_attr(full, feature(adt_const_params))]
|
#![cfg_attr(full, feature(adt_const_params, unsized_const_params))]
|
||||||
#![cfg_attr(full, allow(incomplete_features))]
|
#![cfg_attr(full, allow(incomplete_features))]
|
||||||
|
|
||||||
fn a<const X: &'static [u32]>() {}
|
fn a<const X: &'static [u32]>() {}
|
||||||
//[min]~^ ERROR `&'static [u32]` is forbidden as the type of a const generic parameter
|
//[min]~^ ERROR `&'static [u32]` is forbidden as the type of a const generic parameter
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
a::<{&[]}>();
|
a::<{ &[] }>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
//@ run-pass
|
//@ run-pass
|
||||||
#![feature(adt_const_params, generic_const_exprs)]
|
#![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
pub trait Foo {
|
pub trait Foo {
|
||||||
const ASSOC_C: usize;
|
const ASSOC_C: usize;
|
||||||
fn foo() where [(); Self::ASSOC_C]:;
|
fn foo()
|
||||||
|
where
|
||||||
|
[(); Self::ASSOC_C]:;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -12,7 +14,10 @@ struct Bar<const N: &'static ()>;
|
||||||
impl<const N: &'static ()> Foo for Bar<N> {
|
impl<const N: &'static ()> Foo for Bar<N> {
|
||||||
const ASSOC_C: usize = 3;
|
const ASSOC_C: usize = 3;
|
||||||
|
|
||||||
fn foo() where [u8; Self::ASSOC_C]: {
|
fn foo()
|
||||||
|
where
|
||||||
|
[u8; Self::ASSOC_C]:,
|
||||||
|
{
|
||||||
let _: [u8; Self::ASSOC_C] = loop {};
|
let _: [u8; Self::ASSOC_C] = loop {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//@ run-pass
|
//@ run-pass
|
||||||
#![feature(adt_const_params, generic_const_exprs)]
|
#![feature(adt_const_params, unsized_const_params, generic_const_exprs)]
|
||||||
#![allow(incomplete_features, unused_variables)]
|
#![allow(incomplete_features, unused_variables)]
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//@ run-rustfix
|
//@ run-rustfix
|
||||||
#![feature(generic_const_exprs, adt_const_params)]
|
#![feature(generic_const_exprs, unsized_const_params, adt_const_params)]
|
||||||
#![allow(incomplete_features, dead_code)]
|
#![allow(incomplete_features, dead_code)]
|
||||||
|
|
||||||
struct FieldElement<const N: &'static str> where [(); num_limbs(N)]: {
|
struct FieldElement<const N: &'static str> where [(); num_limbs(N)]: {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue