diff options
| author | bors <bors@rust-lang.org> | 2023-09-22 07:00:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-22 07:00:52 +0000 |
| commit | 8759de0a4935e677fdce99a849addea2d5318da9 (patch) | |
| tree | 664c31b1d3f35009117be7c85a513945a5211ce6 /compiler | |
| parent | aace2dfa37f4589b0071530d2ed7b352f6196704 (diff) | |
| parent | ab168b6ef3b276d06fdf0aac236b9881841815ed (diff) | |
| download | rust-8759de0a4935e677fdce99a849addea2d5318da9.tar.gz rust-8759de0a4935e677fdce99a849addea2d5318da9.zip | |
Auto merge of #114776 - fee1-dead-contrib:enable-effects-in-libcore, r=oli-obk
Enable effects for libcore ~~r? `@oli-obk~~` forgot you are on vacation, oops
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_typeck/src/expr.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 19 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/lang_items.rs | 12 |
3 files changed, 31 insertions, 8 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_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 476394f30cc..7e837243918 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -20,7 +20,8 @@ use rustc_hir::lang_items::{extract, GenericRequirement}; use rustc_hir::{LangItem, LanguageItems, Target}; use rustc_middle::ty::TyCtxt; use rustc_session::cstore::ExternCrate; -use rustc_span::{symbol::kw::Empty, Span}; +use rustc_span::symbol::kw::Empty; +use rustc_span::{sym, Span}; use rustc_middle::query::Providers; @@ -157,7 +158,14 @@ impl<'tcx> LanguageItemCollector<'tcx> { self.tcx.hir().get_by_def_id(item_def_id) { let (actual_num, generics_span) = match kind.generics() { - Some(generics) => (generics.params.len(), generics.span), + Some(generics) => ( + generics + .params + .iter() + .filter(|p| !self.tcx.has_attr(p.def_id, sym::rustc_host)) + .count(), + generics.span, + ), None => (0, *item_span), }; |
