Skip to content

Commit 5162ecc

Browse files
committed
fix clippy issues
1 parent 4f263ca commit 5162ecc

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,14 @@
248248
#![cfg_attr(any(feature = "alloc"), feature(new_uninit))]
249249
#![cfg_attr(any(feature = "alloc"), feature(get_mut_unchecked))]
250250

251-
#[cfg(any(feature = "alloc"))]
251+
#[cfg(feature = "alloc")]
252252
extern crate alloc;
253253

254-
#[cfg(any(feature = "alloc"))]
255-
use alloc::{boxed::Box, sync::Arc};
254+
#[cfg(all(feature = "alloc", not(feature = "std")))]
255+
use alloc::boxed::Box;
256+
#[cfg(feature = "alloc")]
257+
use alloc::sync::Arc;
258+
256259
use core::{
257260
alloc::AllocError,
258261
cell::UnsafeCell,
@@ -1202,8 +1205,9 @@ pub trait InPlaceInit<T>: Sized {
12021205
fn pin_init(init: impl PinInit<T>) -> Result<Pin<Self>, AllocError> {
12031206
// SAFETY: We delegate to `init` and only change the error type.
12041207
let init = unsafe {
1205-
pin_init_from_closure(|slot| {
1206-
Ok(init.__pinned_init(slot).unwrap()) // cannot fail
1208+
pin_init_from_closure(|slot| match init.__pinned_init(slot) {
1209+
Ok(()) => Ok(()),
1210+
Err(i) => match i {},
12071211
})
12081212
};
12091213
Self::try_pin_init(init)
@@ -1217,13 +1221,16 @@ pub trait InPlaceInit<T>: Sized {
12171221
/// Use the given initializer to in-place initialize a `T`.
12181222
fn init(init: impl Init<T>) -> Result<Self, AllocError> {
12191223
let init = unsafe {
1220-
init_from_closure(|slot| Ok(init.__init(slot).unwrap())) //cannot fail
1224+
init_from_closure(|slot| match init.__init(slot) {
1225+
Ok(()) => Ok(()),
1226+
Err(i) => match i {},
1227+
})
12211228
};
12221229
Self::try_init(init)
12231230
}
12241231
}
12251232

1226-
#[cfg(any(feature = "alloc"))]
1233+
#[cfg(feature = "alloc")]
12271234
impl<T> InPlaceInit<T> for Box<T> {
12281235
#[inline]
12291236
fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E>
@@ -1254,7 +1261,7 @@ impl<T> InPlaceInit<T> for Box<T> {
12541261
}
12551262
}
12561263

1257-
#[cfg(any(feature = "alloc"))]
1264+
#[cfg(feature = "alloc")]
12581265
impl<T> InPlaceInit<T> for Arc<T> {
12591266
#[inline]
12601267
fn try_pin_init<E>(init: impl PinInit<T, E>) -> Result<Pin<Self>, E>

tests/ui/missing_pin_data.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ error[E0599]: no associated item named `__pin_data` found for struct `Foo` in th
1212
candidate #1: `HasPinData`
1313
= note: this error originates in the macro `pin_init` (in Nightly builds, run with -Z macro-backtrace for more info)
1414
help: there is an associated function `__init_data` with a similar name
15-
--> $SRC_DIR/src/lib.rs:616:35
15+
--> $SRC_DIR/src/lib.rs:619:35
1616
|
17-
616| @has_data(HasPinData, __init_data),
17+
619| @has_data(HasPinData, __init_data),
1818
| ~~~~~~~~~~~
1919

2020
error: aborting due to 1 previous error

tests/ui/no_pin_data_but_pinned_drop.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ error[E0277]: the trait bound `Foo: HasPinData` is not satisfied
55
| ^^^ the trait `HasPinData` is not implemented for `Foo`
66
|
77
note: required by a bound in `PinnedDrop`
8-
--> $SRC_DIR/src/lib.rs:1319:30
8+
--> $SRC_DIR/src/lib.rs:1326:30
99
|
10-
1319 | pub unsafe trait PinnedDrop: __internal::HasPinData {
10+
1326 | pub unsafe trait PinnedDrop: __internal::HasPinData {
1111
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `PinnedDrop`
1212

1313
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)