about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2023-10-14Auto merge of #115524 - RalfJung:misalign, r=wesleywiserbors-177/+40
const-eval: make misalignment a hard error It's been a future-incompat error (showing up in cargo's reports) since https://github.com/rust-lang/rust/pull/104616, Rust 1.68, released in March. That should be long enough. The question for the lang team is simply -- should we move ahead with this, making const-eval alignment failures a hard error? (It turns out some of them accidentally already were hard errors since #104616. But not all so this is still a breaking change. Crater found no regression.)
2023-10-13Auto merge of #116645 - estebank:issue-116608, r=oli-obkbors-3/+74
Detect ruby-style closure in parser When parsing a closure without a body that is surrounded by a block, suggest moving the opening brace after the closure head. Fix #116608.
2023-10-13Auto merge of #116676 - estebank:issue-116658, r=compiler-errorsbors-1/+2
On type error involving closure, avoid ICE When we encounter a type error involving a closure, we try to typeck prior closure invocations to see if they influenced the current expected type. When trying to do so, ensure that the closure was defined in our current scope. Fix #116658.
2023-10-13Auto merge of #116666 - Urgau:check-cfg-pre-mcp636, r=petrochenkovbors-3/+23
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-13Auto merge of #116619 - nnethercote:rustc_driver_impl, r=compiler-errorsbors-305/+150
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-13Auto merge of #115964 - bjorn3:cgu_reuse_tracker_global_state, r=cjgillotbors-322/+273
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-12On type error involving closure, avoid ICEEsteban Küber-1/+2
When we encounter a type error involving a closure, we try to typeck prior closure invocations to see if they influenced the current expected type. When trying to do so, ensure that the closure was defined in our current scope. Fix #116658.
2023-10-12Detect ruby-style closure in parserEsteban Küber-3/+74
When parsing a closure without a body that is surrounded by a block, suggest moving the opening brace after the closure head. Fix #116608.
2023-10-12Auto merge of #116391 - Nadrieril:constructorset, r=cjgillotbors-581/+665
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-13Remove unneeded `pub`s.Nicholas Nethercote-7/+7
2023-10-13Split and rename the annotation structs.Nicholas Nethercote-27/+36
`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-13Make `needs_analysis` true for `PpHirMode::Typed`.Nicholas Nethercote-2/+1
This avoids the need for a bespoke `tcx.analysis()` call.
2023-10-13Rename some `'hir` lifetimes as `'tcx`.Nicholas Nethercote-8/+8
Because they all end up within a `TyCtxt`.
2023-10-13Remove pretty-printing traits.Nicholas Nethercote-130/+52
`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-13Merge `print_*` functions.Nicholas Nethercote-70/+52
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-13Simplify support traits.Nicholas Nethercote-70/+30
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-13Remove unused `PrinterSupport::hir_map` method.Nicholas Nethercote-16/+0
2023-10-13Remove PpAstTreeMode.Nicholas Nethercote-17/+12
It's simpler to distinguish the two AST modes directly in `PpMode`.
2023-10-13Remove an outdated comment.Nicholas Nethercote-4/+0
`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-13Remove unnecessary call to `call_with_pp_support_hir`.Nicholas Nethercote-4/+2
The callback is trivial and no pp support is actually needed. This makes the `HirTree` case more like the `AstTree` case above.
2023-10-13Rename some things.Nicholas Nethercote-35/+35
- Rename `pprust` as `pprust_ast`, to align with `pprust_hir`. - Rename `PrinterSupport` as `AstPrinterSupport`, to align with `HirPrinterSupport`.
2023-10-12Auto merge of #116510 - scottmcm:no-1-simd-v2, r=compiler-errorsbors-1/+6
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-12check-cfg: only print the list of expected names onceUrgau-1/+6
2023-10-12check-cfg: mention the unexpected name and value in the primary messageUrgau-2/+6
2023-10-12check-cfg: adjust expected names and values when usefulUrgau-1/+12
2023-10-12Rollup merge of #116654 - Zalathar:reloop-traversal, r=oli-obkMatthias Krüger-164/+130
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-12Rollup merge of #116642 - weiznich:diagnostic_on_unimplemented_improvements, ↵Matthias Krüger-12/+34
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-12Rollup merge of #116625 - nnethercote:rustc_hir_pretty, r=fee1-deadMatthias Krüger-127/+76
`rustc_hir_pretty` cleanups Just some improvements I found while looking through this code. r? ``@fee1-dead``
2023-10-12Auto merge of #116649 - nnethercote:improve-print_tts-precursors, r=petrochenkovbors-19/+17
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-12coverage: Simplify adding BCB successors to the traversal worklistsZalathar-38/+39
2023-10-12coverage: Don't store loop backedges in the traversal contextZalathar-7/+10
As long as we store the loop header BCB, we can look up its incoming loop backedges as needed.
2023-10-12coverage: Store a graph reference in the graph traversal structZalathar-17/+16
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-12coverage: Use a `VecDeque` for loop traversal worklistsZalathar-31/+18
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-12coverage: Rename `next_bcb` to just `bcb`Zalathar-9/+10
This is the only BCB that `TraverseCoverageGraphWithLoops::next` works with, so calling it `next_bcb` just makes the code less clear.
2023-10-12coverage: Simplify the detection of reloop edges to be given expressionsZalathar-82/+57
2023-10-12Auto merge of #116628 - gurry:116293-dup-note.rs, r=petrochenkovbors-10/+4
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-12Auto merge of #113487 - estebank:sugg-113174, r=oli-obkbors-23/+149
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-12Fix duplicate note on internal feature gateGurinder Singh-10/+4
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-12Rename `tt_prepend_space` as `space_between`.Nicholas Nethercote-4/+4
And reorder the arguments. I find it easier to think about this way.
2023-10-12Use `TokenStream::token_alone` in one place.Nicholas Nethercote-4/+4
2023-10-12Reorder an expression to improve readability.Nicholas Nethercote-12/+7
2023-10-12Rename `Token::is_op` as `Token::is_punct`.Nicholas Nethercote-4/+7
For consistency with `proc_macro::Punct`.
2023-10-11Handle several `#[diagnostic::on_unimplemented]` attributes correctlyGeorg Semmler-12/+34
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-11Auto merge of #116640 - matthiaskrgr:rollup-xt9r5ir, r=matthiaskrgrbors-106/+54
Rollup of 5 pull requests Successful merges: - #116219 (Relate alias ty with variance) - #116315 (Do not check for impossible predicates in const-prop lint.) - #116436 (Structurally normalize for closure) - #116597 (Prevent showing methods from blanket impls of not available foreign traits to show up in the search results) - #116627 (small cleanup) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-11Use structured suggestion for #113174Esteban Küber-23/+149
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-11Rollup merge of #116627 - fee1-dead-contrib:cleanup, r=spastorinoMatthias Krüger-6/+4
small cleanup this is exactly the same as the `lower_param_bounds` function, so use that instead
2023-10-11Rollup merge of #116436 - ↵Matthias Krüger-7/+13
compiler-errors:structurally-normalize-for-closure, r=lcnr Structurally normalize for closure Fixes some signature deduction problems in the new trait solver (and in the case of async, an ICE). r? lcnr
2023-10-11Rollup merge of #116315 - cjgillot:cpl-clean, r=petrochenkovMatthias Krüger-50/+11
Do not check for impossible predicates in const-prop lint. The enclosing query already checks for them, and replaces the body with a single `unreachable` if they are indeed impossible.
2023-10-11Rollup merge of #116219 - compiler-errors:relate-alias-ty-with-variance, r=lcnrMatthias Krüger-43/+26
Relate alias ty with variance In the new solver, turns out that the subst-relate branch of the alias-relate predicate was relating args invariantly even for opaques, which have variance :skull:. This change is a bit more invasive, but I'd rather not special-case it [here](https://github.com/rust-lang/rust/blob/aeaa5c30e5c9041264a2e8314b68ad84c2dc3169/compiler/rustc_trait_selection/src/solve/alias_relate.rs#L171-L190) and then have it break elsewhere. I'm doing a perf run to see if the extra call to `def_kind` is that expensive, if it is, I'll reconsider. r? ``@lcnr``
2023-10-11Auto merge of #113218 - lqd:polonius-scopes, r=jackh726bors-36/+413
Compute NLL loan scopes using the polonius model For a *location-insensitive* analysis (that is, without expressiveness improvements for users yet), this PR implements loans going out of scope using reachability and liveness, rather than checking if the issuing region's values contain a given CFG point. This is equivalent to NLL scopes and computes the same data. r? `@matthewjasper` A couple of notes: - there are some assumptions about SCC representatives, placeholders, free regions, and member constraints that I believe hold, and they're documented in the code - this passes all the UI tests with `-Zpolonius=next` -- the perf is [not terrible](https://github.com/rust-lang/rust/pull/112432#issuecomment-1749685862) and there are a bunch of ways to improve it in the future. - there's a fixme left, hopefully Matthew you know a clean way to get the information it mentions.