Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

Why qualified path patterns accept constants, structs and enum variants even though the reference forbid those?

$
0
0

Path patterns are patterns that refer either to constant values or to structs or enum variants that have no fields.

Unqualified path patterns can refer to:

enum variants, structs, constants, associated constants

Qualified path patterns can only refer to associated constants.

source

I created this example for this:

mod m {    pub mod n {        pub const CONST: i32 = 1;        pub struct S;        pub enum E {            V,        }        pub struct A;        impl A {            pub const ASSOC_CONST: i32 = 2;        }    }}fn main() {    let v = 10;    match v {        m::n::CONST => (),        m::n::A::ASSOC_CONST => (),        _ => (),    }    let v = m::n::S {};    match v {        m::n::S {} => (),    }    let v = m::n::E::V;    match v {        m::n::E::V => (),    }}

And it compiles without an issue even though I use qualified path patterns. Shouldn't this fail for anything but associated constants in the example?


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>