|
```
-## unions-with-drop-fields
-
-This lint detects use of unions that contain fields with possibly non-trivial drop code. Some
-example code that triggers this lint:
-
-```rust
-#![feature(untagged_unions)]
-
-union U {
- s: String,
-}
-```
-
-This will produce:
-
-```text
-warning: union contains a field with possibly non-trivial drop code, drop code of union fields is ignored when dropping the union
- --> src/main.rs:4:5
- |
-4 | s: String,
- | ^^^^^^^^^
- |
-```
-
## unknown-lints
This lint detects unrecognized lint attribute. Some
}
}
-declare_lint! {
- UNIONS_WITH_DROP_FIELDS,
- Warn,
- "use of unions that contain fields with possibly non-trivial drop code"
-}
-
-declare_lint_pass!(
- /// Lint for unions that contain fields with possibly non-trivial destructors.
- UnionsWithDropFields => [UNIONS_WITH_DROP_FIELDS]
-);
-
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnionsWithDropFields {
- fn check_item(&mut self, ctx: &LateContext<'_, '_>, item: &hir::Item) {
- if let hir::ItemKind::Union(ref vdata, _) = item.kind {
- for field in vdata.fields() {
- let field_ty = ctx.tcx.type_of(
- ctx.tcx.hir().local_def_id(field.hir_id));
- if field_ty.needs_drop(ctx.tcx, ctx.param_env) {
- ctx.span_lint(UNIONS_WITH_DROP_FIELDS,
- field.span,
- "union contains a field with possibly non-trivial drop code, \
- drop code of union fields is ignored when dropping the union");
- return;
- }
- }
- }
- }
-}
-
declare_lint! {
pub UNREACHABLE_PUB,
Allow,
NO_MANGLE_GENERIC_ITEMS,
MUTABLE_TRANSMUTES,
UNSTABLE_FEATURES,
- UNIONS_WITH_DROP_FIELDS,
UNREACHABLE_PUB,
TYPE_ALIAS_BOUNDS,
TRIVIAL_BOUNDS
// Depends on referenced function signatures in expressions
MutableTransmutes: MutableTransmutes,
- // Depends on types of fields, checks if they implement Drop
- UnionsWithDropFields: UnionsWithDropFields,
-
TypeAliasBounds: TypeAliasBounds,
TrivialConstraints: TrivialConstraints,