Commit Graph

37446 Commits

Author SHA1 Message Date
Jacob Pratt
b1b9804f5a
Rollup merge of #126403 - compiler-errors:better-type-errors, r=lcnr
Actually report normalization-based type errors correctly for alias-relate obligations in new solver

We have some special casing to report type mismatch errors that come from projection predicates, but we don't do that for alias-relate obligations. This PR implements that. There's a bit of code duplication, but 🤷

Best reviewed without whitespace.

r? lcnr
2024-07-03 03:03:14 -04:00
bors
d163e5e515 Auto merge of #123737 - compiler-errors:alias-wf, r=lcnr
Check alias args for WF even if they have escaping bound vars

#### What

This PR stops skipping arguments of aliases if they have escaping bound vars, instead recursing into them and only discarding the resulting obligations referencing bounds vars.

#### An example:

From the test:
```
trait Trait {
    type Gat<U: ?Sized>;
}

fn test<T>(f: for<'a> fn(<&'a T as Trait>::Gat<&'a [str]>)) where for<'a> &'a T: Trait {}
//~^ ERROR the size for values of type `[()]` cannot be known at compilation time

fn main() {}
```

We now prove that `str: Sized` in order for `&'a [str]` to be well-formed. We were previously unconditionally skipping over `&'a [str]` as it referenced a buond variable. We now recurse into it and instead only discard the `[str]: 'a` obligation because of the escaping bound vars.

#### Why?

This is a change that improves consistency about proving well-formedness earlier in the pipeline, which is necessary for future work on where-bounds in binders and correctly handling higher-ranked implied bounds. I don't expect this to fix any unsoundness.

#### What doesn't it fix?

Specifically, this doesn't check projection predicates' components are well-formed, because there are too many regressions: https://github.com/rust-lang/rust/pull/123737#issuecomment-2052198478
2024-07-03 03:48:06 +00:00
bors
67f0d43890 Auto merge of #123720 - amandasystems:dyn-enable-refactor, r=nikomatsakis
Rewrite handling of universe-leaking placeholder regions into outlives constraints

This commit prepares for Polonius by moving handling of leak check/universe errors out of the inference step by rewriting any universe error into an outlives-static constraint.

This variant is a work in progress but seems to pass most tests.

Note that a few debug assertions no longer hold; a few extra eyes on those changes are appreciated!
2024-07-03 01:24:07 +00:00
Michael Goulet
ecdaff240d Actually report normalization-based type errors correctly for alias-relate obligations in new solver 2024-07-02 16:39:57 -04:00
Matthias Krüger
a10c231118
Rollup merge of #127230 - hattizai:patch01, r=saethlin
chore: remove duplicate words

remove duplicate words in comments to improve readability.
2024-07-02 17:47:50 +02:00
Matthias Krüger
5f17e5c00f
Rollup merge of #127224 - tgross35:pretty-print-exhaustive, r=RalfJung
Make `FloatTy` checks exhaustive in pretty print

This should prevent the default fallback if we add more float types in the future.
2024-07-02 17:47:50 +02:00
Matthias Krüger
4d2a04914e
Rollup merge of #127203 - chenyukang:yukang-fix-120074-import, r=Nadrieril
Fix import suggestion error when path segment failed not from starting

Fixes #120074
2024-07-02 17:47:49 +02:00
Matthias Krüger
33b0238586
Rollup merge of #127168 - DianQK:cast-size, r=workingjubilee
Use the aligned size for alloca at args/ret when the pass mode is cast

Fixes #75839. Fixes #121028.

The `load` and `store` instructions in LLVM access the aligned size. For example, `load { i64, i32 }` accesses 16 bytes on x86_64: https://alive2.llvm.org/ce/z/n8CHAp.

BTW, this example is expected to be optimized to immediate UB by Alive2: https://rust.godbolt.org/z/b7xK7hv1c and https://alive2.llvm.org/ce/z/vZDtZH.

r? compiler
2024-07-02 17:47:48 +02:00
Matthias Krüger
36da46ab98
Rollup merge of #127146 - compiler-errors:fast-reject, r=lcnr
Uplift fast rejection to new solver

Self explanatory.

r? lcnr
2024-07-02 17:47:47 +02:00
Matthias Krüger
3cf567e3c0
Rollup merge of #127136 - compiler-errors:coroutine-closure-env-shim, r=oli-obk
Fix `FnMut::call_mut`/`Fn::call` shim for async closures that capture references

I adjusted async closures to be able to implement `Fn` and `FnMut` *even if* they capture references, as long as those references did not need to borrow data from the closure captures themselves. See #125259.

However, when I did this, I didn't actually relax an assertion in the `build_construct_coroutine_by_move_shim` shim code, which builds the `Fn`/`FnMut`/`FnOnce` implementations for async closures. Therefore, if we actually tried to *call* `FnMut`/`Fn` on async closures, it would ICE.

This PR adjusts this assertion to ensure that we only capture immutable references in closures if they implement `Fn`/`FnMut`. It also adds a bunch of tests and makes more of the async-closure tests into `build-pass` since we often care about these tests actually generating the right closure shims and stuff. I think it might be excessive to *always* use build-pass here, but 🤷 it's not that big of a deal.

Fixes #127019
Fixes #127012

r? oli-obk
2024-07-02 17:47:46 +02:00
Matthias Krüger
f8f67b2969
Rollup merge of #126883 - dtolnay:breakvalue, r=fmease
Parenthesize break values containing leading label

The AST pretty printer previously produced invalid syntax in the case of `break` expressions with a value that begins with a loop or block label.

```rust
macro_rules! expr {
    ($e:expr) => {
        $e
    };
}

fn main() {
    loop {
        break expr!('a: loop { break 'a 1; } + 1);
    };
}
```

`rustc -Zunpretty=expanded main.rs `:

```console
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
macro_rules! expr { ($e:expr) => { $e }; }

fn main() { loop { break 'a: loop { break 'a 1; } + 1; }; }
```

The expanded code is not valid Rust syntax. Printing invalid syntax is bad because it blocks `cargo expand` from being able to format the output as Rust syntax using rustfmt.

```console
error: parentheses are required around this expression to avoid confusion with a labeled break expression
 --> <anon>:9:26
  |
9 | fn main() { loop { break 'a: loop { break 'a 1; } + 1; }; }
  |                          ^^^^^^^^^^^^^^^^^^^^^^^^
  |
help: wrap the expression in parentheses
  |
9 | fn main() { loop { break ('a: loop { break 'a 1; }) + 1; }; }
  |                          +                        +
```

This PR updates the AST pretty-printer to insert parentheses around the value of a `break` expression as required to avoid this edge case.
2024-07-02 17:47:45 +02:00
hattizai
ada9fda7c3 chore: remove duplicate words 2024-07-02 11:25:31 +08:00
David Tolnay
06982239a6
Parenthesize break values containing leading label 2024-07-01 17:19:58 -07:00
DianQK
2ef82805d5
Use the aligned size for alloca at ret when the pass mode is cast. 2024-07-02 06:33:40 +08:00
DianQK
c453dcd62a
Use the aligned size for alloca at args when the pass mode is cast.
The `load` and `store` instructions in LLVM access the aligned size.
2024-07-02 06:33:35 +08:00
Trevor Gross
bb4c427ce4 Make FloatTy checks exhaustive in pretty print
This should prevent the default fallback if we add more float types in the
future.
2024-07-01 18:18:10 -04:00
Guillaume Gomez
61fe6b6c0c
Rollup merge of #127129 - compiler-errors:full-expr-span, r=jieyouxu
Use full expr span for return suggestion on type error/ambiguity

We sometimes use parts of an expression rather than the whole thing for an obligation span. For example, a method obligation will just point to the path segment corresponding to the `method` in `rcvr.method(args)`.

So let's not use that assuming it'll point to the *whole* expression span, which we can access from the expr hir id we store in `ObligationCauseCode::WhereClauseInExpr`.

Fixes #127109
2024-07-01 20:29:58 +02:00
Guillaume Gomez
6b2e644218
Rollup merge of #126832 - petrochenkov:linkarg, r=jieyouxu
linker: Refactor interface for passing arguments to linker

Separate arguments into passed to the underlying linker, to cc wrapper, or supported by both.
Also avoid allocations in all the argument passing functions.

The interfaces would look nicer if not the limitations on returning `&mut Self` in `dyn`-compatible traits, and unnecessary conflicts between `Trait` and `dyn Trait` methods.

try-job: armhf-gnu
try-job: aarch64-gnu
try-job: dist-x86_64-linux
try-job: x86_64-msvc
try-job: i686-msvc
try-job: dist-x86_64-apple
try-job: test-various
2024-07-01 20:29:56 +02:00
Scott McMurray
23c8ed14c9 Avoid MIR bloat in inlining
In 126578 we ended up with more binary size increases than expected.

This change attempts to avoid inlining large things into small things, to avoid that kind of increase, in cases when top-down inlining will still be able to do that inlining later.
2024-07-01 05:17:13 -07:00
yukang
8cc1ed81df Fix import suggestion error when failed not from starting 2024-07-01 20:07:29 +08:00
Vadim Petrochenkov
5f9a0d3844 linker: Bail out of rpath logic early if the target doesn't support rpath 2024-07-01 14:19:51 +03:00
Vadim Petrochenkov
af31c338fc linker: Refactor interface for passing arguments to linker 2024-07-01 14:19:51 +03:00
Amanda Stjerna
9be3a3d761 Add description for why this PR was made 2024-07-01 11:52:38 +02:00
Amanda Stjerna
eea5cf87b2 Code review: rename the method min_universe() 2024-07-01 11:32:45 +02:00
bors
c3774be741 Auto merge of #127197 - matthiaskrgr:rollup-aqpvn5q, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #126923 (test: dont optimize to invalid bitcasts)
 - #127090 (Reduce merge conflicts from rustfmt's wrapping)
 - #127105 (Only update `Eq` operands in GVN if it can update both sides)
 - #127150 (Fix x86_64 code being produced for bare-metal LoongArch targets' `compiler_builtins`)
 - #127181 (Introduce a `rustc_` attribute to dump all the `DefId` parents of a `DefId`)
 - #127182 (Fix error in documentation for IpAddr::to_canonical and Ipv6Addr::to_canonical)
 - #127191 (Ensure `out_of_scope_macro_calls` lint is registered)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-01 08:51:46 +00:00
Amanda Stjerna
b3ef0e8487 Handle universe leaks by rewriting the constraint graph
This version is a squash-rebased version of a series
of exiermental commits, since large parts of them
were broken out into PR #125069.

It explicitly handles universe violations in higher-kinded
outlives constraints by adding extra outlives static constraints.
2024-07-01 10:39:42 +02:00
Matthias Krüger
f5ef1cd17c
Rollup merge of #127191 - beetrees:register-out-of-scope-macro-calls, r=compiler-errors
Ensure `out_of_scope_macro_calls` lint is registered

Fixes part of https://github.com/rust-lang/rust/issues/126984#issuecomment-2198792687.
2024-07-01 08:53:09 +02:00
Matthias Krüger
b067ee82f8
Rollup merge of #127181 - BoxyUwU:dump_def_parents, r=compiler-errors
Introduce a `rustc_` attribute to dump all the `DefId` parents of a `DefId`

We've run into a bunch of issues with anon consts having the wrong generics and it would have been incredibly helpful to be able to quickly slap a `rustc_` attribute to check what `tcx.parent(` will return on the relevant DefIds.

I wasn't sure of a better way to make this work for anon consts than requiring the attribute to be on the enclosing item and then walking the inside of it to look for any anon consts. This particular method will honestly break at some point when we stop having a `DefId` available for anon consts in hir but that's for another day...

r? ``@compiler-errors``
2024-07-01 08:53:07 +02:00
Matthias Krüger
6938b4b640
Rollup merge of #127105 - scottmcm:issue-127089, r=cjgillot
Only update `Eq` operands in GVN if it can update both sides

Otherwise the types might not match

Fixes #127089

r? mir-opt
2024-07-01 08:53:06 +02:00
Matthias Krüger
04a3969af7
Rollup merge of #127090 - kornelski:wrap-conflicts, r=fee1-dead
Reduce merge conflicts from rustfmt's wrapping

Imports in this file are changed by many different features. Rustfmt insists on reformatting and rewrapping the imports every time they change, which causes chronic merge conflicts.

I've split the big import into multiple smaller ones, so that different features will conflict less often.
2024-07-01 08:53:06 +02:00
bors
7b21c18fe4 Auto merge of #126996 - oli-obk:do_not_count_errors, r=nnethercote
Automatically taint InferCtxt when errors are emitted

r? `@nnethercote`

Basically `InferCtxt::dcx` now returns a `DiagCtxt` that refers back to the `Cell<Option<ErrorGuaranteed>>` of the `InferCtxt` and thus when invoking `Diag::emit`, and the diagnostic is an error, we taint the `InferCtxt` directly.

That change on its own has no effect at all, because `InferCtxt` already tracks whether errors have been emitted by recording the global error count when it gets opened, and checking at the end whether the count changed. So I removed that error count check, which had a bit of fallout that I immediately fixed by invoking `InferCtxt::dcx` instead of `TyCtxt::dcx` in a bunch of places.

The remaining new errors are because an error was reported in another query, and never bubbled up. I think they are minor enough for this to be ok, and sometimes it actually improves diagnostics, by not silencing useful diagnostics anymore.

fixes #126485 (cc `@olafes)`

There are more improvements we can do (like tainting in hir ty lowering), but I would rather do that in follow up PRs, because it requires some refactorings.
2024-07-01 06:35:58 +00:00
bors
f92a6c41e6 Auto merge of #127176 - fee1-dead-contrib:fx-requires-next-solver, r=compiler-errors
Make `feature(effects)` require `-Znext-solver`

Per https://github.com/rust-lang/rust/pull/120639#pullrequestreview-2144804638

I made this a hard error because otherwise it should be a lint and that seemed more complicated. Not sure if this is the best place to put the error though.

r? project-const-traits
2024-07-01 04:21:13 +00:00
Michael Goulet
583b5fcad7 Use full expr span for return suggestion on type error/ambiguity 2024-06-30 23:11:54 -04:00
beetrees
4c919ac50b
Ensure out_of_scope_macro_calls lint is registered 2024-07-01 00:25:25 +01:00
bors
6868c831a1 Auto merge of #127174 - matthiaskrgr:rollup-q87j6cn, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #126018 (Remove the `box_pointers` lint.)
 - #126895 (Fix simd_gather documentation)
 - #126981 (Replace some magic booleans in match-lowering with enums)
 - #127038 (Update test comment)
 - #127053 (Update the LoongArch target documentation)
 - #127069 (small correction to fmt::Pointer impl)
 - #127157 (coverage: Avoid getting extra unexpansion info when we don't need it)
 - #127160 (Add a regression test for #123630)
 - #127161 (Improve `run-make-support` library `args` API)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-30 20:14:40 +00:00
Boxy
552794410a add rustc_dump_def_parents attribute 2024-06-30 19:31:21 +01:00
Deadbeef
34ae56de35 Make feature(effects) require -Znext-solver 2024-06-30 17:08:10 +00:00
Matthias Krüger
b2aebc1b76
Rollup merge of #127157 - Zalathar:unexpand, r=cjgillot
coverage: Avoid getting extra unexpansion info when we don't need it

Several callers of `unexpand_into_body_span_with_visible_macro` would immediately discard the additional macro-related information, which is wasteful. We can avoid this by having them instead call a simpler method that just returns the span they care about.

This PR also moves the relevant functions out of `coverage::spans::from_mir` and into a new submodule `coverage::unexpand`, so that calling them from `coverage::mappings` is less awkward.

There should be no actual changes to coverage-instrumentation output, as demonstrated by the absence of test updates.
2024-06-30 18:25:34 +02:00
Matthias Krüger
d404ce7015
Rollup merge of #126981 - Zalathar:enums, r=Nadrieril
Replace some magic booleans in match-lowering with enums

This PR takes some boolean arguments used by the match-lowering code, and replaces them with dedicated enums that more clearly express their effect, while also making it much easier to find how each value is ultimately used.
2024-06-30 18:25:32 +02:00
Matthias Krüger
6f5765599e
Rollup merge of #126018 - nnethercote:rm-box_pointers-lint, r=lcnr
Remove the `box_pointers` lint.

As the comment says, this lint "is mostly historical, and not particularly useful". It's not worth keeping it around.

r? ``@estebank``
2024-06-30 18:25:31 +02:00
bors
ef3d6fd700 Auto merge of #127162 - bjorn3:sync_cg_clif-2024-06-30, r=bjorn3
Subtree sync for rustc_codegen_cranelift

The main highlight this time is support for arm64 macOS in cg_clif. A future PR will enable distributing it as rustup component.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
2024-06-30 16:23:04 +00:00
bors
6c3485512f Auto merge of #127156 - matthiaskrgr:rollup-jjfd464, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #126705 (Updated docs on `#[panic_handler]` in `library/core/src/lib.rs`)
 - #126876 (Add `.ignore` file to make `config.toml` searchable in vscode)
 - #126906 (Small fixme in core now that split_first has no codegen issues)
 - #127023 (CI: rename Rust for Linux CI job)
 - #127131 (Remove unused `rustc_trait_selection` dependencies)
 - #127134 (Print `TypeId` as a `u128` for `Debug`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-30 13:22:17 +00:00
bjorn3
9ec6a02ab3 Merge commit '49cd5dd454d0115cfbe9e39102a8b3ba4616aa40' into sync_cg_clif-2024-06-30 2024-06-30 11:28:14 +00:00
bors
2975a21b5d Auto merge of #127024 - cjgillot:jump-prof, r=oli-obk
Avoid cloning jump threading state when possible

The current implementation of jump threading passes most of its time cloning its state. This PR attempts to avoid such clones by special-casing the last predecessor when recursing through a terminator.

This is not optimal, but a first step while I refactor the state data structure to be sparse.

The two other commits are drive-by.
Fixes https://github.com/rust-lang/rust/issues/116721

r? `@oli-obk`
2024-06-30 11:09:53 +00:00
Zalathar
6c33149055 coverage: Avoid getting extra unexpansion info when we don't need it
These particular callers don't actually use the returned macro information, so
they can use a simpler span-unexpansion function that doesn't return it.
2024-06-30 19:05:14 +10:00
Zalathar
ed07712e96 Replace a magic boolean with enum ScheduleDrops 2024-06-30 19:02:25 +10:00
Zalathar
3b22589cfa Replace a magic boolean with enum EmitStorageLive
The previous boolean used `true` to indicate that storage-live should _not_ be
emitted, so all occurrences of `Yes` and `No` should be the logical opposite of
the previous value.
2024-06-30 18:55:39 +10:00
Zalathar
ad575b093b Replace a magic boolean with enum DeclareLetBindings
The new enum `DeclareLetBindings` has three variants:
- `Yes`: Declare `let` bindings as normal, for `if` conditions.
- `No`: Don't declare bindings, for match guards and let-else.
- `LetNotPermitted`: Assert that `let` expressions should not occur.
2024-06-30 18:55:39 +10:00
Matthias Krüger
515d17cd15
Rollup merge of #127131 - Kobzol:remove-unused-deps, r=compiler-errors
Remove unused `rustc_trait_selection` dependencies

Found using `cargo-machete`. The `bitflags` and `derivative` crates were added for the new trait solver, but weren't removed when the next trait solver code was uplifted to a separate crate.
2024-06-30 10:39:48 +02:00
Zalathar
617de8cfb5 coverage: Move span unexpansion into its own submodule 2024-06-30 17:44:19 +10:00