Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,18 @@ pub fn try_evaluate_const<'tcx>(
return Err(EvaluateConstErr::HasGenericsOrInfers);
}

let typing_env = infcx
let mut typing_env;

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.
if !uv.args.has_non_region_param() {
typing_env = infcx.typing_env(ty::ParamEnv::empty());
}

(uv.args, typing_env)
}
};
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/traits/next-solver/unevaluated_const_query_cycle.rs
Original file line number Diff line number Diff line change
@@ -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