Skip to content

Remove wildcard imports#2892

Merged
apoelstra merged 1 commit intorust-bitcoin:masterfrom
jamillambert:20240619-wildcards
Jun 30, 2024
Merged

Remove wildcard imports#2892
apoelstra merged 1 commit intorust-bitcoin:masterfrom
jamillambert:20240619-wildcards

Conversation

@jamillambert
Copy link
Copy Markdown
Contributor

@jamillambert jamillambert commented Jun 20, 2024

This patch replaces prelude::* wildcard imports with the types actually used. In a couple of cases DisplayHex was previously imported by the wildcard but was only used in the test module, an additional import was added to the test module instead of at the top where it causes an unused import warning.

Close: #2875

@github-actions github-actions bot added the C-bitcoin PRs modifying the bitcoin crate label Jun 20, 2024
@coveralls
Copy link
Copy Markdown

coveralls commented Jun 20, 2024

Pull Request Test Coverage Report for Build 9600493574

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.119%

Totals Coverage Status
Change from base Build 9599304917: 0.0%
Covered Lines: 19548
Relevant Lines: 23518

💛 - Coveralls

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 20, 2024

Pull Request Test Coverage Report for Build 9600797335

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.119%

Totals Coverage Status
Change from base Build 9599304917: 0.0%
Covered Lines: 19548
Relevant Lines: 23518

💛 - Coveralls

Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

The prelude changes look good so far

Comment on lines 295 to 310
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These ones are ok to leave in, they are enum variants.

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 was hoping this was the answer, there are a lot of these.

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.

Should we update CONTRIBUTING.md to reflect this enum variant policy in

#### Import statements
?

Copy link
Copy Markdown
Contributor Author

@jamillambert jamillambert Jun 21, 2024

Choose a reason for hiding this comment

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

I think that's a good idea, add a policy that wildcard imports should not be used except in the three cases stated in #2875. I can add something to that effect and send it for review.

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.

Done in: #2894

@jamillambert
Copy link
Copy Markdown
Contributor Author

Thanks, I'll keep working on this and mark the PR as ready for review when done.

@github-actions github-actions bot added C-hashes PRs modifying the hashes crate C-units PRs modifying the units crate labels Jun 21, 2024
@coveralls
Copy link
Copy Markdown

coveralls commented Jun 21, 2024

Pull Request Test Coverage Report for Build 9616691165

Details

  • 3 of 6 (50.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.12%

Changes Missing Coverage Covered Lines Changed/Added Lines %
bitcoin/src/blockdata/locktime/absolute.rs 3 6 50.0%
Totals Coverage Status
Change from base Build 9605726098: 0.0%
Covered Lines: 19549
Relevant Lines: 23519

💛 - Coveralls

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 21, 2024

Pull Request Test Coverage Report for Build 9617084191

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.12%

Totals Coverage Status
Change from base Build 9605726098: 0.0%
Covered Lines: 19549
Relevant Lines: 23519

💛 - Coveralls

@jamillambert
Copy link
Copy Markdown
Contributor Author

I have removed all cases of wildcard imports that don't fit in one of the three exceptions given in the corresponding issue. As it happens they were all prelude imports.

@jamillambert jamillambert marked this pull request as ready for review June 21, 2024 17:26
@shinghim
Copy link
Copy Markdown
Contributor

Ack 7a24f66

@apoelstra
Copy link
Copy Markdown
Member

7a24f66 looks good to me. I'm unsure about the prelude module now. Usually the point of a "prelude" is that you wildcard-import it, which I hate, but somehow or other one showed up in this crate. On the other hand, we also use the prelude as a way to expose things like Vec which otherwise have a complicated feature-gated path.

I wonder whether we should move/reexport everything from the prelude at the root so we can replace prelude:: with nothing.

Anyway ACK this.

apoelstra
apoelstra previously approved these changes Jun 23, 2024
Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 7a24f66

@tcharding
Copy link
Copy Markdown
Member

tcharding commented Jun 24, 2024

After you rebase you need to run just check-api && git commit -a -m 'api: Run just check-api' -n

@tcharding
Copy link
Copy Markdown
Member

tcharding commented Jun 24, 2024

I wonder whether we should move/reexport everything from the prelude at the root so we can replace prelude:: with nothing.

I did it for bitcoin in 10846df

And then we could do the same in all crates. An obvious question is should be only import types used in the crate or just use a standard set for all crates?

@tcharding
Copy link
Copy Markdown
Member

I'm happy to merge this as is and do the "remove prelude" module separately or as part of this, up to you @jamillambert

@jamillambert
Copy link
Copy Markdown
Contributor Author

I would prefer to merge this to address the wildcard import issue, and then remove prelude separately. It does seem like two separate issues.

Sorry, I'll remember to run the just check-api and commit command next time, but let me know if you want me to add it to this PR before merging.

@tcharding
Copy link
Copy Markdown
Member

I would prefer to merge this to address the wildcard import issue, and then remove prelude separately. It does seem like two separate issues.

No worries

Sorry, I'll remember to run the just check-api and commit command next time, but let me know if you want me to add it to this PR before merging.

It has to be added to get past CI, we can't merge unless all CI jobs are green. You'll need to rebase on maste also to fix conflicts.

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 25, 2024

Pull Request Test Coverage Report for Build 9659098277

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.143%

Totals Coverage Status
Change from base Build 9639464882: 0.0%
Covered Lines: 19542
Relevant Lines: 23504

💛 - Coveralls

@jamillambert
Copy link
Copy Markdown
Contributor Author

Rebased on master to fix conflict and CI fail.

tcharding
tcharding previously approved these changes Jun 25, 2024
Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 3a28ce51562ba674e843717c2c3b7bf728c93873

@tcharding
Copy link
Copy Markdown
Member

Consider wrapping lines in commit messages at 72 characters bro (subject line should be 50 instead).

apoelstra
apoelstra previously approved these changes Jun 26, 2024
Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 3a28ce51562ba674e843717c2c3b7bf728c93873

@apoelstra
Copy link
Copy Markdown
Member

Sorry, #2915 seems to have conflicted with this. Needs rebase.

Wildcards have been replaced with what is actually used.

In a couple of cases an additional use statement was added to the test
module to import `DisplayHex` which is only used in test, but
previously imported with the wildcard at the top.
@jamillambert jamillambert dismissed stale reviews from apoelstra and tcharding via d099b9c June 28, 2024 07:04
@coveralls
Copy link
Copy Markdown

coveralls commented Jun 28, 2024

Pull Request Test Coverage Report for Build 9708833056

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.094%

Totals Coverage Status
Change from base Build 9702831343: 0.0%
Covered Lines: 19508
Relevant Lines: 23477

💛 - Coveralls

@jamillambert
Copy link
Copy Markdown
Contributor Author

Rebased to remove conflict and wrapped long lines in commit messages.

Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK d099b9c

Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK d099b9c

@apoelstra apoelstra merged commit d36141b into rust-bitcoin:master Jun 30, 2024
apoelstra added a commit to apoelstra/rust-bitcoin that referenced this pull request Aug 22, 2024
These were accidentally removed in rust-bitcoin#2892 and not noticed because of gaps
in all of our testing infrastructure. These gaps have been since fixed.
@apoelstra apoelstra mentioned this pull request Aug 22, 2024
@jamillambert jamillambert deleted the 20240619-wildcards branch September 4, 2024 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bitcoin PRs modifying the bitcoin crate C-hashes PRs modifying the hashes crate C-units PRs modifying the units crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove usage of wildcard imports

7 participants