Skip to content
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

Diagnostics could be better for unclosed delimiters #63690

Closed
sgrif opened this issue Aug 18, 2019 · 0 comments · Fixed by #65838
Closed

Diagnostics could be better for unclosed delimiters #63690

sgrif opened this issue Aug 18, 2019 · 0 comments · Fixed by #65838
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@sgrif
Copy link
Contributor

sgrif commented Aug 18, 2019

Depending on where the unclosed delimiter is in the file, you can get dozens or even hundreds of meaningless errors after the unclosed delimiter. Since terminals display the last output from a program, this means that the actual error gets completely buried. This afternoon I had to scroll through more than 200 lines of output to find where the actual error was. This can be reproduced by taking any reasonably large file, deleting the closing } of a function towards the top, and trying to build it.

Example Output
error: this file contains an un-closed delimiter
   --> src/controllers/helpers/pagination.rs:175:3
    |
16  | impl Page {
    |           - un-closed delimiter
17  |     fn new(params: &IndexMap<String, String>) -> CargoResult<Self> {
    |                                                                    - this delimiter might not be properly closed...
...
31  | }
    | - ...as it matches this but it has different indentation
...
175 | }
    |   ^

error: this file contains an un-closed delimiter
   --> src/controllers/helpers/pagination.rs:175:3
    |
16  | impl Page {
    |           - un-closed delimiter
17  |     fn new(params: &IndexMap<String, String>) -> CargoResult<Self> {
    |                                                                    - this delimiter might not be properly closed...
...
31  | }
    | - ...as it matches this but it has different indentation
...
175 | }
    |   ^

error: expected one of `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `struct`
  --> src/controllers/helpers/pagination.rs:34:12
   |
34 | pub(crate) struct PaginationOptions {
   |            ^^^^^^ expected one of 8 possible tokens here

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
  --> src/controllers/helpers/pagination.rs:39:1
error: expected one of `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `struct`
  --> src/controllers/helpers/pagination.rs:34:12
   |
34 | pub(crate) struct PaginationOptions {
   |            ^^^^^^ expected one of 8 possible tokens here

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
  --> src/controllers/helpers/pagination.rs:39:1
   |
37 | }
   |  - expected one of 11 possible tokens here
38 |
39 | impl PaginationOptions {
   | ^^^^ unexpected token

   |
37 | }
   |  - expected one of 11 possible tokens here
