From 300072b5f36f68d0fda51a53427ee97e7147c85b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 3 Dec 2020 12:12:24 -0800 Subject: [PATCH] Touch up PR 538 --- include/cxx.h | 20 +++++++++++--------- tests/ffi/tests.cc | 3 +-- tests/test.rs | 13 ++++++++----- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/include/cxx.h b/include/cxx.h index cbaf1292..da0194a8 100644 --- a/include/cxx.h +++ b/include/cxx.h @@ -752,12 +752,14 @@ void Vec::emplace_back(Args &&... args) { } template -typename Vec::iterator::reference Vec::iterator::operator*() const noexcept { +typename Vec::iterator::reference +Vec::iterator::operator*() const noexcept { return *static_cast(this->pos); } template -typename Vec::iterator::pointer Vec::iterator::operator->() const noexcept { +typename Vec::iterator::pointer +Vec::iterator::operator->() const noexcept { return static_cast(this->pos); } @@ -811,17 +813,17 @@ Vec::iterator::operator-=(Vec::iterator::difference_type n) noexcept { template typename Vec::iterator Vec::iterator::operator+( Vec::iterator::difference_type n) const noexcept { - auto temp = iterator(*this); - temp.pos = static_cast(this->pos) + this->stride * n; - return temp; + auto ret = iterator(*this); + ret.pos = static_cast(this->pos) + this->stride * n; + return ret; } template typename Vec::iterator Vec::iterator::operator-( Vec::iterator::difference_type n) const noexcept { - auto temp = iterator(*this); - temp.pos = static_cast(this->pos) - this->stride * n; - return temp; + auto ret = iterator(*this); + ret.pos = static_cast(this->pos) - this->stride * n; + return ret; } template @@ -829,7 +831,7 @@ typename Vec::iterator::difference_type Vec::iterator::operator-(const iterator &other) const noexcept { auto diff = std::distance(static_cast(other.pos), static_cast(this->pos)); - return diff / stride; + return diff / this->stride; } template diff --git a/tests/ffi/tests.cc b/tests/ffi/tests.cc index 485346fe..2be1e061 100644 --- a/tests/ffi/tests.cc +++ b/tests/ffi/tests.cc @@ -369,8 +369,7 @@ void c_take_rust_vec_shared_sort(rust::Vec v) { // Exercise requirements of RandomAccessIterator. // https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator std::sort(v.begin(), v.end()); - if (v[0].z == 0 && v[1].z == 2 && v[2].z == 4 && v[3].z == 7) - { + if (v[0].z == 0 && v[1].z == 2 && v[2].z == 4 && v[3].z == 7) { cxx_test_suite_set_correct(); } } diff --git a/tests/test.rs b/tests/test.rs index a2723354..00a7228b 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -149,10 +149,13 @@ fn test_c_take() { check!(ffi::c_take_rust_vec_shared_forward_iterator( shared_test_vec, )); - let shared_sort_vec = vec![ffi::Shared { z: 2 }, ffi::Shared { z: 0 }, ffi::Shared { z: 7 }, ffi::Shared { z: 4 }]; - check!(ffi::c_take_rust_vec_shared_sort( - shared_sort_vec, - )); + let shared_sort_vec = vec![ + ffi::Shared { z: 2 }, + ffi::Shared { z: 0 }, + ffi::Shared { z: 7 }, + ffi::Shared { z: 4 }, + ]; + check!(ffi::c_take_rust_vec_shared_sort(shared_sort_vec)); check!(ffi::c_take_ref_rust_vec(&test_vec)); check!(ffi::c_take_ref_rust_vec_index(&test_vec)); check!(ffi::c_take_ref_rust_vec_copy(&test_vec)); @@ -207,7 +210,7 @@ fn test_c_method_calls() { assert_eq!(2021, unique_ptr.pin_mut().set(2021)); assert_eq!(2021, unique_ptr.get()); assert_eq!(2021, unique_ptr.get2()); - assert_eq!(2022, unique_ptr.pin_mut().set_succeed(2022).unwrap(),); + assert_eq!(2022, unique_ptr.pin_mut().set_succeed(2022).unwrap()); assert!(unique_ptr.pin_mut().get_fail().is_err()); assert_eq!(2021, ffi::Shared { z: 0 }.c_method_on_shared());