Skip to content

Stop implementing methods on SImpl - #696

Merged
nunoplopes merged 5 commits into
Cpp2Rust:masterfrom
lucic71:ptr-receiver-ref
Dec 3, 2026
Merged

nunoplopes merged 5 commits into
Cpp2Rust:masterfrom
lucic71:ptr-receiver-ref

Conversation

@lucic71

@lucic71 lucic71 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Before:

pub trait SImpl {
    fn m(&self) {
        unimplemented!()
    }
}

impl SImpl for Ptr<Self> {
  fn m(&self) { ... }

After:

impl S {
  fn m(this: Ptr<Self>) { ... }
}

Taking a &Ptr<Self> as the receiver was wrong because it aliased with the arguments of the function, so I moved to Ptr<Self>. This also has the nice side-effect that we can write only impl S instead of trait SImpl + impl Simpl for Ptr<Self>.

@lucic71
lucic71 marked this pull request as draft December 3, 2026 11:24
@lucic71
lucic71 marked this pull request as ready for review December 3, 2026 11:37
@lucic71

lucic71 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Did the same for unsafe

@nunoplopes
nunoplopes merged commit 20d251d into Cpp2Rust:master Dec 3, 2026
9 checks passed
nunoplopes pushed a commit that referenced this pull request Dec 3, 2026
Depends on #696

C++ [offers](https://eel.is/c++draft/concept.equalitycomparable)
WeaklyEqualityComparableWith, EqualityComparable,
EqualityComparableWith.

The relationship between them is:

```rs
    pub trait WeaklyEqualityComparableWith<U: WeaklyEqualityComparableWith<Self> = Self>: Sized {                                                                    
        fn equal(this: Ptr<Self>, rhs: Ptr<U>) -> bool;                                  // t == u
        fn not_equal(this: Ptr<Self>, rhs: Ptr<U>) -> bool { !Self::equal(this, rhs) }   // t != u
    }                                                                             
                                                                                  
    pub trait EqualityComparable: WeaklyEqualityComparableWith<Self> {}           
    impl<T: WeaklyEqualityComparableWith<T>> EqualityComparable for T {}                                                                                             
                                                                                  
    pub trait EqualityComparableWith<U: EqualityComparable + WeaklyEqualityComparableWith<Self>>:
        EqualityComparable + WeaklyEqualityComparableWith<U> {}                   
    impl<T, U> EqualityComparableWith<U> for T                                    
    where                                                                         
        T: EqualityComparable + WeaklyEqualityComparableWith<U>,                  
        U: EqualityComparable + WeaklyEqualityComparableWith<T>,                  
    {}  
```

---

std::find now is written as:

```cpp
    template <class T1, class T2> T1 f3(T1 first, T1 last, const T2 &value) {                                                                                        
      return std::find(first, last, value);                                                                                                                          
    }
```

to

```rs
    unsafe fn f3<                                                                                                                                                    
        T1: UnsafeCppInputIterator<T3>,                                                                                                                              
        T2: WeaklyEqualityComparableWithUnsafe<T3>,                                                                                                                  
        T3: WeaklyEqualityComparableWithUnsafe<T2>,                                                                                                                  
    >(a0: T1, a1: T1, a2: T2) -> T1 {
```

---

CppInputIterator is now bounded on EqualityComparable: `pub trait
CppInputIterator<T>: CppIterator<T> + EqualityComparable {}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants