Commit Graph

26204 Commits

Author SHA1 Message Date
Michael Goulet
c9ce51b5c7 Check GAT, IAT, and weak type where clauses during projection 2023-07-16 21:14:38 +00:00
Michael Goulet
085ae9e8b4 Add support for inherent projections 2023-07-16 21:14:38 +00:00
bors
c4083faade Auto merge of #113545 - cjgillot:query-entry, r=compiler-errors
Check entry type as part of item type checking.

This code is currently executed inside the root `analysis` query.
Instead, check it during `check_for_entry_fn(CRATE_DEF_ID)` to hopefully avoid some re-executions.

`CRATE_DEF_ID` is chosen by considering that entry fn are typically at crate root, so the corresponding HIR should already be in the dependencies.
2023-07-16 18:54:18 +00:00
bors
11da267fdb Auto merge of #112239 - jieyouxu:targeted-no-method-suggestions, r=cjgillot
Add `#[rustc_confusables]` attribute to allow targeted "no method" error suggestions on standard library types

After this PR, the standard library developer can annotate methods on e.g. `BTreeSet::push` with `#[rustc_confusables("insert")]`. When the user mistypes `btreeset.push()`, `BTreeSet::insert` will be suggested if there are no other candidates to suggest. This PR lays the foundations for contributors to add `rustc_confusables` annotations to standard library types for targeted suggestions, as specified in #59450, or to address cases such as #108437.

### Example

Assume `BTreeSet` is the standard library type:

```
// Standard library definition
#![feature(rustc_attrs)]

struct BTreeSet;

impl BTreeSet {
    #[rustc_confusables("push")]
    fn insert(&self) {}
}

// User code
fn main() {
    let x = BTreeSet {};
    x.push();
}
```

A new suggestion (which has lower precedence than suggestions for misspellings and only is shown when there are no misspellings suggestions) will be added to hint the user maybe they intended to write `x.insert()` instead:

```
error[E0599]: no method named `push` found for struct `BTreeSet` in the current scope
  --> test.rs:12:7
   |
3  | struct BTreeSet;
   | --------------- method `push` not found for this struct
...
12 |     x.push();
   |       ^^^^ method not found in `BTreeSet`
   |
help: you might have meant to use `insert`
   |
12 |     x.insert();
   |       ~~~~~~

error: aborting due to previous error
```
2023-07-16 15:25:03 +00:00
bors
4a07b2baf5 Auto merge of #113557 - Amanieu:no-builtins-prelude, r=petrochenkov
Hide `compiler_builtins` in the prelude

This crate is a private implementation detail. We only need to insert it into the crate graph for linking and should not expose any of its public API.

Fixes #113533
2023-07-16 13:19:14 +00:00
许杰友 Jieyou Xu (Joe)
08c77a6eb4
Add infrastructure #[rustc_confusables] attribute to allow targeted
"no method" errors on standard library types

The standard library developer can annotate methods on e.g.
`BTreeSet::push` with `#[rustc_confusables("insert")]`. When the user
mistypes `btreeset.push()`, `BTreeSet::insert` will be suggested if
there are no other candidates to suggest.
2023-07-16 19:22:03 +08:00
bors
55be59d2ce Auto merge of #113626 - Urgau:dedup-native-static-libs, r=petrochenkov
De-duplicate consecutive libs when printing native-static-libs

This PR adds a de-duplicate step just before printing the `native-static-libs`.

This step de-duplicates all the consecutive libs based only on the relevant comparison elements (this exclude spans, ast elements, ...).

Fixes https://github.com/rust-lang/rust/issues/113209
2023-07-16 10:59:45 +00:00
bors
ffb9b61294 Auto merge of #113430 - Zalathar:hash, r=b-naber
Remove `LLVMRustCoverageHashCString`

Coverage has two FFI functions for computing the hash of a byte string. One takes a ptr/len pair (`LLVMRustCoverageHashByteArray`), and the other takes a NUL-terminated C string (`LLVMRustCoverageHashCString`).

But on closer inspection, the C string version is unnecessary. The calling-side code converts a Rust `&str` into a `CString`, and the C++ code then immediately turns it back into a ptr/len string before actually hashing it. So we can just call the ptr/len version directly instead.

---

This PR also fixes a bug in the C++ declaration of `LLVMRustCoverageHashByteArray`. It should be `size_t`, since that's what is declared and passed on the Rust side, and it's what `StrRef`'s constructor expects to receive on the callee side.
2023-07-16 01:56:23 +00:00
bors
4124617c6e Auto merge of #113606 - jyn514:parallel-compiler-cleanup, r=cjgillot
Don't require each rustc_interface tool to opt-in to parallel_compiler

Previously, forgetting to call `interface::set_thread_safe_mode` would cause the following ICE:
```
thread 'rustc' panicked at 'uninitialized dyn_thread_safe mode!', /rustc/dfe0683138de0959b6ab6a039b54d9347f6a6355/compiler/rustc_data_structures/src/sync.rs:74:18
```

This calls `set_thread_safe_mode` in `interface::run_compiler` to avoid requiring it in the caller.

Fixes `tests/run-make-fulldeps/issue-19371` when parallel-compiler is enabled.

r? `@SparrowLii` cc https://github.com/rust-lang/rust/issues/75760
2023-07-15 22:23:05 +00:00
Camille GILLOT
87233da5c2 Check entry type as part of item type checking. 2023-07-15 22:02:16 +00:00
Matthias Krüger
9b8be2f0e1
Rollup merge of #113663 - syvb:non_inherited_unsafe_thir, r=cjgillot
Implement "items do not inherit unsafety" note for THIR unsafeck

Implements the "items do not inherit unsafety from separate enclosing items" note from the MIR unsafety checker in the THIR unsafety checker (`-Z thir-unsafeck`) to maintain parity between the two unsafety checkers. The logic to find the separate enclosing item is nearly the same as in the MIR unsafety checker.
2023-07-15 19:42:52 +02:00
Matthias Krüger
da18cf8572
Rollup merge of #113625 - compiler-errors:structurally-norm-in-selection, r=lcnr
Structurally normalize in selection

We need to do this because of the fact that we're checking the `Ty::kind` on a type during selection, but goals passed into select are not necessarily normalized.

Right now, we're (kinda) unnecessarily normalizing the RHS of a trait upcasting goal, which is broken for different reasons (#113393). But I'm waiting for this PR to land before discussing that one.

r? `@lcnr`
2023-07-15 19:42:51 +02:00
syvb
2cfe8ed37d Implement "items do not inherit unsafety" for THIR unsafeck 2023-07-15 11:59:38 -04:00
bors
7a17f577b3 Auto merge of #112157 - erikdesjardins:align, r=nikic
Resurrect: rustc_target: Add alignment to indirectly-passed by-value types, correcting the alignment of byval on x86 in the process.

Same as #111551, which I [accidentally closed](https://github.com/rust-lang/rust/pull/111551#issuecomment-1571222612) :/

---

This resurrects PR #103830, which has sat idle for a while.

Beyond #103830, this also:
- fixes byval alignment for types containing vectors on Darwin (see `tests/codegen/align-byval-vector.rs`)
- fixes byval alignment for overaligned types on x86 Windows (see `tests/codegen/align-byval.rs`)
- fixes ABI for types with 128bit requested alignment on ARM64 Linux (see `tests/codegen/aarch64-struct-align-128.rs`)

r? `@nikic`

---

`@pcwalton's` original PR description is reproduced below:

Commit 88e4d2c from five years ago removed
support for alignment on indirectly-passed arguments because of problems with
the `i686-pc-windows-msvc` target. Unfortunately, the `memcpy` optimizations I
recently added to LLVM 16 depend on this to forward `memcpy`s. This commit
attempts to fix the problems with `byval` parameters on that target and now
correctly adds the `align` attribute.

