about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorJonathan Brouwer <jonathantbrouwer@gmail.com>2025-06-29 11:34:29 +0200
committerJonathan Brouwer <jonathantbrouwer@gmail.com>2025-07-01 16:10:05 +0200
commit149bdde97e65779b126ec1ae6bcbe152fd90f856 (patch)
tree7fd8c5d47bd21f4dfbcd2812a2dad2ed3d2e42ba /compiler
parent86b54d5729f019d5e2c5acff4ddfddbd7af2fde3 (diff)
Fix `#[must_use = 1]` not giving an error
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_attr_parsing/src/attributes/must_use.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_attr_parsing/src/attributes/must_use.rs b/compiler/rustc_attr_parsing/src/attributes/must_use.rs
index a672d956127..b5eb85f68b4 100644
--- a/compiler/rustc_attr_parsing/src/attributes/must_use.rs
+++ b/compiler/rustc_attr_parsing/src/attributes/must_use.rs
@@ -21,7 +21,16 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
             span: cx.attr_span,
             reason: match args {
                 ArgParser::NoArgs => None,
-                ArgParser::NameValue(name_value) => name_value.value_as_str(),
+                ArgParser::NameValue(name_value) => {
+                    let Some(value_str) = name_value.value_as_str() else {
+                        cx.expected_string_literal(
+                            name_value.value_span,
+                            Some(&name_value.value_as_lit()),
+                        );
+                        return None;
+                    };
+                    Some(value_str)
+                }
                 ArgParser::List(_) => {
                     let suggestions =
                         <Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "must_use");