Skip to content

Suggest clone in user-write-code instead of inside macro #142569

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xizheyin
Copy link
Contributor

@xizheyin xizheyin commented Jun 16, 2025

Fixes #139253

Inspired by #142543

r? @fmease

@rustbot
Copy link
Collaborator

rustbot commented Jun 16, 2025

fmease is not on the review rotation at the moment.
They may take a while to respond.

@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 Jun 16, 2025
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Generally speaking, very much in favor. Thanks for considering this approach!

There still some unknowns I'd like solve, see my comment about struct field shorthands.

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 16, 2025
@xizheyin xizheyin marked this pull request as draft June 17, 2025 15:37
xizheyin added 2 commits June 17, 2025 23:42
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
xizheyin

This comment was marked as duplicate.

@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 (such as code changes or more information) from the author. labels Jun 17, 2025
Copy link
Contributor Author

@xizheyin xizheyin left a comment

Choose a reason for hiding this comment

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

@rustbot ready

Comment on lines +1 to +19
#[derive(Debug, Clone)]
struct Struct { field: S }

#[derive(Debug, Clone)]
struct S;

macro_rules! expand {
($ident:ident) => { Struct { $ident } }
}

fn test1() {
let field = &S;
let a: Struct = dbg!(expand!(field)); //~ ERROR mismatched types [E0308]
let b: Struct = dbg!(Struct { field }); //~ ERROR mismatched types [E0308]
let c: S = dbg!(field); //~ ERROR mismatched types [E0308]
let c: S = dbg!(dbg!(field)); //~ ERROR mismatched types [E0308]
}

fn main() {}
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 updated the test case and as you can see from the diff of the two commits, this has no effect on the shorthand case.

But this is actually strange, for the shorthand case, expr.span doesn't come from macro expansion, is this a bug? maybe fix it in another PR.

@xizheyin xizheyin marked this pull request as ready for review June 18, 2025 01:46
@xizheyin
Copy link
Contributor Author

r? compiler

@rustbot rustbot assigned davidtwco and unassigned fmease Jul 15, 2025
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

This is an improvement for one case, even if the shorthand fields are still incorrect, that can always be fixed in a follow-up.

@davidtwco
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 24, 2025

📌 Commit fd9c1b9 has been approved by davidtwco

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 24, 2025
fmease added a commit to fmease/rust that referenced this pull request Jul 24, 2025
Suggest clone in user-write-code instead of inside macro

Fixes rust-lang#139253

Inspired by rust-lang#142543

r? `@fmease`
bors added a commit that referenced this pull request Jul 24, 2025
Rollup of 16 pull requests

Successful merges:

 - #142569 (Suggest clone in user-write-code instead of inside macro)
 - #143401 (tests: Don't check for self-printed output in std-backtrace.rs test)
 - #143424 (clippy fix: rely on autoderef)
 - #143970 (Update core::mem::copy documentation)
 - #143979 (Test fixes for Arm64EC Windows)
 - #144160 (tests: debuginfo: Work around or disable broken tests on powerpc)
 - #144200 (Tweak output for non-`Clone` values moved into closures)
 - #144209 (Don't emit two `assume`s in transmutes when one is a subset of the other)
 - #144225 (Don't special-case llvm.* as nounwind)
 - #144314 (Hint that choose_pivot returns index in bounds)
 - #144316 (bootstrap: Move musl-root fallback out of sanity check)
 - #144364 (Update `dlmalloc` dependency of libstd)
 - #144368 (resolve: Remove `Scope::CrateRoot`)
 - #144373 (remove deprecated Error::description in impls)
 - #144390 (Remove dead code and extend test coverage and diagnostics around it)
 - #144392 (rustc_public: Remove movability from `RigidTy/AggregateKind::Coroutine`)

r? `@ghost`
`@rustbot` modify labels: rollup
fmease added a commit to fmease/rust that referenced this pull request Jul 25, 2025
Suggest clone in user-write-code instead of inside macro

Fixes rust-lang#139253

Inspired by rust-lang#142543

r? ``@fmease``
bors added a commit that referenced this pull request Jul 25, 2025
Rollup of 17 pull requests

