Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

nnethercote
Copy link
Contributor

ModKind::Loaded has an inline field and a had_parse_error field. If the inline field is Inline::Yes then had_parse_error must be Ok(()).

This commit moves the had_parse_error field into the Inline::No variant. This makes it impossible to create the nonsensical combination of inline == Inline::Yes and had_parse_error = Err(_).

r? @Urgau

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Aug 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 19, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@rust-log-analyzer

This comment has been minimized.

`ModKind::Loaded` has an `inline` field and a `had_parse_error` field.
If the `inline` field is `Inline::Yes` then `had_parse_error` must be
`Ok(())`.

This commit moves the `had_parse_error` field into the `Inline::No`
variant. This makes it impossible to create the nonsensical combination
of `inline == Inline::Yes` and `had_parse_error = Err(_)`.
@petrochenkov
Copy link
Contributor

That combination is not nonsensical, parse_mod for inline modules could quite reasonably produce a similar had_parse_error flag, so this seems to be an overfitting for the current state.

@nnethercote
Copy link
Contributor Author

It's not overfitting. If you are parsing an inline mod and there's a parse error, then ModKind simply won't be produced.

@Urgau
Copy link
Member

Urgau commented Aug 20, 2025

The code looks good, but I don't have enough context to know if it's a sensible thing to do.
r? petrochenkov

@rustbot rustbot assigned petrochenkov and unassigned Urgau Aug 20, 2025
@petrochenkov
Copy link
Contributor

So the best recovery strategy for both inline and out-of-line modules would be to always produce an AST module, parse as many items as possible inside it, and produce an "incompleteness" flag like had_parse_error if there's also some unparsed stuff in the module.

I'm not aware of any specific plans to implement that, and this change is small, so I don't see much harm in merging it.
It can be reverted if a better recovery strategy for modules is implemented.
@bors r+

@bors
Copy link
Collaborator

bors commented Aug 20, 2025

📌 Commit bfd5d59 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 20, 2025
@nnethercote
Copy link
Contributor Author

@bors rollup

jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 21, 2025
…ochenkov

Prevent impossible combinations in `ast::ModKind`.

`ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`.

This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`.

r? `@Urgau`
bors added a commit that referenced this pull request Aug 21, 2025
Rollup of 15 pull requests

Successful merges:

 - #143383 (stabilize `const_array_each_ref`)
 - #144758 ([Doc] Add links to the various collections)
 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145137 (Consolidate panicking functions in `slice/index.rs`)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145297 (fix(debuginfo): handle false positives in overflow check)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145590 (Prevent impossible combinations in `ast::ModKind`.)
 - #145621 (Fix some doc typos)
 - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - #145650 (Fix JS search scripts path)
 - #145654 (Download CI GCC into the correct directory)
 - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - #145674 (Enable triagebot `[review-changes-since]` feature)
 - #145678 (Fix typo in docstring)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 21, 2025
…ochenkov

Prevent impossible combinations in `ast::ModKind`.

`ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`.

This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`.

r? ``@Urgau``
bors added a commit that referenced this pull request Aug 21, 2025
Rollup of 19 pull requests

Successful merges:

 - #143383 (stabilize `const_array_each_ref`)
 - #144758 ([Doc] Add links to the various collections)
 - #144915 (Defer tail call ret ty equality to check_tail_calls)
 - #145256 (Add new `--test-codegen-backend` bootstrap option)
 - #145297 (fix(debuginfo): handle false positives in overflow check)
 - #145390 (Shorten some dependency chains in the compiler)
 - #145415 (std_detect: RISC-V: implement implication to "C")
 - #145525 (stdlib: Replace typedef -> type alias in doc comment)
 - #145590 (Prevent impossible combinations in `ast::ModKind`.)
 - #145593 (UnsafePinned::raw_get: sync signature with get)
 - #145621 (Fix some doc typos)
 - #145627 (Unconditionally-const supertraits are considered not dyn compatible)
 - #145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - #145650 (Fix JS search scripts path)
 - #145654 (Download CI GCC into the correct directory)
 - #145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - #145673 (Add flock support for cygwin)
 - #145674 (Enable triagebot `[review-changes-since]` feature)
 - #145678 (Fix typo in docstring)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 25b81bf into rust-lang:master Aug 21, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 21, 2025
rust-timer added a commit that referenced this pull request Aug 21, 2025
Rollup merge of #145590 - nnethercote:ModKind-Inline, r=petrochenkov

Prevent impossible combinations in `ast::ModKind`.

`ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`.

This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`.

r? ```@Urgau```
flip1995 pushed a commit to flip1995/rust that referenced this pull request Aug 22, 2025
…ochenkov

Prevent impossible combinations in `ast::ModKind`.

`ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`.

This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`.

r? ```@Urgau```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants