@@ -979,12 +979,10 @@ impl<E: Encoder> Encodable<E> for Span {
979
979
}
980
980
impl < D : Decoder > Decodable < D > for Span {
981
981
default fn decode ( s : & mut D ) -> Span {
982
- s. read_struct ( |d| {
983
- let lo = d. read_struct_field ( "lo" , Decodable :: decode) ;
984
- let hi = d. read_struct_field ( "hi" , Decodable :: decode) ;
982
+ let lo = s. read_struct_field ( "lo" , Decodable :: decode) ;
983
+ let hi = s. read_struct_field ( "hi" , Decodable :: decode) ;
985
984
986
- Span :: new ( lo, hi, SyntaxContext :: root ( ) , None )
987
- } )
985
+ Span :: new ( lo, hi, SyntaxContext :: root ( ) , None )
988
986
}
989
987
}
990
988
@@ -1440,65 +1438,62 @@ impl<S: Encoder> Encodable<S> for SourceFile {
1440
1438
1441
1439
impl < D : Decoder > Decodable < D > for SourceFile {
1442
1440
fn decode ( d : & mut D ) -> SourceFile {
1443
- d. read_struct ( |d| {
1444
- let name: FileName = d. read_struct_field ( "name" , |d| Decodable :: decode ( d) ) ;
1445
- let src_hash: SourceFileHash =
1446
- d. read_struct_field ( "src_hash" , |d| Decodable :: decode ( d) ) ;
1447
- let start_pos: BytePos = d. read_struct_field ( "start_pos" , |d| Decodable :: decode ( d) ) ;
1448
- let end_pos: BytePos = d. read_struct_field ( "end_pos" , |d| Decodable :: decode ( d) ) ;
1449
- let lines: Vec < BytePos > = d. read_struct_field ( "lines" , |d| {
1450
- let num_lines: u32 = Decodable :: decode ( d) ;
1451
- let mut lines = Vec :: with_capacity ( num_lines as usize ) ;
1452
-
1453
- if num_lines > 0 {
1454
- // Read the number of bytes used per diff.
1455
- let bytes_per_diff: u8 = Decodable :: decode ( d) ;
1456
-
1457
- // Read the first element.
1458
- let mut line_start: BytePos = Decodable :: decode ( d) ;
1459
- lines. push ( line_start) ;
1460
-
1461
- for _ in 1 ..num_lines {
1462
- let diff = match bytes_per_diff {
1463
- 1 => d. read_u8 ( ) as u32 ,
1464
- 2 => d. read_u16 ( ) as u32 ,
1465
- 4 => d. read_u32 ( ) ,
1466
- _ => unreachable ! ( ) ,
1467
- } ;
1441
+ let name: FileName = d. read_struct_field ( "name" , |d| Decodable :: decode ( d) ) ;
1442
+ let src_hash: SourceFileHash = d. read_struct_field ( "src_hash" , |d| Decodable :: decode ( d) ) ;
1443
+ let start_pos: BytePos = d. read_struct_field ( "start_pos" , |d| Decodable :: decode ( d) ) ;
1444
+ let end_pos: BytePos = d. read_struct_field ( "end_pos" , |d| Decodable :: decode ( d) ) ;
1445
+ let lines: Vec < BytePos > = d. read_struct_field ( "lines" , |d| {
1446
+ let num_lines: u32 = Decodable :: decode ( d) ;
1447
+ let mut lines = Vec :: with_capacity ( num_lines as usize ) ;
1448
+
1449
+ if num_lines > 0 {
1450
+ // Read the number of bytes used per diff.
1451
+ let bytes_per_diff: u8 = Decodable :: decode ( d) ;
1452
+
1453
+ // Read the first element.
1454
+ let mut line_start: BytePos = Decodable :: decode ( d) ;
1455
+ lines. push ( line_start) ;
1456
+
1457
+ for _ in 1 ..num_lines {
1458
+ let diff = match bytes_per_diff {
1459
+ 1 => d. read_u8 ( ) as u32 ,
1460
+ 2 => d. read_u16 ( ) as u32 ,
1461
+ 4 => d. read_u32 ( ) ,
1462
+ _ => unreachable ! ( ) ,
1463
+ } ;
1468
1464
1469
- line_start = line_start + BytePos ( diff) ;
1465
+ line_start = line_start + BytePos ( diff) ;
1470
1466
1471
- lines. push ( line_start) ;
1472
- }
1467
+ lines. push ( line_start) ;
1473
1468
}
1474
-
1475
- lines
1476
- } ) ;
1477
- let multibyte_chars: Vec < MultiByteChar > =
1478
- d. read_struct_field ( "multibyte_chars" , |d| Decodable :: decode ( d) ) ;
1479
- let non_narrow_chars: Vec < NonNarrowChar > =
1480
- d. read_struct_field ( "non_narrow_chars" , |d| Decodable :: decode ( d) ) ;
1481
- let name_hash: u128 = d. read_struct_field ( "name_hash" , |d| Decodable :: decode ( d) ) ;
1482
- let normalized_pos: Vec < NormalizedPos > =
1483
- d. read_struct_field ( "normalized_pos" , |d| Decodable :: decode ( d) ) ;
1484
- let cnum: CrateNum = d. read_struct_field ( "cnum" , |d| Decodable :: decode ( d) ) ;
1485
- SourceFile {
1486
- name,
1487
- start_pos,
1488
- end_pos,
1489
- src : None ,
1490
- src_hash,
1491
- // Unused - the metadata decoder will construct
1492
- // a new SourceFile, filling in `external_src` properly
1493
- external_src : Lock :: new ( ExternalSource :: Unneeded ) ,
1494
- lines,
1495
- multibyte_chars,
1496
- non_narrow_chars,
1497
- normalized_pos,
1498
- name_hash,
1499
- cnum,
1500
1469
}
1501
- } )
1470
+
1471
+ lines
1472
+ } ) ;
1473
+ let multibyte_chars: Vec < MultiByteChar > =
1474
+ d. read_struct_field ( "multibyte_chars" , |d| Decodable :: decode ( d) ) ;
1475
+ let non_narrow_chars: Vec < NonNarrowChar > =
1476
+ d. read_struct_field ( "non_narrow_chars" , |d| Decodable :: decode ( d) ) ;
1477
+ let name_hash: u128 = d. read_struct_field ( "name_hash" , |d| Decodable :: decode ( d) ) ;
1478
+ let normalized_pos: Vec < NormalizedPos > =
1479
+ d. read_struct_field ( "normalized_pos" , |d| Decodable :: decode ( d) ) ;
1480
+ let cnum: CrateNum = d. read_struct_field ( "cnum" , |d| Decodable :: decode ( d) ) ;
1481
+ SourceFile {
1482
+ name,
1483
+ start_pos,
1484
+ end_pos,
1485
+ src : None ,
1486
+ src_hash,
1487
+ // Unused - the metadata decoder will construct
1488
+ // a new SourceFile, filling in `external_src` properly
1489
+ external_src : Lock :: new ( ExternalSource :: Unneeded ) ,
1490
+ lines,
1491
+ multibyte_chars,
1492
+ non_narrow_chars,
1493
+ normalized_pos,
1494
+ name_hash,
1495
+ cnum,
1496
+ }
1502
1497
}
1503
1498
}
1504
1499
0 commit comments