Skip to content

Commit

Permalink
Emit rebinding only for interpolations that refer to a field
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 8, 2024
1 parent f4d5c2a commit 3ee0a4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 5 additions & 8 deletions impl/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ impl Display<'_> {
Ok(index) => MemberUnraw::Unnamed(Index { index, span }),
Err(_) => return Ok(()),
};
if !member_index.contains_key(&member) {
out += int;
continue;
}
member
}
'a'..='z' | 'A'..='Z' | '_' => {
Expand Down Expand Up @@ -109,16 +105,17 @@ impl Display<'_> {
Some('E') => Trait::UpperExp,
Some(_) => Trait::Display,
None => {
if member_index.contains_key(&member) {
has_bonus_display = true;
binding_value.extend(quote_spanned!(span=> .as_display()));
}
has_bonus_display = true;
binding_value.extend(quote_spanned!(span=> .as_display()));
Trait::Display
}
};
infinite_recursive |= member == *"self" && bound == Trait::Display;
if let Some(&field) = member_index.get(&member) {
implied_bounds.insert((field, bound));
} else {
out += &member.to_string();
continue;
}
let mut formatvar = IdentUnraw::new(match &member {
MemberUnraw::Unnamed(index) => format_ident!("__field{}", index),
Expand Down
9 changes: 9 additions & 0 deletions impl/src/unraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ impl MemberUnraw {
}
}

impl Display for MemberUnraw {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match self {
MemberUnraw::Named(this) => Display::fmt(this, formatter),
MemberUnraw::Unnamed(this) => Display::fmt(&this.index, formatter),
}
}
}

impl Eq for MemberUnraw {}

impl PartialEq for MemberUnraw {
Expand Down

0 comments on commit 3ee0a4d

Please sign in to comment.