Commit Graph

236073 Commits

Author SHA1 Message Date
blyxyas
54eef1601d
Change my name in mailmap 2023-10-18 12:37:09 +02:00
bors
a4a10bdf29 Auto merge of #116666 - Urgau:check-cfg-pre-mcp636, r=petrochenkov
Improve check-cfg diagnostics

This PR tries to improve some of the diagnostics of check-cfg.

The main changes is the unexpected name or value being added to the main diagnostic:
```diff
- warning: unexpected `cfg` condition name
+ warning: unexpected `cfg` condition name: `widnows`
```

It also cherry-pick the better sensible logic for when we print the list of expected values when we have a matching value for a very similar name.

Address https://github.com/rust-lang/rust/pull/111072#discussion_r1356818100

r? `@petrochenkov`
2023-10-13 08:37:27 +00:00
bors
2763ca50da Auto merge of #116619 - nnethercote:rustc_driver_impl, r=compiler-errors
Streamline `rustc_driver_impl` pretty-printing.

This PR simplifies a lot of unnecessary structure in
`rustc_driver_impl/src/pretty.rs`. It removes some traits and functions,
simplifies some structs, renames some things for increased consistency, and
eliminates some boilerplate code. Overall it cuts more than 150 lines of code.

r? `@compiler-errors`
2023-10-13 05:35:29 +00:00
bors
130ff8cb6c Auto merge of #115964 - bjorn3:cgu_reuse_tracker_global_state, r=cjgillot
Remove cgu_reuse_tracker from Session

This removes a bit of global mutable state.

It will now miss post-lto cgu reuse when ThinLTO determines that a cgu doesn't get changed, but there weren't any tests for this anyway and a test for it would be fragile to the exact implementation of ThinLTO in LLVM.
2023-10-13 00:09:30 +00:00
bors
e20cb77021 Auto merge of #116391 - Nadrieril:constructorset, r=cjgillot
exhaustiveness: Rework constructor splitting

`SplitWildcard` was pretty opaque. I replaced it with a more legible abstraction: `ConstructorSet` represents the set of constructors for patterns of a given type. This clarifies responsibilities: `ConstructorSet` handles one clear task, and diagnostic-related shenanigans can be done separately.

I'm quite excited, I had has this in mind for years but could never quite introduce it. This opens up possibilities, including type-specific optimisations (like using a `FxHashSet` to collect enum variants, which had been [hackily attempted some years ago](https://github.com/rust-lang/rust/pull/76918)), my one-pass rewrite (https://github.com/rust-lang/rust/pull/116042), and future librarification.
2023-10-12 21:33:31 +00:00
Nicholas Nethercote
2b4c33817a Remove unneeded pubs. 2023-10-13 06:35:19 +11:00
Nicholas Nethercote
2e2924f263 Split and rename the annotation structs.
`NoAnn` and `IdentifiedAnnotation` impl both `pprust_ast::PpAnn` and
`pprust_hir::PpAnn`, which is a bit confusing, because the optional
`tcx` is only needed for the HIR cases. (Currently the `tcx` is
unnecessarily provided in the `expanded` AST cases.)

This commit splits each one into `Ast` and `Hir` versions, which makes
things clear about where the `tcx` is needed. The commit also renames
all the traits so they consistently end with `Ann`.
2023-10-13 06:35:19 +11:00
Nicholas Nethercote
b65227a9ee Make needs_analysis true for PpHirMode::Typed.
This avoids the need for a bespoke `tcx.analysis()` call.
2023-10-13 06:35:19 +11:00
Nicholas Nethercote
ba58e3213d Rename some 'hir lifetimes as 'tcx.
Because they all end up within a `TyCtxt`.
2023-10-13 06:35:19 +11:00
Nicholas Nethercote
060851b764 Remove pretty-printing traits.
`call_with_pp_support_ast` and `call_with_pp_support_hir` how each have
a single call site. This commit inlines and removes them, which also
removes the need for all the supporting traits: `Sess`,
`AstPrinterSupport`, and `HirPrinterSupport`. The `sess` member is also
removed from several structs.
2023-10-13 06:35:17 +11:00
Nicholas Nethercote
7d145a0fde Merge print_* functions.
The handling of the `PpMode` variants is currently spread across three
functions: `print_after_parsing`, `print_after_hir_lowering`, and
`print_with_analysis`. Each one handles some of the variants. This split
is primarily because `print_after_parsing` has slightly different
arguments to the other two.

