@@ -377,12 +377,6 @@ enum PatternSource {
377377}
378378
379379impl PatternSource {
380- fn is_refutable ( self ) -> bool {
381- match self {
382- PatternSource :: Match | PatternSource :: IfLet | PatternSource :: WhileLet => true ,
383- PatternSource :: Let | PatternSource :: For | PatternSource :: FnParam => false ,
384- }
385- }
386380 fn descr ( self ) -> & ' static str {
387381 match self {
388382 PatternSource :: Match => "match binding" ,
@@ -2388,20 +2382,24 @@ impl<'a> Resolver<'a> {
23882382 false , pat. span )
23892383 . and_then ( LexicalScopeBinding :: item) ;
23902384 let resolution = binding. map ( NameBinding :: def) . and_then ( |def| {
2391- let ivmode = BindingMode :: ByValue ( Mutability :: Immutable ) ;
2392- let always_binding = !pat_src. is_refutable ( ) || opt_pat. is_some ( ) ||
2393- bmode != ivmode;
2385+ let is_syntactic_ambiguity = opt_pat. is_none ( ) &&
2386+ bmode == BindingMode :: ByValue ( Mutability :: Immutable ) ;
23942387 match def {
23952388 Def :: StructCtor ( _, CtorKind :: Const ) |
23962389 Def :: VariantCtor ( _, CtorKind :: Const ) |
2397- Def :: Const ( ..) if !always_binding => {
2398- // A unit struct/variant or constant pattern.
2390+ Def :: Const ( ..) if is_syntactic_ambiguity => {
2391+ // Disambiguate in favor of a unit struct/variant
2392+ // or constant pattern.
23992393 self . record_use ( ident. node , ValueNS , binding. unwrap ( ) , ident. span ) ;
24002394 Some ( PathResolution :: new ( def) )
24012395 }
24022396 Def :: StructCtor ( ..) | Def :: VariantCtor ( ..) |
24032397 Def :: Const ( ..) | Def :: Static ( ..) => {
2404- // A fresh binding that shadows something unacceptable.
2398+ // This is unambiguously a fresh binding, either syntactically
2399+ // (e.g. `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves
2400+ // to something unusable as a pattern (e.g. constructor function),
2401+ // but we still conservatively report an error, see
2402+ // issues/33118#issuecomment-233962221 for one reason why.
24052403 resolve_error (
24062404 self ,
24072405 ident. span ,
@@ -2410,7 +2408,7 @@ impl<'a> Resolver<'a> {
24102408 ) ;
24112409 None
24122410 }
2413- Def :: Local ( .. ) | Def :: Upvar ( .. ) | Def :: Fn ( ..) | Def :: Err => {
2411+ Def :: Fn ( ..) | Def :: Err => {
24142412 // These entities are explicitly allowed
24152413 // to be shadowed by fresh bindings.
24162414 None
0 commit comments