@@ -30,7 +30,7 @@ pub fn pat_id_map(dm: &DefMap, pat: &ast::Pat) -> PatIdMap {
3030
3131pub fn pat_is_refutable ( dm : & DefMap , pat : & ast:: Pat ) -> bool {
3232 match pat. node {
33- ast:: PatLit ( _) | ast:: PatRange ( _, _) => true ,
33+ ast:: PatLit ( _) | ast:: PatRange ( _, _) | ast :: PatQPath ( .. ) => true ,
3434 ast:: PatEnum ( _, _) |
3535 ast:: PatIdent ( _, _, None ) |
3636 ast:: PatStruct ( ..) => {
@@ -60,7 +60,7 @@ pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &ast::Pat) -> bool {
6060
6161pub fn pat_is_const ( dm : & DefMap , pat : & ast:: Pat ) -> bool {
6262 match pat. node {
63- ast:: PatIdent ( _, _, None ) | ast:: PatEnum ( ..) => {
63+ ast:: PatIdent ( _, _, None ) | ast:: PatEnum ( ..) | ast :: PatQPath ( .. ) => {
6464 match dm. borrow ( ) . get ( & pat. id ) . map ( |d| d. full_def ( ) ) {
6565 Some ( DefConst ( ..) ) | Some ( DefAssociatedConst ( ..) ) => true ,
6666 _ => false
@@ -70,6 +70,22 @@ pub fn pat_is_const(dm: &DefMap, pat: &ast::Pat) -> bool {
7070 }
7171}
7272
73+ // Same as above, except that partially-resolved defs cause `false` to be
74+ // returned instead of a panic.
75+ pub fn pat_is_resolved_const ( dm : & DefMap , pat : & ast:: Pat ) -> bool {
76+ match pat. node {
77+ ast:: PatIdent ( _, _, None ) | ast:: PatEnum ( ..) | ast:: PatQPath ( ..) => {
78+ match dm. borrow ( ) . get ( & pat. id )
79+ . and_then ( |d| if d. depth == 0 { Some ( d. base_def ) }
80+ else { None } ) {
81+ Some ( DefConst ( ..) ) | Some ( DefAssociatedConst ( ..) ) => true ,
82+ _ => false
83+ }
84+ }
85+ _ => false
86+ }
87+ }
88+
7389pub fn pat_is_binding ( dm : & DefMap , pat : & ast:: Pat ) -> bool {
7490 match pat. node {
7591 ast:: PatIdent ( ..) => {
0 commit comments