Skip to content

Commit ab7257d

Browse files
authored
Rollup merge of rust-lang#48083 - jseyfried:improve_tuple_struct_field_access_hygiene, r=petrochenkov
Improve tuple struct field access hygiene Fixes rust-lang#47312 by fixing a span bug. r? @nrc
2 parents 9cf75c2 + a003cb7 commit ab7257d

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/libsyntax/parse/parser.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -2630,8 +2630,7 @@ impl<'a> Parser<'a> {
26302630
// A tuple index may not have a suffix
26312631
self.expect_no_suffix(sp, "tuple index", suf);
26322632

2633-
let dot_span = self.prev_span;
2634-
hi = self.span;
2633+
let idx_span = self.span;
26352634
self.bump();
26362635

26372636
let invalid_msg = "invalid tuple or struct index";
@@ -2646,9 +2645,8 @@ impl<'a> Parser<'a> {
26462645
n.to_string());
26472646
err.emit();
26482647
}
2649-
let id = respan(dot_span.to(hi), n);
2650-
let field = self.mk_tup_field(e, id);
2651-
e = self.mk_expr(lo.to(hi), field, ThinVec::new());
2648+
let field = self.mk_tup_field(e, respan(idx_span, n));
2649+
e = self.mk_expr(lo.to(idx_span), field, ThinVec::new());
26522650
}
26532651
None => {
26542652
let prev_span = self.prev_span;
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2017 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+
// ignore-pretty pretty-printing is unhygienic
12+
13+
#![feature(decl_macro)]
14+
#![allow(unused)]
15+
16+
mod foo {
17+
pub macro m($s:tt, $i:tt) {
18+
$s.$i
19+
}
20+
}
21+
22+
mod bar {
23+
struct S(i32);
24+
fn f() {
25+
let s = S(0);
26+
::foo::m!(s, 0);
27+
}
28+
}
29+
30+
fn main() {}

0 commit comments

Comments
 (0)