Skip to content

Commit 41ed491

Browse files
authored
Merge pull request #141 from Rust-for-Linux/dev/cleanup
cleanup workaround for old Rust compiler
2 parents c36ba14 + 9eff394 commit 41ed491

5 files changed

Lines changed: 12 additions & 52 deletions

File tree

internal/src/init.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,7 @@ pub(crate) fn expand(
172172
init(slot).map(|__InitOk| ())
173173
};
174174
// SAFETY: TODO
175-
let init = unsafe { ::pin_init::#init_from_closure::<_, #error>(init) };
176-
// FIXME: this let binding is required to avoid a compiler error (cycle when computing the
177-
// opaque type returned by this function) before Rust 1.81. Remove after MSRV bump.
178-
#[allow(
179-
clippy::let_and_return,
180-
reason = "some clippy versions warn about the let binding"
181-
)]
182-
init
175+
unsafe { ::pin_init::#init_from_closure::<_, #error>(init) }
183176
}})
184177
}
185178

internal/src/pin_data.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,17 @@ fn generate_projections(
247247
let projection = format_ident!("{ident}Projection");
248248
let this = format_ident!("this");
249249

250-
let (fields_decl, fields_proj) = collect_tuple(fields.iter().map(
251-
|(
252-
pinned,
253-
Field {
250+
let (fields_decl, fields_proj): (Vec<_>, Vec<_>) = fields
251+
.iter()
252+
.map(|(pinned, field)| {
253+
let Field {
254254
vis,
255255
ident,
256256
ty,
257257
attrs,
258258
..
259-
},
260-
)| {
259+
} = field;
260+
261261
let mut no_doc_attrs = attrs.clone();
262262
no_doc_attrs.retain(|a| !a.path().is_ident("doc"));
263263
let ident = ident
@@ -287,8 +287,8 @@ fn generate_projections(
287287
),
288288
)
289289
}
290-
},
291-
));
290+
})
291+
.collect();
292292
let structurally_pinned_fields_docs = fields
293293
.iter()
294294
.filter_map(|(pinned, field)| pinned.then_some(field))
@@ -498,14 +498,3 @@ impl VisitMut for SelfReplacer {
498498
// Do not descend into items, since items reset/change what `Self` refers to.
499499
}
500500
}
501-
502-
// replace with `.collect()` once MSRV is above 1.79
503-
fn collect_tuple<A, B>(iter: impl Iterator<Item = (A, B)>) -> (Vec<A>, Vec<B>) {
504-
let mut res_a = vec![];
505-
let mut res_b = vec![];
506-
for (a, b) in iter {
507-
res_a.push(a);
508-
res_b.push(b);
509-
}
510-
(res_a, res_b)
511-
}

src/lib.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,14 +1139,7 @@ pub const unsafe fn init_from_closure<T: ?Sized, E>(
11391139
pub const unsafe fn cast_pin_init<T, U, E>(init: impl PinInit<T, E>) -> impl PinInit<U, E> {
11401140
// SAFETY: initialization delegated to a valid initializer. Cast is valid by function safety
11411141
// requirements.
1142-
let res = unsafe { pin_init_from_closure(|ptr: *mut U| init.__pinned_init(ptr.cast::<T>())) };
1143-
// FIXME: this let binding is required to avoid a compiler error (cycle when computing the opaque
1144-
// type returned by this function) before Rust 1.81. Remove after MSRV bump.
1145-
#[allow(
1146-
clippy::let_and_return,
1147-
reason = "some clippy versions warn about the let binding"
1148-
)]
1149-
res
1142+
unsafe { pin_init_from_closure(|ptr: *mut U| init.__pinned_init(ptr.cast::<T>())) }
11501143
}
11511144

11521145
/// Changes the to be initialized type.
@@ -1158,14 +1151,7 @@ pub const unsafe fn cast_pin_init<T, U, E>(init: impl PinInit<T, E>) -> impl Pin
11581151
pub const unsafe fn cast_init<T, U, E>(init: impl Init<T, E>) -> impl Init<U, E> {
11591152
// SAFETY: initialization delegated to a valid initializer. Cast is valid by function safety
11601153
// requirements.
1161-
let res = unsafe { init_from_closure(|ptr: *mut U| init.__init(ptr.cast::<T>())) };
1162-
// FIXME: this let binding is required to avoid a compiler error (cycle when computing the opaque
1163-
// type returned by this function) before Rust 1.81. Remove after MSRV bump.
1164-
#[allow(
1165-
clippy::let_and_return,
1166-
reason = "some clippy versions warn about the let binding"
1167-
)]
1168-
res
1154+
unsafe { init_from_closure(|ptr: *mut U| init.__init(ptr.cast::<T>())) }
11691155
}
11701156

11711157
/// An initializer that leaves the memory uninitialized.

tests/ring_buf.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ pub struct EvenU64 {
157157
}
158158

159159
impl EvenU64 {
160-
#[allow(clippy::manual_is_multiple_of)]
161160
pub fn new2(value: u64) -> impl Init<Self, Error> {
162161
init!(Self {
163162
info: "Hello world!".to_owned(),
@@ -169,7 +168,6 @@ impl EvenU64 {
169168
}? Error)
170169
}
171170

172-
#[allow(clippy::manual_is_multiple_of)]
173171
pub fn new(value: u64) -> impl Init<Self, ()> {
174172
init!(Self {
175173
info: "Hello world!".to_owned(),

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ fn main() {
2222
| -> ::core::result::Result<(), ::core::convert::Infallible> {
2323
init(slot).map(|__InitOk| ())
2424
};
25-
let init = unsafe {
26-
::pin_init::init_from_closure::<_, ::core::convert::Infallible>(init)
27-
};
28-
#[allow(
29-
clippy::let_and_return,
30-
reason = "some clippy versions warn about the let binding"
31-
)] init
25+
unsafe { ::pin_init::init_from_closure::<_, ::core::convert::Infallible>(init) }
3226
};
3327
}

0 commit comments

Comments
 (0)