Skip to content

Incorrect help suggestion in "unsafe attribute used without unsafe" error #149756

@nnethercote

Description

@nnethercote

I am upgrading the editions used in github.com/rust-gpu/rust-cuda. When I upgrade cuda_std_macros from 2018 to 2024 with this patch:

diff --git a/crates/cuda_std_macros/Cargo.toml b/crates/cuda_std_macros/Cargo.toml
index 4557dcf..1fc98d1 100644
--- a/crates/cuda_std_macros/Cargo.toml
+++ b/crates/cuda_std_macros/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "cuda_std_macros"
 version = "0.2.0"
-edition = "2018"
+edition = "2024"
 license = "MIT OR Apache-2.0"
 description = "Macros for cuda_std"
 repository = "https://github.com/Rust-GPU/rust-cuda"

and then build rust-cuda with cargo build I get warnings like this:

error: unsafe attribute used without unsafe
 --> examples/vecadd/kernels/src/lib.rs:3:1
  |
3 | #[kernel]
  | ^^^^^^^^^ usage of unsafe attribute
  |
  = note: this error originates in the attribute macro `kernel` (in Nightly builds, run with -Z macro-backtrace for more info)
help: wrap the attribute in `unsafe(...)`
  |
3 | unsafe(#[kernel])
  | +++++++         +

The suggestion unsafe(#[kernel]) is bogus. At first I thought it should instead say #[unsafe(kernel)], but that is also bogus. The real issue is that #[kernel] produces code that uses #[no_mangle], and the real fix is to change that (inside the macro) to #[unsafe(no_mangle)]. It's probably difficult to explain that in the error message, but in lieu of that it would be nice if the bogus help: was omitted.

Metadata

Metadata

Assignees

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2024Area: The 2024 editionA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.F-unsafe_attributes`#![feature(unsafe_attributes)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions