Note what qualifier
This commit is contained in:
parent
c085071631
commit
d6391d5d4d
@ -66,9 +66,9 @@ ast_passes_equality_in_where = equality constraints are not yet supported in `wh
|
|||||||
|
|
||||||
ast_passes_extern_block_suggestion = if you meant to declare an externally defined function, use an `extern` block
|
ast_passes_extern_block_suggestion = if you meant to declare an externally defined function, use an `extern` block
|
||||||
|
|
||||||
ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have qualifiers
|
ast_passes_extern_fn_qualifiers = functions in `extern` blocks cannot have `{$kw}` qualifier
|
||||||
.label = in this `extern` block
|
.label = in this `extern` block
|
||||||
.suggestion = remove this qualifier
|
.suggestion = remove the `{$kw}` qualifier
|
||||||
|
|
||||||
ast_passes_extern_invalid_safety = items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
ast_passes_extern_invalid_safety = items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
||||||
.suggestion = add `unsafe` to this `extern` block
|
.suggestion = add `unsafe` to this `extern` block
|
||||||
|
@ -561,21 +561,24 @@ fn check_foreign_fn_headerless(
|
|||||||
// Deconstruct to ensure exhaustiveness
|
// Deconstruct to ensure exhaustiveness
|
||||||
FnHeader { safety: _, coroutine_kind, constness, ext }: FnHeader,
|
FnHeader { safety: _, coroutine_kind, constness, ext }: FnHeader,
|
||||||
) {
|
) {
|
||||||
let report_err = |span| {
|
let report_err = |span, kw| {
|
||||||
self.dcx()
|
self.dcx().emit_err(errors::FnQualifierInExtern {
|
||||||
.emit_err(errors::FnQualifierInExtern { span, block: self.current_extern_span() });
|
span,
|
||||||
|
kw,
|
||||||
|
block: self.current_extern_span(),
|
||||||
|
});
|
||||||
};
|
};
|
||||||
match coroutine_kind {
|
match coroutine_kind {
|
||||||
Some(knd) => report_err(knd.span()),
|
Some(kind) => report_err(kind.span(), kind.as_str()),
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
match constness {
|
match constness {
|
||||||
Const::Yes(span) => report_err(span),
|
Const::Yes(span) => report_err(span, "const"),
|
||||||
Const::No => (),
|
Const::No => (),
|
||||||
}
|
}
|
||||||
match ext {
|
match ext {
|
||||||
Extern::None => (),
|
Extern::None => (),
|
||||||
Extern::Implicit(span) | Extern::Explicit(_, span) => report_err(span),
|
Extern::Implicit(span) | Extern::Explicit(_, span) => report_err(span, "extern"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,6 +295,7 @@ pub(crate) struct FnQualifierInExtern {
|
|||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[label]
|
#[label]
|
||||||
pub block: Span,
|
pub block: Span,
|
||||||
|
pub kw: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
2
tests/ui/extern/issue-95829.rs
vendored
2
tests/ui/extern/issue-95829.rs
vendored
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
extern {
|
extern {
|
||||||
async fn L() { //~ ERROR: incorrect function inside `extern` block
|
async fn L() { //~ ERROR: incorrect function inside `extern` block
|
||||||
//~^ ERROR: functions in `extern` blocks cannot have qualifiers
|
//~^ ERROR: functions in `extern` blocks cannot have `async` qualifier
|
||||||
async fn M() {}
|
async fn M() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
tests/ui/extern/issue-95829.stderr
vendored
4
tests/ui/extern/issue-95829.stderr
vendored
@ -15,13 +15,13 @@ LL | | }
|
|||||||
= help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
|
= help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
|
||||||
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
|
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
|
||||||
|
|
||||||
error: functions in `extern` blocks cannot have qualifiers
|
error: functions in `extern` blocks cannot have `async` qualifier
|
||||||
--> $DIR/issue-95829.rs:4:5
|
--> $DIR/issue-95829.rs:4:5
|
||||||
|
|
|
|
||||||
LL | extern {
|
LL | extern {
|
||||||
| ------ in this `extern` block
|
| ------ in this `extern` block
|
||||||
LL | async fn L() {
|
LL | async fn L() {
|
||||||
| ^^^^^ help: remove this qualifier
|
| ^^^^^ help: remove the `async` qualifier
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -41,15 +41,15 @@ extern "C" fn fi4() {} // OK.
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
async fn fe1(); //~ ERROR functions in `extern` blocks cannot have qualifiers
|
async fn fe1(); //~ ERROR functions in `extern` blocks cannot
|
||||||
unsafe fn fe2(); //~ ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
unsafe fn fe2(); //~ ERROR items in `extern` blocks without an `unsafe` qualifier cannot
|
||||||
const fn fe3(); //~ ERROR functions in `extern` blocks cannot have qualifiers
|
const fn fe3(); //~ ERROR functions in `extern` blocks cannot
|
||||||
extern "C" fn fe4(); //~ ERROR functions in `extern` blocks cannot have qualifiers
|
extern "C" fn fe4(); //~ ERROR functions in `extern` blocks cannot
|
||||||
const async unsafe extern "C" fn fe5();
|
const async unsafe extern "C" fn fe5();
|
||||||
//~^ ERROR functions in `extern` blocks
|
//~^ ERROR functions in `extern` blocks
|
||||||
//~| ERROR functions in `extern` blocks
|
//~| ERROR functions in `extern` blocks
|
||||||
//~| ERROR functions in `extern` blocks
|
//~| ERROR functions in `extern` blocks
|
||||||
//~| ERROR functions cannot be both `const` and `async`
|
//~| ERROR functions cannot be both `const` and `async`
|
||||||
//~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
//~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot have
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,13 +70,13 @@ LL | const async unsafe extern "C" fn fi5() {}
|
|||||||
| | `async` because of this
|
| | `async` because of this
|
||||||
| `const` because of this
|
| `const` because of this
|
||||||
|
|
||||||
error: functions in `extern` blocks cannot have qualifiers
|
error: functions in `extern` blocks cannot have `async` qualifier
|
||||||
--> $DIR/fn-header-semantic-fail.rs:44:9
|
--> $DIR/fn-header-semantic-fail.rs:44:9
|
||||||
|
|
|
|
||||||
LL | extern "C" {
|
LL | extern "C" {
|
||||||
| ---------- in this `extern` block
|
| ---------- in this `extern` block
|
||||||
LL | async fn fe1();
|
LL | async fn fe1();
|
||||||
| ^^^^^ help: remove this qualifier
|
| ^^^^^ help: remove the `async` qualifier
|
||||||
|
|
||||||
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
||||||
--> $DIR/fn-header-semantic-fail.rs:45:9
|
--> $DIR/fn-header-semantic-fail.rs:45:9
|
||||||
@ -89,50 +89,50 @@ help: add `unsafe` to this `extern` block
|
|||||||
LL | unsafe extern "C" {
|
LL | unsafe extern "C" {
|
||||||
| ++++++
|
| ++++++
|
||||||
|
|
||||||
error: functions in `extern` blocks cannot have qualifiers
|
error: functions in `extern` blocks cannot have `const` qualifier
|
||||||
--> $DIR/fn-header-semantic-fail.rs:46:9
|
--> $DIR/fn-header-semantic-fail.rs:46:9
|
||||||
|
|
|
|
||||||
LL | extern "C" {
|
LL | extern "C" {
|
||||||
| ---------- in this `extern` block
|
| ---------- in this `extern` block
|
||||||
...
|
...
|
||||||
LL | const fn fe3();
|
LL | const fn fe3();
|
||||||
| ^^^^^ help: remove this qualifier
|
| ^^^^^ help: remove the `const` qualifier
|
||||||
|
|
||||||
error: functions in `extern` blocks cannot have qualifiers
|
error: functions in `extern` blocks cannot have `extern` qualifier
|
||||||
--> $DIR/fn-header-semantic-fail.rs:47:9
|
--> $DIR/fn-header-semantic-fail.rs:47:9
|
||||||
|
|
|
|
||||||
LL | extern "C" {
|
LL | extern "C" {
|
||||||
| ---------- in this `extern` block
|
| ---------- in this `extern` block
|
||||||
...
|
...
|
||||||
LL | extern "C" fn fe4();
|
LL | extern "C" fn fe4();
|
||||||
| ^^^^^^^^^^ help: remove this qualifier
|
| ^^^^^^^^^^ help: remove the `extern` qualifier
|
||||||
|
|
||||||
error: functions in `extern` blocks cannot have qualifiers
|
error: functions in `extern` blocks cannot have `async` qualifier
|
||||||
--> $DIR/fn-header-semantic-fail.rs:48:15
|
--> $DIR/fn-header-semantic-fail.rs:48:15
|
||||||
|
|
|
|
||||||
LL | extern "C" {
|
LL | extern "C" {
|
||||||
| ---------- in this `extern` block
|
| ---------- in this `extern` block
|
||||||
...
|
...
|
||||||
LL | const async unsafe extern "C" fn fe5();
|
LL | const async unsafe extern "C" fn fe5();
|
||||||
| ^^^^^ help: remove this qualifier
|
| ^^^^^ help: remove the `async` qualifier
|
||||||
|
|
||||||
error: functions in `extern` blocks cannot have qualifiers
|
error: functions in `extern` blocks cannot have `const` qualifier
|
||||||
--> $DIR/fn-header-semantic-fail.rs:48:9
|
--> $DIR/fn-header-semantic-fail.rs:48:9
|
||||||
|
|
|
|
||||||
LL | extern "C" {
|
LL | extern "C" {
|
||||||
| ---------- in this `extern` block
|
| ---------- in this `extern` block
|
||||||
...
|
...
|
||||||
LL | const async unsafe extern "C" fn fe5();
|
LL | const async unsafe extern "C" fn fe5();
|
||||||
| ^^^^^ help: remove this qualifier
|
| ^^^^^ help: remove the `const` qualifier
|
||||||
|
|
||||||
error: functions in `extern` blocks cannot have qualifiers
|
error: functions in `extern` blocks cannot have `extern` qualifier
|
||||||
--> $DIR/fn-header-semantic-fail.rs:48:28
|
--> $DIR/fn-header-semantic-fail.rs:48:28
|
||||||
|
|
|
|
||||||
LL | extern "C" {
|
LL | extern "C" {
|
||||||
| ---------- in this `extern` block
|
| ---------- in this `extern` block
|
||||||
...
|
...
|
||||||
LL | const async unsafe extern "C" fn fe5();
|
LL | const async unsafe extern "C" fn fe5();
|
||||||
| ^^^^^^^^^^ help: remove this qualifier
|
| ^^^^^^^^^^ help: remove the `extern` qualifier
|
||||||
|
|
||||||
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
||||||
--> $DIR/fn-header-semantic-fail.rs:48:9
|
--> $DIR/fn-header-semantic-fail.rs:48:9
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
const fn foo();
|
const fn foo();
|
||||||
//~^ ERROR functions in `extern` blocks cannot have qualifiers
|
//~^ ERROR functions in `extern` blocks cannot
|
||||||
const unsafe fn bar();
|
const unsafe fn bar();
|
||||||
//~^ ERROR functions in `extern` blocks cannot have qualifiers
|
//~^ ERROR functions in `extern` blocks cannot
|
||||||
//~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
//~| ERROR items in `extern` blocks without an `unsafe` qualifier cannot
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
error: functions in `extern` blocks cannot have qualifiers
|
error: functions in `extern` blocks cannot have `const` qualifier
|
||||||
--> $DIR/no-const-fn-in-extern-block.rs:2:5
|
--> $DIR/no-const-fn-in-extern-block.rs:2:5
|
||||||
|
|
|
|
||||||
LL | extern "C" {
|
LL | extern "C" {
|
||||||
| ---------- in this `extern` block
|
| ---------- in this `extern` block
|
||||||
LL | const fn foo();
|
LL | const fn foo();
|
||||||
| ^^^^^ help: remove this qualifier
|
| ^^^^^ help: remove the `const` qualifier
|
||||||
|
|
||||||
error: functions in `extern` blocks cannot have qualifiers
|
error: functions in `extern` blocks cannot have `const` qualifier
|
||||||
--> $DIR/no-const-fn-in-extern-block.rs:4:5
|
--> $DIR/no-const-fn-in-extern-block.rs:4:5
|
||||||
|
|
|
|
||||||
LL | extern "C" {
|
LL | extern "C" {
|
||||||
| ---------- in this `extern` block
|
| ---------- in this `extern` block
|
||||||
...
|
...
|
||||||
LL | const unsafe fn bar();
|
LL | const unsafe fn bar();
|
||||||
| ^^^^^ help: remove this qualifier
|
| ^^^^^ help: remove the `const` qualifier
|
||||||
|
|
||||||
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
error: items in `extern` blocks without an `unsafe` qualifier cannot have safety qualifiers
|
||||||
--> $DIR/no-const-fn-in-extern-block.rs:4:5
|
--> $DIR/no-const-fn-in-extern-block.rs:4:5
|
||||||
|
Loading…
Reference in New Issue
Block a user