Open
Description
I tried this code:
use core::marker::PhantomData;
struct Check<T: Accept>(PhantomData<T>);
impl<T: Accept> Check<T> {
const CHECK: () = assert!(T::STREAM);
}
trait Accept {
type Foo;
const STREAM: bool = false;
}
impl Accept for u64 {
type Foo = u64;
const STREAM: bool = false;
}
struct Foo;
impl Foo {
fn only_stream<T: Accept>(self, t: T)
{
let _ = Check::<T>::CHECK;
println!("Is stream!");
}
}
fn get_foo() -> Foo {
todo!()
}
fn main() {
let foo: Foo = todo!(); // Comment these out to make it fail to compile
foo.only_stream(5u64); // this line as well
let foo = get_foo();
foo.only_stream(5u64);
}
I expected to see this happen: I expected the second line in main
to cause a compilation failure. But due to the todo
this does not happen.
Instead, this happened: It compiles, but warns about unused code.
Meta
rustc --version --verbose
:
Stable 1.69
this also happens on nightly 1.71.0-nightly (2023-05-03 473f916d836cc662c5bd)
Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c3caf7f91c27f00067173e0e83406a24
Found together with @matthiasbeyer