Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions cpp-overload-test/examples/stdcpp-time-point.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Test c++ std::chrono::time_point
//!
//! Working overloads are in [time_point.rs]
//!
//! [time_point.rs]: ../src/stdcpp/time_point.rs

#![feature(splat, tuple_trait)]
#![allow(incomplete_features)]
#![allow(unused_braces)]

use splat_overload::overload;
use std::ffi::c_longlong;

/// A fake Rust wrapper representing a C++ time_point.
///
/// Using vector to represent the time point because this example only tests
/// overload compatibility.
#[expect(dead_code, reason = "Incompatible overloads can't be used")]
struct StdTimePoint(Vec<c_longlong>);

/// Workaround for testing identical time point types.
///
/// The converting constructor can accept a time point with the same
/// duration type as the copy constructor.
type SameTimePoint = StdTimePoint;

// Constructors: new(...)
//
// When copy constructor and converting constructor receive the same
// time_point type, their argument types become identical.
//
// c++ resolves this by preferring the non-template copy constructor.
// Rust cannot represent both as separate overloads.

overload! {
impl StdTimePoint {

/// Copy constructor
fn new(_other: &StdTimePoint) -> StdTimePoint {
todo!()
}

/// Converting constructor
fn new(_other: &SameTimePoint) -> StdTimePoint {
todo!()
}
}
}

pub fn main() {}
18 changes: 18 additions & 0 deletions cpp-overload-test/examples/stdcpp-time-point.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0119]: conflicting implementations of trait `NewArgs<StdTimePoint>` for type `(&StdTimePoint,)`
--> cpp-overload-test/examples/stdcpp-time-point.rs:35:1
|
35 | / overload! {
36 | | impl StdTimePoint {
37 | |
38 | | /// Copy constructor
... |
48 | | }
| | ^
| | |
| |_first implementation here
| conflicting implementation for `(&StdTimePoint,)`
|
= note: this error originates in the macro `overload` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0119`.
error: could not compile `cpp-overload-test` (example "stdcpp-time-point") due to 1 previous error
1 change: 1 addition & 0 deletions cpp-overload-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod stdcpp {
// Add new modules for each type here, in alphabetical order.
pub mod forward_list;
pub mod hash;
pub mod time_point;
pub mod unordered_map;
pub mod unordered_multiset;
}
Expand Down
Loading
Loading