Commit Graph

624 Commits

Author SHA1 Message Date
Mara Bos a4dbcb525b Expand format_args!() in rust_ast_lowering. 2023-01-12 00:25:45 +01:00
Gimbles 32ab2d95f1
Update format.rs 2023-01-02 15:51:54 +05:30
Nilstrieb 9067e4417e Rename `Rptr` to `Ref` in AST and HIR
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already
as well.
2022-12-28 18:52:36 +01:00
Matthias Krüger d23cb738d2
Rollup merge of #105975 - jeremystucki:rustc-remove-needless-lifetimes, r=eholk
rustc: Remove needless lifetimes
2022-12-24 00:31:41 +01:00
Matthias Krüger 3e58de240c
Rollup merge of #105978 - jyn514:unused_proc_macro_decl, r=tmiasko
Mark `proc_macro_decls_static` as always used

This would have avoided a bug in https://github.com/rust-lang/rust/pull/104860.

In practice this shouldn't matter since nothing uses the query other than the `dead_code` lint, but this isn't documented as an internal-only query so it seems nice for it to be accurate. I think for `dead_code` it doesn't matter because the relevant code is generated by `rustc_builtin_macros` and isn't linted.

I think `@tmiasko` or `@bjorn3` would be a good reviewer?

r? `@tmiasko`
2022-12-23 01:17:50 +01:00
Joshua Nelson 164e22109b Mark `proc_macro_decls_static` as always used
This would have avoided a bug in https://github.com/rust-lang/rust/pull/104860.

In practice this shouldn't matter since nothing uses the query other than the `dead_code` lint,
but this isn't documented as an internal-only query so it seems nice for it to be accurate.
I think for `dead_code` it doesn't matter because the relevant code is generated by `rustc_builtin_macros` and isn't linted.
2022-12-22 12:02:53 -06:00
Jeremy Stucki 3dde32ca97
rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
Matthias Krüger 8892698903
Rollup merge of #105870 - matthiaskrgr:useless_conv, r=oli-obk
avoid .into() conversion to identical types
2022-12-18 18:57:05 +01:00
Matthias Krüger 0aa4cde747 avoid .into() conversion to identical types 2022-12-18 16:20:32 +01:00
Matthias Krüger 1ade25491e remove redundant clone 2022-12-18 00:29:25 +01:00
Matthias Krüger 4069792d73
Rollup merge of #105620 - TaKO8Ki:remove-unnecessary-uses-of-clone, r=compiler-errors
Remove unnecessary uses of `clone`
2022-12-13 01:17:10 +01:00
Takayuki Maeda ee40a67cd9 remove unnecessary uses of `clone` 2022-12-13 02:06:24 +09:00
bors 2cd2070af7 Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkov
Remove `token::Lit` from `ast::MetaItemLit`.

Currently `ast::MetaItemLit` represents the literal kind twice. This PR removes that redundancy. Best reviewed one commit at a time.

r? `@petrochenkov`
2022-12-12 05:16:50 +00:00
Matthias Krüger 2daa3bcbc2
Rollup merge of #105537 - kadiwa4:remove_some_imports, r=fee1-dead
compiler: remove unnecessary imports and qualified paths

Some of these imports were necessary before Edition 2021, others were already in the prelude.

I hope it's fine that this PR is so spread-out across files :/
2022-12-11 09:51:57 +01:00
KaDiWa 9bc69925cb
compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
nils 2f9f097cb8 Migrate parts of `rustc_expand` to session diagnostics
This migrates everything but the `mbe` and `proc_macro` modules. It also
contains a few cleanups and drive-by/accidental diagnostic improvements
which can be seen in the diff for the UI tests.
2022-12-10 11:02:41 +01:00
bors 0d5573e6da Auto merge of #105363 - WaffleLapkin:thin2win_box_next_argument, r=nnethercote
Shrink `rustc_parse_format::Piece`

This makes both variants closer together in size (previously they were different by 208 bytes -- 16 vs 224). This may make things worse, but it's worth a try.

r? `@nnethercote`
2022-12-09 21:27:35 +00:00
Maybe Waffle 700c095306 `rustc_builtin_macros`: remove `ref` patterns
... and other pattern matching improvements
2022-12-06 14:45:58 +00:00
Maybe Waffle 78060cb6de Box `rustc_parse_format::Piece::NextArgument`
This makes both variants closer together in size (previously they were
different by 208 bytes -- 16 vs 224). This may make things worse, but
it's worth a try.
2022-12-06 12:02:56 +00:00
Matthias Krüger 4fdc3eb176
Rollup merge of #104614 - Nilstrieb:type-ascribe!, r=TaKO8Ki
Add `type_ascribe!` macro as placeholder syntax for type ascription

