From 1013ee8df512015855937615500690664399545f Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 4 Nov 2022 03:08:28 +0000 Subject: [PATCH] Fix ICE when negative impl is collected during eager mono --- compiler/rustc_monomorphize/src/collector.rs | 4 ++++ src/test/ui/traits/negative-impls/eager-mono.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/test/ui/traits/negative-impls/eager-mono.rs diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 3cfddd75462c0..58ddb807059ae 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 0000000000000..ce770376c0b2f --- /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() {}