diff options
| author | bors <bors@rust-lang.org> | 2015-03-30 14:25:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-03-30 14:25:48 +0000 |
| commit | 9de34a84bb300bab1bf0227f577331620cd60511 (patch) | |
| tree | 6b1519a5381ecfe0d59e7d9b785c0934e096606d /src/libsyntax | |
| parent | 14192d6df5cc714e5c9a3ca70b08f2514d977be2 (diff) | |
| parent | 7595c25ef93bb18b5f96805daee4d1890f5b6a6b (diff) | |
| download | rust-9de34a84bb300bab1bf0227f577331620cd60511.tar.gz rust-9de34a84bb300bab1bf0227f577331620cd60511.zip | |
Auto merge of #23673 - nikomatsakis:issue-23319-binops-ng-5, r=pnkfelix
The current binary operator code assumed that if the LHS was a scalar (`i32` etc), then the RHS had to match. This is not true with multidispatch. This PR generalizes the existing code to (primarily) use the traits -- this also allows us to defer the precise type-checking when the types aren't fully known. The one caveat is the unstable SIMD types, which don't fit in with the current traits -- in that case, the LHS type must be known to be SIMD ahead of time. There is one semi-hacky bit in that during writeback, for builtin operators, if the types resolve to scalars (i32 etc) then we clear the method override. This is because we know what the semantics are and it is more efficient to generate the code directly. It also ensures that we can use these overloaded operators in constants and so forth. cc @japaric cc @aturon Fixes #23319 (and others).
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast_util.rs | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index b7aa2aebbfa..b83b42c73e7 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -86,33 +86,17 @@ pub fn is_shift_binop(b: BinOp_) -> bool { pub fn is_comparison_binop(b: BinOp_) -> bool { match b { - BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true, - _ => false + BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => + true, + BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem | + BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr => + false, } } /// Returns `true` if the binary operator takes its arguments by value pub fn is_by_value_binop(b: BinOp_) -> bool { - match b { - BiAdd | BiSub | BiMul | BiDiv | BiRem | BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr => { - true - } - _ => false - } -} - -/// Returns `true` if the binary operator is symmetric in the sense that LHS -/// and RHS must have the same type. So the type of LHS can serve as an hint -/// for the type of RHS and vice versa. -pub fn is_symmetric_binop(b: BinOp_) -> bool { - match b { - BiAdd | BiSub | BiMul | BiDiv | BiRem | - BiBitXor | BiBitAnd | BiBitOr | - BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => { - true - } - _ => false - } + !is_comparison_binop(b) } /// Returns `true` if the unary operator takes its argument by value |
