Skip to content

Commit 2098fec

Browse files
committed
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.
1 parent 2529bf2 commit 2098fec

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ check-pass
2+
#![allow(non_camel_case_types)]
3+
#![allow(unused)]
4+
5+
// Ensure that primitives do not interfere with user types of similar names
6+
7+
macro_rules! make_ty_mod {
8+
($modname:ident, $ty:tt) => {
9+
mod $modname {
10+
struct $ty {
11+
a: i32,
12+
}
13+
14+
fn assignment() {
15+
let $ty = ();
16+
}
17+
18+
fn access(a: $ty) -> i32 {
19+
a.a
20+
}
21+
}
22+
};
23+
}
24+
25+
make_ty_mod!(check_f16, f16);
26+
make_ty_mod!(check_f32, f32);
27+
make_ty_mod!(check_f64, f64);
28+
make_ty_mod!(check_f128, f128);
29+
30+
fn main() {}

tests/ui/resolve/primitive-usage.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//@ run-pass
2+
#![allow(unused)]
3+
#![feature(f128)]
4+
#![feature(f16)]
5+
6+
// Same as the feature gate tests but ensure we can use the types
7+
mod check_f128 {
8+
const A: f128 = 10.0;
9+
10+
pub fn foo() {
11+
let a: f128 = 100.0;
12+
let b = 0.0f128;
13+
bar(1.23);
14+
}
15+
16+
fn bar(a: f128) {}
17+
18+
struct Bar {
19+
a: f128,
20+
}
21+
}
22+
23+
mod check_f16 {
24+
const A: f16 = 10.0;
25+
26+
pub fn foo() {
27+
let a: f16 = 100.0;
28+
let b = 0.0f16;
29+
bar(1.23);
30+
}
31+
32+
fn bar(a: f16) {}
33+
34+
struct Bar {
35+
a: f16,
36+
}
37+
}
38+
39+
fn main() {
40+
check_f128::foo();
41+
check_f16::foo();
42+
}

0 commit comments

Comments
 (0)