Skip to content

Commit 0653d7e

Browse files
authored
Rollup merge of rust-lang#116812 - rmehri01:missing_copy_implementations_non_exhaustive, r=petrochenkov
Disable missing_copy_implementations lint on non_exhaustive types Fixes rust-lang#116766
2 parents 6d7160c + a8e7e79 commit 0653d7e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

compiler/rustc_lint/src/builtin.rs

+5
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
677677
if type_implements_negative_copy_modulo_regions(cx.tcx, ty, param_env) {
678678
return;
679679
}
680+
if def.is_variant_list_non_exhaustive()
681+
|| def.variants().iter().any(|variant| variant.is_field_list_non_exhaustive())
682+
{
683+
return;
684+
}
680685

681686
// We shouldn't recommend implementing `Copy` on stateful things,
682687
// such as iterators.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Test for issue #116766.
2+
// Ensure that we don't suggest impl'ing `Copy` for a type if it or at least one
3+
// of it's variants are marked as `non_exhaustive`.
4+
5+
// check-pass
6+
7+
#![deny(missing_copy_implementations)]
8+
9+
#[non_exhaustive]
10+
pub enum MyEnum {
11+
A,
12+
}
13+
14+
#[non_exhaustive]
15+
pub struct MyStruct {
16+
foo: usize,
17+
}
18+
19+
pub enum MyEnum2 {
20+
#[non_exhaustive]
21+
A,
22+
B,
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)