Open
Description
Code
pub struct Instant(chrono::NaiveDateTime);
pub fn example() {
use std::ops::Bound;
use std::ops::RangeBounds;
let hours = Instant(chrono::NaiveDateTime::MIN)..=Instant(chrono::NaiveDateTime::MAX);
let total_hours = match hours.end_bound() {
Bound::Included(a) => a,
_ => unreachable!(),
} - match hours.start_bound() {
Bound::Included(a) => a,
_ => unreachable!(),
};
}
Current output
error[E0308]: `match` arms have incompatible types
--> src/lib.rs:22:14
|
20 | } - match hours.start_bound() {
| _________-
21 | | Bound::Included(a) => a,
| | - this is found to be of type `&Instant`
22 | | _ => unreachable!(),
| | ^^^^^^^^^^^^^^ expected `&Instant`, found `!`
23 | | };
| |_____- `match` arms have incompatible types
|
= note: expected reference `&Instant`
found type `!`
= note: this error originates in the macro `$crate::panic::unreachable_2021` which comes from the expansion of the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0308`.
Desired output
error[E0369]: cannot subtract `&Instant` from `&Instant`
--> src/lib.rs:20:7
|
20 | } - match hours.start_bound() {
| ^ no implementation for `&Instant - &Instant`
|
note: an implementation of `Sub` might be missing for `Instant`
--> src/lib.rs:9:1
|
9 | pub struct Instant(chrono::NaiveDateTime);
| ^^^^^^^^^^^^^^^^^^ must implement `Sub`
note: the trait `Sub` must be implemented
--> /home/lily/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/arith.rs:184:1
|
184 | pub trait Sub<Rhs = Self> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0369`.
Rationale and extra context
The error goes away if std::ops::Sub
is implemented for &Instant
Other cases
Output is identical on latest stable, beta, and nightly toolchains
Anything else?
I think this might be related to this issue (actually I initially thought it was the same, but that issue appears to have been fixed in the latest beta and nightly releases, while this has not).