summaryrefslogtreecommitdiffstats
path: root/tests/ui/offset-of/offset-of-self.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /tests/ui/offset-of/offset-of-self.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/offset-of/offset-of-self.rs')
-rw-r--r--tests/ui/offset-of/offset-of-self.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/ui/offset-of/offset-of-self.rs b/tests/ui/offset-of/offset-of-self.rs
new file mode 100644
index 000000000..dbeef0e74
--- /dev/null
+++ b/tests/ui/offset-of/offset-of-self.rs
@@ -0,0 +1,58 @@
+#![feature(offset_of)]
+
+use std::mem::offset_of;
+
+struct C<T> {
+ v: T,
+ w: T,
+}
+
+struct S {
+ v: u8,
+ w: u16,
+}
+
+impl S {
+ fn v_offs() -> usize {
+ offset_of!(Self, v)
+ }
+ fn v_offs_wrong_syntax() {
+ offset_of!(Self, Self::v); //~ ERROR no rules expected the token `::`
+ offset_of!(S, Self); //~ ERROR expected identifier, found keyword `Self`
+ //~| no field `Self` on type `S`
+ }
+ fn offs_in_c() -> usize {
+ offset_of!(C<Self>, w)
+ }
+ fn offs_in_c_colon() -> usize {
+ offset_of!(C::<Self>, w)
+ }
+}
+
+mod m {
+ use std::mem::offset_of;
+ fn off() {
+ offset_of!(self::S, v); //~ ERROR cannot find type `S` in module
+ offset_of!(super::S, v);
+ offset_of!(crate::S, v);
+ }
+ impl super::n::T {
+ fn v_offs_self() -> usize {
+ offset_of!(Self, v) //~ ERROR field `v` of struct `T` is private
+ }
+ }
+}
+
+mod n {
+ pub struct T { v: u8, }
+}
+
+fn main() {
+ offset_of!(self::S, v);
+ offset_of!(Self, v); //~ ERROR cannot find type `Self` in this scope
+
+ offset_of!(S, self); //~ ERROR expected identifier, found keyword `self`
+ //~| no field `self` on type `S`
+ offset_of!(S, v.self); //~ ERROR expected identifier, found keyword `self`
+ //~| no field `self` on type `u8`
+}