Open
Description
I tried this code:
#![feature(negative_impls, auto_traits)]
use std::num::ParseIntError;
auto trait NotEqual {}
impl<T> !NotEqual for (T, T) {}
struct Error;
struct Error2<T>(T);
impl From<ParseIntError> for Error {
fn from(_: ParseIntError) -> Self {
Error
}
}
impl<T: From<U>, U> From<U> for Error2<T> where (U, Error2<T>): NotEqual {
fn from(from: U) -> Self {
Error2(T::from(from))
}
}
//this doesn't compile
fn a() -> Result<(), Error2<Error>> {
let a: u8 = "999".parse()?;
Ok(())
}
//this doesn't compile
fn b() -> Result<(), Error2<Error>> {
let a = "999".parse::<u8>()?;
Ok(())
}
//this compiles
fn c() -> Result<(), Error> {
let a = "999".parse::<u8>()?;
Ok(())
}
//this doesn't compiles
fn d() {
let err = "999".parse::<u8>().unwrap_err();
let err2 = Error2::<Error>::from(err);
}
//this compiles
fn e() {
let err = "999".parse::<u8>().unwrap_err();
let err2 = <Error2 as From<ParseIntError>>::from(err);
}
fn f<T, U>(t: T, u: U) where (T, U): NotEqual {}
//this doesn't compile
fn g() {
f(1u8, 1i8);
}
//this compiles
fn h() {
f::<u8, i8>(1u8, 1i8);
}
fn main() {
}
I expected this code to compile
but it doesn't
error message:
error[E0271]: type mismatch resolving `<u8 as FromStr>::Err == Error2<Error>`
--> src/main.rs:27:23
|
27 | let a: u8 = "999".parse()?;
| ^^^^^ expected struct `ParseIntError`, found struct `Error2`
|
= note: expected struct `ParseIntError`
found struct `Error2<Error>`
error[E0308]: mismatched types
--> src/main.rs:46:38
|
46 | let err2 = Error2::<Error>::from(err);
| ^^^ expected struct `Error2`, found struct `ParseIntError`
|
= note: expected struct `Error2<Error>`
found struct `ParseIntError`
error[E0107]: missing generics for struct `Error2`
--> src/main.rs:52:17
|
52 | let err2 = <Error2 as From<ParseIntError>>::from(err);
| ^^^^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `T`
--> src/main.rs:10:8
|
10 | struct Error2<T>(T);
| ^^^^^^ -
help: add missing generic argument
|
52 | let err2 = <Error2<T> as From<ParseIntError>>::from(err);
| ~~~~~~~~~
error[E0277]: the trait bound `(_, _): NotEqual` is not satisfied
--> src/main.rs:61:5
|
61 | f(1u8, 1i8);
| ^ the trait `NotEqual` is not implemented for `(_, _)`
|
note: required by a bound in `f`
--> src/main.rs:56:38
|
56 | fn f<T, U>(t: T, u: U) where (T, U): NotEqual {}
| ^^^^^^^^ required by this bound in `f`
i'm linking to rust playground so you can't quote out some code except for the code you are going to test
Meta
rustc --version --verbose
:
rustc 1.59.0-nightly (db9d361a4 2021-11-28)
binary: rustc
commit-hash: db9d361a4731ca0bb48533fab6297a8fea75696f
commit-date: 2021-11-28
host: x86_64-pc-windows-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0
tested on rust playground(2022-01-09 092e1c9) too
used feature auto_traits(#13231) and negative_impls(#68318), might be related to
(compile error, doesn't have backtrace)