Commit Graph

22347 Commits

Author SHA1 Message Date
Matthias Krüger
3fcc79f04a
Rollup merge of #108364 - Nilstrieb:validity-checks-refactor, r=compiler-errors
Unify validity checks into a single query

Previously, there were two queries to check whether a type allows the 0x01 or zeroed bitpattern.

I am planning on adding a further initness to check in #100423, truly uninit for MaybeUninit, which would make this three queries. This seems overkill for such a small feature, so this PR unifies them into one.

I am not entirely happy with the naming and key type and open for improvements.

r? oli-obk
2023-02-27 06:11:52 +01:00
Matthias Krüger
3a6c5429c2
Rollup merge of #108319 - compiler-errors:dont-project-to-specializable-rpitits, r=lcnr
Don't project specializable RPITIT projection

This effective rejects specialization + RPITIT/AFIT (usages of `impl Trait` in traits) because the implementation is significantly complicated over making regular "default" trait method bodies work.

I have another PR that experimentally fixes all this, but the code may not be worth investing in.
2023-02-27 06:11:51 +01:00
bors
58136ffa92 Auto merge of #108440 - Zoxc:encoder-enum, r=cjgillot
Emit the enum discriminant separately for the Encodable macro

This changes the `Encodable` proc macro to first emit the discriminant with a separate `match` statement, then emit the fields. LLVM can optimize down the first `match` to just a read of the enum discriminant. This avoids generating a `emit_usize` call per variant and enums with no fields now optimize down to just a single `emit_usize` call.

The no variant case is special cased to avoid warnings about unreachable code.

<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check:unchanged</td><td align="right">0.4676s</td><td align="right">0.4640s</td><td align="right"> -0.78%</td></tr><tr><td>🟣 <b>hyper</b>:check:unchanged</td><td align="right">0.1348s</td><td align="right">0.1338s</td><td align="right"> -0.75%</td></tr><tr><td>🟣 <b>regex</b>:check:unchanged</td><td align="right">0.3370s</td><td align="right">0.3352s</td><td align="right"> -0.54%</td></tr><tr><td>🟣 <b>syn</b>:check:unchanged</td><td align="right">0.6326s</td><td align="right">0.6281s</td><td align="right"> -0.71%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check:unchanged</td><td align="right">1.8561s</td><td align="right">1.8589s</td><td align="right"> 0.15%</td></tr><tr><td>Total</td><td align="right">3.4282s</td><td align="right">3.4200s</td><td align="right"> -0.24%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9947s</td><td align="right"> -0.53%</td></tr></table>
2023-02-26 21:41:17 +00:00
bors
dfa5643705 Auto merge of #108253 - nnethercote:ena-rm-VarValue-methods, r=joshtriplett
Upgrade to ena-0.14.1.

It avoids some inlining within its `inlined_probe_value` function, which seems to result in better codegen for the very large `process_obligations` function within rustc. It might also help with reducing the bimodal perf results we see for the `keccak` and `cranelift-codegen-0.82.1` benchmarks.

r? `@ghost`
2023-02-26 15:28:24 +00:00
bors
c4e0cd9660 Auto merge of #108488 - matthiaskrgr:rollup-i61epcw, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #107941 (Treat `str` as containing `[u8]` for auto trait purposes)
 - #108299 (Require `literal`s for some `(u)int_impl!` parameters)
 - #108337 (hir-analysis: make a helpful note)
 - #108379 (Add `ErrorGuaranteed` to `hir::{Expr,Ty}Kind::Err` variants)
 - #108418 (Replace parse_[sth]_expr with parse_expr_[sth] function names)
 - #108424 (rustc_infer: Consolidate obligation elaboration de-duplication)
 - #108475 (Fix `VecDeque::shrink_to` and add tests.)
 - #108482 (statically guarantee that current error codes are documented)
 - #108484 (Remove `from` lang item)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-26 12:40:05 +00:00
Matthias Krüger
9c27fc7d34
Rollup merge of #108484 - Nilstrieb:˂DiagnosticItem˂FromFn˃ as From˂˂LangItemFromFn˃˃˃꞉꞉from, r=cjgillot
Remove `from` lang item

It was probably a leftover from the old `?` desugaring but anyways, it's unused now except for clippy, which can just use a diagnostics item.
2023-02-26 12:05:01 +01:00
Matthias Krüger
edd27cf4ca
Rollup merge of #108482 - Ezrashaw:force-error-docs, r=GuillaumeGomez
statically guarantee that current error codes are documented

Closes #61137 (that's right!)

Pretty simple refactor (often just a change from `Result<Option<&str>>` to `Result<&str>`)

