@@ -377,12 +377,6 @@ enum PatternSource {
377
377
}
378
378
379
379
impl 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
- }
386
380
fn descr ( self ) -> & ' static str {
387
381
match self {
388
382
PatternSource :: Match => "match binding" ,
@@ -2388,20 +2382,24 @@ impl<'a> Resolver<'a> {
2388
2382
false , pat. span )
2389
2383
. and_then ( LexicalScopeBinding :: item) ;
2390
2384
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 ) ;
2394
2387
match def {
2395
2388
Def :: StructCtor ( _, CtorKind :: Const ) |
2396
2389
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.
2399
2393
self . record_use ( ident. node , ValueNS , binding. unwrap ( ) , ident. span ) ;
2400
2394
Some ( PathResolution :: new ( def) )
2401
2395
}
2402
2396
Def :: StructCtor ( ..) | Def :: VariantCtor ( ..) |
2403
2397
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.
2405
2403
resolve_error (
2406
2404
self ,
2407
2405
ident. span ,
@@ -2410,7 +2408,7 @@ impl<'a> Resolver<'a> {
2410
2408
) ;
2411
2409
None
2412
2410
}
2413
- Def :: Local ( .. ) | Def :: Upvar ( .. ) | Def :: Fn ( ..) | Def :: Err => {
2411
+ Def :: Fn ( ..) | Def :: Err => {
2414
2412
// These entities are explicitly allowed
2415
2413
// to be shadowed by fresh bindings.
2416
2414
None
0 commit comments