Skip to content

RFC: remove pub use globs #11870

Closed
Closed
@pnkfelix

Description

@pnkfelix

A recent chat I had with pcwalton led me to believe that many of the difficulties we have with globs in use declarations would be resolved if we simply restricted globs solely to imports, i.e. removed glob re-exports via pub use.

Removing pub use globs would imply that when rustc looks at the text of a module, it can locally determine all of the names that it exports. I think this would enable us to make a much simpler resolve algorithm: one pass to associate each module with the set of names it exports, and then a second pass to wire up the glob imports. (It still doesn't necessarily know which of the type/value namespaces the imported/exported names belong to, so resolve still remains non-trivial, but I think that's okay.)

This is meant as an alternative more-conservative option to #11825. In particular, Servo's use-case as documented by jack should continue to function under this plan, if I'm correct in inferring that the auto-generated code-bindings are solely creating imports.

(globs are feature-guarded for 1.0, so choosing a strategy here need not block the release. But it would probably make people more comfortable knowing how drastic a change to globs we might make.)

(I have been careful in my weasel wording above not to claim that all problems with globs stem from pub use alone, since bugs like #3352 do not even use pub use. But I suspect such bugs are artifacts of an complicated implementation strategy necessitated by pub use, and so I still think this route is worth considering.)


I will admit up front: glob imports are not a must-have feature for me; I'd be okay if #11825 landed instead of this approach. But I do think there is value in providing a way for people who want to play with some library to snag all of the functionality it provides trivially, especially for humans who learn via play.

Metadata

Metadata

Assignees

Labels

A-resolveArea: Name/path resolution done by `rustc_resolve` specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions