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

Reduce precedence of expressions that have an outer attr #134661

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Dec 22, 2024

Previously, -Zunpretty=expanded would expand this program as follows:

#![feature(stmt_expr_attributes)]

macro_rules! repro {
    ($e:expr) => {
        #[allow(deprecated)] $e
    };
}

#[derive(Default)]
struct Thing {
    #[deprecated]
    field: i32,
}

fn main() {
    let thing = Thing::default();
    let _ = repro!(thing).field;
}
#![feature(prelude_import)]
#![feature(stmt_expr_attributes)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;

struct Thing {
    #[deprecated]
    field: i32,
}

#[automatically_derived]
impl ::core::default::Default for Thing {
    #[inline]
    fn default() -> Thing {
        Thing { field: ::core::default::Default::default() }
    }
}

fn main() {
    let thing = Thing::default();
    let _ = #[allow(deprecated)] thing.field;
}

This is not the correct expansion. The correct output would have (#[allow(deprecated)] thing).field with the attribute applying only to thing, not to thing.field.

@dtolnay dtolnay added A-pretty Area: Pretty printing (including `-Z unpretty`) F-stmt_expr_attributes `#![feature(stmt_expr_attributes)]` labels Dec 22, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 22, 2024

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 22, 2024
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Dec 22, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@fee1-dead
Copy link
Member

r? compiler

@rustbot rustbot assigned fmease and unassigned fee1-dead Dec 23, 2024
@bors
Copy link
Contributor

bors commented Dec 26, 2024

☔ The latest upstream changes (presumably #134788) made this pull request unmergeable. Please resolve the merge conflicts.

@dtolnay
Copy link
Member Author

dtolnay commented Dec 26, 2024

Rebased to resolve conflict.

@fmease
Copy link
Member

fmease commented Dec 28, 2024

I'm going to look at this in a few hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) F-stmt_expr_attributes `#![feature(stmt_expr_attributes)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants