@@ -2995,7 +2995,7 @@ declare_lint_pass! {
2995
2995
UNSUPPORTED_NAKED_FUNCTIONS ,
2996
2996
MISSING_ABI ,
2997
2997
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS ,
2998
- DISJOINT_CAPTURE_DROP_REORDER ,
2998
+ DISJOINT_CAPTURE_MIGRATION ,
2999
2999
LEGACY_DERIVE_HELPERS ,
3000
3000
PROC_MACRO_BACK_COMPAT ,
3001
3001
OR_PATTERNS_BACK_COMPAT ,
@@ -3027,14 +3027,17 @@ declare_lint! {
3027
3027
}
3028
3028
3029
3029
declare_lint ! {
3030
- /// The `disjoint_capture_drop_reorder ` lint detects variables that aren't completely
3030
+ /// The `disjoint_capture_migration ` lint detects variables that aren't completely
3031
3031
/// captured when the feature `capture_disjoint_fields` is enabled and it affects the Drop
3032
3032
/// order of at least one path starting at this variable.
3033
+ /// It can also detect when a variable implements a trait, but one of its field does not and
3034
+ /// the field is captured by a closure and used with the assumption that said field implements
3035
+ /// the same trait as the root variable.
3033
3036
///
3034
- /// ### Example
3037
+ /// ### Example of drop reorder
3035
3038
///
3036
3039
/// ```rust,compile_fail
3037
- /// # #![deny(disjoint_capture_drop_reorder )]
3040
+ /// # #![deny(disjoint_capture_migration )]
3038
3041
/// # #![allow(unused)]
3039
3042
/// struct FancyInteger(i32);
3040
3043
///
@@ -3065,10 +3068,35 @@ declare_lint! {
3065
3068
///
3066
3069
/// In the above example `p.y` will be dropped at the end of `f` instead of with `c` if
3067
3070
/// the feature `capture_disjoint_fields` is enabled.
3068
- pub DISJOINT_CAPTURE_DROP_REORDER ,
3071
+ ///
3072
+ /// ### Example of auto-trait
3073
+ ///
3074
+ /// ```rust,compile_fail
3075
+ /// #![deny(disjoint_capture_migration)]
3076
+ /// use std::thread;
3077
+ ///
3078
+ /// struct Pointer (*mut i32);
3079
+ /// unsafe impl Send for Pointer {}
3080
+ ///
3081
+ /// fn main() {
3082
+ /// let mut f = 10;
3083
+ /// let fptr = Pointer(&mut f as *mut i32);
3084
+ /// thread::spawn(move || unsafe {
3085
+ /// *fptr.0 = 20;
3086
+ /// });
3087
+ /// }
3088
+ /// ```
3089
+ ///
3090
+ /// {{produces}}
3091
+ ///
3092
+ /// ### Explanation
3093
+ ///
3094
+ /// In the above example `fptr.0` is captured when feature `capture_disjoint_fields` is enabled.
3095
+ /// The field is of type *mut i32 which doesn't implement Send, making the code invalid as the
3096
+ /// field cannot be sent between thread safely.
3097
+ pub DISJOINT_CAPTURE_MIGRATION ,
3069
3098
Allow ,
3070
- "Drop reorder because of `capture_disjoint_fields`"
3071
-
3099
+ "Drop reorder and auto traits error because of `capture_disjoint_fields`"
3072
3100
}
3073
3101
3074
3102
declare_lint_pass ! ( UnusedDocComment => [ UNUSED_DOC_COMMENTS ] ) ;
0 commit comments