-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.I-needs-decisionIssue: In need of a decision.Issue: In need of a decision.T-langRelevant to the language teamRelevant to the language team
Description
a.rs
fn main() {
include!("b.rs")
}
b.rs
fn b() {}
rustc 1.18.0-nightly (2bd4b5c 2017-04-23)
error: expected expression, found keyword `fn`
--> b.rs:1:1
|
1 | fn b(){}
| ^^
RReverser, captain-enjoyable, luaneko, karencfv, ad-si and 3 more
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.Category: This is a bug.I-needs-decisionIssue: In need of a decision.Issue: In need of a decision.T-langRelevant to the language teamRelevant to the language team
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
qnighy commentedon Apr 28, 2017
I think you can just put
;
afterinclude!(..)
. The;
doesn't disturb parsing of the item therein.The current behavior is that a macro invocation at the start of a statement is considered to be a macro statement if
;
, or{}
to enclose its arguments.Otherwise the macro invocation is considered to be a macro expression, not a macro statement.
I suppose the behavior is intentional. Otherwise the parser would not do such case analysis on parentheses/brackets/braces.
SimonSapin commentedon Apr 28, 2017
Same error message with a semi-colon:
SimonSapin commentedon Apr 28, 2017
Or curly braces:
qnighy commentedon Apr 28, 2017
I was only checking the behavior for another macro. Now I know what you mean. Sorry for bothering you.
Kixunil commentedon Nov 3, 2018
I've hit this bug and it's pretty annoying in my case, since I'll have to resort to using build script.
<eof>
rust-sailfish/sailfish#58lolbinarycat commentedon Sep 8, 2024
triage: yep, this is still an issue
here's a repro in txtar format.