Conversation
| Indeterminate(Span), | ||
| ModuleOnly(Span), |
There was a problem hiding this comment.
I tried to generate those errors, but I wasn't able to generate them. Probably some weird edge-case.
Let's keep them.
deed8e1 to
596133b
Compare
|
Thanks for the review! |
596133b to
40df631
Compare
There was a problem hiding this comment.
Looks good to me. I will let @jhpratt do the final review.
|
|
||
| ItemKind::Enum(ident, _, _) | ItemKind::Trait(box ast::Trait { ident, .. }) => { | ||
| ItemKind::Trait(box ast::Trait { ident, ref impl_restriction, .. }) => { | ||
| let impl_restriction = self.resolve_impl_restriction(impl_restriction); |
There was a problem hiding this comment.
build_reduced_graph is the most inappropriate place for resolving names, item visibilities are resolved here only out of necessity, and it still causes issues (like #60552 and similar).
Visibilities in restrictions are not necessary for putting declarations into modules, so these visibilities should be safely resolve-able in somewhere in late.rs without adding hacks that this PR adds.
There was a problem hiding this comment.
rust/compiler/rustc_resolve/src/late.rs
Lines 2804 to 2821 in 40df631
Maybe I should resolve and add impl restrictions here?
There was a problem hiding this comment.
Yes, that looks like the right place.
There was a problem hiding this comment.
Moved the path resolution logic to late.rs.
This change allows resolving used paths, as well as paths referring to modules declared later.
There was a problem hiding this comment.
Most of the logic added to rustc_resolve should be unnecessary, you can just use one of the existing standard path resolution functions used in code nearby in late.rs
(You can also assign this to me once ready.)
There was a problem hiding this comment.
Add the crate root for the 2015 edition and emit an error
Why?
For visibilities it is done for backward compatibility and due to early resolution, but impl restrictions are an entirely new context that doesn't need any of that.
Check whether the restricted module or crate is an ancestor
Even this is technically unnecessary for impl restrictions.
There was a problem hiding this comment.
I'm going to cc @xonx4l who DM'd me on Zulip about a different approach. I told them that I personally favored landing something and then worrying about the finer details later. However, it's obviously not up to only me; that's only me trying to have an implementation rather than the ideal one right off the bat.
Even this is technically unnecessary for impl restrictions.
Regarding this, what makes you say that? The restriction is in fact limited to ancestor modules, so it would necessarily have to be checked for.
There was a problem hiding this comment.
The restriction is in fact limited to ancestor modules
Yeah, the ancestor module condition can be added, because that's how visibilities generally work, I'm just telling that technically it will be artificial.
I personally favored landing something
I'm ok with landing something, unless it's 90% technical debt and can be cleaned up to something reasonable easily.
There was a problem hiding this comment.
I guess smart_resolve_path is what @petrochenkov was referring to. However, it seems to be used for resolving paths of types and values, and I could not find a PathSource variant corresponding to module or crate paths.
In this case, I thought resolve_path would be appropriate, so I added a slightly modified version of it, resolve_module_path. This essentially passes None for both Option<NameSpace> and Option<PathSource> to the internal function resolve_path_with_ribs used by resolve_path.
If my understanding is incorrect, please let me know.
rust/compiler/rustc_resolve/src/late.rs
Lines 4398 to 4413 in 40df631
rust/compiler/rustc_resolve/src/late.rs
Lines 1522 to 1539 in 40df631
There was a problem hiding this comment.
So the approach that I sent @jhpratt was basically because I believe the ideal enforcement should happen within the coherence engine . The idea is what if we integrate impl restriction check into orphan_check_trait_ref in the new trait solver we can trigger a coherence Error similar to E0117 before the solver even begins .
We can add impl_restriction to the interner trait to enforce it universally without duplicating the backend infrastructure Jacob already built.
Thanks!
40df631 to
dcc1cf5
Compare
This PR is linked to a GSoC proposal and is part of the progress toward implementing
implrestrictions proposed in RFC 3323.This PR implements the lowering of
implrestriction information torustc_middle.The UI tests cover path resolution errors, except for
RestrictionResolutionError::ModuleOnlyandRestrictionResolutionError::Indeterminate, as it seemed to be no existing UI tests for their visibility counterparts (ModuleOnlyandIndeterminate).This implementation basically follows the pattern used in #141754. It also introduces the enum
RestrictionTargetincompiler/rustc_resolve/src/lib.rsto allow error handling to be shared withmutrestrictions that will be added later.r? @Urgau
cc @jhpratt