fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args#155198
Conversation
|
HIR ty lowering was modified cc @fmease |
This comment has been minimized.
This comment has been minimized.
f0b92a1 to
28594d7
Compare
|
Fixed that @fmease |
| .prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None); | ||
|
|
||
| // Check if this is the Enum::<...>::Variant form | ||
| let use_enum_segment = if path.segments.len() == 2 |
There was a problem hiding this comment.
The path should be allowed to have more than two segments. Right now, you're only allowing Enum::<...>::Variant but not e.g., very::long::path::to::Enum::<...>::Variant. So it should be >= 2 rather than == 2.
Once you implement that you also need to make sure to reject arguments on all segments before the enum segment since module::<...>::Enum::<...>::Variant should be forbidden.
|
@rustbot ready |
| let _ = self | ||
| .prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None); | ||
|
|
||
| let generics = self.probe_generic_path_segments( |
There was a problem hiding this comment.
I'm glad my suggestion to use probe_generic_path_segments is working out.
However, calling that function isn't sufficient, you still need (manually) prohibit generic args on all path segments that aren't generic using prohibit_generic_args, I know this API is a bit awkward. See the preexisting callers of probe_generic_path_segments for how they do it.
(I guess it could be nice if we'd have one function that does the "probing" and the "prohibiting" at once for convenience but I don't think we can do that yet w/o refactoring some things first, so that has to wait for another time)
There was a problem hiding this comment.
I don't think we can do that yet w/o refactoring some things first
I believe we can. Currently, how this is done is
let generic_segments =
self.probe_generic_path_segments(path.segments, opt_self_ty, kind, did, span);
let indices: FxHashSet<_> =
generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
let _ = self.prohibit_generic_args(
path.segments.iter().enumerate().filter_map(|(index, seg)| {
if !indices.contains(&index) { Some(seg) } else { None }
}),
GenericsArgsErrExtend::DefVariant(&path.segments),
);I believe this could just be turned into a function
There was a problem hiding this comment.
Ah, in that case, go for it! Unless you'd to leave it to a follow-up PR; this way we can merge this PR faster :)
There was a problem hiding this comment.
Let's go for a follow-up PR. I'll create an issue so i don't forget if that's okay
|
apologies for the delay, will look into this on the weekend |
This comment has been minimized.
This comment has been minimized.
c9459f9 to
1e6067d
Compare
|
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. |
There was a problem hiding this comment.
Apologies for the delay, two final nits and one other note.
| let _ = self | ||
| .prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None); | ||
|
|
||
| let generics = self.probe_generic_path_segments( |
There was a problem hiding this comment.
Ah, in that case, go for it! Unless you'd to leave it to a follow-up PR; this way we can merge this PR faster :)
This comment has been minimized.
This comment has been minimized.
…unit & tuple variant constructions in (direct) const args
9d936c2 to
7fe4408
Compare
|
Thanks for your work and your patience! :) I've |
|
@rust-timer build 4858221 |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (4858221): comparison URL. Overall result: no relevant changes - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (primary -0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -2.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 517.006s -> 518.123s (0.22%) |
View all comments
Closes #154915
Basically, we check if there are three segments and if the first one is a
DefKind::Enum, and then use the correct segment forEnum::<...>::Variantsyntax for bothDefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)PS: i'm not sure if the common logic from these two branches could be extracted
r? fmease