forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#91096 - compiler-errors:elaborate_opaque_tr…
…ait, r=estebank Print associated types on opaque `impl Trait` types This PR generalizes rust-lang#91021, printing associated types for all opaque `impl Trait` types instead of just special-casing for future. before: ``` error[E0271]: type mismatch resolving `<impl Iterator as Iterator>::Item == u32` ``` after: ``` error[E0271]: type mismatch resolving `<impl Iterator<Item = usize> as Iterator>::Item == u32` ``` --- Questions: 1. I'm kinda lost in binders hell with this one. Is all of the `rebind`ing necessary? 2. Is there a map collection type that will give me a stable iteration order? Doesn't seem like TraitRef is Ord, so I can't just sort later.. 3. I removed the logic that suppresses printing generator projection types. It creates outputs like this [gist](https://gist.github.com/compiler-errors/d6f12fb30079feb1ad1d5f1ab39a3a8d). Should I put that back? 4. I also added spaces between traits, `impl A+B` -> `impl A + B`. I quite like this change, but is there a good reason to keep it like that? r? ```@estebank```
- Loading branch information
Showing
36 changed files
with
355 additions
and
147 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
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 | ||
} | ||
} | ||
} |
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
Oops, something went wrong.