Don't try to promote already promoted out temporaries#54816
Don't try to promote already promoted out temporaries#54816bors merged 6 commits intorust-lang:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
b62bc2b to
8b097c4
Compare
|
Ping from triage @eddyb: This PR requires your review. |
|
r? @alexreg |
|
@oli-obk I don't have r+ powers. Unless you just want me to review the code... |
|
Oh I guess that's why I can't r? you :D Yes a review would be great. You've been in that code a lot lately so I assumed you're the best one to review right now |
|
@bors delegate=alexreg let's see if that works |
|
✌️ @alexreg can now approve this pull request |
| return | ||
| } | ||
| if this.qualif.is_empty() { | ||
| // if the argument requires a constant, we care about constness, not |
There was a problem hiding this comment.
This could do with elaboration. What do we mean by "requires a constant"? Where is this checked for?
|
Generally looks fine otherwise though... |
| let operand = Operand::Copy(promoted_place(ty, span)); | ||
| mem::replace(&mut args[index], operand) | ||
| } | ||
| // already promoted out |
There was a problem hiding this comment.
Can we explain how we know the candidate is already promoted out here?
| // which happens even without the user requesting it. | ||
| // We can error out with a hard error if the argument is not | ||
| // constant here. | ||
| if (this.qualif - Qualif::NOT_PROMOTABLE).is_empty() { |
There was a problem hiding this comment.
Thanks for expanding on this. I still think the terminology is a bit confusing: it seems to suggest "return values are never promotable but we're going to promote one here anyway, because it's const."
There was a problem hiding this comment.
Well... yes. The rules for automatic promotion don't include function calls. The rules for constants do include function calls. Since the current function requires a constant here, if we did something like 0usize - 1 we'd get an error. If you just do &(0usize - 1) in normal runtime code, you get a warning and a panic at runtime (in debug mode).
There was a problem hiding this comment.
Yeah sure, I agree this makes sense, but could we just change the comment to "never promoted for runtime-evaluated/non-const/whatever functions" or such, just to be super-clear and make me happy? :-)
| // Be conservative about the returned value of a const fn. | ||
| let tcx = self.tcx; | ||
| let ty = dest.ty(self.mir, tcx).to_ty(tcx); | ||
| self.qualif = Qualif::empty(); |
There was a problem hiding this comment.
Why did you remove this line?
There was a problem hiding this comment.
Otherwise we'd be erasing the NOT_PROMOTABLE qualification we added above.
There was a problem hiding this comment.
Yep, but I think you want to reset all fields apart from that one, no? Alternatively, just make sure that's set after self.qualif is reset.
| // already promoted this call away entirely. This case occurs when calling | ||
| // a function requiring a constant argument and as that constant value | ||
| // providing a value whose computation contains another call to a function | ||
| // requiring a constant argument. |
There was a problem hiding this comment.
Thanks for adding this. Sorry to nitpick, but this 2nd sentence doesn't parse grammatically.
|
Looks good, @oli-obk! Thanks for bearing with me. |
|
@bors r+ |
|
📌 Commit fd77500 has been approved by |
Don't try to promote already promoted out temporaries fixes rust-lang#53201 r? @eddyb
Don't try to promote already promoted out temporaries fixes rust-lang#53201 r? @eddyb
Rollup of 21 pull requests Successful merges: - #54816 (Don't try to promote already promoted out temporaries) - #54824 (Cleanup rustdoc tests with `@!has` and `@!matches`) - #54921 (Add line numbers option to rustdoc) - #55167 (Add a "cheap" mode for `compute_missing_ctors`.) - #55258 (Fix Rustdoc ICE when checking blanket impls) - #55264 (Compile the libstd we distribute with -Ccodegen-unit=1) - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators) - #55292 (Macro diagnostics tweaks) - #55298 (Point at macro definition when no rules expect token) - #55301 (List allowed tokens after macro fragments) - #55302 (Extend the impl_stable_hash_for! macro for miri.) - #55325 (Fix link to macros chapter) - #55343 (rustbuild: fix remap-debuginfo when building a release) - #55346 (Shrink `Statement`.) - #55358 (Remove redundant clone (2)) - #55370 (Update mailmap for estebank) - #55375 (Typo fixes in configure_cmake comments) - #55378 (rustbuild: use configured linker to build boostrap) - #55379 (validity: assert that unions are non-empty) - #55383 (Use `SmallVec` for the queue in `coerce_unsized`.) - #55391 (bootstrap: clean up a few clippy findings)
|
Cc @eddyb this touched const qualification. |
|
@RalfJung I should've said something, but I reviewed this and it appears to be a sound relaxation. |
fixes #53201
r? @eddyb