Skip to content

Commit

Permalink
Rollup merge of #106541 - fee1-dead-contrib:no-const-check-no, r=thomcc
Browse files Browse the repository at this point in the history
implement const iterator using `rustc_do_not_const_check`

Previous experiment: #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.
  • Loading branch information
Dylan-DPC committed Feb 24, 2023
2 parents 07c993e + 3aeb43c commit 8c135ee
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 9 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::config;
use rustc_session::Session;
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::Span;
use rustc_span::{sym, Span};

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

Expand Down Expand Up @@ -207,6 +207,11 @@ fn typeck_with_fallback<'tcx>(

let typeck_results = Inherited::build(tcx, def_id).enter(|inh| {
let param_env = tcx.param_env(def_id);
let param_env = if tcx.has_attr(def_id.to_def_id(), sym::rustc_do_not_const_check) {
param_env.without_const()
} else {
param_env
};
let mut fcx = FnCtxt::new(&inh, param_env, def_id);

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

0 comments on commit 8c135ee

Please sign in to comment.