Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit712e7c3

Browse files
Rollup merge of#125088 - compiler-errors:uplift-alias-ty, r=lcnr
Uplift `AliasTy` and `AliasTerm`Follow-up from#125076.r? lcnr
2 parents8c64acd +9f8cdb2 commit712e7c3

File tree

15 files changed

+574
-534
lines changed

15 files changed

+574
-534
lines changed

‎compiler/rustc_errors/src/diagnostic_impls.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::ExistentialTrait
106106
}
107107
}
108108

109+
impl<I: rustc_type_ir::Interner>IntoDiagArgfor rustc_type_ir::UnevaluatedConst<I>{
110+
fninto_diag_arg(self) -> rustc_errors::DiagArgValue{
111+
format!("{self:?}").into_diag_arg()
112+
}
113+
}
114+
109115
into_diag_arg_for_number!(i8,u8,i16,u16,i32,u32,i64,u64,i128,u128,isize,usize);
110116

111117
implIntoDiagArgforbool{

‎compiler/rustc_middle/src/ty/consts.rs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use rustc_hir as hir;
77
use rustc_hir::def::{DefKind,Res};
88
use rustc_hir::def_id::LocalDefId;
99
use rustc_macros::{HashStable,TyDecodable,TyEncodable};
10-
use rustc_type_ir::ConstKindasIrConstKind;
11-
use rustc_type_ir::{TypeFlags,WithCachedTypeInfo};
10+
use rustc_type_ir::{selfas ir,TypeFlags,WithCachedTypeInfo};
1211

1312
mod int;
1413
mod kind;
@@ -20,7 +19,8 @@ use rustc_span::Span;
2019
use rustc_span::DUMMY_SP;
2120
pubuse valtree::*;
2221

23-
pubtypeConstKind<'tcx> =IrConstKind<TyCtxt<'tcx>>;
22+
pubtypeConstKind<'tcx> = ir::ConstKind<TyCtxt<'tcx>>;
23+
pubtypeUnevaluatedConst<'tcx> = ir::UnevaluatedConst<TyCtxt<'tcx>>;
2424

2525
#[cfg(target_pointer_width ="64")]
2626
rustc_data_structures::static_assert_size!(ConstKind<'_>,32);
@@ -184,6 +184,14 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
184184
Const::new_bound(tcx, debruijn, var, ty)
185185
}
186186

187+
fnnew_unevaluated(
188+
interner:TyCtxt<'tcx>,
189+
uv: ty::UnevaluatedConst<'tcx>,
190+
ty:Ty<'tcx>,
191+
) ->Self{
192+
Const::new_unevaluated(interner, uv, ty)
193+
}
194+
187195
fnty(self) ->Ty<'tcx>{
188196
self.ty()
189197
}

‎compiler/rustc_middle/src/ty/consts/kind.rs‎

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
usesuper::Const;
22
usecrate::mir;
33
usecrate::ty::abstract_const::CastKind;
4-
usecrate::ty::GenericArgsRef;
54
usecrate::ty::{self, visit::TypeVisitableExtas _,List,Ty,TyCtxt};
6-
use rustc_hir::def_id::DefId;
7-
use rustc_macros::{HashStable,TyDecodable,TyEncodable,TypeFoldable,TypeVisitable};
5+
use rustc_macros::{extension,HashStable,TyDecodable,TyEncodable,TypeFoldable,TypeVisitable};
86

