Commit Graph

11391 Commits

Author SHA1 Message Date
bors
c872a1418a Auto merge of #125507 - compiler-errors:type-length-limit, r=lcnr
Re-implement a type-size based limit

r? lcnr

This PR reintroduces the type length limit added in #37789, which was accidentally made practically useless by the caching changes to `Ty::walk` in #72412, which caused the `walk` function to no longer walk over identical elements.

Hitting this length limit is not fatal unless we are in codegen -- so it shouldn't affect passes like the mir inliner which creates potentially very large types (which we observed, for example, when the new trait solver compiles `itertools` in `--release` mode).

This also increases the type length limit from `1048576 == 2 ** 20` to `2 ** 24`, which covers all of the code that can be reached with craterbot-check. Individual crates can increase the length limit further if desired.

Perf regression is mild and I think we should accept it -- reinstating this limit is important for the new trait solver and to make sure we don't accidentally hit more type-size related regressions in the future.

Fixes #125460
2024-07-03 11:56:36 +00:00
Jacob Pratt
24eadb2cf1
Rollup merge of #127245 - BoxyUwU:gce_hang_test, r=Nilstrieb
Add a test for `generic_const_exprs`

Fixes #103770

r? ``@Nilstrieb``
2024-07-03 03:03:16 -04:00
Jacob Pratt
ce016f1a3f
Rollup merge of #127239 - RalfJung:big-endian, r=Nadrieril
remove unnecessary ignore-endian-big from stack-overflow-trait-infer …

