Skip to content

Commit 1dd787c

Browse files
Rollup merge of rust-lang#42006 - jseyfried:fix_include_regression, r=nrc
Fix ICE on `include!(line!())` (regression) Fixes rust-lang#41776. r? @nrc
2 parents 85f28cd + 4f2f270 commit 1dd787c

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
@@ -700,7 +700,7 @@ impl<'a> ExtCtxt<'a> {
700700
/// Returns span for the macro which originally caused the current expansion to happen.
701701
///
702702
/// Stops backtracing at include! boundary.
703-
pub fn expansion_cause(&self) -> Span {
703+
pub fn expansion_cause(&self) -> Option<Span> {
704704
let mut ctxt = self.backtrace();
705705
let mut last_macro = None;
706706
loop {
@@ -716,7 +716,7 @@ impl<'a> ExtCtxt<'a> {
716716
break
717717
}
718718
}
719-
last_macro.expect("missing expansion backtrace")
719+
last_macro
720720
}
721721

722722
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)