diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-11-04 12:18:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-04 12:18:03 +0100 |
| commit | ee3c9f7051e26e7a36c8b252299bdd064562f8a9 (patch) | |
| tree | 6293d3b0ffbdb769c93a40d193710c6c876551a1 | |
| parent | 9398676635df1dcf75268f217284329fe917028e (diff) | |
| parent | 1013ee8df512015855937615500690664399545f (diff) | |
| download | rust-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.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/traits/negative-impls/eager-mono.rs | 12 |
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() {} |
