Skip to content

uniq: simplify matches - #16935

Merged
sylvestre merged 1 commit into
uutils:mainfrom
oech3:uniq-strip-pre
Nov 29, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
oech3:uniq-strip-pre

Conversation

@oech3

@oech3 oech3 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Comment thread src/uu/uniq/src/uniq.rs
// following slice should be treaded as value for this option
// even if it starts with '-' (which would be treated as hyphen prefixed value)
if slice.starts_with("--") {
if let Some(opt) = slice.strip_prefix("--") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the commit description says "simplify matches" but this is an unrelated improvement?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I intended to matches!(opt, O::SKIP_CHARS | O::SKIP_FIELDS | O::CHECK_CHARS) (which does not compile and contains is used).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This change would ideally deserve its own commit, though it’s fine to keep it in this PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah matches! doesn't work here because these are statics not constants:

error[E0532]: expected unit struct, unit variant or constant, found static `options::SKIP_CHARS`
   --> src/uu/uniq/src/uniq.rs:520:13
    |
520 |             options::SKIP_CHARS | options::SKIP_FIELDS | options::CHECK_CHARS

I wonder if we can change static to const:

pub mod options {
    pub const ALL_REPEATED: &str = "all-repeated";
    ...
}

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.

Yes, that's possible. I think we already have utils that use const for the options.

@sylvestre
sylvestre merged commit f2aee30 into uutils:main Nov 29, 2026
105 of 106 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

@oech3
oech3 deleted the uniq-strip-pre branch November 29, 2026 08:45
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.

4 participants