Skip to content

Commit 29c0fe7

Browse files
authored
Rollup merge of rust-lang#139294 - beetrees:fix-f16-f128-literal-feature-gate, r=fmease
Fix the `f16`/`f128` feature gates on integer literals The feature gating logic for `f16`/`f128` currently only checks float literals, meaning this code currently compiles with no feature gates on stable ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b0c0e285ccb822fc7e2abc595557886b)): ```rust fn main() { let a = 1f16; let b = 1f128; dbg!(a, b); } ``` This PR fixes that. Tracking issue: rust-lang#116909
2 parents 85c557e + 62fcb9d commit 29c0fe7

7 files changed

+66
-22
lines changed

Diff for: compiler/rustc_ast_passes/src/feature_gate.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
332332
ast::ExprKind::TryBlock(_) => {
333333
gate!(&self, try_blocks, e.span, "`try` expression is experimental");
334334
}
335-
ast::ExprKind::Lit(token::Lit { kind: token::LitKind::Float, suffix, .. }) => {
336-
match suffix {
337-
Some(sym::f16) => {
338-
gate!(&self, f16, e.span, "the type `f16` is unstable")
339-
}
340-
Some(sym::f128) => {
341-
gate!(&self, f128, e.span, "the type `f128` is unstable")
342-
}
343-
_ => (),
335+
ast::ExprKind::Lit(token::Lit {
336+
kind: token::LitKind::Float | token::LitKind::Integer,
337+
suffix,
338+
..
339+
}) => match suffix {
340+
Some(sym::f16) => {
341+
gate!(&self, f16, e.span, "the type `f16` is unstable")
344342
}
345-
}
343+
Some(sym::f128) => {
344+
gate!(&self, f128, e.span, "the type `f128` is unstable")
345+
}
346+
_ => (),
347+
},
346348
_ => {}
347349
}
348350
visit::walk_expr(self, e)

Diff for: tests/ui/feature-gates/feature-gate-f128.e2015.stderr

+13-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | let a: f128 = 100.0;
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0658]: the type `f128` is unstable
22-
--> $DIR/feature-gate-f128.rs:15:11
22+
--> $DIR/feature-gate-f128.rs:16:11
2323
|
2424
LL | fn foo(a: f128) {}
2525
| ^^^^
@@ -29,7 +29,7 @@ LL | fn foo(a: f128) {}
2929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3030

3131
error[E0658]: the type `f128` is unstable
32-
--> $DIR/feature-gate-f128.rs:18:8
32+
--> $DIR/feature-gate-f128.rs:19:8
3333
|
3434
LL | a: f128,
3535
| ^^^^
@@ -48,6 +48,16 @@ LL | let b = 0.0f128;
4848
= help: add `#![feature(f128)]` to the crate attributes to enable
4949
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
5050

51-
error: aborting due to 5 previous errors
51+
error[E0658]: the type `f128` is unstable
52+
--> $DIR/feature-gate-f128.rs:12:13
53+
|
54+
LL | let c = 0f128;
55+
| ^^^^^
56+
|
57+
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
58+
= help: add `#![feature(f128)]` to the crate attributes to enable
59+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
60+
61+
error: aborting due to 6 previous errors
5262

5363
For more information about this error, try `rustc --explain E0658`.

Diff for: tests/ui/feature-gates/feature-gate-f128.e2018.stderr

+13-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | let a: f128 = 100.0;
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0658]: the type `f128` is unstable
22-
--> $DIR/feature-gate-f128.rs:15:11
22+
--> $DIR/feature-gate-f128.rs:16:11
2323
|
2424
LL | fn foo(a: f128) {}
2525
| ^^^^
@@ -29,7 +29,7 @@ LL | fn foo(a: f128) {}
2929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3030

3131
error[E0658]: the type `f128` is unstable
32-
--> $DIR/feature-gate-f128.rs:18:8
32+
--> $DIR/feature-gate-f128.rs:19:8
3333
|
3434
LL | a: f128,
3535
| ^^^^
@@ -48,6 +48,16 @@ LL | let b = 0.0f128;
4848
= help: add `#![feature(f128)]` to the crate attributes to enable
4949
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
5050

