Skip to content

Commit 0038c02

Browse files
committed
Auto merge of rust-lang#125775 - compiler-errors:uplift-closure-args, r=lcnr
Uplift `{Closure,Coroutine,CoroutineClosure}Args` and friends to `rustc_type_ir` Part of converting the new solver's `structural_traits.rs` to be interner-agnostic. I decided against aliasing `ClosureArgs<TyCtxt<'tcx>>` to `ClosureArgs<'tcx>` because it seemed so rare. I could do so if desired, though. r? lcnr
2 parents a94483a + 333458c commit 0038c02

File tree

29 files changed

+897
-768
lines changed

29 files changed

+897
-768
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ use rustc_middle::ty::adjustment::PointerCoercion;
2727
use rustc_middle::ty::cast::CastTy;
2828
use rustc_middle::ty::visit::TypeVisitableExt;
2929
use rustc_middle::ty::{
30-
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, Dynamic,
31-
OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
30+
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt,
31+
Dynamic, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType,
32+
UserTypeAnnotationIndex,
3233
};
3334
use rustc_middle::ty::{GenericArgsRef, UserArgs};
3435
use rustc_middle::{bug, span_bug};

compiler/rustc_codegen_gcc/src/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, LayoutTypeM
55
use rustc_middle::bug;
66
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
77
use rustc_middle::ty::print::with_no_trimmed_paths;
8-
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
8+
use rustc_middle::ty::{self, CoroutineArgsExt, Ty, TypeVisitableExt};
99
use rustc_target::abi::call::{CastTarget, FnAbi, Reg};
1010
use rustc_target::abi::{
1111
self, Abi, Align, FieldsShape, Float, Int, Integer, PointeeInfo, Pointer, Size, TyAbiInterface,

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE};
3131
use rustc_middle::bug;
3232
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
3333
use rustc_middle::ty::{
34-
self, AdtKind, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt, Visibility,
34+
self, AdtKind, CoroutineArgsExt, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt,
35+
Visibility,
3536
};
3637
use rustc_session::config::{self, DebugInfo, Lto};
3738
use rustc_span::symbol::Symbol;

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::{
1212
ty::{
1313
self,
1414
layout::{LayoutOf, TyAndLayout},
15-
AdtDef, CoroutineArgs, Ty,
15+
AdtDef, CoroutineArgs, CoroutineArgsExt, Ty,
1616
},
1717
};
1818
use rustc_target::abi::{Align, Endian, Size, TagEncoding, VariantIdx, Variants};

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::{
1010
ty::{
1111
self,
1212
layout::{IntegerExt, LayoutOf, PrimitiveExt, TyAndLayout},
13-
AdtDef, CoroutineArgs, Ty, VariantDef,
13+
AdtDef, CoroutineArgs, CoroutineArgsExt, Ty, VariantDef,
1414
},
1515
};
1616
use rustc_span::Symbol;

compiler/rustc_codegen_llvm/src/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_codegen_ssa::traits::*;
44
use rustc_middle::bug;
55
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
66
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
7-
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
7+
use rustc_middle::ty::{self, CoroutineArgsExt, Ty, TypeVisitableExt};
88
use rustc_target::abi::{Abi, Align, FieldsShape};
99
use rustc_target::abi::{Float, Int, Pointer};
1010
use rustc_target::abi::{Scalar, Size, Variants};

compiler/rustc_const_eval/src/interpret/discriminant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use rustc_middle::mir;
44
use rustc_middle::span_bug;
55
use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt};
6-
use rustc_middle::ty::{self, ScalarInt, Ty};
6+
use rustc_middle::ty::{self, CoroutineArgsExt, ScalarInt, Ty};
77
use rustc_target::abi::{self, TagEncoding};
88
use rustc_target::abi::{VariantIdx, Variants};
99
use tracing::{instrument, trace};

