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

Commitfa84018

Browse files
Apply nits
1 parent3bcdf30 commitfa84018

File tree

17 files changed

+73
-137
lines changed

17 files changed

+73
-137
lines changed

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
421421
);
422422
debug!(?alias_args);
423423

424-
// Note that we're indeed also using `AliasTy` (alias *type*) for associated
425-
// *constants* to represent *const projections*. Alias *term* would be a more
426-
// appropriate name but alas.
427424
ty::AliasTerm::new(tcx, assoc_item.def_id, alias_args)
428425
});
429426

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -625,22 +625,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
625625
let bound_predicate = pred.kind();
626626
match bound_predicate.skip_binder(){
627627
ty::PredicateKind::Clause(ty::ClauseKind::Projection(pred)) =>{
628-
let pred = bound_predicate.rebind(pred);
629628
// `<Foo as Iterator>::Item = String`.
630-
let projection_term = pred.skip_binder().projection_term;
631-
632-
let args_with_infer_self = tcx.mk_args_from_iter(
633-
std::iter::once(Ty::new_var(tcx, ty::TyVid::ZERO).into())
634-
.chain(projection_term.args.iter().skip(1)),
635-
);
636-
637-
let quiet_projection_ty =
638-
ty::AliasTerm::new(tcx, projection_term.def_id, args_with_infer_self);
639-
640-
let term = pred.skip_binder().term;
629+
let projection_term = pred.projection_term;
630+
let quiet_projection_term =
631+
projection_term.with_self_ty(tcx,Ty::new_var(tcx, ty::TyVid::ZERO));
641632

633+
let term = pred.term;
642634
let obligation =format!("{projection_term} = {term}");
643-
let quiet =format!("{quiet_projection_ty} = {term}");
635+
let quiet =format!("{quiet_projection_term} = {term}");
644636

645637
bound_span_label(projection_term.self_ty(),&obligation,&quiet);
646638
Some((obligation, projection_term.self_ty()))

‎compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,23 +258,20 @@ fn unconstrained_parent_impl_args<'tcx>(
258258
// unconstrained parameters.
259259
for(clause, _)in impl_generic_predicates.predicates.iter(){
260260
iflet ty::ClauseKind::Projection(proj) = clause.kind().skip_binder(){
261-
let projection_term = proj.projection_term;
262-
let projected_term = proj.term;
263-
264-
let unbound_trait_ref = projection_term.trait_ref(tcx);
261+
let unbound_trait_ref = proj.projection_term.trait_ref(tcx);
265262
ifSome(unbound_trait_ref) == impl_trait_ref{
266263
continue;
267264
}
268265

269-
unconstrained_parameters.extend(cgp::parameters_for(tcx, projection_term,true));
266+
unconstrained_parameters.extend(cgp::parameters_for(tcx,proj.projection_term,true));
270267

271-
for paramin cgp::parameters_for(tcx,projected_term,false){
268+
for paramin cgp::parameters_for(tcx,proj.term,false){
272269
if !unconstrained_parameters.contains(&param){
273270
constrained_params.insert(param.0);
274271
}
275272
}
276273

277-
unconstrained_parameters.extend(cgp::parameters_for(tcx,projected_term,true));
274+
unconstrained_parameters.extend(cgp::parameters_for(tcx,proj.term,true));
278275
}
279276
}
280277

‎compiler/rustc_hir_typeck/src/method/suggest.rs‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use std::borrow::Cow;
4646
usesuper::probe::{AutorefOrPtrAdjustment,IsSuggestion,Mode,ProbeScope};
4747
usesuper::{CandidateSource,MethodError,NoMatchData};
4848
use rustc_hir::intravisit::Visitor;
49-
use std::iter;
5049

5150
impl<'a,'tcx>FnCtxt<'a,'tcx>{
5251
fnis_fn_ty(&self,ty:Ty<'tcx>,span:Span) ->bool{
@@ -788,14 +787,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
788787
let pred = bound_predicate.rebind(pred);
789788
// `<Foo as Iterator>::Item = String`.
790789
let projection_term = pred.skip_binder().projection_term;
791-
792-
let args_with_infer_self = tcx.mk_args_from_iter(
793-
iter::once(Ty::new_var(tcx, ty::TyVid::ZERO).into())
794-
.chain(projection_term.args.iter().skip(1)),
795-
);
796-
797790
let quiet_projection_term =
798-
ty::AliasTerm::new(tcx,projection_term.def_id, args_with_infer_self);
791+
projection_term.with_self_ty(tcx,Ty::new_var(tcx,ty::TyVid::ZERO));
799792

800793
let term = pred.skip_binder().term;
801794

‎compiler/rustc_infer/src/traits/project.rs‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub enum ProjectionCacheEntry<'tcx> {
9393
Ambiguous,
9494
Recur,
9595
Error,
96-
NormalizedTy{
96+
NormalizedTerm{
9797
ty:NormalizedTerm<'tcx>,
9898
/// If we were able to successfully evaluate the
9999
/// corresponding cache entry key during predicate
@@ -186,7 +186,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
186186
return;
187187
}
188188
let fresh_key =
189-
map.insert(key,ProjectionCacheEntry::NormalizedTy{ty: value,complete:None});
189+
map.insert(key,ProjectionCacheEntry::NormalizedTerm{ty: value,complete:None});
190190
assert!(!fresh_key,"never started projecting `{key:?}`");
191191
}
192192

@@ -197,13 +197,16 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
197197
pubfncomplete(&mutself,key:ProjectionCacheKey<'tcx>,result:EvaluationResult){
198198
letmut map =self.map();
199199
match map.get(&key){
200-
Some(ProjectionCacheEntry::NormalizedTy{ ty,complete: _}) =>{
200+
Some(ProjectionCacheEntry::NormalizedTerm{ ty,complete: _}) =>{
201201
info!("ProjectionCacheEntry::complete({:?}) - completing {:?}", key, ty);
202202
letmut ty = ty.clone();
203203
if result.must_apply_considering_regions(){
204204
ty.obligations =vec![];
205205
}
206-
map.insert(key,ProjectionCacheEntry::NormalizedTy{ ty,complete:Some(result)});
206+
map.insert(
207+
key,
208+
ProjectionCacheEntry::NormalizedTerm{ ty,complete:Some(result)},
209+
);
207210
}
208211
ref value =>{
209212
// Type inference could "strand behind" old cache entries. Leave
@@ -215,7 +218,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
215218

216219
pubfnis_complete(&mutself,key:ProjectionCacheKey<'tcx>) ->Option<EvaluationResult>{
217220
self.map().get(&key).and_then(|res|match res{
218-
ProjectionCacheEntry::NormalizedTy{ty: _, complete} =>*complete,
221+
ProjectionCacheEntry::NormalizedTerm{ty: _, complete} =>*complete,
219222
_ =>None,
220223
})
221224
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,6 @@ impl<'tcx> Term<'tcx> {
629629
}
630630
}
631631

632-
/// This function returns the inner `AliasTy` for a `ty::Alias` or `ConstKind::Unevaluated`.
633632
pubfnto_alias_term(self) ->Option<AliasTerm<'tcx>>{
634633
matchself.unpack(){
635634
TermKind::Ty(ty) =>match*ty.kind(){

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3216,7 +3216,8 @@ define_print_and_forward_display! {
32163216
ty::AliasTermKind::ProjectionTy
32173217
| ty::AliasTermKind::WeakTy
32183218
| ty::AliasTermKind::OpaqueTy
3219-
| ty::AliasTermKind::UnevaluatedConst =>{
3219+
| ty::AliasTermKind::UnevaluatedConst
3220+
| ty::AliasTermKind::ProjectionConst =>{
32203221
// If we're printing verbosely, or don't want to invoke queries
32213222
// (`is_impl_trait_in_trait`), then fall back to printing the def path.
32223223
// This is likely what you want if you're debugging the compiler anyways.

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::ty::{
1010
GenericArgKind,GenericArgsRef,ImplSubject,Term,TermKind,Ty,TyCtxt,TypeFoldable,
1111
};
1212
use rustc_hiras hir;
13-
use rustc_hir::def::DefKind;
1413
use rustc_hir::def_id::DefId;
1514
use rustc_macros::TypeVisitable;
1615
use rustc_target::spec::abi;
@@ -227,19 +226,18 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> {
227226
if a.def_id != b.def_id{
228227
Err(TypeError::ProjectionMismatched(expected_found(a.def_id, b.def_id)))
229228
}else{
230-
let args =match relation.tcx().def_kind(a.def_id){
231-
DefKind::OpaqueTy =>relate_args_with_variances(
229+
let args =matcha.kind(relation.tcx()){
230+
ty::Opaque =>relate_args_with_variances(
232231
relation,
233232
a.def_id,
234233
relation.tcx().variances_of(a.def_id),
235234
a.args,
236235
b.args,
237236
false,// do not fetch `type_of(a_def_id)`, as it will cause a cycle
238237
)?,
239-
DefKind::AssocTy |DefKind::AssocConst |DefKind::TyAlias =>{
238+
ty::Projection |ty::Weak |ty::Inherent =>{
240239
relate_args_invariantly(relation, a.args, b.args)?
241240
}
242-
def =>bug!("unknown alias DefKind: {def:?}"),
243241
};
244242
Ok(ty::AliasTy::new(relation.tcx(), a.def_id, args))
245243
}
@@ -255,19 +253,22 @@ impl<'tcx> Relate<'tcx> for ty::AliasTerm<'tcx> {
255253
if a.def_id != b.def_id{
256254
Err(TypeError::ProjectionMismatched(expected_found(a.def_id, b.def_id)))
257255
}else{
258-
let args =match relation.tcx().def_kind(a.def_id){
259-
DefKind::OpaqueTy =>relate_args_with_variances(
256+
let args =matcha.kind(relation.tcx()){
257+
ty::AliasTermKind::OpaqueTy =>relate_args_with_variances(
260258
relation,
261259
a.def_id,
262260
relation.tcx().variances_of(a.def_id),
263261
a.args,
264262
b.args,
265263
false,// do not fetch `type_of(a_def_id)`, as it will cause a cycle
266264
)?,
267-
DefKind::AssocTy |DefKind::AssocConst |DefKind::TyAlias =>{
265+
ty::AliasTermKind::ProjectionTy
266+
| ty::AliasTermKind::WeakTy
267+
| ty::AliasTermKind::InherentTy
268+
| ty::AliasTermKind::UnevaluatedConst
269+
| ty::AliasTermKind::ProjectionConst =>{
268270
relate_args_invariantly(relation, a.args, b.args)?
269271
}
270-
def =>bug!("unknown alias DefKind: {def:?}"),
271272
};
272273
Ok(ty::AliasTerm::new(relation.tcx(), a.def_id, args))
273274
}

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_span::symbol::{sym, Symbol};
2222
use rustc_span::{Span,DUMMY_SP};
2323
use rustc_target::abi::{FieldIdx,VariantIdx,FIRST_VARIANT};
2424
use rustc_target::spec::abi::{self,Abi};
25-
use std::assert_matches::{assert_matches,debug_assert_matches};
25+
use std::assert_matches::debug_assert_matches;
2626
use std::borrow::Cow;
2727
use std::iter;
2828
use std::ops::{ControlFlow,Deref,Range};
@@ -1137,8 +1137,8 @@ pub struct AliasTerm<'tcx> {
11371137
/// aka. `tcx.parent(def_id)`.
11381138
pubdef_id:DefId,
11391139

1140-
/// This field exists to prevent the creation of `AliasTy` without using
1141-
/// [AliasTy::new].
1140+
/// This field exists to prevent the creation of `AliasTerm` without using
1141+
/// [AliasTerm::new].
11421142
_use_alias_term_new_instead:(),
11431143
}
11441144

@@ -1202,13 +1202,15 @@ impl<'tcx> AliasTerm<'tcx> {
12021202
}
12031203

12041204
pubfnexpect_ty(self,tcx:TyCtxt<'tcx>) ->AliasTy<'tcx>{
1205-
assert_matches!(
1206-
self.kind(tcx),
1205+
matchself.kind(tcx){
12071206
ty::AliasTermKind::ProjectionTy
1208-
| ty::AliasTermKind::OpaqueTy
1209-
| ty::AliasTermKind::WeakTy
1210-
| ty::AliasTermKind::InherentTy
1211-
);
1207+
| ty::AliasTermKind::InherentTy
1208+
| ty::AliasTermKind::OpaqueTy
1209+
| ty::AliasTermKind::WeakTy =>{}
1210+
ty::AliasTermKind::UnevaluatedConst | ty::AliasTermKind::ProjectionConst =>{
1211+
bug!("Cannot turn `UnevaluatedConst` into `AliasTy`")
1212+
}
1213+
}
12121214
ty::AliasTy{def_id:self.def_id,args:self.args,_use_alias_ty_new_instead:()}
12131215
}
12141216

@@ -1223,13 +1225,14 @@ impl<'tcx> AliasTerm<'tcx> {
12231225
}
12241226
DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy,
12251227
DefKind::TyAlias => ty::AliasTermKind::WeakTy,
1226-
DefKind::AssocConst |DefKind::AnonConst => ty::AliasTermKind::UnevaluatedConst,
1228+
DefKind::AnonConst => ty::AliasTermKind::UnevaluatedConst,
1229+
DefKind::AssocConst => ty::AliasTermKind::ProjectionConst,
12271230
kind =>bug!("unexpected DefKind in AliasTy: {kind:?}"),
12281231
}
12291232
}
12301233
}
12311234

1232-
/// The following methods work only with (trait) associatedtype projections.
1235+
/// The following methods work only with (trait) associateditem projections.
12331236
impl<'tcx>AliasTerm<'tcx>{
12341237
pubfnself_ty(self) ->Ty<'tcx>{
12351238
self.args.type_at(0)
@@ -1269,7 +1272,6 @@ impl<'tcx> AliasTerm<'tcx> {
12691272
self,
12701273
tcx:TyCtxt<'tcx>,
12711274
) ->(ty::TraitRef<'tcx>,&'tcx[ty::GenericArg<'tcx>]){
1272-
debug_assert!(matches!(tcx.def_kind(self.def_id),DefKind::AssocTy |DefKind::AssocConst));
12731275
let trait_def_id =self.trait_def_id(tcx);
12741276
let trait_generics = tcx.generics_of(trait_def_id);
12751277
(
@@ -1304,12 +1306,14 @@ impl<'tcx> AliasTerm<'tcx> {
13041306
AliasTy{def_id:self.def_id,args:self.args,_use_alias_ty_new_instead:()},
13051307
)
13061308
.into(),
1307-
ty::AliasTermKind::UnevaluatedConst => ty::Const::new_unevaluated(
1308-
tcx,
1309-
ty::UnevaluatedConst::new(self.def_id,self.args),
1310-
tcx.type_of(self.def_id).instantiate(tcx,self.args),
1311-
)
1312-
.into(),
1309+
ty::AliasTermKind::UnevaluatedConst | ty::AliasTermKind::ProjectionConst =>{
1310+
ty::Const::new_unevaluated(
1311+
tcx,
1312+
ty::UnevaluatedConst::new(self.def_id,self.args),
1313+
tcx.type_of(self.def_id).instantiate(tcx,self.args),
1314+
)
1315+
.into()
1316+
}
13131317
}
13141318
}
13151319
}
@@ -1358,7 +1362,7 @@ pub struct AliasTy<'tcx> {
13581362
/// aka. `tcx.parent(def_id)`.
13591363
pubdef_id:DefId,
13601364

1361-
/// This field exists to prevent the creation of `AliasTy` without using
1365+
/// This field exists to prevent the creation of `AliasT` without using
13621366
/// [AliasTy::new].
13631367
_use_alias_ty_new_instead:(),
13641368
}
@@ -1422,7 +1426,6 @@ impl<'tcx> AliasTy<'tcx> {
14221426
self,
14231427
tcx:TyCtxt<'tcx>,
14241428
) ->(ty::TraitRef<'tcx>,&'tcx[ty::GenericArg<'tcx>]){
1425-
debug_assert!(matches!(tcx.def_kind(self.def_id),DefKind::AssocTy |DefKind::AssocConst));
14261429
let trait_def_id =self.trait_def_id(tcx);
14271430
let trait_generics = tcx.generics_of(trait_def_id);
14281431
(

‎compiler/rustc_smir/src/rustc_smir/convert/ty.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,9 @@ impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> {
723723
typeT = stable_mir::ty::ProjectionPredicate;
724724

725725
fnstable(&self,tables:&mutTables<'_>) ->Self::T{
726-
let ty::ProjectionPredicate{projection_term: projection_ty, term} =self;
726+
let ty::ProjectionPredicate{ projection_term, term} =self;
727727
stable_mir::ty::ProjectionPredicate{
728-
projection_term:projection_ty.stable(tables),
728+
projection_term:projection_term.stable(tables),
729729
term: term.unpack().stable(tables),
730730
}
731731
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp