Skip to content

Commit 983f4da

Browse files
committed
Auto merge of #100705 - compiler-errors:issue-100620, r=oli-obk
Avoid reporting overflow in `is_impossible_method` Fixes #100620 We're evaluating a new predicate in a different param-env than it was checked during typeck, so be more careful about handling overflow errors. Instead of using `FulfillmentCtxt`, using `InferCtxt::evaluate_obligation` by itself will give us back the overflow error, so we can throw it away properly. This may give us more false-positives, but it doesn't regress the `<HashMap as Iterator>::rev` example that originally motivated adding `is_impossible_method` in the first place.
2 parents 13a6aaf + c4a5b14 commit 983f4da

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

compiler/rustc_trait_selection/src/traits/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,16 @@ fn is_impossible_method<'tcx>(
579579
});
580580

581581
tcx.infer_ctxt().ignoring_regions().enter(|ref infcx| {
582-
let mut fulfill_ctxt = <dyn TraitEngine<'_>>::new(tcx);
583-
fulfill_ctxt.register_predicate_obligations(infcx, predicates_for_trait);
584-
!fulfill_ctxt.select_all_or_error(infcx).is_empty()
582+
for obligation in predicates_for_trait {
583+
// Ignore overflow error, to be conservative.
584+
if let Ok(result) = infcx.evaluate_obligation(&obligation)
585+
&& !result.may_apply()
586+
{
587+
return true;
588+
}
589+
}
590+
591+
false
585592
})
586593
}
587594

src/test/rustdoc/issue-100620.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pub trait Bar<S> {}
2+
3+
pub trait Qux<T> {}
4+
5+
pub trait Foo<T, S> {
6+
fn bar()
7+
where
8+
T: Bar<S>,
9+
{
10+
}
11+
}
12+
13+
pub struct Concrete;
14+
15+
impl<S> Foo<(), S> for Concrete {}
16+
17+
impl<T, S> Bar<S> for T where S: Qux<T> {}
18+
19+
impl<T, S> Qux<T> for S where T: Bar<S> {}

0 commit comments

Comments
 (0)