about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-10-26 17:45:46 +0200
committerGitHub <noreply@github.com>2023-10-26 17:45:46 +0200
commit70a4678a77a97de5580b456adc166fbdb159932e (patch)
tree6634807c47e645f482944d8fc9e760795db22c0e
parent24bdc372feacd866d9ee01b4bea35364cf17ee43 (diff)
parentd572729d59a2812229f39c217246def5f77bd420 (diff)
downloadrust-70a4678a77a97de5580b456adc166fbdb159932e.tar.gz
rust-70a4678a77a97de5580b456adc166fbdb159932e.zip
Rollup merge of #117214 - oli-obk:error_shenanigans, r=compiler-errors
Quietly fail if an error has already occurred

fixes #117195
-rw-r--r--compiler/rustc_borrowck/src/type_check/free_region_relations.rs5
-rw-r--r--tests/ui/lifetimes/issue-76168-hr-outlives-3.rs19
-rw-r--r--tests/ui/lifetimes/issue-76168-hr-outlives-3.stderr51
3 files changed, 73 insertions, 2 deletions
diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs
index f22851d76b3..c84256f8ff3 100644
--- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs
+++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs
@@ -8,7 +8,7 @@ use rustc_infer::infer::InferCtxt;
 use rustc_middle::mir::ConstraintCategory;
 use rustc_middle::traits::query::OutlivesBound;
 use rustc_middle::ty::{self, RegionVid, Ty};
-use rustc_span::{Span, DUMMY_SP};
+use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
 use rustc_trait_selection::traits::query::type_op::{self, TypeOp};
 use std::rc::Rc;
 use type_op::TypeOpOutput;
@@ -318,7 +318,8 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
             .param_env
             .and(type_op::implied_outlives_bounds::ImpliedOutlivesBounds { ty })
             .fully_perform(self.infcx, DUMMY_SP)
-            .unwrap_or_else(|_| bug!("failed to compute implied bounds {:?}", ty));
+            .map_err(|_: ErrorGuaranteed| debug!("failed to compute implied bounds {:?}", ty))
+            .ok()?;
         debug!(?bounds, ?constraints);
         self.add_outlives_bounds(bounds);
         constraints
diff --git a/tests/ui/lifetimes/issue-76168-hr-outlives-3.rs b/tests/ui/lifetimes/issue-76168-hr-outlives-3.rs
new file mode 100644
index 00000000000..081e962028c
--- /dev/null
+++ b/tests/ui/lifetimes/issue-76168-hr-outlives-3.rs
@@ -0,0 +1,19 @@
+// edition:2018
+
+#![feature(unboxed_closures)]
+use std::future::Future;
+
+async fn wrapper<F>(f: F)
+//~^ ERROR: expected a `FnOnce<(&'a mut i32,)>` closure, found `i32`
+//~| ERROR: expected a `FnOnce<(&'a mut i32,)>` closure, found `i32`
+//~| ERROR: expected a `FnOnce<(&'a mut i32,)>` closure, found `i32`
+where
+    F:,
+    for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
+{
+    //~^ ERROR: expected a `FnOnce<(&'a mut i32,)>` closure, found `i32`
+    let mut i = 41;
+    &mut i;
+}
+
+fn main() {}
diff --git a/tests/ui/lifetimes/issue-76168-hr-outlives-3.stderr b/tests/ui/lifetimes/issue-76168-hr-outlives-3.stderr
new file mode 100644
index 00000000000..9d8c15d4a6a
--- /dev/null
+++ b/tests/ui/lifetimes/issue-76168-hr-outlives-3.stderr
@@ -0,0 +1,51 @@
+error[E0277]: expected a `FnOnce<(&'a mut i32,)>` closure, found `i32`
+  --> $DIR/issue-76168-hr-outlives-3.rs:6:1
+   |
+LL | / async fn wrapper<F>(f: F)
+LL | |
+LL | |
+LL | |
+LL | | where
+LL | |     F:,
+LL | |     for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
+   | |______________________________________________________________________________^ expected an `FnOnce<(&'a mut i32,)>` closure, found `i32`
+   |
+   = help: the trait `for<'a> FnOnce<(&'a mut i32,)>` is not implemented for `i32`
+
+error[E0277]: expected a `FnOnce<(&'a mut i32,)>` closure, found `i32`
+  --> $DIR/issue-76168-hr-outlives-3.rs:6:10
+   |
+LL | async fn wrapper<F>(f: F)
+   |          ^^^^^^^ expected an `FnOnce<(&'a mut i32,)>` closure, found `i32`
+   |
+   = help: the trait `for<'a> FnOnce<(&'a mut i32,)>` is not implemented for `i32`
+
+error[E0277]: expected a `FnOnce<(&'a mut i32,)>` closure, found `i32`
+  --> $DIR/issue-76168-hr-outlives-3.rs:13:1
+   |
+LL | / {
+LL | |
+LL | |     let mut i = 41;
+LL | |     &mut i;
+LL | | }
+   | |_^ expected an `FnOnce<(&'a mut i32,)>` closure, found `i32`
+   |
+   = help: the trait `for<'a> FnOnce<(&'a mut i32,)>` is not implemented for `i32`
+
+error[E0277]: expected a `FnOnce<(&'a mut i32,)>` closure, found `i32`
+  --> $DIR/issue-76168-hr-outlives-3.rs:6:1
+   |
+LL | / async fn wrapper<F>(f: F)
+LL | |
+LL | |
+LL | |
+LL | | where
+LL | |     F:,
+LL | |     for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
+   | |______________________________________________________________________________^ expected an `FnOnce<(&'a mut i32,)>` closure, found `i32`
+   |
+   = help: the trait `for<'a> FnOnce<(&'a mut i32,)>` is not implemented for `i32`
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0277`.