This commit changes the structure. It merges the three functions into a
single `print` function, and encapsulates the different arguments in a
new enum `PrintExtra`.

Benefits:
- The code is a little shorter.
- All the `PpMode` variants are handled in a single `match`, with no
  need for `unreachable!` arms.
- It enables the trait removal in the subsequent commit by reducing
  the number of `call_with_pp_support_ast` call sites from two to one.
2023-10-13 06:34:55 +11:00
Nicholas Nethercote
e3d8bbbfe2 Simplify support traits.
First, both `AstPrinterSupport` and `HirPrinterSupport` have a `sess`
method. This commit introduces a `Sess` trait and makes the support
traits be subtraits of `Sess`, to avoid some duplication.

Second, both support traits have a `pp_ann` method that isn't needed if
we enable `trait_upcasting`. This commit removes those methods.

(Both of these traits will be removed in a subsequent commit, as will
the `trait_upcasting` use.)
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
d5e7c5f3cc Remove unused PrinterSupport::hir_map method. 2023-10-13 06:20:11 +11:00
Nicholas Nethercote
1467ba06b6 Remove PpAstTreeMode.
It's simpler to distinguish the two AST modes directly in `PpMode`.
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
87090a97e3 Remove an outdated comment.
`phase_3_run_analysis_passes` no longer exists, and AFAICT this code has
been refactored so much since this comment was written that it no longer
has any useful meaning.
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
c5cfcdc4ac Remove unnecessary call to call_with_pp_support_hir.
The callback is trivial and no pp support is actually needed. This makes
the `HirTree` case more like the `AstTree` case above.
2023-10-13 06:20:11 +11:00
Nicholas Nethercote
ef8701a4a0 Rename some things.
- Rename `pprust` as `pprust_ast`, to align with `pprust_hir`.
- Rename `PrinterSupport` as `AstPrinterSupport`, to align with
  `HirPrinterSupport`.
2023-10-13 06:20:11 +11:00
bors
df4379b4eb Auto merge of #116510 - scottmcm:no-1-simd-v2, r=compiler-errors
Copy 1-element arrays as scalars, not vectors

For `[T; 1]` it's silly to copy as `<1 x T>` when we can just copy as `T`.

Inspired by https://github.com/rust-lang/rust/issues/101210#issuecomment-1732470941, which pointed out that `Option<[u8; 1]>` was codegenning worse than `Option<u8>`.

(I'm not sure *why* LLVM doesn't optimize out `<1 x u8>`, but might as well just not emit it in the first place in this codepath.)

---

I think I bit off too much in #116479; let me try just the scalar case first.

r? `@ghost`
2023-10-12 18:45:01 +00:00
Scott McMurray
f5cdd3e130 Exclude apple from assembly test 2023-10-12 11:03:02 -07:00
bors
672fad9b86 Auto merge of #116671 - matthiaskrgr:rollup-b41rw92, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #116593 (Add unstable book page for the no-jump-tables codegen option)
 - #116625 (`rustc_hir_pretty` cleanups)
 - #116642 (Handle several `#[diagnostic::on_unimplemented]` attributes correctly)
 - #116654 (coverage: Clarify loop-edge detection and graph traversal)
 - #116669 (Fix mips platform support entries.)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-12 16:39:36 +00:00
Urgau
ed922d8c72 check-cfg: update rustdoc ui check-cfg tests 2023-10-12 18:39:35 +02:00
Urgau
001a65c4b0 check-cfg: only print the list of expected names once 2023-10-12 18:39:35 +02:00
Urgau
dcfc484b09 check-cfg: mention the unexpected name and value in the primary message 2023-10-12 18:39:04 +02:00
Urgau
72815dc08f check-cfg: adjust expected names and values when useful 2023-10-12 18:39:04 +02:00
Matthias Krüger
6ccc521267
Rollup merge of #116669 - ehuss:fix-platform-table, r=nikic
Fix mips platform support entries.

