Skip to content

Commit 28e2b29

Browse files
committed
Auto merge of #84730 - sexxi-goose:rox-auto-trait, r=nikomatsakis
Add auto traits and clone trait migrations for RFC2229 This PR - renames the existent RFC2229 migration `disjoint_capture_drop_reorder` to `disjoint_capture_migration` - add additional migrations for auto traits and clone trait Closes rust-lang/project-rfc-2229#29 Closes rust-lang/project-rfc-2229#28 r? `@nikomatsakis`
2 parents e1ff91f + 564b4de commit 28e2b29

27 files changed

+649
-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
@@ -939,6 +939,7 @@ symbols! {
939939
receiver,
940940
recursion_limit,
941941
reexport_test_harness_main,
942+
ref_unwind_safe,
942943
reference,
943944
reflect,
944945
reg,
@@ -1060,6 +1061,7 @@ symbols! {
10601061
self_in_typedefs,
10611062
self_struct_ctor,
10621063
semitransparent,
1064+
send,
10631065
send_trait,
10641066
shl,
10651067
shl_assign,
@@ -1281,6 +1283,7 @@ symbols! {
12811283
unused_qualifications,
12821284
unwind,
12831285
unwind_attributes,
1286+
unwind_safe,
12841287
unwrap,
12851288
unwrap_or,
12861289
use_extern_macros,

0 commit comments

Comments
 (0)