Successful merges:

 - #142569 (Suggest clone in user-write-code instead of inside macro)
 - #143401 (tests: Don't check for self-printed output in std-backtrace.rs test)
 - #143424 (clippy fix: rely on autoderef)
 - #143970 (Update core::mem::copy documentation)
 - #143979 (Test fixes for Arm64EC Windows)
 - #144160 (tests: debuginfo: Work around or disable broken tests on powerpc)
 - #144200 (Tweak output for non-`Clone` values moved into closures)
 - #144209 (Don't emit two `assume`s in transmutes when one is a subset of the other)
 - #144225 (Don't special-case llvm.* as nounwind)
 - #144314 (Hint that choose_pivot returns index in bounds)
 - #144316 (bootstrap: Move musl-root fallback out of sanity check)
 - #144340 (UI test suite clarity changes: Rename `tests/ui/SUMMARY.md` and update rustc dev guide on `error-pattern`)
 - #144364 (Update `dlmalloc` dependency of libstd)
 - #144368 (resolve: Remove `Scope::CrateRoot`)
 - #144390 (Remove dead code and extend test coverage and diagnostics around it)
 - #144392 (rustc_public: Remove movability from `RigidTy/AggregateKind::Coroutine`)
 - #144424 (Allow setting `release-blog-post` label with rustbot)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 25, 2025
Suggest clone in user-write-code instead of inside macro

Fixes rust-lang#139253

Inspired by rust-lang#142543

r? ```@fmease```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 25, 2025
Suggest clone in user-write-code instead of inside macro

Fixes rust-lang#139253

Inspired by rust-lang#142543

r? ````@fmease````
bors added a commit that referenced this pull request Jul 25, 2025
Rollup of 16 pull requests

Successful merges:

 - #142569 (Suggest clone in user-write-code instead of inside macro)
 - #143401 (tests: Don't check for self-printed output in std-backtrace.rs test)
 - #143424 (clippy fix: rely on autoderef)
 - #143970 (Update core::mem::copy documentation)
 - #143979 (Test fixes for Arm64EC Windows)
 - #144160 (tests: debuginfo: Work around or disable broken tests on powerpc)
 - #144200 (Tweak output for non-`Clone` values moved into closures)
 - #144209 (Don't emit two `assume`s in transmutes when one is a subset of the other)
 - #144314 (Hint that choose_pivot returns index in bounds)
 - #144316 (bootstrap: Move musl-root fallback out of sanity check)
 - #144340 (UI test suite clarity changes: Rename `tests/ui/SUMMARY.md` and update rustc dev guide on `error-pattern`)
 - #144364 (Update `dlmalloc` dependency of libstd)
 - #144368 (resolve: Remove `Scope::CrateRoot`)
 - #144390 (Remove dead code and extend test coverage and diagnostics around it)
 - #144392 (rustc_public: Remove movability from `RigidTy/AggregateKind::Coroutine`)
 - #144424 (Allow setting `release-blog-post` label with rustbot)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 25, 2025
Rollup of 12 pull requests

Successful merges:

 - #142569 (Suggest clone in user-write-code instead of inside macro)
 - #143401 (tests: Don't check for self-printed output in std-backtrace.rs test)
 - #143424 (clippy fix: rely on autoderef)
 - #143970 (Update core::mem::copy documentation)
 - #143979 (Test fixes for Arm64EC Windows)
 - #144200 (Tweak output for non-`Clone` values moved into closures)
 - #144209 (Don't emit two `assume`s in transmutes when one is a subset of the other)
 - #144314 (Hint that choose_pivot returns index in bounds)
 - #144340 (UI test suite clarity changes: Rename `tests/ui/SUMMARY.md` and update rustc dev guide on `error-pattern`)
 - #144368 (resolve: Remove `Scope::CrateRoot`)
 - #144390 (Remove dead code and extend test coverage and diagnostics around it)
 - #144392 (rustc_public: Remove movability from `RigidTy/AggregateKind::Coroutine`)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

Inappropriate suggestion when mismatched types occur in the dbg! macro
5 participants