@@ -1385,14 +1385,12 @@ impl<'a> Resolver<'a> {
1385
1385
path : & [ Segment ] ,
1386
1386
opt_ns : Option < Namespace > , // `None` indicates a module path in import
1387
1387
parent_scope : & ParentScope < ' a > ,
1388
- finalize_full : Finalize ,
1389
1388
ribs : Option < & PerNS < Vec < Rib < ' a > > > > ,
1390
1389
unusable_binding : Option < & ' a NameBinding < ' a > > ,
1391
1390
module : Option < ModuleOrUniformRoot < ' a > > ,
1392
1391
i : usize ,
1393
1392
ident : Ident ,
1394
1393
) -> ( String , Option < Suggestion > ) {
1395
- let finalize = finalize_full. path_span ( ) ;
1396
1394
let is_last = i == path. len ( ) - 1 ;
1397
1395
let ns = if is_last { opt_ns. unwrap_or ( TypeNS ) } else { TypeNS } ;
1398
1396
let module_res = match module {
@@ -1418,81 +1416,7 @@ impl<'a> Resolver<'a> {
1418
1416
} else {
1419
1417
( format ! ( "could not find `{}` in the crate root" , ident) , None )
1420
1418
}
1421
- } else if i == 0 {
1422
- if ident. name . as_str ( ) . chars ( ) . next ( ) . map_or ( false , |c| c. is_ascii_uppercase ( ) ) {
1423
- // Check whether the name refers to an item in the value namespace.
1424
- let suggestion = if ribs. is_some ( ) {
1425
- let match_span = match self . resolve_ident_in_lexical_scope (
1426
- ident,
1427
- ValueNS ,
1428
- parent_scope,
1429
- Finalize :: No ,
1430
- & ribs. unwrap ( ) [ ValueNS ] ,
1431
- unusable_binding,
1432
- ) {
1433
- // Name matches a local variable. For example:
1434
- // ```
1435
- // fn f() {
1436
- // let Foo: &str = "";
1437
- // println!("{}", Foo::Bar); // Name refers to local
1438
- // // variable `Foo`.
1439
- // }
1440
- // ```
1441
- Some ( LexicalScopeBinding :: Res ( Res :: Local ( id) ) ) => {
1442
- Some ( * self . pat_span_map . get ( & id) . unwrap ( ) )
1443
- }
1444
-
1445
- // Name matches item from a local name binding
1446
- // created by `use` declaration. For example:
1447
- // ```
1448
- // pub Foo: &str = "";
1449
- //
1450
- // mod submod {
1451
- // use super::Foo;
1452
- // println!("{}", Foo::Bar); // Name refers to local
1453
- // // binding `Foo`.
1454
- // }
1455
- // ```
1456
- Some ( LexicalScopeBinding :: Item ( name_binding) ) => Some ( name_binding. span ) ,
1457
- _ => None ,
1458
- } ;
1459
-
1460
- if let Some ( span) = match_span {
1461
- Some ( (
1462
- vec ! [ ( span, String :: from( "" ) ) ] ,
1463
- format ! ( "`{}` is defined here, but is not a type" , ident) ,
1464
- Applicability :: MaybeIncorrect ,
1465
- ) )
1466
- } else {
1467
- None
1468
- }
1469
- } else {
1470
- None
1471
- } ;
1472
-
1473
- ( format ! ( "use of undeclared type `{}`" , ident) , suggestion)
1474
- } else {
1475
- (
1476
- format ! ( "use of undeclared crate or module `{}`" , ident) ,
1477
- if ident. name == sym:: alloc {
1478
- Some ( (
1479
- vec ! [ ] ,
1480
- String :: from ( "add `extern crate alloc` to use the `alloc` crate" ) ,
1481
- Applicability :: MaybeIncorrect ,
1482
- ) )
1483
- } else {
1484
- self . find_similarly_named_module_or_crate ( ident. name , & parent_scope. module )
1485
- . map ( |sugg| {
1486
- (
1487
- vec ! [ ( ident. span, sugg. to_string( ) ) ] ,
1488
- String :: from ( "there is a crate or module with a similar name" ) ,
1489
- Applicability :: MaybeIncorrect ,
1490
- )
1491
- } )
1492
- } ,
1493
- )
1494
- }
1495
- } else {
1419
+ } else if i > 0 {
1496
1420
let parent = path[ i - 1 ] . ident . name ;
1497
1421
let parent = match parent {
1498
1422
// ::foo is mounted at the crate root for 2015, and is the extern
@@ -1501,9 +1425,7 @@ impl<'a> Resolver<'a> {
1501
1425
"the list of imported crates" . to_owned ( )
1502
1426
}
1503
1427
kw:: PathRoot | kw:: Crate => "the crate root" . to_owned ( ) ,
1504
- _ => {
1505
- format ! ( "`{}`" , parent)
1506
- }
1428
+ _ => format ! ( "`{}`" , parent) ,
1507
1429
} ;
1508
1430
1509
1431
let mut msg = format ! ( "could not find `{}` in {}" , ident, parent) ;
@@ -1515,7 +1437,7 @@ impl<'a> Resolver<'a> {
1515
1437
ident,
1516
1438
ns_to_try,
1517
1439
parent_scope,
1518
- finalize ,
1440
+ None ,
1519
1441
false ,
1520
1442
unusable_binding,
1521
1443
) . ok ( )
@@ -1526,7 +1448,7 @@ impl<'a> Resolver<'a> {
1526
1448
ident,
1527
1449
ns_to_try,
1528
1450
parent_scope,
1529
- finalize_full ,
1451
+ Finalize :: No ,
1530
1452
& ribs[ ns_to_try] ,
1531
1453
unusable_binding,
1532
1454
) {
@@ -1540,8 +1462,8 @@ impl<'a> Resolver<'a> {
1540
1462
ident,
1541
1463
scopes,
1542
1464
parent_scope,
1543
- finalize ,
1544
- finalize . is_some ( ) ,
1465
+ None ,
1466
+ false ,
1545
1467
false ,
1546
1468
unusable_binding,
1547
1469
) . ok ( )
@@ -1567,6 +1489,76 @@ impl<'a> Resolver<'a> {
1567
1489
} ;
1568
1490
}
1569
1491
( msg, None )
1492
+ } else if ident. name . as_str ( ) . chars ( ) . next ( ) . map_or ( false , |c| c. is_ascii_uppercase ( ) ) {
1493
+ // Check whether the name refers to an item in the value namespace.
1494
+ let binding = if let Some ( ribs) = ribs {
1495
+ self . resolve_ident_in_lexical_scope (
1496
+ ident,
1497
+ ValueNS ,
1498
+ parent_scope,
1499
+ Finalize :: No ,
1500
+ & ribs[ ValueNS ] ,
1501
+ unusable_binding,
1502
+ )
1503
+ } else {
1504
+ None
1505
+ } ;
1506
+ let match_span = match binding {
1507
+ // Name matches a local variable. For example:
1508
+ // ```
1509
+ // fn f() {
1510
+ // let Foo: &str = "";
1511
+ // println!("{}", Foo::Bar); // Name refers to local
1512
+ // // variable `Foo`.
1513
+ // }
1514
+ // ```
1515
+ Some ( LexicalScopeBinding :: Res ( Res :: Local ( id) ) ) => {
1516
+ Some ( * self . pat_span_map . get ( & id) . unwrap ( ) )
1517
+ }
1518
+ // Name matches item from a local name binding
1519
+ // created by `use` declaration. For example:
1520
+ // ```
1521
+ // pub Foo: &str = "";
1522
+ //
1523
+ // mod submod {
1524
+ // use super::Foo;
1525
+ // println!("{}", Foo::Bar); // Name refers to local
1526
+ // // binding `Foo`.
1527
+ // }
1528
+ // ```
1529
+ Some ( LexicalScopeBinding :: Item ( name_binding) ) => Some ( name_binding. span ) ,
1530
+ _ => None ,
1531
+ } ;
1532
+ let suggestion = if let Some ( span) = match_span {
1533
+ Some ( (
1534
+ vec ! [ ( span, String :: from( "" ) ) ] ,
1535
+ format ! ( "`{}` is defined here, but is not a type" , ident) ,
1536
+ Applicability :: MaybeIncorrect ,
1537
+ ) )
1538
+ } else {
1539
+ None
1540
+ } ;
1541
+
1542
+ ( format ! ( "use of undeclared type `{}`" , ident) , suggestion)
1543
+ } else {
1544
+ let suggestion = if ident. name == sym:: alloc {
1545
+ Some ( (
1546
+ vec ! [ ] ,
1547
+ String :: from ( "add `extern crate alloc` to use the `alloc` crate" ) ,
1548
+ Applicability :: MaybeIncorrect ,
1549
+ ) )
1550
+ } else {
1551
+ self . find_similarly_named_module_or_crate ( ident. name , & parent_scope. module ) . map (
1552
+ |sugg| {
1553
+ (
1554
+ vec ! [ ( ident. span, sugg. to_string( ) ) ] ,
1555
+ String :: from ( "there is a crate or module with a similar name" ) ,
1556
+ Applicability :: MaybeIncorrect ,
1557
+ )
1558
+ } ,
1559
+ )
1560
+ } ;
1561
+ ( format ! ( "use of undeclared crate or module `{}`" , ident) , suggestion)
1570
1562
}
1571
1563
}
1572
1564
}
0 commit comments