@@ -1517,21 +1517,33 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1517
1517
ident : Ident ,
1518
1518
has_sub : bool ,
1519
1519
) -> 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
+ } ;
1523
1531
1524
1532
// An immutable (no `mut`) by-value (no `ref`) binding pattern without
1525
1533
// a sub pattern (no `@ $pat`) is syntactically ambiguous as it could
1526
1534
// also be interpreted as a path to e.g. a constant, variant, etc.
1527
1535
let is_syntactic_ambiguity = !has_sub && bm == BindingMode :: ByValue ( Mutability :: Not ) ;
1528
1536
1529
1537
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 , _)
1531
1541
if is_syntactic_ambiguity =>
1532
1542
{
1533
1543
// 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
+ }
1535
1547
Some ( res)
1536
1548
}
1537
1549
Res :: Def ( DefKind :: Ctor ( ..) , _)
@@ -1547,23 +1559,20 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1547
1559
ResolutionError :: BindingShadowsSomethingUnacceptable (
1548
1560
pat_src. descr ( ) ,
1549
1561
ident. name ,
1550
- binding,
1562
+ binding. expect ( "no binding for a ctor or static" ) ,
1551
1563
) ,
1552
1564
) ;
1553
1565
None
1554
1566
}
1555
- Res :: Def ( DefKind :: Fn , _) | Res :: Err => {
1567
+ Res :: Def ( DefKind :: Fn , _) | Res :: Local ( .. ) | Res :: Err => {
1556
1568
// These entities are explicitly allowed to be shadowed by fresh bindings.
1557
1569
None
1558
1570
}
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
+ ) ,
1567
1576
}
1568
1577
}
1569
1578
0 commit comments