Skip to content

Commit a78f9aa

Browse files
committed
Auto merge of #146333 - matthiaskrgr:rollup-ib80jyw, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #146111 (Migrate more things in the new solver to specific `DefId`s) - #146298 (GVN: Ensure indirect is first projection in try_as_place.) - #146299 (docs(std): add error docs for path canonicalize) - #146310 (Allow static regions in `type_name`.) - #146313 (Some `rustc_middle` cleanups) - #146319 (Fix typo in default.rs) - #146320 (rustc-dev-guide subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 68baa87 + 65e4c54 commit a78f9aa

56 files changed

Lines changed: 426 additions & 231 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_const_eval/src/util/type_name.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ impl<'tcx> PrettyPrinter<'tcx> for TypeNamePrinter<'tcx> {
168168
// Bound regions are always printed (as `'_`), which gives some idea that they are special,
169169
// even though the `for` is omitted by the pretty printer.
170170
// E.g. `for<'a, 'b> fn(&'a u32, &'b u32)` is printed as "fn(&'_ u32, &'_ u32)".
171+
let kind = region.kind();
171172
match region.kind(){
172-
ty::ReErased | ty::ReEarlyParam(_) => false,
173+
ty::ReErased | ty::ReEarlyParam(_)| ty::ReStatic=> false,
173174
ty::ReBound(..) => true,
174-
_ => unreachable!(),
175+
_ => panic!("type_name unhandled region: {kind:?}"),
175176
}
176177
}
177178

‎compiler/rustc_infer/src/infer/relate/generalize.rs‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use rustc_hir::def_id::DefId;
66
use rustc_middle::bug;
77
use rustc_middle::ty::error::TypeError;
88
use rustc_middle::ty::{
9-
self,AliasRelationDirection,InferConst,MaxUniverse,Term,Ty,TyCtxt,TypeVisitable,
10-
TypeVisitableExt,TypingMode,
9+
self,AliasRelationDirection,InferConst,Term,Ty,TyCtxt,TypeSuperVisitable,TypeVisitable,
10+
TypeVisitableExt,TypeVisitor,TypingMode,
1111
};
1212
use rustc_span::Span;
1313
use tracing::{debug, instrument, warn};
@@ -290,6 +290,45 @@ impl<'tcx> InferCtxt<'tcx> {
290290
}
291291
}
292292

