rust/compiler
Ralf Jung a1ac372894
Rollup merge of #84717 - dtolnay:literalfromstr, r=petrochenkov
impl FromStr for proc_macro::Literal

Note that unlike `impl FromStr for proc_macro::TokenStream`, this impl does not permit whitespace or comments. The input string must consist of nothing but your literal.

- `"1".parse::<Literal>()` ⟶ ok

- `"1.0".parse::<Literal>()` ⟶ ok

- `"'a'".parse::<Literal>()` ⟶ ok

- `"\"\n\"".parse::<Literal>()` ⟶ ok

- `"0 1".parse::<Literal>()` ⟶ LexError

- `" 0".parse::<Literal>()` ⟶ LexError

- `"0 ".parse::<Literal>()` ⟶ LexError

- `"/* comment */0".parse::<Literal>()` ⟶ LexError

- `"0/* comment */".parse::<Literal>()` ⟶ LexError

- `"0// comment".parse::<Literal>()` ⟶ LexError

---

## Use case

```rust
let hex_int: Literal = format!("0x{:x}", int).parse().unwrap();
```

The only way this is expressible in the current API is significantly worse.

```rust
let hex_int = match format!("0x{:x}", int)
    .parse::<TokenStream>()
    .unwrap()
    .into_iter()
    .next()
    .unwrap()
{
    TokenTree::Literal(literal) => literal,
    _ => unreachable!(),
};
```
2021-05-20 00:18:56 +02:00
..
rustc
rustc_apfloat
rustc_arena
rustc_ast
rustc_ast_lowering Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnr 2021-05-18 20:50:01 +00:00
rustc_ast_passes Stabilize extended_key_value_attributes 2021-05-18 01:01:36 -04:00
rustc_ast_pretty
rustc_attr
rustc_builtin_macros
rustc_codegen_cranelift CTFE core engine allocation & memory API improvemenets 2021-05-18 19:33:55 +02:00
rustc_codegen_llvm Auto merge of #85276 - Bobo1239:more_dso_local, r=nagisa 2021-05-19 07:25:17 +00:00
rustc_codegen_ssa Rollup merge of #85274 - luqmana:linker-is-gnu-gc-sections, r=petrochenkov 2021-05-18 22:36:04 -04:00
rustc_data_structures
rustc_driver Auto merge of #83842 - LeSeulArtichaut:thir-vec, r=nikomatsakis 2021-05-19 18:41:23 +00:00
rustc_error_codes
rustc_errors Stabilize extended_key_value_attributes 2021-05-18 01:01:36 -04:00
rustc_expand impl FromStr for proc_macro::Literal 2021-05-19 11:38:24 -07:00
rustc_feature Rollup merge of #83366 - jyn514:stabilize-key-value-attrs, r=petrochenkov 2021-05-18 22:35:54 -04:00
rustc_fs_util
rustc_graphviz
rustc_hir Rollup merge of #83366 - jyn514:stabilize-key-value-attrs, r=petrochenkov 2021-05-18 22:35:54 -04:00
rustc_hir_pretty
rustc_incremental
rustc_index
rustc_infer
rustc_interface
rustc_lexer
rustc_lint
rustc_lint_defs
rustc_llvm
rustc_macros
rustc_metadata
rustc_middle Auto merge of #85376 - RalfJung:ptrless-allocs, r=oli-obk 2021-05-19 10:11:28 +00:00
rustc_mir Auto merge of #85376 - RalfJung:ptrless-allocs, r=oli-obk 2021-05-19 10:11:28 +00:00
rustc_mir_build Auto merge of #83842 - LeSeulArtichaut:thir-vec, r=nikomatsakis 2021-05-19 18:41:23 +00:00
rustc_parse Stabilize extended_key_value_attributes 2021-05-18 01:01:36 -04:00
rustc_parse_format
rustc_passes Rollup merge of #85339 - FabianWolff:issue-83893, r=varkor 2021-05-18 14:08:51 +02:00
rustc_plugin_impl
rustc_privacy
rustc_query_impl
rustc_query_system
rustc_resolve
rustc_save_analysis
rustc_serialize
rustc_session
rustc_span Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnr 2021-05-18 20:50:01 +00:00
rustc_symbol_mangling Rollup merge of #83767 - camelid:mangle-v0-fix, r=nikomatsakis 2021-05-18 22:35:55 -04:00
rustc_target Auto merge of #85376 - RalfJung:ptrless-allocs, r=oli-obk 2021-05-19 10:11:28 +00:00
rustc_trait_selection Rollup merge of #85369 - FabianWolff:issue-84973, r=jackh726 2021-05-18 14:08:55 +02:00
rustc_traits
rustc_ty_utils
rustc_type_ir
rustc_typeck Rollup merge of #83767 - camelid:mangle-v0-fix, r=nikomatsakis 2021-05-18 22:35:55 -04:00