From 42cc42b942088a94d95bc5169724d77429f20582 Mon Sep 17 00:00:00 2001 From: Boxy Date: Sun, 14 Jul 2024 12:50:41 +0100 Subject: [PATCH 1/2] Forbid `!Sized` types and references --- compiler/rustc_feature/src/unstable.rs | 4 +- compiler/rustc_hir_analysis/messages.ftl | 4 + .../rustc_hir_analysis/src/check/wfcheck.rs | 16 ++- .../src/coherence/builtin.rs | 42 +++++-- compiler/rustc_hir_analysis/src/errors.rs | 8 ++ .../rustc_trait_selection/src/traits/misc.rs | 117 ++++++++++++++---- library/core/src/marker.rs | 15 ++- 7 files changed, 167 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 1db3774222a09..7f0c5f6b7a0bd 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -339,8 +339,8 @@ declare_features! ( (unstable, abi_riscv_interrupt, "1.73.0", Some(111889)), /// Allows `extern "x86-interrupt" fn()`. (unstable, abi_x86_interrupt, "1.17.0", Some(40180)), - /// Allows additional const parameter types, such as `&'static str` or user defined types - (incomplete, adt_const_params, "1.56.0", Some(95174)), + /// Allows additional const parameter types, such as `[u8; 10]` or user defined types + (unstable, adt_const_params, "1.56.0", Some(95174)), /// Allows defining an `#[alloc_error_handler]`. (unstable, alloc_error_handler, "1.29.0", Some(51540)), /// Allows trait methods with arbitrary self types. diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index 24c5377a3b125..700b3a2fb00b8 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -78,6 +78,10 @@ hir_analysis_const_impl_for_non_const_trait = .note = marking a trait with `#[const_trait]` ensures all default method bodies are `const` .adding = adding a non-const method body in the future would be a breaking change +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_param_ty_impl_on_non_adt = the trait `ConstParamTy` may not be implemented for this type .label = type is not a structure or enumeration diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index b2ef07d65c5b4..ecd2834dfd17b 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -924,8 +924,6 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(), if tcx.features().adt_const_params { 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( ObligationCause::new( hir_ty.span, @@ -934,7 +932,13 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(), ), wfcx.param_env, ty, - trait_def_id, + tcx.require_lang_item(LangItem::ConstParamTy, Some(hir_ty.span)), + ); + wfcx.register_bound( + ObligationCause::new(hir_ty.span, param.def_id, ObligationCauseCode::Misc), + wfcx.param_env, + ty, + tcx.require_lang_item(LangItem::Sized, Some(hir_ty.span)), ); Ok(()) }) @@ -965,7 +969,11 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(), cause, ) { // Can never implement `ConstParamTy`, don't suggest anything. - Err(ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed) => false, + Err( + ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed + | ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(..) + | ConstParamTyImplementationError::TypeNotSized, + ) => false, // 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. Err(ConstParamTyImplementationError::InfrigingFields(..)) => { diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 2ecb170ec8955..16745668f8cbf 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -103,7 +103,13 @@ fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaran Ok(()) => Ok(()), Err(CopyImplementationError::InfringingFields(fields)) => { 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) => { let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span; @@ -125,7 +131,7 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E 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(()); } @@ -134,12 +140,32 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E Ok(()) => Ok(()), Err(ConstParamTyImplementationError::InfrigingFields(fields)) => { 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) => { let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.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::TypeNotSized) => { + let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span; + Err(tcx.dcx().emit_err(errors::ConstParamTyImplOnUnsized { span })) + } } } @@ -501,9 +527,9 @@ pub fn coerce_unsized_info<'tcx>( Ok(CoerceUnsizedInfo { custom_kind: kind }) } -fn infringing_fields_error( - tcx: TyCtxt<'_>, - fields: Vec<(&ty::FieldDef, Ty<'_>, InfringingFieldsReason<'_>)>, +fn infringing_fields_error<'tcx>( + tcx: TyCtxt<'tcx>, + infringing_tys: impl Iterator, InfringingFieldsReason<'tcx>)>, lang_item: LangItem, impl_did: LocalDefId, impl_span: Span, @@ -521,13 +547,13 @@ fn infringing_fields_error( 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. if !seen_tys.insert(ty) { continue; } - label_spans.push(tcx.def_span(field.did)); + label_spans.push(span); match reason { InfringingFieldsReason::Fulfill(fulfillment_errors) => { diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 0ee87a13e9e37..7f8aefd564d78 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -278,6 +278,14 @@ pub struct CopyImplOnNonAdt { 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)] #[diag(hir_analysis_const_param_ty_impl_on_non_adt)] pub struct ConstParamTyImplOnNonAdt { diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index baec2268629dc..3150bd894ec89 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -19,6 +19,8 @@ pub enum CopyImplementationError<'tcx> { } pub enum ConstParamTyImplementationError<'tcx> { + TypeNotSized, + InvalidInnerTyOfBuiltinTy(Vec<(Ty<'tcx>, InfringingFieldsReason<'tcx>)>), InfrigingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>), NotAnAdtOrBuiltinAllowed, } @@ -89,33 +91,104 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( self_type: Ty<'tcx>, parent_cause: ObligationCause<'tcx>, ) -> Result<(), ConstParamTyImplementationError<'tcx>> { - let (adt, args) = match self_type.kind() { - // `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(()), + { + // Check for sizedness before recursing into ADT fields so that if someone tries to write: + // ```rust + // #[derive(ConstParamTy)] + // struct Foo([u8]) + // ``` + // They are told that const parameter types must be sized, instead of it saying that + // the trait implementation `[u8]: ConstParamTy` is not satisfied. + let infcx = tcx.infer_ctxt().build(); + let ocx = traits::ObligationCtxt::new_with_diagnostics(&infcx); - &ty::Adt(adt, args) => (adt, args), + ocx.register_bound( + parent_cause.clone(), + param_env, + self_type, + tcx.require_lang_item(LangItem::Sized, Some(parent_cause.span)), + ); + + if !ocx.select_all_or_error().is_empty() { + return Err(ConstParamTyImplementationError::TypeNotSized); + } + }; + + 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(()), + + ty::Ref(..) => return Err(ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed), + + // Even if we currently require const params to be `Sized` we may aswell handle them correctly + // here anyway. + ty::Slice(inner_ty) | ty::Array(inner_ty, _) => vec![inner_ty], + // `str` morally acts like a newtype around `[u8]` + ty::Str => vec![Ty::new_slice(tcx, tcx.types.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(), + hir::LangItem::ConstParamTy, + ) + .map_err(ConstParamTyImplementationError::InfrigingFields)?; + + vec![] + } _ => return Err(ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed), }; - all_fields_implement_trait( - tcx, - param_env, - self_type, - adt, - args, - parent_cause, - hir::LangItem::ConstParamTy, - ) - .map_err(ConstParamTyImplementationError::InfrigingFields)?; + let mut infringing_inner_tys = vec![]; + for inner_ty in inner_tys { + // We use an ocx per inner ty for better diagnostics + let infcx = tcx.infer_ctxt().build(); + let ocx = traits::ObligationCtxt::new_with_diagnostics(&infcx); + + ocx.register_bound( + parent_cause.clone(), + param_env, + inner_ty, + tcx.require_lang_item(LangItem::ConstParamTy, 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(()) } diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 21abd7c036ba7..70bd4f67ebfde 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -995,13 +995,22 @@ marker_impls! { isize, i8, i16, i32, i64, i128, bool, char, - str /* Technically requires `[u8]: ConstParamTy` */, (), {T: ConstParamTy, const N: usize} [T; N], - {T: ConstParamTy} [T], - {T: ?Sized + ConstParamTy} &T, } +#[unstable(feature = "adt_const_params", issue = "95174")] +#[rustc_reservation_impl = "types that are not `Sized` are not supported as the type of a const generic parameter"] +impl ConstParamTy for [T] {} + +#[unstable(feature = "adt_const_params", issue = "95174")] +#[rustc_reservation_impl = "types that are not `Sized` are not supported as the type of a const generic parameter"] +impl ConstParamTy for str {} + +#[unstable(feature = "adt_const_params", issue = "95174")] +#[rustc_reservation_impl = "references are not supported as the type of a const generic parameter"] +impl ConstParamTy for &T {} + /// A common trait implemented by all function pointers. #[unstable( feature = "fn_ptr_trait", From d0c11bf6e3fea61711af107c896a763a71606340 Mon Sep 17 00:00:00 2001 From: Boxy Date: Sun, 14 Jul 2024 13:38:51 +0100 Subject: [PATCH 2/2] Split part of `adt_const_params` into `unsized_const_params` --- .../src/deriving/bounds.rs | 39 ++++++++- compiler/rustc_builtin_macros/src/lib.rs | 1 + .../src/error_codes/E0771.md | 4 +- compiler/rustc_feature/src/unstable.rs | 3 + compiler/rustc_hir/src/lang_items.rs | 1 + compiler/rustc_hir_analysis/messages.ftl | 8 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 51 +++++++---- .../src/coherence/builtin.rs | 21 +++-- compiler/rustc_span/src/symbol.rs | 4 + .../rustc_trait_selection/src/traits/misc.rs | 56 +++++-------- library/core/src/lib.rs | 1 + library/core/src/marker.rs | 61 ++++++++++---- library/core/src/mem/transmutability.rs | 6 +- library/core/src/tuple.rs | 14 +++- tests/crashes/119299.rs | 25 ------ tests/mir-opt/const_prop/invalid_constant.rs | 2 +- tests/mir-opt/issue_99325.rs | 2 +- tests/rustdoc/const-generics/const-impl.rs | 2 +- .../regions-in-canonical.rs | 5 +- .../regions-in-canonical.stderr | 8 +- .../alias_const_param_ty-1.rs | 3 +- .../alias_const_param_ty-1.stderr | 12 +-- .../alias_const_param_ty-2.rs | 1 - .../alias_const_param_ty-2.stderr | 11 --- .../auxiliary/unsized_const_param.rs | 7 ++ .../adt_const_params/const_param_ty_bad.rs | 14 ++-- .../const_param_ty_bad.stderr | 42 +++++----- .../const_param_ty_bad_empty_array.rs | 4 +- .../const_param_ty_bad_empty_array.stderr | 8 +- ...nst_param_ty_generic_bounds_do_not_hold.rs | 8 +- ...param_ty_generic_bounds_do_not_hold.stderr | 24 +++--- .../adt_const_params/const_param_ty_good.rs | 13 +-- .../const_param_ty_impl_bad_field.rs | 10 +-- .../const_param_ty_impl_bad_field.stderr | 20 ++--- .../const_param_ty_impl_no_structural_eq.rs | 10 +-- ...onst_param_ty_impl_no_structural_eq.stderr | 32 +++---- .../const_param_ty_impl_union.rs | 9 +- .../const_param_ty_impl_union.stderr | 16 ++-- .../const_param_ty_object_safety.rs | 12 +++ .../const_param_ty_object_safety.stderr | 33 ++++++++ .../adt_const_params/index-oob-ice-83993.rs | 24 ++++-- .../index-oob-ice-83993.stderr | 17 +--- .../nested_bad_const_param_ty.rs | 9 +- .../nested_bad_const_param_ty.stderr | 84 +++++++++++++++---- ..._non-universal_region_substs_ice-111911.rs | 2 +- .../reference_pointee_is_const_param-1.rs | 11 +++ .../reference_pointee_is_const_param-1.stderr | 9 ++ .../reference_pointee_is_const_param-2.rs | 27 ++++++ .../reference_pointee_is_const_param-2.stderr | 9 ++ .../suggest_feature_only_when_possible.rs | 5 +- .../suggest_feature_only_when_possible.stderr | 36 ++++---- .../trait_objects_as_a_const_generic.rs | 13 +++ .../trait_objects_as_a_const_generic.stderr | 8 ++ .../adt_const_params/unsized_field-1.rs | 20 +++++ .../adt_const_params/unsized_field-1.stderr | 36 ++++++++ .../adt_const_params/unsized_field-2.rs | 14 ++++ .../adt_const_params/unsized_field-2.stderr | 28 +++++++ .../const-param-elided-lifetime.min.stderr | 20 +++++ .../const-param-elided-lifetime.rs | 6 +- ...const-param-with-additional-obligations.rs | 6 +- .../float-generic.adt_const_params.stderr | 2 +- .../const-generics/float-generic.full.stderr | 9 ++ tests/ui/const-generics/float-generic.rs | 4 +- .../float-generic.simple.stderr | 2 +- ...n-const-param-call.adt_const_params.stderr | 15 ++++ .../fn-const-param-call.full.stderr | 4 +- .../fn-const-param-call.min.stderr | 4 +- .../ui/const-generics/fn-const-param-call.rs | 8 +- ...-const-param-infer.adt_const_params.stderr | 30 +++++++ .../fn-const-param-infer.full.stderr | 10 +-- .../fn-const-param-infer.min.stderr | 10 +-- .../ui/const-generics/fn-const-param-infer.rs | 32 ++++--- .../generic_const_exprs/issue-100360.rs | 2 +- .../generic_const_exprs/issue-89851.rs | 2 +- .../generic_const_exprs/issue-97047-ice-1.rs | 8 +- .../issue-97047-ice-1.stderr | 14 ++-- .../generic_const_exprs/issue-97047-ice-2.rs | 4 +- .../issue-97047-ice-2.stderr | 14 ++-- ...ics-type_name-as-const-argument.min.stderr | 12 ++- .../intrinsics-type_name-as-const-argument.rs | 7 +- tests/ui/const-generics/issue-66451.rs | 22 ++--- tests/ui/const-generics/issue-66451.stderr | 16 ++-- tests/ui/const-generics/issue-70408.rs | 2 +- tests/ui/const-generics/issue-80471.rs | 1 - tests/ui/const-generics/issue-80471.stderr | 13 +-- .../ui/const-generics/issues/issue-100313.rs | 6 +- .../ui/const-generics/issues/issue-105821.rs | 2 +- .../issues/issue-56445-1.min.stderr | 4 + .../ui/const-generics/issues/issue-56445-1.rs | 2 +- .../issues/issue-63322-forbid-dyn.full.stderr | 2 +- .../issues/issue-63322-forbid-dyn.min.stderr | 4 + .../issues/issue-63322-forbid-dyn.rs | 2 +- ...ssue-66596-impl-trait-for-str-const-arg.rs | 3 +- tests/ui/const-generics/issues/issue-71547.rs | 2 +- ...tic-reference-array-const-param.min.stderr | 4 + ...3727-static-reference-array-const-param.rs | 4 +- .../ui/const-generics/issues/issue-86535-2.rs | 11 ++- tests/ui/const-generics/issues/issue-86535.rs | 2 +- .../const-generics/issues/issue-90455.fixed | 2 +- tests/ui/const-generics/issues/issue-90455.rs | 2 +- .../const-generics/issues/issue-99641.stderr | 4 +- .../min_const_generics/complex-types.stderr | 4 + ...-const-param-deref.adt_const_params.stderr | 15 ++++ .../raw-ptr-const-param-deref.full.stderr | 4 +- .../raw-ptr-const-param-deref.min.stderr | 4 +- .../raw-ptr-const-param-deref.rs | 15 ++-- ...aw-ptr-const-param.adt_const_params.stderr | 21 +++++ .../raw-ptr-const-param.full.stderr | 4 +- .../raw-ptr-const-param.min.stderr | 4 +- .../ui/const-generics/raw-ptr-const-param.rs | 6 +- ...nst-param-mismatch.adt_const_params.stderr | 49 +++++++++++ .../slice-const-param-mismatch.full.stderr | 6 +- .../slice-const-param-mismatch.min.stderr | 18 ++-- .../slice-const-param-mismatch.rs | 11 ++- tests/ui/const-generics/slice-const-param.rs | 7 +- ...m-static-reference.adt_const_params.stderr | 9 ++ ...te-const-param-static-reference.min.stderr | 6 +- .../transmute-const-param-static-reference.rs | 13 +-- .../type-dependent/issue-71348.min.stderr | 8 ++ .../type-dependent/issue-71348.rs | 2 +- .../consts/refs_check_const_eq-issue-88384.rs | 17 ++-- .../refs_check_const_eq-issue-88384.stderr | 12 +-- .../refs_check_const_value_eq-issue-88876.rs | 2 +- tests/ui/error-codes/E0771.rs | 4 +- tests/ui/error-codes/E0771.stderr | 8 +- .../feature-gate-adt_const_params.stderr | 4 + .../feature-gate-unsized-const-params.rs | 6 ++ .../feature-gate-unsized-const-params.stderr | 18 ++++ .../elided-lifetimes.stderr | 4 + ...g-use-uncaptured-non-universal-region-3.rs | 2 +- ...tic-lifetime-return-position-impl-trait.rs | 2 +- .../ice-cannot-relate-region-109178.rs | 2 +- .../lifetimes/unusual-rib-combinations.stderr | 4 + tests/ui/simd/intrinsic/generic-elements.rs | 20 ++--- .../ui/simd/intrinsic/generic-elements.stderr | 42 +++++----- tests/ui/simd/monomorphize-shuffle-index.rs | 2 +- tests/ui/statics/const_generics.rs | 2 +- .../const-generics-str-demangling.rs | 2 +- .../const-generics-structural-demangling.rs | 26 +++--- .../ice-unexpected-region-123863.stderr | 8 ++ 140 files changed, 1127 insertions(+), 556 deletions(-) delete mode 100644 tests/crashes/119299.rs delete mode 100644 tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.stderr create mode 100644 tests/ui/const-generics/adt_const_params/auxiliary/unsized_const_param.rs create mode 100644 tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs create mode 100644 tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr create mode 100644 tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs create mode 100644 tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr create mode 100644 tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs create mode 100644 tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr create mode 100644 tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs create mode 100644 tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr create mode 100644 tests/ui/const-generics/adt_const_params/unsized_field-1.rs create mode 100644 tests/ui/const-generics/adt_const_params/unsized_field-1.stderr create mode 100644 tests/ui/const-generics/adt_const_params/unsized_field-2.rs create mode 100644 tests/ui/const-generics/adt_const_params/unsized_field-2.stderr create mode 100644 tests/ui/const-generics/float-generic.full.stderr create mode 100644 tests/ui/const-generics/fn-const-param-call.adt_const_params.stderr create mode 100644 tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr create mode 100644 tests/ui/const-generics/raw-ptr-const-param-deref.adt_const_params.stderr create mode 100644 tests/ui/const-generics/raw-ptr-const-param.adt_const_params.stderr create mode 100644 tests/ui/const-generics/slice-const-param-mismatch.adt_const_params.stderr create mode 100644 tests/ui/const-generics/transmute-const-param-static-reference.adt_const_params.stderr create mode 100644 tests/ui/feature-gates/feature-gate-unsized-const-params.rs create mode 100644 tests/ui/feature-gates/feature-gate-unsized-const-params.stderr diff --git a/compiler/rustc_builtin_macros/src/deriving/bounds.rs b/compiler/rustc_builtin_macros/src/deriving/bounds.rs index 97e2344ff30e5..f6b5433582929 100644 --- a/compiler/rustc_builtin_macros/src/deriving/bounds.rs +++ b/compiler/rustc_builtin_macros/src/deriving/bounds.rs @@ -38,7 +38,44 @@ pub(crate) fn expand_deriving_const_param_ty( ) { let trait_def = TraitDef { 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, needs_copy_as_bound_if_packed: false, additional_bounds: vec![ty::Ty::Path(path_std!(cmp::Eq))], diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index f8d9366614578..c77ff9eb13cdc 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -118,6 +118,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { Clone: clone::expand_deriving_clone, Copy: bounds::expand_deriving_copy, ConstParamTy: bounds::expand_deriving_const_param_ty, + UnsizedConstParamTy: bounds::expand_deriving_unsized_const_param_ty, Debug: debug::expand_deriving_debug, Default: default::expand_deriving_default, Eq: eq::expand_deriving_eq, diff --git a/compiler/rustc_error_codes/src/error_codes/E0771.md b/compiler/rustc_error_codes/src/error_codes/E0771.md index 4f36590025bae..74149eb79f6ee 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0771.md +++ b/compiler/rustc_error_codes/src/error_codes/E0771.md @@ -6,7 +6,7 @@ allowed. Erroneous code example: ```compile_fail,E0770 -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] 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`: ``` -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] fn function_with_str() {} // ok! ``` diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 7f0c5f6b7a0bd..741c621db081a 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -630,6 +630,9 @@ declare_features! ( (unstable, unsafe_attributes, "1.80.0", Some(123757)), /// Allows unsafe on extern declarations and safety qualifiers over internal items. (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() {`. + (incomplete, unsized_const_params, "CURRENT_RUSTC_VERSION", Some(95174)), /// Allows unsized fn parameters. (internal, unsized_fn_params, "1.49.0", Some(48055)), /// Allows unsized rvalues at arguments and parameters. diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 30c0e40206aaf..58cc0f6211120 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -358,6 +358,7 @@ language_item_table! { 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); + UnsizedConstParamTy, sym::unsized_const_param_ty, unsized_const_param_ty_trait, Target::Trait, GenericRequirement::Exact(0); Poll, sym::Poll, poll, Target::Enum, GenericRequirement::None; PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None; diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index 700b3a2fb00b8..91dd9f92fa8ef 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -78,14 +78,14 @@ hir_analysis_const_impl_for_non_const_trait = .note = marking a trait with `#[const_trait]` ensures all default method bodies are `const` .adding = adding a non-const method body in the future would be a breaking change -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_param_ty_impl_on_non_adt = the trait `ConstParamTy` may not be implemented for this type .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_copy_impl_on_non_adt = diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index ecd2834dfd17b..c1621b6ae4ae7 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -922,7 +922,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(), } => { 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| { wfcx.register_bound( ObligationCause::new( @@ -932,13 +932,21 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(), ), wfcx.param_env, ty, - tcx.require_lang_item(LangItem::ConstParamTy, Some(hir_ty.span)), + 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::Misc), + ObligationCause::new( + hir_ty.span, + param.def_id, + ObligationCauseCode::ConstParam(ty), + ), wfcx.param_env, ty, - tcx.require_lang_item(LangItem::Sized, Some(hir_ty.span)), + tcx.require_lang_item(LangItem::ConstParamTy, Some(hir_ty.span)), ); Ok(()) }) @@ -962,18 +970,29 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(), diag.note("the only supported types are integers, `bool` and `char`"); 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( tcx, tcx.param_env(param.def_id), ty, + LangItem::ConstParamTy, cause, ) { // Can never implement `ConstParamTy`, don't suggest anything. Err( ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed - | ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(..) - | ConstParamTyImplementationError::TypeNotSized, - ) => false, + | 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 // if the type is local, since the user may be able to fix the local type. Err(ConstParamTyImplementationError::InfrigingFields(..)) => { @@ -993,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. - Ok(..) => true, + Ok(..) => Some(vec![(adt_const_params_feature_string, sym::adt_const_params)]), }; - if may_suggest_feature { - tcx.disabled_nightly_features( - &mut diag, - Some(param.hir_id), - [( - " more complex and user defined types".to_string(), - sym::adt_const_params, - )], - ); + if let Some(features) = may_suggest_feature { + tcx.disabled_nightly_features(&mut diag, Some(param.hir_id), features); } Err(diag.emit()) diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 16745668f8cbf..4fad40ff0e62d 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -36,9 +36,13 @@ pub(super) fn check_trait<'tcx>( 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); res = res.and(checker.check(lang_items.copy_trait(), visit_implementation_of_copy)); - res = res.and( - checker.check(lang_items.const_param_ty_trait(), visit_implementation_of_const_param_ty), - ); + res = res.and(checker.check(lang_items.const_param_ty_trait(), |checker| { + 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( checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized), ); @@ -122,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 header = checker.impl_header; let impl_did = checker.impl_def_id; @@ -136,7 +145,7 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E } 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(()), Err(ConstParamTyImplementationError::InfrigingFields(fields)) => { let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span; @@ -162,7 +171,7 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E span, )) } - Err(ConstParamTyImplementationError::TypeNotSized) => { + Err(ConstParamTyImplementationError::UnsizedConstParamsFeatureRequired) => { let span = tcx.hir().expect_item(impl_did).expect_impl().self_ty.span; Err(tcx.dcx().emit_err(errors::ConstParamTyImplOnUnsized { span })) } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 2fe7c951793f7..cfa4d174e7b7b 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -177,6 +177,7 @@ symbols! { CoerceUnsized, Command, ConstParamTy, + ConstParamTy_, Context, Continue, Copy, @@ -336,6 +337,7 @@ symbols! { TyKind, Unknown, Unsize, + UnsizedConstParamTy, Upvars, Vec, VecDeque, @@ -2000,6 +2002,8 @@ symbols! { unsafe_no_drop_flag, unsafe_pin_internals, unsize, + unsized_const_param_ty, + unsized_const_params, unsized_fn_params, unsized_locals, unsized_tuple_coercion, diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index 3150bd894ec89..d749b68680339 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -4,6 +4,7 @@ use crate::regions::InferCtxtRegionExt; use crate::traits::{self, FulfillmentError, ObligationCause}; use hir::LangItem; +use rustc_ast::Mutability; use rustc_data_structures::fx::FxIndexSet; use rustc_hir as hir; use rustc_infer::infer::outlives::env::OutlivesEnvironment; @@ -19,7 +20,7 @@ pub enum CopyImplementationError<'tcx> { } pub enum ConstParamTyImplementationError<'tcx> { - TypeNotSized, + UnsizedConstParamsFeatureRequired, InvalidInnerTyOfBuiltinTy(Vec<(Ty<'tcx>, InfringingFieldsReason<'tcx>)>), InfrigingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>), NotAnAdtOrBuiltinAllowed, @@ -79,9 +80,9 @@ pub fn type_allowed_to_implement_copy<'tcx>( 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. /// /// If it's not an ADT, int ty, `bool` or `char`, returns `Err(NotAnAdtOrBuiltinAllowed)`. @@ -89,30 +90,10 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, self_type: Ty<'tcx>, + lang_item: LangItem, parent_cause: ObligationCause<'tcx>, ) -> Result<(), ConstParamTyImplementationError<'tcx>> { - { - // Check for sizedness before recursing into ADT fields so that if someone tries to write: - // ```rust - // #[derive(ConstParamTy)] - // struct Foo([u8]) - // ``` - // They are told that const parameter types must be sized, instead of it saying that - // the trait implementation `[u8]: ConstParamTy` is not satisfied. - let infcx = tcx.infer_ctxt().build(); - let ocx = traits::ObligationCtxt::new_with_diagnostics(&infcx); - - ocx.register_bound( - parent_cause.clone(), - param_env, - self_type, - tcx.require_lang_item(LangItem::Sized, Some(parent_cause.span)), - ); - - if !ocx.select_all_or_error().is_empty() { - return Err(ConstParamTyImplementationError::TypeNotSized); - } - }; + assert!(matches!(lang_item, LangItem::ConstParamTy | LangItem::UnsizedConstParamTy)); let inner_tys: Vec<_> = match *self_type.kind() { // Trivially okay as these types are all: @@ -121,14 +102,23 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( // - Have structural equality ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Char => return Ok(()), - ty::Ref(..) => return Err(ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed), + // 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], - // Even if we currently require const params to be `Sized` we may aswell handle them correctly - // here anyway. - ty::Slice(inner_ty) | ty::Array(inner_ty, _) => vec![inner_ty], // `str` morally acts like a newtype around `[u8]` - ty::Str => vec![Ty::new_slice(tcx, tcx.types.u8)], - ty::Tuple(inner_tys) => inner_tys.into_iter().collect(), ty::Adt(adt, args) if adt.is_enum() || adt.is_struct() => { @@ -139,7 +129,7 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( adt, args, parent_cause.clone(), - hir::LangItem::ConstParamTy, + lang_item, ) .map_err(ConstParamTyImplementationError::InfrigingFields)?; @@ -159,7 +149,7 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( parent_cause.clone(), param_env, inner_ty, - tcx.require_lang_item(LangItem::ConstParamTy, Some(parent_cause.span)), + tcx.require_lang_item(lang_item, Some(parent_cause.span)), ); let errors = ocx.select_all_or_error(); diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 49f89e702558f..d0622182ea969 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -248,6 +248,7 @@ #![feature(transparent_unions)] #![feature(try_blocks)] #![feature(unboxed_closures)] +#![feature(unsized_const_params)] #![feature(unsized_fn_params)] #![feature(with_negative_coherence)] // tidy-alphabetical-end diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 70bd4f67ebfde..a87528033c03b 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -975,41 +975,74 @@ pub trait PointerLike {} /// that all fields are also `ConstParamTy`, which implies that recursively, all fields /// are `StructuralPartialEq`. #[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")] #[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`. #[rustc_builtin_macro] +#[allow_internal_unstable(unsized_const_params)] #[unstable(feature = "adt_const_params", issue = "95174")] pub macro ConstParamTy($item:item) { /* 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` marker_impls! { #[unstable(feature = "adt_const_params", issue = "95174")] - ConstParamTy for + ConstParamTy_ for usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128, bool, char, (), - {T: ConstParamTy, const N: usize} [T; N], + {T: ConstParamTy_, const N: usize} [T; N], +} +#[cfg(bootstrap)] +marker_impls! { + #[unstable(feature = "adt_const_params", issue = "95174")] + ConstParamTy_ for + str, + {T: ConstParamTy_} [T], + {T: ConstParamTy_ + ?Sized} &T, } -#[unstable(feature = "adt_const_params", issue = "95174")] -#[rustc_reservation_impl = "types that are not `Sized` are not supported as the type of a const generic parameter"] -impl ConstParamTy for [T] {} - -#[unstable(feature = "adt_const_params", issue = "95174")] -#[rustc_reservation_impl = "types that are not `Sized` are not supported as the type of a const generic parameter"] -impl ConstParamTy for str {} +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], -#[unstable(feature = "adt_const_params", issue = "95174")] -#[rustc_reservation_impl = "references are not supported as the type of a const generic parameter"] -impl ConstParamTy for &T {} + str, + {T: UnsizedConstParamTy} [T], + {T: UnsizedConstParamTy + ?Sized} &T, +} /// A common trait implemented by all function pointers. #[unstable( diff --git a/library/core/src/mem/transmutability.rs b/library/core/src/mem/transmutability.rs index 827426b235839..ea73c5b80ba44 100644 --- a/library/core/src/mem/transmutability.rs +++ b/library/core/src/mem/transmutability.rs @@ -1,4 +1,4 @@ -use crate::marker::ConstParamTy; +use crate::marker::{ConstParamTy_, UnsizedConstParamTy}; /// Are values of a type transmutable into values of another type? /// @@ -39,7 +39,9 @@ pub struct Assume { } #[unstable(feature = "transmutability", issue = "99571")] -impl ConstParamTy for Assume {} +impl ConstParamTy_ for Assume {} +#[unstable(feature = "transmutability", issue = "99571")] +impl UnsizedConstParamTy for Assume {} impl Assume { /// Do not assume that *you* have ensured any safety properties are met. diff --git a/library/core/src/tuple.rs b/library/core/src/tuple.rs index 8e961d8adc372..bc376b13f64d9 100644 --- a/library/core/src/tuple.rs +++ b/library/core/src/tuple.rs @@ -1,8 +1,9 @@ // See core/src/primitive_docs.rs for documentation. use crate::cmp::Ordering::{self, *}; -use crate::marker::ConstParamTy; +use crate::marker::ConstParamTy_; use crate::marker::StructuralPartialEq; +use crate::marker::UnsizedConstParamTy; // Recursive macro for implementing n-ary tuple functions and operations // @@ -49,8 +50,15 @@ macro_rules! tuple_impls { maybe_tuple_doc! { $($T)+ @ - #[unstable(feature = "structural_match", issue = "31434")] - impl<$($T: ConstParamTy),+> ConstParamTy for ($($T,)+) + #[unstable(feature = "adt_const_params", issue = "95174")] + impl<$($T: ConstParamTy_),+> ConstParamTy_ for ($($T,)+) + {} + } + + maybe_tuple_doc! { + $($T)+ @ + #[unstable(feature = "unsized_const_params", issue = "95174")] + impl<$($T: UnsizedConstParamTy),+> UnsizedConstParamTy for ($($T,)+) {} } diff --git a/tests/crashes/119299.rs b/tests/crashes/119299.rs deleted file mode 100644 index c8c10546d9409..0000000000000 --- a/tests/crashes/119299.rs +++ /dev/null @@ -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() -> [char; 3] { - ['a','b','c'] -} - -fn main() { - const A: &'static ConstStrU = &ConstStrU::from_bytes(b"abc"); - chars_s::(); -} diff --git a/tests/mir-opt/const_prop/invalid_constant.rs b/tests/mir-opt/const_prop/invalid_constant.rs index 91ee36ae2c54f..b59103792bfc4 100644 --- a/tests/mir-opt/const_prop/invalid_constant.rs +++ b/tests/mir-opt/const_prop/invalid_constant.rs @@ -3,7 +3,7 @@ //@ compile-flags: -Zmir-enable-passes=+RemoveZsts // Verify that we can pretty print invalid constants. -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] #[derive(Copy, Clone)] diff --git a/tests/mir-opt/issue_99325.rs b/tests/mir-opt/issue_99325.rs index 2638b69e2ee5b..4cee4f20b31b3 100644 --- a/tests/mir-opt/issue_99325.rs +++ b/tests/mir-opt/issue_99325.rs @@ -1,7 +1,7 @@ // skip-filecheck // EMIT_MIR_FOR_EACH_BIT_WIDTH -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub fn function_with_bytes() -> &'static [u8] { diff --git a/tests/rustdoc/const-generics/const-impl.rs b/tests/rustdoc/const-generics/const-impl.rs index ce536291290d6..279a78422541b 100644 --- a/tests/rustdoc/const-generics/const-impl.rs +++ b/tests/rustdoc/const-generics/const-impl.rs @@ -1,5 +1,5 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![crate_name = "foo"] use std::marker::ConstParamTy; diff --git a/tests/ui/coherence/negative-coherence/regions-in-canonical.rs b/tests/ui/coherence/negative-coherence/regions-in-canonical.rs index 6c2a11e013583..f0424e724344b 100644 --- a/tests/ui/coherence/negative-coherence/regions-in-canonical.rs +++ b/tests/ui/coherence/negative-coherence/regions-in-canonical.rs @@ -1,13 +1,12 @@ //@ check-pass -#![feature(adt_const_params)] -//~^ WARN the feature `adt_const_params` is incomplete +#![feature(adt_const_params, unsized_const_params)] +//~^ WARN the feature `unsized_const_params` is incomplete #![feature(with_negative_coherence, negative_impls)] pub trait A {} pub trait C {} - struct W(T); // Negative coherence: diff --git a/tests/ui/coherence/negative-coherence/regions-in-canonical.stderr b/tests/ui/coherence/negative-coherence/regions-in-canonical.stderr index dc8c926f182b4..720449152945d 100644 --- a/tests/ui/coherence/negative-coherence/regions-in-canonical.stderr +++ b/tests/ui/coherence/negative-coherence/regions-in-canonical.stderr @@ -1,8 +1,8 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/regions-in-canonical.rs:3:12 +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:30 | -LL | #![feature(adt_const_params)] - | ^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params)] + | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #95174 for more information = note: `#[warn(incomplete_features)]` on by default diff --git a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.rs b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.rs index 8035fce09147d..e90426ec0c762 100644 --- a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.rs +++ b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.rs @@ -1,7 +1,6 @@ //@ check-pass #![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]; const EMPTY_MATRIX: Matrix = [0; 1]; diff --git a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.stderr b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.stderr index 5c6981077b2d1..4f5133474c608 100644 --- a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.stderr +++ b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-1.stderr @@ -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 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 --> $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 for more information + = note: `#[warn(incomplete_features)]` on by default -warning: 2 warnings emitted +warning: 1 warning emitted diff --git a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.rs b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.rs index a576b75341cf0..961e1a9cfbf43 100644 --- a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.rs +++ b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.rs @@ -1,6 +1,5 @@ //@ check-pass #![feature(adt_const_params)] -//~^ WARN: the feature `adt_const_params` is incomplete const EMPTY_MATRIX: ::Matrix = [0; 1]; diff --git a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.stderr b/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.stderr deleted file mode 100644 index dbc8ab716365e..0000000000000 --- a/tests/ui/const-generics/adt_const_params/alias_const_param_ty-2.stderr +++ /dev/null @@ -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 for more information - = note: `#[warn(incomplete_features)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/const-generics/adt_const_params/auxiliary/unsized_const_param.rs b/tests/ui/const-generics/adt_const_params/auxiliary/unsized_const_param.rs new file mode 100644 index 0000000000000..e2ba459f8dd33 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/auxiliary/unsized_const_param.rs @@ -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); diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs index c4d2d02ba7034..35539193a2787 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs @@ -1,13 +1,13 @@ #![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() { - 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(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(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(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 () 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 } diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr index d96491f4f20ea..694f5a5c1a9da 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr @@ -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 | 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 | note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` help: use parentheses to call this function | 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 | 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 | note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` help: use parentheses to call this closure | 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 | 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 | note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` help: use parentheses to call this function pointer | 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 | 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 | - = 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` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` help: consider removing the leading `&`-reference | 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 | 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 | - = help: the trait `ConstParamTy` is implemented for `()` + = help: the trait `UnsizedConstParamTy` is implemented for `()` note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error[E0277]: `*const ()` can't be used as a const parameter type --> $DIR/const_param_ty_bad.rs:12:11 | 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 | - = help: the trait `ConstParamTy` is implemented for `()` + = help: the trait `UnsizedConstParamTy` is implemented for `()` note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | -LL | fn check(_: impl std::marker::ConstParamTy) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check(_: impl std::marker::UnsizedConstParamTy) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error: aborting due to 6 previous errors diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.rs index b0e3b13cc1ef9..2008a96310a8b 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.rs @@ -1,10 +1,10 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #[derive(PartialEq, Eq)] struct NotParam; -fn check() {} +fn check() {} fn main() { check::<[NotParam; 0]>(); diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.stderr index 771d661f615ec..9852e181b9ac5 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad_empty_array.stderr @@ -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 | 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` --> $DIR/const_param_ty_bad_empty_array.rs:7:13 | -LL | fn check() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs index e4dc76703a2d8..7ffdafa33e938 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs @@ -1,13 +1,13 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #[derive(PartialEq, Eq)] struct NotParam; -fn check() {} +fn check() {} 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 } diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr index 83c34c41f1059..e63ae582fd575 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr @@ -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 | 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` --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13 | -LL | fn check() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error[E0277]: `NotParam` can't be used as a const parameter type --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:11:13 | 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` --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13 | -LL | fn check() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error[E0277]: `NotParam` can't be used as a const parameter type --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:12:13 | 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` --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13 | -LL | fn check() {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` +LL | fn check() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check` error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs index bce24059de8e0..98a8eb6ee950d 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs @@ -1,7 +1,9 @@ //@ check-pass + +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] -#![feature(adt_const_params)] -use std::marker::ConstParamTy; + +use std::marker::UnsizedConstParamTy; #[derive(PartialEq, Eq)] struct S { @@ -9,16 +11,15 @@ struct S { gen: T, } -impl ConstParamTy for S {} +impl UnsizedConstParamTy for S {} -#[derive(PartialEq, Eq, ConstParamTy)] +#[derive(PartialEq, Eq, UnsizedConstParamTy)] struct D { field: u8, gen: T, } - -fn check() {} +fn check() {} fn main() { check::(); diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs index 74283a37afcaf..8b3d0546010dc 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs @@ -1,5 +1,5 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #[derive(PartialEq, Eq)] struct NotParam; @@ -7,11 +7,11 @@ struct NotParam; #[derive(PartialEq, Eq)] struct CantParam(NotParam); -impl std::marker::ConstParamTy for CantParam {} -//~^ error: the trait `ConstParamTy` cannot be implemented for this type +impl std::marker::UnsizedConstParamTy for CantParam {} +//~^ error: the trait `ConstParamTy_` cannot be implemented for this type -#[derive(std::marker::ConstParamTy, Eq, PartialEq)] -//~^ error: the trait `ConstParamTy` cannot be implemented for this type +#[derive(std::marker::UnsizedConstParamTy, Eq, PartialEq)] +//~^ error: the trait `ConstParamTy_` cannot be implemented for this type struct CantParamDerive(NotParam); fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr index 52b65d6061ab5..808a569fcadf8 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr @@ -1,22 +1,22 @@ -error[E0204]: the trait `ConstParamTy` cannot be implemented for this type - --> $DIR/const_param_ty_impl_bad_field.rs:10:36 +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/const_param_ty_impl_bad_field.rs:10:43 | LL | struct CantParam(NotParam); - | -------- this field does not implement `ConstParamTy` + | -------- this field does not implement `ConstParamTy_` 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 | -LL | #[derive(std::marker::ConstParamTy, Eq, PartialEq)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[derive(std::marker::UnsizedConstParamTy, Eq, PartialEq)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | 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 diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs index dfb8a36ec5350..761a6387a24e9 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs @@ -1,22 +1,22 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #[derive(PartialEq, Eq)] struct ImplementsConstParamTy; -impl std::marker::ConstParamTy for ImplementsConstParamTy {} +impl std::marker::UnsizedConstParamTy for ImplementsConstParamTy {} struct CantParam(ImplementsConstParamTy); -impl std::marker::ConstParamTy for CantParam {} +impl std::marker::UnsizedConstParamTy for CantParam {} //~^ error: the type `CantParam` does not `#[derive(PartialEq)]` //~| the trait bound `CantParam: Eq` is not satisfied -#[derive(std::marker::ConstParamTy)] +#[derive(std::marker::UnsizedConstParamTy)] //~^ error: the type `CantParamDerive` does not `#[derive(PartialEq)]` //~| the trait bound `CantParamDerive: Eq` is not satisfied struct CantParamDerive(ImplementsConstParamTy); -fn check() {} +fn check() {} fn main() { check::(); diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr index e213808cf7bd6..80d9942c5914e 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr @@ -1,10 +1,10 @@ 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 {} - | ^^^^^^^^^ the trait `Eq` is not implemented for `CantParam` +LL | impl std::marker::UnsizedConstParamTy 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 help: consider annotating `CantParam` with `#[derive(Eq)]` | @@ -13,23 +13,23 @@ LL | struct CantParam(ImplementsConstParamTy); | 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 {} - | ^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `CantParam` +LL | impl std::marker::UnsizedConstParamTy 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 error[E0277]: the trait bound `CantParamDerive: Eq` is not satisfied --> $DIR/const_param_ty_impl_no_structural_eq.rs:14:10 | -LL | #[derive(std::marker::ConstParamTy)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq` is not implemented for `CantParamDerive` +LL | #[derive(std::marker::UnsizedConstParamTy)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - = 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)]` | LL + #[derive(Eq)] @@ -39,12 +39,12 @@ LL | struct CantParamDerive(ImplementsConstParamTy); error[E0277]: the type `CantParamDerive` does not `#[derive(PartialEq)]` --> $DIR/const_param_ty_impl_no_structural_eq.rs:14:10 | -LL | #[derive(std::marker::ConstParamTy)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `StructuralPartialEq` is not implemented for `CantParamDerive` +LL | #[derive(std::marker::UnsizedConstParamTy)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - = 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 diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs index f2986f9cc60d5..236b3bc162aaa 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs @@ -1,5 +1,5 @@ #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] union Union { a: u8, @@ -12,10 +12,10 @@ impl PartialEq for Union { } impl Eq for Union {} -impl std::marker::ConstParamTy for Union {} -//~^ ERROR the type `Union` does not `#[derive(PartialEq)]` +impl std::marker::UnsizedConstParamTy for Union {} +//~^ 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 union UnionDerive { a: u8, @@ -28,5 +28,4 @@ impl PartialEq for UnionDerive { } impl Eq for UnionDerive {} - fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr index 4c937db6c3ab5..837c289c9248f 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr @@ -1,18 +1,14 @@ error: this trait cannot be derived for unions --> $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)]` - --> $DIR/const_param_ty_impl_union.rs:15:36 +error: the trait `ConstParamTy` may not be implemented for this type + --> $DIR/const_param_ty_impl_union.rs:15:43 | -LL | impl std::marker::ConstParamTy for Union {} - | ^^^^^ the trait `StructuralPartialEq` is not implemented for `Union` - | -note: required by a bound in `ConstParamTy` - --> $SRC_DIR/core/src/marker.rs:LL:COL +LL | impl std::marker::UnsizedConstParamTy for Union {} + | ^^^^^ type is not a structure or enumeration error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs new file mode 100644 index 0000000000000..6a553c2e08540 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs @@ -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() {} diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr new file mode 100644 index 0000000000000..ba38f63d5df7b --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr @@ -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 + --> $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 + --> $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`. diff --git a/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs index 0d1f023d565fb..7a4970c2e3c9c 100644 --- a/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs +++ b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.rs @@ -1,18 +1,30 @@ // issue: rust-lang/rust/#83993 #![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>() where for<'b> [(); { let x: &'b (); //~^ ERROR generic parameters may not be used in const operations 0 - }]: -{} + }]:, +{ +} -fn bad() where for<'b> [();{let _:&'b (); 0}]: Sized { } -//~^ ERROR generic parameters may not be used in const operations -fn good() where for<'b> [();{0}]: Sized { } +fn bad() +where + 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() {} diff --git a/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr index a49dfc319167b..b7e459511f15c 100644 --- a/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr +++ b/tests/ui/const-generics/adt_const_params/index-oob-ice-83993.stderr @@ -8,22 +8,13 @@ LL | let x: &'b (); = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions 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 { } - | ^^ cannot perform const operation using `'b` +LL | let _: &'b (); + | ^^ cannot perform const operation using `'b` | = note: lifetime parameters may not be used in 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 - --> $DIR/index-oob-ice-83993.rs:3:12 - | -LL | #![feature(adt_const_params)] - | ^^^^^^^^^^^^^^^^ - | - = note: see issue #95174 for more information - = note: `#[warn(incomplete_features)]` on by default - -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.rs b/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.rs index 9f05c53eef0f6..3a283442a0b01 100644 --- a/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.rs +++ b/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.rs @@ -4,15 +4,18 @@ use std::marker::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]); #[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]); #[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]); fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.stderr b/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.stderr index 9e772e8d55df9..c2520f1d10386 100644 --- a/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.stderr +++ b/tests/ui/const-generics/adt_const_params/nested_bad_const_param_ty.stderr @@ -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 | LL | #[derive(ConstParamTy)] | ^^^^^^^^^^^^ -LL | +... 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` - --> $DIR/nested_bad_const_param_ty.rs:8:12 +note: the `ConstParamTy_` impl for `[*const u8; 1]` requires that `*const u8: ConstParamTy_` + --> $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:10:10 +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/nested_bad_const_param_ty.rs:11:10 | LL | #[derive(ConstParamTy)] | ^^^^^^^^^^^^ -LL | +... 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` - --> $DIR/nested_bad_const_param_ty.rs:12:13 +note: the `ConstParamTy_` impl for `[*mut u8; 1]` requires that `*mut u8: ConstParamTy_` + --> $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:14:10 +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/nested_bad_const_param_ty.rs:16:10 | LL | #[derive(ConstParamTy)] | ^^^^^^^^^^^^ -LL | +... 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` - --> $DIR/nested_bad_const_param_ty.rs:16:13 +note: the `ConstParamTy_` impl for `[fn(); 1]` requires that `fn(): ConstParamTy_` + --> $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 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`. diff --git a/tests/ui/const-generics/adt_const_params/opaque_type_with_non-universal_region_substs_ice-111911.rs b/tests/ui/const-generics/adt_const_params/opaque_type_with_non-universal_region_substs_ice-111911.rs index c55f3dcec68ca..f28bebf85db50 100644 --- a/tests/ui/const-generics/adt_const_params/opaque_type_with_non-universal_region_substs_ice-111911.rs +++ b/tests/ui/const-generics/adt_const_params/opaque_type_with_non-universal_region_substs_ice-111911.rs @@ -3,7 +3,7 @@ // issues rust-lang/rust#111911 // test for ICE opaque type with non-universal region substs -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub async fn foo() {} diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs new file mode 100644 index 0000000000000..a1ee1c4cdd585 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs @@ -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() {} diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr new file mode 100644 index 0000000000000..5ca8e6c75167f --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr @@ -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`. diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs new file mode 100644 index 0000000000000..ac1b522f469e1 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs @@ -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() -> [char; 3] { + ['a', 'b', 'c'] +} + +fn main() { + const A: &'static ConstStrU = &ConstStrU::from_bytes(b"abc"); + chars_s::(); +} diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr new file mode 100644 index 0000000000000..5e5f6cc642d33 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr @@ -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`. diff --git a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs index 0d2e65c45eaf5..33988bc067850 100644 --- a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs +++ b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.rs @@ -8,9 +8,8 @@ fn uwu_0() {} //~| 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(unsized_const_params)]` // Needs the feature but can be used, so suggest adding the feature. fn owo_0() {} diff --git a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr index cd4349623d722..aafc0640dd2da 100644 --- a/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr +++ b/tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.stderr @@ -7,7 +7,7 @@ LL | fn uwu_0() {} = note: the only supported types are integers, `bool` and `char` 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() {} | ^^^^^^^^^^^^ @@ -17,9 +17,13 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 - --> $DIR/suggest_feature_only_when_possible.rs:24:20 + --> $DIR/suggest_feature_only_when_possible.rs:23:20 | LL | fn meow_0() {} | ^^^^ @@ -31,7 +35,7 @@ LL + #![feature(adt_const_params)] | 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() {} | ^^^^^^^^^^^^^ @@ -41,45 +45,37 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 - --> $DIR/suggest_feature_only_when_possible.rs:28:20 + --> $DIR/suggest_feature_only_when_possible.rs:27:20 | LL | fn meow_2() {} | ^^^^^^^^^^^ | = 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 - --> $DIR/suggest_feature_only_when_possible.rs:30:20 + --> $DIR/suggest_feature_only_when_possible.rs:29:20 | LL | fn meow_3() {} | ^^^^^^^^^^ | = 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 - --> $DIR/suggest_feature_only_when_possible.rs:35:20 + --> $DIR/suggest_feature_only_when_possible.rs:34:20 | LL | fn meow_4() {} | ^^^^^^^^^^^^^^ | = 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 - --> $DIR/suggest_feature_only_when_possible.rs:39:19 + --> $DIR/suggest_feature_only_when_possible.rs:38:19 | LL | fn nya_0() {} | ^^^^^^ @@ -87,7 +83,7 @@ LL | fn nya_0() {} = note: the only supported types are integers, `bool` and `char` error: `Vec` 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>() {} | ^^^^^^^^ diff --git a/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs new file mode 100644 index 0000000000000..b0934508399d5 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs @@ -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() {} + +fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr new file mode 100644 index 0000000000000..9933ba6e335b7 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr @@ -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 + diff --git a/tests/ui/const-generics/adt_const_params/unsized_field-1.rs b/tests/ui/const-generics/adt_const_params/unsized_field-1.rs new file mode 100644 index 0000000000000..f6e5bd6e355da --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/unsized_field-1.rs @@ -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() {} diff --git a/tests/ui/const-generics/adt_const_params/unsized_field-1.stderr b/tests/ui/const-generics/adt_const_params/unsized_field-1.stderr new file mode 100644 index 0000000000000..7a4f9b99c6379 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/unsized_field-1.stderr @@ -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`. diff --git a/tests/ui/const-generics/adt_const_params/unsized_field-2.rs b/tests/ui/const-generics/adt_const_params/unsized_field-2.rs new file mode 100644 index 0000000000000..e4a3a481b4e37 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/unsized_field-2.rs @@ -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() {} diff --git a/tests/ui/const-generics/adt_const_params/unsized_field-2.stderr b/tests/ui/const-generics/adt_const_params/unsized_field-2.stderr new file mode 100644 index 0000000000000..15acece538fd7 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/unsized_field-2.stderr @@ -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 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`. diff --git a/tests/ui/const-generics/const-param-elided-lifetime.min.stderr b/tests/ui/const-generics/const-param-elided-lifetime.min.stderr index 1c81b14f8f5c2..62267224738d0 100644 --- a/tests/ui/const-generics/const-param-elided-lifetime.min.stderr +++ b/tests/ui/const-generics/const-param-elided-lifetime.min.stderr @@ -39,6 +39,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 --> $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)] | +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 --> $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)] | +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 --> $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)] | +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 --> $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)] | +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 diff --git a/tests/ui/const-generics/const-param-elided-lifetime.rs b/tests/ui/const-generics/const-param-elided-lifetime.rs index ef1eecb59be9d..e75073de98d30 100644 --- a/tests/ui/const-generics/const-param-elided-lifetime.rs +++ b/tests/ui/const-generics/const-param-elided-lifetime.rs @@ -3,7 +3,7 @@ // elided lifetimes within the type of a const generic parameters to be 'static, like elided // lifetimes within const/static items. //@ 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))] struct A; @@ -12,8 +12,8 @@ struct A; trait B {} impl A { -//~^ ERROR `&` without an explicit lifetime name cannot be used here -//[min]~^^ ERROR `&u8` is forbidden + //~^ ERROR `&` without an explicit lifetime name cannot be used here + //[min]~^^ ERROR `&u8` is forbidden fn foo(&self) {} //~^ ERROR `&` without an explicit lifetime name cannot be used here //[min]~^^ ERROR `&u8` is forbidden diff --git a/tests/ui/const-generics/const-param-with-additional-obligations.rs b/tests/ui/const-generics/const-param-with-additional-obligations.rs index f53cf85cdd39c..98097e86c7dfe 100644 --- a/tests/ui/const-generics/const-param-with-additional-obligations.rs +++ b/tests/ui/const-generics/const-param-with-additional-obligations.rs @@ -1,14 +1,14 @@ -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] -use std::marker::ConstParamTy; +use std::marker::UnsizedConstParamTy; #[derive(Eq, PartialEq)] struct Foo(T); trait Other {} -impl ConstParamTy for Foo where T: Other + ConstParamTy {} +impl UnsizedConstParamTy for Foo where T: Other + UnsizedConstParamTy {} fn foo>() {} //~^ ERROR `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter diff --git a/tests/ui/const-generics/float-generic.adt_const_params.stderr b/tests/ui/const-generics/float-generic.adt_const_params.stderr index cae4806368a90..1a7c19ba4be6e 100644 --- a/tests/ui/const-generics/float-generic.adt_const_params.stderr +++ b/tests/ui/const-generics/float-generic.adt_const_params.stderr @@ -1,5 +1,5 @@ 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() {} | ^^^ diff --git a/tests/ui/const-generics/float-generic.full.stderr b/tests/ui/const-generics/float-generic.full.stderr new file mode 100644 index 0000000000000..1a7c19ba4be6e --- /dev/null +++ b/tests/ui/const-generics/float-generic.full.stderr @@ -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() {} + | ^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0741`. diff --git a/tests/ui/const-generics/float-generic.rs b/tests/ui/const-generics/float-generic.rs index aaf63a93d708e..f92e1667701b6 100644 --- a/tests/ui/const-generics/float-generic.rs +++ b/tests/ui/const-generics/float-generic.rs @@ -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, allow(incomplete_features))] diff --git a/tests/ui/const-generics/float-generic.simple.stderr b/tests/ui/const-generics/float-generic.simple.stderr index eccf9059ee335..2999bce32d6ad 100644 --- a/tests/ui/const-generics/float-generic.simple.stderr +++ b/tests/ui/const-generics/float-generic.simple.stderr @@ -1,5 +1,5 @@ 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() {} | ^^^ diff --git a/tests/ui/const-generics/fn-const-param-call.adt_const_params.stderr b/tests/ui/const-generics/fn-const-param-call.adt_const_params.stderr new file mode 100644 index 0000000000000..fd9346a533ec2 --- /dev/null +++ b/tests/ui/const-generics/fn-const-param-call.adt_const_params.stderr @@ -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 u32>; + | ^^^^^^^^^^^ + +error[E0741]: using function pointers as const generic parameters is forbidden + --> $DIR/fn-const-param-call.rs:15:15 + | +LL | impl u32> Wrapper { + | ^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0741`. diff --git a/tests/ui/const-generics/fn-const-param-call.full.stderr b/tests/ui/const-generics/fn-const-param-call.full.stderr index b55c2449858c9..fd9346a533ec2 100644 --- a/tests/ui/const-generics/fn-const-param-call.full.stderr +++ b/tests/ui/const-generics/fn-const-param-call.full.stderr @@ -1,11 +1,11 @@ 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 u32>; | ^^^^^^^^^^^ 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 u32> Wrapper { | ^^^^^^^^^^^ diff --git a/tests/ui/const-generics/fn-const-param-call.min.stderr b/tests/ui/const-generics/fn-const-param-call.min.stderr index 2d316fba1e90a..d37766b28c9ce 100644 --- a/tests/ui/const-generics/fn-const-param-call.min.stderr +++ b/tests/ui/const-generics/fn-const-param-call.min.stderr @@ -1,5 +1,5 @@ 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 u32>; | ^^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | struct Wrapper u32>; = note: the only supported types are integers, `bool` and `char` 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 u32> Wrapper { | ^^^^^^^^^^^ diff --git a/tests/ui/const-generics/fn-const-param-call.rs b/tests/ui/const-generics/fn-const-param-call.rs index ce780143178a3..d536c24023928 100644 --- a/tests/ui/const-generics/fn-const-param-call.rs +++ b/tests/ui/const-generics/fn-const-param-call.rs @@ -1,8 +1,10 @@ // 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(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] fn function() -> u32 { 17 @@ -11,7 +13,7 @@ fn function() -> u32 { struct Wrapper u32>; //~ ERROR: using function pointers as const generic parameters impl u32> Wrapper { -//~^ ERROR: using function pointers as const generic parameters + //~^ ERROR: using function pointers as const generic parameters fn call() -> u32 { F() } diff --git a/tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr b/tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr new file mode 100644 index 0000000000000..54f3bff172af6 --- /dev/null +++ b/tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr @@ -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 bool>; + | ^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/fn-const-param-infer.rs:33:25 + | +LL | let _ = Checked::<{ generic_arg:: }>; + | ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item + | + = note: expected fn pointer `fn(usize) -> _` + found fn item `fn(u32) -> _ {generic_arg::}` + +error[E0282]: type annotations needed + --> $DIR/fn-const-param-infer.rs:35:23 + | +LL | let _ = Checked::; + | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic` + | +help: consider specifying the generic argument + | +LL | let _ = Checked::>; + | +++++ + +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`. diff --git a/tests/ui/const-generics/fn-const-param-infer.full.stderr b/tests/ui/const-generics/fn-const-param-infer.full.stderr index 753558636e1ef..54f3bff172af6 100644 --- a/tests/ui/const-generics/fn-const-param-infer.full.stderr +++ b/tests/ui/const-generics/fn-const-param-infer.full.stderr @@ -1,20 +1,20 @@ 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 bool>; | ^^^^^^^^^^^^^^^^^ 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::}>; - | ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item +LL | let _ = Checked::<{ generic_arg:: }>; + | ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item | = note: expected fn pointer `fn(usize) -> _` found fn item `fn(u32) -> _ {generic_arg::}` error[E0282]: type annotations needed - --> $DIR/fn-const-param-infer.rs:25:23 + --> $DIR/fn-const-param-infer.rs:35:23 | LL | let _ = Checked::; | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic` diff --git a/tests/ui/const-generics/fn-const-param-infer.min.stderr b/tests/ui/const-generics/fn-const-param-infer.min.stderr index 01e224f8d9ca7..4da503d344a1a 100644 --- a/tests/ui/const-generics/fn-const-param-infer.min.stderr +++ b/tests/ui/const-generics/fn-const-param-infer.min.stderr @@ -1,5 +1,5 @@ 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 bool>; | ^^^^^^^^^^^^^^^^^ @@ -7,16 +7,16 @@ LL | struct Checked bool>; = note: the only supported types are integers, `bool` and `char` 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::}>; - | ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item +LL | let _ = Checked::<{ generic_arg:: }>; + | ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item | = note: expected fn pointer `fn(usize) -> _` found fn item `fn(u32) -> _ {generic_arg::}` error[E0282]: type annotations needed - --> $DIR/fn-const-param-infer.rs:25:23 + --> $DIR/fn-const-param-infer.rs:35:23 | LL | let _ = Checked::; | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic` diff --git a/tests/ui/const-generics/fn-const-param-infer.rs b/tests/ui/const-generics/fn-const-param-infer.rs index ed0bb9f721701..5f1958df26e05 100644 --- a/tests/ui/const-generics/fn-const-param-infer.rs +++ b/tests/ui/const-generics/fn-const-param-infer.rs @@ -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(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] struct Checked bool>; //~^ ERROR: using function pointers as const generic parameters -fn not_one(val: usize) -> bool { val != 1 } -fn not_two(val: usize) -> bool { val != 2 } +fn not_one(val: usize) -> bool { + val != 1 +} +fn not_two(val: usize) -> bool { + val != 2 +} -fn generic_arg(val: T) -> bool { true } +fn generic_arg(val: T) -> bool { + true +} -fn generic(val: usize) -> bool { val != 1 } +fn generic(val: usize) -> bool { + val != 1 +} fn main() { let _: Option> = None; @@ -19,11 +29,11 @@ fn main() { let _: Checked = Checked::; let _ = Checked::; - let _ = Checked::<{generic_arg::}>; - let _ = Checked::<{generic_arg::}>; //~ ERROR: mismatched types + let _ = Checked::<{ generic_arg:: }>; + let _ = Checked::<{ generic_arg:: }>; //~ ERROR: mismatched types let _ = Checked::; //~ ERROR: type annotations needed - let _ = Checked::<{generic::}>; - let _: Checked<{generic::}> = Checked::<{generic::}>; - let _: Checked<{generic::}> = Checked::<{generic::}>; + let _ = Checked::<{ generic:: }>; + let _: Checked<{ generic:: }> = Checked::<{ generic:: }>; + let _: Checked<{ generic:: }> = Checked::<{ generic:: }>; } diff --git a/tests/ui/const-generics/generic_const_exprs/issue-100360.rs b/tests/ui/const-generics/generic_const_exprs/issue-100360.rs index b7e677a4a1e55..37f015d5e0f21 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-100360.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-100360.rs @@ -1,7 +1,7 @@ //@ check-pass // (this requires debug assertions) -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] fn foo(arg: &'static bool) -> bool { diff --git a/tests/ui/const-generics/generic_const_exprs/issue-89851.rs b/tests/ui/const-generics/generic_const_exprs/issue-89851.rs index 78189c5225cd9..f93ba30856dcb 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-89851.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-89851.rs @@ -1,7 +1,7 @@ //@ check-pass // (this requires debug assertions) -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub const BAR: () = ice::<"">(); diff --git a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.rs b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.rs index 5a6565fe2f1e0..443d0a2fe87a2 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.rs @@ -1,7 +1,7 @@ //@ check-pass -#![feature(adt_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] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] +//~^ 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] pub struct Changes @@ -16,9 +16,7 @@ where [(); CHANGES.len()]:, { pub const fn new() -> Self { - Self { - changes: [0; CHANGES.len()], - } + Self { changes: [0; CHANGES.len()] } } } diff --git a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr index 1cceaece715bb..b6b297593a255 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr @@ -1,17 +1,17 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-97047-ice-1.rs:3:12 +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:30 | -LL | #![feature(adt_const_params, generic_const_exprs)] - | ^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params, generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #95174 for more information = 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 - --> $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 for more information diff --git a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.rs b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.rs index 1338f40208c57..6a91b52256728 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.rs @@ -1,7 +1,7 @@ //@ check-pass -#![feature(adt_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] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] +//~^ 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] pub struct Changes diff --git a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr index 774e842bcbeab..c0c7dcc79dc42 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr @@ -1,17 +1,17 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/issue-97047-ice-2.rs:3:12 +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:30 | -LL | #![feature(adt_const_params, generic_const_exprs)] - | ^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params, generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #95174 for more information = 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 - --> $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 for more information diff --git a/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr b/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr index 5e4acd80e9336..2a6d9f533174e 100644 --- a/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr +++ b/tests/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr @@ -1,14 +1,14 @@ 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::()}> - | ^ cannot perform const operation using `T` +LL | T: Trait<{ std::intrinsics::type_name::() }>, + | ^ cannot perform const operation using `T` | = note: type parameters may not be used in 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 - --> $DIR/intrinsics-type_name-as-const-argument.rs:10:22 + --> $DIR/intrinsics-type_name-as-const-argument.rs:9:22 | LL | trait Trait {} | ^^^^^^^^^^^^ @@ -18,6 +18,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 diff --git a/tests/ui/const-generics/intrinsics-type_name-as-const-argument.rs b/tests/ui/const-generics/intrinsics-type_name-as-const-argument.rs index 02e6d27a27e6c..79c20fe81e35c 100644 --- a/tests/ui/const-generics/intrinsics-type_name-as-const-argument.rs +++ b/tests/ui/const-generics/intrinsics-type_name-as-const-argument.rs @@ -2,8 +2,7 @@ //@ revisions: full min #![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(const_type_name)] @@ -12,10 +11,10 @@ trait Trait {} struct Bug where - T: Trait<{std::intrinsics::type_name::()}> + T: Trait<{ std::intrinsics::type_name::() }>, //[min]~^ ERROR generic parameters may not be used in const operations { - t: T + t: T, } fn main() {} diff --git a/tests/ui/const-generics/issue-66451.rs b/tests/ui/const-generics/issue-66451.rs index c8d5515e98739..0b8693e0e675d 100644 --- a/tests/ui/const-generics/issue-66451.rs +++ b/tests/ui/const-generics/issue-66451.rs @@ -1,30 +1,20 @@ -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] -use std::marker::ConstParamTy; +use std::marker::UnsizedConstParamTy; -#[derive(Debug, PartialEq, Eq, ConstParamTy)] +#[derive(Debug, PartialEq, Eq, UnsizedConstParamTy)] struct Foo { value: i32, nested: &'static Bar, } -#[derive(Debug, PartialEq, Eq, ConstParamTy)] +#[derive(Debug, PartialEq, Eq, UnsizedConstParamTy)] struct Bar(T); struct Test; fn main() { - let x: Test<{ - Foo { - value: 3, - nested: &Bar(4), - } - }> = Test; - let y: Test<{ - Foo { - value: 3, - nested: &Bar(5), - } - }> = x; //~ ERROR mismatched types + let x: Test<{ Foo { value: 3, nested: &Bar(4) } }> = Test; + let y: Test<{ Foo { value: 3, nested: &Bar(5) } }> = x; //~ ERROR mismatched types } diff --git a/tests/ui/const-generics/issue-66451.stderr b/tests/ui/const-generics/issue-66451.stderr index 404e3839bca90..63d193e1bca47 100644 --- a/tests/ui/const-generics/issue-66451.stderr +++ b/tests/ui/const-generics/issue-66451.stderr @@ -1,16 +1,10 @@ error[E0308]: mismatched types - --> $DIR/issue-66451.rs:29:10 + --> $DIR/issue-66451.rs:19:58 | -LL | let y: Test<{ - | ____________- -LL | | Foo { -LL | | value: 3, -LL | | nested: &Bar(5), -LL | | } -LL | | }> = x; - | | - ^ expected `Foo { value: 3, nested: &Bar::(5) }`, found `Foo { value: 3, nested: &Bar::(4) }` - | |______| - | expected due to this +LL | let y: Test<{ Foo { value: 3, nested: &Bar(5) } }> = x; + | ------------------------------------------- ^ expected `Foo { value: 3, nested: &Bar::(5) }`, found `Foo { value: 3, nested: &Bar::(4) }` + | | + | expected due to this | = note: expected struct `Test(5) }>` found struct `Test(4) }>` diff --git a/tests/ui/const-generics/issue-70408.rs b/tests/ui/const-generics/issue-70408.rs index e74bcf945a54f..ea7a57d3b2f9e 100644 --- a/tests/ui/const-generics/issue-70408.rs +++ b/tests/ui/const-generics/issue-70408.rs @@ -1,6 +1,6 @@ //@ build-pass -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub fn function_with_bytes() -> &'static [u8] { diff --git a/tests/ui/const-generics/issue-80471.rs b/tests/ui/const-generics/issue-80471.rs index fa6f1fde435a0..20d92092b9fa2 100644 --- a/tests/ui/const-generics/issue-80471.rs +++ b/tests/ui/const-generics/issue-80471.rs @@ -1,5 +1,4 @@ #![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)] enum Nat { diff --git a/tests/ui/const-generics/issue-80471.stderr b/tests/ui/const-generics/issue-80471.stderr index b21ad3aec7950..a8514c5cc0746 100644 --- a/tests/ui/const-generics/issue-80471.stderr +++ b/tests/ui/const-generics/issue-80471.stderr @@ -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 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 - --> $DIR/issue-80471.rs:10:17 + --> $DIR/issue-80471.rs:9:17 | LL | fn foo() {} | ^^^ @@ -19,6 +10,6 @@ LL + #[derive(ConstParamTy)] 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`. diff --git a/tests/ui/const-generics/issues/issue-100313.rs b/tests/ui/const-generics/issues/issue-100313.rs index 4e9d3626aa89c..e07fde76a4a83 100644 --- a/tests/ui/const-generics/issues/issue-100313.rs +++ b/tests/ui/const-generics/issues/issue-100313.rs @@ -1,10 +1,10 @@ #![allow(incomplete_features)] #![feature(const_mut_refs)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] struct T; -impl T { +impl T { const fn set_false(&self) { unsafe { *(B as *const bool as *mut bool) = false; @@ -14,7 +14,7 @@ impl T { } const _: () = { - let x = T::<{&true}>; + let x = T::<{ &true }>; x.set_false(); }; diff --git a/tests/ui/const-generics/issues/issue-105821.rs b/tests/ui/const-generics/issues/issue-105821.rs index ecbae4d9f35c8..3092893837aad 100644 --- a/tests/ui/const-generics/issues/issue-105821.rs +++ b/tests/ui/const-generics/issues/issue-105821.rs @@ -4,7 +4,7 @@ // a failing test, we just started masking the bug. #![allow(incomplete_features)] -#![feature(adt_const_params, generic_const_exprs)] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] #![allow(dead_code)] const fn catone(_a: &[u8; M]) -> [u8; M + 1] diff --git a/tests/ui/const-generics/issues/issue-56445-1.min.stderr b/tests/ui/const-generics/issues/issue-56445-1.min.stderr index 580542bb6da38..ff0a1bfc0b555 100644 --- a/tests/ui/const-generics/issues/issue-56445-1.min.stderr +++ b/tests/ui/const-generics/issues/issue-56445-1.min.stderr @@ -17,6 +17,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 diff --git a/tests/ui/const-generics/issues/issue-56445-1.rs b/tests/ui/const-generics/issues/issue-56445-1.rs index 35126b3f55ad6..53aab40b0ad4a 100644 --- a/tests/ui/const-generics/issues/issue-56445-1.rs +++ b/tests/ui/const-generics/issues/issue-56445-1.rs @@ -1,6 +1,6 @@ // Regression test for https://github.com/rust-lang/rust/issues/56445#issuecomment-518402995. //@ 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))] #![crate_type = "lib"] diff --git a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.full.stderr b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.full.stderr index 5082705927ee5..8ea96428deb3b 100644 --- a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.full.stderr +++ b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.full.stderr @@ -4,7 +4,7 @@ error[E0741]: `&'static (dyn A + 'static)` can't be used as a const parameter ty LL | fn test() { | ^^^^^^^^^^^^^^ | - = 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 diff --git a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr index 7f387cbd5a13f..101ca456cd90f 100644 --- a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr +++ b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.min.stderr @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 diff --git a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.rs b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.rs index c5b83e9d5298d..9b15a8a70132c 100644 --- a/tests/ui/const-generics/issues/issue-63322-forbid-dyn.rs +++ b/tests/ui/const-generics/issues/issue-63322-forbid-dyn.rs @@ -1,5 +1,5 @@ //@ 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))] trait A {} diff --git a/tests/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs b/tests/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs index 113bf94b5cb09..41c5eaa0cd9c3 100644 --- a/tests/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs +++ b/tests/ui/const-generics/issues/issue-66596-impl-trait-for-str-const-arg.rs @@ -1,8 +1,7 @@ //@ check-pass -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] - trait Trait { type Assoc; } diff --git a/tests/ui/const-generics/issues/issue-71547.rs b/tests/ui/const-generics/issues/issue-71547.rs index a2cea433a44de..bb9ca63bd3268 100644 --- a/tests/ui/const-generics/issues/issue-71547.rs +++ b/tests/ui/const-generics/issues/issue-71547.rs @@ -1,6 +1,6 @@ //@ check-pass -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub trait GetType { diff --git a/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr b/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr index e9363d421487f..cba03b1cb1f0f 100644 --- a/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr +++ b/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.min.stderr @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 diff --git a/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.rs b/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.rs index 701b3423f3190..fcab1f70507c5 100644 --- a/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.rs +++ b/tests/ui/const-generics/issues/issue-73727-static-reference-array-const-param.rs @@ -3,12 +3,12 @@ //@ revisions: full min //@[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))] fn a() {} //[min]~^ ERROR `&'static [u32]` is forbidden as the type of a const generic parameter fn main() { - a::<{&[]}>(); + a::<{ &[] }>(); } diff --git a/tests/ui/const-generics/issues/issue-86535-2.rs b/tests/ui/const-generics/issues/issue-86535-2.rs index bd9431dbc85b5..ab68c6b78df34 100644 --- a/tests/ui/const-generics/issues/issue-86535-2.rs +++ b/tests/ui/const-generics/issues/issue-86535-2.rs @@ -1,10 +1,12 @@ //@ run-pass -#![feature(adt_const_params, generic_const_exprs)] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] #![allow(incomplete_features)] pub trait Foo { const ASSOC_C: usize; - fn foo() where [(); Self::ASSOC_C]:; + fn foo() + where + [(); Self::ASSOC_C]:; } #[allow(dead_code)] @@ -12,7 +14,10 @@ struct Bar; impl Foo for Bar { 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 {}; } } diff --git a/tests/ui/const-generics/issues/issue-86535.rs b/tests/ui/const-generics/issues/issue-86535.rs index cd9934a4a9971..9aaf7ddc9e86e 100644 --- a/tests/ui/const-generics/issues/issue-86535.rs +++ b/tests/ui/const-generics/issues/issue-86535.rs @@ -1,5 +1,5 @@ //@ 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(dead_code)] diff --git a/tests/ui/const-generics/issues/issue-90455.fixed b/tests/ui/const-generics/issues/issue-90455.fixed index 2502d47eb4628..423a1fbd7657a 100644 --- a/tests/ui/const-generics/issues/issue-90455.fixed +++ b/tests/ui/const-generics/issues/issue-90455.fixed @@ -1,5 +1,5 @@ //@ run-rustfix -#![feature(generic_const_exprs, adt_const_params)] +#![feature(generic_const_exprs, unsized_const_params, adt_const_params)] #![allow(incomplete_features, dead_code)] struct FieldElement where [(); num_limbs(N)]: { diff --git a/tests/ui/const-generics/issues/issue-90455.rs b/tests/ui/const-generics/issues/issue-90455.rs index 794c7d76cb1f0..be4f27ec689a5 100644 --- a/tests/ui/const-generics/issues/issue-90455.rs +++ b/tests/ui/const-generics/issues/issue-90455.rs @@ -1,5 +1,5 @@ //@ run-rustfix -#![feature(generic_const_exprs, adt_const_params)] +#![feature(generic_const_exprs, unsized_const_params, adt_const_params)] #![allow(incomplete_features, dead_code)] struct FieldElement { diff --git a/tests/ui/const-generics/issues/issue-99641.stderr b/tests/ui/const-generics/issues/issue-99641.stderr index 800aec3ef2ce7..3365012a03841 100644 --- a/tests/ui/const-generics/issues/issue-99641.stderr +++ b/tests/ui/const-generics/issues/issue-99641.stderr @@ -4,7 +4,7 @@ error[E0741]: `(fn(),)` can't be used as a const parameter type LL | pub struct Color; | ^^^^^^^ | - = note: `fn()` must implement `ConstParamTy`, but it does not + = note: `fn()` must implement `ConstParamTy_`, but it does not error[E0741]: `(fn(),)` can't be used as a const parameter type --> $DIR/issue-99641.rs:8:23 @@ -12,7 +12,7 @@ error[E0741]: `(fn(),)` can't be used as a const parameter type LL | impl Color { | ^^^^^^^ | - = note: `fn()` must implement `ConstParamTy`, but it does not + = note: `fn()` must implement `ConstParamTy_`, but it does not error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/min_const_generics/complex-types.stderr b/tests/ui/const-generics/min_const_generics/complex-types.stderr index 8e83ea58194f7..0211770f9e51b 100644 --- a/tests/ui/const-generics/min_const_generics/complex-types.stderr +++ b/tests/ui/const-generics/min_const_generics/complex-types.stderr @@ -45,6 +45,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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: `!` is forbidden as the type of a const generic parameter --> $DIR/complex-types.rs:17:21 diff --git a/tests/ui/const-generics/raw-ptr-const-param-deref.adt_const_params.stderr b/tests/ui/const-generics/raw-ptr-const-param-deref.adt_const_params.stderr new file mode 100644 index 0000000000000..18f47f7dc23e6 --- /dev/null +++ b/tests/ui/const-generics/raw-ptr-const-param-deref.adt_const_params.stderr @@ -0,0 +1,15 @@ +error[E0741]: using raw pointers as const generic parameters is forbidden + --> $DIR/raw-ptr-const-param-deref.rs:11:23 + | +LL | struct Const; + | ^^^^^^^^^^ + +error[E0741]: using raw pointers as const generic parameters is forbidden + --> $DIR/raw-ptr-const-param-deref.rs:13:15 + | +LL | impl Const

{ + | ^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0741`. diff --git a/tests/ui/const-generics/raw-ptr-const-param-deref.full.stderr b/tests/ui/const-generics/raw-ptr-const-param-deref.full.stderr index 657eee2be2443..18f47f7dc23e6 100644 --- a/tests/ui/const-generics/raw-ptr-const-param-deref.full.stderr +++ b/tests/ui/const-generics/raw-ptr-const-param-deref.full.stderr @@ -1,11 +1,11 @@ error[E0741]: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param-deref.rs:9:23 + --> $DIR/raw-ptr-const-param-deref.rs:11:23 | LL | struct Const; | ^^^^^^^^^^ error[E0741]: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param-deref.rs:11:15 + --> $DIR/raw-ptr-const-param-deref.rs:13:15 | LL | impl Const

{ | ^^^^^^^^^^ diff --git a/tests/ui/const-generics/raw-ptr-const-param-deref.min.stderr b/tests/ui/const-generics/raw-ptr-const-param-deref.min.stderr index 1eb238255abc2..6027dbb01cddb 100644 --- a/tests/ui/const-generics/raw-ptr-const-param-deref.min.stderr +++ b/tests/ui/const-generics/raw-ptr-const-param-deref.min.stderr @@ -1,5 +1,5 @@ error: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param-deref.rs:9:23 + --> $DIR/raw-ptr-const-param-deref.rs:11:23 | LL | struct Const; | ^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | struct Const; = note: the only supported types are integers, `bool` and `char` error: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param-deref.rs:11:15 + --> $DIR/raw-ptr-const-param-deref.rs:13:15 | LL | impl Const

{ | ^^^^^^^^^^ diff --git a/tests/ui/const-generics/raw-ptr-const-param-deref.rs b/tests/ui/const-generics/raw-ptr-const-param-deref.rs index b7fcbb3447a6a..bf077acd4fae8 100644 --- a/tests/ui/const-generics/raw-ptr-const-param-deref.rs +++ b/tests/ui/const-generics/raw-ptr-const-param-deref.rs @@ -1,21 +1,22 @@ // Checks that pointers must not be used as the type of const params. -//@ 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(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] const A: u32 = 3; struct Const; //~ ERROR: using raw pointers as const generic parameters -impl Const

{ //~ ERROR: using raw pointers as const generic parameters +impl Const

{ + //~^ ERROR: using raw pointers as const generic parameters fn get() -> u32 { - unsafe { - *P - } + unsafe { *P } } } fn main() { - assert_eq!(Const::<{&A as *const _}>::get(), 3) + assert_eq!(Const::<{ &A as *const _ }>::get(), 3) } diff --git a/tests/ui/const-generics/raw-ptr-const-param.adt_const_params.stderr b/tests/ui/const-generics/raw-ptr-const-param.adt_const_params.stderr new file mode 100644 index 0000000000000..f040d3cc36a7a --- /dev/null +++ b/tests/ui/const-generics/raw-ptr-const-param.adt_const_params.stderr @@ -0,0 +1,21 @@ +error[E0741]: using raw pointers as const generic parameters is forbidden + --> $DIR/raw-ptr-const-param.rs:8:23 + | +LL | struct Const; + | ^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/raw-ptr-const-param.rs:11:40 + | +LL | let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>; + | ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{0xf as *const u32}`, found `{0xa as *const u32}` + | | + | expected due to this + | + = note: expected struct `Const<{0xf as *const u32}>` + found struct `Const<{0xa as *const u32}>` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0308, E0741. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/raw-ptr-const-param.full.stderr b/tests/ui/const-generics/raw-ptr-const-param.full.stderr index 7ba9ac15bf3ac..f040d3cc36a7a 100644 --- a/tests/ui/const-generics/raw-ptr-const-param.full.stderr +++ b/tests/ui/const-generics/raw-ptr-const-param.full.stderr @@ -1,11 +1,11 @@ error[E0741]: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param.rs:6:23 + --> $DIR/raw-ptr-const-param.rs:8:23 | LL | struct Const; | ^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/raw-ptr-const-param.rs:9:40 + --> $DIR/raw-ptr-const-param.rs:11:40 | LL | let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>; | ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{0xf as *const u32}`, found `{0xa as *const u32}` diff --git a/tests/ui/const-generics/raw-ptr-const-param.min.stderr b/tests/ui/const-generics/raw-ptr-const-param.min.stderr index 18bbcc33c4df6..c48eea069e0da 100644 --- a/tests/ui/const-generics/raw-ptr-const-param.min.stderr +++ b/tests/ui/const-generics/raw-ptr-const-param.min.stderr @@ -1,5 +1,5 @@ error: using raw pointers as const generic parameters is forbidden - --> $DIR/raw-ptr-const-param.rs:6:23 + --> $DIR/raw-ptr-const-param.rs:8:23 | LL | struct Const; | ^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | struct Const; = note: the only supported types are integers, `bool` and `char` error[E0308]: mismatched types - --> $DIR/raw-ptr-const-param.rs:9:40 + --> $DIR/raw-ptr-const-param.rs:11:40 | LL | let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>; | ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{0xf as *const u32}`, found `{0xa as *const u32}` diff --git a/tests/ui/const-generics/raw-ptr-const-param.rs b/tests/ui/const-generics/raw-ptr-const-param.rs index 19d18a2f9d2cc..49e48d9905f41 100644 --- a/tests/ui/const-generics/raw-ptr-const-param.rs +++ b/tests/ui/const-generics/raw-ptr-const-param.rs @@ -1,7 +1,9 @@ -//@ 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(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] struct Const; //~ ERROR: using raw pointers as const generic parameters diff --git a/tests/ui/const-generics/slice-const-param-mismatch.adt_const_params.stderr b/tests/ui/const-generics/slice-const-param-mismatch.adt_const_params.stderr new file mode 100644 index 0000000000000..bcb2bd255dab9 --- /dev/null +++ b/tests/ui/const-generics/slice-const-param-mismatch.adt_const_params.stderr @@ -0,0 +1,49 @@ +error[E0741]: `&'static str` can't be used as a const parameter type + --> $DIR/slice-const-param-mismatch.rs:8:29 + | +LL | struct ConstString; + | ^^^^^^^^^^^^ + +error[E0741]: `&'static [u8]` can't be used as a const parameter type + --> $DIR/slice-const-param-mismatch.rs:11:28 + | +LL | struct ConstBytes; + | ^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/slice-const-param-mismatch.rs:17:35 + | +LL | let _: ConstString<"Hello"> = ConstString::<"World">; + | -------------------- ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"` + | | + | expected due to this + | + = note: expected struct `ConstString<"Hello">` + found struct `ConstString<"World">` + +error[E0308]: mismatched types + --> $DIR/slice-const-param-mismatch.rs:19:33 + | +LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; + | ------------------- ^^^^^^^^^^^^^^^^^^^^^ expected `"ℇ㇈↦"`, found `"ℇ㇈↥"` + | | + | expected due to this + | + = note: expected struct `ConstString<"ℇ㇈↦">` + found struct `ConstString<"ℇ㇈↥">` + +error[E0308]: mismatched types + --> $DIR/slice-const-param-mismatch.rs:21:33 + | +LL | let _: ConstBytes = ConstBytes::; + | ------------------ ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"` + | | + | expected due to this + | + = note: expected struct `ConstBytes` + found struct `ConstBytes` + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0308, E0741. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/slice-const-param-mismatch.full.stderr b/tests/ui/const-generics/slice-const-param-mismatch.full.stderr index 80dd1be33c241..883ba988be71f 100644 --- a/tests/ui/const-generics/slice-const-param-mismatch.full.stderr +++ b/tests/ui/const-generics/slice-const-param-mismatch.full.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:14:35 + --> $DIR/slice-const-param-mismatch.rs:17:35 | LL | let _: ConstString<"Hello"> = ConstString::<"World">; | -------------------- ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"` @@ -10,7 +10,7 @@ LL | let _: ConstString<"Hello"> = ConstString::<"World">; found struct `ConstString<"World">` error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:16:33 + --> $DIR/slice-const-param-mismatch.rs:19:33 | LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; | ------------------- ^^^^^^^^^^^^^^^^^^^^^ expected `"ℇ㇈↦"`, found `"ℇ㇈↥"` @@ -21,7 +21,7 @@ LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; found struct `ConstString<"ℇ㇈↥">` error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:18:33 + --> $DIR/slice-const-param-mismatch.rs:21:33 | LL | let _: ConstBytes = ConstBytes::; | ------------------ ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"` diff --git a/tests/ui/const-generics/slice-const-param-mismatch.min.stderr b/tests/ui/const-generics/slice-const-param-mismatch.min.stderr index 0650dafc685d5..3b2410c989477 100644 --- a/tests/ui/const-generics/slice-const-param-mismatch.min.stderr +++ b/tests/ui/const-generics/slice-const-param-mismatch.min.stderr @@ -1,5 +1,5 @@ error: `&'static str` is forbidden as the type of a const generic parameter - --> $DIR/slice-const-param-mismatch.rs:7:29 + --> $DIR/slice-const-param-mismatch.rs:8:29 | LL | struct ConstString; | ^^^^^^^^^^^^ @@ -9,9 +9,13 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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: `&'static [u8]` is forbidden as the type of a const generic parameter - --> $DIR/slice-const-param-mismatch.rs:9:28 + --> $DIR/slice-const-param-mismatch.rs:11:28 | LL | struct ConstBytes; | ^^^^^^^^^^^^^ @@ -21,9 +25,13 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:14:35 + --> $DIR/slice-const-param-mismatch.rs:17:35 | LL | let _: ConstString<"Hello"> = ConstString::<"World">; | -------------------- ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"` @@ -34,7 +42,7 @@ LL | let _: ConstString<"Hello"> = ConstString::<"World">; found struct `ConstString<"World">` error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:16:33 + --> $DIR/slice-const-param-mismatch.rs:19:33 | LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; | ------------------- ^^^^^^^^^^^^^^^^^^^^^ expected `"ℇ㇈↦"`, found `"ℇ㇈↥"` @@ -45,7 +53,7 @@ LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; found struct `ConstString<"ℇ㇈↥">` error[E0308]: mismatched types - --> $DIR/slice-const-param-mismatch.rs:18:33 + --> $DIR/slice-const-param-mismatch.rs:21:33 | LL | let _: ConstBytes = ConstBytes::; | ------------------ ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"` diff --git a/tests/ui/const-generics/slice-const-param-mismatch.rs b/tests/ui/const-generics/slice-const-param-mismatch.rs index 733eeb69fa997..feee39e602d06 100644 --- a/tests/ui/const-generics/slice-const-param-mismatch.rs +++ b/tests/ui/const-generics/slice-const-param-mismatch.rs @@ -1,19 +1,22 @@ -//@ 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(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] struct ConstString; //[min]~^ ERROR +//[adt_const_params]~^^ ERROR struct ConstBytes; //[min]~^ ERROR +//[adt_const_params]~^^ ERROR pub fn main() { let _: ConstString<"Hello"> = ConstString::<"Hello">; let _: ConstString<"Hello"> = ConstString::<"World">; //~ ERROR mismatched types let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↦">; let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; //~ ERROR mismatched types - let _: ConstBytes = ConstBytes::<{&[0x41, 0x41, 0x41]}>; + let _: ConstBytes = ConstBytes::<{ &[0x41, 0x41, 0x41] }>; let _: ConstBytes = ConstBytes::; //~ ERROR mismatched types } diff --git a/tests/ui/const-generics/slice-const-param.rs b/tests/ui/const-generics/slice-const-param.rs index c6c0047c929b4..1c5088b528355 100644 --- a/tests/ui/const-generics/slice-const-param.rs +++ b/tests/ui/const-generics/slice-const-param.rs @@ -1,6 +1,6 @@ //@ run-pass -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] pub fn function_with_str() -> &'static str { @@ -12,9 +12,8 @@ pub fn function_with_bytes() -> &'static [u8] { } // Also check the codepaths for custom DST -#[derive(PartialEq, Eq)] +#[derive(std::marker::UnsizedConstParamTy, PartialEq, Eq)] struct MyStr(str); -impl std::marker::ConstParamTy for MyStr {} fn function_with_my_str() -> &'static MyStr { S @@ -34,7 +33,7 @@ pub fn main() { assert_eq!(function_with_str::<"Rust">(), "Rust"); assert_eq!(function_with_str::<"ℇ㇈↦">(), "ℇ㇈↦"); assert_eq!(function_with_bytes::(), &[0x41, 0x41, 0x41, 0x41]); - assert_eq!(function_with_bytes::<{&[0x41, 0x41, 0x41, 0x41]}>(), b"AAAA"); + assert_eq!(function_with_bytes::<{ &[0x41, 0x41, 0x41, 0x41] }>(), b"AAAA"); assert_eq!(function_with_my_str::<{ MyStr::new("hello") }>().as_str(), "hello"); } diff --git a/tests/ui/const-generics/transmute-const-param-static-reference.adt_const_params.stderr b/tests/ui/const-generics/transmute-const-param-static-reference.adt_const_params.stderr new file mode 100644 index 0000000000000..7a936ced0305a --- /dev/null +++ b/tests/ui/const-generics/transmute-const-param-static-reference.adt_const_params.stderr @@ -0,0 +1,9 @@ +error[E0741]: `&'static ()` can't be used as a const parameter type + --> $DIR/transmute-const-param-static-reference.rs:9:23 + | +LL | struct Const; + | ^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0741`. diff --git a/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr b/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr index fdb6ddeb578b6..cf236487cf0ec 100644 --- a/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr +++ b/tests/ui/const-generics/transmute-const-param-static-reference.min.stderr @@ -1,5 +1,5 @@ error: `&'static ()` is forbidden as the type of a const generic parameter - --> $DIR/transmute-const-param-static-reference.rs:7:23 + --> $DIR/transmute-const-param-static-reference.rs:9:23 | LL | struct Const; | ^^^^^^^^^^^ @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 diff --git a/tests/ui/const-generics/transmute-const-param-static-reference.rs b/tests/ui/const-generics/transmute-const-param-static-reference.rs index 49541233ed1ff..0b47fd31eaf69 100644 --- a/tests/ui/const-generics/transmute-const-param-static-reference.rs +++ b/tests/ui/const-generics/transmute-const-param-static-reference.rs @@ -1,16 +1,17 @@ -//@ revisions: full min +//@ revisions: full adt_const_params min //@[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(adt_const_params, feature(adt_const_params))] +#![cfg_attr(adt_const_params, allow(incomplete_features))] struct Const; //[min]~^ ERROR `&'static ()` is forbidden as the type of a const generic parameter +//[adt_const_params]~^^ ERROR `&'static ()` can't be used as a const parameter type fn main() { - const A: &'static () = unsafe { - std::mem::transmute(10 as *const ()) - }; + const A: &'static () = unsafe { std::mem::transmute(10 as *const ()) }; - let _ = Const::<{A}>; + let _ = Const::<{ A }>; } diff --git a/tests/ui/const-generics/type-dependent/issue-71348.min.stderr b/tests/ui/const-generics/type-dependent/issue-71348.min.stderr index f42a331a8a405..858900a500d84 100644 --- a/tests/ui/const-generics/type-dependent/issue-71348.min.stderr +++ b/tests/ui/const-generics/type-dependent/issue-71348.min.stderr @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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: `&'static str` is forbidden as the type of a const generic parameter --> $DIR/issue-71348.rs:18:25 @@ -21,6 +25,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 diff --git a/tests/ui/const-generics/type-dependent/issue-71348.rs b/tests/ui/const-generics/type-dependent/issue-71348.rs index f349a88d124f4..2ffbd015485aa 100644 --- a/tests/ui/const-generics/type-dependent/issue-71348.rs +++ b/tests/ui/const-generics/type-dependent/issue-71348.rs @@ -1,6 +1,6 @@ //@ [full] run-pass //@ 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))] struct Foo { diff --git a/tests/ui/consts/refs_check_const_eq-issue-88384.rs b/tests/ui/consts/refs_check_const_eq-issue-88384.rs index fb0405b651cc5..46cb627517173 100644 --- a/tests/ui/consts/refs_check_const_eq-issue-88384.rs +++ b/tests/ui/consts/refs_check_const_eq-issue-88384.rs @@ -1,10 +1,10 @@ #![feature(fn_traits)] -#![feature(adt_const_params)] -//~^ WARNING the feature `adt_const_params` is incomplete +#![feature(adt_const_params, unsized_const_params)] +//~^ WARNING the feature `unsized_const_params` is incomplete #[derive(PartialEq, Eq)] -struct CompileTimeSettings{ - hooks: &'static[fn()], +struct CompileTimeSettings { + hooks: &'static [fn()], } struct Foo; @@ -12,14 +12,11 @@ struct Foo; impl Foo { //~^ ERROR `CompileTimeSettings` must implement `ConstParamTy` to be used as the type of a const generic parameter - fn call_hooks(){ - } + fn call_hooks() {} } -fn main(){ - const SETTINGS: CompileTimeSettings = CompileTimeSettings{ - hooks: &[], - }; +fn main() { + const SETTINGS: CompileTimeSettings = CompileTimeSettings { hooks: &[] }; Foo::::call_hooks(); } diff --git a/tests/ui/consts/refs_check_const_eq-issue-88384.stderr b/tests/ui/consts/refs_check_const_eq-issue-88384.stderr index c490cd053e70e..62c5c52764115 100644 --- a/tests/ui/consts/refs_check_const_eq-issue-88384.stderr +++ b/tests/ui/consts/refs_check_const_eq-issue-88384.stderr @@ -1,8 +1,8 @@ -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/refs_check_const_eq-issue-88384.rs:2:12 +warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/refs_check_const_eq-issue-88384.rs:2:30 | -LL | #![feature(adt_const_params)] - | ^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params)] + | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #95174 for more information = note: `#[warn(incomplete_features)]` on by default @@ -16,7 +16,7 @@ LL | struct Foo; help: add `#[derive(ConstParamTy)]` to the struct | LL + #[derive(ConstParamTy)] -LL | struct CompileTimeSettings{ +LL | struct CompileTimeSettings { | error[E0741]: `CompileTimeSettings` must implement `ConstParamTy` to be used as the type of a const generic parameter @@ -28,7 +28,7 @@ LL | impl Foo { help: add `#[derive(ConstParamTy)]` to the struct | LL + #[derive(ConstParamTy)] -LL | struct CompileTimeSettings{ +LL | struct CompileTimeSettings { | error: aborting due to 2 previous errors; 1 warning emitted diff --git a/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs b/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs index 446fdc7551483..33b6b7f52ca10 100644 --- a/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs +++ b/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs @@ -1,7 +1,7 @@ //@ check-pass #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] struct FooConst {} diff --git a/tests/ui/error-codes/E0771.rs b/tests/ui/error-codes/E0771.rs index c0a2e98a7df60..a932c5ef9815d 100644 --- a/tests/ui/error-codes/E0771.rs +++ b/tests/ui/error-codes/E0771.rs @@ -1,5 +1,5 @@ -#![feature(adt_const_params)] -//~^ WARN the feature `adt_const_params` is incomplete +#![feature(adt_const_params, unsized_const_params)] +//~^ WARN the feature `unsized_const_params` is incomplete fn function_with_str<'a, const STRING: &'a str>() {} //~ ERROR E0770 diff --git a/tests/ui/error-codes/E0771.stderr b/tests/ui/error-codes/E0771.stderr index e1384effe37ab..5e829e6f6d2d8 100644 --- a/tests/ui/error-codes/E0771.stderr +++ b/tests/ui/error-codes/E0771.stderr @@ -6,11 +6,11 @@ LL | fn function_with_str<'a, const STRING: &'a str>() {} | = note: lifetime parameters may not be used in the type of const parameters -warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/E0771.rs:1:12 +warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/E0771.rs:1:30 | -LL | #![feature(adt_const_params)] - | ^^^^^^^^^^^^^^^^ +LL | #![feature(adt_const_params, unsized_const_params)] + | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #95174 for more information = note: `#[warn(incomplete_features)]` on by default diff --git a/tests/ui/feature-gates/feature-gate-adt_const_params.stderr b/tests/ui/feature-gates/feature-gate-adt_const_params.stderr index fcb9b8a6fc573..649e936888b22 100644 --- a/tests/ui/feature-gates/feature-gate-adt_const_params.stderr +++ b/tests/ui/feature-gates/feature-gate-adt_const_params.stderr @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 diff --git a/tests/ui/feature-gates/feature-gate-unsized-const-params.rs b/tests/ui/feature-gates/feature-gate-unsized-const-params.rs new file mode 100644 index 0000000000000..d088d382377cf --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-unsized-const-params.rs @@ -0,0 +1,6 @@ +struct Foo; +//~^ ERROR: `[u8]` is forbidden as the type of a const generic parameter +//~| HELP: add `#![feature(adt_const_params)]` to the crate +//~| HELP: add `#![feature(unsized_const_params)]` to the crate + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-unsized-const-params.stderr b/tests/ui/feature-gates/feature-gate-unsized-const-params.stderr new file mode 100644 index 0000000000000..0a87f34f4f51f --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-unsized-const-params.stderr @@ -0,0 +1,18 @@ +error: `[u8]` is forbidden as the type of a const generic parameter + --> $DIR/feature-gate-unsized-const-params.rs:1:21 + | +LL | struct Foo; + | ^^^^ + | + = 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)] + | +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 + diff --git a/tests/ui/generic-const-items/elided-lifetimes.stderr b/tests/ui/generic-const-items/elided-lifetimes.stderr index 1d4a997ff6067..85807a1b631a6 100644 --- a/tests/ui/generic-const-items/elided-lifetimes.stderr +++ b/tests/ui/generic-const-items/elided-lifetimes.stderr @@ -32,6 +32,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 4 previous errors diff --git a/tests/ui/impl-trait/defining-use-uncaptured-non-universal-region-3.rs b/tests/ui/impl-trait/defining-use-uncaptured-non-universal-region-3.rs index a6dcad3face0a..00034fb9f447f 100644 --- a/tests/ui/impl-trait/defining-use-uncaptured-non-universal-region-3.rs +++ b/tests/ui/impl-trait/defining-use-uncaptured-non-universal-region-3.rs @@ -1,6 +1,6 @@ //@ check-pass -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] trait Bar {} diff --git a/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs b/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs index b6395258c892f..9205f1e1632c8 100644 --- a/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs +++ b/tests/ui/impl-trait/static-lifetime-return-position-impl-trait.rs @@ -1,7 +1,7 @@ //@ check-pass #![allow(incomplete_features)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] pub struct Element; diff --git a/tests/ui/inference/ice-cannot-relate-region-109178.rs b/tests/ui/inference/ice-cannot-relate-region-109178.rs index 3282f95a992ab..2e3953646fff7 100644 --- a/tests/ui/inference/ice-cannot-relate-region-109178.rs +++ b/tests/ui/inference/ice-cannot-relate-region-109178.rs @@ -2,7 +2,7 @@ #![allow(incomplete_features)] #![crate_type = "lib"] -#![feature(adt_const_params, generic_const_exprs)] +#![feature(adt_const_params, unsized_const_params, generic_const_exprs)] struct Changes //~^ ERROR `&` without an explicit lifetime name cannot be used here diff --git a/tests/ui/lifetimes/unusual-rib-combinations.stderr b/tests/ui/lifetimes/unusual-rib-combinations.stderr index 70f06b4be603c..e446345aedce5 100644 --- a/tests/ui/lifetimes/unusual-rib-combinations.stderr +++ b/tests/ui/lifetimes/unusual-rib-combinations.stderr @@ -63,6 +63,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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 8 previous errors diff --git a/tests/ui/simd/intrinsic/generic-elements.rs b/tests/ui/simd/intrinsic/generic-elements.rs index abceb08ecc5a6..aec75a673067e 100644 --- a/tests/ui/simd/intrinsic/generic-elements.rs +++ b/tests/ui/simd/intrinsic/generic-elements.rs @@ -1,6 +1,6 @@ //@ build-fail -#![feature(repr_simd, intrinsics, rustc_attrs, adt_const_params)] +#![feature(repr_simd, intrinsics, rustc_attrs, adt_const_params, unsized_const_params)] #![allow(incomplete_features)] #[repr(simd)] @@ -14,8 +14,7 @@ struct i32x4(i32, i32, i32, i32); #[repr(simd)] #[derive(Copy, Clone)] #[allow(non_camel_case_types)] -struct i32x8(i32, i32, i32, i32, - i32, i32, i32, i32); +struct i32x8(i32, i32, i32, i32, i32, i32, i32, i32); #[repr(simd)] #[derive(Copy, Clone)] @@ -28,8 +27,7 @@ struct f32x4(f32, f32, f32, f32); #[repr(simd)] #[derive(Copy, Clone)] #[allow(non_camel_case_types)] -struct f32x8(f32, f32, f32, f32, - f32, f32, f32, f32); +struct f32x8(f32, f32, f32, f32, f32, f32, f32, f32); extern "rust-intrinsic" { fn simd_insert(x: T, idx: u32, y: E) -> T; @@ -61,11 +59,11 @@ fn main() { //~^ ERROR expected SIMD input type, found non-SIMD `i32` simd_shuffle::<_, _, f32x2>(x, x, IDX2); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` simd_shuffle::<_, _, f32x4>(x, x, IDX4); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` simd_shuffle::<_, _, f32x8>(x, x, IDX8); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` simd_shuffle::<_, _, i32x8>(x, x, IDX2); //~^ ERROR expected return type of length 2, found `i32x8` with length 8 @@ -85,11 +83,11 @@ fn main() { //~^ ERROR expected SIMD input type, found non-SIMD `i32` simd_shuffle_generic::<_, f32x2, I2>(x, x); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` simd_shuffle_generic::<_, f32x4, I4>(x, x); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` simd_shuffle_generic::<_, f32x8, I8>(x, x); -//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` + //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` simd_shuffle_generic::<_, i32x8, I2>(x, x); //~^ ERROR expected return type of length 2, found `i32x8` with length 8 diff --git a/tests/ui/simd/intrinsic/generic-elements.stderr b/tests/ui/simd/intrinsic/generic-elements.stderr index 26e01344939cc..0788a7c17f994 100644 --- a/tests/ui/simd/intrinsic/generic-elements.stderr +++ b/tests/ui/simd/intrinsic/generic-elements.stderr @@ -1,125 +1,125 @@ error[E0511]: invalid monomorphization of `simd_insert` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:46:9 + --> $DIR/generic-elements.rs:44:9 | LL | simd_insert(0, 0, 0); | ^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_insert` intrinsic: expected inserted type `i32` (element of input `i32x4`), found `f64` - --> $DIR/generic-elements.rs:48:9 + --> $DIR/generic-elements.rs:46:9 | LL | simd_insert(x, 0, 1.0); | ^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_extract` intrinsic: expected return type `i32` (element of input `i32x4`), found `f32` - --> $DIR/generic-elements.rs:50:9 + --> $DIR/generic-elements.rs:48:9 | LL | simd_extract::<_, f32>(x, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:54:9 + --> $DIR/generic-elements.rs:52:9 | LL | simd_shuffle::(0, 0, IDX2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:57:9 + --> $DIR/generic-elements.rs:55:9 | LL | simd_shuffle::(0, 0, IDX4); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:60:9 + --> $DIR/generic-elements.rs:58:9 | LL | simd_shuffle::(0, 0, IDX8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` - --> $DIR/generic-elements.rs:63:9 + --> $DIR/generic-elements.rs:61:9 | LL | simd_shuffle::<_, _, f32x2>(x, x, IDX2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` - --> $DIR/generic-elements.rs:65:9 + --> $DIR/generic-elements.rs:63:9 | LL | simd_shuffle::<_, _, f32x4>(x, x, IDX4); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` - --> $DIR/generic-elements.rs:67:9 + --> $DIR/generic-elements.rs:65:9 | LL | simd_shuffle::<_, _, f32x8>(x, x, IDX8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return type of length 2, found `i32x8` with length 8 - --> $DIR/generic-elements.rs:70:9 + --> $DIR/generic-elements.rs:68:9 | LL | simd_shuffle::<_, _, i32x8>(x, x, IDX2); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return type of length 4, found `i32x8` with length 8 - --> $DIR/generic-elements.rs:72:9 + --> $DIR/generic-elements.rs:70:9 | LL | simd_shuffle::<_, _, i32x8>(x, x, IDX4); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return type of length 8, found `i32x2` with length 2 - --> $DIR/generic-elements.rs:74:9 + --> $DIR/generic-elements.rs:72:9 | LL | simd_shuffle::<_, _, i32x2>(x, x, IDX8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:78:9 + --> $DIR/generic-elements.rs:76:9 | LL | simd_shuffle_generic::(0, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:81:9 + --> $DIR/generic-elements.rs:79:9 | LL | simd_shuffle_generic::(0, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-elements.rs:84:9 + --> $DIR/generic-elements.rs:82:9 | LL | simd_shuffle_generic::(0, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32` - --> $DIR/generic-elements.rs:87:9 + --> $DIR/generic-elements.rs:85:9 | LL | simd_shuffle_generic::<_, f32x2, I2>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32` - --> $DIR/generic-elements.rs:89:9 + --> $DIR/generic-elements.rs:87:9 | LL | simd_shuffle_generic::<_, f32x4, I4>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32` - --> $DIR/generic-elements.rs:91:9 + --> $DIR/generic-elements.rs:89:9 | LL | simd_shuffle_generic::<_, f32x8, I8>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return type of length 2, found `i32x8` with length 8 - --> $DIR/generic-elements.rs:94:9 + --> $DIR/generic-elements.rs:92:9 | LL | simd_shuffle_generic::<_, i32x8, I2>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return type of length 4, found `i32x8` with length 8 - --> $DIR/generic-elements.rs:96:9 + --> $DIR/generic-elements.rs:94:9 | LL | simd_shuffle_generic::<_, i32x8, I4>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_shuffle_generic` intrinsic: expected return type of length 8, found `i32x2` with length 2 - --> $DIR/generic-elements.rs:98:9 + --> $DIR/generic-elements.rs:96:9 | LL | simd_shuffle_generic::<_, i32x2, I8>(x, x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/simd/monomorphize-shuffle-index.rs b/tests/ui/simd/monomorphize-shuffle-index.rs index 379616884a1b5..30c345cb90471 100644 --- a/tests/ui/simd/monomorphize-shuffle-index.rs +++ b/tests/ui/simd/monomorphize-shuffle-index.rs @@ -1,7 +1,7 @@ //@[old]run-pass //@[generic_with_fn]run-pass //@ revisions: old generic generic_with_fn -#![feature(repr_simd, intrinsics, adt_const_params, generic_const_exprs)] +#![feature(repr_simd, intrinsics, adt_const_params, unsized_const_params, generic_const_exprs)] #![allow(incomplete_features)] extern "rust-intrinsic" { diff --git a/tests/ui/statics/const_generics.rs b/tests/ui/statics/const_generics.rs index 70d9b933a7656..7f64f6995a453 100644 --- a/tests/ui/statics/const_generics.rs +++ b/tests/ui/statics/const_generics.rs @@ -11,7 +11,7 @@ //@[opt] compile-flags: -O #![feature(const_refs_to_static)] -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_params)] #![allow(incomplete_features)] static FOO: usize = 42; diff --git a/tests/ui/symbol-names/const-generics-str-demangling.rs b/tests/ui/symbol-names/const-generics-str-demangling.rs index 871f3694e00c5..87b1fdf8a479c 100644 --- a/tests/ui/symbol-names/const-generics-str-demangling.rs +++ b/tests/ui/symbol-names/const-generics-str-demangling.rs @@ -1,7 +1,7 @@ //@ build-fail //@ compile-flags: -C symbol-mangling-version=v0 --crate-name=c //@ normalize-stderr-test: "c\[.*?\]" -> "c[HASH]" -#![feature(adt_const_params, rustc_attrs)] +#![feature(adt_const_params, unsized_const_params, rustc_attrs)] #![allow(incomplete_features)] pub struct Str; diff --git a/tests/ui/symbol-names/const-generics-structural-demangling.rs b/tests/ui/symbol-names/const-generics-structural-demangling.rs index 6c79ed7314cf4..9f5f31177b38c 100644 --- a/tests/ui/symbol-names/const-generics-structural-demangling.rs +++ b/tests/ui/symbol-names/const-generics-structural-demangling.rs @@ -3,10 +3,10 @@ //@ normalize-stderr-test: "c\[[0-9a-f]+\]" -> "c[HASH]" -#![feature(adt_const_params, decl_macro, rustc_attrs)] +#![feature(adt_const_params, unsized_const_params, decl_macro, rustc_attrs)] #![allow(incomplete_features)] -use std::marker::ConstParamTy; +use std::marker::UnsizedConstParamTy; pub struct RefByte; @@ -14,7 +14,7 @@ pub struct RefByte; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(>) -impl RefByte<{&123}> {} +impl RefByte<{ &123 }> {} // FIXME(eddyb) this was supposed to be `RefMutZst` with `&mut []`, // but that is currently not allowed in const generics. @@ -24,7 +24,7 @@ pub struct RefZst; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(>) -impl RefZst<{&[]}> {} +impl RefZst<{ &[] }> {} pub struct Array3Bytes; @@ -32,7 +32,7 @@ pub struct Array3Bytes; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(>) -impl Array3Bytes<{[1, 2, 3]}> {} +impl Array3Bytes<{ [1, 2, 3] }> {} pub struct TupleByteBool; @@ -40,9 +40,9 @@ pub struct TupleByteBool; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(>) -impl TupleByteBool<{(1, false)}> {} +impl TupleByteBool<{ (1, false) }> {} -#[derive(PartialEq, Eq, ConstParamTy)] +#[derive(PartialEq, Eq, UnsizedConstParamTy)] pub enum MyOption { Some(T), None, @@ -56,7 +56,7 @@ pub struct OptionUsize>; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(::None}>>) -impl OptionUsize<{MyOption::None}> {} +impl OptionUsize<{ MyOption::None }> {} // HACK(eddyb) the full mangling is only in `.stderr` because we can normalize // the `core` disambiguator hash away there, but not here. @@ -64,9 +64,9 @@ impl OptionUsize<{MyOption::None}> {} //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(::Some(0)}>>) -impl OptionUsize<{MyOption::Some(0)}> {} +impl OptionUsize<{ MyOption::Some(0) }> {} -#[derive(PartialEq, Eq, ConstParamTy)] +#[derive(PartialEq, Eq, UnsizedConstParamTy)] pub struct Foo { s: &'static str, ch: char, @@ -78,12 +78,12 @@ pub struct Foo_; //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(>) -impl Foo_<{Foo { s: "abc", ch: 'x', slice: &[1, 2, 3] }}> {} +impl Foo_<{ Foo { s: "abc", ch: 'x', slice: &[1, 2, 3] } }> {} // NOTE(eddyb) this tests specifically the use of disambiguators in field names, // using macros 2.0 hygiene to create a `struct` with conflicting field names. macro duplicate_field_name_test($x:ident) { - #[derive(PartialEq, Eq, ConstParamTy)] + #[derive(PartialEq, Eq, UnsizedConstParamTy)] pub struct Bar { $x: u8, x: u16, @@ -94,7 +94,7 @@ macro duplicate_field_name_test($x:ident) { //~^ ERROR symbol-name //~| ERROR demangling //~| ERROR demangling-alt(>) - impl Bar_<{Bar { $x: 123, x: 4096 }}> {} + impl Bar_<{ Bar { $x: 123, x: 4096 } }> {} } duplicate_field_name_test!(x); diff --git a/tests/ui/typeck/ice-unexpected-region-123863.stderr b/tests/ui/typeck/ice-unexpected-region-123863.stderr index 08f1ede95b45f..0479f134a3897 100644 --- a/tests/ui/typeck/ice-unexpected-region-123863.stderr +++ b/tests/ui/typeck/ice-unexpected-region-123863.stderr @@ -9,6 +9,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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: `&'static str` is forbidden as the type of a const generic parameter --> $DIR/ice-unexpected-region-123863.rs:3:27 @@ -21,6 +25,10 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more | 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[E0223]: ambiguous associated type --> $DIR/ice-unexpected-region-123863.rs:5:5