@@ -348,8 +348,7 @@ MatchStatement: ast::Stmt = {
348
348
.body
349
349
.last()
350
350
.unwrap()
351
- .end_location
352
- .unwrap();
351
+ .end();
353
352
ast::Stmt::new(
354
353
location,
355
354
end_location,
@@ -366,8 +365,7 @@ MatchStatement: ast::Stmt = {
366
365
.body
367
366
.last()
368
367
.unwrap()
369
- .end_location
370
- .unwrap();
368
+ .end();
371
369
ast::Stmt::new(
372
370
location,
373
371
end_location,
@@ -384,8 +382,7 @@ MatchStatement: ast::Stmt = {
384
382
.body
385
383
.last()
386
384
.unwrap()
387
- .end_location
388
- .unwrap();
385
+ .end();
389
386
let mut subjects = subjects;
390
387
subjects.insert(0, subject);
391
388
ast::Stmt::new(
@@ -803,8 +800,7 @@ IfStatement: ast::Stmt = {
803
800
.or_else(|| s2.last().and_then(|last| last.4.last()))
804
801
.or_else(|| body.last())
805
802
.unwrap()
806
- .end_location
807
- .unwrap();
803
+ .end();
808
804
// handle elif:
809
805
for i in s2.into_iter().rev() {
810
806
let x = ast::Stmt::new(
@@ -830,8 +826,7 @@ WhileStatement: ast::Stmt = {
830
826
.last()
831
827
.or_else(|| body.last())
832
828
.unwrap()
833
- .end_location
834
- .unwrap();
829
+ .end();
835
830
ast::Stmt::new(
836
831
location,
837
832
end_location,
@@ -851,8 +846,7 @@ ForStatement: ast::Stmt = {
851
846
.last()
852
847
.or_else(|| body.last())
853
848
.unwrap()
854
- .end_location
855
- .unwrap();
849
+ .end();
856
850
let target = Box::new(set_context(target, ast::ExprContext::Store));
857
851
let iter = Box::new(iter);
858
852
let type_comment = None;
@@ -871,9 +865,9 @@ TryStatement: ast::Stmt = {
871
865
let finalbody = finally.map(|s| s.2).unwrap_or_default();
872
866
let end_location = finalbody
873
867
.last()
874
- .and_then (|last| last.end_location )
875
- .or_else(|| orelse.last().and_then (|last| last.end_location ))
876
- .or_else(|| handlers.last().and_then (|last| last.end_location ))
868
+ .map (|last| last.end() )
869
+ .or_else(|| orelse.last().map (|last| last.end() ))
870
+ .or_else(|| handlers.last().map (|last| last.end() ))
877
871
.unwrap();
878
872
ast::Stmt::new(
879
873
location,
@@ -892,8 +886,8 @@ TryStatement: ast::Stmt = {
892
886
let end_location = finalbody
893
887
.last()
894
888
.or_else(|| orelse.last())
895
- .and_then (|last| last.end_location )
896
- .or_else(|| handlers.last().and_then (|last| last.end_location ))
889
+ .map (|last| last.end() )
890
+ .or_else(|| handlers.last().map (|last| last.end() ))
897
891
.unwrap();
898
892
ast::Stmt::new(
899
893
location,
@@ -910,7 +904,7 @@ TryStatement: ast::Stmt = {
910
904
let handlers = vec![];
911
905
let orelse = vec![];
912
906
let finalbody = finally.2;
913
- let end_location = finalbody.last().unwrap().end_location.unwrap ();
907
+ let end_location = finalbody.last().unwrap().end ();
914
908
ast::Stmt::new(
915
909
location,
916
910
end_location,
@@ -926,7 +920,7 @@ TryStatement: ast::Stmt = {
926
920
927
921
ExceptStarClause: ast::Excepthandler = {
928
922
<location:@L> "except" "*" <typ:Test<"all">> ":" <body:Suite> => {
929
- let end_location = body.last().unwrap().end_location.unwrap ();
923
+ let end_location = body.last().unwrap().end ();
930
924
ast::Excepthandler::new(
931
925
location,
932
926
end_location,
@@ -938,7 +932,7 @@ ExceptStarClause: ast::Excepthandler = {
938
932
)
939
933
},
940
934
<location:@L> "except" "*" <x:(Test<"all"> "as" Identifier)> ":" <body:Suite> => {
941
- let end_location = body.last().unwrap().end_location.unwrap ();
935
+ let end_location = body.last().unwrap().end ();
942
936
ast::Excepthandler::new(
943
937
location,
944
938
end_location,
@@ -954,7 +948,7 @@ ExceptStarClause: ast::Excepthandler = {
954
948
955
949
ExceptClause: ast::Excepthandler = {
956
950
<location:@L> "except" <typ:Test<"all">?> ":" <body:Suite> => {
957
- let end_location = body.last().unwrap().end_location.unwrap ();
951
+ let end_location = body.last().unwrap().end ();
958
952
ast::Excepthandler::new(
959
953
location,
960
954
end_location,
@@ -966,7 +960,7 @@ ExceptClause: ast::Excepthandler = {
966
960
)
967
961
},
968
962
<location:@L> "except" <x:(Test<"all"> "as" Identifier)> ":" <body:Suite> => {
969
- let end_location = body.last().unwrap().end_location.unwrap ();
963
+ let end_location = body.last().unwrap().end ();
970
964
ast::Excepthandler::new(
971
965
location,
972
966
end_location,
@@ -981,7 +975,7 @@ ExceptClause: ast::Excepthandler = {
981
975
982
976
WithStatement: ast::Stmt = {
983
977
<location:@L> <is_async:"async"?> "with" <items:WithItems> ":" <body:Suite> => {
984
- let end_location = body.last().unwrap().end_location.unwrap ();
978
+ let end_location = body.last().unwrap().end ();
985
979
let type_comment = None;
986
980
let node = if is_async.is_some() {
987
981
ast::StmtKind::AsyncWith { items, body, type_comment }
@@ -1022,7 +1016,7 @@ FuncDef: ast::Stmt = {
1022
1016
<decorator_list:Decorator*> <location:@L> <is_async:"async"?> "def" <name:Identifier> <args:Parameters> <r:("->" Test<"all">)?> ":" <body:Suite> => {
1023
1017
let args = Box::new(args);
1024
1018
let returns = r.map(|x| Box::new(x.1));
1025
- let end_location = body.last().unwrap().end_location.unwrap ();
1019
+ let end_location = body.last().unwrap().end ();
1026
1020
let type_comment = None;
1027
1021
let node = if is_async.is_some() {
1028
1022
ast::StmtKind::AsyncFunctionDef { name, args, body, decorator_list, returns, type_comment }
@@ -1197,7 +1191,7 @@ ClassDef: ast::Stmt = {
1197
1191
Some((_, arg, _)) => (arg.args, arg.keywords),
1198
1192
None => (vec![], vec![]),
1199
1193
};
1200
- let end_location = body.last().unwrap().end_location.unwrap ();
1194
+ let end_location = body.last().unwrap().end ();
1201
1195
ast::Stmt::new(
1202
1196
location,
1203
1197
end_location,
@@ -1253,19 +1247,18 @@ NamedExpressionTest: ast::Expr = {
1253
1247
1254
1248
NamedExpression: ast::Expr = {
1255
1249
<location:@L> <id:Identifier> <end_location:@R> ":=" <value:Test<"all">> => {
1256
- ast::Expr {
1250
+ ast::Expr::new(
1257
1251
location,
1258
- end_location: value.end_location,
1259
- custom: (),
1260
- node: ast::ExprKind::NamedExpr {
1252
+ value.end(),
1253
+ ast::ExprKind::NamedExpr {
1261
1254
target: Box::new(ast::Expr::new(
1262
1255
location,
1263
1256
end_location,
1264
1257
ast::ExprKind::Name { id, ctx: ast::ExprContext::Store },
1265
1258
)),
1266
1259
value: Box::new(value),
1267
1260
}
1268
- }
1261
+ )
1269
1262
},
1270
1263
};
1271
1264
@@ -1564,7 +1557,7 @@ Atom<Goal>: ast::Expr = {
1564
1557
if matches!(mid.node, ast::ExprKind::Starred { .. }) {
1565
1558
Err(LexicalError{
1566
1559
error: LexicalErrorType::OtherError("cannot use starred expression here".to_string()),
1567
- location: mid.location ,
1560
+ location: mid.start() ,
1568
1561
})?
1569
1562
}
1570
1563
Ok(mid)
0 commit comments