parse: use parse_item_common in parse_foreign_item.
This commit is contained in:
parent
a920a05603
commit
a63f35daee
14 changed files with 392 additions and 70 deletions
|
|
@ -1,5 +1,6 @@
|
|||
// Test parsing for `default` where it doesn't belong.
|
||||
// Specifically, we are interested in kinds of items or items in certain contexts.
|
||||
// Also test item kinds in `extern` blocks and associated contexts which are not allowed there.
|
||||
|
||||
fn main() {}
|
||||
|
||||
|
|
@ -24,3 +25,38 @@ mod free_items {
|
|||
default macro foo {} //~ ERROR item cannot be `default`
|
||||
default macro_rules! foo {} //~ ERROR item cannot be `default`
|
||||
}
|
||||
|
||||
#[cfg(FALSE)]
|
||||
extern "C" {
|
||||
default extern crate foo; //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default use foo; //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default static foo: u8; //~ ERROR item cannot be `default`
|
||||
default const foo: u8; //~ ERROR item cannot be `default`
|
||||
//~^ ERROR extern items cannot be `const`
|
||||
default fn foo(); //~ ERROR item cannot be `default`
|
||||
default mod foo {} //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default extern "C" {} //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default type foo = u8; //~ ERROR item cannot be `default`
|
||||
default enum foo {} //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default struct foo {} //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default union foo {} //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default trait foo {} //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default trait foo = Ord; //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default impl foo {}
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default!();
|
||||
default::foo::bar!();
|
||||
default macro foo {} //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
default macro_rules! foo {} //~ ERROR item cannot be `default`
|
||||
//~^ ERROR item kind not supported in `extern` block
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:8:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:9:5
|
||||
|
|
||||
LL | default extern crate foo;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -7,7 +7,7 @@ LL | default extern crate foo;
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:9:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:10:5
|
||||
|
|
||||
LL | default use foo;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -15,7 +15,7 @@ LL | default use foo;
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:10:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:11:5
|
||||
|
|
||||
LL | default static foo: u8;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -23,7 +23,7 @@ LL | default static foo: u8;
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:11:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:12:5
|
||||
|
|
||||
LL | default const foo: u8;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -31,7 +31,7 @@ LL | default const foo: u8;
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:12:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:13:5
|
||||
|
|
||||
LL | default fn foo();
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -39,7 +39,7 @@ LL | default fn foo();
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:13:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:14:5
|
||||
|
|
||||
LL | default mod foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -47,7 +47,7 @@ LL | default mod foo {}
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:14:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:15:5
|
||||
|
|
||||
LL | default extern "C" {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -55,7 +55,7 @@ LL | default extern "C" {}
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:15:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:16:5
|
||||
|
|
||||
LL | default type foo = u8;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -63,7 +63,7 @@ LL | default type foo = u8;
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:16:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:17:5
|
||||
|
|
||||
LL | default enum foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -71,7 +71,7 @@ LL | default enum foo {}
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:17:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:18:5
|
||||
|
|
||||
LL | default struct foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -79,7 +79,7 @@ LL | default struct foo {}
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:18:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:19:5
|
||||
|
|
||||
LL | default union foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -87,7 +87,7 @@ LL | default union foo {}
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:19:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:20:5
|
||||
|
|
||||
LL | default trait foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -95,7 +95,7 @@ LL | default trait foo {}
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:20:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:21:5
|
||||
|
|
||||
LL | default trait foo = Ord;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -103,7 +103,7 @@ LL | default trait foo = Ord;
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:24:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:25:5
|
||||
|
|
||||
LL | default macro foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
@ -111,12 +111,214 @@ LL | default macro foo {}
|
|||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:25:5
|
||||
--> $DIR/default-on-wrong-item-kind.rs:26:5
|
||||
|
|
||||
LL | default macro_rules! foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:31:5
|
||||
|
|
||||
LL | default extern crate foo;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:31:5
|
||||
|
|
||||
LL | default extern crate foo;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:33:5
|
||||
|
|
||||
LL | default use foo;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:33:5
|
||||
|
|
||||
LL | default use foo;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:35:5
|
||||
|
|
||||
LL | default static foo: u8;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:36:5
|
||||
|
|
||||
LL | default const foo: u8;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: extern items cannot be `const`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:36:19
|
||||
|
|
||||
LL | default const foo: u8;
|
||||
| --------------^^^
|
||||
| |
|
||||
| help: try using a static value: `static`
|
||||
|
|
||||
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:38:5
|
||||
|
|
||||
LL | default fn foo();
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:39:5
|
||||
|
|
||||
LL | default mod foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:39:5
|
||||
|
|
||||
LL | default mod foo {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:41:5
|
||||
|
|
||||
LL | default extern "C" {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:41:5
|
||||
|
|
||||
LL | default extern "C" {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:43:5
|
||||
|
|
||||
LL | default type foo = u8;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:44:5
|
||||
|
|
||||
LL | default enum foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:44:5
|
||||
|
|
||||
LL | default enum foo {}
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:46:5
|
||||
|
|
||||
LL | default struct foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:46:5
|
||||
|
|
||||
LL | default struct foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:48:5
|
||||
|
|
||||
LL | default union foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:48:5
|
||||
|
|
||||
LL | default union foo {}
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:50:5
|
||||
|
|
||||
LL | default trait foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:50:5
|
||||
|
|
||||
LL | default trait foo {}
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:52:5
|
||||
|
|
||||
LL | default trait foo = Ord;
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:52:5
|
||||
|
|
||||
LL | default trait foo = Ord;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:54:5
|
||||
|
|
||||
LL | default impl foo {}
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:58:5
|
||||
|
|
||||
LL | default macro foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:58:5
|
||||
|
|
||||
LL | default macro foo {}
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item cannot be `default`
|
||||
--> $DIR/default-on-wrong-item-kind.rs:60:5
|
||||
|
|
||||
LL | default macro_rules! foo {}
|
||||
| ^^^^^^^ `default` because of this
|
||||
|
|
||||
= note: only associated `fn`, `const`, and `type` items can be `default`
|
||||
|
||||
error: item kind not supported in `extern` block
|
||||
--> $DIR/default-on-wrong-item-kind.rs:60:5
|
||||
|
|
||||
LL | default macro_rules! foo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 43 previous errors
|
||||
|
||||
|
|
|
|||
8
src/test/ui/parser/default-unmatched-extern.rs
Normal file
8
src/test/ui/parser/default-unmatched-extern.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fn main() {}
|
||||
|
||||
extern "C" {
|
||||
default!(); //~ ERROR cannot find macro `default` in this scope
|
||||
default do
|
||||
//~^ ERROR unmatched `default`
|
||||
//~| ERROR non-item in item list
|
||||
}
|
||||
26
src/test/ui/parser/default-unmatched-extern.stderr
Normal file
26
src/test/ui/parser/default-unmatched-extern.stderr
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
error: unmatched `default`
|
||||
--> $DIR/default-unmatched-extern.rs:5:5
|
||||
|
|
||||
LL | default do
|
||||
| ^^^^^^^ the unmatched `default`
|
||||
|
||||
error: non-item in item list
|
||||
--> $DIR/default-unmatched-extern.rs:5:13
|
||||
|
|
||||
LL | extern "C" {
|
||||
| - item list starts here
|
||||
LL | default!();
|
||||
LL | default do
|
||||
| ^^ non-item starts here
|
||||
...
|
||||
LL | }
|
||||
| - item list ends here
|
||||
|
||||
error: cannot find macro `default` in this scope
|
||||
--> $DIR/default-unmatched-extern.rs:4:5
|
||||
|
|
||||
LL | default!();
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
@ -2,5 +2,6 @@ fn main() {}
|
|||
|
||||
extern {
|
||||
pub pub fn foo();
|
||||
//~^ ERROR missing `fn`, `type`, `const`, or `static` for item declaration
|
||||
//~^ ERROR unmatched visibility `pub`
|
||||
//~| ERROR non-item in item list
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,21 @@
|
|||
error: missing `fn`, `type`, `const`, or `static` for item declaration
|
||||
--> $DIR/duplicate-visibility.rs:4:8
|
||||
error: unmatched visibility `pub`
|
||||
--> $DIR/duplicate-visibility.rs:4:5
|
||||
|
|
||||
LL | pub pub fn foo();
|
||||
| ^ missing `fn`, `type`, `const`, or `static`
|
||||
| ^^^ the unmatched visibility
|
||||
|
|
||||
= help: you likely meant to define an item, e.g., `pub fn foo() {}`
|
||||
|
||||
error: aborting due to previous error
|
||||
error: non-item in item list
|
||||
--> $DIR/duplicate-visibility.rs:4:9
|
||||
|
|
||||
LL | extern {
|
||||
| - item list starts here
|
||||
LL | pub pub fn foo();
|
||||
| ^^^ non-item starts here
|
||||
...
|
||||
LL | }
|
||||
| - item list ends here
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
extern {
|
||||
//~^ ERROR missing `fn`, `type`, `const`, or `static` for item declaration
|
||||
f();
|
||||
f(); //~ ERROR expected one of `!` or `::`, found `(`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
error: missing `fn`, `type`, `const`, or `static` for item declaration
|
||||
--> $DIR/extern-no-fn.rs:1:9
|
||||
error: expected one of `!` or `::`, found `(`
|
||||
--> $DIR/extern-no-fn.rs:2:6
|
||||
|
|
||||
LL | extern {
|
||||
| _________^
|
||||
LL | |
|
||||
LL | | f();
|
||||
| |____^ missing `fn`, `type`, `const`, or `static`
|
||||
LL | f();
|
||||
| ^ expected one of `!` or `::`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ extern {
|
|||
//~^ ERROR extern items cannot be `const`
|
||||
const B: isize = 42;
|
||||
//~^ ERROR extern items cannot be `const`
|
||||
//~| ERROR incorrect `static` inside `extern` block
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,5 +18,18 @@ LL | const B: isize = 42;
|
|||
|
|
||||
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: incorrect `static` inside `extern` block
|
||||
--> $DIR/foreign-const-semantic-fail.rs:6:11
|
||||
|
|
||||
LL | extern {
|
||||
| ------ `extern` blocks define existing foreign statics and statics inside of them cannot have a body
|
||||
...
|
||||
LL | const B: isize = 42;
|
||||
| ^ -- the invalid body
|
||||
| |
|
||||
| cannot have a body
|
||||
|
|
||||
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue