0

Pass real crate-level attributes to `pre_expansion_lint` by smoelius · Pull Requ...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/89214
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Contributor

smoelius commented on Sep 24, 2021

edited

The PR concerns the unstable feature register_tool (#66079).

The feature's implementation requires the attributes of the crate being compiled, so that when attributes like allow(foo::bar) are encountered, it can be verified that register_tool(foo) appears in the crate root.

However, the crate's attributes are not readily available during early lint passes. Specifically, on this line, krate.attrs appears to be the attributes of the current source file, not the attributes of the whole crate:

builder: LintLevelsBuilder::new(sess, warn_about_weird_lints, lint_store, &krate.attrs),

Consequently, "unknown tool" errors were being produced when allow(foo::bar) appeared in a submodule, even though register_tool(foo) appeared in the crate root.

EDITED: The proposed fix is to obtain the real crate-level attributes in configure_and_expand and pass them to pre_expansion_lint. (See @petrochenkov's comment below.)

The original "prosed fix" text follows.


The proposed fix is to add an error_on_unknown_tool flag to LintLevelsBuilder. The flag controls whether "unknown tool" errors are emitted. The flag is set during late passes, but not earlier.

More specifically, this PR contains two commits:

  • The first adds a known-tool-in-submodule UI test that does not currently pass.
  • The second adds the error_on_unknown_tool flag. The new test passes with the addition of this flag.

This change has the added benefit of eliminating some errors that were duplicated in existing tests.

To the reviewer: please check that I implemented the UI test correctly.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK