summaryrefslogtreecommitdiffstats
path: root/tests/ui/rfcs/rfc-2151-raw-identifiers
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/rfcs/rfc-2151-raw-identifiers
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/rfcs/rfc-2151-raw-identifiers')
-rw-r--r--tests/ui/rfcs/rfc-2151-raw-identifiers/attr.rs15
-rw-r--r--tests/ui/rfcs/rfc-2151-raw-identifiers/basic.rs20
-rw-r--r--tests/ui/rfcs/rfc-2151-raw-identifiers/items.rs32
-rw-r--r--tests/ui/rfcs/rfc-2151-raw-identifiers/macros.rs38
4 files changed, 105 insertions, 0 deletions
diff --git a/tests/ui/rfcs/rfc-2151-raw-identifiers/attr.rs b/tests/ui/rfcs/rfc-2151-raw-identifiers/attr.rs
new file mode 100644
index 000000000..d359067f6
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2151-raw-identifiers/attr.rs
@@ -0,0 +1,15 @@
+// run-pass
+use std::mem;
+
+#[r#repr(r#C, r#packed)]
+struct Test {
+ a: bool, b: u64
+}
+
+#[r#derive(r#Debug)]
+struct Test2(#[allow(unused_tuple_struct_fields)] u32);
+
+pub fn main() {
+ assert_eq!(mem::size_of::<Test>(), 9);
+ assert_eq!("Test2(123)", format!("{:?}", Test2(123)));
+}
diff --git a/tests/ui/rfcs/rfc-2151-raw-identifiers/basic.rs b/tests/ui/rfcs/rfc-2151-raw-identifiers/basic.rs
new file mode 100644
index 000000000..f2fe59668
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2151-raw-identifiers/basic.rs
@@ -0,0 +1,20 @@
+// run-pass
+fn r#fn(r#match: u32) -> u32 {
+ r#match
+}
+
+pub fn main() {
+ let r#struct = 1;
+ assert_eq!(1, r#struct);
+
+ let foo = 2;
+ assert_eq!(2, r#foo);
+
+ let r#bar = 3;
+ assert_eq!(3, bar);
+
+ assert_eq!(4, r#fn(4));
+
+ let r#true = false;
+ assert_eq!(r#true, false);
+}
diff --git a/tests/ui/rfcs/rfc-2151-raw-identifiers/items.rs b/tests/ui/rfcs/rfc-2151-raw-identifiers/items.rs
new file mode 100644
index 000000000..466522517
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2151-raw-identifiers/items.rs
@@ -0,0 +1,32 @@
+// run-pass
+#[derive(Debug, PartialEq, Eq)]
+struct IntWrapper(u32);
+
+#[derive(Debug, Ord, PartialOrd, PartialEq, Eq, Hash, Copy, Clone, Default)]
+struct HasKeywordField {
+ r#struct: u32,
+}
+
+struct Generic<r#T>(T);
+
+trait Trait {
+ fn r#trait(&self) -> u32;
+}
+impl Trait for Generic<u32> {
+ fn r#trait(&self) -> u32 {
+ self.0
+ }
+}
+
+pub fn main() {
+ assert_eq!(IntWrapper(1), r#IntWrapper(1));
+
+ match IntWrapper(2) {
+ r#IntWrapper(r#struct) => assert_eq!(2, r#struct),
+ }
+
+ assert_eq!("HasKeywordField { struct: 3 }", format!("{:?}", HasKeywordField { r#struct: 3 }));
+
+ assert_eq!(4, Generic(4).0);
+ assert_eq!(5, Generic(5).r#trait());
+}
diff --git a/tests/ui/rfcs/rfc-2151-raw-identifiers/macros.rs b/tests/ui/rfcs/rfc-2151-raw-identifiers/macros.rs
new file mode 100644
index 000000000..0ab7e17f8
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2151-raw-identifiers/macros.rs
@@ -0,0 +1,38 @@
+// run-pass
+#![feature(decl_macro)]
+
+macro_rules! r#struct {
+ ($r#struct:expr) => { $r#struct }
+}
+
+macro_rules! old_macro {
+ ($a:expr) => {$a}
+}
+
+macro r#decl_macro($r#fn:expr) {
+ $r#fn
+}
+
+macro passthrough($id:ident) {
+ $id
+}
+
+macro_rules! test_pat_match {
+ (a) => { 6 };
+ (r#a) => { 7 };
+}
+
+pub fn main() {
+ r#println!("{struct}", r#struct = 1);
+ assert_eq!(2, r#struct!(2));
+ assert_eq!(3, r#old_macro!(3));
+ assert_eq!(4, decl_macro!(4));
+
+ let r#match = 5;
+ assert_eq!(5, passthrough!(r#match));
+
+ assert_eq!("r#struct", stringify!(r#struct));
+
+ assert_eq!(6, test_pat_match!(a));
+ assert_eq!(7, test_pat_match!(r#a));
+}