293+
/// Finds the max universe present
294+
structMaxUniverse{
295+
max_universe: ty::UniverseIndex,
296+
}
297+
298+
implMaxUniverse{
299+
fnnew() -> Self{
300+
MaxUniverse{max_universe: ty::UniverseIndex::ROOT}
301+
}
302+
303+
fnmax_universe(self) -> ty::UniverseIndex{
304+
self.max_universe
305+
}
306+
}
307+
308+
impl<'tcx>TypeVisitor<TyCtxt<'tcx>>forMaxUniverse{
309+
fnvisit_ty(&mutself,t:Ty<'tcx>){
310+
iflet ty::Placeholder(placeholder) = t.kind(){
311+
self.max_universe = self.max_universe.max(placeholder.universe);
312+
}
313+
314+
t.super_visit_with(self)
315+
}
316+
317+
fnvisit_const(&mutself,c: ty::Const<'tcx>){
318+
iflet ty::ConstKind::Placeholder(placeholder) = c.kind(){
319+
self.max_universe = self.max_universe.max(placeholder.universe);
320+
}
321+
322+
c.super_visit_with(self)
323+
}
324+
325+
fnvisit_region(&mutself,r: ty::Region<'tcx>){
326+
iflet ty::RePlaceholder(placeholder) = r.kind(){
327+
self.max_universe = self.max_universe.max(placeholder.universe);
328+
}
329+
}
330+
}
331+
293332
/// The "generalizer" is used when handling inference variables.
294333
///
295334
/// The basic strategy for handling a constraint like `?A <: B` is to

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ use crate::traits::{
135135
};
136136
usecrate::ty::fast_reject::SimplifiedType;
137137
usecrate::ty::layout::ValidityRequirement;
138-
usecrate::ty::print::{PrintTraitRefExt, describe_as_module};
138+
usecrate::ty::print::PrintTraitRefExt;
139139
usecrate::ty::util::AlwaysRequiresDrop;
140140
usecrate::ty::{
141141
self,CrateInherentImpls,GenericArg,GenericArgsRef,PseudoCanonicalInput,SizedTraitKind,Ty,
@@ -2731,3 +2731,12 @@ rustc_queries! {
27312731

27322732
rustc_with_all_queries!{ define_callbacks! }
27332733
rustc_feedable_queries!{ define_feedable! }
2734+
2735+
fndescribe_as_module(def_id:implInto<LocalDefId>,tcx:TyCtxt<'_>) -> String{
2736+
let def_id = def_id.into();
2737+
if def_id.is_top_level_module(){
2738+
"top-level module".to_string()
2739+
}else{
2740+
format!("module `{}`", tcx.def_path_str(def_id))
2741+
}
2742+
}

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use rustc_session::{Limit, Session};
5252
use rustc_span::def_id::{CRATE_DEF_ID,DefPathHash,StableCrateId};
5353
use rustc_span::{DUMMY_SP,Ident,Span,Symbol, kw, sym};
5454
use rustc_type_ir::TyKind::*;
55-
use rustc_type_ir::lang_items::{SolverLangItem,SolverTraitLangItem};
55+
use rustc_type_ir::lang_items::{SolverAdtLangItem,SolverLangItem,SolverTraitLangItem};
5656
pubuse rustc_type_ir::lift::Lift;
5757
use rustc_type_ir::{
5858
CollectAndApply,Interner,TypeFlags,TypeFoldable,WithCachedTypeInfo, elaborate, search_graph,
@@ -94,6 +94,13 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
9494
typeDefId = DefId;
9595
typeLocalDefId = LocalDefId;
9696
typeTraitId = DefId;
97+
typeForeignId = DefId;
98+
typeFunctionId = DefId;
99+
typeClosureId = DefId;
100+
typeCoroutineClosureId = DefId;
101+
typeCoroutineId = DefId;
102+
typeAdtId = DefId;
103+
typeImplId = DefId;
97104
typeSpan = Span;
98105

99106
typeGenericArgs = ty::GenericArgsRef<'tcx>;
@@ -492,6 +499,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
492499
self.require_lang_item(solver_trait_lang_item_to_lang_item(lang_item),DUMMY_SP)
493500
}
494501

502+
fnrequire_adt_lang_item(self,lang_item:SolverAdtLangItem) -> DefId{
503+
self.require_lang_item(solver_adt_lang_item_to_lang_item(lang_item),DUMMY_SP)
504+
}
505+
495506
fnis_lang_item(self,def_id:DefId,lang_item:SolverLangItem) -> bool{
496507
self.is_lang_item(def_id,solver_lang_item_to_lang_item(lang_item))
497508
}
@@ -500,6 +511,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
500511
self.is_lang_item(def_id,solver_trait_lang_item_to_lang_item(lang_item))
501512
}
502513

514+
fnis_adt_lang_item(self,def_id:DefId,lang_item:SolverAdtLangItem) -> bool{
515+
self.is_lang_item(def_id,solver_adt_lang_item_to_lang_item(lang_item))
516+
}
517+
503518
fnis_default_trait(self,def_id:DefId) -> bool{
504519
self.is_default_trait(def_id)
505520
}
@@ -512,6 +527,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
512527
lang_item_to_solver_trait_lang_item(self.lang_items().from_def_id(def_id)?)
513528
}
514529

530+
fnas_adt_lang_item(self,def_id:DefId) -> Option<SolverAdtLangItem>{
531+
lang_item_to_solver_adt_lang_item(self.lang_items().from_def_id(def_id)?)
532+
}
533+
515534
fnassociated_type_def_ids(self,def_id:DefId) -> implIntoIterator<Item = DefId>{
516535
self.associated_items(def_id)
517536
.in_definition_order()
@@ -783,6 +802,13 @@ bidirectional_lang_item_map! {
783802
DynMetadata,
784803
FutureOutput,
785804
Metadata,
805+
// tidy-alphabetical-end
806+
}
807+
808+
bidirectional_lang_item_map!{
809+
SolverAdtLangItem, lang_item_to_solver_adt_lang_item, solver_adt_lang_item_to_lang_item;
810+
811+
// tidy-alphabetical-start
786812
Option,
787813
Poll,
788814
// tidy-alphabetical-end

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ pub use self::typeck_results::{
109109
CanonicalUserType,CanonicalUserTypeAnnotation,CanonicalUserTypeAnnotations,IsIdentity,
110110
Rust2024IncompatiblePatInfo,TypeckResults,UserType,UserTypeAnnotationIndex,UserTypeKind,
111111
};
112-
pubuseself::visit::*;
113112
usecrate::error::{OpaqueHiddenTypeMismatch,TypeMismatchReason};
114113
usecrate::metadata::ModChild;
115114
usecrate::middle::privacy::EffectiveVisibilities;

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

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -638,43 +638,15 @@ impl<'tcx> Predicate<'tcx> {
638638
let predicate = self.kind();
639639
match predicate.skip_binder(){
640640
PredicateKind::Clause(ClauseKind::Trait(t)) => Some(predicate.rebind(t)),
641-
PredicateKind::Clause(ClauseKind::Projection(..))
642-
| PredicateKind::Clause(ClauseKind::HostEffect(..))
643-
| PredicateKind::Clause(ClauseKind::ConstArgHasType(..))
644-
| PredicateKind::Clause(ClauseKind::UnstableFeature(_))
645-
| PredicateKind::NormalizesTo(..)
646-
| PredicateKind::AliasRelate(..)
647-
| PredicateKind::Subtype(..)
648-
| PredicateKind::Coerce(..)
649-
| PredicateKind::Clause(ClauseKind::RegionOutlives(..))
650-
| PredicateKind::Clause(ClauseKind::WellFormed(..))
651-
| PredicateKind::DynCompatible(..)
652-
| PredicateKind::Clause(ClauseKind::TypeOutlives(..))
653-
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(..))
654-
| PredicateKind::ConstEquate(..)
655-
| PredicateKind::Ambiguous => None,
641+
_ => None,
656642
}
657643
}
658644

659645
pubfnas_projection_clause(self) -> Option<PolyProjectionPredicate<'tcx>>{
660646
let predicate = self.kind();
661647
match predicate.skip_binder(){
662648
PredicateKind::Clause(ClauseKind::Projection(t)) => Some(predicate.rebind(t)),
663-
PredicateKind::Clause(ClauseKind::Trait(..))
664-
| PredicateKind::Clause(ClauseKind::HostEffect(..))
665-
| PredicateKind::Clause(ClauseKind::ConstArgHasType(..))
666-
| PredicateKind::Clause(ClauseKind::UnstableFeature(_))
667-
| PredicateKind::NormalizesTo(..)
668-
| PredicateKind::AliasRelate(..)
669-
| PredicateKind::Subtype(..)
670-
| PredicateKind::Coerce(..)
671-
| PredicateKind::Clause(ClauseKind::RegionOutlives(..))
672-
| PredicateKind::Clause(ClauseKind::WellFormed(..))
673-
| PredicateKind::DynCompatible(..)
674-
| PredicateKind::Clause(ClauseKind::TypeOutlives(..))
675-
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(..))
676-
| PredicateKind::ConstEquate(..)
677-
| PredicateKind::Ambiguous => None,
649+
_ => None,
678650
}
679651
}
680652

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use hir::def::Namespace;
22
use rustc_data_structures::fx::FxHashSet;
33
use rustc_data_structures::sso::SsoHashSet;
44
use rustc_hir as hir;
5-
use rustc_hir::def_id::{CrateNum,DefId,LocalDefId};
5+
use rustc_hir::def_id::{CrateNum,DefId};
66
use rustc_hir::definitions::{DefPathData,DisambiguatedDefPathData};
77
use tracing::{debug, instrument, trace};
88

