@@ -376,12 +376,6 @@ enum PatternSource {
376376}
377377
378378impl PatternSource {
379- fn is_refutable ( self ) -> bool {
380- match self {
381- PatternSource :: Match | PatternSource :: IfLet | PatternSource :: WhileLet => true ,
382- PatternSource :: Let | PatternSource :: For | PatternSource :: FnParam => false ,
383- }
384- }
385379 fn descr ( self ) -> & ' static str {
386380 match self {
387381 PatternSource :: Match => "match binding" ,
@@ -2378,20 +2372,24 @@ impl<'a> Resolver<'a> {
23782372 false , pat. span )
23792373 . and_then ( LexicalScopeBinding :: item) ;
23802374 let resolution = binding. map ( NameBinding :: def) . and_then ( |def| {
2381- let ivmode = BindingMode :: ByValue ( Mutability :: Immutable ) ;
2382- let always_binding = !pat_src. is_refutable ( ) || opt_pat. is_some ( ) ||
2383- bmode != ivmode;
2375+ let is_syntactic_ambiguity = opt_pat. is_none ( ) &&
2376+ bmode == BindingMode :: ByValue ( Mutability :: Immutable ) ;
23842377 match def {
23852378 Def :: StructCtor ( _, CtorKind :: Const ) |
23862379 Def :: VariantCtor ( _, CtorKind :: Const ) |
2387- Def :: Const ( ..) if !always_binding => {
2388- // A unit struct/variant or constant pattern.
2380+ Def :: Const ( ..) if is_syntactic_ambiguity => {
2381+ // Disambiguate in favor of a unit struct/variant
2382+ // or constant pattern.
23892383 self . record_use ( ident. node , ValueNS , binding. unwrap ( ) , ident. span ) ;
23902384 Some ( PathResolution :: new ( def) )
23912385 }
23922386 Def :: StructCtor ( ..) | Def :: VariantCtor ( ..) |
23932387 Def :: Const ( ..) | Def :: Static ( ..) => {
2394- // A fresh binding that shadows something unacceptable.
2388+ // This is unambiguously a fresh binding, either syntactically
2389+ // (e.g. `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves
2390+ // to something unusable as a pattern (e.g. constructor function),
2391+ // but we still conservatively report an error, see
2392+ // issues/33118#issuecomment-233962221 for one reason why.
23952393 resolve_error (
23962394 self ,
23972395 ident. span ,
@@ -2400,7 +2398,7 @@ impl<'a> Resolver<'a> {
24002398 ) ;
24012399 None
24022400 }
2403- Def :: Local ( .. ) | Def :: Upvar ( .. ) | Def :: Fn ( ..) | Def :: Err => {
2401+ Def :: Fn ( ..) | Def :: Err => {
24042402 // These entities are explicitly allowed
24052403 // to be shadowed by fresh bindings.
24062404 None
0 commit comments