forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#91221 - matthiaskrgr:rollup-iuz3gxq, r=matthi…
…askrgr Rollup of 6 pull requests Successful merges: - rust-lang#89359 (Various fixes for const_trait_impl) - rust-lang#90499 (Link with default MACOSX_DEPLOYMENT_TARGET if not otherwise specified.) - rust-lang#91096 (Print associated types on opaque `impl Trait` types) - rust-lang#91111 (Do not visit attributes in `ItemLowerer`.) - rust-lang#91162 (explain why CTFE/Miri perform truncation on shift offset) - rust-lang#91185 (Remove `-Z force-overflow-checks`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
59 changed files
with
578 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use rustc_data_structures::stable_set::FxHashSet; | ||
|
||
use crate::ty::{PolyTraitRef, TyCtxt}; | ||
|
||
/// Given a PolyTraitRef, get the PolyTraitRefs of the trait's (transitive) supertraits. | ||
/// | ||
/// A simplfied version of the same function at `rustc_infer::traits::util::supertraits`. | ||
pub fn supertraits<'tcx>( | ||
tcx: TyCtxt<'tcx>, | ||
trait_ref: PolyTraitRef<'tcx>, | ||
) -> impl Iterator<Item = PolyTraitRef<'tcx>> { | ||
Elaborator { tcx, visited: FxHashSet::from_iter([trait_ref]), stack: vec![trait_ref] } | ||
} | ||
|
||
struct Elaborator<'tcx> { | ||
tcx: TyCtxt<'tcx>, | ||
visited: FxHashSet<PolyTraitRef<'tcx>>, | ||
stack: Vec<PolyTraitRef<'tcx>>, | ||
} | ||
|
||
impl<'tcx> Elaborator<'tcx> { | ||
fn elaborate(&mut self, trait_ref: PolyTraitRef<'tcx>) { | ||
let supertrait_refs = self | ||
.tcx | ||
.super_predicates_of(trait_ref.def_id()) | ||
.predicates | ||
.into_iter() | ||
.flat_map(|(pred, _)| { | ||
pred.subst_supertrait(self.tcx, &trait_ref).to_opt_poly_trait_ref() | ||
}) | ||
.map(|t| t.value) | ||
.filter(|supertrait_ref| self.visited.insert(*supertrait_ref)); | ||
|
||
self.stack.extend(supertrait_refs); | ||
} | ||
} | ||
|
||
impl<'tcx> Iterator for Elaborator<'tcx> { | ||
type Item = PolyTraitRef<'tcx>; | ||
|
||
fn next(&mut self) -> Option<PolyTraitRef<'tcx>> { | ||
if let Some(trait_ref) = self.stack.pop() { | ||
self.elaborate(trait_ref); | ||
Some(trait_ref) | ||
} else { | ||
None | ||
} | ||
} | ||
} |
Oops, something went wrong.