@@ -1517,21 +1517,33 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
15171517 ident : Ident ,
15181518 has_sub : bool ,
15191519 ) -> Option < Res > {
1520- let binding =
1521- self . resolve_ident_in_lexical_scope ( ident, ValueNS , None , pat. span ) ?. item ( ) ?;
1522- let res = binding. res ( ) ;
1520+ let ls_binding = self . resolve_ident_in_lexical_scope ( ident, ValueNS , None , pat. span ) ?;
1521+ let ( res, binding) = match ls_binding {
1522+ LexicalScopeBinding :: Item ( binding) if binding. is_ambiguity ( ) => {
1523+ // For ambiguous bindings we don't know all their definitions and cannot check
1524+ // whether they can be shadowed by fresh bindings or not, so force an error.
1525+ self . r . record_use ( ident, ValueNS , binding, false ) ;
1526+ return None ;
1527+ }
1528+ LexicalScopeBinding :: Item ( binding) => ( binding. res ( ) , Some ( binding) ) ,
1529+ LexicalScopeBinding :: Res ( res) => ( res, None ) ,
1530+ } ;
15231531
15241532 // An immutable (no `mut`) by-value (no `ref`) binding pattern without
15251533 // a sub pattern (no `@ $pat`) is syntactically ambiguous as it could
15261534 // also be interpreted as a path to e.g. a constant, variant, etc.
15271535 let is_syntactic_ambiguity = !has_sub && bm == BindingMode :: ByValue ( Mutability :: Not ) ;
15281536
15291537 match res {
1530- Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Const ) , _) | Res :: Def ( DefKind :: Const , _)
1538+ Res :: Def ( DefKind :: Ctor ( _, CtorKind :: Const ) , _)
1539+ | Res :: Def ( DefKind :: Const , _)
1540+ | Res :: Def ( DefKind :: ConstParam , _)
15311541 if is_syntactic_ambiguity =>
15321542 {
15331543 // Disambiguate in favor of a unit struct/variant or constant pattern.
1534- self . r . record_use ( ident, ValueNS , binding, false ) ;
1544+ if let Some ( binding) = binding {
1545+ self . r . record_use ( ident, ValueNS , binding, false ) ;
1546+ }
15351547 Some ( res)
15361548 }
15371549 Res :: Def ( DefKind :: Ctor ( ..) , _)
@@ -1547,23 +1559,20 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
15471559 ResolutionError :: BindingShadowsSomethingUnacceptable (
15481560 pat_src. descr ( ) ,
15491561 ident. name ,
1550- binding,
1562+ binding. expect ( "no binding for a ctor or static" ) ,
15511563 ) ,
15521564 ) ;
15531565 None
15541566 }
1555- Res :: Def ( DefKind :: Fn , _) | Res :: Err => {
1567+ Res :: Def ( DefKind :: Fn , _) | Res :: Local ( .. ) | Res :: Err => {
15561568 // These entities are explicitly allowed to be shadowed by fresh bindings.
15571569 None
15581570 }
1559- res => {
1560- span_bug ! (
1561- ident. span,
1562- "unexpected resolution for an \
1563- identifier in pattern: {:?}",
1564- res
1565- ) ;
1566- }
1571+ _ => span_bug ! (
1572+ ident. span,
1573+ "unexpected resolution for an identifier in pattern: {:?}" ,
1574+ res
1575+ ) ,
15671576 }
15681577 }
15691578
0 commit comments