38 |
39 | impl PaginationOptions {
   | ^^^^ unexpected token

error: expected one of `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `trait`
  --> src/controllers/helpers/pagination.rs:69:12
   |
69 | pub(crate) trait Paginate: Sized {
   |            ^^^^^ expected one of 8 possible tokens here

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
  --> src/controllers/helpers/pagination.rs:78:1
   |
76 | }
   |  - expected one of 11 possible tokens here
77 |
78 | impl<T> Paginate for T {}
   | ^^^^ unexpected token

error: expected one of `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `trait`
  --> src/controllers/helpers/pagination.rs:69:12
   |
69 | pub(crate) trait Paginate: Sized {
   |            ^^^^^ expected one of 8 possible tokens here

error: expected one of `(`, `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `struct`
  --> src/controllers/helpers/pagination.rs:80:5
   |
80 | pub struct Paginated<T> {
   |     ^^^^^^ expected one of 9 possible tokens here

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
  --> src/controllers/helpers/pagination.rs:78:1
   |
76 | }
   |  - expected one of 11 possible tokens here
77 |
78 | impl<T> Paginate for T {}
   | ^^^^ unexpected token
error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
  --> src/controllers/helpers/pagination.rs:85:1
   |
83 | }
   |  - expected one of 11 possible tokens here

84 |
85 | impl<T> Paginated<T> {
   | ^^^^ unexpected token

error: expected one of `(`, `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `struct`
  --> src/controllers/helpers/pagination.rs:80:5
   |
80 | pub struct Paginated<T> {
   |     ^^^^^^ expected one of 9 possible tokens here

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:120:1
    |
118 | }
    |  - expected one of 11 possible tokens here
119 |
120 | impl<T> IntoIterator for Paginated<T> {
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
  --> src/controllers/helpers/pagination.rs:85:1
   |
83 | }
   |  - expected one of 11 possible tokens here
84 |
85 | impl<T> Paginated<T> {
   | ^^^^ unexpected token
error: expected one of `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `struct`
   --> src/controllers/helpers/pagination.rs:130:12
    |
130 | pub(crate) struct PaginatedQuery<T> {

    |            ^^^^^^ expected one of 8 possible tokens here

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:135:1
    |
133 | }
    |  - expected one of 11 possible tokens here
134 |
135 | impl<T> PaginatedQuery<T> {
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:120:1
    |
118 | }
    |  - expected one of 11 possible tokens here
119 |
120 | impl<T> IntoIterator for Paginated<T> {
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `default`, `existential`, `extern`, `fn`, `type`, or `unsafe`, found `struct`
   --> src/controllers/helpers/pagination.rs:130:12
    |
130 | pub(crate) struct PaginatedQuery<T> {
    |            ^^^^^^ expected one of 8 possible tokens here

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:149:1
    |
147 | }
    |  - expected one of 11 possible tokens here
148 |
149 | impl<T> QueryId for PaginatedQuery<T> {
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:135:1
    |
133 | }
    |  - expected one of 11 possible tokens here
134 |
135 | impl<T> PaginatedQuery<T> {
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:154:1
    |
152 | }
    |  - expected one of 11 possible tokens here
153 |
154 | impl<T: Query> Query for PaginatedQuery<T> {
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:149:1
    |
147 | }
    |  - expected one of 11 possible tokens here
148 |
149 | impl<T> QueryId for PaginatedQuery<T> {
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:158:1
    |
156 | }
    |  - expected one of 11 possible tokens here
157 |
158 | impl<T, DB> RunQueryDsl<DB> for PaginatedQuery<T> {}
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:154:1
    |
152 | }
    |  - expected one of 11 possible tokens here
153 |
154 | impl<T: Query> Query for PaginatedQuery<T> {
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:158:1
    |
156 | }
    |  - expected one of 11 possible tokens here
157 |
158 | impl<T, DB> RunQueryDsl<DB> for PaginatedQuery<T> {}
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:160:1
    |
158 | impl<T, DB> RunQueryDsl<DB> for PaginatedQuery<T> {}
    |                                                     - expected one of 11 possible tokens here
159 |
160 | impl<T> QueryFragment<Pg> for PaginatedQuery<T>
    | ^^^^ unexpected token

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `impl`
   --> src/controllers/helpers/pagination.rs:160:1
    |
158 | impl<T, DB> RunQueryDsl<DB> for PaginatedQuery<T> {}
    |                                                     - expected one of 11 possible tokens here
159 |
160 | impl<T> QueryFragment<Pg> for PaginatedQuery<T>
    | ^^^^ unexpected token
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 18, 2019
@estebank estebank added D-papercut Diagnostics: An error or lint that needs small tweaks. WG-diagnostics Working group: Diagnostics labels Oct 9, 2019
@estebank estebank self-assigned this Oct 25, 2019
tmandry added a commit to tmandry/rust that referenced this issue Nov 1, 2019
Reduce amount of errors given unclosed delimiter

When in a file with a non-terminated item, catch the error and consume
the block instead of trying to recover it on a more granular way in order to
reduce the amount of unrelated errors that would be fixed after adding
the missing closing brace. Also point out the possible location of the
missing closing brace.

Fix rust-lang#63690.
tmandry added a commit to tmandry/rust that referenced this issue Nov 1, 2019
Reduce amount of errors given unclosed delimiter

When in a file with a non-terminated item, catch the error and consume
the block instead of trying to recover it on a more granular way in order to
reduce the amount of unrelated errors that would be fixed after adding
the missing closing brace. Also point out the possible location of the
missing closing brace.

Fix rust-lang#63690.
@bors bors closed this as completed in f49f388 Nov 4, 2019
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 parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants