Skip to content

Commit

Permalink
Add comment to RewriteVisitor's visit_expr_mut function
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Oct 2, 2024
1 parent 72750c6 commit baaa4ed
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ impl VisitMut for RewriteVisitor {
#[allow(unused_imports)]
use cast_checks::MaybeTryIntoFallback;

// smoelius: It is tempting to want to use `TryFrom` here rather than `TryInto`.
// However, there are at least two reasons to prefer `TryInto`:
// - Practical: Though developers should not implement `TryInto` directly, they may.
// Thus, using `TryInto` can catch more cases.
// - Aesthetic: The value `#operand` is wrapped in a `MaybeTryInto`, which becomes
// the `self` argument to `maybe_try_into`. Thus, `TryInto` better resembles the
// underlying implementation.
#[allow(unused_parens, clippy::double_parens)]
if let Some(result) = cast_checks::MaybeTryInto::<_, #ty >::new( #operand ).maybe_try_into() {
result.expect( #msg )
Expand Down

0 comments on commit baaa4ed

Please sign in to comment.