-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
change hir::ExprLit
to take a ConstVal
instead of an ast::Lit
#32793
Conversation
this is necessary to catch unary negation of suffixed unsigned integers and overflowing suffixed integers
} | ||
} | ||
|
||
pub fn lower_un_neg(lctx: &LoweringContext, inner: &Expr) -> (hir::Expr_, ThinAttributes) { |
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.
Is all of this necessary? Can't we just keep the negation expression?
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 works better in patterns
I am quite sure the HIR is supposed to be immutable |
I think everything which wants accurate information should use MIR as the source of truth - maybe the lints could be triggered from the MIR building code? |
@eddyb triggering lints manually is weird I have a different suggestion:
|
@@ -1145,10 +1152,17 @@ fn lit_to_const<'tcx>(lit: &ast::LitKind, | |||
infer(Infer(n), tcx, &ty::TyUint(ity), span).map(Integral) | |||
}, | |||
|
|||
LitKind::Float(ref n, _) | | |||
LitKind::Float(ref n, fty) => { | |||
if let Ok(x) = n.parse::<f64>() { |
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.
Is this supposed to do a double-rounding?
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.
I don't know why anyone would want to do that, but ConstVal
doesn't have separate variants for f64 and f32 so avoiding the double rounding doesn't seem possible without semi-large changes all throughout const eval. I've been meaning to find a short example program that demonstrates the double-rounding and file an issue. In any case, fixing this existing brokenness seems orthogonal to and out of scope for this PR.
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.
There's #32805 which is vaguely relevant.
☔ The latest upstream changes (presumably #32016) made this pull request unmergeable. Please resolve the merge conflicts. |
@eddyb I could do these changes without touching MIR. I'll simply reinstate the current HIR-lint. |
closing until things have settled around lints and MIR |
This PR uses the lowering step to move from
ast::Lit
toConstVal
. Since suffixed literals (e.g.42_u8
) are turned into concreteConstInt
variants, these literal overflow checks need to be done in the ast. This causes a little code duplication in therustc_lint/types
lints.I don't know how immutable the HIR is, but if we can run a mutating pass after typeck, we could also lower allConstInt::Infer
/ConstInt::InferSigned
variants to their concrete variants.r? @eddyb
As a next step I can remove some code-duplication between MIR-trans and normal trans (since MIR already uses
ConstVal
instead of literals).