summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc/example/track-caller-attribute.rs
diff options
context:
space:
mode:
authorAntoni Boucher <bouanto@zoho.com>2021-08-12 21:53:49 -0400
committerAntoni Boucher <bouanto@zoho.com>2021-08-12 21:53:49 -0400
commitf7237f16ae1c94e35b1927f0e25aef4a3a6e3f22 (patch)
treee6b06bb2124751d299cae8600981517e9de8624d /compiler/rustc_codegen_gcc/example/track-caller-attribute.rs
parentae90dcf0207c57c3034f00b07048d63f8b2363c8 (diff)
parentafae271d5d3719eeb92c18bc004bb6d1965a5f3f (diff)
downloadrust-f7237f16ae1c94e35b1927f0e25aef4a3a6e3f22.tar.gz
rust-f7237f16ae1c94e35b1927f0e25aef4a3a6e3f22.zip
Add 'compiler/rustc_codegen_gcc/' from commit 'afae271d5d3719eeb92c18bc004bb6d1965a5f3f'
git-subtree-dir: compiler/rustc_codegen_gcc
git-subtree-mainline: ae90dcf0207c57c3034f00b07048d63f8b2363c8
git-subtree-split: afae271d5d3719eeb92c18bc004bb6d1965a5f3f
Diffstat (limited to 'compiler/rustc_codegen_gcc/example/track-caller-attribute.rs')
-rw-r--r--compiler/rustc_codegen_gcc/example/track-caller-attribute.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_gcc/example/track-caller-attribute.rs b/compiler/rustc_codegen_gcc/example/track-caller-attribute.rs
new file mode 100644
index 00000000000..93bab17e46b
--- /dev/null
+++ b/compiler/rustc_codegen_gcc/example/track-caller-attribute.rs
@@ -0,0 +1,40 @@
+// Based on https://github.com/anp/rust/blob/175631311716d7dfeceec40d2587cde7142ffa8c/src/test/ui/rfc-2091-track-caller/track-caller-attribute.rs
+
+// run-pass
+
+use std::panic::Location;
+
+#[track_caller]
+fn tracked() -> &'static Location<'static> {
+    Location::caller()
+}
+
+fn nested_intrinsic() -> &'static Location<'static> {
+    Location::caller()
+}
+
+fn nested_tracked() -> &'static Location<'static> {
+    tracked()
+}
+
+fn main() {
+    let location = Location::caller();
+    assert_eq!(location.file(), file!());
+    assert_eq!(location.line(), 21);
+    assert_eq!(location.column(), 20);
+
+    let tracked = tracked();
+    assert_eq!(tracked.file(), file!());
+    assert_eq!(tracked.line(), 26);
+    assert_eq!(tracked.column(), 19);
+
+    let nested = nested_intrinsic();
+    assert_eq!(nested.file(), file!());
+    assert_eq!(nested.line(), 13);
+    assert_eq!(nested.column(), 5);
+
+    let contained = nested_tracked();
+    assert_eq!(contained.file(), file!());
+    assert_eq!(contained.line(), 17);
+    assert_eq!(contained.column(), 5);
+}