Confusing parser error when writing expression in item context
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2241d9411a77aa3a465dd34e997bd74d
I tried using the documented example for std::panic::set_hook in a clean project (see playground)
use std::panic;
panic::set_hook(Box::new(|_| {
println!("Custom panic hook");
}));
panic!("Normal panic");
I expected to see this happen: It compiles
Instead, this happened:
Compiling playground v0.0.1 (/playground)
error: expected one of `!` or `::`, found `(`
--> src/lib.rs:3:16
|
3 | panic::set_hook(Box::new(|_| {
| ^ expected one of `!` or `::`
error: could not compile `playground` (lib) due to previous error
I tried this with 1.74.1, 1.75.0-beta.7 (2023-12-16 b216e7b0e7a2bdf11300), and 1.76.0-nightly (2023-12-17 6a62871320e262661bb1) from the playground as well as locally with
rustc 1.76.0-nightly (3f28fe133 2023-12-18)
binary: rustc
commit-hash: 3f28fe133475ec5faf3413b556bf3cfb0d51336c
commit-date: 2023-12-18
host: aarch64-apple-darwin
release: 1.76.0-nightly
LLVM version: 17.0.6
rustc 1.75.0-beta.7 (b216e7b0e 2023-12-16)
binary: rustc
commit-hash: b216e7b0e7a2bdf11300a21a614dac6be3e99c5b
commit-date: 2023-12-16
host: aarch64-apple-darwin
release: 1.75.0-beta.7
LLVM version: 17.0.6
rustc 1.74.1 (a28077b28 2023-12-04)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: aarch64-apple-darwin
release: 1.74.1
LLVM version: 17.0.4
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: aarch64-apple-darwin
release: 1.73.0
LLVM version: 17.0.2
rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: aarch64-apple-darwin
release: 1.71.0
LLVM version: 16.0.5
rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: aarch64-apple-darwin
release: 1.69.0
LLVM version: 15.0.7
rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: aarch64-apple-darwin
release: 1.65.0
LLVM version: 15.0.0
rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: aarch64-apple-darwin
release: 1.63.0
LLVM version: 14.0.5
None of them worked, it's the same error in all cases.
I also tried various forms of using set_hook:
use std::panic::set_hook as sh;
sh(...);
use ::std::panic::set_hook as sh;
sh(...);
use std::panic as p;
p::set_hook(...);
use ::std::panic as p;
p::set_hook(...);
std::panic::set_hook(...);
::std::panic::set_hook(...);
And they all produce the same error.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the diagnostic in the linked Rust Playground using the documented std::panic::set_hook example and the listed compiler versions. Start by tracing how the parser handles the expression in item context and compare the resulting message with the reported expectation. Done means the confusing error is addressed and covered by an appropriate compiler test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100