This makes it still possible to test the internal semantics of type ascription even once the `:`-syntax is removed from the parser. The macro now gets used in a bunch of UI tests that test the semantics and not syntax of type ascription.

I might have forgotten a few tests but this should hopefully be most of them. The remaining ones will certainly be found once type ascription is removed from the parser altogether.

Part of #101728
2022-12-02 08:28:08 +01:00
bors 11663b1b48 Auto merge of #104963 - petrochenkov:noaddids2, r=cjgillot
rustc_ast_lowering: Stop lowering imports into multiple items

Lower them into a single item with multiple resolutions instead.
This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-02 04:24:57 +00:00
Nicholas Nethercote 2fd364acff Remove `token::Lit` from `ast::MetaItemLit`.
`token::Lit` contains a `kind` field that indicates what kind of literal
it is. `ast::MetaItemLit` currently wraps a `token::Lit` but also has
its own `kind` field. This means that `ast::MetaItemLit` encodes the
literal kind in two different ways.

This commit changes `ast::MetaItemLit` so it no longer wraps
`token::Lit`. It now contains the `symbol` and `suffix` fields from
`token::Lit`, but not the `kind` field, eliminating the redundancy.
2022-12-02 13:49:19 +11:00
Nicholas Nethercote a7f35c42d4 Add `StrStyle` to `ast::LitKind::ByteStr`.
This is required to distinguish between cooked and raw byte string
literals in an `ast::LitKind`, without referring to an adjacent
`token::Lit`. It's a prerequisite for the next commit.
2022-12-02 10:38:58 +11:00
Vadim Petrochenkov b32a4edb20 rustc_ast_lowering: Stop lowering imports into multiple items
Lower them into a single item with multiple resolutions instead.
This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-01 18:51:20 +03:00
Matthias Krüger ee9eaa695c
Rollup merge of #105106 - jhpratt:issue-105101, r=TaKO8Ki
Fix ICE from #105101

Fixes #105101

Rather than comparing idents, compare spans, which should be unique to each variant.
2022-12-01 11:59:01 +01:00
bors d6c4de0fb2 Auto merge of #104861 - nnethercote:attr-cleanups, r=petrochenkov
Attribute cleanups

Best reviewed one commit at a time.

r? `@petrochenkov`
2022-12-01 07:13:45 +00:00
Jacob Pratt ab264ae612
Fix ICE from #105101 2022-11-30 21:18:31 +00:00
Nicholas Nethercote bf4a62c381 Fix an ICE parsing a malformed literal in `concat_bytes!`.
Fixes #104769.
2022-11-30 12:19:07 +11:00
Nicholas Nethercote ba1751a201 Avoid more `MetaItem`-to-`Attribute` conversions.
There is code for converting `Attribute` (syntactic) to `MetaItem`
(semantic). There is also code for the reverse direction. The reverse
direction isn't really necessary; it's currently only used when
generating attributes, e.g. in `derive` code.

This commit adds some new functions for creating `Attributes`s directly,
without involving `MetaItem`s: `mk_attr_word`, `mk_attr_name_value_str`,
`mk_attr_nested_word`, and
`ExtCtxt::attr_{word,name_value_str,nested_word}`.

These new methods replace the old functions for creating `Attribute`s:
`mk_attr_inner`, `mk_attr_outer`, and `ExtCtxt::attribute`. Those
functions took `MetaItem`s as input, and relied on many other functions
that created `MetaItems`, which are also removed: `mk_name_value_item`,
`mk_list_item`, `mk_word_item`, `mk_nested_word_item`,
`{MetaItem,MetaItemKind,NestedMetaItem}::token_trees`,
`MetaItemKind::attr_args`, `MetaItemLit::{from_lit_kind,to_token}`,
`ExtCtxt::meta_word`.

Overall this cuts more than 100 lines of code and makes thing simpler.
2022-11-29 18:43:53 +11:00
Nicholas Nethercote a709f87be7 Avoid more unnecessary `MetaItem`/`Attribute` conversions.
In `Expander::expand` the code currently uses `mk_attr_outer` to convert
a `MetaItem` to an `Attribute`, and then follows that with
`meta_item_list` which converts back. This commit avoids the unnecessary
conversions.

There was one wrinkle: the existing conversions caused the bogus `<>` on
`Default<>` to be removed. With the conversion gone, we get a second
error message about the `<>`. This is a rare case, so I think it
probably doesn't matter much.
2022-11-29 12:54:45 +11:00
Nicholas Nethercote c9ae38c71e Avoid unnecessary `MetaItem`/`Attribute` conversions.
`check_builtin_attribute` calls `parse_meta` to convert an `Attribute`
to a `MetaItem`, which it then checks. However, many callers of
`check_builtin_attribute` start with a `MetaItem`, and then convert it
to an `Attribute` by calling `cx.attribute(meta_item)`. This `MetaItem`
to `Attribute` to `MetaItem` conversion is silly.

This commit adds a new function `check_builtin_meta_item`, which can be
called instead from these call sites. `check_builtin_attribute` also now
calls it. The commit also renames `check_meta` as `check_attr` to better
match its arguments.
2022-11-29 12:08:57 +11:00
Nicholas Nethercote a60e337c88 Rename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`.
We already use a mix of `Literal` and `Lit`. The latter is better
because it is shorter without causing any ambiguity.
2022-11-28 15:18:53 +11:00
Nicholas Nethercote e4a9150872 Rename `ast::Lit` as `ast::MetaItemLit`. 2022-11-28 15:18:49 +11:00
Maybe Waffle 1d42936b18 Prefer doc comments over `//`-comments in compiler 2022-11-27 11:19:04 +00:00
Matthias Krüger 5197ef66b7
Rollup merge of #103908 - estebank:consider-cloning, r=compiler-errors
Suggest `.clone()` or `ref binding` on E0382
2022-11-24 08:42:33 +01:00
bors 872631d0f0 Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiser
Use `as_deref` in compiler (but only where it makes sense)

This simplifies some code :3

(there are some changes that are not exacly `as_deref`, but more like "clever `Option`/`Result` method use")
2022-11-24 00:17:35 +00:00
Esteban Küber 9e72e35ceb Suggest `.clone()` or `ref binding` on E0382 2022-11-23 12:17:47 -08:00
Nicholas Nethercote 3e3a4192d8 Split `MacArgs` in two.
`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's
used in two ways:
- For representing attribute macro arguments (e.g. in `AttrItem`), where all
  three variants are used.
- For representing function-like macros (e.g. in `MacCall` and `MacroDef`),
  where only the `Delimited` variant is used.

In other words, `MacArgs` is used in two quite different places due to them
having partial overlap. I find this makes the code hard to read. It also leads
to various unreachable code paths, and allows invalid values (such as
accidentally using `MacArgs::Empty` in a `MacCall`).

This commit splits `MacArgs` in two:
- `DelimArgs` is a new struct just for the "delimited arguments" case. It is
  now used in `MacCall` and `MacroDef`.
- `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro
  case. Its `Delimited` variant now contains a `DelimArgs`.

Various other related things are renamed as well.

These changes make the code clearer, avoids several unreachable paths, and
disallows the invalid values.
2022-11-22 09:04:15 +11:00
Nicholas Nethercote a6e09a19fc Streamline deriving on packed structs.
The current approach to field accesses in derived code:
- Normal case: `&self.0`
- In a packed struct that derives `Copy`: `&{self.0}`
- In a packed struct that doesn't derive `Copy`: `let Self(ref x) = *self`

The `let` pattern used in the third case is equivalent to the simpler
field access in the first case. This commit changes the third case to
use a field access.

The commit also combines two boolean arguments (`is_packed` and
`always_copy`) into a single field (`copy_fields`) earlier, to save
passing both around.
2022-11-21 14:07:39 +11:00
Nilstrieb 6ee0dd97e3
Add unstable `type_ascribe` macro
This macro serves as a placeholder for future type ascription syntax to
make sure that the semantic implementation keeps working.
2022-11-19 22:16:42 +01:00
Nicholas Nethercote 6b7ca2fcf2 Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and patterns. 2022-11-17 13:45:59 +11:00
Maybe Waffle 94470f4efd Use `as_deref` in compiler (but only where it makes sense) 2022-11-16 21:58:58 +00:00
Nicholas Nethercote 358a603f11 Use `token::Lit` in `ast::ExprKind::Lit`.
Instead of `ast::Lit`.

Literal lowering now happens at two different times. Expression literals
are lowered when HIR is crated. Attribute literals are lowered during
parsing.

This commit changes the language very slightly. Some programs that used
to not compile now will compile. This is because some invalid literals
that are removed by `cfg` or attribute macros will no longer trigger
errors. See this comment for more details:
https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
2022-11-16 09:41:28 +11:00
Matthias Krüger aea4c0c1b8
Rollup merge of #104391 - nnethercote:deriving-cleanups, r=jackh726
Deriving cleanups

Fixing some minor problems `@RalfJung` found in #99046.

r? `@RalfJung`
2022-11-15 01:40:44 +01:00
Nicholas Nethercote 111db7d3a8 Remove TraitDef::generics.
Because it's always empty.
2022-11-14 15:59:41 +11:00
Nicholas Nethercote 96280b6a1d Remove `addr_of` argument from `create_struct_pattern_fields`.
Because it's always false.
2022-11-14 13:59:54 +11:00
Nicholas Nethercote 9985f4611b Clarify `expand_struct_method_body`.
Spotted by @RalfJung. This causes no behavioural changes.
2022-11-14 13:49:08 +11:00
bors 8ef2485bd5 Auto merge of #103812 - clubby789:improve-include-bytes, r=petrochenkov
Delay `include_bytes` to AST lowering

Hopefully addresses #65818.
This PR introduces a new `ExprKind::IncludedBytes` which stores the path and bytes of a file included with `include_bytes!()`. We can then create a literal from the bytes during AST lowering, which means we don't need to escape the bytes into valid UTF8 which is the cause of most of the overhead of embedding large binary blobs.
2022-11-12 14:30:34 +00:00
Dylan DPC 4b0b89827d
Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obk
Add the `#[derive_const]` attribute

Closes #102371. This is a minimal patchset for the attribute to work. There are no restrictions on what traits this attribute applies to.

r? `````@oli-obk`````
2022-11-12 12:02:50 +05:30
clubby789 b2da155a9a Introduce `ExprKind::IncludedBytes` 2022-11-11 16:31:32 +00:00
Dylan DPC bc9567fbf6
Rollup merge of #103445 - fmease:fix-50291, r=estebank
`#[test]`: Point at return type if `Termination` bound is unsatisfied

Together with #103142 (already merged) this fully fixes #50291.

I don't consider my current solution of changing a few spans “here and there” very clean since the
failed obligation is a `FunctionArgumentObligation` and we point at a type instead of a function argument.

If you agree with me on this point, I can offer to keep the spans of the existing nodes and instead inject
`let _: AssertRetTyIsTermination<$ret_ty>;` (type to be defined in `libtest`) similar to `AssertParamIsEq` etc.
used by some built-in derive-macros.

I haven't tried that approach yet though and cannot promise that it would actually work out or
be “cleaner” for that matter.

````@rustbot```` label A-libtest A-diagnostics
r? ````@estebank````
2022-11-11 20:51:38 +05:30
Michael Howell 03968a802c rustdoc: use ThinVec for cleaned generics 2022-11-02 16:17:22 -07:00
Amanieu d'Antras 56074b5231 Rewrite implementation of `#[alloc_error_handler]`
The new implementation doesn't use weak lang items and instead changes
`#[alloc_error_handler]` to an attribute macro just like
`#[global_allocator]`.

The attribute will generate the `__rg_oom` function which is called by
the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom`
function is defined in any crate then the compiler shim will call
`__rdl_oom` in the alloc crate which will simply panic.

This also fixes link errors with `-C link-dead-code` with
`default_alloc_error_handler`: `__rg_oom` was previously defined in the
alloc crate and would attempt to reference the `oom` lang item, even if
it didn't exist. This worked as long as `__rg_oom` was excluded from
linking since it was not called.

This is a prerequisite for the stabilization of
`default_alloc_error_handler` (#102318).
2022-10-31 16:32:57 +00:00
Dylan DPC c9a04cddc0
Rollup merge of #103430 - cjgillot:receiver-attrs, r=petrochenkov
Workaround unstable stmt_expr_attributes for method receiver expressions

Fixes https://github.com/rust-lang/rust/issues/103244

cc ``@Mark-Simulacrum`` ``@ehuss``
2022-10-26 11:29:55 +05:30
Yuki Okushi 779418deb4
Rollup merge of #99939 - saethlin:pre-sort-tests, r=thomcc,jackh726
Sort tests at compile time, not at startup

Recently, another Miri user was trying to run `cargo miri test` on the crate `iced-x86` with `--features=code_asm,mvex`. This configuration has a startup time of ~18 minutes. That's ~18 minutes before any tests even start to run. The fact that this crate has over 26,000 tests and Miri is slow makes a lot of code which is otherwise a bit sloppy but fine into a huge runtime issue.

Sorting the tests when the test harness is created instead of at startup time knocks just under 4 minutes out of those ~18 minutes. I have ways to remove most of the rest of the startup time, but this change requires coordinating changes of both the compiler and libtest, so I'm sending it separately.

(except for doctests, because there is no compile-time harness)
2022-10-24 19:32:25 +09:00
León Orell Valerian Liehr 449a4404f5
test attr: point at return type if Termination bound unsatisfied 2022-10-23 19:30:35 +02:00
Camille GILLOT 74d4eefc13 Workaround unstable stmt_expr_attributes for method receiver expressions. 2022-10-23 09:27:12 +00:00
Nilstrieb c65ebae221
Migrate all diagnostics 2022-10-23 10:09:44 +02:00
Camille GILLOT 16e22e143d Mark derived StructuralEq as automatically derived. 2022-10-15 15:16:32 +00:00
Michael Goulet d3bd6beb97 Rename AssocItemKind::TyAlias to AssocItemKind::Type 2022-10-10 02:31:37 +00:00
bors 0152393048 Auto merge of #99324 - reez12g:issue-99144, r=jyn514
Enable doctests in compiler/ crates

Helps with https://github.com/rust-lang/rust/issues/99144
2022-10-06 03:01:57 +00:00
reez12g 488eb4209e Temporarily reinstate doctest=false 2022-10-05 09:53:49 +09:00
Matthias Krüger df11395a55
Rollup merge of #101040 - danielhenrymantilla:no-bounds-for-default-annotated-derive, r=joshtriplett
Fix `#[derive(Default)]` on a generic `#[default]` enum adding unnecessary `Default` bounds

That is, given something like:

```rs
// #[default] on a generic enum does not add `Default` bounds to the type params.
#[derive(Default)]
enum MyOption<T> {
    #[default]
    None,
    Some(T),
}
```

then `MyOption<T> : Default`_as currently implemented_ only holds when `T : Default`, as reported by ```@5225225``` [over Zulip](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/.23.5Bderive.28Default.29.5D.20for.20enums.20with.20fields).

This is contrary to [what the accepted RFC proposes](https://rust-lang.github.io/rfcs/3107-derive-default-enum.html#generated-bounds) (_i.e._, that `T` be allowed not to be itself `Default`), and indeed seems to be a rather unnecessary limitation.
2022-10-03 20:58:55 +02:00
Petr Portnov afae9576dc
Fix duplicate usage of `a` article.
This fixes a typo first appearing in #94624
in which test-macro diagnostic uses "a" article twice.

Since I searched sources for " a a " sequences,
I also fixed the same issue in a few source files where I found it.

Signed-off-by: Petr Portnov <gh@progrm-jarvis.ru>
2022-10-02 21:40:39 +03:00
bors 91931ec2fc Auto merge of #98354 - camsteffen:is-some-and-by-value, r=m-ou-se
Change `is_some_and` to take by value

Consistent with other function-accepting `Option` methods.

Tracking issue: #93050

r? `@m-ou-se`
2022-10-02 12:48:15 +00:00
Cameron Steffen 4f12de0660 Change feature name to is_some_and 2022-10-01 11:45:52 -05:00
Alex Macleod 71db0dd918 Fix format_args capture for macro expanded format strings 2022-09-30 17:40:14 +01:00
reez12g 73775a96dc Fix docs in compiler/rustc_builtin_macros/src/deriving/generic/mod.rs 2022-09-29 16:49:21 +09:00
reez12g cc8f98f4f2 Fix docs in compiler/rustc_builtin_macros/src/assert/context.rs 2022-09-29 16:49:20 +09:00
reez12g 213910a8a2 Add feature flag to docs in compiler/rustc_builtin_macros/src/assert/context.rs 2022-09-29 16:49:18 +09:00
reez12g 9a4c5abe45 Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
Mara Bos 20bb600849 Remove confusing drop. 2022-09-27 13:31:52 +02:00
Mara Bos ba7bf1d8ef Update doc comments. 2022-09-27 13:31:52 +02:00
Mara Bos cf53fef0d6 Turn format arguments Vec into its own struct.
With efficient lookup through a hash map.
2022-09-27 13:31:52 +02:00
Mara Bos c1c6e3ae7c Add clarifying comments. 2022-09-27 13:31:51 +02:00
Mara Bos 8d9a5881ea Flatten if-let and match into one. 2022-09-27 13:31:51 +02:00
Mara Bos 15754f5ea1 Move enum definition closer to its usage. 2022-09-27 13:31:51 +02:00
Mara Bos df7fd119d2 Use if let chain. 2022-09-27 13:31:51 +02:00
Mara Bos e65c96e4ad Tweak comments. 2022-09-27 13:31:51 +02:00
Mara Bos ae238efe91 Prefer new_v1_formatted instead of new_v1 with duplicates. 2022-09-27 13:31:51 +02:00
Mara Bos 00074926bb Fix typo. 2022-09-27 13:31:51 +02:00
Mara Bos 8efc383047 Move FormatArgs structure to its own module. 2022-09-27 13:31:51 +02:00
Mara Bos 9bec0de397 Rewrite and refactor format_args!() builtin macro. 2022-09-27 13:13:08 +02:00
Pietro Albini 3975d55d98
remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Jhonny Bill Mena a3396b2070 UPDATE - rename DiagnosticHandler macro to Diagnostic 2022-09-21 11:39:53 -04:00
Jhonny Bill Mena 19b348fed4 UPDATE - rename DiagnosticHandler trait to IntoDiagnostic 2022-09-21 11:39:52 -04:00
Michael Howell 14b27cfd11
Rollup merge of #100250 - cjgillot:recover-token-stream, r=Aaron1011
Manually cleanup token stream when macro expansion aborts.

In case of syntax error in macro expansion, the expansion code can decide to stop processing anything. In that case, the token stream is malformed. This makes downstream users, like derive macros, ICE.

In this case, this PR manually cleans up the token stream by closing all currently open delimiters.

Fixes https://github.com/rust-lang/rust/issues/96818.
Fixes https://github.com/rust-lang/rust/issues/80447.
Fixes https://github.com/rust-lang/rust/issues/81920.
Fixes https://github.com/rust-lang/rust/issues/91023.
2022-09-20 10:12:56 -07:00
Deadbeef a052f2cce1 Add the `#[derive_const]` attribute 2022-09-20 11:57:58 +00:00
est31 173eb6f407 Only enable the let_else feature on bootstrap
On later stages, the feature is already stable.

Result of running:

rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-15 21:06:45 +02:00
SparrowLii 1a3ecbdb6a make `mk_attr_id` part of `ParseSess` 2022-09-14 08:49:10 +08:00
Camille GILLOT cb5ea8d0b6 Emit an error instead of reconstructing token stream. 2022-09-13 19:47:50 +02:00
Nicholas Nethercote a56d345490 Rename `AttrAnnotatedToken{Stream,Tree}`.
These two type names are long and have long matching prefixes. I find
them hard to read, especially in combinations like
`AttrAnnotatedTokenStream::new(vec![AttrAnnotatedTokenTree::Token(..)])`.

This commit renames them as `AttrToken{Stream,Tree}`.
2022-09-09 12:45:26 +10:00
Daniel Henry-Mantilla cb86c38cdb Fix `#[derive(Default)]` on a generic `#[default]` enum adding unnecessary `Default` bounds 2022-09-05 13:49:37 +02:00
Cameron Steffen 02ba216e3c Refactor and re-use BindingAnnotation 2022-09-02 12:55:05 -05:00
Oli Scherer ee3c835018 Always import all tracing macros for the entire crate instead of piecemeal by module 2022-09-01 14:54:27 +00:00
Ben Kimock df6221adc6 Sort tests at compile time, not at startup
Recently, another Miri user was trying to run `cargo miri test` on the
crate `iced-x86` with `--features=code_asm,mvex`. This configuration has
a startup time of ~18 minutes. That's ~18 minutes before any tests even
start to run. The fact that this crate has over 26,000 tests and Miri is
slow makes a lot of code which is otherwise a bit sloppy but fine into a
huge runtime issue.

Sorting the tests when the test harness is created instead of at startup
time knocks just under 4 minutes out of those ~18 minutes. I have ways
to remove most of the rest of the startup time, but this change requires
coordinating changes of both the compiler and libtest, so I'm sending it
separately.
2022-09-01 09:04:25 -04:00
bors eac6c33bc6 Auto merge of #100869 - nnethercote:replace-ThinVec, r=spastorino
Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec`

`rustc_data_structures::thin_vec::ThinVec` looks like this:
```
pub struct ThinVec<T>(Option<Box<Vec<T>>>);
```
It's just a zero word if the vector is empty, but requires two
allocations if it is non-empty. So it's only usable in cases where the
vector is empty most of the time.

This commit removes it in favour of `thin_vec::ThinVec`, which is also
word-sized, but stores the length and capacity in the same allocation as
the elements. It's good in a wider variety of situation, e.g. in enum
variants where the vector is usually/always non-empty.

The commit also:
- Sorts some `Cargo.toml` dependency lists, to make additions easier.
- Sorts some `use` item lists, to make additions easier.
- Changes `clean_trait_ref_with_bindings` to take a
  `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this
  avoid some unnecessary allocations.

r? `@spastorino`
2022-09-01 08:01:06 +00:00
bors a0d07093f8 Auto merge of #100812 - Nilstrieb:revert-let-chains-nightly, r=Mark-Simulacrum
Revert let_chains stabilization

This is the revert against master, the beta revert was already done in #100538.

Bumps the stage0 compiler which already has it reverted.
2022-08-30 05:48:22 +00:00
Nilstrieb d1ef8180f9 Revert let_chains stabilization
This reverts commit 3266460749.

This is the revert against master, the beta revert was already done in #100538.
2022-08-29 19:34:11 +02:00
Dylan DPC 0b6faca670
Rollup merge of #101000 - m-ou-se:count-is-star, r=nagisa
Separate CountIsStar from CountIsParam in rustc_parse_format.

`rustc_parse_format`'s parser would result in the exact same output for `{:.*}` and `{:.0$}`, making it hard for diagnostics to handle these cases properly.

This splits those cases by adding a new `CountIsStar` enum variant.

This fixes #100995

Prerequisite for https://github.com/rust-lang/rust/pull/100996
2022-08-29 16:49:45 +05:30
Nicholas Nethercote b38106b6d8 Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec`.
`rustc_data_structures::thin_vec::ThinVec` looks like this:
```
pub struct ThinVec<T>(Option<Box<Vec<T>>>);
```
It's just a zero word if the vector is empty, but requires two
allocations if it is non-empty. So it's only usable in cases where the
vector is empty most of the time.

This commit removes it in favour of `thin_vec::ThinVec`, which is also
word-sized, but stores the length and capacity in the same allocation as
the elements. It's good in a wider variety of situation, e.g. in enum
variants where the vector is usually/always non-empty.

The commit also:
- Sorts some `Cargo.toml` dependency lists, to make additions easier.
- Sorts some `use` item lists, to make additions easier.
- Changes `clean_trait_ref_with_bindings` to take a
  `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this
  avoid some unnecessary allocations.
2022-08-29 15:42:13 +10:00
bors ce36e88256 Auto merge of #100497 - kadiwa4:remove_clone_into_iter, r=cjgillot
Avoid cloning a collection only to iterate over it

`@rustbot` label: +C-cleanup
2022-08-28 18:31:08 +00:00
Mara Bos 1b044da5bb Separate CountIsStar from CountIsParam in rustc_parse_format. 2022-08-25 14:49:09 +02:00
Dylan DPC 28ead17745
Rollup merge of #100909 - nnethercote:minor-ast-LitKind-improvement, r=petrochenkov
Minor `ast::LitKind` improvements

r? `@petrochenkov`
2022-08-23 20:40:09 +05:30
Dylan DPC 110d8d99b2
Rollup merge of #100851 - Alexendoo:rpf-width-prec-spans, r=fee1-dead
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-23 20:40:06 +05:30
Nicholas Nethercote 6087dc2054 Remove the symbol from `ast::LitKind::Err`.
Because it's never used meaningfully.
2022-08-23 16:56:24 +10:00
Dylan DPC 57e521e0e5
Rollup merge of #100694 - finalchild:ast-passes-diag, r=TaKO8Ki
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-22 11:45:44 +05:30
Nicholas Nethercote 619b8abaa6 Use `AttrVec` in more places.
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-22 07:35:33 +10:00
Alex Macleod 586c84a052 Fix rustc_parse_format precision & width spans 2022-08-21 20:21:45 +00:00
finalchild 6a340741bd Remove redundant clone 2022-08-22 01:11:59 +09:00
finalchild 80451de390 Use DiagnosticMessage for BufferedEarlyLint.msg 2022-08-22 00:57:21 +09:00
Xiretza 7f3a6fd7f6 Replace #[lint/warning/error] with #[diag] 2022-08-21 09:17:43 +02:00
bors dd01122b5c Auto merge of #100564 - nnethercote:box-ast-MacCall, r=spastorino
Box the `MacCall` in various types.

r? `@spastorino`
2022-08-20 10:26:54 +00:00
bors 361c599fee Auto merge of #98655 - nnethercote:dont-derive-PartialEq-ne, r=dtolnay
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-18 10:11:11 +00:00
Matthias Krüger 3e057d1512
Rollup merge of #100669 - nnethercote:attribute-cleanups, r=spastorino
Attribute cleanups

r? `@ghost`
2022-08-18 05:10:48 +02:00
Matthias Krüger d5dca26a94
Rollup merge of #100018 - nnethercote:clean-up-LitKind, r=petrochenkov
Clean up `LitKind`

r? ``@petrochenkov``
2022-08-17 12:32:49 +02:00
Nicholas Nethercote 6cd40d0e51 Remove `attrs` arg from `typaram` and `mk_ty_param`.
Because it's always empty.
2022-08-17 12:33:42 +10:00
Nicholas Nethercote 2c24958cfd Remove `TraitDef::attributes`.
Because it's always empty.
2022-08-17 12:29:02 +10:00
Nicholas Nethercote eafd0dfd05 Box the `MacCall` in various types. 2022-08-17 08:10:56 +10:00
Nicholas Nethercote 5d3cc1713a Rename some things related to literals.
- 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-16 13:41:34 +10:00
Nicholas Nethercote 3e04fed6fa Remove `{ast,hir}::WhereEqPredicate::id`.
These fields are unused.
2022-08-16 12:13:23 +10:00
Nicholas Nethercote d7a041f607 Make `ExtCtxt::expr_lit` non-`pub`.
By using `expr_str` more and adding `expr_{char,byte_str}`.
2022-08-16 11:17:15 +10:00
Matthias Krüger 965ed812fb
Rollup merge of #100277 - m-ou-se:format-args-1, r=compiler-errors
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-15 10:28:10 +02:00
KaDiWa 4eebcb9910
avoid cloning and then iterating 2022-08-13 16:16:52 +02:00
Mark Rousskov 154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Matthias Krüger 8237efc52d
Rollup merge of #100392 - nnethercote:simplify-visitors, r=cjgillot
Simplify visitors

By removing some unused arguments.

r? `@cjgillot`
2022-08-11 22:53:08 +02:00
Nicholas Nethercote 232bd80130 Simplify `rustc_ast::visit::Visitor::visit_poly_trait_ref`.
It is passed an argument that is never used.
2022-08-11 11:10:01 +10:00
Camille GILLOT 9701845287 Do not consider method call receiver as an argument in AST. 2022-08-10 18:34:54 +02:00
Mara Bos a639fdb7d8 Get rid of named_pos in format_args impl. 2022-08-08 15:51:14 +02:00
Mara Bos 2808e071dd 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-08 15:41:32 +02:00
Matthias Krüger d3aa757ff8
Rollup merge of #100058 - 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-04 22:25:01 +02:00
Takayuki Maeda dcd70c0995 return when captured argument is not a struct field 2022-08-04 11:51:25 +09:00
Takayuki Maeda 4233a13ceb suggest a positional formatting argument instead of a captured argument 2022-08-03 11:12:31 +09:00
Matthias Krüger 82feb4996c
Rollup merge of #99958 - PrestonFrom:issue_99907, r=compiler-errors
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-02 23:07:45 +02:00
Matthias Krüger 06333e092b
Rollup merge of #100045 - Amanieu:global_asm_may_unwind, r=tmiasko
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-02 17:17:34 +02:00
Preston From 298acef307 Move if-block into closure to reduce duplicate code 2022-08-02 00:20:44 -06:00
Preston From d0ea440dfe 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-02 00:20:44 -06:00
Amanieu d'Antras 96c955e66b 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-02 06:29:32 +01:00
Nicholas Nethercote d4a5b034b7 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-01 08:01:58 +10:00
Alex Macleod 2a0b51d852 Always include a position span in rustc_parse_format::Argument 2022-07-31 15:11:33 +00:00
bors 1202bbaf48 Auto merge of #99887 - nnethercote:rm-TreeAndSpacing, r=petrochenkov
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-30 14:50:05 +00:00
Nicholas Nethercote 332dffb1f9 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`.
2022-07-29 15:52:15 +10:00
Preston From 1b2e05e212 Use more idiomatic rust, comment for lint logic 2022-07-28 00:10:19 -06:00
Preston From 1a08b17044 Use Span::from_inner and make changes to precision inner span clearer 2022-07-25 23:23:33 -06:00
Preston From 3330c7d1c3 Generate correct suggestion with named arguments used positionally
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-25 00:00:27 -06:00
Matthias Krüger 4b21ad26df
Rollup merge of #99508 - TaKO8Ki:avoid-symbol-to-string-conversion-in-BuiltinLintDiagnostics, r=compiler-errors
Avoid `Symbol` to `String` conversions

follow-up to #99342
2022-07-20 18:58:20 +02:00
Matthias Krüger 9e197b75f0
Rollup merge of #99480 - miam-miam100:arg-format, r=oli-obk
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-20 18:58:17 +02:00
miam-miam100 f8dfc4bf35
Fix off by one error and add ui test. 2022-07-20 13:40:45 +01:00
Takayuki Maeda 57a155b9fa avoid a `Symbol` to `String` conversion 2022-07-20 18:19:25 +09:00
Samrat Man Singh 8374ab6d65 Don't add attribute to allow unused-qualifications to derive impl's
Currently `#![forbid(unused_qualifications)]` is incompatible with all
derive's because we add `#[allow(unused_qualifications)]` in all
generated impl's.
2022-07-18 22:28:17 -04:00