about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-11-04 12:18:03 +0100
committerGitHub <noreply@github.com>2022-11-04 12:18:03 +0100
commitee3c9f7051e26e7a36c8b252299bdd064562f8a9 (patch)
tree6293d3b0ffbdb769c93a40d193710c6c876551a1
parent9398676635df1dcf75268f217284329fe917028e (diff)
parent1013ee8df512015855937615500690664399545f (diff)
downloadrust-ee3c9f7051e26e7a36c8b252299bdd064562f8a9.tar.gz
rust-ee3c9f7051e26e7a36c8b252299bdd064562f8a9.zip
Rollup merge of #103950 - nbdd0121:master, r=tmiasko
Fix ICE when negative impl is collected during eager mono

```rust
trait Foo {
    fn foo() {}
}

impl !Foo for () {}
```

This code will currently cause an ICE when mono collection mode is "eager" (with `-C link-dead-code=y` or `-Z print-mono-items=eager`.
-rw-r--r--compiler/rustc_monomorphize/src/collector.rs4
-rw-r--r--src/test/ui/traits/negative-impls/eager-mono.rs12
2 files changed, 16 insertions, 0 deletions
diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs
index 3cfddd75462..58ddb807059 100644
--- a/compiler/rustc_monomorphize/src/collector.rs
+++ b/compiler/rustc_monomorphize/src/collector.rs
@@ -1336,6 +1336,10 @@ fn create_mono_items_for_default_impls<'tcx>(
 ) {
     match item.kind {
         hir::ItemKind::Impl(ref impl_) => {
+            if matches!(impl_.polarity, hir::ImplPolarity::Negative(_)) {
+                return;
+            }
+
             for param in impl_.generics.params {
                 match param.kind {
                     hir::GenericParamKind::Lifetime { .. } => {}
diff --git a/src/test/ui/traits/negative-impls/eager-mono.rs b/src/test/ui/traits/negative-impls/eager-mono.rs
new file mode 100644
index 00000000000..ce770376c0b
--- /dev/null
+++ b/src/test/ui/traits/negative-impls/eager-mono.rs
@@ -0,0 +1,12 @@
+// build-pass
+// compile-flags:-C link-dead-code=y
+
+#![feature(negative_impls)]
+
+trait Foo {
+    fn foo() {}
+}
+
+impl !Foo for () {}
+
+fn main() {}