Skip to content

Conversation

@jeremystucki
Copy link
Contributor

No description provided.

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this! I agree with some of these changes, but not all of them. If you want to go through and remove the ones I've noted, then I think this pretty much looks good to go. It would also be very helpful if you could format the commit messages in a style that is consistent with this repo. e.g., style: use is_empty instead of Use 'is_empty'.

/// be beneficial to avoid finding sub-captures.
///
/// In general, this is called once for every call to `replacen`.
fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, [u8]>> {
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm I'd actually rather have these lifetimes. I don't agree with all flavors of lifetime elision. In particular, it's not necessarily obvious that the returned Cow has a lifetime attached to sefl when the lifetimes are elided.

Copy link
Member

Choose a reason for hiding this comment

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

I think this comment applies to all changes in this commit except for ClassQuery, which I like.

Copy link
Contributor

Choose a reason for hiding this comment

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

I might be wrong, but I think fn class(query: ClassQuery) will trigger a warning once edition lints are enabled. I think it is supposed to be spelled pub fn class(query: ClassQuery<'_>), ie, 2018 edition soft-deprecates lifetime elision outside of & and &mut. Similarly, the best way to spell this fn might be fn no_expansion(&mut self) -> Option<Cow<'_, [u8]>>. The '_ syntax was stablized in 1.26, so I think we can use it.

Copy link
Member

Choose a reason for hiding this comment

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

Not a huge fan of the '_ syntax either to be honest... I like the fact that lifetime parameters are introduced just like type parameters.

I'll likely give in once regex switches to 2018, but I'd prefer to just leave well enough alone for now. :-)

self.re.find_at(self.text, self.last_match).map(|(s, e)| {
self.last_match = e;
(s, e)
})
Copy link
Member

Choose a reason for hiding this comment

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

I personally am not a fan of using map combined with mutations on other objects. Maybe revert this change and others like it above?

}
cls.iter().next().is_none().ok_or_else(|| {
self.error(ast.span, ErrorKind::EmptyClassNotAllowed)
})?;
Copy link
Member

Choose a reason for hiding this comment

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

This also just reads weird to me. It feels much more natural as an if statement.

src/utf8.rs Outdated
} else {
Some((cp, n))
}
})
Copy link
Member

Choose a reason for hiding this comment

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

I prefer the previous version. Here, you have to process a monadic bind followed by case analysis. Before, it was just case analysis.

@jeremystucki
Copy link
Contributor Author

r? @BurntSushi

BurntSushi pushed a commit that referenced this pull request Jan 9, 2020
@BurntSushi BurntSushi closed this in 2f3fd66 Jan 9, 2020
@jeremystucki jeremystucki deleted the refactoring branch January 9, 2020 22:26
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.

3 participants