Follow-up to [this](https://github.com/rust-lang/rust/pull/122895#discussion_r1632206218) discussion
2024-07-03 03:03:16 -04:00
Jacob Pratt
18ec452b24
Rollup merge of #127115 - RalfJung:unreferenced-used-static, r=lqd,ChrisDenton
unreferenced-used-static: run test everywhere

Follow-up to https://github.com/rust-lang/rust/pull/127099.
2024-07-03 03:03:15 -04:00
Jacob Pratt
3e6f6deddf
Rollup merge of #126917 - ferrocene:hoverbear/riscv64-inaccessible-temp-dir-resolution, r=jieyouxu
Disable rmake test `inaccessible-temp-dir` on riscv64

In https://github.com/rust-lang/rust/pull/126279 the `inaccessible-temp-dir` test was moved to rmake, I followed up with a 'fix' derived from https://github.com/rust-lang/rust/pull/126355 in https://github.com/rust-lang/rust/pull/126707.

That 'fix' was misguided and hiding the true issue of the linker being incorrect for `riscv64gc-unknown-linux-gnu` (addressed in https://github.com/rust-lang/rust/pull/126916).

Unfortunately, even with the linker fixed, this test doesn't work. I asked myself why this appeared to work on other platforms and investigated why. Both the containers for `armhf-gnu` and `riscv64gc` run their tests as `root` and have `NO_CHANGE_USER` set:

553a69030e/src/ci/docker/host-x86_64/disabled/riscv64gc-gnu/Dockerfile (L99)

This means the tests are run as `root`. As `root`, it's perfectly normal and reasonable to violate permission checks this way:

```bash
$ sudo mkdir scratch
$ sudo chmod o-w scratch
$ sudo mkdir scratch/backs
$
```

Because of this, this PR makes the test ignored on `riscv64gc` for now.

As an alternative, I believe the best long-term strategy would be to not run the tests as `root` for this job.

## Testing

> [!NOTE]
> `riscv64gc-unknown-linux-gnu` is a [**Tier 2 with Host Tools** platform](https://doc.rust-lang.org/beta/rustc/platform-support.html), all tests may not necessarily pass! This change should only ignore `inaccessible-temp-dir` and not affect other tests.

You can test out the job locally:

```sh
mv src/ci/docker/host-x86_64/disabled/riscv64gc-gnu src/ci/docker/host-x86_64/riscv64gc-gnu
DEPLOY=1 ./src/ci/docker/run.sh riscv64gc-gnu
```
2024-07-03 03:03:14 -04:00
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
Jacob Pratt
db592253a6
Rollup merge of #123588 - tgross35:stabilize-assert_unchecked, r=dtolnay
Stabilize `hint::assert_unchecked`

Make the following API stable, including const:

```rust
// core::hint, std::hint

pub const unsafe fn assert_unchecked(p: bool);
```

This PR also reworks some of the documentation and adds an example.

Tracking issue: https://github.com/rust-lang/rust/issues/119131
FCP: https://github.com/rust-lang/rust/issues/119131#issuecomment-1906394087. The docs update should resolve the remaining concern.
2024-07-03 03:03:13 -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
Michael Goulet
b1059ccda2 Instance::resolve -> Instance::try_resolve, and other nits 2024-07-02 17:28:03 -04: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
Michael Goulet
0f7f3f4045 Re-implement a type-size based limit 2024-07-02 15:48:48 -04:00
Boxy
8ce8c62f1e add test 2024-07-02 17:07:21 +01:00
Matthias Krüger
6407580aab
Rollup merge of #127243 - BoxyUwU:new_invalid_const_param_ty_test, r=compiler-errors
Add test for adt_const_params

Fixes #84238

r? `@compiler-errors`
2024-07-02 17:47:51 +02: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
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
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
Boxy
1df876f4c0 Add test 2024-07-02 16:28:01 +01:00
Ralf Jung
6c803ffefb remove unnecessary ignore-endian-big from stack-overflow-trait-infer test 2024-07-02 16:31:40 +02:00
Ana Hobden
8c353cbc46
Disable rmake test inaccessible-temp-dir on riscv64 2024-07-02 06:50:02 -07: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
DianQK
09e0abb0d1
Add the definition for extern "C" at cast-target-abi.rs. 2024-07-02 06:31:35 +08:00
bors
7d97c59438 Auto merge of #126941 - GuillaumeGomez:migrate-run-make-llvm-ident, r=Kobzol
Migrate `run-make/llvm-ident` to `rmake.rs`

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

r? `@Kobzol`

try-job: armhf-gnu
2024-07-01 21:55:41 +00:00
Guillaume Gomez
a509b5a0ba
Rollup merge of #127201 - GuillaumeGomez:improve-run-make-support, r=Kobzol
Improve run-make-support API

I think I'll slowly continue this work. Makes things a bit nicer for contributors, so why not. :D

r? ``@Kobzol``
2024-07-01 20:29:59 +02: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
61e7f05895
Rollup merge of #126880 - Rejyr:migrate-rmake-vw, r=Kobzol
Migrate `volatile-intrinsics`, `weird-output-filenames`, `wasm-override-linker`, `wasm-exceptions-nostd` to `rmake`

Also refactors `wasm-abi` and `compressed-debuginfo`.

Part of #121876.

r? ``@jieyouxu``

try-job: x86_64-gnu-debug
try-job: dist-various-2
2024-07-01 20:29:57 +02:00
Guillaume Gomez
61db24d15d
Rollup merge of #126732 - StackOverflowExcept1on:master, r=m-ou-se
Stabilize `PanicInfo::message()` and `PanicMessage`

Resolves #66745

This stabilizes the [`PanicInfo::message()`](https://doc.rust-lang.org/nightly/core/panic/struct.PanicInfo.html#method.message) and [`PanicMessage`](https://doc.rust-lang.org/nightly/core/panic/struct.PanicMessage.html).

Demonstration of [custom panic handler](https://github.com/StackOverflowExcept1on/panicker):
```rust
#![no_std]
#![no_main]

extern crate libc;

#[no_mangle]
extern "C" fn main() -> libc::c_int {
    panic!("I just panic every time");
}

#[panic_handler]
fn my_panic(panic_info: &core::panic::PanicInfo) -> ! {
    use arrayvec::ArrayString;
    use core::fmt::Write;

    let message = panic_info.message();
    let location = panic_info.location().unwrap();

    let mut debug_msg = ArrayString::<1024>::new();
    let _ = write!(&mut debug_msg, "panicked with '{message}' at '{location}'");

    if debug_msg.try_push_str("\0").is_ok() {
        unsafe {
            libc::puts(debug_msg.as_ptr() as *const _);
        }
    }

    unsafe { libc::exit(libc::EXIT_FAILURE) }
}
```
```
$ cargo +stage1 run --release
panicked with 'I just panic every time' at 'src/main.rs:8:5'
```

- [x] FCP: https://github.com/rust-lang/rust/issues/66745#issuecomment-2198143725

r? libs-api
2024-07-01 20:29:55 +02:00
Guillaume Gomez
7276499dc9 Migrate run-make/llvm-ident to rmake.rs 2024-07-01 15:12:13 +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
Guillaume Gomez
fcfac05657 Improve target method API in run-make-support 2024-07-01 10:55:57 +02:00
Guillaume Gomez
b5b97dccae Improve run-make-support API for assert* functions 2024-07-01 10:55:57 +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
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
c471e07156
Rollup merge of #126923 - workingjubilee:regression-tests-for-simd-invalid-bitcast, r=calebzulawski
test: dont optimize to invalid bitcasts

Regression tests to prevent regressing.
2024-07-01 08:53:05 +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
bors
ad12a2a5fc Auto merge of #127082 - GuillaumeGomez:help-gui-test, r=notriddle
Add back `help-page.goml` rustdoc GUI test

Since https://github.com/rust-lang/rust/pull/127010 was merged, let's see if we can revert https://github.com/rust-lang/rust/pull/126445...

r? `@notriddle`
2024-07-01 00:52:41 +00:00
beetrees
4c919ac50b
Ensure out_of_scope_macro_calls lint is registered 2024-07-01 00:25:25 +01:00
Boxy
552794410a add rustc_dump_def_parents attribute 2024-06-30 19:31:21 +01:00
Scott McMurray
f6942112eb Add a GVN test for 127089 that doesn't optimize to a constant 2024-06-30 11:30:54 -07:00
Deadbeef
daff015314 Migrate tests to use -Znext-solver 2024-06-30 17:08:45 +00:00
Deadbeef
34ae56de35 Make feature(effects) require -Znext-solver 2024-06-30 17:08:10 +00:00