The problem is summarized in [this comment] by `@eddyb.` Briefly, 32-bit x86 has
special alignment rules for `byval` parameters: for the most part, their
alignment is forced to 4. This is not well-documented anywhere but in the Clang
source. I looked at the logic in Clang `TargetInfo.cpp` and tried to replicate
it here. The relevant methods in that file are
`X86_32ABIInfo::getIndirectResult()` and
`X86_32ABIInfo::getTypeStackAlignInBytes()`. The `align` parameter attribute
for `byval` parameters in LLVM must match the platform ABI, or miscompilations
will occur. Note that this doesn't use the approach suggested by eddyb, because
I felt it was overkill to store the alignment in `on_stack` when special
handling is really only needed for 32-bit x86.

As a side effect, this should fix #80127, because it will make the `align`
parameter attribute for `byval` parameters match the platform ABI on LLVM
x86-64.

[this comment]: #80822 (comment)
2023-07-15 15:39:53 +00:00
Erik Desjardins
2daacf5af9 i686-windows: make requested alignment > 4 special case apply transitively 2023-07-14 17:48:13 -04:00
bors
ad963232d9 Auto merge of #113471 - compiler-errors:new-solver-norm-escaping, r=lcnr
Allow escaping bound vars during `normalize_erasing_regions` in new solver

Add `AllowEscapingBoundVars` to `deeply_normalize`, and use it in the new solver in the `query_normalize` routine.

Ideally, we'd make all `query_normalize` calls handle pass in `AllowEscapingBoundVars` individually, because really the only `query_normalize` call that needs `AllowEscapingBoundVars::Yes` is the one in `try_normalize_generic_arg_after_erasing_regions`, but I think that's kind of overkill. I am happy to be convinced otherwise, though.

r? `@lcnr`
2023-07-14 21:14:30 +00:00
bors
3b55d2385a Auto merge of #113703 - matthiaskrgr:rollup-19uhwuh, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #113599 (Use maybe_body_owned_by for multiple suggestions)
 - #113662 (Rename VecDeque's `rotate_left` and `rotate_right` parameters)
 - #113681 (rustdoc-json: Add test for private supertrait.)
 - #113682 (trait system refactor ping: also apply to nested modules of `solve`)
 - #113685 (Print artifact sizes in `opt-dist`)
 - #113688 (llvm-wrapper: update for LLVM API change)
 - #113692 (tests: adapt for removal of -opaque-pointers in LLVM 17)
 - #113698 (Make it clearer that we're just checking for an RPITIT)
 - #113699 (update Miri)

Failed merges:

 - #113625 (Structurally normalize in selection)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-14 19:26:19 +00:00
Michael Goulet
7fb27e4717 Structurally normalize in selection 2023-07-14 18:40:18 +00:00
Matthias Krüger
0baf4406da
Rollup merge of #113698 - compiler-errors:rpitit-check, r=spastorino
Make it clearer that we're just checking for an RPITIT

Tiny nit to use `is_impl_trait_in_trait` more, to make it clearer that we're just checking whether a def-id is an RPITIT, rather than doing something meaningful with the `opt_rpitit_info`.

r? `@spastorino`
2023-07-14 19:33:29 +02:00
Matthias Krüger
59d8da00e5
Rollup merge of #113688 - krasimirgg:llvm-17-small-string, r=nikic
llvm-wrapper: update for LLVM API change

No functional changes intended.

Adds an include for `llvm::SmallString`. Previously, this must have been implicitly provided by some of the existing headers. With recent LLVM changes, not anymore:
https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/20776#01895448-44a4-4a1e-8407-9d41d0186132/209-690
2023-07-14 19:33:28 +02:00
Matthias Krüger
f6dbf7d69b
Rollup merge of #113599 - chenyukang:yukang-fix-use-maybe_body_owned_by, r=cjgillot
Use maybe_body_owned_by for multiple suggestions

This is a continued work from https://github.com/rust-lang/rust/pull/113567

We have several other suggestions not working for closure, this PR use `maybe_body_owned_by` to fix them and add test cases for them.
2023-07-14 19:33:26 +02:00
bors
079e544174 Auto merge of #109025 - cjgillot:refprop-dbg, r=JakobDegen
Enable MIR reference propagation by default
2023-07-14 17:32:59 +00:00
Amanieu d'Antras
07f855d781 Hide compiler_builtins in the prelude
This crate is a private implementation detail. We only need to insert it
into the crate graph for linking and should not expose any of its public
API.

Fixes #113533
2023-07-14 16:53:36 +01:00
bors
5767cad9b8 Auto merge of #113591 - mdibaiee:genericargs-cleanup, r=oli-obk
refactor(rustc_middle): Substs -> GenericArg

resolves #110793

- [x] rename `SubstsRef` and `InternalSubsts` to `GenericArgsRef<'tcx>` and `GenericArgs<'tcx>`.
- [x] rename variables and fields currently using `substs` to `args`.
- [x] update the module name of `ty::subst` to `ty::generic_args` or sth. Make that module private and publicly reexport its content in the ty module.
- [x] rename `EarlyBinder::subst(_identity)` to `EarlyBinder::instantiate(_identity)`.
- [x] types called `[a-zA-Z]+Substs` renamed to `XArgs`.
- [x] functions containing `substs` now use `args` or `generic_args` (mostly the former).

However, the verb of "substituting" is still being used here and there, mostly in comments. I think that can be a separate PR as part of https://github.com/rust-lang/rust/issues/110254 to change the verb to `replace_generics` or something similar.
2023-07-14 15:31:15 +00:00
Michael Goulet
14672eba8b Make it clearer that we're just checking for an RPITIT 2023-07-14 15:18:48 +00:00
Michael Goulet
1ef85d82e0 assertion, comment 2023-07-14 15:03:21 +00:00
Michael Goulet
4bcca3294a Allow escaping bound vars during normalize_erasing_regions in new solver 2023-07-14 15:03:21 +00:00
Mahdi Dibaiee
e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Krasimir Georgiev
6ddf9128b2 llvm-wrapper: update for LLVM API change
No functional changes intended.

Adds an include for llvm::SmallString. Previously, this must have been
implicitly provided by some of the existing headers. With recent LLVM
changes, not anymore:
https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/20776#01895448-44a4-4a1e-8407-9d41d0186132/209-690
2023-07-14 12:10:29 +00:00
bors
bacf5bcbc7 Auto merge of #112982 - lukas-code:bootstrap-alias-default-crates, r=albertlarsan68
bootstrap: update defaults for `compiler` and `library` aliases

* `x doc compiler` now documents all of compiler, not just `rustc_driver`.
* `x doc` with compiler docs enabled now includes `rustc-main` and `rustc_smir`. `rustc_codegen_llvm` is only included if the LLVM backend is enabled, which is the default.
* `x doc library` now excludes `sysroot`.
* `x check compiler` and `x check library` now properly check tests/benches/examples of all compiler or library crates, respectively. Note that `x check compiler` will check the library artifacts, but not tests.

fixes the fallout from https://github.com/rust-lang/rust/pull/111955, cc `@jyn514`
2023-07-14 12:09:27 +00:00
bors
df5c2cf9bc Auto merge of #113328 - michaelwoerister:no_hashmap_in_typeck, r=cjgillot,lcnr
Enable potential_query_instability lint in rustc_hir_typeck.

Fix linting errors by using `FxIndex(Map|Set)` and `Unord(Map|Set)` as appropriate. Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).

I really like the `potential_query_instability` lint!

r? `@lcnr`
2023-07-14 09:55:40 +00:00
Lukas Markeffsky
9d6bfc281d fix docs for rustc_smir 2023-07-14 09:41:42 +00:00
Michael Woerister
457b787a52 Introduce ExtentUnord trait for collections that can safely consume UnordItems. 2023-07-14 10:10:15 +02:00
Michael Woerister
cfb310939b Enable potential_query_instability lint in rustc_hir_typeck.
Fix linting errors by using FxIndex(Map|Set) and Unord(Map|Set) as appropriate.
2023-07-14 10:10:14 +02:00
bors
320b412f9c Auto merge of #113639 - ericmarkmartin:more-smir-types, r=oli-obk
Add more ty conversions to smir

add str, slice, and array to smir types

r? `@spastorino`
2023-07-14 07:42:02 +00:00
bors
fe03b46ee4 Auto merge of #113609 - nnethercote:maybe_lint_level_root_bounded-cache, r=cjgillot
Add a cache for `maybe_lint_level_root_bounded`

`maybe_lint_level_root_bounded` is called many times and traces node sub-paths many times. This PR adds a cache that lets many of these tracings be skipped, avoiding lots of calls to functions like `Map::attrs` and `Map::parent_id`.

r? `@cjgillot`
2023-07-14 05:30:53 +00:00
bors
7d60819bfd Auto merge of #113519 - SparrowLii:parallel_typeck, r=cjgillot
typeck in parallel

#108118 caused `typeck` to be transferred to the serial part (`check_unused`), which made the performance of parallel rustc significantly reduced.

This pr re-parallelize this part, which increases the average performance improvement of parallel rustc in `full` and `incr-full` scenarios from [14.4%](https://github.com/rust-lang/rust/pull/110284#issuecomment-1545354608) to [23.2%](https://github.com/rust-lang/rust/pull/110284#issuecomment-1624770626).

r? `@cjgillot`
cc `@oli-obk` `@Zoxc`
2023-07-14 03:47:02 +00:00
Eric Mark Martin
fd5553ffea add str, slice, and array to smir types 2023-07-13 20:59:44 -04:00
yukang
bdd04a62f9 fix the issue of shorthand in suggest_cloning 2023-07-14 07:12:38 +08:00
yukang
3ddf6f7c17 use maybe_body_owned_by for closure 2023-07-14 07:12:35 +08:00
Matthias Krüger
2cc04536b4
Rollup merge of #112729 - jieyouxu:unused-qualifications-suggestion, r=b-naber
Add machine-applicable suggestion for `unused_qualifications` lint

```
error: unnecessary qualification
  --> $DIR/unused-qualifications-suggestion.rs:17:5
   |
LL |     foo::bar();
   |     ^^^^^^^^
   |
note: the lint level is defined here
  --> $DIR/unused-qualifications-suggestion.rs:3:9
   |
LL | #![deny(unused_qualifications)]
   |         ^^^^^^^^^^^^^^^^^^^^^
help: replace it with the unqualified path
   |
LL |     bar();
   |     ~~~
```

Closes #92198.
2023-07-14 01:03:07 +02:00
Matthias Krüger
fc1cb0459d
Rollup merge of #113631 - lqd:fix-113597, r=petrochenkov
make MCP510 behavior opt-in to avoid conflicts between the CLI and target flavors

Fixes #113597, which contains more details on how this happens through the code, and showcases an unexpected `Gnu(Cc::Yes, Lld::Yes)` flavor.

#112910 added support to use `lld` when the flavor requests it, but didn't explicitly do so only when using `-Clink-self-contained=+linker` or one of the unstable `-Clinker-flavor`s.

The problem: some targets have a `lld` linker and flavor, e.g. `thumbv6m-none-eabi` from that issue. Users can override the linker but there are no linker flavors precise enough to describe the linker opting out of lld: when using `-Clinker=arm-none-eabi-gcc`, we infer this is a `Cc::Yes` linker flavor, but the `lld` component is unknown and therefore defaulted to the target's linker flavor, `Lld::Yes`.

<details>
<summary>Walkthrough of how this happens</summary>

The linker flavor used is a mix between what can be inferred from the CLI (`-C linker`) and the target's default linker flavor:

- there is no linker flavor on the CLI (and that also offers another workaround on nightly: `-C linker-flavor=gnu-cc -Zunstable-options`), so it will have to be inferred [from here](5dac6b320b/compiler/rustc_codegen_ssa/src/back/link.rs (L1334-L1336)) to [here](5dac6b320b/compiler/rustc_codegen_ssa/src/back/link.rs (L1321-L1327)).
- in [`infer_linker_hints`](5dac6b320b/compiler/rustc_target/src/spec/mod.rs (L320-L352)) `-C linker=arm-none-eabi-gcc` infers a `Some(Cc::Yes)` cc hint, and no hint about lld.
- the target's `linker_flavor` is combined in `with_cli_hints` with these hints. We have our `Cc::Yes`, but there is no hint about lld, [so the target's flavor `lld` component is used](5dac6b320b/compiler/rustc_target/src/spec/mod.rs (L356-L358)). It's [`Gnu(Cc::No, Lld::Yes)`](993deaa0bf/compiler/rustc_target/src/spec/thumb_base.rs (L35)).
- so we now have our `Gnu(Cc::Yes, Lld::Yes)` flavor

</details>

This results in a `Gnu(Cc::Yes, Lld::Yes)` flavor on a non-lld linker, causing an additional unexpected `-fuse-ld=lld` argument to be passed.

I don't know if this target defaulting to `rust-lld` is expected, but until MCP510's new linker flavor are stable, when people will be able to describe their linker/flavor accurately, this PR keeps the stable behavior of not doing anything when the linker/flavor on the CLI unexpectedly conflict with the target's.

I've tested this on a `no_std` `-C linker=arm-none-eabi-gcc -C link-arg=-nostartfiles --target thumbv6m-none-eabi` example, trying to simulate one of `cortex-m`'s test mentioned in issue #113597 (I don't know how to build a local complete  `thumbv6m-none-eabi` toolchain to run the exact test), and checked that `-fuse-lld` was indeed gone and the error disappeared.

r? `````@petrochenkov`````
2023-07-13 22:33:25 +02:00
Matthias Krüger
017112f834
Rollup merge of #113629 - spastorino:smir-types-3, r=oli-obk
Add Adt to SMIR

r? ````@oli-obk````
2023-07-13 22:33:25 +02:00
Matthias Krüger
b0eb3c7ee4
Rollup merge of #113570 - lcnr:inspect-format, r=BoxyUwU
refactor proof tree formatting

mostly:
- handle indentation via a separate formatter
- change nested to use a closure

tested it after rebasing on top of #113536 and everything looks good.

r? `````@BoxyUwU`````
2023-07-13 22:33:24 +02:00
Matthias Krüger
dec104c7ad
Rollup merge of #113536 - lcnr:proof-tree-select, r=BoxyUwU
avoid building proof trees in select

otherwise we ICE because select isn't currently set up to print proof trees.

r? `````@BoxyUwU`````
2023-07-13 22:33:23 +02:00
bors
a161ab00db Auto merge of #113637 - Mark-Simulacrum:bootstrap-bump, r=ozkanonur
Bump bootstrap to 1.72 beta
2023-07-13 18:15:14 +00:00
Santiago Pastorino
c80a0f3178
Add Adt to SMIR 2023-07-13 12:00:46 -03:00
Matthias Krüger
b37c916559
Rollup merge of #113615 - krasimirgg:llvm-17-pgo, r=nikic
llvm-wrapper: adapt for LLVM API change

Adapts the wrapper for LLVM commit 546ec641b4.

Found by the experimental rust + LLVM @ HEAD bot: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/20723#01894922-ed5d-4830-81f6-a27fb82ec8c7/210-645
2023-07-13 12:19:24 +02:00
Matthias Krüger
66233fbb32
Rollup merge of #113553 - spastorino:smir-types-2, r=oli-obk
Make Placeholder, GeneratorWitness*, Infer and Error unreachable on SMIR rustc_ty_to_ty

Let's remove these todos to not confuse ``@ericmarkmartin`` if they pick some conversion up.

r? ``@oli-obk``
2023-07-13 12:19:22 +02:00
Matthias Krüger
893a5d2b32
Rollup merge of #113353 - compiler-errors:select-better, r=lcnr
Implement selection for `Unsize` for better coercion behavior

In order for much of coercion to succeed, we need to be able to deal with partial ambiguity of `Unsize` traits during selection. However, I pessimistically implemented selection in the new trait solver to just bail out with ambiguity if it was a built-in impl:
9227ff28af/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs (L126)

This implements a proper "rematch" procedure for dealing with built-in `Unsize` goals, so that even if the goal is ambiguous, we are able to get nested obligations which are used in the coercion selection-like loop:
9227ff28af/compiler/rustc_hir_typeck/src/coercion.rs (L702)

Second commit just moves a `resolve_vars_if_possible` call to fix a bug where we weren't detecting a trait upcasting to occur.

r? ``@lcnr``
2023-07-13 12:19:22 +02:00