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:
commit
3bc1eaa66a
2 changed files with 24 additions and 3 deletions
|
|
@ -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)
|
||||
}
|
||||
};
|
||||
|
|
|
|||
20
tests/ui/traits/next-solver/unevaluated_const_query_cycle.rs
Normal file
20
tests/ui/traits/next-solver/unevaluated_const_query_cycle.rs
Normal 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(){}
|
||||
Loading…
Add table
Add a link
Reference in a new issue