about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src
AgeCommit message (Collapse)AuthorLines
2022-07-15Only suggest if span is not erroneousMichael Goulet-1/+1
2022-07-15Fix ICE in named_arguments_used_positionally lintMichael Goulet-9/+8
2022-07-15Auto merge of #99046 - nnethercote:final-derive-output-improvements, ↵bors-320/+285
r=Mark-Simulacrum Final derive output improvements With all these changes, the derive output in `deriving-all-codegen.stdout` is pretty close to optimal, i.e. very similar to what you'd write by hand. r? `@ghost`
2022-07-14Rollup merge of #99192 - Amanieu:fix-asm-srcloc, r=petrochenkovDylan DPC-2/+2
Fix spans for asm diagnostics Line spans were incorrect if the first line of an asm statement was an empty string.
2022-07-14Rollup merge of #98580 - PrestonFrom:issue_98466, r=estebankDylan DPC-13/+72
Emit warning when named arguments are used positionally in format Addresses Issue 98466 by emitting an error if a named argument is used like a position argument (i.e. the name is not used in the string to be formatted). Fixes rust-lang#98466
2022-07-14Auto merge of #99231 - Dylan-DPC:rollup-0tl8c0o, r=Dylan-DPCbors-1/+1
Rollup of 5 pull requests Successful merges: - #97720 (Always create elided lifetime parameters for functions) - #98315 (Stabilize `core::ffi:c_*` and rexport in `std::ffi`) - #98705 (Implement `for<>` lifetime binder for closures) - #99126 (remove allow(rustc::potential_query_instability) in rustc_span) - #99139 (Give a better error when `x dist` fails for an optional tool) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-07-14Fix spans for asm diagnosticsAmanieu d'Antras-2/+2
Line spans were incorrect if the first line of an asm statement was an empty string.
2022-07-14Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillotDylan DPC-1/+1
Implement `for<>` lifetime binder for closures This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following: ```rust let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) }; // ^^^^^^^^^^^--- new! ``` cc ``@Aaron1011`` ``@cjgillot``
2022-07-13Rename `debugging_opts` to `unstable_opts`Joshua Nelson-1/+1
This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`). Rename it to be more clear.
2022-07-13Emit warning when named arguments are used positionally in formatPreston From-13/+72
Addresses Issue 98466 by emitting a warning if a named argument is used like a position argument (i.e. the name is not used in the string to be formatted). Fixes rust-lang#98466
2022-07-13Use `&{self.x}` for packed `Copy` structs.Nicholas Nethercote-19/+33
Because it's more concise than the `let` form.
2022-07-12Parse closure bindersMaybe Waffle-1/+1
This is first step in implementing RFC 3216. - Parse `for<'a>` before closures in ast - Error in lowering - Add `closure_lifetime_binder` feature
2022-07-11Handle tags better.Nicholas Nethercote-211/+167
Currently, for the enums and comparison traits we always check the tag for equality before doing anything else. This is a bit clumsy. This commit changes things so that the tags are handled very much like a zeroth field in the enum. For `eq`/ne` this makes the code slightly cleaner. For `partial_cmp` and `cmp` it's a more notable change: in the case where the tags aren't equal, instead of having a tag equality check followed by a tag comparison, it just does a single tag comparison. The commit also improves how `Hash` works for enums: instead of having duplicated code to hash the tag for every arm within the match, we do it just once before the match. All this required replacing the `EnumNonMatchingCollapsed` value with a new `EnumTag` value. For fieldless enums the new code is particularly improved. All the code now produced is close to optimal, being very similar to what you'd write by hand.
2022-07-11Move the no-variants handling code earlier in `expand_enum_method_body`.Nicholas Nethercote-5/+6
To avoid computing a bunch of stuff that it doesn't need.
2022-07-11Avoid some unnecessary blocks in derive output.Nicholas Nethercote-0/+8
2022-07-11Rename tag-related things.Nicholas Nethercote-23/+20
Use `tag` in names of things referring to tags, instead of the mysterious `vi`. Also change `arg_N` in output to `argN`, which has the same length as `self` and so results in nicer vertical alignments.
2022-07-11Remove unnecessary `&*` sigil pairs in derived code.Nicholas Nethercote-39/+65
By producing `&T` expressions for fields instead of `T`. This matches what the existing comments (e.g. on `FieldInfo`) claim is happening, and it's also what most of the trait-specific code needs. The exception is `PartialEq`, which needs `T` expressions for lots of special case error messaging to work. So we now convert the `&T` back to a `T` for `PartialEq`.
2022-07-11Remove unnecessary sigils and `ref`s in derived code.Nicholas Nethercote-89/+55
E.g. improving code like this: ``` match &*self { &Enum1::Single { x: ref __self_0 } => { ::core::hash::Hash::hash(&*__self_0, state) } } ``` to this: ``` match self { Enum1::Single { x: __self_0 } => { ::core::hash::Hash::hash(&*__self_0, state) } } ``` by removing the `&*`, the `&`, and the `ref`. I suspect the current generated code predates deref-coercion. The commit also gets rid of `use_temporaries`, instead passing around `always_copy`, which makes things a little clearer. And it fixes up some comments.
2022-07-11Remove `mutbl` argument from `create_struct_patterns`.Nicholas Nethercote-4/+1
It's always `ast::Mutability::Not`.
2022-07-09Minor updates based on review comments.Nicholas Nethercote-15/+10
2022-07-09Simplify `cs_fold`.Nicholas Nethercote-162/+114
`cs_fold` has four distinct cases, covered by three different function arguments: - first field - combine current field with previous results - no fields - non-matching enum variants This commit clarifies things by replacing the three function arguments with one that takes a new `CsFold` type with four slightly different) cases - single field - combine result for current field with results for previous fields - no fields - non-matching enum variants This makes the code shorter and clearer.
2022-07-09Fix some inconsistencies.Nicholas Nethercote-58/+31
This makes `cs_cmp`, `cs_partial_cmp`, and `cs_op` (for `PartialEq`) more similar. It also fixes some out of date comments.
2022-07-09Cut down large comment about zero-variant enums.Nicholas Nethercote-49/+3
When deriving functions for zero-variant enums, we just generated a function body that calls `std::instrincs::unreachable`. There is a large comment with some not-very-useful historical discussion about alternatives, including some discussion of feature-gating zero-variant enums, which is clearly irrelevant today. This commit cuts the comment down greatly.
2022-07-09Avoid transposes in deriving code.Nicholas Nethercote-218/+183
The deriving code has some complex parts involving iterations over selflike args and also fields within structs and enum variants. The return types for a few functions demonstrate this: - `TraitDef::create_{struct_pattern,enum_variant_pattern}` returns a `(P<ast::Pat>, Vec<(Span, Option<Ident>, P<Expr>)>)` - `TraitDef::create_struct_field_accesses` returns a `Vec<(Span, Option<Ident>, P<Expr>)>`. This results in per-field data stored within per-selflike-arg data, with lots of repetition within the per-field data elements. This then has to be "transposed" in two places (`expand_struct_method_body` and `expand_enum_method_body`) into per-self-like-arg data stored within per-field data. It's all quite clumsy and confusing. This commit rearranges things greatly. Data is obtained in the needed form up-front, avoiding the need for transposition. Also, various functions are split, removed, and added, to make things clearer and avoid tuple return values. The diff is hard to read, which reflects the messiness of the original code -- there wasn't an easy way to break these changes into small pieces. (Sorry!) It's a net reduction of 35 lines and a readability improvement. The generated code is unchanged.
2022-07-09Remove `FieldInfo::attrs`.Nicholas Nethercote-18/+14
It's unused. This also removes the need for the lifetime on `FieldInfo`, which is nice.
2022-07-09Rename `FieldInfo` fields.Nicholas Nethercote-45/+59
Use `self_exprs` and `other_selflike_exprs` in a manner similar to the previous commit.
2022-07-09Clarify args terminology.Nicholas Nethercote-109/+147
The deriving code has inconsistent terminology to describe args. In some places it distinguishes between: - the `&self` arg (if present), versus - all other args. In other places it distinguishes between: - the `&self` arg (if present) and any other arguments with the same type (in practice there is at most one, e.g. in `PartialEq::eq`), versus - all other args. The terms "self_args" and "nonself_args" are sometimes used for the former distinction, and sometimes for the latter. "args" is also sometimes used for "all other args". This commit makes the code consistently uses "self_args"/"nonself_args" for the former and "selflike_args"/"nonselflike_args" for the latter. This change makes the code easier to read. The commit also adds a panic on an impossible path (the `Self_` case) in `extract_arg_details`.
2022-07-05Inline and remove the `cs_fold_*` functions.Nicholas Nethercote-51/+17
Because they now have a single call site each. Also rename `cs_fold1` as `cs_fold`, now that it's the only folding function left.
2022-07-05Avoid the unnecessary innermost match in `partial_cmp`/`cmp`.Nicholas Nethercote-34/+34
We currently do a match on the comparison of every field in a struct or enum variant. But the last field has a degenerate match like this: ``` match ::core::cmp::Ord::cmp(&self.y, &other.y) { ::core::cmp::Ordering::Equal => ::core::cmp::Ordering::Equal, cmp => cmp, }, ``` This commit changes it to this: ``` ::core::cmp::Ord::cmp(&self.y, &other.y), ``` This is fairly straightforward thanks to the existing `cs_fold1` function. The commit also removes the `cs_fold` function which is no longer used. (Note: there is some repetition now in `cs_cmp` and `cs_partial_cmp`. I will remove that in a follow-up PR.)
2022-07-04Avoid unnecessary 1-tuples in derived code.Nicholas Nethercote-2/+10
2022-07-04Don't repeat `AssertParamIs{Clone,Eq}` assertions.Nicholas Nethercote-16/+35
It's common to see repeated assertions like this in derived `clone` and `eq` methods: ``` let _: ::core::clone::AssertParamIsClone<u32>; let _: ::core::clone::AssertParamIsClone<u32>; ``` This commit avoids them.
2022-07-04Avoid unnecessary blocks in derive output.Nicholas Nethercote-111/+146
By not committing to either block form or expression form until necessary, we can avoid lots of unnecessary blocks.
2022-07-04Don't use match-destructuring for derived ops on structs.Nicholas Nethercote-44/+80
All derive ops currently use match-destructuring to access fields. This is reasonable for enums, but sub-optimal for structs. E.g.: ``` fn eq(&self, other: &Point) -> bool { match *other { Self { x: ref __self_1_0, y: ref __self_1_1 } => match *self { Self { x: ref __self_0_0, y: ref __self_0_1 } => (*__self_0_0) == (*__self_1_0) && (*__self_0_1) == (*__self_1_1), }, } } ``` This commit changes derive ops on structs to use field access instead, e.g.: ``` fn eq(&self, other: &Point) -> bool { self.x == other.x && self.y == other.y } ``` This is faster to compile, results in smaller binaries, and is simpler to generate. Unfortunately, we have to keep the old pattern generating code around for `repr(packed)` structs because something like `&self.x` (which doesn't show up in `PartialEq` ops, but does show up in `Debug` and `Hash` ops) isn't allowed. But this commit at least changes those cases to use let-destructuring instead of match-destructuring, e.g.: ``` fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { { let Self(ref __self_0_0) = *self; { ::core::hash::Hash::hash(&(*__self_0_0), state) } } } ``` There are some unnecessary blocks remaining in the generated code, but I will fix them in a follow-up PR.
2022-07-04Comment fixes.Nicholas Nethercote-2/+1
Remove an out-of-date sentence, and fix a typo.
2022-07-01Change `Ty::Tuple` to `Ty::Unit`.Nicholas Nethercote-14/+8
Because that's all that is needed in practice.
2022-07-01Rename `Ty::Literal` as `Ty::Path`.Nicholas Nethercote-29/+18
Because a `Literal` is a type of expression, and is simply the wrong name for this.
2022-07-01Remove lifetime support in deriving code.Nicholas Nethercote-32/+11
It's unused.
2022-07-01Simplify pointer handling.Nicholas Nethercote-100/+43
The existing derive code allows for various possibilities that aren't needed in practice, which complicates the code. There are only a few auto-derived traits and new ones are unlikely, so this commit simplifies things. - `PtrTy` has been eliminated. The `Raw` variant was never used, and the lifetime for the `Borrowed` variant was always `None`. That left just the mutability field, which has been inlined as necessary. - `MethodDef::explicit_self` was a confusing `Option<Option<PtrTy>>`. Indicating either `&self` or nothing. It's now a `bool`. - `borrowed_self` is renamed as `self_ref`. - `Ty::Ptr` is renamed to `Ty::Ref`.
2022-07-01`expand_deriving_clone` tweaks.Nicholas Nethercote-28/+22
Improve a comment, and panic on an impossible code path.
2022-07-01Remove some commented-out code.Nicholas Nethercote-2/+0
This was accidentally left behind in a previous commit.
2022-07-01Remove some unnecessary `pub`s.Nicholas Nethercote-3/+3
2022-07-01Remove `Substructure::self_args`.Nicholas Nethercote-18/+2
It's unused.
2022-07-01Remove `{Method,Trait}Def::is_unsafe`.Nicholas Nethercote-37/+2
They are always `false`.
2022-07-01Remove `Substructure::method_ident`.Nicholas Nethercote-9/+1
It's unused.
2022-07-01Remove unnecessary fields from `EnumNonMatchingCollapsed`.Nicholas Nethercote-30/+14
The `&[ast::Variant]` field isn't used. The `Vec<Ident>` field is only used for its length, but that's always the same as the length of the `&[Ident]` and so isn't necessary.
2022-07-01Use `split_{first,last}` in `cs_fold1`.Nicholas Nethercote-9/+8
It makes the code a little nicer to read.
2022-06-29Auto merge of #98376 - nnethercote:improve-derive-PartialEq, r=petrochenkovbors-131/+85
Improve some deriving code and add a test The `.stdout` test is particularly useful. r? `@petrochenkov`
2022-06-28Rollup merge of #98337 - c410-f3r:assert-compiler, r=oli-obkDylan DPC-15/+81
[RFC 2011] Optimize non-consuming operators Tracking issue: https://github.com/rust-lang/rust/issues/44838 Fifth step of https://github.com/rust-lang/rust/pull/96496 The most non-invasive approach that will probably have very little to no performance impact. ## Current behaviour Captures are handled "on-the-fly", i.e., they are performed in the same place expressions are located. ```rust // `let a = 1; let b = 2; assert!(a > 1 && b < 100);` if !( { ***try capture `a` and then return `a`*** } > 1 && { ***try capture `b` and then return `b`*** } < 100 ) { panic!( ... ); } ``` As such, some overhead is likely to occur (Specially with very large chains of conditions). ## New behaviour for non-consuming operators When an operator is known to not take `self`, then it is possible to capture variables **AFTER** the condition. ```rust // `let a = 1; let b = 2; assert!(a > 1 && b < 100);` if !( a > 1 && b < 100 ) { { ***try capture `a`*** } { ***try capture `b`*** } panic!( ... ); } ``` So the possible impact on the runtime execution time will be diminished. r? ````@oli-obk````
2022-06-27Convert `process_variant` functions into closures.Nicholas Nethercote-16/+12
It makes things a bit nicer.
2022-06-27Factor out the repeated `assert_ty_bounds` function.Nicholas Nethercote-44/+39