diff options
| author | Michael Goulet <michael@errs.io> | 2022-08-18 01:12:46 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-08-18 01:12:46 +0000 |
| commit | c4a5b142113ce9d161fcb653fcb3ec11c45680bf (patch) | |
| tree | 4dfa4998a3d252db7b324ce1ead1bf0b21068130 | |
| parent | 9c20b2a8cc7588decb6de25ac6a7912dcef24d65 (diff) | |
Avoid overflow in is_impossible_method
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/mod.rs | 13 | ||||
| -rw-r--r-- | src/test/rustdoc/issue-100620.rs | 19 |
2 files changed, 29 insertions, 3 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index b6d6df1eec6..20e9cbaa38f 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -571,9 +571,16 @@ fn is_impossible_method<'tcx>( }); tcx.infer_ctxt().ignoring_regions().enter(|ref infcx| { - let mut fulfill_ctxt = <dyn TraitEngine<'_>>::new(tcx); - fulfill_ctxt.register_predicate_obligations(infcx, predicates_for_trait); - !fulfill_ctxt.select_all_or_error(infcx).is_empty() + for obligation in predicates_for_trait { + // Ignore overflow error, to be conservative. + if let Ok(result) = infcx.evaluate_obligation(&obligation) + && !result.may_apply() + { + return true; + } + } + + false }) } diff --git a/src/test/rustdoc/issue-100620.rs b/src/test/rustdoc/issue-100620.rs new file mode 100644 index 00000000000..097666eb515 --- /dev/null +++ b/src/test/rustdoc/issue-100620.rs @@ -0,0 +1,19 @@ +pub trait Bar<S> {} + +pub trait Qux<T> {} + +pub trait Foo<T, S> { + fn bar() + where + T: Bar<S>, + { + } +} + +pub struct Concrete; + +impl<S> Foo<(), S> for Concrete {} + +impl<T, S> Bar<S> for T where S: Qux<T> {} + +impl<T, S> Qux<T> for S where T: Bar<S> {} |
