-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lower all trivial const paths as ConstArgKind::Path
#135186
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
c501669
to
4efbed3
Compare
This comment has been minimized.
This comment has been minimized.
4efbed3
to
0036c2c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ConstArgKind::Path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx for working on this :3
263637d
to
a296ff8
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #135896) made this pull request unmergeable. Please resolve the merge conflicts. |
a5a9370
to
ece9e77
Compare
ConstArgKind::Path
ConstArgKind::Path
☔ The latest upstream changes (presumably #136024) made this pull request unmergeable. Please resolve the merge conflicts. |
7cbecce
to
50bd398
Compare
☔ The latest upstream changes (presumably #137164) made this pull request unmergeable. Please resolve the merge conflicts. |
0dc9d63
to
25a92ee
Compare
Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: BoxyUwU <[email protected]>
A bit tricky to support this special case now, so might as well save it for once we're ready to handle the general case. See rust-lang#135186 (comment). Co-authored-by: BoxyUwU <[email protected]>
// FIXME: should this only allow single-segment paths? | ||
&& path.is_potential_trivial_const_arg(self.tcx.features().min_generic_const_args()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// FIXME: should this only allow single-segment paths? | |
&& path.is_potential_trivial_const_arg(self.tcx.features().min_generic_const_args()) | |
&& path.is_potential_trivial_const_arg(false) |
Yes I think this should only work for mcg paths rn. Generally this needs to be kept in sync with the logic in name resolution that attempts to resolve type args in both valuens and typens and that currently uses false
.
@@ -1200,7 +1200,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r | |||
if let TyKind::Path(None, ref path) = ty.kind | |||
// We cannot disambiguate multi-segment paths right now as that requires type | |||
// checking. | |||
&& path.is_potential_trivial_const_arg() | |||
&& path.is_potential_trivial_const_arg(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.
I think making this use self.features().min_generic_const_args()
is spooky 🤔 We would need to update logic furthur down to call methods that can actually resolve multi-seg paths and idk if such methods exist.
So yeah, tl;dr we just make both of these false
and handle it down the road when we support unbraced const arguments of more complex paths (probably under a different feature gate)
const ASSOC: usize; | ||
} | ||
|
||
// FIXME(min_generic_const_args): implement support for this, behind the feature gate | ||
// FIXME(min_generic_const_args): add suggestion for mgca to this error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// FIXME(min_generic_const_args): add suggestion for mgca to this error | |
// FIXME(mgca): add suggestion for mgca to this error |
let assoc = tcx.associated_item(def_id); | ||
let ty = if matches!(assoc, ty::AssocItem { | ||
container: ty::AssocItemContainer::Impl, | ||
trait_item_def_id: None, | ||
.. | ||
}) { | ||
Ty::new_alias(tcx, ty::Inherent, ty::AliasTy::new_from_args(tcx, def_id, args)) | ||
} else { | ||
Ty::new_projection_from_args(tcx, def_id, args) | ||
}; | ||
Ok((ty, DefKind::AssocTy, def_id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah you're right I don't think we care about any of the other kinds of aliases here... It's just more concise then I guess 😅 My understanding is that type Foo = impl Trait;
is a projection/iat that normalizes to an opaque, rather than T::Foo
itself referring to an opaque so doesnt matter here
/// that the path resolves to a const param, the caller should check this. | ||
pub fn is_potential_trivial_const_arg(&self) -> bool { | ||
matches!(self.segments[..], [PathSegment { args: None, .. }]) | ||
// FIXME: add docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:3
@@ -1177,22 +1178,26 @@ pub struct Expr { | |||
} | |||
|
|||
impl Expr { | |||
// FIXME: update docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:3
I think this is basically good to go now (once minor nits are resolved). I'm really happy to see this feature at the point its at :3 thx for doing this |
☔ The latest upstream changes (presumably #135726) made this pull request unmergeable. Please resolve the merge conflicts. |
This PR:
hir::ConstArgKind::Path
ty::ConstKind::Unevaluated
#[type_const]
attribute for trait assoc consts that are allowed as const argsNext steps:
#[type_const]
if present (basically is it a const path or monomorphic anon const)r? @BoxyUwU