about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src
AgeCommit message (Collapse)AuthorLines
2022-08-28Auto merge of #100497 - kadiwa4:remove_clone_into_iter, r=cjgillotbors-2/+1
Avoid cloning a collection only to iterate over it `@rustbot` label: +C-cleanup
2022-08-25Separate CountIsStar from CountIsParam in rustc_parse_format.Mara Bos-6/+6
2022-08-23Rollup merge of #100909 - nnethercote:minor-ast-LitKind-improvement, ↵Dylan DPC-2/+2
r=petrochenkov Minor `ast::LitKind` improvements r? `@petrochenkov`
2022-08-23Rollup merge of #100851 - Alexendoo:rpf-width-prec-spans, r=fee1-deadDylan DPC-11/+16
Fix rustc_parse_format precision & width spans When a `precision`/`width` was `CountIsName - {:name$}` or `CountIs - {:10}` the `precision_span`/`width_span` was set to `None` For `width` the name span in `CountIsName(_, name_span)` had its `.start` off by one r? ``@fee1-dead`` / cc ``@PrestonFrom`` since this is similar to #99987
2022-08-23Remove the symbol from `ast::LitKind::Err`.Nicholas Nethercote-2/+2
Because it's never used meaningfully.
2022-08-22Rollup merge of #100694 - finalchild:ast-passes-diag, r=TaKO8KiDylan DPC-1/+1
Migrate rustc_ast_passes diagnostics to `SessionDiagnostic` and translatable messages (first part) Doing a full migration of the `rustc_ast_passes` crate. Making a draft here since there's not yet a tracking issue for the migrations going on. `@rustbot` label +A-translation
2022-08-22Use `AttrVec` in more places.Nicholas Nethercote-32/+34
In some places we use `Vec<Attribute>` and some places we use `ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points where we have to convert between `Vec` and `ThinVec`. This commit changes the places that use `Vec<Attribute>` to use `AttrVec`. A lot of this is mechanical and boring, but there are some interesting parts: - It adds a few new methods to `ThinVec`. - It implements `MapInPlace` for `ThinVec`, and introduces a macro to avoid the repetition of this trait for `Vec`, `SmallVec`, and `ThinVec`. Overall, it makes the code a little nicer, and has little effect on performance. But it is a precursor to removing `rustc_data_structures::thin_vec::ThinVec` and replacing it with `thin_vec::ThinVec`, which is implemented more efficiently.
2022-08-21Fix rustc_parse_format precision & width spansAlex Macleod-11/+16
2022-08-22Remove redundant clonefinalchild-1/+1
2022-08-22Use DiagnosticMessage for BufferedEarlyLint.msgfinalchild-1/+1
2022-08-21Replace #[lint/warning/error] with #[diag]Xiretza-2/+2
2022-08-20Auto merge of #100564 - nnethercote:box-ast-MacCall, r=spastorinobors-6/+6
Box the `MacCall` in various types. r? `@spastorino`
2022-08-18Auto merge of #98655 - nnethercote:dont-derive-PartialEq-ne, r=dtolnaybors-57/+25
Don't derive `PartialEq::ne`. Currently we skip deriving `PartialEq::ne` for C-like (fieldless) enums and empty structs, thus reyling on the default `ne`. This behaviour is unnecessarily conservative, because the `PartialEq` docs say this: > Implementations must ensure that eq and ne are consistent with each other: > > `a != b` if and only if `!(a == b)` (ensured by the default > implementation). This means that the default implementation (`!(a == b)`) is always good enough. So this commit changes things such that `ne` is never derived. The motivation for this change is that not deriving `ne` reduces compile times and binary sizes. Observable behaviour may change if a user has defined a type `A` with an inconsistent `PartialEq` and then defines a type `B` that contains an `A` and also derives `PartialEq`. Such code is already buggy and preserving bug-for-bug compatibility isn't necessary. Two side-effects of the change: - There is only one error message produced for types where `PartialEq` cannot be derived, instead of two. - For coverage reports, some warnings about generated `ne` methods not being executed have disappeared. Both side-effects seem fine, and possibly preferable.
2022-08-18Rollup merge of #100669 - nnethercote:attribute-cleanups, r=spastorinoMatthias Krüger-21/+5
Attribute cleanups r? `@ghost`
2022-08-17Rollup merge of #100018 - nnethercote:clean-up-LitKind, r=petrochenkovMatthias Krüger-16/+9
Clean up `LitKind` r? ``@petrochenkov``
2022-08-17Remove `attrs` arg from `typaram` and `mk_ty_param`.Nicholas Nethercote-4/+3
Because it's always empty.
2022-08-17Remove `TraitDef::attributes`.Nicholas Nethercote-17/+2
Because it's always empty.
2022-08-17Box the `MacCall` in various types.Nicholas Nethercote-6/+6
2022-08-16Rename some things related to literals.Nicholas Nethercote-3/+3
- Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is `token::Lit`, which is not a token. (This has been confusing me for a long time.) reasonable because we have an `ast::token::Lit` inside an `ast::Lit`. - Rename `LitKind::{from,to}_lit_token` as `LitKind::{from,to}_token_lit`, to match the above change and `token::Lit`.
2022-08-16Remove `{ast,hir}::WhereEqPredicate::id`.Nicholas Nethercote-5/+1
These fields are unused.
2022-08-16Make `ExtCtxt::expr_lit` non-`pub`.Nicholas Nethercote-13/+6
By using `expr_str` more and adding `expr_{char,byte_str}`.
2022-08-15Rollup merge of #100277 - m-ou-se:format-args-1, r=compiler-errorsMatthias Krüger-90/+64
Simplify format_args builtin macro implementation. Instead of a FxHashMap<Symbol, (usize, Span)> for the named arguments, this now includes the name and span in the elements of the Vec<FormatArg> directly. The FxHashMap still exists to look up the index, but no longer contains the span. Looking up the name or span of an argument is now trivial and does not need the map anymore.
2022-08-13avoid cloning and then iteratingKaDiWa-2/+1
2022-08-12Adjust cfgsMark Rousskov-1/+0
2022-08-11Rollup merge of #100392 - nnethercote:simplify-visitors, r=cjgillotMatthias Krüger-6/+2
Simplify visitors By removing some unused arguments. r? `@cjgillot`
2022-08-11Simplify `rustc_ast::visit::Visitor::visit_poly_trait_ref`.Nicholas Nethercote-6/+2
It is passed an argument that is never used.
2022-08-10Do not consider method call receiver as an argument in AST.Camille GILLOT-11/+10
2022-08-08Get rid of named_pos in format_args impl.Mara Bos-5/+1
2022-08-08Simplify format_args builtin macro implementation.Mara Bos-86/+64
Instead of a FxHashMap<Symbol, (usize, Span)> for the named arguments, this now includes the name and span in the elements of the Vec<FormatArg> directly. The FxHashMap still exists to look up the index, but no longer contains the span. Looking up the name or span of an argument is now trivial and does not need the map anymore.
2022-08-04Rollup merge of #100058 - ↵Matthias Krüger-8/+32
TaKO8Ki:suggest-positional-formatting-argument-instead-of-format-args-capture, r=estebank Suggest a positional formatting argument instead of a captured argument This patch fixes a part of #96999. fixes #98241 fixes #97311 r? `@estebank`
2022-08-04return when captured argument is not a struct fieldTakayuki Maeda-7/+8
2022-08-03suggest a positional formatting argument instead of a captured argumentTakayuki Maeda-8/+31
2022-08-02Rollup merge of #99958 - PrestonFrom:issue_99907, r=compiler-errorsMatthias Krüger-25/+59
Improve position named arguments lint underline and formatting names For named arguments used as implicit position arguments, underline both the opening curly brace and either: * if there is formatting, the next character (which will either be the closing curl brace or the `:` denoting the start of formatting args) * if there is no formatting, the entire arg span (important if there is whitespace like `{ }`) This should make it more obvious where the named argument should be. Additionally, in the lint message, emit the formatting argument names without a dollar sign to avoid potentially confusion. Fixes #99907
2022-08-02Rollup merge of #100045 - Amanieu:global_asm_may_unwind, r=tmiaskoMatthias Krüger-2/+2
Properly reject the `may_unwind` option in `global_asm!` This was accidentally accepted even though it had no effect in `global_asm!`. The option only makes sense for `asm!` which runs within a function.
2022-08-02Move if-block into closure to reduce duplicate codePreston From-7/+5
2022-08-02Improve position named arguments lint underline and formatting namesPreston From-25/+61
For named arguments used as implicit position arguments, underline both the opening curly brace and either: * if there is formatting, the next character (which will either be the closing curl brace or the `:` denoting the start of formatting args) * if there is no formatting, the entire arg span (important if there is whitespace like `{ }`) This should make it more obvious where the named argument should be. Additionally, in the lint message, emit the formatting argument names without a dollar sign to avoid potentially confusion. Fixes #99907
2022-08-02Properly reject the `may_unwind` option in `global_asm!`Amanieu d'Antras-2/+2
This was accidentally accepted even though it had no effect in `global_asm!`. The option only makes sense for `asm!` which runs within a function.
2022-08-01Don't derive `PartialEq::ne`.Nicholas Nethercote-57/+25
Currently we skip deriving `PartialEq::ne` for C-like (fieldless) enums and empty structs, thus reyling on the default `ne`. This behaviour is unnecessarily conservative, because the `PartialEq` docs say this: > Implementations must ensure that eq and ne are consistent with each other: > > `a != b` if and only if `!(a == b)` (ensured by the default > implementation). This means that the default implementation (`!(a == b)`) is always good enough. So this commit changes things such that `ne` is never derived. The motivation for this change is that not deriving `ne` reduces compile times and binary sizes. Observable behaviour may change if a user has defined a type `A` with an inconsistent `PartialEq` and then defines a type `B` that contains an `A` and also derives `PartialEq`. Such code is already buggy and preserving bug-for-bug compatibility isn't necessary. Two side-effects of the change: - There is only one error message produced for types where `PartialEq` cannot be derived, instead of two. - For coverage reports, some warnings about generated `ne` methods not being executed have disappeared. Both side-effects seem fine, and possibly preferable.
2022-07-31Always include a position span in rustc_parse_format::ArgumentAlex Macleod-8/+11
2022-07-30Auto merge of #99887 - nnethercote:rm-TreeAndSpacing, r=petrochenkovbors-8/+8
Remove `TreeAndSpacing`. A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`. r? `@petrochenkov`
2022-07-29Remove `TreeAndSpacing`.Nicholas Nethercote-8/+8
A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`.
2022-07-28Use more idiomatic rust, comment for lint logicPreston From-50/+79
2022-07-25Use Span::from_inner and make changes to precision inner span clearerPreston From-16/+14
2022-07-25Generate correct suggestion with named arguments used positionallyPreston From-61/+188
Address issue #99265 by checking each positionally used argument to see if the argument is named and adding a lint to use the name instead. This way, when named arguments are used positionally in a different order than their argument order, the suggested lint is correct. For example: ``` println!("{b} {}", a=1, b=2); ``` This will now generate the suggestion: ``` println!("{b} {a}", a=1, b=2); ``` Additionally, this check now also correctly replaces or inserts only where the positional argument is (or would be if implicit). Also, width and precision are replaced with their argument names when they exists. Since the issues were so closely related, this fix for issue #99265 also fixes issue #99266. Fixes #99265 Fixes #99266
2022-07-20Rollup merge of #99508 - ↵Matthias Krüger-3/+1
TaKO8Ki:avoid-symbol-to-string-conversion-in-BuiltinLintDiagnostics, r=compiler-errors Avoid `Symbol` to `String` conversions follow-up to #99342
2022-07-20Rollup merge of #99480 - miam-miam100:arg-format, r=oli-obkMatthias Krüger-1/+1
Diagnostic width span is not added when '0$' is used as width in format strings When the following code is run rustc does not add diagnostic spans for the width argument. Such spans are necessary for a clippy lint that I am currently writing. ```rust println!("Hello {1:0$}!", 5, "x"); // ^^ // Should have a span here ```
2022-07-20Fix off by one error and add ui test.miam-miam100-1/+1
2022-07-20avoid a `Symbol` to `String` conversionTakayuki Maeda-3/+1
2022-07-18Don't add attribute to allow unused-qualifications to derive impl'sSamrat Man Singh-9/+1
Currently `#![forbid(unused_qualifications)]` is incompatible with all derive's because we add `#[allow(unused_qualifications)]` in all generated impl's.
2022-07-16Stabilize `let_chains`Caio-1/+1