Skip to content

Refactor maybe_item to use Marker argument - #987

Merged
bors[bot] merged 2 commits into
rust-lang:masterfrom
pcpthm:marker_argument
Mar 18, 2019
Merged

bors[bot] merged 2 commits into
rust-lang:masterfrom
pcpthm:marker_argument

Conversation

@pcpthm

@pcpthm pcpthm commented Mar 17, 2019 •

Copy link
Copy Markdown
Contributor

As suggested at #980 (comment).
For expression paring functions, changing signature

  • from fn(&mut Parser) -> Option<CompletedMarker> to fn(&mut Parser, Marker) -> Result<CompletedMarker, Marker>
  • from fn(&mut Parser) -> CompletedMarker to fn(&mut Parser, Marker) -> CompletedMarker
    is my plan.

@bors

bors Bot commented Mar 17, 2019

Copy link
Copy Markdown
Contributor

✌️ pcpthm can now approve this pull request

@matklad matklad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sweet, this is significantly simpler now!

I've left a couple of stylistic comments, but otherwise r=me

bors delegate+

Comment thread crates/ra_parser/src/grammar/items.rs Outdated
m.complete(p, ERROR);
None
} else {
Some(m)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of lislint None in every branch, I think we can use return Some here, and then just a single None at the end of the function

Comment thread crates/ra_parser/src/grammar/items.rs Outdated
}
m = match maybe_item(p, m, flavor) {
Some(m) => m,
None => return,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This gave me a pause: Option has an inverted modality here, where None means "success" and Some is an error. What do you think about making the return type be Result<(), Marker> instead?

m.complete(p, kind);
}
items::MaybeItem::Modifiers => {
m = match items::maybe_item(p, m, items::ItemFlavor::Mod) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tink we can write let m = here, to avoid making m mutable.

@pcpthm

pcpthm commented Mar 18, 2019

Copy link
Copy Markdown
Contributor Author

bors r+

bors Bot added a commit that referenced this pull request Mar 18, 2019
987: Refactor maybe_item to use Marker argument r=pcpthm a=pcpthm

As suggested at <#980 (comment)>.
For expression paring functions, changing signature
- from `fn(&mut Parser) -> Option<CompletedMarker>` to `fn(&mut Parser, Marker) -> Result<CompletedMarker, Marker>`
- from `fn(&mut Parser) -> CompletedMarker` to `fn(&mut Parser, Marker) -> CompletedMarker`
is my plan.

Co-authored-by: pcpthm <pcpthm@gmail.com>
@bors

bors Bot commented Mar 18, 2019

Copy link
Copy Markdown
Contributor

Build succeeded

@bors
bors Bot merged commit 3d9c2be into rust-lang:master Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants