Skip to content

Commit 23fcf14

Browse files
jseyfriedbrson
authored andcommitted
Fix regression on include!(line!()).
1 parent 191cde0 commit 23fcf14

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/libsyntax/ext/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl<'a> ExtCtxt<'a> {
695695
/// Returns span for the macro which originally caused the current expansion to happen.
696696
///
697697
/// Stops backtracing at include! boundary.
698-
pub fn expansion_cause(&self) -> Span {
698+
pub fn expansion_cause(&self) -> Option<Span> {
699699
let mut ctxt = self.backtrace();
700700
let mut last_macro = None;
701701
loop {
@@ -711,7 +711,7 @@ impl<'a> ExtCtxt<'a> {
711711
break
712712
}
713713
}
714-
last_macro.expect("missing expansion backtrace")
714+
last_macro
715715
}
716716

717717
pub fn struct_span_warn(&self,

src/libsyntax/ext/source_util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
3535
-> Box<base::MacResult+'static> {
3636
base::check_zero_tts(cx, sp, tts, "line!");
3737

38-
let topmost = cx.expansion_cause();
38+
let topmost = cx.expansion_cause().unwrap_or(sp);
3939
let loc = cx.codemap().lookup_char_pos(topmost.lo);
4040

4141
base::MacEager::expr(cx.expr_u32(topmost, loc.line as u32))
@@ -46,7 +46,7 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
4646
-> Box<base::MacResult+'static> {
4747
base::check_zero_tts(cx, sp, tts, "column!");
4848

49-
let topmost = cx.expansion_cause();
49+
let topmost = cx.expansion_cause().unwrap_or(sp);
5050
let loc = cx.codemap().lookup_char_pos(topmost.lo);
5151

5252
base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32))
@@ -59,7 +59,7 @@ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree])
5959
-> Box<base::MacResult+'static> {
6060
base::check_zero_tts(cx, sp, tts, "file!");
6161

62-
let topmost = cx.expansion_cause();
62+
let topmost = cx.expansion_cause().unwrap_or(sp);
6363
let loc = cx.codemap().lookup_char_pos(topmost.lo);
6464
base::MacEager::expr(cx.expr_str(topmost, Symbol::intern(&loc.file.name)))
6565
}

src/test/compile-fail/issue-41776.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
fn main() {
12+
include!(line!()); //~ ERROR argument must be a string literal
13+
}

0 commit comments

Comments
 (0)