about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-03-07 17:09:36 +0000
committerMichael Goulet <michael@errs.io>2025-03-07 17:20:57 +0000
commitbbc80a819b542d751450bd82208438de5754ee47 (patch)
tree4d28fceb08858adbaa58d4b1803b6e6e9f915322
parent03eb45452305f2d52348279d0caa5fc1f12c438d (diff)
downloadrust-bbc80a819b542d751450bd82208438de5754ee47.tar.gz
rust-bbc80a819b542d751450bd82208438de5754ee47.zip
Delay bug for negative auto trait rather than ICEing
-rw-r--r--compiler/rustc_hir_analysis/src/check/always_applicable.rs5
-rw-r--r--tests/ui/auto-traits/ungated-impl.rs7
-rw-r--r--tests/ui/auto-traits/ungated-impl.stderr23
3 files changed, 34 insertions, 1 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/always_applicable.rs b/compiler/rustc_hir_analysis/src/check/always_applicable.rs
index ba5b61d3fce..8a841a11556 100644
--- a/compiler/rustc_hir_analysis/src/check/always_applicable.rs
+++ b/compiler/rustc_hir_analysis/src/check/always_applicable.rs
@@ -124,7 +124,10 @@ pub(crate) fn check_negative_auto_trait_impl<'tcx>(
                 // be implemented here to handle non-ADT rigid types.
                 Ok(())
             } else {
-                span_bug!(tcx.def_span(impl_def_id), "incoherent impl of negative auto trait");
+                Err(tcx.dcx().span_delayed_bug(
+                    tcx.def_span(impl_def_id),
+                    "incoherent impl of negative auto trait",
+                ))
             }
         }
     }
diff --git a/tests/ui/auto-traits/ungated-impl.rs b/tests/ui/auto-traits/ungated-impl.rs
new file mode 100644
index 00000000000..d46b4b01af9
--- /dev/null
+++ b/tests/ui/auto-traits/ungated-impl.rs
@@ -0,0 +1,7 @@
+auto trait MyTrait {}
+//~^ ERROR auto traits are experimental and possibly buggy
+
+impl<T> !MyTrait for *mut T {}
+//~^ ERROR negative trait bounds are not fully implemented
+
+fn main() {}
diff --git a/tests/ui/auto-traits/ungated-impl.stderr b/tests/ui/auto-traits/ungated-impl.stderr
new file mode 100644
index 00000000000..9d10d46a902
--- /dev/null
+++ b/tests/ui/auto-traits/ungated-impl.stderr
@@ -0,0 +1,23 @@
+error[E0658]: auto traits are experimental and possibly buggy
+  --> $DIR/ungated-impl.rs:1:1
+   |
+LL | auto trait MyTrait {}
+   | ^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
+   = help: add `#![feature(auto_traits)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error[E0658]: negative trait bounds are not fully implemented; use marker types for now
+  --> $DIR/ungated-impl.rs:4:9
+   |
+LL | impl<T> !MyTrait for *mut T {}
+   |         ^^^^^^^^
+   |
+   = note: see issue #68318 <https://github.com/rust-lang/rust/issues/68318> for more information
+   = help: add `#![feature(negative_impls)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0658`.