about summary refs log tree commit diff
path: root/src/libsyntax_ext
AgeCommit message (Collapse)AuthorLines
2018-08-01Rollup merge of #52888 - estebank:shell-sugg, r=oli-obkPietro Albini-34/+46
Use suggestions for shell format arguments Follow up to #52649.
2018-07-31Use suggestions for shell format argumentsEsteban Küber-34/+46
2018-07-29Auto merge of #52738 - ljedrz:push_to_extend, r=eddybbors-22/+19
Replace push loops with extend() where possible Or set the vector capacity where I couldn't do it. According to my [simple benchmark](https://gist.github.com/ljedrz/568e97621b749849684c1da71c27dceb) `extend`ing a vector can be over **10 times** faster than `push`ing to it in a loop: 10 elements (6.1 times faster): ``` test bench_extension ... bench: 75 ns/iter (+/- 23) test bench_push_loop ... bench: 458 ns/iter (+/- 142) ``` 100 elements (11.12 times faster): ``` test bench_extension ... bench: 87 ns/iter (+/- 26) test bench_push_loop ... bench: 968 ns/iter (+/- 3,528) ``` 1000 elements (11.04 times faster): ``` test bench_extension ... bench: 311 ns/iter (+/- 9) test bench_push_loop ... bench: 3,436 ns/iter (+/- 233) ``` Seems like a good idea to use `extend` as much as possible.
2018-07-29Replace push loops with collect() and extend() where possibleljedrz-22/+19
2018-07-29Auto merge of #52767 - ljedrz:avoid_format, r=petrochenkovbors-2/+2
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-27Auto merge of #52336 - ishitatsuyuki:dyn-rollup, r=Mark-Simulacrumbors-2/+0
Rollup of bare_trait_objects PRs All deny attributes were moved into bootstrap so they can be disabled with a line of config. Warnings for external tools are allowed and it's up to the tool's maintainer to keep it warnings free. r? @Mark-Simulacrum cc @ljedrz @kennytm
2018-07-27Prefer to_string() to format!()ljedrz-2/+2
2018-07-26Rollup merge of #52649 - estebank:fmt-span, r=oli-obkMark Rousskov-99/+222
Point spans to inner elements of format strings - Point at missing positional specifiers in string literal ``` error: invalid reference to positional arguments 3, 4 and 5 (there are 3 arguments) --> $DIR/ifmt-bad-arg.rs:34:38 | LL | format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2); | ^^ ^^ ^^ | = note: positional arguments are zero-based ``` - Point at named formatting specifier in string literal ``` error: there is no argument named `foo` --> $DIR/ifmt-bad-arg.rs:37:17 | LL | format!("{} {foo} {} {bar} {}", 1, 2, 3); | ^^^^^ ``` - Update label for formatting string in "multiple unused formatting arguments" to be more correct ``` error: multiple unused formatting arguments --> $DIR/ifmt-bad-arg.rs:42:17 | LL | format!("", 1, 2); //~ ERROR: multiple unused formatting arguments | -- ^ ^ | | | multiple missing formatting specifiers ``` - When using `printf` string formatting, provide a structured suggestion instead of a note ``` error: multiple unused formatting arguments --> $DIR/format-foreign.rs:12:30 | LL | println!("%.*3$s %s!/n", "Hello,", "World", 4); //~ ERROR multiple unused formatting arguments | -------------- ^^^^^^^^ ^^^^^^^ ^ | | | multiple missing formatting specifiers | = note: printf formatting not supported; see the documentation for `std::fmt` help: format specifiers in Rust are written using `{}` | LL | println!("{:.2$} {}!/n", "Hello,", "World", 4); //~ ERROR multiple unused formatting arguments | ^^^^^^ ^^ ```
2018-07-24Add span label for format str missing specifierEsteban Küber-8/+11
2018-07-24Rename method and remove commented out codeEsteban Küber-4/+2
2018-07-24Fix unittestEsteban Küber-24/+26
2018-07-25Deny bare_trait_objects globallyTatsuyuki Ishi-2/+0
2018-07-24Use suggestions for `printf` formatEsteban Küber-5/+66
2018-07-24Rollup merge of #52658 - Wallacoloo:topics/use-option-methods, r=cramertjMark Rousskov-8/+4
Prefer `Option::map`/etc over `match` wherever it improves clarity This isn't intended to change behavior anywhere. A lot of times statements like `match x { None => None, Some(y) => [...] }` can be rewritten using `Option::map` or `Option::and_then` in a way that preserves or improves clarity, so that's what I've done here. I think it's particularly valuable to keep things in `libcore` and `libstd` pretty/idiomatic since it's not uncommon to follow the `[src]` links when browsing the rust-lang.org docs for std/core. If there's any concern about pushing style-based changes though, I'll happily back out the non-std/core commits here.
2018-07-24Reword missing formatting arguments labelEsteban Küber-1/+1
2018-07-23libsyntax_ext: Prefer `Option::map` over `match` where applicableColin Wallace-8/+4
2018-07-23Only point at inside of string literals if they're actually string literalsEsteban Küber-6/+24
2018-07-23Point only at invalid positional argumentsEsteban Küber-62/+76
2018-07-23Point at incorrect named arg in format stringEsteban Küber-2/+19
2018-07-23Replace a few expect+format combos with unwrap_or_else+panicljedrz-2/+2
2018-07-22Point at internal span in format stringEsteban Küber-12/+22
2018-07-21fix logic bugEsteban Küber-2/+2
2018-07-21Remove dependency on `libsyntax`Esteban Küber-1/+5
2018-07-21Gate `format_args_nll` behind feature flagEsteban Küber-0/+15
2018-07-21Suggest space separated format str literalEsteban Küber-1/+1
2018-07-19Use correct spans for format string errorsEsteban Küber-1/+1
When encountering format string errors in a raw string, or regular string literal with embedded newlines, account for the positional change to use correct spans. :drive by fix: 🚗
2018-07-19rework printlnEsteban Küber-2/+30
2018-07-19review comments: modify note wording and change `println`Esteban Küber-1/+1
- Don't print the newline on its own to avoid the possibility of printing it out of order due to `stdout` locking. - Modify wording of `concat!()` with non-literals to not mislead into believing that only `&str` literals are accepted. - Add test for `concat!()` with non-literals.
2018-07-19Improve suggestion for missing fmt str in printlnEsteban Küber-14/+29
Avoid using `concat!(fmt, "\n")` to improve the diagnostics being emitted when the first `println!()` argument isn't a formatting string literal.
2018-07-15Auto merge of #52383 - petrochenkov:pmns, r=alexcrichtonbors-5/+0
resolve: Functions introducing procedural macros reserve a slot in the macro namespace as well Similarly to https://github.com/rust-lang/rust/pull/52234, this gives us symmetry between internal and external views of a crate, but in this case it's always an error to call a procedural macro in the same crate in which it's defined. Closes https://github.com/rust-lang/rust/issues/52225
2018-07-14Auto merge of #52326 - alexcrichton:tweak-proc-macro-expand, r=petrochenkovbors-3/+8
rustc: Tweak expansion of #[proc_macro] for 2018 The syntactical expansion of `#[proc_macro]` and related attributes currently contains absolute paths which conflicts with a lint for the 2018 edition, causing issues like #52214. This commit puts a band-aid on the issue by ensuring that procedural macros can also migrate to the 2018 edition for now by tweaking the expansion based on what features are activated. A more long-term solution would probably tweak the edition hygiene of spans, but this should do the trick for now. Closes #52214
2018-07-14Functions introducing procedural macros reserve a slot in the macro ↵Vadim Petrochenkov-5/+0
namespace as well
2018-07-14Address commentsVadim Petrochenkov-6/+4
2018-07-14Remove some tests using AST comparisons, fix other testsVadim Petrochenkov-4/+4
2018-07-14Remove most of `PartialEq` impls from AST and HIR structuresVadim Petrochenkov-20/+16
2018-07-13rustc: Tweak expansion of #[proc_macro] for 2018Alex Crichton-3/+8
The syntactical expansion of `#[proc_macro]` and related attributes currently contains absolute paths which conflicts with a lint for the 2018 edition, causing issues like #52214. This commit puts a band-aid on the issue by ensuring that procedural macros can also migrate to the 2018 edition for now by tweaking the expansion based on what features are activated. A more long-term solution would probably tweak the edition hygiene of spans, but this should do the trick for now. Closes #52214
2018-07-13proc_macro: Fix crate root detectionVadim Petrochenkov-10/+6
2018-07-12Rollup merge of #52295 - ljedrz:dyn_libsyntax_ext, r=petrochenkovkennytm-35/+37
Deny bare trait objects in src/libsyntax_ext Enforce `#![deny(bare_trait_objects)]` in `src/libsyntax_ext`.
2018-07-12Rollup merge of #52276 - alexcrichton:validate-proc-macro-attr, r=petrochenkovkennytm-4/+4
rustc: Verify #[proc_macro] is only a word ... and perform the same verification for #[proc_macro_attribute], currently neither of these attributes take any arguments. Closes #52273
2018-07-12Deny bare trait objects in src/libsyntax_extljedrz-35/+37
2018-07-11rustc: Verify #[proc_macro] is only a wordAlex Crichton-4/+4
... and perform the same verification for #[proc_macro_attribute], currently neither of these attributes take any arguments. Closes #52273
2018-07-11suggest on new snippetcsmoe-29/+29
2018-07-06suggests with whole macro callcsmoe-10/+1
2018-07-04add span notecsmoe-1/+8
2018-07-03Suggestion for printcsmoe-1/+8
2018-06-27Implement `#[macro_export(local_inner_macros)]`Vadim Petrochenkov-0/+3
2018-06-26migrate codebase to `..=` inclusive range patternsZack M. Davis-7/+7
These were stabilized in March 2018's #47813, and are the Preferred Way to Do It going forward (q.v. #51043).
2018-06-23hygiene: Merge `NameAndSpan` into `ExpnInfo`Vadim Petrochenkov-10/+8
2018-06-21Parse async fn header.Without Boats-5/+5
This is gated on edition 2018 & the `async_await` feature gate. The parser will accept `async fn` and `async unsafe fn` as fn items. Along the same lines as `const fn`, only `async unsafe fn` is permitted, not `unsafe async fn`.The parser will not accept `async` functions as trait methods. To do a little code clean up, four fields of the function type struct have been merged into the new `FnHeader` struct: constness, asyncness, unsafety, and ABI. Also, a small bug in HIR printing is fixed: it previously printed `const unsafe fn` as `unsafe const fn`, which is grammatically incorrect.
2018-06-20Fix additional commentsvarkor-1/+1