Skip to content

Commit c611f6f

Browse files
committed
Don't strip shebang in expr-ctxt include!(…)
1 parent 2e624cb commit c611f6f

File tree

6 files changed

+58
-3
lines changed

6 files changed

+58
-3
lines changed

compiler/rustc_builtin_macros/src/source_util.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ pub(crate) fn expand_include<'cx>(
148148
let mut p = unwrap_or_emit_fatal(new_parser_from_file(
149149
self.psess,
150150
&self.path,
151-
// Don't strip frontmatter for backward compatibility, `---` may be the start of a
152-
// manifold negation. FIXME: Ideally, we wouldn't strip shebangs here either.
153-
StripTokens::Shebang,
151+
StripTokens::Nothing,
154152
Some(self.span),
155153
));
156154
let expr = parse_expr(&mut p).ok()?;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env my-rust-expr-evaluator
2+
3+
2 * (1 + 3)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env my-rust-script-runner
2+
3+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// XXX XXX XXX
2+
3+
fn main() {
4+
// expr ctxt
5+
_ = include!("auxiliary/shebang-expr.rs");
6+
//~^ ERROR non-expression macro in expression position
7+
//~? ERROR expected `[`, found `/`
8+
9+
// stmt ctxt (reuses expr expander)
10+
include!("auxiliary/shebang-expr.rs");
11+
//~^ ERROR non-statement macro in statement position
12+
//~? ERROR expected `[`, found `/`
13+
}
14+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error: expected `[`, found `/`
2+
--> $DIR/auxiliary/shebang-expr.rs:1:3
3+
|
4+
LL | #!/usr/bin/env my-rust-expr-evaluator
5+
| ^ expected `[`
6+
|
7+
= note: the token sequence `#!` here looks like the start of a shebang interpreter directive but it is not
8+
= help: if you meant this to be a shebang interpreter directive, move it to the very start of the file
9+
10+
error: non-expression macro in expression position: include
11+
--> $DIR/shebang-in-expr-ctxt.rs:5:9
12+
|
13+
LL | _ = include!("auxiliary/shebang-expr.rs");
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
16+
error: expected `[`, found `/`
17+
--> $DIR/auxiliary/shebang-expr.rs:1:3
18+
|
19+
LL | #!/usr/bin/env my-rust-expr-evaluator
20+
| ^ expected `[`
21+
|
22+
= note: the token sequence `#!` here looks like the start of a shebang interpreter directive but it is not
23+
= help: if you meant this to be a shebang interpreter directive, move it to the very start of the file
24+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
25+
26+
error: non-statement macro in statement position: include
27+
--> $DIR/shebang-in-expr-ctxt.rs:10:5
28+
|
29+
LL | include!("auxiliary/shebang-expr.rs");
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
32+
error: aborting due to 4 previous errors
33+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// XXX XXX XXX
2+
//@ check-pass
3+
4+
include!("auxiliary/shebang-items.rs");

0 commit comments

Comments
 (0)