Rollup merge of #119725 - compiler-errors:has_effect_param, r=fmease
Add helper for when we want to know if an item has a host param r? ````@fmease```` since you're a good reviewer and no good deed goes unpunished This helper will see far more usages as built-in traits get constified.
This commit is contained in:
commit
cd93114deb
4 changed files with 13 additions and 10 deletions
|
@ -157,9 +157,7 @@ impl Qualif for NeedsNonConstDrop {
|
||||||
// FIXME(effects): If `destruct` is not a `const_trait`,
|
// FIXME(effects): If `destruct` is not a `const_trait`,
|
||||||
// or effects are disabled in this crate, then give up.
|
// or effects are disabled in this crate, then give up.
|
||||||
let destruct_def_id = cx.tcx.require_lang_item(LangItem::Destruct, Some(cx.body.span));
|
let destruct_def_id = cx.tcx.require_lang_item(LangItem::Destruct, Some(cx.body.span));
|
||||||
if cx.tcx.generics_of(destruct_def_id).host_effect_index.is_none()
|
if !cx.tcx.has_host_param(destruct_def_id) || !cx.tcx.features().effects {
|
||||||
|| !cx.tcx.features().effects
|
|
||||||
{
|
|
||||||
return NeedsDrop::in_any_value_of_ty(cx, ty);
|
return NeedsDrop::in_any_value_of_ty(cx, ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -490,11 +490,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.tcx.require_lang_item(hir::LangItem::FnOnce, Some(span));
|
self.tcx.require_lang_item(hir::LangItem::FnOnce, Some(span));
|
||||||
let fn_once_output_def_id =
|
let fn_once_output_def_id =
|
||||||
self.tcx.require_lang_item(hir::LangItem::FnOnceOutput, Some(span));
|
self.tcx.require_lang_item(hir::LangItem::FnOnceOutput, Some(span));
|
||||||
if self.tcx.generics_of(fn_once_def_id).host_effect_index.is_none() {
|
if self.tcx.has_host_param(fn_once_def_id) {
|
||||||
if idx == 0 && !self.tcx.is_const_fn_raw(def_id) {
|
|
||||||
self.dcx().emit_err(errors::ConstSelectMustBeConst { span });
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let const_param: ty::GenericArg<'tcx> =
|
let const_param: ty::GenericArg<'tcx> =
|
||||||
([self.tcx.consts.false_, self.tcx.consts.true_])[idx].into();
|
([self.tcx.consts.false_, self.tcx.consts.true_])[idx].into();
|
||||||
self.register_predicate(traits::Obligation::new(
|
self.register_predicate(traits::Obligation::new(
|
||||||
|
@ -523,6 +519,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
));
|
));
|
||||||
|
|
||||||
self.select_obligations_where_possible(|_| {});
|
self.select_obligations_where_possible(|_| {});
|
||||||
|
} else if idx == 0 && !self.tcx.is_const_fn_raw(def_id) {
|
||||||
|
self.dcx().emit_err(errors::ConstSelectMustBeConst { span });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.dcx().emit_err(errors::ConstSelectMustBeFn { span, ty: arg_ty });
|
self.dcx().emit_err(errors::ConstSelectMustBeFn { span, ty: arg_ty });
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Miscellaneous type-system utilities that are too small to deserve their own modules.
|
//! Miscellaneous type-system utilities that are too small to deserve their own modules.
|
||||||
|
|
||||||
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||||
use crate::query::Providers;
|
use crate::query::{IntoQueryParam, Providers};
|
||||||
use crate::ty::layout::IntegerExt;
|
use crate::ty::layout::IntegerExt;
|
||||||
use crate::ty::{
|
use crate::ty::{
|
||||||
self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
|
self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
|
||||||
|
@ -786,6 +786,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|| self.extern_crate(key.as_def_id()).is_some_and(|e| e.is_direct())
|
|| self.extern_crate(key.as_def_id()).is_some_and(|e| e.is_direct())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the item has a host effect param. This is different from `TyCtxt::is_const`,
|
||||||
|
/// because the item must also be "maybe const", and the crate where the item is
|
||||||
|
/// defined must also have the effects feature enabled.
|
||||||
|
pub fn has_host_param(self, def_id: impl IntoQueryParam<DefId>) -> bool {
|
||||||
|
self.generics_of(def_id).host_effect_index.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn expected_host_effect_param_for_body(self, def_id: impl Into<DefId>) -> ty::Const<'tcx> {
|
pub fn expected_host_effect_param_for_body(self, def_id: impl Into<DefId>) -> ty::Const<'tcx> {
|
||||||
let def_id = def_id.into();
|
let def_id = def_id.into();
|
||||||
// FIXME(effects): This is suspicious and should probably not be done,
|
// FIXME(effects): This is suspicious and should probably not be done,
|
||||||
|
|
|
@ -271,7 +271,7 @@ pub fn closure_trait_ref_and_return_type<'tcx>(
|
||||||
TupleArgumentsFlag::No => sig.skip_binder().inputs()[0],
|
TupleArgumentsFlag::No => sig.skip_binder().inputs()[0],
|
||||||
TupleArgumentsFlag::Yes => Ty::new_tup(tcx, sig.skip_binder().inputs()),
|
TupleArgumentsFlag::Yes => Ty::new_tup(tcx, sig.skip_binder().inputs()),
|
||||||
};
|
};
|
||||||
let trait_ref = if tcx.generics_of(fn_trait_def_id).host_effect_index.is_some() {
|
let trait_ref = if tcx.has_host_param(fn_trait_def_id) {
|
||||||
ty::TraitRef::new(
|
ty::TraitRef::new(
|
||||||
tcx,
|
tcx,
|
||||||
fn_trait_def_id,
|
fn_trait_def_id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue