@@ -376,12 +376,6 @@ enum PatternSource {
376
376
}
377
377
378
378
impl 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
- }
385
379
fn descr ( self ) -> & ' static str {
386
380
match self {
387
381
PatternSource :: Match => "match binding" ,
@@ -2378,20 +2372,24 @@ impl<'a> Resolver<'a> {
2378
2372
false , pat. span )
2379
2373
. and_then ( LexicalScopeBinding :: item) ;
2380
2374
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 ) ;
2384
2377
match def {
2385
2378
Def :: StructCtor ( _, CtorKind :: Const ) |
2386
2379
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.
2389
2383
self . record_use ( ident. node , ValueNS , binding. unwrap ( ) , ident. span ) ;
2390
2384
Some ( PathResolution :: new ( def) )
2391
2385
}
2392
2386
Def :: StructCtor ( ..) | Def :: VariantCtor ( ..) |
2393
2387
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.
2395
2393
resolve_error (
2396
2394
self ,
2397
2395
ident. span ,
@@ -2400,7 +2398,7 @@ impl<'a> Resolver<'a> {
2400
2398
) ;
2401
2399
None
2402
2400
}
2403
- Def :: Local ( .. ) | Def :: Upvar ( .. ) | Def :: Fn ( ..) | Def :: Err => {
2401
+ Def :: Fn ( ..) | Def :: Err => {
2404
2402
// These entities are explicitly allowed
2405
2403
// to be shadowed by fresh bindings.
2406
2404
None
0 commit comments