Skip to content

Commit 05e4116

Browse files
committed
Fix the span for try shorthand expressions
1 parent c0b8c43 commit 05e4116

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,7 @@ impl<'a> Parser<'a> {
25762576
loop {
25772577
// expr?
25782578
while self.eat(&token::Question) {
2579-
let hi = self.span.hi;
2579+
let hi = self.last_span.hi;
25802580
e = self.mk_expr(lo, hi, ExprKind::Try(e), None);
25812581
}
25822582

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(question_mark)]
12+
13+
// Make sure that the span of try shorthand does not include the trailing
14+
// semicolon;
15+
fn a() -> Result<i32, ()> {
16+
Err(5)?; //~ ERROR 16:5: 16:12
17+
Ok(1)
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)