@@ -1272,35 +1272,71 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
1272
1272
debug ! ( "(resolving block) leaving block" ) ;
1273
1273
}
1274
1274
1275
- fn fresh_binding ( & mut self ,
1276
- ident : Ident ,
1277
- pat_id : NodeId ,
1278
- outer_pat_id : NodeId ,
1279
- pat_src : PatternSource ,
1280
- bindings : & mut IdentMap < NodeId > )
1281
- -> Res {
1282
- // Add the binding to the local ribs, if it
1283
- // doesn't already exist in the bindings map. (We
1284
- // must not add it if it's in the bindings map
1285
- // because that breaks the assumptions later
1286
- // passes make about or-patterns.)
1275
+ fn resolve_pattern (
1276
+ & mut self ,
1277
+ pat : & Pat ,
1278
+ pat_src : PatternSource ,
1279
+ // Maps idents to the node ID for the outermost pattern that binds them.
1280
+ bindings : & mut IdentMap < NodeId > ,
1281
+ ) {
1282
+ // Visit all direct subpatterns of this pattern.
1283
+ let outer_pat_id = pat. id ;
1284
+ pat. walk ( & mut |pat| {
1285
+ debug ! ( "resolve_pattern pat={:?} node={:?}" , pat, pat. node) ;
1286
+ match pat. node {
1287
+ PatKind :: Ident ( bmode, ident, ref sub) => {
1288
+ // First try to resolve the identifier as some existing entity,
1289
+ // then fall back to a fresh binding.
1290
+ let has_sub = sub. is_some ( ) ;
1291
+ let res = self . try_resolve_as_non_binding ( pat_src, pat, bmode, ident, has_sub)
1292
+ . unwrap_or_else ( || {
1293
+ self . fresh_binding ( ident, pat. id , outer_pat_id, pat_src, bindings)
1294
+ } ) ;
1295
+ self . r . record_partial_res ( pat. id , PartialRes :: new ( res) ) ;
1296
+ }
1297
+ PatKind :: TupleStruct ( ref path, ..) => {
1298
+ self . smart_resolve_path ( pat. id , None , path, PathSource :: TupleStruct ) ;
1299
+ }
1300
+ PatKind :: Path ( ref qself, ref path) => {
1301
+ self . smart_resolve_path ( pat. id , qself. as_ref ( ) , path, PathSource :: Pat ) ;
1302
+ }
1303
+ PatKind :: Struct ( ref path, ..) => {
1304
+ self . smart_resolve_path ( pat. id , None , path, PathSource :: Struct ) ;
1305
+ }
1306
+ _ => { }
1307
+ }
1308
+ true
1309
+ } ) ;
1310
+
1311
+ visit:: walk_pat ( self , pat) ;
1312
+ }
1313
+
1314
+ fn fresh_binding (
1315
+ & mut self ,
1316
+ ident : Ident ,
1317
+ pat_id : NodeId ,
1318
+ outer_pat_id : NodeId ,
1319
+ pat_src : PatternSource ,
1320
+ bindings : & mut IdentMap < NodeId > ,
1321
+ ) -> Res {
1322
+ // Add the binding to the local ribs, if it doesn't already exist in the bindings map.
1323
+ // (We must not add it if it's in the bindings map because that breaks the assumptions
1324
+ // later passes make about or-patterns.)
1287
1325
let ident = ident. modern_and_legacy ( ) ;
1288
1326
let mut res = Res :: Local ( pat_id) ;
1289
1327
match bindings. get ( & ident) . cloned ( ) {
1290
1328
Some ( id) if id == outer_pat_id => {
1291
1329
// `Variant(a, a)`, error
1292
1330
self . r . report_error (
1293
1331
ident. span ,
1294
- ResolutionError :: IdentifierBoundMoreThanOnceInSamePattern (
1295
- & ident. as_str ( ) )
1332
+ ResolutionError :: IdentifierBoundMoreThanOnceInSamePattern ( & ident. as_str ( ) ) ,
1296
1333
) ;
1297
1334
}
1298
1335
Some ( ..) if pat_src == PatternSource :: FnParam => {
1299
1336
// `fn f(a: u8, a: u8)`, error
1300
1337
self . r . report_error (
1301
1338
ident. span ,
1302
- ResolutionError :: IdentifierBoundMoreThanOnceInParameterList (
1303
- & ident. as_str ( ) )
1339
+ ResolutionError :: IdentifierBoundMoreThanOnceInParameterList ( & ident. as_str ( ) ) ,
1304
1340
) ;
1305
1341
}
1306
1342
Some ( ..) if pat_src == PatternSource :: Match ||
@@ -1329,45 +1365,6 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
1329
1365
& mut self . ribs [ ns] . last_mut ( ) . unwrap ( ) . bindings
1330
1366
}
1331
1367
1332
- fn resolve_pattern (
1333
- & mut self ,
1334
- pat : & Pat ,
1335
- pat_src : PatternSource ,
1336
- // Maps idents to the node ID for the outermost pattern that binds them.
1337
- bindings : & mut IdentMap < NodeId > ,
1338
- ) {
1339
- // Visit all direct subpatterns of this pattern.
1340
- let outer_pat_id = pat. id ;
1341
- pat. walk ( & mut |pat| {
1342
- debug ! ( "resolve_pattern pat={:?} node={:?}" , pat, pat. node) ;
1343
- match pat. node {
1344
- PatKind :: Ident ( bmode, ident, ref sub) => {
1345
- // First try to resolve the identifier as some existing entity,
1346
- // then fall back to a fresh binding.
1347
- let has_sub = sub. is_some ( ) ;
1348
- let res = self . try_resolve_as_non_binding ( pat_src, pat, bmode, ident, has_sub)
1349
- . unwrap_or_else ( || {
1350
- self . fresh_binding ( ident, pat. id , outer_pat_id, pat_src, bindings)
1351
- } ) ;
1352
- self . r . record_partial_res ( pat. id , PartialRes :: new ( res) ) ;
1353
- }
1354
- PatKind :: TupleStruct ( ref path, ..) => {
1355
- self . smart_resolve_path ( pat. id , None , path, PathSource :: TupleStruct ) ;
1356
- }
1357
- PatKind :: Path ( ref qself, ref path) => {
1358
- self . smart_resolve_path ( pat. id , qself. as_ref ( ) , path, PathSource :: Pat ) ;
1359
- }
1360
- PatKind :: Struct ( ref path, ..) => {
1361
- self . smart_resolve_path ( pat. id , None , path, PathSource :: Struct ) ;
1362
- }
1363
- _ => { }
1364
- }
1365
- true
1366
- } ) ;
1367
-
1368
- visit:: walk_pat ( self , pat) ;
1369
- }
1370
-
1371
1368
fn try_resolve_as_non_binding (
1372
1369
& mut self ,
1373
1370
pat_src : PatternSource ,
0 commit comments