Skip to content

Conversation

@danielvallance
Copy link
Contributor

A foreign imported interface can be missing from pkg.interfaces either because it does not exist, or because it was disabled by feature-gating.

Previously, the parser failed in both cases, when it should only fail when it does not exist, and should succeed when the references to it are disabled by feature-gating.

By checking the set of unresolved worlds' imports and exports for references to this interface, it is possible to determine if they contain any references to the interface, and whether or not they were disabled by feature gating.

If they are all disabled, then it does not matter that the interface is absent from pkg.interfaces, and the code should not fail. If any references are active however, then this is an error as the code will not be able to find the interface in pkg.interfaces.

If no references exist at all, then no combination of feature enabling/disabling would satisfy the import/use statement which requires the interface, and the code should fail.

This fixes issue 2285 and a unit test was added to cover this case.

A foreign imported interface can be missing from pkg.interfaces either
because it does not exist, or because it was disabled by feature-gating.

Previously, the parser failed in both cases, when it should only
fail when it does not exist, and should succeed when the references
to it are disabled by feature-gating.

By checking the set of unresolved worlds' imports and exports for
references to this interface, it is possible to determine if they
contain any references to the interface, and whether or not they
were disabled by feature gating.

If they are all disabled, then it does not matter that the interface
is absent from pkg.interfaces, and the code should not fail. If any
references are active however, then this is an error as the code
will not be able to find the interface in pkg.interfaces.

If no references exist at all, then no combination of feature
enabling/disabling would satisfy the import/use statement which
requires the interface, and the code should fail.

This fixes issue 2285 and a unit test was added to cover this case.
@danielvallance danielvallance requested a review from a team as a code owner November 30, 2025 17:41
@danielvallance danielvallance requested review from pchickey and removed request for a team November 30, 2025 17:41
@pchickey pchickey requested review from alexcrichton and removed request for pchickey December 1, 2025 18:44
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks!

I'm a bit worried about this approaching being brittle though in how it relies on iterating over all worlds and checking for stability. Would it be possible to push None, instead of Some(iface_id), and then handle the None case later when it shows up?

@danielvallance
Copy link
Contributor Author

Hi @alexcrichton , yeah my initial approach was to just push None when the interface was not found in pkg.interfaces, however it caused some unit tests to fail as it results in successfully parsing some packages which import nonexistent interfaces. That's what led me to create the is_gated closure as a form of basic validation that the interface actually exists in some form. I could not see another place where it would be more appropriate to check the interface actually exists however I may be overlooking something as I am not super familiar with the code.

Just to confirm, we definitely want to fail in the case where a nonexistent interface is imported but not used, right?

(the unit tests which failed my initial approach were "tests/ui/parse-fail/bad-pkg3", "tests/ui/parse-fail/bad-pkg2" and "tests/ui/parse-fail/use-world")

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants