Skip to content

Commit 61f40ed

Browse files
nnethercoteLegNeato
authored andcommitted
Update various crates from edition 2021 to 2024.
Three kinds of changes are required. - Unsafe operations within unsafe functions now need to be explicitly marked with `unsafe`. - `#[no_mangle]` now must be `#[unsafe(no_mangle)]`. - `gen` is now a keyword. - `cargo fmt` formats some things slightly different in edition 2024. - `env::set_var` is now unsafe. - Clippy wants nested `if`s to be chained where possible.
1 parent c120ff7 commit 61f40ed

File tree

22 files changed

+97
-93
lines changed

22 files changed

+97
-93
lines changed

crates/cuda_builder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cuda_builder"
33
version = "0.3.0"
4-
edition = "2021"
4+
edition = "2024"
55
authors = ["Riccardo D'Ambrosio <[email protected]>", "The rust-gpu Authors"]
66
license = "MIT OR Apache-2.0"
77
description = "Builder for easily building rustc_codegen_nvvm crates"

crates/cuda_builder/src/lib.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,11 @@ fn find_in_dir(dir: &Path, filename: &str) -> Option<PathBuf> {
469469
continue;
470470
}
471471

472-
if let Some(name) = path.file_name().and_then(|s| s.to_str()) {
473-
if (name == filename)
474-
|| (name.starts_with(&hashed_prefix) && name.ends_with(dll_suffix))
475-
{
476-
return Some(path);
477-
}
472+
if let Some(name) = path.file_name().and_then(|s| s.to_str())
473+
&& (name == filename
474+
|| (name.starts_with(&hashed_prefix) && name.ends_with(dll_suffix)))
475+
{
476+
return Some(path);
478477
}
479478
}
480479
}
@@ -580,12 +579,11 @@ fn workspace_root_dir() -> Option<PathBuf> {
580579

581580
loop {
582581
let candidate = path.join("Cargo.toml");
583-
if candidate.is_file() {
584-
if let Ok(contents) = fs::read_to_string(&candidate) {
585-
if contents.contains("[workspace]") {
586-
return Some(path.clone());
587-
}
588-
}
582+
if candidate.is_file()
583+
&& let Ok(contents) = fs::read_to_string(&candidate)
584+
&& contents.contains("[workspace]")
585+
{
586+
return Some(path.clone());
589587
}
590588

591589
if !path.pop() {

crates/cuda_std_macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cuda_std_macros"
33
version = "0.2.0"
4-
edition = "2021"
4+
edition = "2024"
55
license = "MIT OR Apache-2.0"
66
description = "Macros for cuda_std"
77
repository = "https://github.com/Rust-GPU/rust-cuda"

crates/cuda_std_macros/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use proc_macro::TokenStream;
22
use proc_macro2::Span;
3-
use quote::{quote_spanned, ToTokens};
3+
use quote::{ToTokens, quote_spanned};
44
use syn::{
5-
parse::Parse, parse_macro_input, parse_quote, punctuated::Punctuated, spanned::Spanned, Error,
6-
FnArg, Ident, ItemFn, ReturnType, Stmt, Token,
5+
Error, FnArg, Ident, ItemFn, ReturnType, Stmt, Token, parse::Parse, parse_macro_input,
6+
parse_quote, punctuated::Punctuated, spanned::Spanned,
77
};
88

99
/// Registers a function as a gpu kernel.
@@ -25,7 +25,7 @@ pub fn kernel(input: proc_macro::TokenStream, item: proc_macro::TokenStream) ->
2525
let _ = parse_macro_input!(input as KernelHints);
2626
let input = parse_macro_input!(cloned as proc_macro2::TokenStream);
2727
let mut item = parse_macro_input!(item as ItemFn);
28-
let no_mangle = parse_quote!(#[no_mangle]);
28+
let no_mangle = parse_quote!(#[unsafe(no_mangle)]);
2929
item.attrs.push(no_mangle);
3030
let internal = parse_quote!(#[cfg_attr(target_arch="nvptx64", nvvm_internal::kernel(#input))]);
3131
item.attrs.push(internal);

crates/cust_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cust_core"
33
version = "0.1.1"
4-
edition = "2021"
4+
edition = "2024"
55
license = "MIT OR Apache-2.0"
66
description = "Core library for cust that can be shared across CPU and GPU"
77
repository = "https://github.com/Rust-GPU/rust-cuda"

crates/cust_core/src/lib.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,36 +108,36 @@ pub mod _hidden {
108108
{
109109
}
110110
unsafe impl<
111-
A: DeviceCopy,
112-
B: DeviceCopy,
113-
C: DeviceCopy,
114-
D: DeviceCopy,
115-
E: DeviceCopy,
116-
F: DeviceCopy,
117-
> DeviceCopy for (A, B, C, D, E, F)
111+
A: DeviceCopy,
112+
B: DeviceCopy,
113+
C: DeviceCopy,
114+
D: DeviceCopy,
115+
E: DeviceCopy,
116+
F: DeviceCopy,
117+
> DeviceCopy for (A, B, C, D, E, F)
118118
{
119119
}
120120
unsafe impl<
121-
A: DeviceCopy,
122-
B: DeviceCopy,
123-
C: DeviceCopy,
124-
D: DeviceCopy,
125-
E: DeviceCopy,
126-
F: DeviceCopy,
127-
G: DeviceCopy,
128-
> DeviceCopy for (A, B, C, D, E, F, G)
121+
A: DeviceCopy,
122+
B: DeviceCopy,
123+
C: DeviceCopy,
124+
D: DeviceCopy,
125+
E: DeviceCopy,
126+
F: DeviceCopy,
127+
G: DeviceCopy,
128+
> DeviceCopy for (A, B, C, D, E, F, G)
129129
{
130130
}
131131
unsafe impl<
132-
A: DeviceCopy,
133-
B: DeviceCopy,
134-
C: DeviceCopy,
135-
D: DeviceCopy,
136-
E: DeviceCopy,
137-
F: DeviceCopy,
138-
G: DeviceCopy,
139-
H: DeviceCopy,
140-
> DeviceCopy for (A, B, C, D, E, F, G, H)
132+
A: DeviceCopy,
133+
B: DeviceCopy,
134+
C: DeviceCopy,
135+
D: DeviceCopy,
136+
E: DeviceCopy,
137+
F: DeviceCopy,
138+
G: DeviceCopy,
139+
H: DeviceCopy,
140+
> DeviceCopy for (A, B, C, D, E, F, G, H)
141141
{
142142
}
143143

crates/cust_derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "cust_derive"
33
version = "0.2.0"
44
authors = ["Brook Heisler <[email protected]>", "Riccardo D'Ambrosio <[email protected]>"]
5-
edition = "2021"
5+
edition = "2024"
66
license = "MIT OR Apache-2.0"
77
description = "Macros for cust"
88
repository = "https://github.com/Rust-GPU/rust-cuda"

crates/cust_derive/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ extern crate syn;
66

77
use proc_macro2::{Ident, Span, TokenStream};
88
use syn::{
9-
parse_str, Data, DataEnum, DataStruct, DataUnion, DeriveInput, Field, Fields, Generics,
10-
TypeParamBound,
9+
Data, DataEnum, DataStruct, DataUnion, DeriveInput, Field, Fields, Generics, TypeParamBound,
10+
parse_str,
1111
};
1212

1313
#[proc_macro_derive(DeviceCopyCore)]
1414
pub fn device_copy_core(input: BaseTokenStream) -> BaseTokenStream {
1515
let ast = syn::parse(input).unwrap();
16-
let gen = impl_device_copy(&ast, quote!(::cust_core::DeviceCopy));
17-
BaseTokenStream::from(gen)
16+
let code = impl_device_copy(&ast, quote!(::cust_core::DeviceCopy));
17+
BaseTokenStream::from(code)
1818
}
1919
#[proc_macro_derive(DeviceCopy)]
2020
pub fn device_copy(input: BaseTokenStream) -> BaseTokenStream {
2121
let ast = syn::parse(input).unwrap();
22-
let gen = impl_device_copy(&ast, quote!(::cust::memory::DeviceCopy));
23-
BaseTokenStream::from(gen)
22+
let code = impl_device_copy(&ast, quote!(::cust::memory::DeviceCopy));
23+
BaseTokenStream::from(code)
2424
}
2525

2626
use proc_macro::TokenStream as BaseTokenStream;

crates/gpu_rand/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "gpu_rand"
33
version = "0.1.3"
44
authors = ["The Rand Project Developers", "The Rust CUDA Project Developers"]
55
license = "MIT OR Apache-2.0"
6-
edition = "2021"
6+
edition = "2024"
77
description = "GPU-friendly random number generators for the Rust CUDA Project"
88
repository = "https://github.com/Rust-GPU/rust-cuda"
99
readme = "../../README.md"

crates/gpu_rand/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! assembly. However, it is supposed to also work on the CPU, allowing you to reuse the same random states across CPU and GPU.
66
//!
77
//! A lot of the initial code is taken from the [rust-random project](https://github.com/rust-random) and modified to make it able to
8-
//! pass to the GPU, as well as cleaning up certain things and updating it to edition 2021.
8+
//! pass to the GPU, as well as cleaning up certain things and updating it to edition 2024.
99
//! The following generators are implemented:
1010
//!
1111

0 commit comments

Comments
 (0)