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 |
… r=fmease fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args Closes rust-lang#154915 Basically, we check if there are three segments and if the first one is a `DefKind::Enum`, and then use the correct segment for `Enum::<...>::Variant` syntax for both `DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)` PS: i'm not sure if the common logic from these two branches could be extracted r? fmease
… r=fmease fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args Closes rust-lang#154915 Basically, we check if there are three segments and if the first one is a `DefKind::Enum`, and then use the correct segment for `Enum::<...>::Variant` syntax for both `DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)` PS: i'm not sure if the common logic from these two branches could be extracted r? fmease
… r=fmease fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args Closes rust-lang#154915 Basically, we check if there are three segments and if the first one is a `DefKind::Enum`, and then use the correct segment for `Enum::<...>::Variant` syntax for both `DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)` PS: i'm not sure if the common logic from these two branches could be extracted r? fmease
… r=fmease fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args Closes rust-lang#154915 Basically, we check if there are three segments and if the first one is a `DefKind::Enum`, and then use the correct segment for `Enum::<...>::Variant` syntax for both `DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)` PS: i'm not sure if the common logic from these two branches could be extracted r? fmease
Rollup of 31 pull requests Successful merges: - #141030 (Expand free alias types during variance computation) - #154853 (mgca: Register `ConstArgHasType` when normalizing projection consts) - #155527 (Replace printables table with `unicode_data.rs` tables) - #156629 (Stabilize `core::range::{legacy, RangeFull, RangeTo}`) - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty) - #157282 (Fix post-monomorphization error note race in the parallel frontend) - #157352 (Make the retained dep graph deterministic under the parallel frontend) - #157601 (Emit error for unused target expression in glob and list delegations) - #157611 (Update `browser-ui-test` version to `0.24.0`) - #157620 (Add a strategy FnMut to inject behavior into the flush cycle) - #157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded) - #157646 (Keep rename-imported main alive in dead-code analysis under `--test`) - #157647 (Start using comptime for reflection intrinsics and their wrapper functions) - #157719 (resolve: Partially revert "Remove a special case for dummy imports") - #155153 (Ensure Send/Sync is not implemented for std::env::Vars{,Os}) - #155198 (fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args) - #155323 (refactor `TypeRelativePath::AssocItem` to use `AliasTerm`) - #156497 (fix-155516: Don't suggest wrong unwrap expect) - #156583 (Support defaults for static EIIs) - #157013 (Ensure inferred let pattern types are well-formed) - #157196 (Only suggest reborrowing a moved value where the reborrow is valid) - #157230 (borrowck: avoid ICE describing fields on generic params) - #157288 (platform support: add SNaN erratum to MIPS targets) - #157330 (remove `IsTypeConst` from `hir::TraitItemKind`) - #157350 (compiletest: ignore SVG `y` offset in by-lines comparison) - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs) - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`) - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N)) - #157691 (Move symbol hiding code to a new file) - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N)) - #157703 (Fix doc link to Instant sub in saturating caveat) Failed merges: - #157699 (Arg splat experiment - hir FnDecl impl)
Rollup merge of #155198 - JayanAXHF:mgca/const-generic-args, r=fmease fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args 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 for `Enum::<...>::Variant` syntax for both `DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn)` PS: i'm not sure if the common logic from these two branches could be extracted r? fmease
Rollup of 31 pull requests Successful merges: - rust-lang#141030 (Expand free alias types during variance computation) - rust-lang#154853 (mgca: Register `ConstArgHasType` when normalizing projection consts) - rust-lang#155527 (Replace printables table with `unicode_data.rs` tables) - rust-lang#156629 (Stabilize `core::range::{legacy, RangeFull, RangeTo}`) - rust-lang#157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty) - rust-lang#157282 (Fix post-monomorphization error note race in the parallel frontend) - rust-lang#157352 (Make the retained dep graph deterministic under the parallel frontend) - rust-lang#157601 (Emit error for unused target expression in glob and list delegations) - rust-lang#157611 (Update `browser-ui-test` version to `0.24.0`) - rust-lang#157620 (Add a strategy FnMut to inject behavior into the flush cycle) - rust-lang#157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded) - rust-lang#157646 (Keep rename-imported main alive in dead-code analysis under `--test`) - rust-lang#157647 (Start using comptime for reflection intrinsics and their wrapper functions) - rust-lang#157719 (resolve: Partially revert "Remove a special case for dummy imports") - rust-lang#155153 (Ensure Send/Sync is not implemented for std::env::Vars{,Os}) - rust-lang#155198 (fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args) - rust-lang#155323 (refactor `TypeRelativePath::AssocItem` to use `AliasTerm`) - rust-lang#156497 (fix-155516: Don't suggest wrong unwrap expect) - rust-lang#156583 (Support defaults for static EIIs) - rust-lang#157013 (Ensure inferred let pattern types are well-formed) - rust-lang#157196 (Only suggest reborrowing a moved value where the reborrow is valid) - rust-lang#157230 (borrowck: avoid ICE describing fields on generic params) - rust-lang#157288 (platform support: add SNaN erratum to MIPS targets) - rust-lang#157330 (remove `IsTypeConst` from `hir::TraitItemKind`) - rust-lang#157350 (compiletest: ignore SVG `y` offset in by-lines comparison) - rust-lang#157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs) - rust-lang#157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`) - rust-lang#157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N)) - rust-lang#157691 (Move symbol hiding code to a new file) - rust-lang#157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N)) - rust-lang#157703 (Fix doc link to Instant sub in saturating caveat) Failed merges: - rust-lang#157699 (Arg splat experiment - hir FnDecl impl)
Rollup of 31 pull requests Successful merges: - rust-lang#141030 (Expand free alias types during variance computation) - rust-lang#154853 (mgca: Register `ConstArgHasType` when normalizing projection consts) - rust-lang#155527 (Replace printables table with `unicode_data.rs` tables) - rust-lang#156629 (Stabilize `core::range::{legacy, RangeFull, RangeTo}`) - rust-lang#157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty) - rust-lang#157282 (Fix post-monomorphization error note race in the parallel frontend) - rust-lang#157352 (Make the retained dep graph deterministic under the parallel frontend) - rust-lang#157601 (Emit error for unused target expression in glob and list delegations) - rust-lang#157611 (Update `browser-ui-test` version to `0.24.0`) - rust-lang#157620 (Add a strategy FnMut to inject behavior into the flush cycle) - rust-lang#157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded) - rust-lang#157646 (Keep rename-imported main alive in dead-code analysis under `--test`) - rust-lang#157647 (Start using comptime for reflection intrinsics and their wrapper functions) - rust-lang#157719 (resolve: Partially revert "Remove a special case for dummy imports") - rust-lang#155153 (Ensure Send/Sync is not implemented for std::env::Vars{,Os}) - rust-lang#155198 (fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args) - rust-lang#155323 (refactor `TypeRelativePath::AssocItem` to use `AliasTerm`) - rust-lang#156497 (fix-155516: Don't suggest wrong unwrap expect) - rust-lang#156583 (Support defaults for static EIIs) - rust-lang#157013 (Ensure inferred let pattern types are well-formed) - rust-lang#157196 (Only suggest reborrowing a moved value where the reborrow is valid) - rust-lang#157230 (borrowck: avoid ICE describing fields on generic params) - rust-lang#157288 (platform support: add SNaN erratum to MIPS targets) - rust-lang#157330 (remove `IsTypeConst` from `hir::TraitItemKind`) - rust-lang#157350 (compiletest: ignore SVG `y` offset in by-lines comparison) - rust-lang#157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs) - rust-lang#157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`) - rust-lang#157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N)) - rust-lang#157691 (Move symbol hiding code to a new file) - rust-lang#157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N)) - rust-lang#157703 (Fix doc link to Instant sub in saturating caveat) Failed merges: - rust-lang#157699 (Arg splat experiment - hir FnDecl impl)
|
@rust-timer build 4858221 |
|
Queued 4858221 with parent 485ec3f, future comparison URL. |
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