-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Description
#![forbid(unsafe_op_in_unsafe_fn)]
#![forbid(unsafe_code)]
trait Foo {
unsafe fn dangerous();
}
struct SafeImpl;
impl Foo for SafeImpl {
unsafe fn dangerous() {
println!("this is safe!");
}
}
With forbid(unsafe_op_in_unsafe_fn)
, an unsafe fn
's body in principle no longer has an implicit unsafe
block. So, unsafe_code
should not trigger on an unsafe fn
alone: there is not necessarily any unsafe code inside!
This has practical effect. Consider one crate defining interfaces with unsafe methods (e.g. representing an OS API). Another crate wants to create mock implementations of these interfaces that are 100% safe. While any crate consuming these mocks will necessarily contain unsafe {...}
blocks, it is nice for the test support crate to declare it itself has only safe code.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team