r? `@GuillaumeGomez` (could you specially look at 53044158eff0d64673a6100f701c57b484232aca? I believe you wrote that in the first place, just want to make sure you're happy with the change)
2023-02-26 12:05:00 +01:00
Matthias Krüger
c815e03447
Rollup merge of #108424 - megakorre:elaborator_refactor, r=compiler-errors
rustc_infer: Consolidate obligation elaboration de-duplication

# Explanation

The obligations `Elaborator` is doing de-duplication of obligations in 3 different locations. 1 off which has a comment.
This PR consolidates the functionality and comment to a single function.
2023-02-26 12:04:59 +01:00
Matthias Krüger
786a75a65f
Rollup merge of #108418 - est31:parser_function_names, r=Nilstrieb
Replace parse_[sth]_expr with parse_expr_[sth] function names

This resolves an inconsistency in naming style for functions on the parser, where:

* functions parsing specific kinds of items are named `parse_item_[sth]` and
* functions parsing specific kinds of *expressions* are named `parse_[sth]_expr`

favoring the style used by functions for items. There are multiple advantages of that style:

* functions of both categories are collected in the same place in the [rustdoc output](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/parser/struct.Parser.html).
* it helps with autocompletion, as you can narrow down your search for a function to those about expressions.
* it mirrors rust's path syntax where less specific things come first, then it gets more specific, i.e. `std::collections::hash_map::Entry`.

The disadvantage is that it doesn't "read like a sentence" any more. But I think the advantages weigh more greatly.

This change was mostly application of this command:

```
sed -i -E 's/(fn |\.)parse_([[:alnum:]_]+)_expr/\1parse_expr_\2/' compiler/rustc_parse/src/parser/*.rs
```

Plus very minor fixes outside of `rustc_parse`, and an invocation of `x fmt`.
2023-02-26 12:04:59 +01:00
Matthias Krüger
19b8685b06
Rollup merge of #108379 - compiler-errors:hir-error-guaranteed, r=cjgillot
Add `ErrorGuaranteed` to `hir::{Expr,Ty}Kind::Err` variants

First step in making the `Err` variants of `ExprKind` and `TyKind` require an `ErrorGuaranteed` during parsing. Making the corresponding AST versions require `ErrorGuaranteed` is a bit harder, whereas it was pretty easy to do this for HIR, so let's do that first.

The only weird thing about this PR is that `ErrorGuaranteed` is moved to `rustc_span`. This is *certainly* not the right place to put it, but `rustc_hir` cannot depend on `rustc_error` because the latter already depends on the former. Should I just pull out some of the error machinery from `rustc_error` into an even more minimal crate that `rustc_hir` can depend on? Advice would be appreciated.
2023-02-26 12:04:58 +01:00
Matthias Krüger
b27f37da07
Rollup merge of #108337 - tshepang:translatable-hir-analysis, r=cjgillot
hir-analysis: make a helpful note
2023-02-26 12:04:58 +01:00
Matthias Krüger
2bc553c6ea
Rollup merge of #107941 - compiler-errors:str-has-u8-slice-for-auto, r=lcnr
Treat `str` as containing `[u8]` for auto trait purposes

Wanted to gauge ``@rust-lang/lang`` and ``@rust-lang/types`` teams' thoughts on treating `str` as "containing" a `[u8]` slice for auto-trait purposes.

``@dtolnay`` brought this up in https://github.com/rust-lang/rust/issues/13231#issuecomment-1399386472 as a blocker for future `str` type librarification, and I think it's both a valid concern and very easy to fix. I'm interested in actually doing that `str` type librarification (#107939), but this probably should be considered in the mean time regardless of that PR.

r? types for the impl, though this definitely needs an FCP.
2023-02-26 12:04:57 +01:00
bors
43ee4d15bf Auto merge of #108375 - Zoxc:query-inline, r=cjgillot
Add inlining attributes for query system functions

These only have a single caller, but don't always get inlined.
2023-02-26 09:44:54 +00:00
Nilstrieb
312020ef6a Remove from_fn lang item
It was probably a leftover from the old `?` desugaring but anyways, it's
unused now except for clippy, which can just use a diagnostics item.
2023-02-26 09:15:54 +00:00
Ezra Shaw
90677edcba
refactor: statically guarantee that current error codes are documented 2023-02-26 20:12:36 +13:00
bors
70fd012439 Auto merge of #108473 - matthiaskrgr:rollup-qjyae58, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #107062 (Do some cleanup of doc/index.md)
 - #107890 (Lint against `Iterator::map` receiving a callable that returns `()`)
 - #108431 (Add regression test for #107918)
 - #108432 (test: drop unused deps)
 - #108436 (make "proc macro panicked" translatable)
 - #108444 (docs/test: add UI test and docs for `E0476`)
 - #108449 (Do not lint ineffective unstable trait impl for unresolved trait)
 - #108456 (Complete migrating `ast_passes` to derive diagnostics)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-26 02:04:23 +00:00
Matthias Krüger
767c865f07
Rollup merge of #108456 - clubby789:ast-passes-diag-migrate, r=compiler-errors
Complete migrating `ast_passes` to derive diagnostics

cc #100717

```@rustbot``` label +A-translation
2023-02-26 00:46:28 +01:00
Matthias Krüger
a223ff7cea
Rollup merge of #108449 - fee1-dead-contrib:do_not_lint_unresolved, r=compiler-errors
Do not lint ineffective unstable trait impl for unresolved trait
2023-02-26 00:46:28 +01:00
Matthias Krüger
65eecc6b59
Rollup merge of #108444 - Ezrashaw:add-test+docs-for-e0476, r=GuillaumeGomez
docs/test: add UI test and docs for `E0476`

Final undocumented error code. Not entirely sure about wording in the docs.

Part of https://github.com/rust-lang/rust/issues/61137.

r? ```@compiler-errors```

cc ```@compiler-errors```
2023-02-26 00:46:28 +01:00
Matthias Krüger
9631f4b5c9
Rollup merge of #108436 - tshepang:translatable-proc-macro-panicked, r=estebank
make "proc macro panicked" translatable
2023-02-26 00:46:27 +01:00
Matthias Krüger
fa10a21bd2
Rollup merge of #107890 - obeis:mapping-to-unit, r=cjgillot
Lint against `Iterator::map` receiving a callable that returns `()`

Close #106991
2023-02-26 00:46:25 +01:00
Tshepang Mbambo
e5d1fcd535 hir-analysis: make a helpful note 2023-02-26 00:01:44 +02:00
Michael Goulet
53fb433652 Special note for str in auto traits 2023-02-25 20:01:33 +00:00
Michael Goulet
3560e65c44 Treat str as containing [u8] for auto trait purposes 2023-02-25 20:01:33 +00:00
Michael Goulet
4723a9ad14
Rollup merge of #108333 - compiler-errors:new-solver-object-sound, r=lcnr
Make object bound candidates sound in the new trait solver

r? `@lcnr`
2023-02-25 11:53:11 -08:00
Michael Goulet
cf049ac2af
Rollup merge of #107911 - blyxyas:issue-107231-fix, r=compiler-errors
Add check for invalid #[macro_export] arguments

Resolves #107231
Sorry if I made something wrong, this is my first contribution to the repo.
2023-02-25 11:53:10 -08:00
Michael Goulet
1a599d7d97
Rollup merge of #107675 - jsgf:link-directives, r=davidtwco
Implement -Zlink-directives=yes/no

`-Zlink-directives=no` will ignored `#[link]` directives while compiling a crate, so nothing is emitted into the crate's metadata.  The assumption is that the build system already knows about the crate's native dependencies and can provide them at link time without these directives.

This is another way to address issue # #70093, which is currently addressed by `-Zlink-native-libraries` (implemented in #70095). The latter is implemented at link time, which has the effect of ignoring `#[link]` in *every* crate. This makes it a very large hammer as it requires all native dependencies to be known to the build system to be at all usable, including those in sysroot libraries. I think this means its effectively unused, and definitely under-used.

Being able to control this on a crate-by-crate basis should make it much easier to apply when needed.

I'm not sure if we need both mechanisms, but we can decide that later.

cc `@pcwalton` `@cramertj`
2023-02-25 11:53:09 -08:00
Michael Goulet
a4119ba0ae
Rollup merge of #107291 - oli-obk:rustdoc_breaking_change, r=estebank
[breaking change] Remove a rustdoc back compat warning

This warning was introduced in https://github.com/rust-lang/rust/pull/62855 for users who use `rustdoc` directly on proc macro crates (instead of using `cargo doc`) without passing `--crate-type proc-macro` (which `cargo doc` passed automatically).
2023-02-25 11:53:08 -08:00
Michael Goulet
c0e58c3420 Add ErrorGuaranteed to HIR ExprKind::Err 2023-02-25 19:46:36 +00:00
Michael Goulet
a772a6fc2a Add ErrorGuaranteed to HIR TyKind::Err 2023-02-25 19:46:36 +00:00
bors
31448badfd Auto merge of #108450 - matthiaskrgr:rollup-rqvfgu3, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #108354 (Update `fuchsia-test-runner.py` and docs)
 - #108404 (support `x fmt` for sub and outside of rust directories)
 - #108407 (docs: use intra-doc links for `Vec::get(_mut)`)
 - #108410 (rustdoc: avoid including `<li>` tags in item table short desc)
 - #108412 (Fix GUI test navigation bug)
 - #108433 (Wrap missing provider message correctly)
 - #108434 (Migrate `rustc_hir_analysis` to session diagnostic [Part One])

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-25 16:48:04 +00:00
clubby789
885f9e72d7 Complete migrating ast_passes to derive diagnostics 2023-02-25 15:19:13 +00:00
bors
dcca6a375b Auto merge of #108250 - nnethercote:rename-interner-funcs, r=compiler-errors
Rename interner funcs

This PR cleans up some inconsistencies in interner naming.

Best reviewed one commit at a time.

r? `@compiler-errors`
2023-02-25 13:55:26 +00:00
Matthias Krüger
2aad179b4e
Rollup merge of #108434 - obeis:hir-analysis-migrate-diagnostics, r=Nilstrieb
Migrate `rustc_hir_analysis` to session diagnostic [Part One]

Finishing `lib.rs` file
Updates #100717
r? ``@davidtwco``
2023-02-25 11:31:35 +01:00
Matthias Krüger
a4740a1922
Rollup merge of #108433 - compiler-errors:missing-provider-nit, r=Nilstrieb
Wrap missing provider message correctly

Fixes #108429

```
error: internal compiler error: compiler/rustc_middle/src/ty/query.rs:441:1: `tcx.trigger_delay_span_bug(DefId(0:3 ~ test[78c5]::main))` is not supported for local crate;
                                hint: Queries can be either made to the local crate, or the external crate. This error means you tried to use it for one that's not supported.
                                If that's not the case, trigger_delay_span_bug was likely never assigned to a provider function.

thread 'rustc' panicked at 'Box<dyn Any>', /home/ec2-user/rust3/compiler/rustc_errors/src/lib.rs:1651:9
stack backtrace:
   0:     0x7f51870926d7 - std::backtrace_rs::backtrace::libunwind::trace::hb0876bb39e7adf0d
                               at /home/ec2-user/rust3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f51870926d7 - std::backtrace_rs::backtrace::trace_unsynchronized::h1bcab1313827007b
                               at /home/ec2-user/rust3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f5187077e07 - std::sys_common::backtrace::_print_fmt::h262d2a62279fa102
                               at /home/ec2-user/rust3/library/std/src/sys_common/backtrace.rs:65:5
```
2023-02-25 11:31:34 +01:00
Deadbeef
ed34354bfa Do not lint unresolved trait for ineffective unstable trait impl 2023-02-25 10:12:20 +00:00
Ezra Shaw
9f876cc900
docs/test: add UI test and docs for E0476 2023-02-25 19:31:02 +13:00
bors
313219c0b6 Auto merge of #106430 - tmiasko:rm-dead-unwinds, r=cjgillot
Remove dead unwinds before drop elaboration

As a part of drop elaboration, we identify dead unwinds, i.e., unwind
edges on a drop terminators which are known to be unreachable, because
there is no need to drop anything.

Previously, the data flow framework was informed about the dead unwinds,
and it assumed those edges are absent from MIR. Unfortunately, the data
flow framework wasn't consistent in maintaining this assumption.

In particular, if a block was reachable only through a dead unwind edge,
its state was propagated to other blocks still. This became an issue in
the context of change removes DropAndReplace terminator, since it
introduces initialization into cleanup blocks.

To avoid this issue, remove unreachable unwind edges before the drop
elaboration, and elaborate only blocks that remain reachable.

cc `@Zeegomo`
2023-02-25 06:14:35 +00:00
John Kåre Alsaker
dd73080cc0 Don't inline try_execute_query 2023-02-25 06:11:02 +01:00
John Kåre Alsaker
ab5d3fbe7d Add inlining attributes for query system functions 2023-02-25 06:11:02 +01:00
John Kåre Alsaker
a049550c45 Move ensure_sufficient_stack to try_execute_query callers 2023-02-25 06:11:01 +01:00
John Kåre Alsaker
5fa60a5d25 Reduce calls to current_query_job 2023-02-25 06:11:01 +01:00
John Kåre Alsaker
7de205ea3a Emit the enum discriminant separately for the Encodable macro 2023-02-25 01:04:56 +01:00
bors
f0bc76ac41 Auto merge of #91742 - cjgillot:force-backtrace, r=estebank
Print a backtrace when query forcing fails.

The aim of this PR is to help debugging incremental compilation bugs where query forcing panics.
For instance: https://github.com/rust-lang/rust/issues/90682 https://github.com/rust-lang/rust/issues/90697 https://github.com/rust-lang/rust/issues/90715 https://github.com/rust-lang/rust/issues/90739 https://github.com/rust-lang/rust/issues/91401

These bugs happen when the dep-graph attempts to force a dep-node whose fingerprint does not correspond to an actual DefPathHash. PR https://github.com/rust-lang/rust/pull/91741 attempts to hide this bug.

I still don't know how to reproduce these bugs, so I sadly could not test this debugging device.
2023-02-24 23:48:44 +00:00
Tshepang Mbambo
dca52ac835 make "proc macro panicked" translatable 2023-02-24 23:37:10 +02:00
Obei Sideg
34966aab55 Migrate rustc_hir_analysis to session diagnostic
Part one, lib.rs file
2023-02-24 23:23:30 +03:00
Michael Goulet
a861b192da Wrap missing provider message correctly 2023-02-24 18:46:29 +00:00
Patrik Kårlin
3d34538f5d
rustc_infer: Consolidate obligation elaboration de-duplication 2023-02-24 11:32:41 +01:00
Dylan DPC
c77cf40df0
Rollup merge of #108401 - notriddle:notriddle/diagnostics-article, r=compiler-errors
diagnostics: remove inconsistent English article "this" from E0107

Consider [`tests/ui/const-generics/generic_const_exprs/issue-102768.stderr`][issue-102768.stderr], the error message where it gives additional notes about where the associated type is defined, and how the dead code lint doesn't have an article, like in [`tests/ui/lint/dead-code/issue-85255.stderr`][issue-85255.stderr]. They don't have articles, so it seems unnecessary to have one here.

[issue-102768.stderr]: 07c993eba8/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr
[issue-85255.stderr]: 07c993eba8/tests/ui/lint/dead-code/issue-85255.stderr
2023-02-24 12:02:45 +05:30
Dylan DPC
8acbfe27d6
Rollup merge of #108388 - ohno418:better-suggestion-on-malformed-closure, r=davidtwco
parser: provide better suggestions and errors on closures with braces missing

We currently provide wrong suggestions and unhelpful errors on closure bodies with braces missing.

For example, given the following code:

```rust
fn main() {
    let _x = Box::new(|x|x+1;);
}
```

the current output is:

```
error: expected expression, found `)`
 --> ./main.rs:2:30
  |
2 |     let _x = Box::new(|x|x+1;);
  |                              ^ expected expression

error: closure bodies that contain statements must be surrounded by braces
 --> ./main.rs:2:25
  |
2 |     let _x = Box::new(|x|x+1;);
  |                         ^
3 | }
  | ^
  |
note: statement found outside of a block
 --> ./main.rs:2:29
  |
2 |     let _x = Box::new(|x|x+1;);
  |                          ---^ this `;` turns the preceding closure into a statement
  |                          |
  |                          this expression is a statement because of the trailing semicolon
note: the closure body may be incorrectly delimited
 --> ./main.rs:2:23
  |
2 |     let _x = Box::new(|x|x+1;);
  |                       ^^^^^^ this is the parsed closure...
3 | }
  | - ...but likely you meant the closure to end here
help: try adding braces
  |
2 ~     let _x = Box::new(|x| {x+1;);
3 ~ }}
  |

error: expected `;`, found `}`
 --> ./main.rs:2:32
  |
2 |     let _x = Box::new(|x|x+1;);
  |                                ^ help: add `;` here
3 | }
  | - unexpected token

error: aborting due to 3 previous errors
```

We got 3 errors, but all but the second are unnecessary or just wrong.

This commit allows outputting correct suggestions and errors. The above code would output like this:

```
error: closure bodies that contain statements must be surrounded by braces
 --> ./main.rs:2:25
  |
2 |     let _x = Box::new(|x|x+1;);
  |                         ^    ^
  |
note: statement found outside of a block
 --> ./main.rs:2:29
  |
2 |     let _x = Box::new(|x|x+1;);
  |                          ---^ this `;` turns the preceding closure into a statement
  |                          |
  |                          this expression is a statement because of the trailing semicolon
note: the closure body may be incorrectly delimited
 --> ./main.rs:2:23
  |
2 |     let _x = Box::new(|x|x+1;);
  |                       ^^^^^^ - ...but likely you meant the closure to end here
  |                       |
  |                       this is the parsed closure...
help: try adding braces
  |
2 |     let _x = Box::new(|x| {x+1;});
  |                           +    +

error: aborting due to previous error
```

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

r? diagnostics
2023-02-24 12:02:44 +05:30