Auto merge of #127111 - matthiaskrgr:rollup-ybzkuuv, r=matthiaskrgr · rust-lang/rust@be99243 (original) (raw)
73 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -50,7 +50,7 @@ libc = "0.2" | ||
50 | 50 | memmap2 = "0.2.1" |
51 | 51 | # tidy-alphabetical-end |
52 | 52 | |
53 | -[target.'cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))'.dependencies] | |
53 | +[target.'cfg(not(target_has_atomic = "64"))'.dependencies] | |
54 | 54 | portable-atomic = "1.5.1" |
55 | 55 | |
56 | 56 | [features] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -147,14 +147,13 @@ cfg_match! { | ||
147 | 147 | [crate::owned_slice::OwnedSlice] |
148 | 148 | ); |
149 | 149 | |
150 | -// MIPS, PowerPC and SPARC platforms with 32-bit pointers do not | |
151 | -// have AtomicU64 type. | |
152 | - #[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc", target_arch = "sparc")))] | |
150 | +// Use portable AtomicU64 for targets without native 64-bit atomics | |
151 | + #[cfg(target_has_atomic = "64")] | |
153 | 152 | already_sync!( |
154 | 153 | [std::sync::atomic::AtomicU64] |
155 | 154 | ); |
156 | 155 | |
157 | - #[cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))] | |
156 | + #[cfg(not(target_has_atomic = "64"))] | |
158 | 157 | already_sync!( |
159 | 158 | [portable_atomic::AtomicU64] |
160 | 159 | ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -270,12 +270,11 @@ cfg_match! { | ||
270 | 270 | |
271 | 271 | pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32}; |
272 | 272 | |
273 | -// MIPS, PowerPC and SPARC platforms with 32-bit pointers do not | |
274 | -// have AtomicU64 type. | |
275 | - #[cfg(not(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc")))] | |
273 | +// Use portable AtomicU64 for targets without native 64-bit atomics | |
274 | + #[cfg(target_has_atomic = "64")] | |
276 | 275 | pub use std::sync::atomic::AtomicU64; |
277 | 276 | |
278 | - #[cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))] | |
277 | + #[cfg(not(target_has_atomic = "64"))] | |
279 | 278 | pub use portable_atomic::AtomicU64; |
280 | 279 | |
281 | 280 | pub use std::sync::Arc as Lrc; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -70,10 +70,10 @@ pub fn provide(providers: &mut Providers) { | ||
70 | 70 | predicates_of: predicates_of::predicates_of, |
71 | 71 | predicates_defined_on, |
72 | 72 | explicit_predicates_of: predicates_of::explicit_predicates_of, |
73 | -super_predicates_of: predicates_of::super_predicates_of, | |
74 | -implied_predicates_of: predicates_of::implied_predicates_of, | |
75 | -super_predicates_that_define_assoc_item: | |
76 | - predicates_of::super_predicates_that_define_assoc_item, | |
73 | +explicit_super_predicates_of: predicates_of::explicit_super_predicates_of, | |
74 | +explicit_implied_predicates_of: predicates_of::explicit_implied_predicates_of, | |
75 | +explicit_supertraits_containing_assoc_item: | |
76 | + predicates_of::explicit_supertraits_containing_assoc_item, | |
77 | 77 | trait_explicit_predicates_and_bounds: predicates_of::trait_explicit_predicates_and_bounds, |
78 | 78 | type_param_predicates: predicates_of::type_param_predicates, |
79 | 79 | trait_def, |
@@ -691,14 +691,14 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { | ||
691 | 691 | hir::ItemKind::Trait(..) => { |
692 | 692 | tcx.ensure().generics_of(def_id); |
693 | 693 | tcx.ensure().trait_def(def_id); |
694 | - tcx.at(it.span).super_predicates_of(def_id); | |
694 | + tcx.at(it.span).explicit_super_predicates_of(def_id); | |
695 | 695 | tcx.ensure().predicates_of(def_id); |
696 | 696 | tcx.ensure().associated_items(def_id); |
697 | 697 | } |
698 | 698 | hir::ItemKind::TraitAlias(..) => { |
699 | 699 | tcx.ensure().generics_of(def_id); |
700 | - tcx.at(it.span).implied_predicates_of(def_id); | |
701 | - tcx.at(it.span).super_predicates_of(def_id); | |
700 | + tcx.at(it.span).explicit_implied_predicates_of(def_id); | |
701 | + tcx.at(it.span).explicit_super_predicates_of(def_id); | |
702 | 702 | tcx.ensure().predicates_of(def_id); |
703 | 703 | } |
704 | 704 | hir::ItemKind::Struct(struct_def, _) | hir::ItemKind::Union(struct_def, _) => { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -519,21 +519,21 @@ pub(super) fn explicit_predicates_of<'tcx>( | ||
519 | 519 | /// Ensures that the super-predicates of the trait with a `DefId` |
520 | 520 | /// of `trait_def_id` are lowered and stored. This also ensures that |
521 | 521 | /// the transitive super-predicates are lowered. |
522 | -pub(super) fn super_predicates_of( | |
522 | +pub(super) fn explicit_super_predicates_of( | |
523 | 523 | tcx: TyCtxt<'_>, |
524 | 524 | trait_def_id: LocalDefId, |
525 | 525 | ) -> ty::GenericPredicates<'_> { |
526 | 526 | implied_predicates_with_filter(tcx, trait_def_id.to_def_id(), PredicateFilter::SelfOnly) |
527 | 527 | } |
528 | 528 | |
529 | -pub(super) fn super_predicates_that_define_assoc_item( | |
529 | +pub(super) fn explicit_supertraits_containing_assoc_item( | |
530 | 530 | tcx: TyCtxt<'_>, |
531 | 531 | (trait_def_id, assoc_name): (DefId, Ident), |
532 | 532 | ) -> ty::GenericPredicates<'_> { |
533 | 533 | implied_predicates_with_filter(tcx, trait_def_id, PredicateFilter::SelfThatDefines(assoc_name)) |
534 | 534 | } |
535 | 535 | |
536 | -pub(super) fn implied_predicates_of( | |
536 | +pub(super) fn explicit_implied_predicates_of( | |
537 | 537 | tcx: TyCtxt<'_>, |
538 | 538 | trait_def_id: LocalDefId, |
539 | 539 | ) -> ty::GenericPredicates<'_> { |
@@ -560,7 +560,7 @@ pub(super) fn implied_predicates_with_filter( | ||
560 | 560 | // if `assoc_name` is None, then the query should've been redirected to an |
561 | 561 | // external provider |
562 | 562 | assert!(matches!(filter, PredicateFilter::SelfThatDefines(_))); |
563 | -return tcx.super_predicates_of(trait_def_id); | |
563 | +return tcx.explicit_super_predicates_of(trait_def_id); | |
564 | 564 | }; |
565 | 565 | |
566 | 566 | let Node::Item(item) = tcx.hir_node_by_def_id(trait_def_id) else { |
@@ -601,7 +601,7 @@ pub(super) fn implied_predicates_with_filter( | ||
601 | 601 | if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder() |
602 | 602 | && bound.polarity == ty::PredicatePolarity::Positive |
603 | 603 | { |
604 | - tcx.at(span).super_predicates_of(bound.def_id()); | |
604 | + tcx.at(span).explicit_super_predicates_of(bound.def_id()); | |
605 | 605 | } |
606 | 606 | } |
607 | 607 | } |
@@ -611,7 +611,7 @@ pub(super) fn implied_predicates_with_filter( | ||
611 | 611 | if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder() |
612 | 612 | && bound.polarity == ty::PredicatePolarity::Positive |
613 | 613 | { |
614 | - tcx.at(span).implied_predicates_of(bound.def_id()); | |
614 | + tcx.at(span).explicit_implied_predicates_of(bound.def_id()); | |
615 | 615 | } |
616 | 616 | } |
617 | 617 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1760,7 +1760,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { | ||
1760 | 1760 | if let Some(assoc_item) = trait_defines_associated_item_named(def_id) { |
1761 | 1761 | break Some((bound_vars.into_iter().collect(), assoc_item)); |
1762 | 1762 | } |
1763 | -let predicates = tcx.super_predicates_that_define_assoc_item((def_id, assoc_name)); | |
1763 | +let predicates = tcx.explicit_supertraits_containing_assoc_item((def_id, assoc_name)); | |
1764 | 1764 | let obligations = predicates.predicates.iter().filter_map(|&(pred, _) |
1765 | 1765 | let bound_predicate = pred.kind(); |
1766 | 1766 | match bound_predicate.skip_binder() { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -275,10 +275,10 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> { | ||
275 | 275 | } |
276 | 276 | // Get predicates implied by the trait, or only super predicates if we only care about self predicates. |
277 | 277 | let predicates = match self.mode { |
278 | -Filter::All => tcx.implied_predicates_of(data.def_id()), | |
279 | -Filter::OnlySelf => tcx.super_predicates_of(data.def_id()), | |
278 | +Filter::All => tcx.explicit_implied_predicates_of(data.def_id()), | |
279 | +Filter::OnlySelf => tcx.explicit_super_predicates_of(data.def_id()), | |
280 | 280 | Filter::OnlySelfThatDefines(ident) => { |
281 | - tcx.super_predicates_that_define_assoc_item((data.def_id(), ident)) | |
281 | + tcx.explicit_supertraits_containing_assoc_item((data.def_id(), ident)) | |
282 | 282 | } |
283 | 283 | }; |
284 | 284 | |
@@ -420,7 +420,7 @@ pub fn transitive_bounds<'tcx>( | ||
420 | 420 | |
421 | 421 | /// A specialized variant of `elaborate` that only elaborates trait references that may |
422 | 422 | /// define the given associated item with the name `assoc_name`. It uses the |
423 | -/// `super_predicates_that_define_assoc_item` query to avoid enumerating super-predicates that | |
423 | +/// `explicit_supertraits_containing_assoc_item` query to avoid enumerating super-predicates that | |
424 | 424 | /// aren't related to `assoc_item`. This is used when resolving types like `Self::Item` or |
425 | 425 | /// `T::Item` and helps to avoid cycle errors (see e.g. #35237). |
426 | 426 | pub fn transitive_bounds_that_define_assoc_item<'tcx>( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable { | ||
45 | 45 | { |
46 | 46 | let direct_super_traits_iter = cx |
47 | 47 | .tcx |
48 | -.super_predicates_of(def_id) | |
48 | +.explicit_super_predicates_of(def_id) | |
49 | 49 | .predicates |
50 | 50 | .into_iter() |
51 | 51 | .filter_map(|(pred, _) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -211,8 +211,8 @@ provide! { tcx, def_id, other, cdata, | ||
211 | 211 | explicit_predicates_of => { table } |
212 | 212 | generics_of => { table } |
213 | 213 | inferred_outlives_of => { table_defaulted_array } |
214 | -super_predicates_of => { table } | |
215 | -implied_predicates_of => { table } | |
214 | +explicit_super_predicates_of => { table } | |
215 | +explicit_implied_predicates_of => { table } | |
216 | 216 | type_of => { table } |
217 | 217 | type_alias_is_lazy => { cdata.root.tables.type_alias_is_lazy.get(cdata, def_id.index) } |
218 | 218 | variances_of => { table } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1431,17 +1431,17 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { | ||
1431 | 1431 | } |
1432 | 1432 | if let DefKind::Trait = def_kind { |
1433 | 1433 | record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id)); |
1434 | -record!(self.tables.super_predicates_of[def_id] <- self.tcx.super_predicates_of(def_id)); | |
1435 | -record!(self.tables.implied_predicates_of[def_id] <- self.tcx.implied_predicates_of(def_id)); | |
1434 | +record!(self.tables.explicit_super_predicates_of[def_id] <- self.tcx.explicit_super_predicates_of(def_id)); | |
1435 | +record!(self.tables.explicit_implied_predicates_of[def_id] <- self.tcx.explicit_implied_predicates_of(def_id)); | |
1436 | 1436 | |
1437 | 1437 | let module_children = self.tcx.module_children_local(local_id); |
1438 | 1438 | record_array!(self.tables.module_children_non_reexports[def_id] <- |
1439 | 1439 | module_children.iter().map(|child |
1440 | 1440 | } |
1441 | 1441 | if let DefKind::TraitAlias = def_kind { |
1442 | 1442 | record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id)); |
1443 | -record!(self.tables.super_predicates_of[def_id] <- self.tcx.super_predicates_of(def_id)); | |
1444 | -record!(self.tables.implied_predicates_of[def_id] <- self.tcx.implied_predicates_of(def_id)); | |
1443 | +record!(self.tables.explicit_super_predicates_of[def_id] <- self.tcx.explicit_super_predicates_of(def_id)); | |
1444 | +record!(self.tables.explicit_implied_predicates_of[def_id] <- self.tcx.explicit_implied_predicates_of(def_id)); | |
1445 | 1445 | } |
1446 | 1446 | if let DefKind::Trait | DefKind::Impl { .. } = def_kind { |
1447 | 1447 | let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -416,10 +416,10 @@ define_tables! { | ||
416 | 416 | lookup_deprecation_entry: Table<DefIndex, LazyValueattr::Deprecation\>, |
417 | 417 | explicit_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>, |
418 | 418 | generics_of: Table<DefIndex, LazyValuety::Generics\>, |
419 | -super_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>, | |
419 | +explicit_super_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>, | |
420 | 420 | // As an optimization, we only store this for trait aliases, |
421 | -// since it's identical to super_predicates_of for traits. | |
422 | -implied_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>, | |
421 | +// since it's identical to explicit_super_predicates_of for traits. | |
422 | +explicit_implied_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>, | |
423 | 423 | type_of: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, Ty<'static>>>>, |
424 | 424 | variances_of: Table<DefIndex, LazyArrayty::Variance\>, |
425 | 425 | fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, ty::PolyFnSig<'static>>>>, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -646,6 +646,9 @@ rustc_queries! { | ||
646 | 646 | } |
647 | 647 | |
648 | 648 | /// Returns the predicates written explicitly by the user. |
649 | + /// | |
650 | + /// You should probably use `predicates_of` unless you're looking for | |
651 | + /// predicates with explicit spans for diagnostics purposes. | |
649 | 652 | query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> { |
650 | 653 | desc { |tcx |
651 | 654 | cache_on_disk_if { key.is_local() } |
@@ -662,29 +665,32 @@ rustc_queries! { | ||
662 | 665 | feedable |
663 | 666 | } |
664 | 667 | |
665 | -/// Maps from the `DefId` of a trait to the list of | |
666 | - /// super-predicates. This is a subset of the full list of | |
667 | - /// predicates. We store these in a separate map because we must | |
668 | - /// evaluate them even during type conversion, often before the | |
669 | - /// full predicates are available (note that supertraits have | |
670 | - /// additional acyclicity requirements). | |
671 | - query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> { | |
668 | +/// Maps from the `DefId` of a trait to the list of super-predicates of the trait, | |
669 | + /// *before* elaboration (so it doesn't contain transitive super-predicates). This | |
670 | + /// is a subset of the full list of predicates. We store these in a separate map | |
671 | + /// because we must evaluate them even during type conversion, often before the full | |
672 | + /// predicates are available (note that super-predicates must not be cyclic). | |
673 | + query explicit_super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> { | |
672 | 674 | desc { |tcx |
673 | 675 | cache_on_disk_if { key.is_local() } |
674 | 676 | separate_provide_extern |
675 | 677 | } |
676 | 678 | |
677 | - query implied_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> { | |
679 | +/// The predicates of the trait that are implied during elaboration. This is a | |
680 | + /// superset of the super-predicates of the trait, but a subset of the predicates | |
681 | + /// of the trait. For regular traits, this includes all super-predicates and their | |
682 | + /// associated type bounds. For trait aliases, currently, this includes all of the | |
683 | + /// predicates of the trait alias. | |
684 | + query explicit_implied_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> { | |
678 | 685 | desc { |tcx |
679 | 686 | cache_on_disk_if { key.is_local() } |
680 | 687 | separate_provide_extern |
681 | 688 | } |
682 | 689 | |
683 | -/// The `Option` is the name of an associated type. If it is `None`, then this query | |
684 | - /// returns the full set of predicates. If `Some`, then the query returns only the | |
685 | - /// subset of super-predicates that reference traits that define the given associated type. | |
686 | - /// This is used to avoid cycles in resolving types like `T::Item`. | |
687 | - query super_predicates_that_define_assoc_item(key: (DefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> { | |
690 | +/// The Ident is the name of an associated type.The query returns only the subset | |
691 | + /// of supertraits that define the given associated type. This is used to avoid | |
692 | + /// cycles in resolving type-dependent associated item paths like `T::Item`. | |
693 | + query explicit_supertraits_containing_assoc_item(key: (DefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> { | |
688 | 694 | desc { |tcx |
689 | 695 | tcx.def_path_str(key.0), |
690 | 696 | key.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -35,7 +35,7 @@ struct Elaborator<'tcx> { | ||
35 | 35 | impl<'tcx> Elaborator<'tcx> { |
36 | 36 | fn elaborate(&mut self, trait_ref: PolyTraitRef<'tcx>) { |
37 | 37 | let super_predicates = |
38 | -self.tcx.super_predicates_of(trait_ref.def_id()).predicates.iter().filter_map( | |
38 | +self.tcx.explicit_super_predicates_of(trait_ref.def_id()).predicates.iter().filter_map( | |
39 | 39 | |&(pred, _) |
40 | 40 | let clause = pred.instantiate_supertrait(self.tcx, trait_ref); |
41 | 41 | self.visited.insert(clause).then_some(clause) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -342,12 +342,15 @@ impl<'tcx> Interner for TyCtxt<'tcx> { | ||
342 | 342 | ) |
343 | 343 | } |
344 | 344 | |
345 | -fn super_predicates_of( | |
345 | +fn explicit_super_predicates_of( | |
346 | 346 | self, |
347 | 347 | def_id: DefId, |
348 | 348 | ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> { |
349 | 349 | ty::EarlyBinder::bind( |
350 | -self.super_predicates_of(def_id).instantiate_identity(self).predicates.into_iter(), | |
350 | +self.explicit_super_predicates_of(def_id) | |
351 | +.instantiate_identity(self) | |
352 | +.predicates | |
353 | +.into_iter(), | |
351 | 354 | ) |
352 | 355 | } |
353 | 356 | |
@@ -2440,7 +2443,7 @@ impl<'tcx> TyCtxt<'tcx> { | ||
2440 | 2443 | /// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name` |
2441 | 2444 | /// returns true if the `trait_def_id` defines an associated item of name `assoc_name`. |
2442 | 2445 | pub fn trait_may_define_assoc_item(self, trait_def_id: DefId, assoc_name: Ident) -> bool { |
2443 | -self.super_traits_of(trait_def_id).any(|trait_did | |
2446 | +self.supertrait_def_ids(trait_def_id).any(|trait_did | |
2444 | 2447 | self.associated_items(trait_did) |
2445 | 2448 | .filter_by_name_unhygienic(assoc_name.name) |
2446 | 2449 | .any(|item |
@@ -2463,17 +2466,17 @@ impl<'tcx> TyCtxt<'tcx> { | ||
2463 | 2466 | |
2464 | 2467 | /// Computes the def-ids of the transitive supertraits of `trait_def_id`. This (intentionally) |
2465 | 2468 | /// does not compute the full elaborated super-predicates but just the set of def-ids. It is used |
2466 | - /// to identify which traits may define a given associated type to help avoid cycle errors. | |
2467 | - /// Returns a `DefId` iterator. | |
2468 | - fn super_traits_of(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx { | |
2469 | + /// to identify which traits may define a given associated type to help avoid cycle errors, | |
2470 | + /// and to make size estimates for vtable layout computation. | |
2471 | + pub fn supertrait_def_ids(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx { | |
2469 | 2472 | let mut set = FxHashSet::default(); |
2470 | 2473 | let mut stack = vec![trait_def_id]; |
2471 | 2474 | |
2472 | 2475 | set.insert(trait_def_id); |
2473 | 2476 | |
2474 | 2477 | iter::from_fn(move | |
2475 | 2478 | let trait_did = stack.pop()?; |
2476 | -let generic_predicates = self.super_predicates_of(trait_did); | |
2479 | +let generic_predicates = self.explicit_super_predicates_of(trait_did); | |
2477 | 2480 | |
2478 | 2481 | for (predicate, _) in generic_predicates.predicates { |
2479 | 2482 | if let ty::ClauseKind::Trait(data) = predicate.kind().skip_binder() { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,8 +3,6 @@ use std::fmt; | ||
3 | 3 | use crate::mir::interpret::{alloc_range, AllocId, Allocation, Pointer, Scalar}; |
4 | 4 | use crate::ty::{self, Instance, PolyTraitRef, Ty, TyCtxt}; |
5 | 5 | use rustc_ast::Mutability; |
6 | -use rustc_data_structures::fx::FxHashSet; | |
7 | -use rustc_hir::def_id::DefId; | |
8 | 6 | use rustc_macros::HashStable; |
9 | 7 | |
10 | 8 | #[derive(Clone, Copy, PartialEq, HashStable)] |
@@ -42,45 +40,12 @@ impl<'tcx> fmt::Debug for VtblEntry<'tcx> { | ||
42 | 40 | impl<'tcx> TyCtxt<'tcx> { |
43 | 41 | pub const COMMON_VTABLE_ENTRIES: &'tcx [VtblEntry<'tcx>] = |
44 | 42 | &[VtblEntry::MetadataDropInPlace, VtblEntry::MetadataSize, VtblEntry::MetadataAlign]; |
45 | - | |
46 | -pub fn supertrait_def_ids(self, trait_def_id: DefId) -> SupertraitDefIds<'tcx> { | |
47 | -SupertraitDefIds { | |
48 | -tcx: self, | |
49 | -stack: vec![trait_def_id], | |
50 | -visited: Some(trait_def_id).into_iter().collect(), | |
51 | -} | |
52 | -} | |
53 | 43 | } |
54 | 44 | |
55 | 45 | pub const COMMON_VTABLE_ENTRIES_DROPINPLACE: usize = 0; |
56 | 46 | pub const COMMON_VTABLE_ENTRIES_SIZE: usize = 1; |
57 | 47 | pub const COMMON_VTABLE_ENTRIES_ALIGN: usize = 2; |
58 | 48 | |
59 | -pub struct SupertraitDefIds<'tcx> { | |
60 | -tcx: TyCtxt<'tcx>, | |
61 | -stack: Vec<DefId>, | |
62 | -visited: FxHashSet<DefId>, | |
63 | -} | |
64 | - | |
65 | -impl Iterator for SupertraitDefIds<'_> { | |
66 | -type Item = DefId; | |
67 | - | |
68 | -fn next(&mut self) -> Option<DefId> { | |
69 | -let def_id = self.stack.pop()?; | |
70 | -let predicates = self.tcx.super_predicates_of(def_id); | |
71 | -let visited = &mut self.visited; | |
72 | -self.stack.extend( | |
73 | - predicates | |
74 | -.predicates | |
75 | -.iter() | |
76 | -.filter_map(|(pred, _) | |
77 | -.map(|trait_ref | |
78 | -.filter(|&super_def_id | |
79 | -); | |
80 | -Some(def_id) | |
81 | -} | |
82 | -} | |
83 | - | |
84 | 49 | // Note that we don't have access to a self type here, this has to be purely based on the trait (and |
85 | 50 | // supertrait) definitions. That means we can't call into the same vtable_entries code since that |
86 | 51 | // returns a specific instantiation (e.g., with Vacant slots when bounds aren't satisfied). The goal |