-
Notifications
You must be signed in to change notification settings - Fork 14k
lint(unsafe_code): exclude unsafe declarations from lint coverage #148651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Unsafe declarations of traits, functions, methods, or extern blocks cannot cause undefined behavior by themselves — only unsafe blocks or implementations of unsafe traits can. The `unsafe_code` lint previously applied to these declarations, preventing, for example, declarations of `extern "C"` blocks. See rust-lang#108926. This change removes all such unsafe declarations from `unsafe_code` coverage. However, to maintain soundness, unsafe functions *with bodies* are only allowed when `unsafe_op_in_unsafe_fn` is set to `forbid`. This ensures unsafe operations inside such functions require an `unsafe` block. Declarations of unsafe functions *without bodies* (e.g., in traits) are always allowed. Closes rust-lang#108926
|
rustbot has assigned @petrochenkov. Use |
|
At least for extern blocks, that is not correct. The mere presence of an incorrect extern block can cause UB. See #46188. |
This comment has been minimized.
This comment has been minimized.
Indeed, my bad, I've rolled back this part. |
Unsafe declarations of traits, functions, methods,
or extern blockscannot cause undefined behavior by themselves — only unsafe blocks or implementations of unsafe traits can.The
unsafe_codelint previously applied to these declarations, preventing, for example, declarations ofextern "C"blocks. See #108926.This change removes all such unsafe declarations from
unsafe_codecoverage.However, to maintain soundness, unsafe functions with bodies are only allowed when
unsafe_op_in_unsafe_fnis set toforbid. This ensures unsafe operations inside such functions require anunsafeblock. Declarations of unsafe functions without bodies (e.g., in traits) are always allowed.Closes #108926