about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2024-03-03 23:59:44 -0500
committerTrevor Gross <tmgross@umich.edu>2024-03-14 13:32:54 -0400
commit2098fec0809521ea8dd489f6cd5f09337a31764f (patch)
tree6d67f0fcf3dfb00eafaaac18da2ff6291d74dbee
parent2529bf2650ee548eb170822816aadacaa1ca05d2 (diff)
downloadrust-2098fec0809521ea8dd489f6cd5f09337a31764f.tar.gz
rust-2098fec0809521ea8dd489f6cd5f09337a31764f.zip
Add UI tests related to feature-gated primitives
Add a test that `f16` and `f128` are usable with the feature gate
enabled, as well as a test that user types with the same name as
primitives are not improperly gated.
-rw-r--r--tests/ui/resolve/conflicting-primitive-names.rs30
-rw-r--r--tests/ui/resolve/primitive-usage.rs42
2 files changed, 72 insertions, 0 deletions
diff --git a/tests/ui/resolve/conflicting-primitive-names.rs b/tests/ui/resolve/conflicting-primitive-names.rs
new file mode 100644
index 00000000000..79b6990681d
--- /dev/null
+++ b/tests/ui/resolve/conflicting-primitive-names.rs
@@ -0,0 +1,30 @@
+//@ check-pass
+#![allow(non_camel_case_types)]
+#![allow(unused)]
+
+// Ensure that primitives do not interfere with user types of similar names
+
+macro_rules! make_ty_mod {
+    ($modname:ident, $ty:tt) => {
+        mod $modname {
+            struct $ty {
+                a: i32,
+            }
+
+            fn assignment() {
+                let $ty = ();
+            }
+
+            fn access(a: $ty) -> i32 {
+                a.a
+            }
+        }
+    };
+}
+
+make_ty_mod!(check_f16, f16);
+make_ty_mod!(check_f32, f32);
+make_ty_mod!(check_f64, f64);
+make_ty_mod!(check_f128, f128);
+
+fn main() {}
diff --git a/tests/ui/resolve/primitive-usage.rs b/tests/ui/resolve/primitive-usage.rs
new file mode 100644
index 00000000000..b00d18a4e1e
--- /dev/null
+++ b/tests/ui/resolve/primitive-usage.rs
@@ -0,0 +1,42 @@
+//@ run-pass
+#![allow(unused)]
+#![feature(f128)]
+#![feature(f16)]
+
+// Same as the feature gate tests but ensure we can use the types
+mod check_f128 {
+    const A: f128 = 10.0;
+
+    pub fn foo() {
+        let a: f128 = 100.0;
+        let b = 0.0f128;
+        bar(1.23);
+    }
+
+    fn bar(a: f128) {}
+
+    struct Bar {
+        a: f128,
+    }
+}
+
+mod check_f16 {
+    const A: f16 = 10.0;
+
+    pub fn foo() {
+        let a: f16 = 100.0;
+        let b = 0.0f16;
+        bar(1.23);
+    }
+
+    fn bar(a: f16) {}
+
+    struct Bar {
+        a: f16,
+    }
+}
+
+fn main() {
+    check_f128::foo();
+    check_f16::foo();
+}