compiler/rustc_middle/src/mir/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Values computed by queries that use MIR.
22
33
use crate::mir;
4-
use crate::ty::{self, OpaqueHiddenType, Ty, TyCtxt};
4+
use crate::ty::{self, CoroutineArgsExt, OpaqueHiddenType, Ty, TyCtxt};
55
use rustc_data_structures::fx::FxIndexMap;
66
use rustc_errors::ErrorGuaranteed;
77
use rustc_hir::def_id::LocalDefId;

compiler/rustc_middle/src/ty/context.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
9090
type AdtDef = ty::AdtDef<'tcx>;
9191

9292
type GenericArgs = ty::GenericArgsRef<'tcx>;
93-
type OwnItemArgs = &'tcx [ty::GenericArg<'tcx>];
93+
type GenericArgsSlice = &'tcx [ty::GenericArg<'tcx>];
9494
type GenericArg = ty::GenericArg<'tcx>;
9595
type Term = ty::Term<'tcx>;
9696

@@ -113,7 +113,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
113113

114114
type ErrorGuaranteed = ErrorGuaranteed;
115115
type BoundExistentialPredicates = &'tcx List<PolyExistentialPredicate<'tcx>>;
116-
type PolyFnSig = PolyFnSig<'tcx>;
117116
type AllocId = crate::mir::interpret::AllocId;
118117

119118
type Pat = Pattern<'tcx>;
@@ -191,7 +190,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
191190
self,
192191
def_id: Self::DefId,
193192
args: Self::GenericArgs,
194-
) -> (rustc_type_ir::TraitRef<Self>, Self::OwnItemArgs) {
193+
) -> (rustc_type_ir::TraitRef<Self>, Self::GenericArgsSlice) {
195194
assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
196195
let trait_def_id = self.parent(def_id);
197196
assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);

compiler/rustc_middle/src/ty/generic_args.rs

+64-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
use crate::ty::codec::{TyDecoder, TyEncoder};
44
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable};
5-
use crate::ty::sty::{ClosureArgs, CoroutineArgs, CoroutineClosureArgs, InlineConstArgs};
65
use crate::ty::visit::{TypeVisitable, TypeVisitor};
7-
use crate::ty::{self, Lift, List, Ty, TyCtxt};
6+
use crate::ty::{
7+
self, ClosureArgs, CoroutineArgs, CoroutineClosureArgs, InlineConstArgs, Lift, List, Ty, TyCtxt,
8+
};
89

910
use rustc_ast_ir::visit::VisitorResult;
1011
use rustc_ast_ir::walk_visitable_list;
@@ -56,6 +57,64 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
5657
) -> ty::GenericArgsRef<'tcx> {
5758
ty::GenericArgs::extend_with_error(tcx, def_id, original_args)
5859
}
60+
61+
fn split_closure_args(self) -> ty::ClosureArgsParts<TyCtxt<'tcx>> {
62+
match self[..] {
63+
[ref parent_args @ .., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => {
64+
ty::ClosureArgsParts {
65+
parent_args,
66+
closure_kind_ty: closure_kind_ty.expect_ty(),
67+
closure_sig_as_fn_ptr_ty: closure_sig_as_fn_ptr_ty.expect_ty(),
68+
tupled_upvars_ty: tupled_upvars_ty.expect_ty(),
69+
}
70+
}
71+
_ => bug!("closure args missing synthetics"),
72+
}
73+
}
74+
75+
fn split_coroutine_closure_args(self) -> ty::CoroutineClosureArgsParts<TyCtxt<'tcx>> {
76+
match self[..] {
77+
[
78+
ref parent_args @ ..,
79+
closure_kind_ty,
80+
signature_parts_ty,
81+
tupled_upvars_ty,
82+
coroutine_captures_by_ref_ty,
83+
coroutine_witness_ty,
84+
] => ty::CoroutineClosureArgsParts {
85+
parent_args,
86+
closure_kind_ty: closure_kind_ty.expect_ty(),
87+
signature_parts_ty: signature_parts_ty.expect_ty(),
88+
tupled_upvars_ty: tupled_upvars_ty.expect_ty(),
89+
coroutine_captures_by_ref_ty: coroutine_captures_by_ref_ty.expect_ty(),
90+
coroutine_witness_ty: coroutine_witness_ty.expect_ty(),
91+
},
92+
_ => bug!("closure args missing synthetics"),
93+
}
94+
}
95+
96+
fn split_coroutine_args(self) -> ty::CoroutineArgsParts<TyCtxt<'tcx>> {
97+
match self[..] {
98+
[
99+
ref parent_args @ ..,
100+
kind_ty,
101+
resume_ty,
102+
yield_ty,
103+
return_ty,
104+
witness,
105+
tupled_upvars_ty,
106+
] => ty::CoroutineArgsParts {
107+
parent_args,
108+
kind_ty: kind_ty.expect_ty(),
109+
resume_ty: resume_ty.expect_ty(),
110+
yield_ty: yield_ty.expect_ty(),
111+
return_ty: return_ty.expect_ty(),
112+
witness: witness.expect_ty(),
113+
tupled_upvars_ty: tupled_upvars_ty.expect_ty(),
114+
},
115+
_ => bug!("coroutine args missing synthetics"),
116+
}
117+
}
59118
}
60119

