about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUrgau <urgau@numericable.fr>2024-10-01 10:25:18 +0200
committerUrgau <urgau@numericable.fr>2024-10-04 09:09:20 +0200
commita3ffa1eae507809628decc6250b28db6ab167b11 (patch)
tree1557002d8c545a8b05e453b7355fddd76fcbe1b9
parent781f1840cd37348ce4d76fff2b04e1ada531864e (diff)
downloadrust-a3ffa1eae507809628decc6250b28db6ab167b11.tar.gz
rust-a3ffa1eae507809628decc6250b28db6ab167b11.zip
Improve non-boolean literal error in cfg predicate
-rw-r--r--compiler/rustc_attr/messages.ftl2
-rw-r--r--compiler/rustc_attr/src/builtin.rs3
-rw-r--r--compiler/rustc_attr/src/session_diagnostics.rs1
-rw-r--r--tests/ui/macros/cfg.rs2
-rw-r--r--tests/ui/macros/cfg.stderr2
5 files changed, 7 insertions, 3 deletions
diff --git a/compiler/rustc_attr/messages.ftl b/compiler/rustc_attr/messages.ftl
index 5d9ac23ec49..adabf18ca85 100644
--- a/compiler/rustc_attr/messages.ftl
+++ b/compiler/rustc_attr/messages.ftl
@@ -107,6 +107,8 @@ attr_unknown_version_literal =
 attr_unstable_cfg_target_compact =
     compact `cfg(target(..))` is experimental and subject to change
 
+attr_unsupported_literal_cfg_boolean =
+    literal in `cfg` predicate value must be a boolean
 attr_unsupported_literal_cfg_string =
     literal in `cfg` predicate value must be a string
 attr_unsupported_literal_deprecated_kv_pair =
diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs
index a3c6132d484..af73281c316 100644
--- a/compiler/rustc_attr/src/builtin.rs
+++ b/compiler/rustc_attr/src/builtin.rs
@@ -36,6 +36,7 @@ pub fn is_builtin_attr(attr: &Attribute) -> bool {
 pub(crate) enum UnsupportedLiteralReason {
     Generic,
     CfgString,
+    CfgBoolean,
     DeprecatedString,
     DeprecatedKvPair,
 }
@@ -623,7 +624,7 @@ pub fn eval_condition(
         _ => {
             dcx.emit_err(session_diagnostics::UnsupportedLiteral {
                 span: cfg.span(),
-                reason: UnsupportedLiteralReason::Generic,
+                reason: UnsupportedLiteralReason::CfgBoolean,
                 is_bytestr: false,
                 start_point_span: sess.source_map().start_point(cfg.span()),
             });
diff --git a/compiler/rustc_attr/src/session_diagnostics.rs b/compiler/rustc_attr/src/session_diagnostics.rs
index 959a5a4bba7..626840aa6a3 100644
--- a/compiler/rustc_attr/src/session_diagnostics.rs
+++ b/compiler/rustc_attr/src/session_diagnostics.rs
@@ -206,6 +206,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnsupportedLiteral {
         let mut diag = Diag::new(dcx, level, match self.reason {
             UnsupportedLiteralReason::Generic => fluent::attr_unsupported_literal_generic,
             UnsupportedLiteralReason::CfgString => fluent::attr_unsupported_literal_cfg_string,
+            UnsupportedLiteralReason::CfgBoolean => fluent::attr_unsupported_literal_cfg_boolean,
             UnsupportedLiteralReason::DeprecatedString => {
                 fluent::attr_unsupported_literal_deprecated_string
             }
diff --git a/tests/ui/macros/cfg.rs b/tests/ui/macros/cfg.rs
index 387cc0ba8e2..50998572274 100644
--- a/tests/ui/macros/cfg.rs
+++ b/tests/ui/macros/cfg.rs
@@ -1,6 +1,6 @@
 fn main() {
     cfg!(); //~ ERROR macro requires a cfg-pattern
-    cfg!(123); //~ ERROR unsupported literal
+    cfg!(123); //~ ERROR literal in `cfg` predicate value must be a boolean
     cfg!(foo = 123); //~ ERROR literal in `cfg` predicate value must be a string
     cfg!(foo, bar); //~ ERROR expected 1 cfg-pattern
 }
diff --git a/tests/ui/macros/cfg.stderr b/tests/ui/macros/cfg.stderr
index 5c21497dc5d..53326914865 100644
--- a/tests/ui/macros/cfg.stderr
+++ b/tests/ui/macros/cfg.stderr
@@ -6,7 +6,7 @@ LL |     cfg!();
    |
    = note: this error originates in the macro `cfg` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error[E0565]: unsupported literal
+error[E0565]: literal in `cfg` predicate value must be a boolean
   --> $DIR/cfg.rs:3:10
    |
 LL |     cfg!(123);