Don't inline integer literals when they overflow - new attempt by tstsrt · Pull Request #123935 · rust-lang/rust (original) (raw)

I agree that #118659 would have been much more elegant if it handled the edge case correctly. But I think this way is still ok because:

  1. Only a few types of literals will ever be inlined — at present just strings and integers, and only bools, chars, and floats are left that implement Display
  2. Each type needs to be handled differently anyway, so validity checks being performed before inlining is only a small amount of duplicated code.

I don't think it's a good idea to deliberately ignore a user when they disable a lint. Since integer overflow is not undefined behaviour in Rust, it is likely that a user who deliberately allows overflowing literals wants to observe its effect. We should support such cases. The alternative is to make integer literal overflow a hard error instead of a lint. @m-ou-se's comment indicated that this might be what users expect in the first place, but promoting this lint to a hard error might be a bigger breaking change.

Speaking of which, any resolution to this issue will be a breaking change in case anyone is depending on the current behaviour. EDIT: I forgot that the lang team already determined that this is just a bug and should be fixed as normal. Although they spoke about explicitly suffixed literals, but this fix will also make unsuffixed literals larger than i32::MAX also invalid (unless specified). This is consistent with old non-inlined behaviour, but I would like some clarity on the issue..