From c4a5b142113ce9d161fcb653fcb3ec11c45680bf Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 18 Aug 2022 01:12:46 +0000 Subject: [PATCH] Avoid overflow in is_impossible_method --- .../rustc_trait_selection/src/traits/mod.rs | 13 ++++++++++--- src/test/rustdoc/issue-100620.rs | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/test/rustdoc/issue-100620.rs 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 visit_const(&mut self, ct: ty::Const<'tcx>) -> ControlFlow { }); tcx.infer_ctxt().ignoring_regions().enter(|ref infcx| { - let mut fulfill_ctxt = >::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 {} + +pub trait Qux {} + +pub trait Foo { + fn bar() + where + T: Bar, + { + } +} + +pub struct Concrete; + +impl Foo<(), S> for Concrete {} + +impl Bar for T where S: Qux {} + +impl Qux for S where T: Bar {}