about summary refs log tree commit diff
path: root/tests/ui/impl-trait
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2025-04-15 07:44:24 +0200
committerLeón Orell Valerian Liehr <me@fmease.dev>2025-04-15 10:08:49 +0200
commit6242335fdb7444876abf1c3669b6aab1649a0a64 (patch)
tree4eebc86603d28b2ceba1cfe8abb60c7fad06e802 /tests/ui/impl-trait
parent8887af72a0b1f37a34b02d488ca3278576e2d73d (diff)
downloadrust-6242335fdb7444876abf1c3669b6aab1649a0a64.tar.gz
rust-6242335fdb7444876abf1c3669b6aab1649a0a64.zip
Improve diagnostic for E0178 (bad `+` in type)
Namely, use a more sensical primary span.
Don't pretty-print AST nodes for the diagnostic message. Why:
* It's lossy (e.g., it doesn't replicate trailing `+`s in trait objects.
* It's prone to leak error nodes (printed as `(/*ERROR*/)`) since
  the LHS can easily represent recovered code (e.g., `fn(i32?) + T`).
Diffstat (limited to 'tests/ui/impl-trait')
-rw-r--r--tests/ui/impl-trait/impl-trait-plus-priority.rs4
-rw-r--r--tests/ui/impl-trait/impl-trait-plus-priority.stderr10
2 files changed, 8 insertions, 6 deletions
diff --git a/tests/ui/impl-trait/impl-trait-plus-priority.rs b/tests/ui/impl-trait/impl-trait-plus-priority.rs
index 5575493a17d..8f76d412662 100644
--- a/tests/ui/impl-trait/impl-trait-plus-priority.rs
+++ b/tests/ui/impl-trait/impl-trait-plus-priority.rs
@@ -27,7 +27,7 @@ type A = fn() -> impl A + B;
 type A = fn() -> dyn A + B;
 //~^ ERROR ambiguous `+` in a type
 type A = fn() -> A + B;
-//~^ ERROR expected a path on the left-hand side of `+`, not `fn() -> A`
+//~^ ERROR expected a path on the left-hand side of `+`
 
 type A = Fn() -> impl A +;
 //~^ ERROR ambiguous `+` in a type
@@ -44,6 +44,6 @@ type A = &impl A + B;
 type A = &dyn A + B;
 //~^ ERROR ambiguous `+` in a type
 type A = &A + B;
-//~^ ERROR expected a path on the left-hand side of `+`, not `&A`
+//~^ ERROR expected a path on the left-hand side of `+`
 
 fn main() {}
diff --git a/tests/ui/impl-trait/impl-trait-plus-priority.stderr b/tests/ui/impl-trait/impl-trait-plus-priority.stderr
index 03e7910095a..16120657960 100644
--- a/tests/ui/impl-trait/impl-trait-plus-priority.stderr
+++ b/tests/ui/impl-trait/impl-trait-plus-priority.stderr
@@ -31,11 +31,13 @@ help: try adding parentheses
 LL | type A = fn() -> (dyn A + B);
    |                  +         +
 
-error[E0178]: expected a path on the left-hand side of `+`, not `fn() -> A`
+error[E0178]: expected a path on the left-hand side of `+`
   --> $DIR/impl-trait-plus-priority.rs:29:10
    |
 LL | type A = fn() -> A + B;
-   |          ^^^^^^^^^^^^^ perhaps you forgot parentheses?
+   |          ^^^^^^^^^----
+   |          |
+   |          perhaps you forgot parentheses?
 
 error: ambiguous `+` in a type
   --> $DIR/impl-trait-plus-priority.rs:32:18
@@ -103,11 +105,11 @@ help: try adding parentheses
 LL | type A = &(dyn A + B);
    |           +         +
 
-error[E0178]: expected a path on the left-hand side of `+`, not `&A`
+error[E0178]: expected a path on the left-hand side of `+`
   --> $DIR/impl-trait-plus-priority.rs:46:10
    |
 LL | type A = &A + B;
-   |          ^^^^^^
+   |          ^^
    |
 help: try adding parentheses
    |