mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
expl_impl_clone_on_copy: ignore packed structs with type/const params
This commit is contained in:
parent
15226f91bb
commit
34024adc88
@ -14,8 +14,8 @@ use rustc_lint::{LateContext, LateLintPass};
|
|||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::traits::Reveal;
|
use rustc_middle::traits::Reveal;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate,
|
self, Binder, BoundConstness, Clause, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind,
|
||||||
Ty, TyCtxt,
|
TraitPredicate, Ty, TyCtxt,
|
||||||
};
|
};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
@ -366,6 +366,15 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h
|
|||||||
if ty_subs.types().any(|ty| !implements_trait(cx, ty, clone_id, &[])) {
|
if ty_subs.types().any(|ty| !implements_trait(cx, ty, clone_id, &[])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// `#[repr(packed)]` structs with type/const parameters can't derive `Clone`.
|
||||||
|
// https://github.com/rust-lang/rust-clippy/issues/10188
|
||||||
|
if ty_adt.repr().packed()
|
||||||
|
&& ty_subs
|
||||||
|
.iter()
|
||||||
|
.any(|arg| matches!(arg.unpack(), GenericArgKind::Type(_) | GenericArgKind::Const(_)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
span_lint_and_note(
|
span_lint_and_note(
|
||||||
cx,
|
cx,
|
||||||
|
@ -85,4 +85,15 @@ impl<T: Clone, U> Clone for GenericRef<'_, T, U> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust-clippy/issues/10188
|
||||||
|
#[repr(packed)]
|
||||||
|
#[derive(Copy)]
|
||||||
|
struct Packed<T>(T);
|
||||||
|
|
||||||
|
impl<T: Copy> Clone for Packed<T> {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user