diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 71fb6058cd2c5..fe5d6ea022e94 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -205,10 +205,11 @@ fn satisfied_from_param_env<'tcx>( let mut single_match: Option, ()>> = None; + let ct = tcx.erase_regions(ct); for pred in param_env.caller_bounds() { match pred.kind().skip_binder() { ty::PredicateKind::ConstEvaluatable(ce) => { - let b_ct = tcx.expand_abstract_consts(ce); + let b_ct = tcx.erase_regions(tcx.expand_abstract_consts(ce)); let mut v = Visitor { ct, infcx, param_env, single_match }; let _ = b_ct.visit_with(&mut v); diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index a9b4e1420ea0d..0cecde1bb0768 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -5,7 +5,7 @@ use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput}; use rustc_middle::thir::visit; use rustc_middle::thir::visit::Visitor; use rustc_middle::ty::abstract_const::CastKind; -use rustc_middle::ty::{self, Expr, TyCtxt, TypeVisitable}; +use rustc_middle::ty::{self, DefIdTree, Expr, TyCtxt, TypeVisitable}; use rustc_middle::{mir, thir}; use rustc_span::Span; use rustc_target::abi::VariantIdx; @@ -361,6 +361,10 @@ pub fn thir_abstract_const( // // Right now we do neither of that and simply always fail to unify them. DefKind::AnonConst | DefKind::InlineConst => (), + DefKind::AssocConst if let Some(parent) = tcx.opt_local_parent(def.did) + && DefKind::Impl == tcx.def_kind(parent) => { + () + }, _ => return Ok(None), } diff --git a/compiler/rustc_ty_utils/src/lib.rs b/compiler/rustc_ty_utils/src/lib.rs index 7ad5cbc01ccf2..24fff69e6bc5c 100644 --- a/compiler/rustc_ty_utils/src/lib.rs +++ b/compiler/rustc_ty_utils/src/lib.rs @@ -9,6 +9,7 @@ #![feature(control_flow_enum)] #![feature(never_type)] #![feature(box_patterns)] +#![feature(if_let_guard)] #![recursion_limit = "256"] #[macro_use] diff --git a/tests/ui/const-generics/issues/issue-105821.rs b/tests/ui/const-generics/issues/issue-105821.rs new file mode 100644 index 0000000000000..a3c22192b3865 --- /dev/null +++ b/tests/ui/const-generics/issues/issue-105821.rs @@ -0,0 +1,26 @@ +#![allow(incomplete_features)] +#![feature(adt_const_params, const_ptr_read, generic_const_exprs)] +#![allow(dead_code)] + +const fn catone(_a: &[u8; M]) -> [u8; M + 1] +where + [(); M + 1]:, +{ + [0; M+1] +} + +struct Catter; +impl Catter +where + [(); A.len() + 1]:, +{ + const ZEROS: &'static [u8; A.len()] = &[0_u8; A.len()]; + //~^ ERROR overly complex + const R: &'static [u8] = &catone(Self::ZEROS); + //~^ ERROR overly complex +} + +fn main() { + let _ = Catter::<{&[]}>::R; + let _ = Catter::<{&[]}>::ZEROS; +} diff --git a/tests/ui/const-generics/issues/issue-105821.stderr b/tests/ui/const-generics/issues/issue-105821.stderr new file mode 100644 index 0000000000000..be7f31dbddbd2 --- /dev/null +++ b/tests/ui/const-generics/issues/issue-105821.stderr @@ -0,0 +1,19 @@ +error: overly complex generic constant + --> $DIR/issue-105821.rs:17:43 + | +LL | const ZEROS: &'static [u8; A.len()] = &[0_u8; A.len()]; + | ^^^^^^^^^^^^^^^^ borrowing is not supported in generic constants + | + = help: consider moving this anonymous constant into a `const` function + = note: this operation may be supported in the future + +error: overly complex generic constant + --> $DIR/issue-105821.rs:19:30 + | +LL | const R: &'static [u8] = &catone(Self::ZEROS); + | ^^^^^^^^^^^^^^^^^^^^ pointer casts are not allowed in generic constants + | + = help: consider moving this anonymous constant into a `const` function + +error: aborting due to 2 previous errors + diff --git a/tests/ui/const-generics/issues/issue-106423.rs b/tests/ui/const-generics/issues/issue-106423.rs new file mode 100644 index 0000000000000..d39dbe8d25a53 --- /dev/null +++ b/tests/ui/const-generics/issues/issue-106423.rs @@ -0,0 +1,53 @@ +#![feature(generic_const_exprs, generic_arg_infer)] +#![allow(incomplete_features)] +#![allow(unused)] + +use std::mem::MaybeUninit; + +pub struct Arr { + v: [MaybeUninit; N], +} + +impl Arr { + const ELEM: MaybeUninit = MaybeUninit::uninit(); + const INIT: [MaybeUninit; N] = [Self::ELEM; N]; // important for optimization of `new` + //~^ ERROR overly complex + + fn new() -> Self { + Arr { v: Self::INIT } + } +} + +pub struct BaFormatFilter {} + +pub enum DigitalFilter +where + [(); N * 2 + 1]: Sized, + [(); N * 2]: Sized, +{ + Ba(BaFormatFilter<{ N * 2 + 1 }>), +} + +pub fn iirfilter_st_copy(_: [f32; M]) -> DigitalFilter +where + [(); N * 2 + 1]: Sized, + [(); N * 2]: Sized, +{ + let zpk = zpk2tf_st(&Arr::::new(), &Arr::::new()); + DigitalFilter::Ba(zpk) +} + +pub fn zpk2tf_st( + _z: &Arr, + _p: &Arr, +) -> BaFormatFilter<{ N + 1 }> +where + [(); N + 1]: Sized, +{ + BaFormatFilter {} +} + + +fn main() { + iirfilter_st_copy::<4, 2>([10., 50.,]); +} diff --git a/tests/ui/const-generics/issues/issue-106423.stderr b/tests/ui/const-generics/issues/issue-106423.stderr new file mode 100644 index 0000000000000..82c5f4b14e58c --- /dev/null +++ b/tests/ui/const-generics/issues/issue-106423.stderr @@ -0,0 +1,11 @@ +error: overly complex generic constant + --> $DIR/issue-106423.rs:13:39 + | +LL | const INIT: [MaybeUninit; N] = [Self::ELEM; N]; // important for optimization of `new` + | ^^^^^^^^^^^^^^^ array construction is not supported in generic constants + | + = help: consider moving this anonymous constant into a `const` function + = note: this operation may be supported in the future + +error: aborting due to previous error +