Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto traits and clone trait migrations for RFC2229 #84730

Merged
merged 4 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,7 @@ language_item_table! {
Range, sym::Range, range_struct, Target::Struct;
RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct;
RangeTo, sym::RangeTo, range_to_struct, Target::Struct;
Send, sym::send, send_trait, Target::Trait;
UnwindSafe, sym::unwind_safe, unwind_safe_trait, Target::Trait;
RefUnwindSafe, sym::ref_unwind_safe, ref_unwind_safe_trait, Target::Trait;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just seen in #86603 that Send is made a lang item again.

I don't see why this PR needs to add new lang items, all of these could be diagnostic items instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, I forgot that diagnostic items were a thing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrochenkov Thanks for pointing this out, I'll try to have a fix done in the next few days.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrochenkov The fix is up for review #86726

}
42 changes: 35 additions & 7 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2995,7 +2995,7 @@ declare_lint_pass! {
UNSUPPORTED_NAKED_FUNCTIONS,
MISSING_ABI,
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
DISJOINT_CAPTURE_DROP_REORDER,
DISJOINT_CAPTURE_MIGRATION,
LEGACY_DERIVE_HELPERS,
PROC_MACRO_BACK_COMPAT,
OR_PATTERNS_BACK_COMPAT,
Expand Down Expand Up @@ -3027,14 +3027,17 @@ declare_lint! {
}

declare_lint! {
/// The `disjoint_capture_drop_reorder` lint detects variables that aren't completely
/// The `disjoint_capture_migration` lint detects variables that aren't completely
/// captured when the feature `capture_disjoint_fields` is enabled and it affects the Drop
/// order of at least one path starting at this variable.
/// It can also detect when a variable implements a trait, but one of its field does not and
/// the field is captured by a closure and used with the assumption that said field implements
/// the same trait as the root variable.
///
/// ### Example
/// ### Example of drop reorder
///
/// ```rust,compile_fail
/// # #![deny(disjoint_capture_drop_reorder)]
/// # #![deny(disjoint_capture_migration)]
/// # #![allow(unused)]
/// struct FancyInteger(i32);
///
Expand Down Expand Up @@ -3065,10 +3068,35 @@ declare_lint! {
///
/// In the above example `p.y` will be dropped at the end of `f` instead of with `c` if
/// the feature `capture_disjoint_fields` is enabled.
pub DISJOINT_CAPTURE_DROP_REORDER,
///
/// ### Example of auto-trait
///
/// ```rust,compile_fail
/// #![deny(disjoint_capture_migration)]
/// use std::thread;
///
/// struct Pointer (*mut i32);
/// unsafe impl Send for Pointer {}
///
/// fn main() {
/// let mut f = 10;
/// let fptr = Pointer(&mut f as *mut i32);
/// thread::spawn(move || unsafe {
/// *fptr.0 = 20;
/// });
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In the above example `fptr.0` is captured when feature `capture_disjoint_fields` is enabled.
/// The field is of type *mut i32 which doesn't implement Send, making the code invalid as the
/// field cannot be sent between thread safely.
pub DISJOINT_CAPTURE_MIGRATION,
Allow,
"Drop reorder because of `capture_disjoint_fields`"

"Drop reorder and auto traits error because of `capture_disjoint_fields`"
}

declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ symbols! {
receiver,
recursion_limit,
reexport_test_harness_main,
ref_unwind_safe,
reference,
reflect,
reg,
Expand Down Expand Up @@ -1054,6 +1055,7 @@ symbols! {
self_in_typedefs,
self_struct_ctor,
semitransparent,
send,
send_trait,
shl,
shl_assign,
Expand Down Expand Up @@ -1275,6 +1277,7 @@ symbols! {
unused_qualifications,
unwind,
unwind_attributes,
unwind_safe,
unwrap,
unwrap_or,
use_extern_macros,
Expand Down
Loading