Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 59191 - ICE when macro replaces crate root with non-module item #68758

Merged
merged 3 commits into from
Feb 5, 2020

Conversation

daboross
Copy link
Contributor

@daboross daboross commented Feb 2, 2020

Hi,

This should fix #59191! My friend and I are working on learning the rustc codebase through contributions, so please feel free to mention anything amiss or that could be done better.

The code adds an explicit case for when a macro applied to the crate root (via an inner attribute) replaces it with something nonsensical, like a function. The crate root must be a module, and the error message reflects this.


I should note that there are a few other weird edge cases here, like if they do output a module, it succeeds but uses that module's name as a prefix for all names in the crate. I'm assuming that's an issue for stabilizing #54726, though.

This adds an explicit error for when macros replace the crate root with
a non-module item.
@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 2, 2020
@petrochenkov
Copy link
Contributor

r? @petrochenkov

@rust-highfive rust-highfive assigned petrochenkov and unassigned eddyb Feb 2, 2020
Changes the error handler for inner attributes that replace the root
with a non-module. Previously it would emit a fatal error. It now emits
an empty expasion and a non-fatal error like the existing handler for a
failed expansion.
self.cx.span_err(
span,
&format!(
"expected crate top-level item to be a module after macro expansion, found a {}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crate-level attribute macros aren't really expected to produce a module, they are just not supported at all and may result in nonsense and paradoxes.
This is an ok fix and it removes the ICE, but this case should ideally report the same error as this example:

enum E {
    #[test] // error: expected an inert attribute, found an attribute macro
    V
}

fn main() {}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not urgent though, and I still hope to rewrite the macro invocation collector anyway.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 4, 2020

📌 Commit 152811d has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 4, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Feb 4, 2020
Fix 59191 - ICE when macro replaces crate root with non-module item

Hi,

This should fix rust-lang#59191! My friend and I are working on learning the rustc codebase through contributions, so please feel free to mention anything amiss or that could be done better.

The code adds an explicit case for when a macro applied to the crate root (via an inner attribute) replaces it with something nonsensical, like a function. The crate root must be a module, and the error message reflects this.

---

I should note that there are a few other weird edge cases here, like if they do output a module, it succeeds but uses that module's name as a prefix for all names in the crate. I'm assuming that's an issue for stabilizing rust-lang#54726, though.
bors added a commit that referenced this pull request Feb 5, 2020
Rollup of 7 pull requests

Successful merges:

 - #68282 (Instrument C / C++ in MemorySanitizer example)
 - #68758 (Fix 59191 - ICE when macro replaces crate root with non-module item)
 - #68805 (bootstrap: fix clippy warnings)
 - #68810 (Remove Copy impl from OnceWith)
 - #68815 (remove redundant imports (clippy::single_component_path_imports))
 - #68818 (fix couple of perf related clippy warnings)
 - #68819 (Suggest `split_at_mut` on multiple mutable index access)

Failed merges:

r? @ghost
@bors bors merged commit 152811d into rust-lang:master Feb 5, 2020
@daboross daboross deleted the fix-59191 branch February 5, 2020 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

thread 'rustc' panicked at 'internal error: entered unreachable code', src/libsyntax/ext/expand.rs:289:18
6 participants