rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.16k stars 12.8k forks source link

Invalid help suggestion when `vec` macro incorrectly used without `!` #101490

Open Rageking8 opened 2 years ago

Rageking8 commented 2 years ago

Given the following code: link

fn main() {
    let _x = vec[1, 2, 3];
}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: expected `;`, found `[`
 --> src/main.rs:2:17
  |
2 |     let _x = vec[1, 2, 3];
  |                 ^
  |
help: consider adding `;` here
  |
2 |     let _x = vec;[1, 2, 3];
  |                 +

error: could not compile `playground` due to previous error

Just for some context this is the current error message for the stable and beta versions:

   Compiling playground v0.0.1 (/playground)
error: expected one of `.`, `?`, `]`, or an operator, found `,`
 --> src/main.rs:2:19
  |
2 |     let _x = vec[1, 2, 3];
  |                   ^ expected one of `.`, `?`, `]`, or an operator

error: could not compile `playground` due to previous error

Which is also not ideal as for the other std macros AFAIK (only checked a few), incorrect usage (i.e. without the !) will lead to a help suggestion informing the user to include a ! to invoke a macro (e.g. print, println).

Hence, the ideal output is to suggest adding the ! when invoking the vec macro incorrectly as with other macros.

@rustbot label +regression-from-stable-to-nightly +D-invalid-suggestion

May need a bisect.

lukas-code commented 2 years ago

Did not bisect, but this is probably caused by #100334.

apiraino commented 2 years ago

LOL at the new suggestion

anyway, yes confirmed the bisection points to a rollup merge with contains #100334 cc @TaKO8Ki

searched nightlies: from nightly-2022-07-13 to nightly-2022-09-06 regressed nightly: nightly-2022-08-11 searched commit range: https://github.com/rust-lang/rust/compare/34a6cae28e7013ff0e640026a8e46f315426829d...29e4a9ee0253cd39e552a77f51f11f9a5f1c41e6 regressed commit: https://github.com/rust-lang/rust/commit/1603a70f82240ba2d27f72f964e36614d7620ad3

bisected with cargo-bisect-rustc v0.6.3 Host triple: x86_64-unknown-linux-gnu Reproduce with: ```bash cargo bisect-rustc --start 2022-07-13 --preserve ```

I'll try to dig further back in time to find where we lost the correct diagnostic message

EDIT: the diagnostic we had previously was introduced in Rust 1.18 so basically I think we never really suggested the right thing ("adding the ! when invoking the vec macro incorrectly as with other macros.")

Rageking8 commented 2 years ago

The regression that causes the compiler to emit the invalid help suggestion is fixed by #101502 Hence, the current output error message is:

   Compiling playground v0.0.1 (/playground)
error: expected one of `.`, `?`, `]`, or an operator, found `,`
 --> src/main.rs:2:19
  |
2 |     let _x = vec[1, 2, 3];
  |                   ^ expected one of `.`, `?`, `]`, or an operator

error: could not compile `playground` due to previous error

However, as mentioned in the top of this issue, it is still not ideal. Therefore, "suggest adding the ! when invoking the vec macro incorrectly as with other macros." this part still needs to get implemented.

estebank commented 2 years ago

Doing the "correct" thing and emitting an always correct "add ! here" suggestion will require delaying a parse error until resolution is available, which is quite hard to do. Alternatively, we could customize the check to tentatively mention macros when encountering ident[<parse error> not dissimilar to how we treat ident{<parse error>.

apiraino commented 1 year ago

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-low +regression-from-stable-to-stable -regression-from-stable-to-nightly

estebank commented 1 year ago

The current output is back to what it originally was

error: expected one of `.`, `?`, `]`, or an operator, found `,`
 --> src/main.rs:2:19
  |
2 |     let _x = vec[1, 2, 3];
  |                   ^ expected one of `.`, `?`, `]`, or an operator

I don't think it qualifies as a regression anymore, but it would be great still to make the output be the following instead

error: missing `!` in macro invokation
 --> src/main.rs:2:19
  |
2 |     let _x = vec[1, 2, 3];
  |                 ^ expected a `!` here