refactor: add move check_align to parse_alignment#153189
refactor: add move check_align to parse_alignment#153189JayanAXHF wants to merge 1 commit intorust-lang:mainfrom
check_align to parse_alignment#153189Conversation
|
Some changes occurred in compiler/rustc_attr_parsing |
| let max = Size::from_bits(cx.sess.target.pointer_width).signed_int_max() as u64; | ||
| // lit must be < 2^29 | ||
| let lit_u64 = literal.get().try_into().map_err(|_| "alignment larger than 2^29")?; | ||
| let align = Align::from_bytes(lit_u64).map_err(|_| "alignment larger than 2^29")?; |
There was a problem hiding this comment.
Could you change this code back to how it was with the and_then so that the error message isn't duplicated?
| return Err("not a power of two"); | ||
| } | ||
| // alignment must not be larger than the pointer width (`isize::MAX`) | ||
| let max = Size::from_bits(cx.sess.target.pointer_width).signed_int_max() as u64; |
There was a problem hiding this comment.
nit: Could you put this variable next to if statement where it is used?
| let lit_u64 = literal.get().try_into().map_err(|_| "alignment larger than 2^29")?; | ||
| let align = Align::from_bytes(lit_u64).map_err(|_| "alignment larger than 2^29")?; | ||
| if align.bytes() > max { | ||
| return Err("alignment larger than pointer width: {max}"); |
There was a problem hiding this comment.
This is not how formatting works, you need to make this a format string :P
There was a problem hiding this comment.
ohhh how did that get though :3
There was a problem hiding this comment.
Turns out, since this needs to return a &'static str, i can't include the max in the error message
There was a problem hiding this comment.
Returning a String is also fine :) I don't think this needs to return a 'static str, that's just what it happens to atm
There was a problem hiding this comment.
I think it needs the &'static str because session_diagnostics::InvalidAlignmentValue<'a> takes an &'a str. I could probably change that since it isn't used in many other places
Note: maybe a Cow<'static, str> would be better?
There was a problem hiding this comment.
You can also just make that take a String :)
These are diagnostics so performance is not significant, just do what is easiest
| } | ||
| } | ||
|
|
||
| fn parse_alignment(node: &LitKind) -> Result<Align, &'static str> { |
There was a problem hiding this comment.
You should just be able to remove the old check_align function, and do nothing in the place where it is called
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Part of #153101
r? @JonathanBrouwer
PS: jonathan i'm not sure about what to do with
check_alignnow