-
Notifications
You must be signed in to change notification settings - Fork 434
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
Enable various new clippy lints #1025
base: rust-next
Are you sure you want to change the base?
Changes from 4 commits
3754849
82157b8
bbc6d1c
8f4700d
a764f0a
2118d15
b2d5dbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -621,6 +621,7 @@ macro_rules! try_pin_init { | |||||||||||||
// no possibility of returning without `unsafe`. | ||||||||||||||
struct __InitOk; | ||||||||||||||
// Get the pin data from the supplied type. | ||||||||||||||
// SAFETY: TODO | ||||||||||||||
let data = unsafe { | ||||||||||||||
use $crate::init::__internal::HasPinData; | ||||||||||||||
$t$(::<$($generics),*>)?::__pin_data() | ||||||||||||||
|
@@ -664,6 +665,7 @@ macro_rules! try_pin_init { | |||||||||||||
let init = move |slot| -> ::core::result::Result<(), $err> { | ||||||||||||||
init(slot).map(|__InitOk| ()) | ||||||||||||||
}; | ||||||||||||||
// SAFETY: TODO | ||||||||||||||
let init = unsafe { $crate::init::pin_init_from_closure::<_, $err>(init) }; | ||||||||||||||
init | ||||||||||||||
}}; | ||||||||||||||
|
@@ -735,8 +737,9 @@ macro_rules! try_pin_init { | |||||||||||||
@acc($($acc:tt)*), | ||||||||||||||
) => { | ||||||||||||||
// Endpoint, nothing more to munch, create the initializer. | ||||||||||||||
// Since we are in the `if false` branch, this will never get executed. We abuse `slot` to | ||||||||||||||
// get the correct type inference here: | ||||||||||||||
|
||||||||||||||
// SAFETY: Since we are in the `if false` branch, this will never get executed. We abuse | ||||||||||||||
// `slot` to get the correct type inference here: | ||||||||||||||
Comment on lines
-738
to
+742
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would leave the original comment and just add |
||||||||||||||
unsafe { | ||||||||||||||
::core::ptr::write($slot, $t { | ||||||||||||||
$($acc)* | ||||||||||||||
|
@@ -777,6 +780,7 @@ macro_rules! try_pin_init { | |||||||||||||
(forget_guards: | ||||||||||||||
@munch_fields($field:ident <- $val:expr, $($rest:tt)*), | ||||||||||||||
) => { | ||||||||||||||
// SAFETY: forgetting the guard is intentional | ||||||||||||||
unsafe { $crate::init::__internal::DropGuard::forget($field) }; | ||||||||||||||
Comment on lines
+783
to
784
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can leave these (forgetting guards) with a |
||||||||||||||
|
||||||||||||||
$crate::try_pin_init!(forget_guards: | ||||||||||||||
|
@@ -786,6 +790,7 @@ macro_rules! try_pin_init { | |||||||||||||
(forget_guards: | ||||||||||||||
@munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*), | ||||||||||||||
) => { | ||||||||||||||
// SAFETY: forgetting the guard is intentional | ||||||||||||||
unsafe { $crate::init::__internal::DropGuard::forget($field) }; | ||||||||||||||
|
||||||||||||||
$crate::try_pin_init!(forget_guards: | ||||||||||||||
|
@@ -891,6 +896,7 @@ macro_rules! try_init { | |||||||||||||
// no possibility of returning without `unsafe`. | ||||||||||||||
struct __InitOk; | ||||||||||||||
// Get the init data from the supplied type. | ||||||||||||||
// SAFETY: `HasInitData` is a marker trait which we are allowed to use in this context | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
let data = unsafe { | ||||||||||||||
use $crate::init::__internal::HasInitData; | ||||||||||||||
$t$(::<$($generics),*>)?::__init_data() | ||||||||||||||
|
@@ -933,6 +939,7 @@ macro_rules! try_init { | |||||||||||||
let init = move |slot| -> ::core::result::Result<(), $err> { | ||||||||||||||
init(slot).map(|__InitOk| ()) | ||||||||||||||
}; | ||||||||||||||
// SAFETY: TODO | ||||||||||||||
let init = unsafe { $crate::init::init_from_closure::<_, $err>(init) }; | ||||||||||||||
init | ||||||||||||||
}}; | ||||||||||||||
|
@@ -999,8 +1006,8 @@ macro_rules! try_init { | |||||||||||||
@acc($($acc:tt)*), | ||||||||||||||
) => { | ||||||||||||||
// Endpoint, nothing more to munch, create the initializer. | ||||||||||||||
// Since we are in the `if false` branch, this will never get executed. We abuse `slot` to | ||||||||||||||
// get the correct type inference here: | ||||||||||||||
// SAFETY: Since we are in the `if false` branch, this will never get | ||||||||||||||
// executed. We abuse `slot` to get the correct type inference here: | ||||||||||||||
Comment on lines
-1002
to
+1010
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||||||||||||||
unsafe { | ||||||||||||||
::core::ptr::write($slot, $t { | ||||||||||||||
$($acc)* | ||||||||||||||
|
@@ -1041,6 +1048,7 @@ macro_rules! try_init { | |||||||||||||
(forget_guards: | ||||||||||||||
@munch_fields($field:ident <- $val:expr, $($rest:tt)*), | ||||||||||||||
) => { | ||||||||||||||
// SAFETY: forgetting the guard is intentional | ||||||||||||||
unsafe { $crate::init::__internal::DropGuard::forget($field) }; | ||||||||||||||
|
||||||||||||||
$crate::try_init!(forget_guards: | ||||||||||||||
|
@@ -1050,6 +1058,7 @@ macro_rules! try_init { | |||||||||||||
(forget_guards: | ||||||||||||||
@munch_fields($field:ident $(: $val:expr)?, $($rest:tt)*), | ||||||||||||||
) => { | ||||||||||||||
// SAFETY: forgetting the guard is intentional | ||||||||||||||
unsafe { $crate::init::__internal::DropGuard::forget($field) }; | ||||||||||||||
|
||||||||||||||
$crate::try_init!(forget_guards: | ||||||||||||||
|
@@ -1197,6 +1206,7 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> { | |||||||||||||
// SAFETY: Every type can be initialized by-value. | ||||||||||||||
unsafe impl<T, E> Init<T, E> for T { | ||||||||||||||
unsafe fn __init(self, slot: *mut T) -> Result<(), E> { | ||||||||||||||
// SAFETY: `slot` is valid per the invariants of `__init` | ||||||||||||||
unsafe { slot.write(self) }; | ||||||||||||||
Ok(()) | ||||||||||||||
} | ||||||||||||||
|
@@ -1371,8 +1381,12 @@ pub fn zeroed<T: Zeroable>() -> impl Init<T> { | |||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// # Safety | ||||||||||||||
/// | ||||||||||||||
/// This can only be used on types that meet `Zeroable`'s guidelines | ||||||||||||||
Comment on lines
+1384
to
+1386
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
macro_rules! impl_zeroable { | ||||||||||||||
($($({$($generics:tt)*})? $t:ty, )*) => { | ||||||||||||||
// SAFETY: upheld by documented use | ||||||||||||||
$(unsafe impl$($($generics)*)? Zeroable for $t {})* | ||||||||||||||
}; | ||||||||||||||
} | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
//! - `macros/pin_data.rs` | ||
//! - `macros/pinned_drop.rs` | ||
|
||
#![allow(clippy::undocumented_unsafe_blocks)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also document these here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's only misssing two: unsafe impl<T: ?Sized> InitData for AllData<T> and unsafe impl<T: ?Sized> HasInitData for T Would you mind providing the comments for them? |
||
|
||
use super::*; | ||
|
||
/// See the [nomicon] for what subtyping is. See also [this table]. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -808,6 +808,7 @@ macro_rules! __pin_data { | |
>, | ||
} | ||
|
||
#[allow(clippy::expl_impl_clone_on_copy)] | ||
impl<$($impl_generics)*> ::core::clone::Clone for __ThePinData<$($ty_generics)*> | ||
where $($whr)* | ||
{ | ||
|
@@ -841,6 +842,7 @@ macro_rules! __pin_data { | |
} | ||
} | ||
|
||
// SAFETY: `__ThePinData` has the correct projections | ||
unsafe impl<$($impl_generics)*> | ||
$crate::init::__internal::PinData for __ThePinData<$($ty_generics)*> | ||
where $($whr)* | ||
|
@@ -965,6 +967,7 @@ macro_rules! __pin_data { | |
slot: *mut $p_type, | ||
init: impl $crate::init::PinInit<$p_type, E>, | ||
) -> ::core::result::Result<(), E> { | ||
// SAFETY: `slot` is valid per this function's contract | ||
unsafe { $crate::init::PinInit::__pinned_init(init, slot) } | ||
} | ||
)* | ||
|
@@ -974,6 +977,7 @@ macro_rules! __pin_data { | |
slot: *mut $type, | ||
init: impl $crate::init::Init<$type, E>, | ||
) -> ::core::result::Result<(), E> { | ||
// SAFETY: `slot` is valid per this function's contract | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function has no |
||
unsafe { $crate::init::Init::__init(init, slot) } | ||
} | ||
)* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.