about summary refs log tree commit diff
path: root/tests/ui/consts
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-12-12 09:55:50 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2023-12-12 15:54:25 +1100
commit226edf64fa58e591d8abc6afef5e38c15c181698 (patch)
tree794954d943af6c79141f6a967b6d3dfb23ea2518 /tests/ui/consts
parent57010939ed1d00076b4af0ed06a81ec69ea5e4a8 (diff)
downloadrust-226edf64fa58e591d8abc6afef5e38c15c181698.tar.gz
rust-226edf64fa58e591d8abc6afef5e38c15c181698.zip
Improve an error involving attribute values.
Attribute values must be literals. The error you get when that doesn't
hold is pretty bad, e.g.:
```
unexpected expression: 1 + 1
```
You also get the same error if the attribute value is a literal, but an
invalid literal, e.g.:
```
unexpected expression: "foo"suffix
```

This commit does two things.
- Changes the error message to "attribute value must be a literal",
  which gives a better idea of what the problem is and how to fix it. It
  also no longer prints the invalid expression, because the carets below
  highlight it anyway.
- Separates the "not a literal" case from the "invalid literal" case.
  Which means invalid literals now get the specific error at the literal
  level, rather than at the attribute level.
Diffstat (limited to 'tests/ui/consts')
-rw-r--r--tests/ui/consts/issue-90878-2.rs2
-rw-r--r--tests/ui/consts/issue-90878-2.stderr2
2 files changed, 2 insertions, 2 deletions
diff --git a/tests/ui/consts/issue-90878-2.rs b/tests/ui/consts/issue-90878-2.rs
index e5bcecce6ee..0e61c65305f 100644
--- a/tests/ui/consts/issue-90878-2.rs
+++ b/tests/ui/consts/issue-90878-2.rs
@@ -1,4 +1,4 @@
- #![l=|x|[b;x ]] //~ ERROR unexpected expression: `|x| [b; x]`
+ #![l=|x|[b;x ]] //~ ERROR attribute value must be a literal
 //~^ ERROR cannot find attribute `l` in this scope
 
 // notice the space at the start,
diff --git a/tests/ui/consts/issue-90878-2.stderr b/tests/ui/consts/issue-90878-2.stderr
index 71b8d21fb4d..0b332840042 100644
--- a/tests/ui/consts/issue-90878-2.stderr
+++ b/tests/ui/consts/issue-90878-2.stderr
@@ -1,4 +1,4 @@
-error: unexpected expression: `|x| [b; x]`
+error: attribute value must be a literal
   --> $DIR/issue-90878-2.rs:1:7
    |
 LL |  #![l=|x|[b;x ]]