Commit graph

437 commits

Author SHA1 Message Date
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
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
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
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