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

Draft
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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

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