-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
base: master
Are you sure you want to change the base?
Conversation
|
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.
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.
tests/ui/typeck/suggestions/suggest-clone-in-macro-issue-139253.rs
Outdated
Show resolved
Hide resolved
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
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.
@rustbot ready
#[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() {} |
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 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.
Fixes #139253
Inspired by #142543
r? @fmease