Skip to content

Commit 4745cbe

Browse files
committed
Auto merge of rust-lang#75205 - Aaron1011:fix/auto-trait-proj-ice, r=nikomatsakis
Handle projection predicates in the param env for auto-trait docs Fixes rust-lang#72213 Any predicates in the param env are guaranteed to hold, so we don't need to do any additional processing of them if we come across them as sub-obligations of a different predicate. This allows us to avoid adding the same predicate to the computed ParamEnv multiple times (but with different regions each time), which causes an ambiguity error during fulfillment.
2 parents c94ed5c + ab766f0 commit 4745cbe

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/librustc_trait_selection/traits/auto_trait.rs

+7
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ impl AutoTraitFinder<'tcx> {
270270
) -> Option<(ty::ParamEnv<'tcx>, ty::ParamEnv<'tcx>)> {
271271
let tcx = infcx.tcx;
272272

273+
// Don't try to proess any nested obligations involving predicates
274+
// that are already in the `ParamEnv` (modulo regions): we already
275+
// know that they must hold.
276+
for predicate in param_env.caller_bounds() {
277+
fresh_preds.insert(self.clean_pred(infcx, predicate));
278+
}
279+
273280
let mut select = SelectionContext::with_negative(&infcx, true);
274281

275282
let mut already_visited = FxHashSet::default();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Regression test for issue #72213
2+
// Tests that we don't ICE when we have projection predicates
3+
// in our initial ParamEnv
4+
5+
pub struct Lines<'a, L>
6+
where
7+
L: Iterator<Item = &'a ()>,
8+
{
9+
words: std::iter::Peekable<Words<'a, L>>,
10+
}
11+
12+
pub struct Words<'a, L> {
13+
_m: std::marker::PhantomData<&'a L>,
14+
}
15+
16+
impl<'a, L> Iterator for Words<'a, L>
17+
where
18+
L: Iterator<Item = &'a ()>,
19+
{
20+
type Item = ();
21+
22+
fn next(&mut self) -> Option<Self::Item> {
23+
unimplemented!()
24+
}
25+
}

0 commit comments

Comments
 (0)