mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
merge DefKind::Coroutine
into DefKind::Closure
This commit is contained in:
parent
274b5249eb
commit
f23befe6c1
@ -89,7 +89,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||
}
|
||||
}
|
||||
|
||||
self.nodes.insert(hir_id.local_id, ParentedNode { parent: self.parent_node, node: node });
|
||||
self.nodes.insert(hir_id.local_id, ParentedNode { parent: self.parent_node, node });
|
||||
}
|
||||
|
||||
fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_node_id: HirId, f: F) {
|
||||
|
@ -2072,8 +2072,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
.map(|name| format!("function `{name}`"))
|
||||
.unwrap_or_else(|| {
|
||||
match &self.infcx.tcx.def_kind(self.mir_def_id()) {
|
||||
DefKind::Closure
|
||||
if self
|
||||
.infcx
|
||||
.tcx
|
||||
.is_coroutine(self.mir_def_id().to_def_id()) =>
|
||||
{
|
||||
"enclosing coroutine"
|
||||
}
|
||||
DefKind::Closure => "enclosing closure",
|
||||
DefKind::Coroutine => "enclosing coroutine",
|
||||
kind => bug!("expected closure or coroutine, found {:?}", kind),
|
||||
}
|
||||
.to_string()
|
||||
|
@ -2678,8 +2678,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
let typeck_root_args = ty::GenericArgs::identity_for_item(tcx, typeck_root_def_id);
|
||||
|
||||
let parent_args = match tcx.def_kind(def_id) {
|
||||
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => {
|
||||
args.as_coroutine().parent_args()
|
||||
}
|
||||
DefKind::Closure => args.as_closure().parent_args(),
|
||||
DefKind::Coroutine => args.as_coroutine().parent_args(),
|
||||
DefKind::InlineConst => args.as_inline_const().parent_args(),
|
||||
other => bug!("unexpected item {:?}", other),
|
||||
};
|
||||
|
@ -373,10 +373,7 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
|
||||
// just "functions", like consts, statics, etc. Filter those out.
|
||||
// If `ignore_unused_generics` was specified, filter out any
|
||||
// generic functions from consideration as well.
|
||||
if !matches!(
|
||||
kind,
|
||||
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine
|
||||
) {
|
||||
if !matches!(kind, DefKind::Fn | DefKind::AssocFn | DefKind::Closure) {
|
||||
return None;
|
||||
}
|
||||
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {
|
||||
|
@ -114,7 +114,6 @@ pub enum DefKind {
|
||||
of_trait: bool,
|
||||
},
|
||||
Closure,
|
||||
Coroutine,
|
||||
}
|
||||
|
||||
impl DefKind {
|
||||
@ -157,7 +156,6 @@ impl DefKind {
|
||||
DefKind::Field => "field",
|
||||
DefKind::Impl { .. } => "implementation",
|
||||
DefKind::Closure => "closure",
|
||||
DefKind::Coroutine => "coroutine",
|
||||
DefKind::ExternCrate => "extern crate",
|
||||
DefKind::GlobalAsm => "global assembly block",
|
||||
}
|
||||
@ -216,7 +214,6 @@ impl DefKind {
|
||||
| DefKind::LifetimeParam
|
||||
| DefKind::ExternCrate
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine
|
||||
| DefKind::Use
|
||||
| DefKind::ForeignMod
|
||||
| DefKind::GlobalAsm
|
||||
@ -226,7 +223,7 @@ impl DefKind {
|
||||
|
||||
#[inline]
|
||||
pub fn is_fn_like(self) -> bool {
|
||||
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine)
|
||||
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure)
|
||||
}
|
||||
|
||||
/// Whether `query get_codegen_attrs` should be used with this definition.
|
||||
@ -236,7 +233,6 @@ impl DefKind {
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Ctor(..)
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine
|
||||
| DefKind::Static(_) => true,
|
||||
DefKind::Mod
|
||||
| DefKind::Struct
|
||||
|
@ -1451,7 +1451,7 @@ fn opaque_type_cycle_error(
|
||||
label_match(capture.place.ty(), capture.get_path_span(tcx));
|
||||
}
|
||||
// Label any coroutine locals that capture the opaque
|
||||
if let DefKind::Coroutine = tcx.def_kind(closure_def_id)
|
||||
if tcx.is_coroutine(closure_def_id)
|
||||
&& let Some(coroutine_layout) = tcx.mir_coroutine_witnesses(closure_def_id)
|
||||
{
|
||||
for interior_ty in &coroutine_layout.field_tys {
|
||||
@ -1472,7 +1472,7 @@ pub(super) fn check_coroutine_obligations(
|
||||
tcx: TyCtxt<'_>,
|
||||
def_id: LocalDefId,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Coroutine));
|
||||
debug_assert!(tcx.is_coroutine(def_id.to_def_id()));
|
||||
|
||||
let typeck = tcx.typeck(def_id);
|
||||
let param_env = tcx.param_env(def_id);
|
||||
|
@ -756,7 +756,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
|
||||
});
|
||||
|
||||
tcx.hir().par_body_owners(|def_id| {
|
||||
if let rustc_hir::def::DefKind::Coroutine = tcx.def_kind(def_id) {
|
||||
if tcx.is_coroutine(def_id.to_def_id()) {
|
||||
tcx.ensure().mir_coroutine_witnesses(def_id);
|
||||
tcx.ensure().check_coroutine_obligations(def_id);
|
||||
}
|
||||
|
@ -856,8 +856,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
|
||||
| DefKind::OpaqueTy
|
||||
| DefKind::Field
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine => true,
|
||||
| DefKind::Closure => true,
|
||||
DefKind::ForeignMod | DefKind::GlobalAsm => false,
|
||||
}
|
||||
}
|
||||
@ -897,8 +896,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
|
||||
| DefKind::InlineConst
|
||||
| DefKind::OpaqueTy
|
||||
| DefKind::LifetimeParam
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::Coroutine => false,
|
||||
| DefKind::GlobalAsm => false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -933,8 +931,7 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
|
||||
| DefKind::Field
|
||||
| DefKind::LifetimeParam
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine => false,
|
||||
| DefKind::Closure => false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -969,7 +966,6 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine
|
||||
| DefKind::ExternCrate => false,
|
||||
}
|
||||
}
|
||||
@ -1005,7 +1001,6 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
|
||||
| DefKind::InlineConst
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine
|
||||
| DefKind::ExternCrate => false,
|
||||
}
|
||||
}
|
||||
@ -1048,6 +1043,8 @@ fn should_encode_mir(
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Const => (true, false),
|
||||
// Coroutines require optimized MIR to compute layout.
|
||||
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true),
|
||||
// Full-fledged functions + closures
|
||||
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
|
||||
let generics = tcx.generics_of(def_id);
|
||||
@ -1061,8 +1058,6 @@ fn should_encode_mir(
|
||||
|| tcx.is_const_default_method(def_id.to_def_id());
|
||||
(is_const_fn, opt)
|
||||
}
|
||||
// Coroutines require optimized MIR to compute layout.
|
||||
DefKind::Coroutine => (false, true),
|
||||
// The others don't have MIR.
|
||||
_ => (false, false),
|
||||
}
|
||||
@ -1098,7 +1093,6 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def
|
||||
| DefKind::InlineConst
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine
|
||||
| DefKind::ExternCrate => false,
|
||||
DefKind::TyAlias => tcx.type_alias_is_lazy(def_id),
|
||||
}
|
||||
@ -1127,8 +1121,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::Field
|
||||
| DefKind::TyParam
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine => true,
|
||||
| DefKind::Closure => true,
|
||||
DefKind::Mod
|
||||
| DefKind::ForeignMod
|
||||
| DefKind::ConstParam
|
||||
@ -1157,7 +1150,6 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
|
||||
| DefKind::AssocFn
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine
|
||||
| DefKind::ConstParam
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst => true,
|
||||
@ -1218,7 +1210,6 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine
|
||||
| DefKind::ConstParam
|
||||
| DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
@ -1257,7 +1248,6 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
|
||||
| DefKind::OpaqueTy
|
||||
| DefKind::Impl { of_trait: false }
|
||||
| DefKind::ForeignTy
|
||||
| DefKind::Coroutine
|
||||
| DefKind::ConstParam
|
||||
| DefKind::InlineConst
|
||||
| DefKind::AssocTy
|
||||
@ -1292,7 +1282,6 @@ fn should_encode_const(def_kind: DefKind) -> bool {
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::AssocFn
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine
|
||||
| DefKind::ConstParam
|
||||
| DefKind::AssocTy
|
||||
| DefKind::TyParam
|
||||
@ -1452,8 +1441,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
self.encode_info_for_assoc_item(def_id);
|
||||
}
|
||||
}
|
||||
if let DefKind::Coroutine = def_kind {
|
||||
let data = self.tcx.coroutine_kind(def_id).unwrap();
|
||||
if def_kind == DefKind::Closure
|
||||
&& let Some(data) = self.tcx.coroutine_kind(def_id)
|
||||
{
|
||||
record!(self.tables.coroutine_kind[def_id] <- data);
|
||||
}
|
||||
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
|
||||
@ -1635,7 +1625,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
record!(self.tables.closure_saved_names_of_captured_variables[def_id.to_def_id()]
|
||||
<- tcx.closure_saved_names_of_captured_variables(def_id));
|
||||
|
||||
if let DefKind::Coroutine = self.tcx.def_kind(def_id)
|
||||
if self.tcx.is_coroutine(def_id.to_def_id())
|
||||
&& let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
|
||||
{
|
||||
record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
|
||||
@ -1662,7 +1652,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
}
|
||||
record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id));
|
||||
|
||||
if let DefKind::Coroutine = self.tcx.def_kind(def_id)
|
||||
if self.tcx.is_coroutine(def_id.to_def_id())
|
||||
&& let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
|
||||
{
|
||||
record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
|
||||
|
@ -167,7 +167,6 @@ fixed_size_enum! {
|
||||
( Impl { of_trait: false } )
|
||||
( Impl { of_trait: true } )
|
||||
( Closure )
|
||||
( Coroutine )
|
||||
( Static(ast::Mutability::Not) )
|
||||
( Static(ast::Mutability::Mut) )
|
||||
( Ctor(CtorOf::Struct, CtorKind::Fn) )
|
||||
|
@ -236,8 +236,7 @@ impl<'hir> Map<'hir> {
|
||||
Node::ConstBlock(_) => DefKind::InlineConst,
|
||||
Node::Field(_) => DefKind::Field,
|
||||
Node::Expr(expr) => match expr.kind {
|
||||
ExprKind::Closure(Closure { movability: None, .. }) => DefKind::Closure,
|
||||
ExprKind::Closure(Closure { movability: Some(_), .. }) => DefKind::Coroutine,
|
||||
ExprKind::Closure(_) => DefKind::Closure,
|
||||
_ => bug!("def_kind: unsupported node: {}", self.node_to_string(hir_id)),
|
||||
},
|
||||
Node::GenericParam(param) => match param.kind {
|
||||
@ -441,7 +440,7 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
DefKind::InlineConst => BodyOwnerKind::Const { inline: true },
|
||||
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => BodyOwnerKind::Fn,
|
||||
DefKind::Closure | DefKind::Coroutine => BodyOwnerKind::Closure,
|
||||
DefKind::Closure => BodyOwnerKind::Closure,
|
||||
DefKind::Static(mt) => BodyOwnerKind::Static(mt),
|
||||
dk => bug!("{:?} is not a body node: {:?}", def_id, dk),
|
||||
}
|
||||
|
@ -800,6 +800,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
self.diagnostic_items(did.krate).name_to_id.get(&name) == Some(&did)
|
||||
}
|
||||
|
||||
pub fn is_coroutine(self, def_id: DefId) -> bool {
|
||||
self.coroutine_kind(def_id).is_some()
|
||||
}
|
||||
|
||||
/// Returns `true` if the node pointed to by `def_id` is a coroutine for an async construct.
|
||||
pub fn coroutine_is_async(self, def_id: DefId) -> bool {
|
||||
matches!(self.coroutine_kind(def_id), Some(hir::CoroutineKind::Async(_)))
|
||||
|
@ -550,16 +550,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// those are not yet phased out). The parent of the closure's
|
||||
/// `DefId` will also be the context where it appears.
|
||||
pub fn is_closure(self, def_id: DefId) -> bool {
|
||||
matches!(self.def_kind(def_id), DefKind::Closure | DefKind::Coroutine)
|
||||
matches!(self.def_kind(def_id), DefKind::Closure)
|
||||
}
|
||||
|
||||
/// Returns `true` if `def_id` refers to a definition that does not have its own
|
||||
/// type-checking context, i.e. closure, coroutine or inline const.
|
||||
pub fn is_typeck_child(self, def_id: DefId) -> bool {
|
||||
matches!(
|
||||
self.def_kind(def_id),
|
||||
DefKind::Closure | DefKind::Coroutine | DefKind::InlineConst
|
||||
)
|
||||
matches!(self.def_kind(def_id), DefKind::Closure | DefKind::InlineConst)
|
||||
}
|
||||
|
||||
/// Returns `true` if `def_id` refers to a trait (i.e., `trait Foo { ... }`).
|
||||
@ -732,11 +729,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn def_kind_descr(self, def_kind: DefKind, def_id: DefId) -> &'static str {
|
||||
match def_kind {
|
||||
DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "method",
|
||||
DefKind::Coroutine => match self.coroutine_kind(def_id).unwrap() {
|
||||
rustc_hir::CoroutineKind::Async(..) => "async closure",
|
||||
rustc_hir::CoroutineKind::Coroutine => "coroutine",
|
||||
rustc_hir::CoroutineKind::Gen(..) => "gen closure",
|
||||
},
|
||||
DefKind::Closure if let Some(coroutine_kind) = self.coroutine_kind(def_id) => {
|
||||
match coroutine_kind {
|
||||
rustc_hir::CoroutineKind::Async(..) => "async closure",
|
||||
rustc_hir::CoroutineKind::Coroutine => "coroutine",
|
||||
rustc_hir::CoroutineKind::Gen(..) => "gen closure",
|
||||
}
|
||||
}
|
||||
_ => def_kind.descr(def_id),
|
||||
}
|
||||
}
|
||||
@ -750,11 +749,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn def_kind_descr_article(self, def_kind: DefKind, def_id: DefId) -> &'static str {
|
||||
match def_kind {
|
||||
DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "a",
|
||||
DefKind::Coroutine => match self.coroutine_kind(def_id).unwrap() {
|
||||
rustc_hir::CoroutineKind::Async(..) => "an",
|
||||
rustc_hir::CoroutineKind::Coroutine => "a",
|
||||
rustc_hir::CoroutineKind::Gen(..) => "a",
|
||||
},
|
||||
DefKind::Closure if let Some(coroutine_kind) = self.coroutine_kind(def_id) => {
|
||||
match coroutine_kind {
|
||||
rustc_hir::CoroutineKind::Async(..) => "an",
|
||||
rustc_hir::CoroutineKind::Coroutine => "a",
|
||||
rustc_hir::CoroutineKind::Gen(..) => "a",
|
||||
}
|
||||
}
|
||||
_ => def_kind.article(),
|
||||
}
|
||||
}
|
||||
|
@ -638,6 +638,14 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
|
||||
);
|
||||
(sig.inputs().to_vec(), sig.output(), None)
|
||||
}
|
||||
DefKind::Closure if coroutine_kind.is_some() => {
|
||||
let coroutine_ty = tcx.type_of(def_id).instantiate_identity();
|
||||
let ty::Coroutine(_, args, _) = coroutine_ty.kind() else { bug!() };
|
||||
let args = args.as_coroutine();
|
||||
let yield_ty = args.yield_ty();
|
||||
let return_ty = args.return_ty();
|
||||
(vec![coroutine_ty, args.resume_ty()], return_ty, Some(yield_ty))
|
||||
}
|
||||
DefKind::Closure => {
|
||||
let closure_ty = tcx.type_of(def_id).instantiate_identity();
|
||||
let ty::Closure(_, args) = closure_ty.kind() else { bug!() };
|
||||
@ -650,14 +658,6 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
|
||||
};
|
||||
([self_ty].into_iter().chain(sig.inputs().to_vec()).collect(), sig.output(), None)
|
||||
}
|
||||
DefKind::Coroutine => {
|
||||
let coroutine_ty = tcx.type_of(def_id).instantiate_identity();
|
||||
let ty::Coroutine(_, args, _) = coroutine_ty.kind() else { bug!() };
|
||||
let args = args.as_coroutine();
|
||||
let yield_ty = args.yield_ty();
|
||||
let return_ty = args.return_ty();
|
||||
(vec![coroutine_ty, args.resume_ty()], return_ty, Some(yield_ty))
|
||||
}
|
||||
dk => bug!("{:?} is not a body: {:?}", def_id, dk),
|
||||
};
|
||||
|
||||
|
@ -37,7 +37,7 @@ pub(crate) fn thir_body(
|
||||
|
||||
// The resume argument may be missing, in that case we need to provide it here.
|
||||
// It will always be `()` in this case.
|
||||
if tcx.def_kind(owner_def) == DefKind::Coroutine && body.params.is_empty() {
|
||||
if tcx.is_coroutine(owner_def.to_def_id()) && body.params.is_empty() {
|
||||
cx.thir.params.push(Param {
|
||||
ty: Ty::new_unit(tcx),
|
||||
pat: None,
|
||||
@ -119,6 +119,17 @@ impl<'tcx> Cx<'tcx> {
|
||||
|
||||
fn closure_env_param(&self, owner_def: LocalDefId, owner_id: HirId) -> Option<Param<'tcx>> {
|
||||
match self.tcx.def_kind(owner_def) {
|
||||
DefKind::Closure if self.tcx.is_coroutine(owner_def.to_def_id()) => {
|
||||
let coroutine_ty = self.typeck_results.node_type(owner_id);
|
||||
let coroutine_param = Param {
|
||||
ty: coroutine_ty,
|
||||
pat: None,
|
||||
ty_span: None,
|
||||
self_kind: None,
|
||||
hir_id: None,
|
||||
};
|
||||
Some(coroutine_param)
|
||||
}
|
||||
DefKind::Closure => {
|
||||
let closure_ty = self.typeck_results.node_type(owner_id);
|
||||
|
||||
@ -148,17 +159,6 @@ impl<'tcx> Cx<'tcx> {
|
||||
|
||||
Some(env_param)
|
||||
}
|
||||
DefKind::Coroutine => {
|
||||
let coroutine_ty = self.typeck_results.node_type(owner_id);
|
||||
let coroutine_param = Param {
|
||||
ty: coroutine_ty,
|
||||
pat: None,
|
||||
ty_span: None,
|
||||
self_kind: None,
|
||||
hir_id: None,
|
||||
};
|
||||
Some(coroutine_param)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -84,8 +84,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
|
||||
|
||||
// FIXME(welseywiser) const prop doesn't work on coroutines because of query cycles
|
||||
// computing their layout.
|
||||
let is_coroutine = def_kind == DefKind::Coroutine;
|
||||
if is_coroutine {
|
||||
if tcx.is_coroutine(def_id.to_def_id()) {
|
||||
trace!("ConstProp skipped for coroutine {:?}", def_id);
|
||||
return;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ impl<'tcx> MirLint<'tcx> for ConstPropLint {
|
||||
|
||||
// FIXME(welseywiser) const prop doesn't work on coroutines because of query cycles
|
||||
// computing their layout.
|
||||
if let DefKind::Coroutine = def_kind {
|
||||
if tcx.is_coroutine(def_id.to_def_id()) {
|
||||
trace!("ConstPropLint skipped for coroutine {:?}", def_id);
|
||||
return;
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
|
||||
/// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't
|
||||
/// end up missing the source MIR due to stealing happening.
|
||||
fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal<Body<'_>> {
|
||||
if let DefKind::Coroutine = tcx.def_kind(def) {
|
||||
if tcx.is_coroutine(def.to_def_id()) {
|
||||
tcx.ensure_with_value().mir_coroutine_witnesses(def);
|
||||
}
|
||||
let mir_borrowck = tcx.mir_borrowck(def);
|
||||
|
@ -131,7 +131,7 @@ fn mark_used_by_default_parameters<'tcx>(
|
||||
unused_parameters: &mut UnusedGenericParams,
|
||||
) {
|
||||
match tcx.def_kind(def_id) {
|
||||
DefKind::Closure | DefKind::Coroutine => {
|
||||
DefKind::Closure => {
|
||||
for param in &generics.params {
|
||||
debug!(?param, "(closure/gen)");
|
||||
unused_parameters.mark_used(param.index);
|
||||
@ -248,7 +248,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
|
||||
fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
|
||||
if local == Local::from_usize(1) {
|
||||
let def_kind = self.tcx.def_kind(self.def_id);
|
||||
if matches!(def_kind, DefKind::Closure | DefKind::Coroutine) {
|
||||
if matches!(def_kind, DefKind::Closure) {
|
||||
// Skip visiting the closure/coroutine that is currently being processed. This only
|
||||
// happens because the first argument to the closure is a reference to itself and
|
||||
// that will call `visit_args`, resulting in each generic parameter captured being
|
||||
|
@ -653,8 +653,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
|
||||
| DefKind::Field
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine => (),
|
||||
| DefKind::Closure => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -973,8 +973,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
| DefKind::LifetimeParam
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::Closure
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::Coroutine,
|
||||
| DefKind::Impl { .. },
|
||||
_,
|
||||
)
|
||||
| Res::Local(..)
|
||||
|
@ -89,7 +89,7 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
|
||||
| DefKind::GlobalAsm => {
|
||||
unreachable!("Not a valid item kind: {kind:?}");
|
||||
}
|
||||
DefKind::Closure | DefKind::Coroutine | DefKind::AssocFn | DefKind::Fn => ItemKind::Fn,
|
||||
DefKind::Closure | DefKind::AssocFn | DefKind::Fn => ItemKind::Fn,
|
||||
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
|
||||
ItemKind::Const
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ fn compute_symbol_name<'tcx>(
|
||||
// and we want to be sure to avoid any symbol conflicts here.
|
||||
let is_globally_shared_function = matches!(
|
||||
tcx.def_kind(instance.def_id()),
|
||||
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine | DefKind::Ctor(..)
|
||||
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Ctor(..)
|
||||
) && matches!(
|
||||
MonoItem::Fn(instance).instantiation_mode(tcx),
|
||||
InstantiationMode::GloballyShared { may_conflict: true }
|
||||
|
@ -156,8 +156,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
|
||||
| DefKind::Field
|
||||
| DefKind::LifetimeParam
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine => ty::List::empty(),
|
||||
| DefKind::Closure => ty::List::empty(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ fn opaque_types_defined_by<'tcx>(
|
||||
| DefKind::Impl { .. } => {}
|
||||
// Closures and coroutines are type checked with their parent, so we need to allow all
|
||||
// opaques from the closure signature *and* from the parent body.
|
||||
DefKind::Closure | DefKind::Coroutine | DefKind::InlineConst => {
|
||||
DefKind::Closure | DefKind::InlineConst => {
|
||||
collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item)));
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ pub(crate) fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
|
||||
// These are not part of a public API, they can only appear as hidden types, and there
|
||||
// the interesting parts are solely in the signature of the containing item's opaque type
|
||||
// or dyn type.
|
||||
DefKind::InlineConst | DefKind::Closure | DefKind::Coroutine => {}
|
||||
DefKind::InlineConst | DefKind::Closure => {}
|
||||
DefKind::Impl { of_trait } => {
|
||||
if of_trait {
|
||||
let span = tcx.hir().get_by_def_id(item).expect_item().expect_impl().of_trait.unwrap().path.span;
|
||||
|
@ -149,8 +149,7 @@ impl From<DefKind> for ItemType {
|
||||
| DefKind::LifetimeParam
|
||||
| DefKind::GlobalAsm
|
||||
| DefKind::Impl { .. }
|
||||
| DefKind::Closure
|
||||
| DefKind::Coroutine => Self::ForeignType,
|
||||
| DefKind::Closure => Self::ForeignType,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1924,7 +1924,6 @@ fn resolution_failure(
|
||||
Variant
|
||||
| Field
|
||||
| Closure
|
||||
| Coroutine
|
||||
| AssocTy
|
||||
| AssocConst
|
||||
| AssocFn
|
||||
|
Loading…
Reference in New Issue
Block a user