Rollup merge of #148698 - tiif:const_query_cycle, r=BoxyUwU

Fix query cycle when encounter unevaluated const

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/249

In this PR, the environment is dropped when evaluating const that does not have any generic parameter to fix the query cycle.
This commit is contained in:
Matthias Krüger 2025-11-17 18:07:33 +01:00 committed by GitHub
commit 3bc1eaa66a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View file

@ -635,9 +635,10 @@ pub fn try_evaluate_const<'tcx>(
return Err(EvaluateConstErr::HasGenericsOrInfers);
}
let typing_env = infcx
.typing_env(tcx.erase_and_anonymize_regions(param_env))
.with_post_analysis_normalized(tcx);
// Since there is no generic parameter, we can just drop the environment
// to prevent query cycle.
let typing_env = infcx.typing_env(ty::ParamEnv::empty());
(uv.args, typing_env)
}
};

View file

@ -0,0 +1,20 @@
//@ compile-flags: -Znext-solver
//@ check-pass
// Regression test for https://github.com/rust-lang/trait-system-refactor-initiative/issues/249
const CONST: &str = "hi";
trait ToUnit {
type Assoc;
}
impl<T> ToUnit for T {
type Assoc = ();
}
fn foo()
where
<[u8; CONST.len()] as ToUnit>::Assoc: Sized,
{}
fn main(){}