Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
Fix binary op lifetime inference (#12)
Browse files Browse the repository at this point in the history

* fix lifetimes for borrowed-borrowed binary ops

* added RELEASES.md and bumped patch version
  • Loading branch information
brianwp3000 authored Jul 10, 2017
1 parent a226f53 commit 0f5668e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "impl_ops"
version = "0.1.0"
version = "0.1.1"
authors = ["Brian Porter <[email protected]>"]
license="MIT"
description = "Macros for easy operator overloading."
keywords = ["macro", "operator", "overloading", "impl", "op"]
categories = ["Rust patterns"]
categories = ["rust-patterns"]
repository = "https://github.com/brianwp3000/impl_ops"
include = [
"**/*.rs",
Expand Down
7 changes: 7 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Version 0.1
===========
* Initial release

Version 0.1.1
=============
* Fixed lifetime inference bug with binary operators
6 changes: 3 additions & 3 deletions src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ macro_rules! _impl_binary_op_owned_borrowed {
impl<'a> ops::$ops_trait<&'a $rhs> for $lhs {
type Output = $out;

fn $ops_fn(self, $rhs_i: &'a $rhs) -> Self::Output {
fn $ops_fn(self, $rhs_i: &$rhs) -> Self::Output {
let $lhs_i = self;
$body
}
Expand Down Expand Up @@ -82,10 +82,10 @@ macro_rules! _impl_binary_op_borrowed_owned {
#[macro_export]
macro_rules! _impl_binary_op_borrowed_borrowed {
($ops_trait:ident, $ops_fn:ident, $lhs:ty, $rhs:ty, $out:ty, $lhs_i:ident, $rhs_i:ident, $body:block) => (
impl<'a> ops::$ops_trait<&'a $rhs> for &'a $lhs {
impl<'a, 'b> ops::$ops_trait<&'a $rhs> for &'b $lhs {
type Output = $out;

fn $ops_fn(self, $rhs_i: &'a $rhs) -> Self::Output {
fn $ops_fn(self, $rhs_i: &$rhs) -> Self::Output {
let $lhs_i = self;
$body
}
Expand Down
14 changes: 14 additions & 0 deletions tests/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,18 @@ mod multiline {
assert_eq!(kong::Donkey::new(2 * 1), &kong::Barrel::new(1) * kong::Donkey::new(2));
assert_eq!(kong::Donkey::new(2 * 1), &kong::Barrel::new(1) * &kong::Donkey::new(2));
}
}

fn do_bitor(a: &kong::Donkey, b: &kong::Dixie) -> kong::Diddy {
a | b
}

fn do_bitor_2(a: &kong::Dixie, b: &kong::Donkey) -> kong::Diddy {
a | b
}

#[test]
fn infer_lifetimes() {
assert_eq!(kong::Diddy::new(1 | 2), do_bitor(&kong::Donkey::new(1), &kong::Dixie::new(2)));
assert_eq!(kong::Diddy::new(2 | 1), do_bitor_2(&kong::Dixie::new(1), &kong::Donkey::new(2)));
}

0 comments on commit 0f5668e

Please sign in to comment.