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

Clairify ast::PatKind::Struct presese of .. by using an enum instead of a bool #119231

Merged
merged 1 commit into from
Dec 23, 2023

Conversation

aDotInTheVoid
Copy link
Member

The bool is mainly used for when a .. is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases.

See

let (fields, etc) = self.parse_pat_fields().unwrap_or_else(|mut e| {
e.span_label(path.span, "while parsing the fields for this pattern");
e.emit();
self.recover_stmt();
(ThinVec::new(), true)
});
self.bump();
Ok(PatKind::Struct(qself, path, fields, etc))
for the only place this is constructed.

r? @compiler-errors

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 22, 2023
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but I wonder if we could make it better

/// The `bool` is `true` in the presence of a `..`.
Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, /* recovered */ bool),
/// The `bool` is `true` in the presence of a `..` (or when recovered).
Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, bool),
Copy link
Member

@compiler-errors compiler-errors Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please either convert this into:

Struct {
    qself: Option<P<QSelf>>,
    path: Path,
    fields: ThinVec<PatField>,
    // Whether `..` is meant to capture the rest of the tuple fields
    rest: bool,
}

Or alternatively, change the bool into an enum like StructRest is used in StructExpr:

enum PatFieldsRest {
  Rest,
  None,
}

Do you think you could do either of these? I have no preference which, but I think we could do better 😸

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the latter is preferable, as it also clarifies it in the return type in the parser.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make the same change in HIR? Or can I leave that as a potential followup commit?

@aDotInTheVoid aDotInTheVoid changed the title Clairify ast::PatKind::Struct docs. Clairify ast::PatKind::Struct presese of .. by using an enum instead of a bool Dec 23, 2023
@rustbot
Copy link
Collaborator

rustbot commented Dec 23, 2023

Could not assign reviewer from: compiler-errors.
User(s) compiler-errors are either the PR author, already assigned, or on vacation, and there are no other candidates.
Use r? to specify someone else to assign.

@aDotInTheVoid
Copy link
Member Author

Pushed a version using the enum approach, only in the AST.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me when it's green

@@ -82,7 +82,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: self.lower_span(f.span),
}
}));
break hir::PatKind::Struct(qpath, fs, *etc);
break hir::PatKind::Struct(qpath, fs, *etc == ast::PatFieldsRest::Rest);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a follow-up perhaps

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Dec 23, 2023

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@aDotInTheVoid
Copy link
Member Author

Pushed a fix to tools. Should I add .is_rest() and .is_none() methods to PatFieldsRest, to avoid needing a load of ugly == methods everywhere?

@@ -324,7 +327,7 @@ fn rewrite_struct_pat(

let has_trailing_comma = fmt.needs_trailing_separator();

if ellipsis {
if ellipsis == ast::PatFieldsRest::None {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong

@compiler-errors
Copy link
Member

Should I add .is_rest() and .is_none() methods to PatFieldsRest, to avoid needing a load of ugly == methods everywhere?

Nah I think it's fine

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Dec 23, 2023

📌 Commit 03bed27 has been approved by compiler-errors

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 Dec 23, 2023
@aDotInTheVoid
Copy link
Member Author

sorry about making you review changes that i should have figured were broken here. i'll try to be less careless and make sure everything builds before opening next time

@compiler-errors

This comment was marked as off-topic.

@compiler-errors
Copy link
Member

Let's do that I guess then

@bors r-

@bors rollup

r=me after minimizing the rustfmt change

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 23, 2023
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Dec 23, 2023

📌 Commit 1349d86 has been approved by compiler-errors

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 23, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 23, 2023
…docs, r=compiler-errors

Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool

The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases.

See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed.

r? `@compiler-errors`
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 23, 2023
…iaskrgr

Rollup of 2 pull requests

Successful merges:

 - rust-lang#119072 (Clean up `check_consts` and misc fixes)
 - rust-lang#119231 (Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 23, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#119231 (Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool)
 - rust-lang#119232 (Fix doc typos)
 - rust-lang#119245 (Improve documentation for using warning blocks in documentation)
 - rust-lang#119248 (remove dead inferred outlives testing code)
 - rust-lang#119249 (Add spastorino to users_on_vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit bdc4480 into rust-lang:master Dec 23, 2023
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Dec 23, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 23, 2023
Rollup merge of rust-lang#119231 - aDotInTheVoid:PatKind-struct-bool-docs, r=compiler-errors

Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool

The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases.

See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed.

r? ``@compiler-errors``
flip1995 pushed a commit to flip1995/rust that referenced this pull request Dec 28, 2023
…docs, r=compiler-errors

Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool

The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases.

See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed.

r? ``@compiler-errors``
calebcartwright pushed a commit to calebcartwright/rust that referenced this pull request Jun 22, 2024
…docs, r=compiler-errors

Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool

The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases.

See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed.

r? ``@compiler-errors``
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants