summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2023-05-09 12:33:45 +0530
committerGitHub <noreply@github.com>2023-05-09 12:33:45 +0530
commitdbd090c655b4a4389fe51cbd3ad6f401e2953dbe (patch)
tree6de355c93e791dc65923c0cf69e80c267a799e33 /tests
parentff30b8cb7bcf3eaee7a5222c8ec35adba4a0d243 (diff)
parent83b4df4e611961373ffaf4bfcd9f8940a4f37c09 (diff)
downloadrust-dbd090c655b4a4389fe51cbd3ad6f401e2953dbe.tar.gz
Rollup merge of #110694 - est31:builtin, r=petrochenkov
Implement builtin # syntax and use it for offset_of!(...) Add `builtin #` syntax to the parser, as well as a generic infrastructure to support both item and expression position builtin syntaxes. The PR also uses this infrastructure for the implementation of the `offset_of!` macro, added by #106934. cc `@petrochenkov` `@DrMeepster` cc #110680 `builtin #` tracking issue cc #106655 `offset_of!` tracking issue
Diffstat (limited to 'tests')
-rw-r--r--tests/mir-opt/const_prop/offset_of.concrete.ConstProp.diff16
-rw-r--r--tests/mir-opt/const_prop/offset_of.generic.ConstProp.diff8
-rw-r--r--tests/ui/feature-gates/feature-gate-builtin_syntax.rs7
-rw-r--r--tests/ui/feature-gates/feature-gate-builtin_syntax.stderr12
-rw-r--r--tests/ui/offset-of/offset-of-arg-count.rs14
-rw-r--r--tests/ui/offset-of/offset-of-arg-count.stderr59
-rw-r--r--tests/ui/offset-of/offset-of-builtin.rs44
-rw-r--r--tests/ui/offset-of/offset-of-builtin.stderr65
-rw-r--r--tests/ui/offset-of/offset-of-dst-field.stderr3
-rw-r--r--tests/ui/offset-of/offset-of-unstable.stderr5
-rw-r--r--tests/ui/parser/builtin-syntax.rs9
-rw-r--r--tests/ui/parser/builtin-syntax.stderr14
12 files changed, 231 insertions, 25 deletions
diff --git a/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.diff b/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.diff
index e768a47a96d..e3757941c8c 100644
--- a/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.diff
+++ b/tests/mir-opt/const_prop/offset_of.concrete.ConstProp.diff
@@ -22,17 +22,17 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/offset_of.rs:+1:9: +1:10
-- _1 = OffsetOf(Alpha, [0]); // scope 0 at $DIR/offset_of.rs:+1:13: +1:33
-+ _1 = const 4_usize; // scope 0 at $DIR/offset_of.rs:+1:13: +1:33
+- _1 = OffsetOf(Alpha, [0]); // scope 0 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
++ _1 = const 4_usize; // scope 0 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
StorageLive(_2); // scope 1 at $DIR/offset_of.rs:+2:9: +2:10
-- _2 = OffsetOf(Alpha, [1]); // scope 1 at $DIR/offset_of.rs:+2:13: +2:33
-+ _2 = const 0_usize; // scope 1 at $DIR/offset_of.rs:+2:13: +2:33
+- _2 = OffsetOf(Alpha, [1]); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
++ _2 = const 0_usize; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
StorageLive(_3); // scope 2 at $DIR/offset_of.rs:+3:9: +3:11
-- _3 = OffsetOf(Alpha, [2, 0]); // scope 2 at $DIR/offset_of.rs:+3:14: +3:36
-+ _3 = const 2_usize; // scope 2 at $DIR/offset_of.rs:+3:14: +3:36
+- _3 = OffsetOf(Alpha, [2, 0]); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
++ _3 = const 2_usize; // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
StorageLive(_4); // scope 3 at $DIR/offset_of.rs:+4:9: +4:11
-- _4 = OffsetOf(Alpha, [2, 1]); // scope 3 at $DIR/offset_of.rs:+4:14: +4:36
-+ _4 = const 3_usize; // scope 3 at $DIR/offset_of.rs:+4:14: +4:36
+- _4 = OffsetOf(Alpha, [2, 1]); // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
++ _4 = const 3_usize; // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
_0 = const (); // scope 0 at $DIR/offset_of.rs:+0:15: +5:2
StorageDead(_4); // scope 3 at $DIR/offset_of.rs:+5:1: +5:2
StorageDead(_3); // scope 2 at $DIR/offset_of.rs:+5:1: +5:2
diff --git a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.diff b/tests/mir-opt/const_prop/offset_of.generic.ConstProp.diff
index e40fdbd79d8..4a655604cd1 100644
--- a/tests/mir-opt/const_prop/offset_of.generic.ConstProp.diff
+++ b/tests/mir-opt/const_prop/offset_of.generic.ConstProp.diff
@@ -22,13 +22,13 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/offset_of.rs:+1:9: +1:11
- _1 = OffsetOf(Gamma<T>, [0]); // scope 0 at $DIR/offset_of.rs:+1:14: +1:37
+ _1 = OffsetOf(Gamma<T>, [0]); // scope 0 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
StorageLive(_2); // scope 1 at $DIR/offset_of.rs:+2:9: +2:11
- _2 = OffsetOf(Gamma<T>, [1]); // scope 1 at $DIR/offset_of.rs:+2:14: +2:37
+ _2 = OffsetOf(Gamma<T>, [1]); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
StorageLive(_3); // scope 2 at $DIR/offset_of.rs:+3:9: +3:11
- _3 = OffsetOf(Delta<T>, [1]); // scope 2 at $DIR/offset_of.rs:+3:14: +3:37
+ _3 = OffsetOf(Delta<T>, [1]); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
StorageLive(_4); // scope 3 at $DIR/offset_of.rs:+4:9: +4:11
- _4 = OffsetOf(Delta<T>, [2]); // scope 3 at $DIR/offset_of.rs:+4:14: +4:37
+ _4 = OffsetOf(Delta<T>, [2]); // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
_0 = const (); // scope 0 at $DIR/offset_of.rs:+0:17: +5:2
StorageDead(_4); // scope 3 at $DIR/offset_of.rs:+5:1: +5:2
StorageDead(_3); // scope 2 at $DIR/offset_of.rs:+5:1: +5:2
diff --git a/tests/ui/feature-gates/feature-gate-builtin_syntax.rs b/tests/ui/feature-gates/feature-gate-builtin_syntax.rs
new file mode 100644
index 00000000000..832bb5a96bc
--- /dev/null
+++ b/tests/ui/feature-gates/feature-gate-builtin_syntax.rs
@@ -0,0 +1,7 @@
+struct Foo {
+ v: u8,
+ w: u8,
+}
+fn main() {
+ builtin # offset_of(Foo, v); //~ ERROR `builtin #` syntax is unstable
+}
diff --git a/tests/ui/feature-gates/feature-gate-builtin_syntax.stderr b/tests/ui/feature-gates/feature-gate-builtin_syntax.stderr
new file mode 100644
index 00000000000..3bc7848f66d
--- /dev/null
+++ b/tests/ui/feature-gates/feature-gate-builtin_syntax.stderr
@@ -0,0 +1,12 @@
+error[E0658]: `builtin #` syntax is unstable
+ --> $DIR/feature-gate-builtin_syntax.rs:6:15
+ |
+LL | builtin # offset_of(Foo, v);
+ | ^^^^^^^^^
+ |
+ = note: see issue #110680 <https://github.com/rust-lang/rust/issues/110680> for more information
+ = help: add `#![feature(builtin_syntax)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/offset-of/offset-of-arg-count.rs b/tests/ui/offset-of/offset-of-arg-count.rs
index 163b07454ec..5e66e33f8a2 100644
--- a/tests/ui/offset-of/offset-of-arg-count.rs
+++ b/tests/ui/offset-of/offset-of-arg-count.rs
@@ -3,7 +3,15 @@
use std::mem::offset_of;
fn main() {
- offset_of!(NotEnoughArguments); //~ ERROR expected one of
- offset_of!(NotEnoughArgumentsWithAComma, ); //~ ERROR expected 2 arguments
- offset_of!(Container, field, too many arguments); //~ ERROR expected 2 arguments
+ offset_of!(NotEnoughArguments); //~ ERROR unexpected end of macro invocation
+ offset_of!(NotEnoughArgumentsWithAComma, ); //~ ERROR unexpected end of macro invocation
+ offset_of!(Container, field, too many arguments); //~ ERROR no rules expected the token `too`
+ offset_of!(S, f); // compiles fine
+ offset_of!(S, f,); // also compiles fine
+ offset_of!(S, f.); //~ ERROR unexpected end of macro invocation
+ offset_of!(S, f.,); //~ ERROR expected identifier
+ offset_of!(S, f..); //~ ERROR no rules expected the token
+ offset_of!(S, f..,); //~ ERROR no rules expected the token
}
+
+struct S { f: u8, }
diff --git a/tests/ui/offset-of/offset-of-arg-count.stderr b/tests/ui/offset-of/offset-of-arg-count.stderr
index ebecc982c51..4275a89545f 100644
--- a/tests/ui/offset-of/offset-of-arg-count.stderr
+++ b/tests/ui/offset-of/offset-of-arg-count.stderr
@@ -1,20 +1,59 @@
-error: expected one of `!`, `(`, `+`, `,`, `::`, or `<`, found `<eof>`
- --> $DIR/offset-of-arg-count.rs:6:16
+error: unexpected end of macro invocation
+ --> $DIR/offset-of-arg-count.rs:6:34
|
LL | offset_of!(NotEnoughArguments);
- | ^^^^^^^^^^^^^^^^^^ expected one of `!`, `(`, `+`, `,`, `::`, or `<`
+ | ^ missing tokens in macro arguments
+ |
+note: while trying to match `,`
+ --> $SRC_DIR/core/src/mem/mod.rs:LL:COL
-error: expected 2 arguments
- --> $DIR/offset-of-arg-count.rs:7:5
+error: unexpected end of macro invocation
+ --> $DIR/offset-of-arg-count.rs:7:45
|
LL | offset_of!(NotEnoughArgumentsWithAComma, );
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^ missing tokens in macro arguments
+ |
+note: while trying to match meta-variable `$fields:tt`
+ --> $SRC_DIR/core/src/mem/mod.rs:LL:COL
-error: expected 2 arguments
- --> $DIR/offset-of-arg-count.rs:8:5
+error: no rules expected the token `too`
+ --> $DIR/offset-of-arg-count.rs:8:34
|
LL | offset_of!(Container, field, too many arguments);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^^ no rules expected this token in macro call
+ |
+ = note: while trying to match sequence end
+
+error: unexpected end of macro invocation
+ --> $DIR/offset-of-arg-count.rs:11:21
+ |
+LL | offset_of!(S, f.);
+ | ^ missing tokens in macro arguments
+ |
+note: while trying to match meta-variable `$fields:tt`
+ --> $SRC_DIR/core/src/mem/mod.rs:LL:COL
+
+error: expected identifier, found `,`
+ --> $DIR/offset-of-arg-count.rs:12:21
+ |
+LL | offset_of!(S, f.,);
+ | ^ expected identifier
+
+error: no rules expected the token `..`
+ --> $DIR/offset-of-arg-count.rs:13:20
+ |
+LL | offset_of!(S, f..);
+ | ^^ no rules expected this token in macro call
+ |
+ = note: while trying to match sequence start
+
+error: no rules expected the token `..`
+ --> $DIR/offset-of-arg-count.rs:14:20
+ |
+LL | offset_of!(S, f..,);
+ | ^^ no rules expected this token in macro call
+ |
+ = note: while trying to match sequence start
-error: aborting due to 3 previous errors
+error: aborting due to 7 previous errors
diff --git a/tests/ui/offset-of/offset-of-builtin.rs b/tests/ui/offset-of/offset-of-builtin.rs
new file mode 100644
index 00000000000..1be9899887b
--- /dev/null
+++ b/tests/ui/offset-of/offset-of-builtin.rs
@@ -0,0 +1,44 @@
+#![feature(builtin_syntax)]
+
+// For the exposed macro we already test these errors in the other files,
+// but this test helps to make sure the builtin construct also errors.
+// This has the same examples as offset-of-arg-count.rs
+
+fn main() {
+ builtin # offset_of(NotEnoughArguments); //~ ERROR expected one of
+}
+fn t1() {
+ // Already errored upon at the macro level. Yielding an error would require
+ // extra effort.
+ builtin # offset_of(NotEnoughArgumentsWithAComma, );
+}
+fn t2() {
+ builtin # offset_of(Container, field, too many arguments); //~ ERROR expected identifier, found
+ //~| ERROR found `,`
+ //~| ERROR found `many`
+ //~| ERROR found `arguments`
+}
+fn t3() {
+ builtin # offset_of(S, f); // compiles fine
+}
+fn t4() {
+ // Already errored upon at the macro level. Yielding an error would require
+ // extra effort.
+ builtin # offset_of(S, f);
+}
+fn t5() {
+ builtin # offset_of(S, f.); //~ ERROR expected identifier
+}
+fn t6() {
+ builtin # offset_of(S, f.,); //~ ERROR expected identifier
+}
+fn t7() {
+ builtin # offset_of(S, f..); //~ ERROR expected one of
+}
+fn t8() {
+ // Already errored upon at the macro level. Yielding an error would require
+ // extra effort.
+ builtin # offset_of(S, f..,);
+}
+
+struct S { f: u8, }
diff --git a/tests/ui/offset-of/offset-of-builtin.stderr b/tests/ui/offset-of/offset-of-builtin.stderr
new file mode 100644
index 00000000000..1a1f33cc613
--- /dev/null
+++ b/tests/ui/offset-of/offset-of-builtin.stderr
@@ -0,0 +1,65 @@
+error: expected one of `!`, `(`, `+`, `,`, `::`, or `<`, found `)`
+ --> $DIR/offset-of-builtin.rs:8:43
+ |
+LL | builtin # offset_of(NotEnoughArguments);
+ | ^ expected one of `!`, `(`, `+`, `,`, `::`, or `<`
+
+error: expected identifier, found `,`
+ --> $DIR/offset-of-builtin.rs:16:41
+ |
+LL | builtin # offset_of(Container, field, too many arguments);
+ | ^
+ | |
+ | expected identifier
+ | help: remove this comma
+
+error: expected one of `)` or `.`, found `,`
+ --> $DIR/offset-of-builtin.rs:16:41
+ |
+LL | builtin # offset_of(Container, field, too many arguments);
+ | ^
+ | |
+ | expected one of `)` or `.`
+ | help: missing `.`
+
+error: expected one of `)` or `.`, found `many`
+ --> $DIR/offset-of-builtin.rs:16:47
+ |
+LL | builtin # offset_of(Container, field, too many arguments);
+ | -^^^^ expected one of `)` or `.`
+ | |
+ | help: missing `.`
+
+error: expected one of `)` or `.`, found `arguments`
+ --> $DIR/offset-of-builtin.rs:16:52
+ |
+LL | builtin # offset_of(Container, field, too many arguments);
+ | -^^^^^^^^^ expected one of `)` or `.`
+ | |
+ | help: missing `.`
+
+error: expected identifier, found `)`
+ --> $DIR/offset-of-builtin.rs:30:30
+ |
+LL | builtin # offset_of(S, f.);
+ | ^ expected identifier
+
+error: expected identifier, found `,`
+ --> $DIR/offset-of-builtin.rs:33:30
+ |
+LL | builtin # offset_of(S, f.,);
+ | ^ expected identifier
+
+error: expected one of `)` or `.`, found `..`
+ --> $DIR/offset-of-builtin.rs:36:29
+ |
+LL | builtin # offset_of(S, f..);
+ | ^^ expected one of `)` or `.`
+ |
+help: if you meant to bind the contents of the rest of the array pattern into `f`, use `@`
+ |
+LL | builtin # offset_of(S, f @ ..);
+ | +
+
+error: aborting due to 8 previous errors
+
diff --git a/tests/ui/offset-of/offset-of-dst-field.stderr b/tests/ui/offset-of/offset-of-dst-field.stderr
index 8e88015b07a..e6e0f499236 100644
--- a/tests/ui/offset-of/offset-of-dst-field.stderr
+++ b/tests/ui/offset-of/offset-of-dst-field.stderr
@@ -5,6 +5,7 @@ LL | offset_of!(Alpha, z);
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
+ = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
--> $DIR/offset-of-dst-field.rs:31:5
@@ -13,6 +14,7 @@ LL | offset_of!(Beta, z);
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Trait + 'static)`
+ = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the size for values of type `Extern` cannot be known at compilation time
--> $DIR/offset-of-dst-field.rs:32:5
@@ -21,6 +23,7 @@ LL | offset_of!(Gamma, z);
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `Extern`
+ = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors
diff --git a/tests/ui/offset-of/offset-of-unstable.stderr b/tests/ui/offset-of/offset-of-unstable.stderr
index 25811a061d7..c39882519a5 100644
--- a/tests/ui/offset-of/offset-of-unstable.stderr
+++ b/tests/ui/offset-of/offset-of-unstable.stderr
@@ -33,6 +33,7 @@ LL | | );
| |_____^
|
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
+ = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0658]: use of unstable library feature 'unstable_test_feature'
--> $DIR/offset-of-unstable.rs:18:5
@@ -41,6 +42,7 @@ LL | offset_of!(StableWithUnstableField, unstable);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
+ = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0658]: use of unstable library feature 'unstable_test_feature'
--> $DIR/offset-of-unstable.rs:20:5
@@ -49,6 +51,7 @@ LL | offset_of!(StableWithUnstableFieldType, stable.unstable);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
+ = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0658]: use of unstable library feature 'unstable_test_feature'
--> $DIR/offset-of-unstable.rs:21:5
@@ -61,6 +64,7 @@ LL | | );
| |_____^
|
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
+ = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0658]: use of unstable library feature 'unstable_test_feature'
--> $DIR/offset-of-unstable.rs:26:5
@@ -73,6 +77,7 @@ LL | | );
| |_____^
|
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
+ = note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 8 previous errors
diff --git a/tests/ui/parser/builtin-syntax.rs b/tests/ui/parser/builtin-syntax.rs
new file mode 100644
index 00000000000..897dab8ec50
--- /dev/null
+++ b/tests/ui/parser/builtin-syntax.rs
@@ -0,0 +1,9 @@
+#![feature(builtin_syntax)]
+
+fn main() {
+ builtin # foobar(); //~ ERROR unknown `builtin #` construct
+}
+
+fn not_identifier() {
+ builtin # {}(); //~ ERROR expected identifier after
+}
diff --git a/tests/ui/parser/builtin-syntax.stderr b/tests/ui/parser/builtin-syntax.stderr
new file mode 100644
index 00000000000..ee3764a6221
--- /dev/null
+++ b/tests/ui/parser/builtin-syntax.stderr
@@ -0,0 +1,14 @@
+error: unknown `builtin #` construct `foobar`
+ --> $DIR/builtin-syntax.rs:4:5
+ |
+LL | builtin # foobar();
+ | ^^^^^^^^^^^^^^^^
+
+error: expected identifier after `builtin #`
+ --> $DIR/builtin-syntax.rs:8:15
+ |
+LL | builtin # {}();
+ | ^
+
+error: aborting due to 2 previous errors
+