Fix non_copy_const ICE (#15083)

fixes rust-lang/rust-clippy#15069

----

changelog: none
This commit is contained in:
llogiq 2025-06-19 20:46:45 +00:00 committed by GitHub
commit 62fd159a5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View file

@ -617,7 +617,7 @@ impl<'tcx> NonCopyConst<'tcx> {
// Then a type check. Note we only check the type here as the result
// gets cached.
let ty = EarlyBinder::bind(typeck.expr_ty(src_expr)).instantiate(tcx, init_args);
let ty = typeck.expr_ty(src_expr);
// Normalized as we need to check if this is an array later.
let ty = tcx.try_normalize_erasing_regions(typing_env, ty).unwrap_or(ty);
if self.is_ty_freeze(tcx, typing_env, ty).is_freeze() {

View file

@ -218,4 +218,20 @@ fn main() {
let _ = &S::VALUE.1; //~ borrow_interior_mutable_const
let _ = &S::VALUE.2;
}
{
pub struct Foo<T, const N: usize>(pub Entry<N>, pub T);
pub struct Entry<const N: usize>(pub Cell<[u32; N]>);
impl<const N: usize> Entry<N> {
const INIT: Self = Self(Cell::new([42; N]));
}
impl<T, const N: usize> Foo<T, N> {
pub fn make_foo(v: T) -> Self {
// Used to ICE due to incorrect instantiation.
Foo(Entry::INIT, v)
}
}
}
}