The table entries for these MIPS entries were broken because they had the wrong number of columns (from #116503). Additionally, there was a conflict with #115238, which made the same change (but on different lines, so git didn't complain).
2023-10-12 18:36:45 +02:00
Matthias Krüger
4832811b0d
Rollup merge of #116654 - Zalathar:reloop-traversal, r=oli-obk
coverage: Clarify loop-edge detection and graph traversal

This is a collection of improvements to two semi-related pieces of code:

- The code in `counters` that detects which graph edges don't exit a loop, and would therefore be good candidates to have their coverage computed as an expression rather than having a physical counter.
- The code in `graph` that traverses the coverage BCB graph in a particular order, and tracks loops and loop edges along the way (which is relevant to the above).

I was originally only planning to make the `graph` changes, but there was going to be a lot of indentation churn in `counters` anyway, and once I started looking I noticed a lot of opportunities for simplification.

---

`@rustbot` label +A-code-coverage
2023-10-12 18:36:44 +02:00
Matthias Krüger
5f90bee663
Rollup merge of #116642 - weiznich:diagnostic_on_unimplemented_improvements, r=compiler-errors
Handle several `#[diagnostic::on_unimplemented]` attributes correctly

This PR fixes an issues where rustc would ignore subsequent `#[diagnostic::on_unimplemented]` attributes. The [corresponding RFC](https://rust-lang.github.io/rfcs/3368-diagnostic-attribute-namespace.html) specifies that the first matching instance of each option is used. Invalid attributes are linted and otherwise ignored.
2023-10-12 18:36:44 +02:00
Matthias Krüger
4b1867a9ee
Rollup merge of #116625 - nnethercote:rustc_hir_pretty, r=fee1-dead
`rustc_hir_pretty` cleanups

Just some improvements I found while looking through this code.

r? ``@fee1-dead``
2023-10-12 18:36:43 +02:00
Matthias Krüger
54c528ee05
Rollup merge of #116593 - tgross35:no-jump-tables-docs, r=compiler-errors
Add unstable book page for the no-jump-tables codegen option

See tracking issue: https://github.com/rust-lang/rust/issues/116592
2023-10-12 18:36:43 +02:00
Eric Huss
8309097163 Fix mips platform support entries. 2023-10-12 08:45:02 -07:00
bors
19149d1ea9 Auto merge of #116649 - nnethercote:improve-print_tts-precursors, r=petrochenkov
Token cleanups

Some precursors to #114571 that are worth merging even if the main part of #114571 doesn't get merged.

r? `@petrochenkov`
2023-10-12 13:10:14 +00:00
Zalathar
d99ab97b02 coverage: Simplify adding BCB successors to the traversal worklists 2023-10-12 22:37:58 +11:00
Zalathar
59f4f1c89d coverage: Don't store loop backedges in the traversal context
As long as we store the loop header BCB, we can look up its incoming loop
backedges as needed.
2023-10-12 21:41:13 +11:00
Zalathar
15360b3bc8 coverage: Store a graph reference in the graph traversal struct
Having to keep passing in a graph reference was a holdover from when the graph
was partly mutated during traversal. As of #114354 that is no longer necessary,
so we can simplify the traversal code by storing a graph reference as a field
in `TraverseCoverageGraphWithLoops`.
2023-10-12 21:41:13 +11:00
Zalathar
ea3fb7bc2c coverage: Use a VecDeque for loop traversal worklists
The previous code was storing the worklist in a vector, and then selectively
adding items to the start or end of the vector. That's a perfect use-case for a
double-ended queue.

This change also reveals that the existing code was a bit confused about which
end of the worklist is the front or back. For now, items are always removed
from the front of the queue (instead of the back), and code that adds items to
the queue has been flipped, to preserve the existing behaviour.
2023-10-12 21:41:13 +11:00
Zalathar
d1920c5181 coverage: Rename next_bcb to just bcb
This is the only BCB that `TraverseCoverageGraphWithLoops::next` works with, so
calling it `next_bcb` just makes the code less clear.
2023-10-12 21:41:13 +11:00
Zalathar
a7ae2a6e6c coverage: Simplify the detection of reloop edges to be given expressions 2023-10-12 21:41:13 +11:00
bors
3ff244b61c Auto merge of #116600 - GuillaumeGomez:repr-enums-discriminant, r=fmease
Show enum discriminant if a compatible repr is used

Follow-up of #116142.

It was mentioned in the [team meeting](https://rust-lang.zulipchat.com/#narrow/stream/393423-t-rustdoc.2Fmeetings/topic/meeting.2002-10-2023/near/394504024) that an enum with a `repr` should also get its discriminants displayed. Forgot to implement it in #116142...

It also allowed to uncover a bug: i was not providing the correct `DefId` in case it was a type alias to `render_enum_fields`. It's also fixed in this PR.

r? `@fmease`
2023-10-12 10:31:48 +00:00
bors
4f05e95452 Auto merge of #116628 - gurry:116293-dup-note.rs, r=petrochenkov
Fix duplicate note on internal feature gates with associated issues

Fixes #116293

Note sure if I should add tests because the issue occurs only for feature gates having associated issues and that set of feature gates will change unpredictably leading to an unnecessary churn in tests.
2023-10-12 07:57:51 +00:00
bors
3d575a2f2e Auto merge of #113487 - estebank:sugg-113174, r=oli-obk
Use structured suggestion for #113174

When encountering a for loop that is rejected by the borrow checker because it is being advanced within its body, provide a structured suggestion for `while let Some(pat) = iter.next()`.
2023-10-12 02:34:07 +00:00
Gurinder Singh
66e643d0f8 Fix duplicate note on internal feature gate
The BuiltinInternalFeatures gate already has a struct level #[note]
attribute. The additional note field in it caused a duplicate to be
displayed when it was set to Some(...) which happened when the
feature had an associated issue
2023-10-12 07:22:41 +05:30
bors
f562931178 Auto merge of #116506 - Wilfred:remove_tmp_var, r=workingjubilee
Remove unnecessary tmp variable in default_read_exact

This `tmp` variable has existed since the original implementation (added in ff81920f03), but it's not necessary (maybe non-lexical lifetimes helped?).

It's common to read std source code to understand how things actually work, and this tripped me up on my first read.
2023-10-12 00:45:22 +00:00
bors
9d1e4b7870 Auto merge of #116448 - Kobzol:bootstrap-host-flags, r=onur-ozkan,petrochenkov
Pass rustc shim flags using environment variable

This PR implements a generalized way of passing of host flags to the `rustc` shim in bootstrap, as proposed [here](https://github.com/rust-lang/rust/pull/116278#discussion_r1346979960).

I tried to implement the bootstrap side using `OsString`, but then I realized that the shim code was using `env::var` before anyway, instead of `env::var_os`, so I just settled on a `String`. The shim side is still general and uses `env::vars_os` now.

I'm not sure if we actually need to do something with the `rustdoc` shim. It *seems* to me that the env. vars passed to it (`RUSTDOC_LINKER`) and (`RUSTDOC_LLD_NO_THREADS`) could just be passed to cargo directly (or rather, the commands that they invoke in the shim could be passed directly). I'm not sure why are they set by the shim.

r? `@onur-ozkan`
CC `@petrochenkov`
2023-10-11 23:00:24 +00:00
Nicholas Nethercote
66c2b77a4a Rename tt_prepend_space as space_between.
And reorder the arguments. I find it easier to think about this way.
2023-10-12 08:50:42 +11:00
Nicholas Nethercote
33aff5b152 Use TokenStream::token_alone in one place. 2023-10-12 08:46:16 +11:00
Nicholas Nethercote
bb9c2f50c3 Reorder an expression to improve readability. 2023-10-12 08:46:15 +11:00
Nicholas Nethercote
129fe9a998 Add a comment to tests/ui/proc-macro/issue-75930-derive-cfg.rs.
Explaining something in the output that surprised me.
2023-10-12 08:46:15 +11:00
Nicholas Nethercote
becf4942a2 Rename Token::is_op as Token::is_punct.
For consistency with `proc_macro::Punct`.
2023-10-12 08:46:15 +11:00
Guillaume Gomez
00c3de96e6 Improve code documentation a bit 2023-10-11 23:46:11 +02:00
Guillaume Gomez
bd59fc603f Add tests for enum discriminant value display with repr 2023-10-11 23:44:12 +02:00