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

#![no_implicit_prelude] cannot coexist with #[rustfmt::skip] and other tool-prelude attributes #106518

Open
mcy opened this issue Jan 6, 2023 · 3 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@mcy
Copy link
Contributor

mcy commented Jan 6, 2023

#![no_implicit_prelude] disables all preludes, including the tool prelude. However, unlike the std prelude and the extern prelude, there is no way to selectively re-enable it.

This has the concrete result that if I am writing a tool that generates Rust code and want to disable implicit symbols that may happen to clash with my own (hygine, etc), tool-generates symbols, I cannot mark the whole file as #![rustfmt::skip] to disable formatting, since it's machine-generated source code.

See https://godbolt.org/z/bfdKzG47E

@mcy
Copy link
Contributor Author

mcy commented Jan 6, 2023

There is also the related issue that it is possible to permanently shadow items from the tool prelude: https://godbolt.org/z/P5eYn69hz

Amusingly, the expected fixes do not work, because, again, these names are not real:

#[rustfmt::skip]
fn works() {}

#[::rustfmt::skip]
fn doesnt() {}

use rustfmt as x;
#[x::skip]
fn also_doesnt() {}

@PatchMixolydic
Copy link
Contributor

PatchMixolydic commented Jan 6, 2023

This even affects tools that are explicitly declared with #![register_tool] (playground):

#![feature(register_tool)]
#![no_implicit_prelude]
#![register_tool(a)]

#[a::skip]
fn main() {}
error[E0433]: failed to resolve: use of undeclared crate or module `a`
 --> src/main.rs:5:3
  |
5 | #[a::skip]
  |   ^ use of undeclared crate or module `a`

@jyn514 jyn514 added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 9, 2023
@jyn514
Copy link
Member

jyn514 commented Apr 9, 2023

cc #66079

@jyn514 jyn514 added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants