[EXPERIMENT] Disallow all literal suffixes except the standard numeric ones by nnethercote · Pull Request #103872 · rust-lang/rust (original) (raw)

To summarize the crater results: dozens of crates use literal suffixes in all sorts of interesting ways. Here are some examples from many (but not all) of the crates that were broken by the crater run disallowing arbitrary suffixes:

Use cases:

Correctly handling some of these on the macro side must be quite the task.

Note that arbitrary literal suffixes go back to #19103 RFC 463, where the idea was introduced to "futureproof" Rust for the possibility of fancier suffixes, e.g. for different kinds of literals. One of the unresolved questions in that RFC was:

Should it be the parser or the tokenizer rejecting invalid suffixes? This is effectively asking if it is legal for syntax extensions to be passed the raw literals? That is, can a foo procedural syntax extension accept and handle literals like foo!(1u2)?

The answer chosen by the implementation was "the parser", which allowed arbitrary suffixes to be used as macro inputs. This arguably broke the futureproofing. Can new suffixes can be reasonably added, given that existing macros can (and do) effectively define their own? I'm honestly not sure.