61120
impl<'tcx> rustc_type_ir::inherent::IntoKind for GenericArg<'tcx> {
@@ -295,23 +354,23 @@ impl<'tcx> GenericArgs<'tcx> {
295354
/// Closure args have a particular structure controlled by the
296355
/// compiler that encodes information like the signature and closure kind;
297356
/// see `ty::ClosureArgs` struct for more comments.
298-
pub fn as_closure(&'tcx self) -> ClosureArgs<'tcx> {
357+
pub fn as_closure(&'tcx self) -> ClosureArgs<TyCtxt<'tcx>> {
299358
ClosureArgs { args: self }
300359
}
301360

302361
/// Interpret these generic args as the args of a coroutine-closure type.
303362
/// Coroutine-closure args have a particular structure controlled by the
304363
/// compiler that encodes information like the signature and closure kind;
305364
/// see `ty::CoroutineClosureArgs` struct for more comments.
306-
pub fn as_coroutine_closure(&'tcx self) -> CoroutineClosureArgs<'tcx> {
365+
pub fn as_coroutine_closure(&'tcx self) -> CoroutineClosureArgs<TyCtxt<'tcx>> {
307366
CoroutineClosureArgs { args: self }
308367
}
309368

310369
/// Interpret these generic args as the args of a coroutine type.
311370
/// Coroutine args have a particular structure controlled by the
312371
/// compiler that encodes information like the signature and coroutine kind;
313372
/// see `ty::CoroutineArgs` struct for more comments.
314-
pub fn as_coroutine(&'tcx self) -> CoroutineArgs<'tcx> {
373+
pub fn as_coroutine(&'tcx self) -> CoroutineArgs<TyCtxt<'tcx>> {
315374
CoroutineArgs { args: self }
316375
}
317376

compiler/rustc_middle/src/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::error::UnsupportedFnAbi;
22
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
33
use crate::query::TyCtxtAt;
44
use crate::ty::normalize_erasing_regions::NormalizationError;
5-
use crate::ty::{self, Ty, TyCtxt, TypeVisitableExt};
5+
use crate::ty::{self, CoroutineArgsExt, Ty, TyCtxt, TypeVisitableExt};
66
use rustc_error_messages::DiagMessage;
77
use rustc_errors::{
88
Diag, DiagArgValue, DiagCtxt, Diagnostic, EmissionGuarantee, IntoDiagArg, Level,

compiler/rustc_middle/src/ty/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ pub use self::region::{
113113
pub use self::rvalue_scopes::RvalueScopes;
114114
pub use self::sty::{
115115
AliasTy, Article, Binder, BoundTy, BoundTyKind, BoundVariableKind, CanonicalPolyFnSig,
116-
ClosureArgs, ClosureArgsParts, CoroutineArgs, CoroutineArgsParts, CoroutineClosureArgs,
117-
CoroutineClosureArgsParts, CoroutineClosureSignature, EarlyBinder, FnSig, GenSig,
118-
InlineConstArgs, InlineConstArgsParts, ParamConst, ParamTy, PolyFnSig, TyKind, TypeAndMut,
119-
UpvarArgs, VarianceDiagInfo,
116+
CoroutineArgsExt, EarlyBinder, FnSig, InlineConstArgs, InlineConstArgsParts, ParamConst,
117+
ParamTy, PolyFnSig, TyKind, TypeAndMut, UpvarArgs, VarianceDiagInfo,
120118
};
121119
pub use self::trait_def::TraitDef;
122120
pub use self::typeck_results::{

compiler/rustc_middle/src/ty/print/pretty.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
19381938
Ok(())
19391939
}
19401940

1941-
fn pretty_closure_as_impl(&mut self, closure: ty::ClosureArgs<'tcx>) -> Result<(), PrintError> {
1941+
fn pretty_closure_as_impl(
1942+
&mut self,
1943+
closure: ty::ClosureArgs<TyCtxt<'tcx>>,
1944+
) -> Result<(), PrintError> {
19421945
let sig = closure.sig();
19431946
let kind = closure.kind_ty().to_opt_closure_kind().unwrap_or(ty::ClosureKind::Fn);
19441947

@@ -2973,7 +2976,7 @@ impl<'tcx> ty::PolyTraitPredicate<'tcx> {
29732976

29742977
#[derive(Debug, Copy, Clone, Lift)]
29752978
pub struct PrintClosureAsImpl<'tcx> {
2976-
pub closure: ty::ClosureArgs<'tcx>,
2979+
pub closure: ty::ClosureArgs<TyCtxt<'tcx>>,
29772980
}
29782981

29792982
macro_rules! forward_display_to_print {

compiler/rustc_middle/src/ty/relate.rs

-22
Original file line numberDiff line numberDiff line change
@@ -756,28 +756,6 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
756756
}
757757
}
758758

759-
impl<'tcx> Relate<'tcx> for ty::ClosureArgs<'tcx> {
760-
fn relate<R: TypeRelation<'tcx>>(
761-
relation: &mut R,
762-
a: ty::ClosureArgs<'tcx>,
763-
b: ty::ClosureArgs<'tcx>,
764-
) -> RelateResult<'tcx, ty::ClosureArgs<'tcx>> {
765-
let args = relate_args_invariantly(relation, a.args, b.args)?;
766-
Ok(ty::ClosureArgs { args })
767-
}
768-
}
769-
770-
impl<'tcx> Relate<'tcx> for ty::CoroutineArgs<'tcx> {
771-
fn relate<R: TypeRelation<'tcx>>(
772-
relation: &mut R,
773-
a: ty::CoroutineArgs<'tcx>,
774-
b: ty::CoroutineArgs<'tcx>,
775-
) -> RelateResult<'tcx, ty::CoroutineArgs<'tcx>> {
776-
let args = relate_args_invariantly(relation, a.args, b.args)?;
777-
Ok(ty::CoroutineArgs { args })
778-
}
779-
}
780-
781759
impl<'tcx> Relate<'tcx> for GenericArgsRef<'tcx> {
782760
fn relate<R: TypeRelation<'tcx>>(
783761
relation: &mut R,

compiler/rustc_middle/src/ty/structural_impls.rs

-12
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,6 @@ impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for Region<'tcx> {
259259
}
260260
}
261261

262-
impl<'tcx, T: DebugWithInfcx<TyCtxt<'tcx>>> DebugWithInfcx<TyCtxt<'tcx>> for ty::Binder<'tcx, T> {
263-
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
264-
this: WithInfcx<'_, Infcx, &Self>,
265-
f: &mut core::fmt::Formatter<'_>,
266-
) -> core::fmt::Result {
267-
f.debug_tuple("Binder")
268-
.field(&this.map(|data| data.as_ref().skip_binder()))
269-
.field(&this.data.bound_vars())
270-
.finish()
271-
}
272-
}
273-
274262
///////////////////////////////////////////////////////////////////////////
275263
// Atomic structs
276264
//

0 commit comments

Comments
 (0)