Skip to content

Commit c4a5b14

Browse files
Avoid overflow in is_impossible_method
1 parent 9c20b2a commit c4a5b14

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
@@ -571,9 +571,16 @@ fn is_impossible_method<'tcx>(
571571
});
572572

573573
tcx.infer_ctxt().ignoring_regions().enter(|ref infcx| {
574-
let mut fulfill_ctxt = <dyn TraitEngine<'_>>::new(tcx);
575-
fulfill_ctxt.register_predicate_obligations(infcx, predicates_for_trait);
576-
!fulfill_ctxt.select_all_or_error(infcx).is_empty()
574+
for obligation in predicates_for_trait {
575+
// Ignore overflow error, to be conservative.
576+
if let Ok(result) = infcx.evaluate_obligation(&obligation)
577+
&& !result.may_apply()
578+
{
579+
return true;
580+
}
581+
}
582+
583+
false
577584
})
578585
}
579586

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)