about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-02-23 09:42:12 +0100
committerGitHub <noreply@github.com>2024-02-23 09:42:12 +0100
commit5de3a4ce0e4f4105c663fafef34c1b370fd402a4 (patch)
treec3fd29c54b4922500840075d226f7695137f921d
parent7ae95b266ee483b0a63d627ed763cecbe44b388d (diff)
parent938e594d62e66cf1d15452a7ed29e2eec4d2efef (diff)
Rollup merge of #121480 - nnethercote:fix-more-121208-fallout, r=lcnr
Fix more #121208 fallout

#121208 converted lots of delayed bugs to bugs. Unsurprisingly, there were a few invalid conversion found via fuzzing.

r? `@lcnr`
-rw-r--r--compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs12
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs7
-rw-r--r--tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs18
-rw-r--r--tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr30
-rw-r--r--tests/ui/never_type/span-bug-issue-121445.rs15
-rw-r--r--tests/ui/never_type/span-bug-issue-121445.stderr22
6 files changed, 94 insertions, 10 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs
index 7bdbab4325c..b5e69b8e376 100644
--- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs
+++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs
@@ -154,10 +154,8 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
         trait_m_sig.inputs_and_output,
     ));
     if !ocx.select_all_or_error().is_empty() {
-        // This code path is not reached in any tests, but may be reachable. If
-        // this is triggered, it should be converted to `delayed_bug` and the
-        // triggering case turned into a test.
-        tcx.dcx().bug("encountered errors when checking RPITIT refinement (selection)");
+        tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
+        return;
     }
     let outlives_env = OutlivesEnvironment::with_bounds(
         param_env,
@@ -165,10 +163,8 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
     );
     let errors = infcx.resolve_regions(&outlives_env);
     if !errors.is_empty() {
-        // This code path is not reached in any tests, but may be reachable. If
-        // this is triggered, it should be converted to `delayed_bug` and the
-        // triggering case turned into a test.
-        tcx.dcx().bug("encountered errors when checking RPITIT refinement (regions)");
+        tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)");
+        return;
     }
     // Resolve any lifetime variables that may have been introduced during normalization.
     let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 89cc46dc5ab..81440b0562e 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -77,8 +77,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         // coercions from ! to `expected`.
         if ty.is_never() {
             if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
-                self.dcx()
-                    .span_bug(expr.span, "expression with never type wound up being adjusted");
+                let reported = self.dcx().span_delayed_bug(
+                    expr.span,
+                    "expression with never type wound up being adjusted",
+                );
+                return Ty::new_error(self.tcx(), reported);
             }
 
             let adj_ty = self.next_ty_var(TypeVariableOrigin {
diff --git a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs
new file mode 100644
index 00000000000..10167ee9352
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs
@@ -0,0 +1,18 @@
+pub trait Iterable {
+    type Item<'a>
+    where
+        Self: 'a;
+
+    fn iter(&self) -> impl Iterator;
+}
+
+impl<'a, I: 'a + Iterable> Iterable for &'a I {
+    type Item = u32;
+    //~^ ERROR lifetime parameters or bounds on type `Item` do not match the trait declaration
+
+    fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {}
+    //~^ ERROR binding for associated type `Item` references lifetime `'missing`
+    //~| ERROR `()` is not an iterator
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr
new file mode 100644
index 00000000000..96c3644f893
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr
@@ -0,0 +1,30 @@
+error[E0582]: binding for associated type `Item` references lifetime `'missing`, which does not appear in the trait input types
+  --> $DIR/span-bug-issue-121457.rs:13:51
+   |
+LL |     fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {}
+   |                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0195]: lifetime parameters or bounds on type `Item` do not match the trait declaration
+  --> $DIR/span-bug-issue-121457.rs:10:14
+   |
+LL |     type Item<'a>
+   |              ---- lifetimes in impl do not match this type in trait
+LL |     where
+LL |         Self: 'a;
+   |               -- this bound might be missing in the impl
+...
+LL |     type Item = u32;
+   |              ^ lifetimes do not match type in trait
+
+error[E0277]: `()` is not an iterator
+  --> $DIR/span-bug-issue-121457.rs:13:23
+   |
+LL |     fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {}
+   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
+   |
+   = help: the trait `Iterator` is not implemented for `()`
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0195, E0277, E0582.
+For more information about an error, try `rustc --explain E0195`.
diff --git a/tests/ui/never_type/span-bug-issue-121445.rs b/tests/ui/never_type/span-bug-issue-121445.rs
new file mode 100644
index 00000000000..2fe22529c4e
--- /dev/null
+++ b/tests/ui/never_type/span-bug-issue-121445.rs
@@ -0,0 +1,15 @@
+#![feature(never_type)]
+
+fn test2() {
+    let x: !;
+    let c2 = SingleVariant::Points(0)
+        | match x { //~ ERROR no implementation for `SingleVariant | ()`
+            _ => (),
+        };
+}
+
+enum SingleVariant {
+    Points(u32),
+}
+
+fn main() {}
diff --git a/tests/ui/never_type/span-bug-issue-121445.stderr b/tests/ui/never_type/span-bug-issue-121445.stderr
new file mode 100644
index 00000000000..b211afa236f
--- /dev/null
+++ b/tests/ui/never_type/span-bug-issue-121445.stderr
@@ -0,0 +1,22 @@
+error[E0369]: no implementation for `SingleVariant | ()`
+  --> $DIR/span-bug-issue-121445.rs:6:9
+   |
+LL |       let c2 = SingleVariant::Points(0)
+   |                ------------------------ SingleVariant
+LL |           | match x {
+   |  _________^_-
+LL | |             _ => (),
+LL | |         };
+   | |_________- ()
+   |
+note: an implementation of `BitOr<()>` might be missing for `SingleVariant`
+  --> $DIR/span-bug-issue-121445.rs:11:1
+   |
+LL | enum SingleVariant {
+   | ^^^^^^^^^^^^^^^^^^ must implement `BitOr<()>`
+note: the trait `BitOr` must be implemented
+  --> $SRC_DIR/core/src/ops/bit.rs:LL:COL
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0369`.