clean up handling of paths in mgca - #160216
Conversation
|
|
This comment has been minimized.
This comment has been minimized.
8dda2c6 to
5b41ff7
Compare
| } | ||
|
|
||
| fn can_lower_path_to_const_arg_direct( | ||
| &mut self, |
There was a problem hiding this comment.
nit:
| &mut self, | |
| &self, |
There was a problem hiding this comment.
thanks! I also removed the mut from can_lower_expr_to_const_arg_direct :3
| TyKind::DirectConstArg(expr) => self.resolve_anon_const_manual( | ||
| true, | ||
| AnonConstKind::ConstArg(IsRepeatExpr::No), | ||
| |this| this.resolve_expr(&expr, None), |
There was a problem hiding this comment.
nit:
| |this| this.resolve_expr(&expr, None), | |
| |this| this.resolve_expr(expr, None), |
There was a problem hiding this comment.
out of curiosity, how did you spot this? just a good eye, or do you have some sort of setup where you can run clippy locally or something, and you checked out my code?
| { | ||
| let ct = | ||
| self.lower_const_path_to_const_arg(&None, path, res, ty.id, ty.span); | ||
| let ct = self.arena.alloc(ct); |
There was a problem hiding this comment.
Curious why we do arena alloc here?
There was a problem hiding this comment.
GenericArg::Const(&'hir ConstArg<..>)is arena'd, so it needs an arena alloc somewherelower_anon_const_to_const_argreturns ConstArg by value (this has been the case since before I started working on this code)- there's a
lower_anon_const_to_const_arg_and_allocwrapper, fwiw
- there's a
- which requires
lower_expr_to_const_arg_directto return it by value - which requires
lower_path_to_const_arg_directto do the same - and then I said shrug, make
lower_const_path_to_const_argdo the same, since it's a parallel tolower_anon_const_to_const_arg - so we arena alloc in the caller of
lower_const_path_to_const_arg, here
there's no particular reason why this whole set of functions (lower_anon_const_to_const_arg/lower_expr_to_const_arg_direct/lower_const_path_to_const_arg/lower_path_to_const_arg_direct) returns by value instead of by &'hir, could go the other way around, but they should all be consistently the same IMO.
There was a problem hiding this comment.
I guess in other words:
the diff adds an arena alloc here, because I removed it from lower_const_path_to_const_arg, because I wanted lower_const_path_to_const_arg to be more parallel to lower_anon_const_to_const_arg: they are conceptually extremely similar functions (take an X, attempt to lower it to a direct const arg, and fall back to anon const if that fails), just X is a path for one, and an AST anon const in the other.
5b41ff7 to
2f54b38
Compare
related tracking issue: #132980
Handling of ambiguous type-or-constant argument paths was really wonky and distinct from the regular
can_lower_expr_to_const_arg_directlowering paths. Clean that up and unify it, as discussed here #158479 (comment)Also, do a bunch of other little cleanups at the same time while I'm here:
I am unsure if/how this changes behavioradded a test,direct-const-arg-correct-rib.rs) - this was discussed here allow mGCA const arguments to fall back to anon consts #158617 (comment)direct_const_arg!(_)inferring to a type - this test should have been added in implement #![feature(macroless_generic_const_args)] #159058 which added this behavior (well, changed the behavior from an ICE to inferring to a type)r? @BoxyUwU