@@ -396,16 +396,6 @@ impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Const<'tcx> {
396396
}
397397
}
398398

399-
// This is only used by query descriptions
400-
pubfndescribe_as_module(def_id:implInto<LocalDefId>,tcx:TyCtxt<'_>) -> String{
401-
let def_id = def_id.into();
402-
if def_id.is_top_level_module(){
403-
"top-level module".to_string()
404-
}else{
405-
format!("module `{}`", tcx.def_path_str(def_id))
406-
}
407-
}
408-
409399
impl<T> rustc_type_ir::ir_print::IrPrint<T>forTyCtxt<'_>
410400
where
411401
T:Copy + for<'a,'tcx>Lift<TyCtxt<'tcx>,Lifted:Print<'tcx,FmtPrinter<'a,'tcx>>>,

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -212,42 +212,3 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector {
212212
}
213213
}
214214
}
215-
216-
/// Finds the max universe present
217-
pubstructMaxUniverse{
218-
max_universe: ty::UniverseIndex,
219-
}
220-
221-
implMaxUniverse{
222-
pubfnnew() -> Self{
223-
MaxUniverse{max_universe: ty::UniverseIndex::ROOT}
224-
}
225-
226-
pubfnmax_universe(self) -> ty::UniverseIndex{
227-
self.max_universe
228-
}
229-
}
230-
231-
impl<'tcx>TypeVisitor<TyCtxt<'tcx>>forMaxUniverse{
232-
fnvisit_ty(&mutself,t:Ty<'tcx>){
233-
iflet ty::Placeholder(placeholder) = t.kind(){
234-
self.max_universe = self.max_universe.max(placeholder.universe);
235-
}
236-
237-
t.super_visit_with(self)
238-
}
239-
240-
fnvisit_const(&mutself,c: ty::consts::Const<'tcx>){
241-
iflet ty::ConstKind::Placeholder(placeholder) = c.kind(){
242-
self.max_universe = self.max_universe.max(placeholder.universe);
243-
}
244-
245-
c.super_visit_with(self)
246-
}
247-
248-
fnvisit_region(&mutself,r: ty::Region<'tcx>){
249-
iflet ty::RePlaceholder(placeholder) = r.kind(){
250-
self.max_universe = self.max_universe.max(placeholder.universe);
251-
}
252-
}
253-
}

‎compiler/rustc_mir_transform/src/gvn.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,11 @@ impl<'tcx> VnState<'_, 'tcx> {
16441644
let place =
16451645
Place{ local,projection:self.tcx.mk_place_elems(projection.as_slice())};
16461646
returnSome(place);
1647+
}elseif projection.last() == Some(&PlaceElem::Deref){
1648+
// `Deref` can only be the first projection in a place.
1649+
// If we are here, we failed to find a local, and we already have a `Deref`.
1650+
// Trying to add projections will only result in an ill-formed place.
1651+
returnNone;
16471652
}elseifletValue::Projection(pointer, proj) = *self.get(index)
16481653
&& (allow_complex_projection || proj.is_stable_offset())
16491654
&& letSome(proj) = self.try_as_place_elem(self.ty(index), proj, loc)

‎compiler/rustc_next_trait_solver/src/coherence.rs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,21 @@ where
435435
}
436436
}
437437
ty::Error(_) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)),
438-
ty::Closure(did, ..) | ty::CoroutineClosure(did, ..) | ty::Coroutine(did, ..) => {
438+
ty::Closure(did, ..) => {
439+
ifself.def_id_is_local(did){
440+
ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty))
441+
}else{
442+
self.found_non_local_ty(ty)
443+
}
444+
}
445+
ty::CoroutineClosure(did, ..) => {
446+
ifself.def_id_is_local(did){
447+
ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty))
448+
}else{
449+
self.found_non_local_ty(ty)
450+
}
451+
}
452+
ty::Coroutine(did, ..) => {
439453
ifself.def_id_is_local(did){
440454
ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty))
441455
}else{

0 commit comments

Comments
 (0)