Skip to content

Commit baaa4ed

Browse files
committed
Add comment to RewriteVisitor's visit_expr_mut function
1 parent 72750c6 commit baaa4ed

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

macro/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ impl VisitMut for RewriteVisitor {
100100
#[allow(unused_imports)]
101101
use cast_checks::MaybeTryIntoFallback;
102102

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

0 commit comments

Comments
 (0)