Skip to content

Commit 3bc1eaa

Browse files
authored
Rollup merge of #148698 - tiif:const_query_cycle, r=BoxyUwU
Fix query cycle when encounter unevaluated const Fixes rust-lang/trait-system-refactor-initiative#249 In this PR, the environment is dropped when evaluating const that does not have any generic parameter to fix the query cycle.
2 parents 4e5c61e + 10fa334 commit 3bc1eaa

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,10 @@ pub fn try_evaluate_const<'tcx>(
635635
return Err(EvaluateConstErr::HasGenericsOrInfers);
636636
}
637637

638-
let typing_env = infcx
639-
.typing_env(tcx.erase_and_anonymize_regions(param_env))
640-
.with_post_analysis_normalized(tcx);
638+
// Since there is no generic parameter, we can just drop the environment
639+
// to prevent query cycle.
640+
let typing_env = infcx.typing_env(ty::ParamEnv::empty());
641+
641642
(uv.args, typing_env)
642643
}
643644
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
// Regression test for https://github.com/rust-lang/trait-system-refactor-initiative/issues/249
5+
6+
const CONST: &str = "hi";
7+
8+
trait ToUnit {
9+
type Assoc;
10+
}
11+
impl<T> ToUnit for T {
12+
type Assoc = ();
13+
}
14+
15+
fn foo()
16+
where
17+
<[u8; CONST.len()] as ToUnit>::Assoc: Sized,
18+
{}
19+
20+
fn main(){}

0 commit comments

Comments
 (0)