Skip to content

Commit 54f5649

Browse files
authored
Merge pull request #108 from Rust-for-Linux/dev/msrv-clippy-comment
properly document let binding workaround
2 parents e7a5b50 + bb3e96f commit 54f5649

File tree

7 files changed

+31
-8
lines changed

7 files changed

+31
-8
lines changed

examples/big_struct_in_place.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22

3+
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
4+
35
use pin_init::*;
46

57
// Struct with size over 1GiB

internal/src/init.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ pub(crate) fn expand(
189189
};
190190
// SAFETY: TODO
191191
let init = unsafe { ::pin_init::#init_from_closure::<_, #error>(init) };
192+
// FIXME: this let binding is required to avoid a compiler error (cycle when computing the
193+
// opaque type returned by this function) before Rust 1.81. Remove after MSRV bump.
194+
#[allow(
195+
clippy::let_and_return,
196+
reason = "some clippy versions warn about the let binding"
197+
)]
192198
init
193199
}})
194200
}

src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,9 +1147,12 @@ pub const unsafe fn cast_pin_init<T, U, E>(init: impl PinInit<T, E>) -> impl Pin
11471147
// SAFETY: initialization delegated to a valid initializer. Cast is valid by function safety
11481148
// requirements.
11491149
let res = unsafe { pin_init_from_closure(|ptr: *mut U| init.__pinned_init(ptr.cast::<T>())) };
1150-
// FIXME: remove the let statement once the nightly-MSRV allows it (1.78 otherwise encounters a
1151-
// cycle when computing the type returned by this function)
1152-
#[allow(clippy::let_and_return)]
1150+
// FIXME: this let binding is required to avoid a compiler error (cycle when computing the opaque
1151+
// type returned by this function) before Rust 1.81. Remove after MSRV bump.
1152+
#[allow(
1153+
clippy::let_and_return,
1154+
reason = "some clippy versions warn about the let binding"
1155+
)]
11531156
res
11541157
}
11551158

@@ -1163,9 +1166,12 @@ pub const unsafe fn cast_init<T, U, E>(init: impl Init<T, E>) -> impl Init<U, E>
11631166
// SAFETY: initialization delegated to a valid initializer. Cast is valid by function safety
11641167
// requirements.
11651168
let res = unsafe { init_from_closure(|ptr: *mut U| init.__init(ptr.cast::<T>())) };
1166-
// FIXME: remove the let statement once the nightly-MSRV allows it (1.78 otherwise encounters a
1167-
// cycle when computing the type returned by this function)
1168-
#[allow(clippy::let_and_return)]
1169+
// FIXME: this let binding is required to avoid a compiler error (cycle when computing the opaque
1170+
// type returned by this function) before Rust 1.81. Remove after MSRV bump.
1171+
#[allow(
1172+
clippy::let_and_return,
1173+
reason = "some clippy versions warn about the let binding"
1174+
)]
11691175
res
11701176
}
11711177

tests/default_error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(dead_code)]
2+
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
23

34
use pin_init::{init, Init};
45

tests/ui/expand/no_field_access.expanded.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ fn main() {
6868
let init = unsafe {
6969
::pin_init::init_from_closure::<_, ::core::convert::Infallible>(init)
7070
};
71-
init
71+
#[allow(
72+
clippy::let_and_return,
73+
reason = "some clippy versions warn about the let binding"
74+
)] init
7275
};
7376
}

tests/ui/expand/simple-init.expanded.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ fn main() {
3030
let init = unsafe {
3131
::pin_init::init_from_closure::<_, ::core::convert::Infallible>(init)
3232
};
33-
init
33+
#[allow(
34+
clippy::let_and_return,
35+
reason = "some clippy versions warn about the let binding"
36+
)] init
3437
};
3538
}

tests/underscore.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
2+
13
use pin_init::{init, Init};
24

35
pub struct Foo {

0 commit comments

Comments
 (0)