9-
/// An unevaluated (potentially generic) constant used in the type-system.
10-
#[derive(Copy,Clone,Eq,PartialEq,TyEncodable,TyDecodable)]
11-
#[derive(Hash,HashStable,TypeFoldable,TypeVisitable)]
12-
pubstructUnevaluatedConst<'tcx>{
13-
pubdef:DefId,
14-
pubargs:GenericArgsRef<'tcx>,
15-
}
16-
17-
impl rustc_errors::IntoDiagArgforUnevaluatedConst<'_>{
18-
fninto_diag_arg(self) -> rustc_errors::DiagArgValue{
19-
format!("{self:?}").into_diag_arg()
20-
}
21-
}
22-
23-
impl<'tcx>UnevaluatedConst<'tcx>{
7+
#[extension(pub(crate)traitUnevaluatedConstEvalExt<'tcx>)]
8+
impl<'tcx> ty::UnevaluatedConst<'tcx>{
249
/// FIXME(RalfJung): I cannot explain what this does or why it makes sense, but not doing this
2510
/// hurts performance.
2611
#[inline]
27-
pub(crate)fnprepare_for_eval(
12+
fnprepare_for_eval(
2813
self,
2914
tcx:TyCtxt<'tcx>,
3015
param_env: ty::ParamEnv<'tcx>,
@@ -55,13 +40,6 @@ impl<'tcx> UnevaluatedConst<'tcx> {
5540
}
5641
}
5742

58-
impl<'tcx>UnevaluatedConst<'tcx>{
59-
#[inline]
60-
pubfnnew(def:DefId,args:GenericArgsRef<'tcx>) ->UnevaluatedConst<'tcx>{
61-
UnevaluatedConst{ def, args}
62-
}
63-
}
64-
6543
#[derive(Copy,Clone,Eq,PartialEq,Hash)]
6644
#[derive(HashStable,TyEncodable,TyDecodable,TypeVisitable,TypeFoldable)]
6745
pubenumExpr<'tcx>{

‎compiler/rustc_middle/src/ty/context.rs‎

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ use rustc_type_ir::TyKind::*;
7676
use rustc_type_ir::WithCachedTypeInfo;
7777
use rustc_type_ir::{CollectAndApply,Interner,TypeFlags};
7878

79+
use std::assert_matches::assert_matches;
7980
use std::borrow::Borrow;
8081
use std::cmp::Ordering;
8182
use std::fmt;
@@ -91,67 +92,124 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
9192
typeDefiningOpaqueTypes =&'tcx ty::List<LocalDefId>;
9293
typeAdtDef = ty::AdtDef<'tcx>;
9394
typeGenericArgs = ty::GenericArgsRef<'tcx>;
95+
typeGenericArgsSlice =&'tcx[ty::GenericArg<'tcx>];
9496
typeGenericArg = ty::GenericArg<'tcx>;
95-
typeTerm = ty::Term<'tcx>;
9697

98+
typeTerm = ty::Term<'tcx>;
9799
typeBinder<T:TypeVisitable<TyCtxt<'tcx>>> =Binder<'tcx,T>;
98100
typeBoundVars =&'tcxList<ty::BoundVariableKind>;
99101
typeBoundVar = ty::BoundVariableKind;
100-
typeCanonicalVars =CanonicalVarInfos<'tcx>;
101102

103+
typeCanonicalVars =CanonicalVarInfos<'tcx>;
102104
typeTy =Ty<'tcx>;
103105
typeTys =&'tcxList<Ty<'tcx>>;
104-
typeAliasTy = ty::AliasTy<'tcx>;
105106
typeParamTy =ParamTy;
106107
typeBoundTy = ty::BoundTy;
107108
typePlaceholderTy = ty::PlaceholderType;
108-
typeErrorGuaranteed =ErrorGuaranteed;
109109

110+
typeErrorGuaranteed =ErrorGuaranteed;
110111
typeBoundExistentialPredicates =&'tcxList<PolyExistentialPredicate<'tcx>>;
111112
typePolyFnSig =PolyFnSig<'tcx>;
112113
typeAllocId =crate::mir::interpret::AllocId;
113-
typePat =Pattern<'tcx>;
114114

115+
typePat =Pattern<'tcx>;
115116
typeConst = ty::Const<'tcx>;
116117
typeAliasConst = ty::UnevaluatedConst<'tcx>;
117118
typePlaceholderConst = ty::PlaceholderConst;
118119
typeParamConst = ty::ParamConst;
119120
typeBoundConst = ty::BoundVar;
120121
typeValueConst = ty::ValTree<'tcx>;
121-
typeExprConst = ty::Expr<'tcx>;
122122

123+
typeExprConst = ty::Expr<'tcx>;
123124
typeRegion =Region<'tcx>;
124125
typeEarlyParamRegion = ty::EarlyParamRegion;
125126
typeLateParamRegion = ty::LateParamRegion;
126127
typeBoundRegion = ty::BoundRegion;
127128
typeInferRegion = ty::RegionVid;
128-
typePlaceholderRegion = ty::PlaceholderRegion;
129129

130+
typePlaceholderRegion = ty::PlaceholderRegion;
130131
typePredicate =Predicate<'tcx>;
131132
typeTraitPredicate = ty::TraitPredicate<'tcx>;
132133
typeRegionOutlivesPredicate = ty::RegionOutlivesPredicate<'tcx>;
133134
typeTypeOutlivesPredicate = ty::TypeOutlivesPredicate<'tcx>;
134135
typeProjectionPredicate = ty::ProjectionPredicate<'tcx>;
135-
typeAliasTerm = ty::AliasTerm<'tcx>;
136136
typeNormalizesTo = ty::NormalizesTo<'tcx>;
137137
typeSubtypePredicate = ty::SubtypePredicate<'tcx>;
138138
typeCoercePredicate = ty::CoercePredicate<'tcx>;
139139
typeClosureKind = ty::ClosureKind;
140-
typeClauses = ty::Clauses<'tcx>;
141140

141+
typeClauses = ty::Clauses<'tcx>;
142142
fnmk_canonical_var_infos(self,infos:&[ty::CanonicalVarInfo<Self>]) ->Self::CanonicalVars{
143143
self.mk_canonical_var_infos(infos)
144144
}
145145

146146
typeGenericsOf =&'tcx ty::Generics;
147+
147148
fngenerics_of(self,def_id:DefId) ->&'tcx ty::Generics{
148149
self.generics_of(def_id)
149150
}
150151

152+
fntype_of_instantiated(self,def_id:DefId,args: ty::GenericArgsRef<'tcx>) ->Ty<'tcx>{
153+
self.type_of(def_id).instantiate(self, args)
154+
}
155+
156+
fnalias_ty_kind(self,alias: ty::AliasTy<'tcx>) -> ty::AliasTyKind{
157+
matchself.def_kind(alias.def_id){
158+
DefKind::AssocTy =>{
159+
ifletDefKind::Impl{of_trait:false} =self.def_kind(self.parent(alias.def_id))
160+
{
161+
ty::Inherent
162+
}else{
163+
ty::Projection
164+
}
165+
}
166+
DefKind::OpaqueTy => ty::Opaque,
167+
DefKind::TyAlias => ty::Weak,
168+
kind =>bug!("unexpected DefKind in AliasTy: {kind:?}"),
169+
}
170+
}
171+
172+
fnalias_term_kind(self,alias: ty::AliasTerm<'tcx>) -> ty::AliasTermKind{
173+
matchself.def_kind(alias.def_id){
174+
DefKind::AssocTy =>{
175+
ifletDefKind::Impl{of_trait:false} =self.def_kind(self.parent(alias.def_id))
176+
{
177+
ty::AliasTermKind::InherentTy
178+
}else{
179+
ty::AliasTermKind::ProjectionTy
180+
}
181+
}
182+
DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy,
183+
DefKind::TyAlias => ty::AliasTermKind::WeakTy,
184+
DefKind::AssocConst => ty::AliasTermKind::ProjectionConst,
185+
DefKind::AnonConst => ty::AliasTermKind::UnevaluatedConst,
186+
kind =>bug!("unexpected DefKind in AliasTy: {kind:?}"),
187+
}
188+
}
189+
190+
fntrait_ref_and_own_args_for_alias(
191+
self,
192+
def_id:Self::DefId,
193+
args:Self::GenericArgs,
194+
) ->(rustc_type_ir::TraitRef<Self>,Self::GenericArgsSlice){
195+
assert_matches!(self.def_kind(def_id),DefKind::AssocTy |DefKind::AssocConst);
196+
let trait_def_id =self.parent(def_id);
197+
assert_matches!(self.def_kind(trait_def_id),DefKind::Trait);
198+
let trait_generics =self.generics_of(trait_def_id);
199+
(
200+
ty::TraitRef::new(self, trait_def_id, args.truncate_to(self, trait_generics)),
201+
&args[trait_generics.count()..],
202+
)
203+
}
204+
151205
fnmk_args(self,args:&[Self::GenericArg]) ->Self::GenericArgs{
152206
self.mk_args(args)
153207
}
154208

209+
fnmk_args_from_iter(self,args:implIterator<Item =Self::GenericArg>) ->Self::GenericArgs{
210+
self.mk_args_from_iter(args)
211+
}
212+
155213
fncheck_and_mk_args(
156214
self,
157215
def_id:DefId,

‎compiler/rustc_middle/src/ty/mod.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ pub use self::list::{List, ListWithCachedTypeInfo};
9696
pubuseself::parameterized::ParameterizedOverTcx;
9797
pubuseself::pattern::{Pattern,PatternKind};
9898
pubuseself::predicate::{
99-
Clause,ClauseKind,CoercePredicate,ExistentialPredicate,ExistentialPredicateStableCmpExt,
100-
ExistentialProjection,ExistentialTraitRef,NormalizesTo,OutlivesPredicate,
101-
PolyCoercePredicate,PolyExistentialPredicate,PolyExistentialProjection,
99+
AliasTerm,Clause,ClauseKind,CoercePredicate,ExistentialPredicate,
100+
ExistentialPredicateStableCmpExt,ExistentialProjection,ExistentialTraitRef,NormalizesTo,
101+
OutlivesPredicate,PolyCoercePredicate,PolyExistentialPredicate,PolyExistentialProjection,
102102
PolyExistentialTraitRef,PolyProjectionPredicate,PolyRegionOutlivesPredicate,
103103
PolySubtypePredicate,PolyTraitPredicate,PolyTraitRef,PolyTypeOutlivesPredicate,Predicate,
104104
PredicateKind,ProjectionPredicate,RegionOutlivesPredicate,SubtypePredicate,ToPolyTraitRef,
@@ -110,11 +110,11 @@ pub use self::region::{
110110
};
111111
pubuseself::rvalue_scopes::RvalueScopes;
112112
pubuseself::sty::{
113-
AliasTerm,AliasTy,Article,Binder,BoundTy,BoundTyKind,BoundVariableKind,
114-
CanonicalPolyFnSig,ClosureArgs,ClosureArgsParts,CoroutineArgs,CoroutineArgsParts,
115-
CoroutineClosureArgs,CoroutineClosureArgsParts,CoroutineClosureSignature,FnSig,GenSig,
116-
InlineConstArgs,InlineConstArgsParts,ParamConst,ParamTy,PolyFnSig,TyKind,TypeAndMut,
117-
UpvarArgs,VarianceDiagInfo,
113+
AliasTy,Article,Binder,BoundTy,BoundTyKind,BoundVariableKind,CanonicalPolyFnSig,
114+
ClosureArgs,ClosureArgsParts,CoroutineArgs,CoroutineArgsParts,CoroutineClosureArgs,
115+
CoroutineClosureArgsParts,CoroutineClosureSignature,FnSig,GenSig,InlineConstArgs,
116+
InlineConstArgsParts,ParamConst,ParamTy,PolyFnSig,TyKind,TypeAndMut,UpvarArgs,
117+
VarianceDiagInfo,
118118
};
119119
pubuseself::trait_def::TraitDef;
120120
pubuseself::typeck_results::{

‎compiler/rustc_middle/src/ty/predicate.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::ty::{
1313
};
1414

1515
pubtypeTraitRef<'tcx> = ir::TraitRef<TyCtxt<'tcx>>;
16+
pubtypeAliasTerm<'tcx> = ir::AliasTerm<TyCtxt<'tcx>>;
1617
pubtypeProjectionPredicate<'tcx> = ir::ProjectionPredicate<TyCtxt<'tcx>>;
1718
pubtypeExistentialPredicate<'tcx> = ir::ExistentialPredicate<TyCtxt<'tcx>>;
1819
pubtypeExistentialTraitRef<'tcx> = ir::ExistentialTraitRef<TyCtxt<'tcx>>;

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,6 +3038,33 @@ define_print! {
30383038
p!(write("<{} as {}>",self.self_ty(),self.print_only_trait_path()))
30393039
}
30403040

3041+
ty::AliasTy<'tcx>{
3042+
let alias_term: ty::AliasTerm<'tcx> =(*self).into();
3043+
p!(print(alias_term))
3044+
}
3045+
3046+
ty::AliasTerm<'tcx>{
3047+
matchself.kind(cx.tcx()){
3048+
ty::AliasTermKind::InherentTy => p!(pretty_print_inherent_projection(*self)),
3049+
ty::AliasTermKind::ProjectionTy
3050+
| ty::AliasTermKind::WeakTy
3051+
| ty::AliasTermKind::OpaqueTy
3052+
| ty::AliasTermKind::UnevaluatedConst
3053+
| ty::AliasTermKind::ProjectionConst =>{
3054+
// If we're printing verbosely, or don't want to invoke queries
3055+
// (`is_impl_trait_in_trait`), then fall back to printing the def path.
3056+
// This is likely what you want if you're debugging the compiler anyways.
3057+
if !(cx.should_print_verbose() || with_reduced_queries())
3058+
&& cx.tcx().is_impl_trait_in_trait(self.def_id)
3059+
{
3060+
return cx.pretty_print_opaque_impl_type(self.def_id,self.args);
3061+
} else{
3062+
p!(print_def_path(self.def_id,self.args));
3063+
}
3064+
}
3065+
}
3066+
}
3067+
30413068
ty::TraitPredicate<'tcx>{
30423069
p!(print(self.trait_ref.self_ty()),": ");
30433070
p!(pretty_print_bound_constness(self.trait_ref));
@@ -3205,33 +3232,6 @@ define_print_and_forward_display! {
32053232
}
32063233
}
32073234

3208-
ty::AliasTy<'tcx>{
3209-
let alias_term: ty::AliasTerm<'tcx> =(*self).into();
3210-
p!(print(alias_term))
3211-
}
3212-
3213-
ty::AliasTerm<'tcx>{
3214-
matchself.kind(cx.tcx()){
3215-
ty::AliasTermKind::InherentTy => p!(pretty_print_inherent_projection(*self)),
3216-
ty::AliasTermKind::ProjectionTy
3217-
| ty::AliasTermKind::WeakTy
3218-
| ty::AliasTermKind::OpaqueTy
3219-
| ty::AliasTermKind::UnevaluatedConst
3220-
| ty::AliasTermKind::ProjectionConst =>{
3221-
// If we're printing verbosely, or don't want to invoke queries
3222-
// (`is_impl_trait_in_trait`), then fall back to printing the def path.
3223-
// This is likely what you want if you're debugging the compiler anyways.
3224-
if !(cx.should_print_verbose() || with_reduced_queries())
3225-
&& cx.tcx().is_impl_trait_in_trait(self.def_id)
3226-
{
3227-
return cx.pretty_print_opaque_impl_type(self.def_id,self.args);
3228-
} else{
3229-
p!(print_def_path(self.def_id,self.args));
3230-
}
3231-
}
3232-
}
3233-
}
3234-
32353235
ty::Predicate<'tcx>{
32363236
p!(print(self.kind()))
32373237
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp