Skip to content

Commit 9afea61

Browse files
committed
Add additional migrations to handle auto-traits and clone traits
Combine all 2229 migrations under one flag name
1 parent 109248a commit 9afea61

27 files changed

+666
-83
lines changed

compiler/rustc_hir/src/lang_items.rs

+3
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,7 @@ language_item_table! {
343343
Range, sym::Range, range_struct, Target::Struct;
344344
RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct;
345345
RangeTo, sym::RangeTo, range_to_struct, Target::Struct;
346+
Send, sym::send, send_trait, Target::Trait;
347+
UnwindSafe, sym::unwind_safe, unwind_safe_trait, Target::Trait;
348+
RefUnwindSafe, sym::ref_unwind_safe, ref_unwind_safe_trait, Target::Trait;
346349
}

compiler/rustc_lint_defs/src/builtin.rs

+35-7
Original file line numberDiff line numberDiff line change
@@ -2995,7 +2995,7 @@ declare_lint_pass! {
29952995
UNSUPPORTED_NAKED_FUNCTIONS,
29962996
MISSING_ABI,
29972997
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2998-
DISJOINT_CAPTURE_DROP_REORDER,
2998+
DISJOINT_CAPTURE_MIGRATION,
29992999
LEGACY_DERIVE_HELPERS,
30003000
PROC_MACRO_BACK_COMPAT,
30013001
OR_PATTERNS_BACK_COMPAT,
@@ -3027,14 +3027,17 @@ declare_lint! {
30273027
}
30283028

30293029
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
30313031
/// captured when the feature `capture_disjoint_fields` is enabled and it affects the Drop
30323032
/// 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.
30333036
///
3034-
/// ### Example
3037+
/// ### Example of drop reorder
30353038
///
30363039
/// ```rust,compile_fail
3037-
/// # #![deny(disjoint_capture_drop_reorder)]
3040+
/// # #![deny(disjoint_capture_migration)]
30383041
/// # #![allow(unused)]
30393042
/// struct FancyInteger(i32);
30403043
///
@@ -3065,10 +3068,35 @@ declare_lint! {
30653068
///
30663069
/// In the above example `p.y` will be dropped at the end of `f` instead of with `c` if
30673070
/// 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,
30693098
Allow,
3070-
"Drop reorder because of `capture_disjoint_fields`"
3071-
3099+
"Drop reorder and auto traits error because of `capture_disjoint_fields`"
30723100
}
30733101

30743102
declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);

compiler/rustc_span/src/symbol.rs

+3
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ symbols! {
933933
receiver,
934934
recursion_limit,
935935
reexport_test_harness_main,
936+
ref_unwind_safe,
936937
reference,
937938
reflect,
938939
reg,
@@ -1054,6 +1055,7 @@ symbols! {
10541055
self_in_typedefs,
10551056
self_struct_ctor,
10561057
semitransparent,
1058+
send,
10571059
send_trait,
10581060
shl,
10591061
shl_assign,
@@ -1275,6 +1277,7 @@ symbols! {
12751277
unused_qualifications,
12761278
unwind,
12771279
unwind_attributes,
1280+
unwind_safe,
12781281
unwrap,
12791282
unwrap_or,
12801283
use_extern_macros,

0 commit comments

Comments
 (0)