Skip to content

Conversation

ada4a
Copy link
Contributor

@ada4a ada4a commented Sep 19, 2025

Fixes #14552

changelog: [new_without_default]: if new has #[cfg], copy that onto impl Default

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2025

r? @samueltardieu

rustbot has assigned @samueltardieu.
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

This comment has been minimized.

@ada4a ada4a force-pushed the new_without_default branch from 6a4abd0 to ae2ebd6 Compare September 29, 2025 20:26
@rustbot
Copy link
Collaborator

rustbot commented Sep 29, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@ada4a
Copy link
Contributor Author

ada4a commented Sep 29, 2025

This range-diff thing is awesome:)

return;
}

let mut appl = Applicability::MachineApplicable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applicability is usually stored into app or applicability. There is only one existing instance of appl (against more than 80 for the others), let's not use this.

Comment on lines 122 to 138
[] => String::new(),
[attr] if attr.has_name(sym::cfg_trace) => {
format!(
"{}\n",
snippet_with_applicability(cx.sess(), attr.span(), "_", &mut appl)
)
},
_ => {
// There might be some other attributes which the `impl Default` ought to inherit from `fn new`.
// At the same time, there are many attributes that actually can't be put on an impl block --
// like `#[inline]`, for example. And for some attributes we can't even build a suggestion,
// since `Attribute::span` may panic. Because of all this, remain conservative: don't inherit
// any attrs, and just reduce the applicability
appl = Applicability::MaybeIncorrect;
String::new()
},
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not extract all #[cfg] attributes and repeat them? Why just one, and only if it is alone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought having multiple #[cfg] attributes would be disallowed -- if one of them is false, then the item under it is removed, leaving the rest of the attributes dangle -- but it turns out Rust is (unsurprisingly) smarter than that

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Sep 29, 2025
- reduce indentation
- use `snippet_with_applicability`
@ada4a ada4a force-pushed the new_without_default branch from ae2ebd6 to a1ac9e6 Compare September 29, 2025 23:18
@ada4a
Copy link
Contributor Author

ada4a commented Sep 29, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Sep 29, 2025
@ada4a ada4a force-pushed the new_without_default branch from a1ac9e6 to 7a04ada Compare September 29, 2025 23:24
@samueltardieu samueltardieu added this pull request to the merge queue Sep 30, 2025
Merged via the queue into rust-lang:master with commit 189b4c3 Sep 30, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 30, 2025
@ada4a ada4a deleted the new_without_default branch September 30, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-fix for new_without_default ignores conditional compilation

3 participants