about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2023-08-13 09:02:31 +0000
committerDeadbeef <ent3rm4n@gmail.com>2023-09-20 03:02:14 +0000
commit04eec37dc2cababaecffd423e330d3c19d3c6169 (patch)
tree55b68f8b57e28c6dd1fda1657cd14f4e8a3b7306 /compiler
parent3b9e0feff480b8df3254e7a828f50a1a55b88885 (diff)
downloadrust-04eec37dc2cababaecffd423e330d3c19d3c6169.tar.gz
rust-04eec37dc2cababaecffd423e330d3c19d3c6169.zip
Enable effects for libcore
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs8
-rw-r--r--compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs19
-rw-r--r--compiler/rustc_monomorphize/src/collector.rs6
3 files changed, 27 insertions, 6 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 70d1dad8a6f..4ad14ce3059 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -525,8 +525,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             _ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0,
         };
 
-        if let ty::FnDef(did, ..) = *ty.kind() {
+        if let ty::FnDef(did, callee_args) = *ty.kind() {
             let fn_sig = ty.fn_sig(tcx);
+
+            // HACK: whenever we get a FnDef in a non-const context, enforce effects to get the
+            // default `host = true` to avoid inference errors later.
+            if tcx.hir().body_const_context(self.body_id).is_none() {
+                self.enforce_context_effects(expr.hir_id, qpath.span(), did, callee_args);
+            }
             if tcx.fn_sig(did).skip_binder().abi() == RustIntrinsic
                 && tcx.item_name(did) == sym::transmute
             {
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
index 4def7867384..37ea94d821e 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
@@ -273,11 +273,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             //
             // This check is here because there is currently no way to express a trait bound for `FnDef` types only.
             if is_const_eval_select && (1..=2).contains(&idx) {
-                if let ty::FnDef(def_id, _) = checked_ty.kind() {
-                    if idx == 1 && !self.tcx.is_const_fn_raw(*def_id) {
-                        self.tcx
-                            .sess
-                            .emit_err(errors::ConstSelectMustBeConst { span: provided_arg.span });
+                if let ty::FnDef(def_id, args) = *checked_ty.kind() {
+                    if idx == 1 {
+                        if !self.tcx.is_const_fn_raw(def_id) {
+                            self.tcx.sess.emit_err(errors::ConstSelectMustBeConst {
+                                span: provided_arg.span,
+                            });
+                        } else {
+                            self.enforce_context_effects(
+                                provided_arg.hir_id,
+                                provided_arg.span,
+                                def_id,
+                                args,
+                            )
+                        }
                     }
                 } else {
                     self.tcx.sess.emit_err(errors::ConstSelectMustBeFn {
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs
index 67e821dcf5a..118b3862887 100644
--- a/compiler/rustc_monomorphize/src/collector.rs
+++ b/compiler/rustc_monomorphize/src/collector.rs
@@ -815,6 +815,12 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
                     mir::AssertKind::BoundsCheck { .. } => LangItem::PanicBoundsCheck,
                     _ => LangItem::Panic,
                 };
+                let def_id = tcx.require_lang_item(lang_item, Some(source));
+                let instance = if has_host_effect {
+                    Instance::new(def_id, tcx.mk_args(&[tcx.consts.true_.into()]))
+                } else {
+                    Instance::mono(tcx, def_id)
+                };
                 push_mono_lang_item(self, lang_item);
             }
             mir::TerminatorKind::UnwindTerminate(reason) => {