Skip to content

Conversation

@ogoffart
Copy link
Contributor

@ogoffart ogoffart commented Nov 30, 2025

The problem is that when a macro expand to compile_error! because its input is malformed, the actual error message from the compile_error! might be hidden in a long list of other messages about using items that should have otherwise been generated by the macro.

So suppress error about missing items in that module.

Fixes #68838

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 30, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Contributor

lcnr commented Dec 1, 2025

@rustbot reroll

@rustbot rustbot assigned fee1-dead and unassigned lcnr Dec 1, 2025
@fee1-dead
Copy link
Member

r? petrochenkov

@rustbot rustbot assigned petrochenkov and unassigned fee1-dead Dec 5, 2025
let mut module = None;
let mut module_had_parse_errors = false;
let mut module_had_parse_errors = !self.mods_with_parse_errors.is_empty()
&& self.mods_with_parse_errors.contains(&parent_scope.module.nearest_parent_mod());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary?
The nearest_parent_mod() part doesn't look right, and I'm not sure what effect this has in general, because a similar check already exists below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when looking for foo::bar::baz() the test bellow only starts when checking for bar in foo, but without this test here, we would still get the errors if foo is not found and that the current module contains a compile_error!

Copy link
Contributor

@petrochenkov petrochenkov Dec 8, 2025

Choose a reason for hiding this comment

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

This is why I dislike random diagnostic changes like this, the added logic partially repeats a piece of logic that normally happens in an entirely different function (resolve_ident_in_lexical_scope/resolve_ident_in_scope_set).

Also, foo may be "not found" in multiple other locations, not just the current module (local variables, unnamed blocks, various preludes).
I guess it's ok to suppress the error if a poisoned module was found in at least one of those location during the search.
And parent_scope.module.nearest_parent_mod() will always be in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review.

Indeed, the function scope are not added to the poisoned modules. (If I use invalid symbols in error_in_this_function, the error is not suppressed as it should)

I am not very familiar with the rustc codebase, so let me know if there is a way to solve that. (Adding non-module NodeId in the set?)

I was just re-using the existing module_had_parse_errors set, but maybe there is a better option?

I tried to change a bit the logic to be more robust, but I'm not sure what logic you mean is repeated.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 8, 2025
@rust-log-analyzer

This comment has been minimized.

The problem is that when a macro expand to `compile_error!` because
its input is malformed, the actual error message from the
`compile_error!` might be hidden in a long list of other messages about
using items that should have otherwise been generated by the macro.

So suppress error about missing items in that module.
@rustbot
Copy link
Collaborator

rustbot commented Dec 9, 2025

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 10, 2025
}
_ => Err(Determinacy::determined(finalize.is_some())),
_ => {
for rib in &ribs[ns] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just keep the previous version, it's better to have something simpler, than to copy even more logic from resolve_ident_in_(scope_set,lexical_scope) to here.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for fatal compile_error that suppresses subsequent errors

6 participants