Skip to content

Commit 8c135ee

Browse files
authored
Rollup merge of rust-lang#106541 - fee1-dead-contrib:no-const-check-no, r=thomcc
implement const iterator using `rustc_do_not_const_check` Previous experiment: rust-lang#102225. Explanation: rather than making all default methods work under `const` all at once, this uses `rustc_do_not_const_check` as a workaround to "trick" the compiler to not run any checks on those other default methods. Any const implementations are only required to implement the `next` method. Any actual calls to the trait methods other than `next` will either error in compile time (at CTFE runs), or run the methods correctly if they do not have any non-const operations. This is extremely easy to maintain, remove, or improve.
2 parents 07c993e + 3aeb43c commit 8c135ee

File tree

9 files changed

+166
-9
lines changed

9 files changed

+166
-9
lines changed

compiler/rustc_hir_typeck/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
7171
use rustc_session::config;
7272
use rustc_session::Session;
7373
use rustc_span::def_id::{DefId, LocalDefId};
74-
use rustc_span::Span;
74+
use rustc_span::{sym, Span};
7575

7676
fluent_messages! { "../locales/en-US.ftl" }
7777

@@ -207,6 +207,11 @@ fn typeck_with_fallback<'tcx>(
207207

208208
let typeck_results = Inherited::build(tcx, def_id).enter(|inh| {
209209
let param_env = tcx.param_env(def_id);
210+
let param_env = if tcx.has_attr(def_id.to_def_id(), sym::rustc_do_not_const_check) {
211+
param_env.without_const()
212+
} else {
213+
param_env
214+
};
210215
let mut fcx = FnCtxt::new(&inh, param_env, def_id);
211216

212217
if let Some(hir::FnSig { header, decl, .. }) = fn_sig {

0 commit comments

Comments
 (0)