about summary refs log tree commit diff
path: root/src/libsyntax/print/pprust.rs
AgeCommit message (Collapse)AuthorLines
2019-03-24Remove methods is_struct/is_tuple/is_unit from VariantDataVadim Petrochenkov-35/+38
2019-03-24Separate variant id and variant constructor id.David Wood-0/+1
This commit makes two changes - separating the `NodeId` that identifies an enum variant from the `NodeId` that identifies the variant's constructor; and no longer creating a `NodeId` for `Struct`-style enum variants and structs. Separation of the variant id and variant constructor id will allow the rest of RFC 2008 to be implemented by lowering the visibility of the variant's constructor without lowering the visbility of the variant itself. No longer creating a `NodeId` for `Struct`-style enum variants and structs mostly simplifies logic as previously this `NodeId` wasn't used. There were various cases where the `NodeId` wouldn't be used unless there was an unit or tuple struct or enum variant but not all uses of this `NodeId` had that condition, by removing this `NodeId`, this must be explicitly dealt with. This change mostly applied cleanly, but there were one or two cases in name resolution and one case in type check where the existing logic required a id for `Struct`-style enum variants and structs.
2019-03-18Rename typarams to param_namesvarkor-2/+2
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
2019-03-16Refactor away `NestedMetaItemKind`Vadim Petrochenkov-3/+3
Remove methods `Attribute::span` and `MetaItem::span` duplicating public fields
2019-03-16Rename `MetaItem::ident` to `MetaItem::path`Vadim Petrochenkov-3/+3
2019-03-02Fix C-variadic function printingDan Robertson-3/+0
There is no longer a need to append the string `", ..."` to a functions args as `...` is parsed as an argument and will appear in the functions arguments.
2019-02-28Auto merge of #57760 - dlrobertson:varargs1, r=alexregbors-2/+5
Support defining C compatible variadic functions ## Summary Add support for defining C compatible variadic functions in unsafe rust with `extern "C"` according to [RFC 2137]. ## Details ### Parsing When parsing a user defined function that is `unsafe` and `extern "C"` allow variadic signatures and inject a "spoofed" `VaList` in the new functions signature. This allows the user to interact with the variadic arguments via a `VaList` instead of manually using `va_start` and `va_end` (See [RFC 2137] for details). ### Codegen When running codegen for a variadic function, remove the "spoofed" `VaList` from the function signature and inject `va_start` when the arg local references are created for the function and `va_end` on return. ## TODO - [x] Get feedback on injecting `va_start/va_end` in MIR vs codegen - [x] Properly inject `va_end` - It seems like it should be possible to inject `va_end` on the `TerminatorKind::Return`. I just need to figure out how to get the `LocalRef` here. - [x] Properly call Rust defined C variadic functions in Rust - The spoofed `VaList` causes problems here. Related to: #44930 r? @ghost [RFC 2137]: https://github.com/rust-lang/rfcs/blob/master/text/2137-variadic.md
2019-02-27Rename variadic to c_variadicDan Robertson-2/+2
Function signatures with the `variadic` member set are actually C-variadic functions. Make this a little more explicit by renaming the `variadic` boolean value, `c_variadic`.
2019-02-27Support defining C compatible variadic functionsDan Robertson-0/+3
Add support for defining C compatible variadic functions in unsafe rust with extern "C".
2019-02-24Deny `async fn` in 2015 editionNathan Corbyn-2/+2
Fix style issues and update diagnostic messages Update src/librustc_passes/diagnostics.rs Co-Authored-By: doctorn <me@nathancorbyn.com> Deny nested `async fn` in Rust 2015 edition Deny nested `async fn` in Rust 2015 edition Deny nested `async fn` in Rust 2015 edition
2019-02-18Remove `LazyTokenStream`.Nicholas Nethercote-1/+1
It's present within `Token::Interpolated` as an optimization, so that if a nonterminal is converted to a `TokenStream` multiple times, the first-computed value is saved and reused. But in practice it's not needed. `interpolated_to_tokenstream()` is a cold function: it's only called a few dozen times while compiling rustc itself, and a few hundred times across the entire `rustc-perf` suite. Furthermore, when it is called, it is almost always the first conversion, so no benefit is gained from it. So this commit removes `LazyTokenStream`, along with the now-unnecessary `Token::interpolated()`. As well as a significant simplification, the removal speeds things up slightly, mostly due to not having to `drop` the `LazyTokenStream` instances.
2019-02-18Change `Token::interpolated_to_tokenstream()`.Nicholas Nethercote-24/+28
It is currently a method of `Token`, but it only is valid to call if `self` is a `Token::Interpolated`. This commit eliminates the possibility of misuse by changing it to an associated function that takes a `Nonterminal`, which also simplifies the call sites. This requires splitting out a new function, `nonterminal_to_string`.
2019-02-12New return types for str::escape_* that impl Display and Iterator<char>Simon Sapin-1/+1
As FCP’ed in the tracking issue: https://github.com/rust-lang/rust/issues/27791#issuecomment-376864727
2019-02-07Add pretty-printing for const genericsvarkor-1/+11
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
2019-02-07libsyntax => 2018Taiki Endo-22/+23
2019-01-20Auto merge of #57651 - JohnTitor:give-char-type, r=estebankbors-0/+9
Implement new literal type `Err` Fixes #57384 I removed `return Ok`, otherwise, two errors occur. Any solutions? r? @estebank
2019-01-20Mark incorrect recovered `char` literals as `TyErr` to avoid type errorsYuki Okushi-0/+8
2019-01-16Add new literal type ErrYuki Okushi-0/+1
2019-01-14Remove `ThinTokenStream`.Nicholas Nethercote-1/+1
`TokenStream` is now almost identical to `ThinTokenStream`. This commit removes the latter, replacing it with the former.
2018-12-27AST/HIR: Introduce `ExprKind::Err` for better error recovery in the front-endVadim Petrochenkov-1/+8
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-19Reintroduce special pretty-printing for `$crate` when it's necessary for ↵Vadim Petrochenkov-2/+25
proc macros
2018-12-19Remove `eliminate_crate_var` and special pretty-printing for `$crate`Vadim Petrochenkov-23/+2
2018-12-10Remove `tokenstream::Delimited`.Nicholas Nethercote-4/+4
Because it's an extra type layer that doesn't really help; in a couple of places it actively gets in the way, and overall removing it makes the code nicer. It does, however, move `tokenstream::TokenTree` further away from the `TokenTree` in `quote.rs`. More importantly, this change reduces the size of `TokenStream` from 48 bytes to 40 bytes on x86-64, which is enough to slightly reduce instruction counts on numerous benchmarks, the best by 1.5%. Note that `open_tt` and `close_tt` have gone from being methods on `Delimited` to associated methods of `TokenTree`.
2018-12-04syntax: Rename some keywordsVadim Petrochenkov-2/+2
`CrateRoot` -> `PathRoot`, `::` doesn't necessarily mean crate root now `SelfValue` -> `SelfLower`, `SelfType` -> `SelfUpper`, both `self` and `Self` can be used in type and value namespaces now
2018-12-03Rollup merge of #56438 - yui-knk:remove_not_used_DotEq_token, r=petrochenkovkennytm-1/+0
Remove not used `DotEq` token Currently libproc_macro does not use `DotEq` token. https://github.com/rust-lang/rust/pull/49545 changed libproc_macro to not generate `DotEq` token.
2018-12-03Rollup merge of #56419 - mark-i-m:remove-try, r=Centrilkennytm-1/+1
Remove some uses of try!
2018-12-02Remove not used `DotEq` tokenyui-knk-1/+0
Currently libproc_macro does not use `DotEq` token. https://github.com/rust-lang/rust/pull/49545 changed libproc_macro to not generate `DotEq` token.
2018-12-01remove some uses of try!Mark Mansi-1/+1
2018-11-29Use `Cow` in `Token::String`.Nicholas Nethercote-53/+53
`Printer::word` takes a `&str` and converts it into a `String`, which causes an allocation. But that allocation is rarely necessary, because `&str` is almost always a `&'static str` or a `String` that won't be used again. This commit changes `Token::String` so it holds a `Cow<'static, str>` instead of a `String`, which avoids a lot of allocations.
2018-10-19Prefer unwrap_or_else to unwrap_or in case of function calls/allocationsljedrz-1/+1
2018-10-02abolish ICE when pretty-printing async blockZack M. Davis-0/+3
Joshua Netterfield reported an ICE when the unused-parentheses lint triggered around an async block (#54752). In order to compose an autofixable suggestion, the lint invokes the pretty-printer on the unnecessarily-parenthesized expression. (One wonders why the lint doesn't just use `SourceMap::span_to_snippet` instead, to preserve the formatting of the original source?—but for that, you'd have to ask the author of 5c9f806d.) But then the pretty-printer panics when trying to call `<pprust::State as PrintState>::end` when `State.boxes` is empty. Empirically, the problem would seem to be solved if we start some "boxes" beforehand in the `ast::ExprKind::Async` arm of the big match in `print_expr_outer_attr_style`, exactly like we do in the immediately-preceding match arm for `ast::ExprKind::Block`—it would seem pretty ("pretty") reasonable for the pretty-printing of async blocks to work a lot like the pretty-printing of ordinary non-async blocks, right?? Of course, it would be shamefully cargo-culty to commit code on the basis of this kind of mere reasoning-by-analogy (in contrast to understanding the design of the pretty-printer in such detail that the correctness of the patch is comprehended with all the lucid certainty of mathematical proof, rather than being merely surmised by intuition). But maybe we care more about fixing the bug with high probability today, than with certainty in some indefinite hypothetical future? Maybe the effort is worth a fifth of a shirt?? Humbly resolves #54752.
2018-09-10Correctly close indentation blocks when pretty printing non-inline moduleTinco Andringa-1/+2
2018-09-10pretty=expanded should expand mod declarationsTinco Andringa-3/+10
2018-09-10Track whether module declarations are inline (fixes #12590)Tinco Andringa-4/+10
2018-09-01Auto merge of #53815 - F001:if-let-guard, r=petrochenkovbors-4/+8
refactor match guard This is the first step to implement RFC 2294: if-let-guard. Tracking issue: https://github.com/rust-lang/rust/issues/51114 The second step should be introducing another variant `IfLet` in the Guard enum. I separated them into 2 PRs for the convenience of reviewers. r? @petrochenkov
2018-08-30introduce Guard enumF001-4/+8
2018-08-27Remove Node* prefix from AnnNodevarkor-23/+21
2018-08-23Auto merge of #52602 - scottmcm:tryblock-expr, r=nikomatsakisbors-2/+2
Implement try block expressions I noticed that `try` wasn't a keyword yet in Rust 2018, so... ~~Fix​es https://github.com/rust-lang/rust/issues/52604~~ That was fixed by PR https://github.com/rust-lang/rust/pull/53135 cc https://github.com/rust-lang/rust/issues/31436 https://github.com/rust-lang/rust/issues/50412
2018-08-19Parse try blocks with the try keyword instead of do catch placeholderScott McMurray-1/+1
2018-08-19Rename `Catch` variants to `TryBlock`Scott McMurray-1/+1
(Not `Try` since `QuestionMark` is using that.)
2018-08-19mv (mod) codemap source_mapDonato Sciarra-8/+8
2018-08-19mv CodeMap SourceMapDonato Sciarra-5/+5
2018-07-29Auto merge of #52767 - ljedrz:avoid_format, r=petrochenkovbors-1/+1
Prefer to_string() to format!() Simple benchmarks suggest in some cases it can be faster by even 37%: ``` test converting_f64_long ... bench: 339 ns/iter (+/- 199) test converting_f64_short ... bench: 136 ns/iter (+/- 34) test converting_i32_long ... bench: 87 ns/iter (+/- 16) test converting_i32_short ... bench: 87 ns/iter (+/- 49) test converting_str ... bench: 54 ns/iter (+/- 15) test formatting_f64_long ... bench: 349 ns/iter (+/- 176) test formatting_f64_short ... bench: 145 ns/iter (+/- 14) test formatting_i32_long ... bench: 98 ns/iter (+/- 14) test formatting_i32_short ... bench: 93 ns/iter (+/- 15) test formatting_str ... bench: 86 ns/iter (+/- 23) ```
2018-07-29Auto merge of #52764 - sinkuu:cleanup, r=nikomatsakisbors-6/+4
Misc cleanups
2018-07-27Use slices where a vector is not necessaryljedrz-1/+1
2018-07-27Use str::repeatShotaro Yamada-6/+4
2018-07-27Prefer to_string() to format!()ljedrz-1/+1
2018-07-18Implement existential typesOliver Schneider-5/+19
2018-07-14Remove most of `PartialEq` impls from AST and HIR structuresVadim Petrochenkov-1/+3