Skip to content

Fix the f16/f128 feature gates on integer literals #139294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::ExprKind::TryBlock(_) => {
gate!(&self, try_blocks, e.span, "`try` expression is experimental");
}
ast::ExprKind::Lit(token::Lit { kind: token::LitKind::Float, suffix, .. }) => {
match suffix {
Some(sym::f16) => {
gate!(&self, f16, e.span, "the type `f16` is unstable")
}
Some(sym::f128) => {
gate!(&self, f128, e.span, "the type `f128` is unstable")
}
_ => (),
ast::ExprKind::Lit(token::Lit {
kind: token::LitKind::Float | token::LitKind::Integer,
suffix,
..
}) => match suffix {
Some(sym::f16) => {
gate!(&self, f16, e.span, "the type `f16` is unstable")
}
}
Some(sym::f128) => {
gate!(&self, f128, e.span, "the type `f128` is unstable")
}
_ => (),
},
_ => {}
}
visit::walk_expr(self, e)
Expand Down
16 changes: 13 additions & 3 deletions tests/ui/feature-gates/feature-gate-f128.e2015.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LL | let a: f128 = 100.0;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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

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

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

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0658`.
16 changes: 13 additions & 3 deletions tests/ui/feature-gates/feature-gate-f128.e2018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LL | let a: f128 = 100.0;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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

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

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

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0658`.
1 change: 1 addition & 0 deletions tests/ui/feature-gates/feature-gate-f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const A: f128 = 10.0; //~ ERROR the type `f128` is unstable
pub fn main() {
let a: f128 = 100.0; //~ ERROR the type `f128` is unstable
let b = 0.0f128; //~ ERROR the type `f128` is unstable
let c = 0f128; //~ ERROR the type `f128` is unstable
foo(1.23);
}

Expand Down
16 changes: 13 additions & 3 deletions tests/ui/feature-gates/feature-gate-f16.e2015.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LL | let a: f16 = 100.0;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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

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

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

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0658`.
16 changes: 13 additions & 3 deletions tests/ui/feature-gates/feature-gate-f16.e2018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LL | let a: f16 = 100.0;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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

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

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

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0658`.
1 change: 1 addition & 0 deletions tests/ui/feature-gates/feature-gate-f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const A: f16 = 10.0; //~ ERROR the type `f16` is unstable
pub fn main() {
let a: f16 = 100.0; //~ ERROR the type `f16` is unstable
let b = 0.0f16; //~ ERROR the type `f16` is unstable
let c = 0f16; //~ ERROR the type `f16` is unstable
foo(1.23);
}

Expand Down
Loading