-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Reduce precedence of expressions that have an outer attr #134661
base: master
Are you sure you want to change the base?
Conversation
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
This comment has been minimized.
This comment has been minimized.
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
r? compiler |
☔ The latest upstream changes (presumably #134788) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased to resolve conflict. |
I'm going to look at this in a few hours. |
fn prefix_attrs_precedence(attrs: &AttrVec) -> ExprPrecedence { | ||
for attr in attrs { | ||
if let AttrStyle::Outer = attr.style { | ||
return ExprPrecedence::Prefix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ExprPrecedence::Prefix
isn't low enough. Consider the following cases involving binops:
#![feature(stmt_expr_attributes)]
macro_rules! group { ($e:expr) => { $e } }
macro_rules! extra { ($e:expr) => { #[allow()] $e } }
fn main() { // `-Zunpretty=expanded` on master & prefixattr:
let _ = #[allow()] 1 + 1; // let _ = #[allow()] 1 + 1;
let _ = group!(#[allow()] 1) + 1; // let _ = #[allow()] 1 + 1;
let _ = 1 + group!(#[allow()] 1); // let _ = 1 + #[allow()] 1;
let _ = extra!({ 0 }) + 1; // let _ = #[allow()] { 0 } + 1;
let _ = extra!({ 0 } + 1); // let _ = #[allow()] { 0 } + 1;
}
I haven't given it that much thought yet, so I don't know which specific precedence level(s) would make sense instead.
And indeed, this example is heavily inspired by the ones found in #15701 / #127436. So maybe answering this pretty-printing question is partially blocked by the open design question (meaning we can ignore it for now).
Previously,
-Zunpretty=expanded
would expand this program as follows:This is not the correct expansion. The correct output would have
(#[allow(deprecated)] thing).field
with the attribute applying only tothing
, not tothing.field
.