Fix bad replacement for unsafe extern block suggestion
This commit is contained in:
parent
c3d7fb3985
commit
0addda6578
10 changed files with 75 additions and 26 deletions
|
@ -464,7 +464,7 @@ impl<'a> AstValidator<'a> {
|
|||
{
|
||||
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
|
||||
item_span: span,
|
||||
block: self.current_extern_span(),
|
||||
block: self.current_extern_span().shrink_to_lo(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ pub enum ExternBlockSuggestion {
|
|||
pub struct InvalidSafetyOnExtern {
|
||||
#[primary_span]
|
||||
pub item_span: Span,
|
||||
#[suggestion(code = "", applicability = "maybe-incorrect")]
|
||||
#[suggestion(code = "unsafe ", applicability = "machine-applicable", style = "verbose")]
|
||||
pub block: Span,
|
||||
}
|
||||
|
||||
|
|
|
@ -81,11 +81,13 @@ LL | async fn fe1();
|
|||
error: items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
--> $DIR/fn-header-semantic-fail.rs:47:9
|
||||
|
|
||||
LL | extern "C" {
|
||||
| ---------- help: add unsafe to this `extern` block
|
||||
LL | async fn fe1();
|
||||
LL | unsafe fn fe2();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add unsafe to this `extern` block
|
||||
|
|
||||
LL | unsafe extern "C" {
|
||||
| ++++++
|
||||
|
||||
error: functions in `extern` blocks cannot have qualifiers
|
||||
--> $DIR/fn-header-semantic-fail.rs:48:9
|
||||
|
@ -135,11 +137,13 @@ LL | const async unsafe extern "C" fn fe5();
|
|||
error: items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
--> $DIR/fn-header-semantic-fail.rs:50:9
|
||||
|
|
||||
LL | extern "C" {
|
||||
| ---------- help: add unsafe to this `extern` block
|
||||
...
|
||||
LL | const async unsafe extern "C" fn fe5();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add unsafe to this `extern` block
|
||||
|
|
||||
LL | unsafe extern "C" {
|
||||
| ++++++
|
||||
|
||||
error: functions cannot be both `const` and `async`
|
||||
--> $DIR/fn-header-semantic-fail.rs:50:9
|
||||
|
|
|
@ -18,11 +18,13 @@ LL | const unsafe fn bar();
|
|||
error: items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
--> $DIR/no-const-fn-in-extern-block.rs:4:5
|
||||
|
|
||||
LL | extern "C" {
|
||||
| ---------- help: add unsafe to this `extern` block
|
||||
...
|
||||
LL | const unsafe fn bar();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add unsafe to this `extern` block
|
||||
|
|
||||
LL | unsafe extern "C" {
|
||||
| ++++++
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
@ -13,11 +13,13 @@ LL | extern "C" unsafe {
|
|||
error: items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
--> $DIR/unsafe-foreign-mod-2.rs:4:5
|
||||
|
|
||||
LL | extern "C" unsafe {
|
||||
| ----------------- help: add unsafe to this `extern` block
|
||||
...
|
||||
LL | unsafe fn foo();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add unsafe to this `extern` block
|
||||
|
|
||||
LL | unsafe extern "C" unsafe {
|
||||
| ++++++
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
error: items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
|
||||
|
|
||||
LL | extern "C" {
|
||||
| ---------- help: add unsafe to this `extern` block
|
||||
LL |
|
||||
LL | safe static TEST1: i32;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add unsafe to this `extern` block
|
||||
|
|
||||
LL | unsafe extern "C" {
|
||||
| ++++++
|
||||
|
||||
error: items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:12:5
|
||||
|
|
||||
LL | extern "C" {
|
||||
| ---------- help: add unsafe to this `extern` block
|
||||
...
|
||||
LL | safe fn test1(i: i32);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add unsafe to this `extern` block
|
||||
|
|
||||
LL | unsafe extern "C" {
|
||||
| ++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -13,20 +13,24 @@ LL | | }
|
|||
error: items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:10:5
|
||||
|
|
||||
LL | extern "C" {
|
||||
| ---------- help: add unsafe to this `extern` block
|
||||
LL |
|
||||
LL | safe static TEST1: i32;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add unsafe to this `extern` block
|
||||
|
|
||||
LL | unsafe extern "C" {
|
||||
| ++++++
|
||||
|
||||
error: items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
--> $DIR/safe-unsafe-on-unadorned-extern-block.rs:12:5
|
||||
|
|
||||
LL | extern "C" {
|
||||
| ---------- help: add unsafe to this `extern` block
|
||||
...
|
||||
LL | safe fn test1(i: i32);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add unsafe to this `extern` block
|
||||
|
|
||||
LL | unsafe extern "C" {
|
||||
| ++++++
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
//@ run-rustfix
|
||||
|
||||
#![feature(unsafe_extern_blocks)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
unsafe extern "C" {
|
||||
unsafe fn foo(); //~ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,10 @@
|
|||
//@ run-rustfix
|
||||
|
||||
#![feature(unsafe_extern_blocks)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
extern "C" {
|
||||
unsafe fn foo(); //~ ERROR items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,13 @@
|
|||
error: items in unadorned `extern` blocks cannot have safety qualifiers
|
||||
--> $DIR/unsafe-on-extern-block-issue-126756.rs:7:5
|
||||
|
|
||||
LL | unsafe fn foo();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add unsafe to this `extern` block
|
||||
|
|
||||
LL | unsafe extern "C" {
|
||||
| ++++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
Add table
Reference in a new issue