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

Internal lint: Ban pub re-exports #65233

Closed
Centril opened this issue Oct 9, 2019 · 11 comments
Closed

Internal lint: Ban pub re-exports #65233

Centril opened this issue Oct 9, 2019 · 11 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Centril
Copy link
Contributor

Centril commented Oct 9, 2019

Suggested lint name: rustc::pub_reexport.

When given something like the following, reject it (as a lint):

pub use syntax_pos::symbol;

cc #49509


Me and @Mark-Simulacrum were discussing library-ification and I mentioned to them how re-exports like this (specifically of syntax_pos::hygiene in the case of a refactoring I'm working on) was detrimental because it encourages relying on wider dependencies than strictly necessary. We want to fix the situation in #65031 and having this lint could help with that.

@Mark-Simulacrum had the idea of introducing an internal lint to ban it. This will cause some large diffs for syntax_pos::symbol:: in particular but that should be gradually fixable on a crate-by-crate basis through #![allow(...)] and it is mostly mechanical.

cc @oli-obk @nikomatsakis

@Centril Centril added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Oct 9, 2019
@eddyb
Copy link
Member

eddyb commented Oct 9, 2019

That specific example made me wonder if syntax_pos should be merged with rustc_lexer or be its own rustc_source_map or something along those lines. syntax_pos doesn't feel like it fits anywhere.

And Symbol specifically belongs in rustc_lexer, even if Span may not.

cc @petrochenkov @matklad

@petrochenkov
Copy link
Contributor

I actually wanted to do the opposite thing and reexport the whole syntax_pos from syntax for convenience.
There are almost no crates that depend on the former but don't need to depend the latter (rustc_errors?).

And Symbol specifically belongs in rustc_lexer, even if Span may not.

That includes the symbol interner.
(Unless rustc_lexer provides only the Symbol type but not a way to create it.)
Do other users of rustc_lexer need this global state?

@petrochenkov
Copy link
Contributor

I agree that it would be nice to cleanup random public reexports that are traces of various refactorings rather than conscious choices.
E.g. I recently removed some of those in rustc_metadata in d17296d.

@matklad
Copy link
Member

matklad commented Oct 9, 2019

And Symbol specifically belongs in rustc_lexer, even if Span may not.

Hm, I don't see this :) I see this as a very happy accident that rustc_lexer can exist as a separate crate as a pure algorithm without exposing any data structures at all.

Sharing data types would be a step back. Sharing state (the interner) would be even more problematic.

@eddyb
Copy link
Member

eddyb commented Oct 9, 2019

Oh, my bad, I forgot that rustc_lexer can function without Span or Symbol.

@nikomatsakis
Copy link
Contributor

I would be ok with this change. Even leaving aside the library-ification question, I personally find the "facade" style sort of confusing -- I'm never quite sure which name I should be importing. I'd prefer if we had one canonical path that we used everywhere. I also like to use rg as a simple "find all uses", and having more than one path by which something can be named makes that harder.

@RalfJung
Copy link
Member

In Miri we currently make heavy use of public re-exports. Namely, librustc_mir::interpret re-exports all of librustc::mir::interpret. I would prefer if we could keep it that way: The split of Miri between these two crates is mostly because some Miri types are needed in the wider compiler and hence have to live in librustc; when working inside the interpreter I generally could not care less about whether some type is defined here or there.

OTOH, for hir/syntax-level things, I have often been confused myself by all the reexports. When seeing two types of the same name (e.g. in the docs, comparing to what I have in my code), I never know if those are genuinely different or if one is a reexport of the other. So maybe the lesson is that the Miri part works for me just because I know better? I am not sure.

@Centril
Copy link
Contributor Author

Centril commented Oct 12, 2019

In Miri we currently make heavy use of public re-exports. Namely, librustc_mir::interpret re-exports all of librustc::mir::interpret. I would prefer if we could keep it that way: [...]

Would you be OK with just #[allow(...)]ing the lint for this specific re-export for now?

@RalfJung
Copy link
Member

Sure, the question is more if you'd be okay with that. ;)

@Centril
Copy link
Contributor Author

Centril commented Oct 12, 2019

Yeah sure, doesn't have to be all / at once or nothing with internal lints. :)

@jyn514
Copy link
Member

jyn514 commented Jan 1, 2021

I tried adding this (rust-lang/compiler-team#368) and it was rejected because it was too intrusive and people were used to using the re-exports. Does it still make sense to keep this open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants