-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Another false positive: match_same_arms
vs. &Any
#1218
Comments
Weird, I'm pretty sure types are checked exactly for that kind of things. |
Found it: https://github.com/Manishearth/rust-clippy/blob/master/tests/compile-fail/copies.rs#L273-L277 (took me much longer than I like to admit to find something I wrote 😅) |
There's a difference in that different types are usually not returned from the match – in fact the type system usually doesn't permit it. However there's the |
Yup, I was just pointing out the insufficient test. |
@llogiq can you provide a MCVE? I can't reproduce. |
This is the closest I could get to reproducing it maybe I am missing something? use std::any::*;
#[derive(Debug)]
struct FooBar;
#[derive(Debug)]
struct Buzz;
enum Foo<'a> {
Bar(&'a FooBar),
Baz(&'a Buzz),
}
fn main() {
let fb = FooBar{};
let _ = Foo::Baz(&Buzz{});
let x: &dyn Any = match Foo::Bar(&fb) {
Foo::Bar(bar) => bar as &dyn Any,
Foo::Baz(bar) => bar as &dyn Any,
};
println!("{:?}", x);
} |
I can't reproduce it. Can we close this, or add a reproducer? |
I've checked it and found it to be solved. |
If the two arms do not have the same actual type, pulling them together with
|
will fail. The lint should not trigger if the actual types of the match arms differ.E.g.
Changing it to
will fail with a type error.
The text was updated successfully, but these errors were encountered: