Skip to content

Missing a single bracket in an import statement can cause tens of cascading errors. #83498

New issue

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

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

Already on GitHub? Sign in to your account

Closed
Frederik-Baetens opened this issue Mar 25, 2021 · 0 comments · Fixed by #84024
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Frederik-Baetens
Copy link

Missing a single bracket, can lead to 8 errors in this case, and 16 in the actual project this sample code comes from.

Example mistake:

use serde::{Deserialize, Serialize//};

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=015ef4d8827e4c3915e385428acf29fb

use serde::{Deserialize, Serialize//};
use std::net::SocketAddr;

fn main() {
    let addr = "0.0.0.0:8000".parse().unwrap();
    let noderef = NodeRef::new(addr);
    noderef.get("hi");
    noderef.upsert("hi".to_owned(), "hey".to_owned());
    noderef.upsert_prefix_ref("hi", addr);
}

#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
pub struct NodeRef {
    pub address: SocketAddr,
}

impl NodeRef {
    pub fn new(address: SocketAddr) -> NodeRef {
        NodeRef { address }
    }

    pub  fn get(&self, key: &str) -> Option<String> {
        dbg!(key);
        None
    }

    pub  fn upsert(&self, key: String, value: String) {
        dbg!(key, value);
    }

    pub  fn upsert_prefix_ref(&self, prefix: &str, addr: SocketAddr) {
        dbg!(prefix, addr);
    }
}

The current output is:

    Checking errortest v0.1.0 (/home/frederik/Programmeren/rust/errortest)
error: this file contains an unclosed delimiter
  --> src/main.rs:35:2
   |
1  | use serde::{Deserialize, Serialize//};
   |            - unclosed delimiter
...
35 | 
   |  ^

error: expected identifier, found keyword `use`
 --> src/main.rs:2:1
  |
2 | use std::net::SocketAddr;
  | ^^^ expected identifier, found keyword

error: expected one of `,`, `::`, `as`, or `}`, found keyword `use`
 --> src/main.rs:2:1
  |
1 | use serde::{Deserialize, Serialize//};
  |            - unclosed delimiter   - expected one of `,`, `::`, `as`, or `}`
2 | use std::net::SocketAddr;
  | ^^^ unexpected token
  |
help: `}` may belong here
  |
1 | use serde::{Deserialize, Serialize}//};
  |                                   ^
help: missing `,`
  |
1 | use serde::{Deserialize, Serialize,//};
  |                                   ^

error: expected one of `,`, `::`, `as`, or `}`, found `std`
 --> src/main.rs:2:5
  |
2 | use std::net::SocketAddr;
  |    -^^^ expected one of `,`, `::`, `as`, or `}`
  |    |
  |    help: missing `,`

error: expected identifier, found keyword `fn`
 --> src/main.rs:4:1
  |
4 | fn main() {
  | ^^ expected identifier, found keyword

error: expected one of `,`, `::`, `as`, or `}`, found `;`
 --> src/main.rs:2:25
  |
2 | use std::net::SocketAddr;
  |                         ^
  |                         |
  |                         expected one of `,`, `::`, `as`, or `}`
  |                         help: missing `,`

error: expected one of `,`, `::`, `as`, or `}`, found `main`
 --> src/main.rs:4:4
  |
4 | fn main() {
  |   -^^^^ expected one of `,`, `::`, `as`, or `}`
  |   |
  |   help: missing `,`

error: expected one of `,`, `::`, `as`, or `}`, found `(`
 --> src/main.rs:4:8
  |
4 | fn main() {
  |        ^ expected one of `,`, `::`, `as`, or `}`

error: aborting due to 8 previous errors

error: could not compile `errortest`

To learn more, run the command again with --verbose.

Ideally the output should look like:

    Checking errortest v0.1.0 (/home/frederik/Programmeren/rust/errortest)
error: this file contains an unclosed delimiter
  --> src/main.rs:35:2
   |
1  | use serde::{Deserialize, Serialize//};
   |            - unclosed delimiter
...
35 | 
   |  ^

error: aborting due to 1 previous error

error: could not compile `errortest`

To learn more, run the command again with --verbose.

Also the placing of the unclosed delimiter warning arrow seems weird? I think it should point to where I put the // ? Usually rustc error output is pretty good at pointing to where I actually need to make a change.

@Frederik-Baetens Frederik-Baetens added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 25, 2021
@jyn514 jyn514 added A-parser Area: The lexing & parsing of Rust source code to an AST D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Mar 26, 2021
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Apr 5, 2021
@bors bors closed this as completed in 481598b Apr 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. 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.

3 participants