Skip to content

A : instead of a :: in a path of a use item should be a recoverable parsing error #103269

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
pnkfelix opened this issue Oct 19, 2022 · 9 comments · Fixed by #103443
Closed

A : instead of a :: in a path of a use item should be a recoverable parsing error #103269

pnkfelix opened this issue Oct 19, 2022 · 9 comments · Fixed by #103443
Assignees
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Oct 19, 2022

I tried this code:

use std::process:Command;
use std::fs:File;

fn main() { }

I expected to see this happen: I expected to see two diagnostic messages, telling me about the distinct parse errors on lines 1 and 2.

Instead, this happened: The first error was treated as non-recoverable, yielding this output (playground):

error: expected one of `::`, `;`, or `as`, found `:`
 --> src/main.rs:1:17
  |
1 | [use std::process:Command;](https://play.rust-lang.org/#)
  |                 ^ expected one of `::`, `;`, or `as`

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

I'm assuming recovering in the face of this parse error would be a relatively simple task, given that there is already the : present that should be a strong hint that someone meant to type ::. So I'm tagging this with labels indicating that its a good opportunity for someone who wants to acquaint themselves with the code base.

@pnkfelix pnkfelix added C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-mentor labels Oct 19, 2022
@pnkfelix
Copy link
Member Author

(This needs a mentor. I am thinking that if someone doesn't pick it up by Friday, then I will see about using it as the basis for one or more instructional videos.)

@pnkfelix pnkfelix added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-parser Area: The parsing of Rust source code to an AST labels Oct 19, 2022
@compiler-errors
Copy link
Member

I can mentor whoever wants to work on this. See https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/parser/item.rs#L950 for the general area where changes need to be made, and ping me if someone needs help on Zulip.

@me-diru
Copy link

me-diru commented Oct 19, 2022

May I work on this?

@compiler-errors
Copy link
Member

You can claim an issue with rustbot, and I recommend checking out the rustc dev guide to find out what the contribution process looks like.

@will-flores1
Copy link

@rustbot claim

@will-flores1
Copy link

@rustbot release-assignment

@fee1-dead
Copy link
Member

fee1-dead commented Oct 22, 2022

This is mostly about adding checks around eat(token::ModSep) such that it recovers when encountering token::Colon. src

However, we would also need the ability to recover to be configurable as arguments to parse_path, as we would want to recover from use std:process::Command as well.

PS: don't take this as is.. I am not that familiar with ast and recovery, but I think this is the main idea

@mucinoab
Copy link
Contributor

I will take a quick look into this.
@rustbot claim

notriddle added a commit to notriddle/rust that referenced this issue Nov 10, 2022
…aretor, r=compiler-errors

Parser: Recover from using colon as path separator in imports

I don't know if this is the right approach, any feedback is welcome.

r? `@compiler-errors`

Fixes rust-lang#103269
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 10, 2022
…aretor, r=compiler-errors

Parser: Recover from using colon as path separator in imports

I don't know if this is the right approach, any feedback is welcome.

r? ``@compiler-errors``

Fixes rust-lang#103269
@bors bors closed this as completed in 0c4a81c Nov 10, 2022
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
…aretor, r=compiler-errors

Parser: Recover from using colon as path separator in imports

I don't know if this is the right approach, any feedback is welcome.

r? ```@compiler-errors```

Fixes rust-lang#103269
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
@pnkfelix @compiler-errors @mucinoab @me-diru @fee1-dead @will-flores1 and others