Skip to content

Commit

Permalink
Merge pull request #376 from dtolnay/check
Browse files Browse the repository at this point in the history
Check invalid Named member references before producing MemberUnraw
  • Loading branch information
dtolnay authored Nov 8, 2024
2 parents 2f6bff3 + 1bb7e7a commit f728f12
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions impl/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,25 @@ impl Display<'_> {
if read.starts_with("r#") {
continue;
}
let ident = Ident::new(take_ident(&mut read), span);
MemberUnraw::Named(IdentUnraw::new(ident))
let repr = take_ident(&mut read);
if repr == "_" {
// Invalid. Let rustc produce the diagnostic.
out += repr;
continue;
}
let ident = IdentUnraw::new(Ident::new(repr, span));
if user_named_args.contains(&ident) {
// Refers to a named argument written by the user, not to field.
out += repr;
continue;
}
MemberUnraw::Named(ident)
}
_ => continue,
};
let mut formatvar = match &member {
MemberUnraw::Unnamed(index) => IdentUnraw::new(format_ident!("__field{}", index)),
MemberUnraw::Named(ident) => {
if user_named_args.contains(ident) || ident == "_" {
// Refers to a named argument written by the user, not to field.
out += &ident.to_string();
continue;
}
IdentUnraw::new(format_ident!("__field_{}", ident.to_string()))
}
};
Expand Down

0 comments on commit f728f12

Please sign in to comment.