Skip to content

Do not emit inference errors after encountering mod parse errors#151883

Open
estebank wants to merge 1 commit intorust-lang:mainfrom
estebank:issue-105618
Open

Do not emit inference errors after encountering mod parse errors#151883
estebank wants to merge 1 commit intorust-lang:mainfrom
estebank:issue-105618

Conversation

@estebank
Copy link
Contributor

@estebank estebank commented Jan 31, 2026

Even in the face of parse recovery of a mod, when encountering parse errors silence knock-down inference errors.

For context, in the repro project from #105618 with a single parse error goes from emitting 69 diagnostics to 1.

Fix #105618.

Even in the face of parse recovery of a `mod`, when encountering parse errors silence knock-down inference errors.

For conctex, in a repro project with a single parse error goes from emitting 69 diagnostics to 1.
@rustbot
Copy link
Collaborator

rustbot commented Jan 31, 2026

Some changes occurred in need_type_info.rs

cc @lcnr

@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 Jan 31, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 31, 2026

r? @mati865

rustbot has assigned @mati865.
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

@estebank
Copy link
Contributor Author

I'm unhappy with adding the encountered_mod_parse_error field to GlobalCtxt. We also need a minimized test for this.

@mati865
Copy link
Member

mati865 commented Jan 31, 2026

@rustbot reroll

@rustbot rustbot assigned chenyukang and unassigned mati865 Jan 31, 2026
@chenyukang
Copy link
Member

looks good for me, add a test for it?

@estebank
Copy link
Contributor Author

estebank commented Feb 1, 2026

@chenyukang I'm gonna need a hand to come up with a minimized repro suitable for the test suite.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

This fix feels somewhat weird to me. It seems both very broad (in that it entirely silences ambiguity errors if there was any parse error) and overly specific (why only silence ambiguity errors)

What are the specific cases where a mod parse error causes ambiguity?

I expect it's largely "the mod should have contained an impl and now does not anymore"?

I don't see how silencing ambiguity is enough for that. THis can also result in trait selection errors or type mismatches due to incorrect inference

I think that if the set of applicable impls is unknown, trait solving as a whole is somewhat undesirable

View changes since this review

@estebank
Copy link
Contributor Author

An alternative is to rely on FatalRaise again, which is also undesirable IMO.

I agree that the ways that these kind of errors can blow up is myriad. This was an attempt of addressing the reported case without making any claims about other cases that should also be handled.

An alternative to this would be to inject a synthetic item into every mod that had parse errors, and look for that item later on when constructing errors...

Note that trait selection mismatches due to inference can only happen if this misparsed mod with missing items is part of the currently available search paths... while the current PR is global in its behavior.

@lcnr
Copy link
Contributor

lcnr commented Feb 12, 2026

if this misparsed mod with missing items is part of the currently available search paths... while the current PR is global in its behavior.

this doesn't seem right. The trait solver is always able to use all trait implementations.

I personally feel a lot better about fatally erroring here than inconsistently silencing errors.

An alternative to this would be to inject a synthetic item into every mod that had parse errors, and look for that item later on when constructing errors...

This would require tainting the set of trait impls for all traits which are nameable in that module as we e.g. don't know whether any macro in the module would expand to something referencing the trait. This is a lot of complexity for imo fairly limited benefits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation targeting nothing emits unrelated errors

5 participants