51-
error: aborting due to 5 previous errors
51+
error[E0658]: the type `f128` is unstable
52+
--> $DIR/feature-gate-f128.rs:12:13
53+
|
54+
LL | let c = 0f128;
55+
| ^^^^^
56+
|
57+
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
58+
= help: add `#![feature(f128)]` to the crate attributes to enable
59+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
60+
61+
error: aborting due to 6 previous errors
5262

5363
For more information about this error, try `rustc --explain E0658`.

Diff for: tests/ui/feature-gates/feature-gate-f128.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const A: f128 = 10.0; //~ ERROR the type `f128` is unstable
99
pub fn main() {
1010
let a: f128 = 100.0; //~ ERROR the type `f128` is unstable
1111
let b = 0.0f128; //~ ERROR the type `f128` is unstable
12+
let c = 0f128; //~ ERROR the type `f128` is unstable
1213
foo(1.23);
1314
}
1415

Diff for: tests/ui/feature-gates/feature-gate-f16.e2015.stderr

+13-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | let a: f16 = 100.0;
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0658]: the type `f16` is unstable
22-
--> $DIR/feature-gate-f16.rs:15:11
22+
--> $DIR/feature-gate-f16.rs:16:11
2323
|
2424
LL | fn foo(a: f16) {}
2525
| ^^^
@@ -29,7 +29,7 @@ LL | fn foo(a: f16) {}
2929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3030

3131
error[E0658]: the type `f16` is unstable
32-
--> $DIR/feature-gate-f16.rs:18:8
32+
--> $DIR/feature-gate-f16.rs:19:8
3333
|
3434
LL | a: f16,
3535
| ^^^
@@ -48,6 +48,16 @@ LL | let b = 0.0f16;
4848
= help: add `#![feature(f16)]` to the crate attributes to enable
4949
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
5050

51-
error: aborting due to 5 previous errors
51+
error[E0658]: the type `f16` is unstable
52+
--> $DIR/feature-gate-f16.rs:12:13
53+
|
54+
LL | let c = 0f16;
55+
| ^^^^
56+
|
57+
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
58+
= help: add `#![feature(f16)]` to the crate attributes to enable
59+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
60+
61+
error: aborting due to 6 previous errors
5262

5363
For more information about this error, try `rustc --explain E0658`.

Diff for: tests/ui/feature-gates/feature-gate-f16.e2018.stderr

+13-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | let a: f16 = 100.0;
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0658]: the type `f16` is unstable
22-
--> $DIR/feature-gate-f16.rs:15:11
22+
--> $DIR/feature-gate-f16.rs:16:11
2323
|
2424
LL | fn foo(a: f16) {}
2525
| ^^^
@@ -29,7 +29,7 @@ LL | fn foo(a: f16) {}
2929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3030

3131
error[E0658]: the type `f16` is unstable
32-
--> $DIR/feature-gate-f16.rs:18:8
32+
--> $DIR/feature-gate-f16.rs:19:8
3333
|
3434
LL | a: f16,
3535
| ^^^
@@ -48,6 +48,16 @@ LL | let b = 0.0f16;
4848
= help: add `#![feature(f16)]` to the crate attributes to enable
4949
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
5050

51-
error: aborting due to 5 previous errors
51+
error[E0658]: the type `f16` is unstable
52+
--> $DIR/feature-gate-f16.rs:12:13
53+
|
54+
LL | let c = 0f16;
55+
| ^^^^
56+
|
57+
= note: see issue #116909 <https://github.com/rust-lang/rust/issues/116909> for more information
58+
= help: add `#![feature(f16)]` to the crate attributes to enable
59+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
60+
61+
error: aborting due to 6 previous errors
5262

5363
For more information about this error, try `rustc --explain E0658`.

Diff for: tests/ui/feature-gates/feature-gate-f16.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const A: f16 = 10.0; //~ ERROR the type `f16` is unstable
99
pub fn main() {
1010
let a: f16 = 100.0; //~ ERROR the type `f16` is unstable
1111
let b = 0.0f16; //~ ERROR the type `f16` is unstable
12+
let c = 0f16; //~ ERROR the type `f16` is unstable
1213
foo(1.23);
1314
}
1415

0 commit comments

Comments
 (0)