Commit Graph

14045 Commits

Author SHA1 Message Date
Esteban Küber
1a0c502183 On long E0277 primary span label, move it to a help
Long span labels don't read well.
2024-11-02 03:08:04 +00:00
Esteban Küber
092ecca5b9 Point at tail expression on rpit E0277
```
error[E0277]: the trait bound `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}: Coroutine` is not satisfied
  --> $DIR/gen_block_is_coro.rs:6:13
   |
LL | fn foo() -> impl Coroutine<Yield = u32, Return = ()> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine` is not implemented for `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}`
LL |     gen { yield 42 }
   |     ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}` here
```

The secondary span label is new.
2024-11-02 03:08:04 +00:00
Esteban Küber
7b9105dd88 Trim output of E0277 in some cases
Remove default note for "trait is not implemented" in favor of the
more colorful diff output from the previous commit. Removes
duplicated output.
2024-11-02 03:08:04 +00:00
Esteban Küber
b7fc1a7431 Add trait diff highlighting logic and use it in E0277
When a trait is not implemented for a type, but there *is* an `impl`
for another type or different trait params, we format the output to
use highlighting in the same way that E0308 does for types.

The logic accounts for 3 cases:
- When both the type and trait in the expected predicate and the candidate are different
- When only the types are different
- When only the trait generic params are different

For each case, we use slightly different formatting and wording.
2024-11-02 03:08:04 +00:00
bors
7c7bb7dc01 Auto merge of #132470 - GuillaumeGomez:rollup-1a1mkmp, r=GuillaumeGomez
Rollup of 14 pull requests

Successful merges:

 - #131829 (Remove support for `-Zprofile` (gcov-style coverage instrumentation))
 - #132369 (style-guide: Only use the new binop heuristic for assignments)
 - #132383 (Implement suggestion for never type fallback lints)
 - #132413 (update offset_of! docs to reflect the stabilization of nesting)
 - #132438 (Remove unncessary option for default rust-analyzer setting)
 - #132439 (Add `f16` and `f128` to `invalid_nan_comparison`)
 - #132444 (rustdoc: Directly use rustc_abi instead of reexports)
 - #132445 (Cleanup attributes around unchecked shifts and unchecked negation in const)
 - #132448 (Add missing backtick)
 - #132450 (Show actual MIR when MIR building forgot to terminate block)
 - #132451 (remove some unnecessary rustc_allow_const_fn_unstable)
 - #132455 (make const_alloc_layout feature gate only about functions that are already stable)
 - #132456 (Move remaining inline assembly test files into asm directory)
 - #132459 (feat(byte_sub_ptr): unstably add ptr::byte_sub_ptr)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-01 21:49:15 +00:00
Guillaume Gomez
81c6943f1a
Rollup merge of #132456 - taiki-e:test-asm-dir, r=jieyouxu
Move remaining inline assembly test files into asm directory

Before:
```
tests/assembly/asm/*
tests/assembly/asm-comments.rs
tests/codegen/asm-target-clobbers.rs
tests/codegen/asm-goto.rs
tests/codegen/asm-maybe-uninit.rs
tests/codegen/asm-msp430-clobbers.rs
tests/codegen/asm-options.rs
tests/codegen/asm-clobbers.rs
tests/codegen/asm-may_unwind.rs
tests/codegen/asm-arm64ec-clobbers.rs
tests/codegen/asm-powerpc-clobbers.rs
tests/codegen/asm-sanitize-llvm.rs
tests/codegen/asm-s390x-clobbers.rs
tests/codegen/asm-clobber_abi.rs
tests/codegen/asm-multiple-options.rs
tests/codegen/global_asm.rs
tests/codegen/global_asm_include.rs
tests/codegen/global_asm_x2.rs
tests/ui/asm/*
```

After:
```
tests/assembly/asm/*
tests/codegen/asm/*
tests/ui/asm/*
```

I moved the remaining standalone test files into the asm directory, and then either removed the "asm-" suffix or for x86-specific registers tests replaced the "asm-" suffix with the "x86-" suffix.

(Then I noticed that there is no test for clobber_abi for already stabilized aarch64, arm, riscv, and loongarch64 asm... I don't believe there is a problem like https://github.com/rust-lang/rust/pull/131332, but I plan to add tests for them later.)

r? ``@Amanieu``

``@rustbot`` label +A-inline-assembly
2024-11-02 03:08:56 +08:00
Guillaume Gomez
e9e7aa8487
Rollup merge of #132448 - chengehe:master, r=Noratrieb
Add missing backtick
2024-11-02 03:08:54 +08:00
Guillaume Gomez
2896483320
Rollup merge of #132439 - tgross35:f16-f128-nan-lint, r=jieyouxu
Add `f16` and `f128` to `invalid_nan_comparison`

Currently `f32_nan` and `f64_nan` are used to provide the `invalid_nan_comparison` lint. Since we have `f16_nan` and `f128_nan`, hook these up so the new float types get the same lints.
2024-11-02 03:08:52 +08:00
Guillaume Gomez
e31a5ca1a3
Rollup merge of #132383 - compiler-errors:never-type-fallback-sugg, r=WaffleLapkin
Implement suggestion for never type fallback lints

r? ```@WaffleLapkin```

Just opening this up for vibes; it's not done yet. I'd still like to make this suggestable in a few more cases before merge:
- [x] Try to annotate `_` -> `()`
- [x] Try to annotate local variables if they're un-annotated: `let x = ...` -> `let x: () = ...`
- [x] Try to annotate the self type of a `Trait::method()` -> `<() as Trait>::method()`.

The only other case we may want to suggest is a missing turbofish, like `f()` -> `f::<()>()`. That may be possible, but seems overly annoying.

This partly addresses https://github.com/rust-lang/rust/issues/132358; the other half of fixing that would be to make the error message a bit better, perhaps just special casing the `?` operator 🤔 I don't think I'll do that part.
2024-11-02 03:08:51 +08:00
Guillaume Gomez
526c67f37b
Rollup merge of #131829 - Zalathar:goodbye-zprofile, r=chenyukang
Remove support for `-Zprofile` (gcov-style coverage instrumentation)

Tracking issue: #42524

MCP: https://github.com/rust-lang/compiler-team/issues/798

---

This PR removes the unstable `-Zprofile` flag, which enables ”gcov-style” coverage instrumentation, along with its associated `-Zprofile-emit` configuration flag.

(The profile flag predates and is almost entirely separate from the stable `-Cinstrument-coverage` flag.)

Notably, the `-Zprofile` flag:
- Is largely untested in-tree, having only one run-make test that does not check whether its output is correct or useful.
- Has no known maintainer.
- Has seen no push towards stabilization.
- Has at least one severe regression reported in 2022 that apparently remains unaddressed.
  - #100125
- Is confusingly named, since it appears to be more about coverage than performance profiling, and has nothing to do with PGO.
- Is fundamentally limited by relying on counters auto-inserted by LLVM, with no knowledge of Rust beyond debuginfo.
2024-11-02 03:08:49 +08:00
Michael Goulet
57f2e12f4a Completely deny calling functions with const conditions in MIR const check unless const_trait_impl is enabled
This will help us make sure that we never leak any conditionally const
functions into stable.
2024-11-01 16:13:30 +00:00
Michael Goulet
e319838e8d Double-check conditional constness in MIR
To prevent any conditional constness from leaking through during MIR lowering
2024-11-01 16:03:52 +00:00
Taiki Endo
96e7eaf478 Move remaining inline assembly test files into asm directory 2024-11-01 22:12:55 +09:00
chengehe
5342eb0597
Add missing backtick 2024-11-01 16:53:36 +08:00
Trevor Gross
3afbe4f9c7 Add f16 and f128 to invalid_nan_comparison
Currently `f32_nan` and `f64_nan` are used to provide the
`invalid_nan_comparison` lint. Since we have `f16_nan` and `f128_nan`,
hook these up so the new float types get the same lints.
2024-10-31 21:26:36 -05:00
Michael Goulet
df6f5841e5 And also suggest for qpaths 2024-11-01 01:46:23 +00:00
Michael Goulet
c930bba283 And locals too 2024-11-01 01:46:23 +00:00
Michael Goulet
ea4fb7c25c Suggest adding self type to method 2024-11-01 01:46:23 +00:00
Michael Goulet
41966e71bc Suggest annotations for never type fallback 2024-11-01 01:46:23 +00:00
Jubilee
6b0c8cfedc
Rollup merge of #132357 - m-ou-se:explicit-abi, r=compiler-errors
Improve missing_abi lint

This is for the migration lint for https://github.com/rust-lang/rfcs/pull/3722

It is not yet marked as an edition migration lint, because `Edition2027` doesn't exist yet.

The lint now includes a machine applicable suggestion:

```
warning: extern declarations without an explicit ABI are deprecated
 --> src/main.rs:3:1
  |
3 | extern fn a() {}
  | ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
  |
```
2024-10-31 17:50:41 -07:00
Jubilee
e31988cfc9
Rollup merge of #132209 - compiler-errors:modifiers, r=fmease
Fix validation when lowering `?` trait bounds

Pass the unlowered (`rustc_hir`) polarity to `lower_poly_trait_ref`.

This allows us to actually *validate* that generic args are actually valid on `?Trait` paths. This actually regressed in #113671 because that PR changed the behavior where we were inadvertently re-lowering paths as `BoundPolarity::Positive`, which was also coincidentally the only place we were enforcing the generics on `?Trait` paths were correct.
2024-10-31 17:50:40 -07:00
Jubilee
a43492b884
Rollup merge of #131168 - madsmtm:target-info-psx-os, r=davidtwco
Fix `target_os` for `mipsel-sony-psx`

Previously set to `target_os = "none"` and `target_env = "psx"` in [the PR introducing the target](https://github.com/rust-lang/rust/pull/102689/), but although the Playstation 1 is _close_ to a bare metal target in some regards, it's still very much an operating system, so we should instead set `target_os = "psx"`.

This also matches the `mipsel-sony-psp` target, which sets `target_os = "psp"`.

CC target maintainer ``@ayrtonm.``

If there's any code out there that uses `cfg(target_env = "psx")`, they can use `cfg(any(target_os = "psx", target_env = "psx"))` until they bump their MSRV to a version where this is fully fixed.
2024-10-31 17:50:40 -07:00
bors
a0d98ff0e5 Auto merge of #132356 - jieyouxu:unsound-simplify_aggregate_to_copy, r=cjgillot,DianQK
Mark `simplify_aggregate_to_copy` mir-opt as unsound

Mark the `simplify_aggregate_to_copy` mir-opt added in #128299 as unsound as it seems to miscompile the MCVE reported in https://github.com/rust-lang/rust/issues/132353. The mir-opt can be re-enabled once this case is fixed.

```rs
fn pop_min(mut score2head: Vec<Option<usize>>) -> Option<usize> {
    loop {
        if let Some(col) = score2head[0] {
            score2head[0] = None;
            return Some(col);
        }
    }
}

fn main() {
    let min = pop_min(vec![Some(1)]);
    println!("min: {:?}", min);
    // panic happens here on beta in release mode
    // but not in debug mode
    min.unwrap();
}
```

This MCVE is included as a `run-pass` ui regression test in the first commit. I built the ui test with a nightly manually, and can reproduce the behavioral difference with `-C opt-level=0` and `-C opt-level=1`. Locally, this ui test will fail unless it was run on a compiler built with the second commit marking the mir-opt as unsound thus disabling it by default.

This PR **partially reverts** commit e7386b3, reversing changes made to 02b1be1. The mir-opt implementation is just marked as unsound but **not** reverted to make reland reviews easier. Test changes are **reverted if they were not pure additions**. Tests added by the original PR received `-Z unsound-mir-opts` compile-flags.

cc `@DianQK` `@cjgillot` (PR author and reviewer of #128299)
2024-10-31 15:29:14 +00:00
许杰友 Jieyou Xu (Joe)
adb6d4752f tests: use minicore in tests/ui/abi/compatibility.rs as an example 2024-10-31 18:20:11 +08:00
许杰友 Jieyou Xu (Joe)
0bbe07e8ff tests/ui: add minicore compiletest self-test 2024-10-31 18:20:11 +08:00
许杰友 Jieyou Xu (Joe)
a8b34f58cf tests/codegen: add minicore compiletest self-test 2024-10-31 18:20:11 +08:00
许杰友 Jieyou Xu (Joe)
b115a22828 tests/assembly: add minicore compiletest self-test
Check that `minicore` cannot be used with `run-{pass,fail}` tests.
2024-10-31 18:20:11 +08:00
许杰友 Jieyou Xu (Joe)
82c2e42894 minicore: add minimal minicore test auxiliary
The initial `minicore` is intentionally super minimal and contains an
incomplete subset of `core` items, and explicitly not items from `alloc`
or `std`-only items.
2024-10-31 18:20:11 +08:00
Mara Bos
a433ea2518 Update tests. 2024-10-31 10:55:45 +01:00
bors
4d296eabe4 Auto merge of #132384 - matthiaskrgr:rollup-0ze5wc4, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #132347 (Remove `ValueAnalysis` and `ValueAnalysisWrapper`.)
 - #132365 (pass `RUSTC_HOST_FLAGS` at once without the for loop)
 - #132366 (Do not enforce `~const` constness effects in typeck if `rustc_do_not_const_check`)
 - #132376 (Annotate `input` reference tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-31 06:22:57 +00:00
许杰友 Jieyou Xu (Joe)
cfb4c05d77 Add a mir-opt GVN test for #128299
Co-authored-by: DianQK <dianqk@dianqk.net>
2024-10-31 13:48:35 +08:00
许杰友 Jieyou Xu (Joe)
10b8ba4ecb Mark simplify_aggregate_to_copy mir-opt as unsound
Co-authored-by: DianQK <dianqk@dianqk.net>
2024-10-31 13:48:06 +08:00
许杰友 Jieyou Xu (Joe)
4d8bda335e Add a regression test for #132353
To catch at least one pattern that was miscompiled. The test is a
minimization of the MCVE reported in
<https://github.com/rust-lang/rust/issues/132353>.
2024-10-31 13:12:22 +08:00
Matthias Krüger
49a76c14c4
Rollup merge of #132376 - ehuss:reference-input, r=traviscross
Annotate `input` reference tests

This adds test annotations for rules in the [input chapter](https://doc.rust-lang.org/nightly/reference/input-format.html) of the reference.
2024-10-31 06:11:58 +01:00
Matthias Krüger
39086e4290
Rollup merge of #132366 - compiler-errors:do-not-const-check, r=fee1-dead
Do not enforce `~const` constness effects in typeck if `rustc_do_not_const_check`

Fixes a slight inconsistency between HIR and MIR enforcement of `~const` :D

r? `@rust-lang/project-const-traits`
2024-10-31 06:11:58 +01:00
bors
c8b83785dc Auto merge of #131186 - compiler-errors:precise-capturing-borrowck, r=estebank
Try to point out when edition 2024 lifetime capture rules cause borrowck issues

Lifetime capture rules in 2024 are modified to capture more lifetimes, which sometimes lead to some non-local borrowck errors. This PR attempts to link these back together with a useful note pointing out the capture rule changes.

This is not a blocking concern, but I'd appreciate feedback (though, again, I'd like to stress that I don't want to block this PR on this): I'm worried about this note drowning in the sea of other diagnostics that borrowck emits. I was tempted to change the level of the note to `.span_warn` just so it would show up in a different color. Thoughts?

Fixes #130545

Opening as a draft first since it's stacked on #131183.
r? `@ghost`
2024-10-31 03:36:06 +00:00
Michael Goulet
c1457798db Try to point out when edition 2024 lifetime capture rules cause borrowck issues 2024-10-31 01:35:14 +00:00
bors
75eff9a574 Auto merge of #132377 - matthiaskrgr:rollup-3p1c6hs, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #132368 (Remove `do_not_const_check` from `Iterator` methods)
 - #132373 (Make sure `type_param_predicates` resolves correctly for RPITIT)
 - #132374 (Remove dead code stemming from the old effects desugaring)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-31 00:46:22 +00:00
Matthias Krüger
efd5645e43
Rollup merge of #132373 - compiler-errors:rpitit-bound, r=fmease
Make sure `type_param_predicates` resolves correctly for RPITIT

After #132194, we end up lowering the item bounds for an RPITIT in an `ItemCtxt` whose def id is the *synthetic GAT*, not the opaque type from the HIR.

This means that when we're resolving a shorthand projection like `T::Assoc`, we call the `type_param_predicates` function with the `item_def_id` of the *GAT* and not the opaque. That function operates on the HIR, and is not designed to work with the `Node::Synthetic` that gets fed for items synthesized by the compiler...

This PR reuses the trick we use elsewhere in lowering, where we intercept whether an item comes from RPITIT lowering, and forwards the query off to the correct item.

Fixes #132372
2024-10-31 01:14:03 +01:00
Michael Goulet
06a49b609f Validate associated type bounds on ? 2024-10-31 00:09:52 +00:00
Eric Huss
37c3884152 Annotate input reference tests 2024-10-30 16:47:47 -07:00
Michael Goulet
e356279bdf Actually do validation for poly trait refs with ? modifier 2024-10-30 23:42:50 +00:00
Michael Goulet
d53ca63453 Make sure type_param_predicates resolves correctly for RPITIT 2024-10-30 22:30:28 +00:00
Zalathar
ce3e14a448 Remove support for -Zprofile (gcov-style coverage instrumentation) 2024-10-31 09:09:25 +11:00
Jubilee
847b6fe6b0
Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errors
Rename `rustc_abi::Abi` to `BackendRepr`

Remove the confabulation of `rustc_abi::Abi` with what "ABI" actually means by renaming it to `BackendRepr`, and rename `Abi::Aggregate` to `BackendRepr::Memory`. The type never actually represented how things are passed, as that has to have `PassMode` considered, at minimum, but rather it just is how we represented some things to the backend. This conflation arose because LLVM, the primary backend at the time, would lower certain IR forms using certain ABIs. Even that only somewhat was true, as it broke down when one ventured significantly afield of what is described by the System V AMD64 ABI either by using different architectures, ABI-modifying IR annotations, the same architecture **with different ISA extensions enabled**, or other... unexpected delights.

Unfortunately both names are still somewhat of a misnomer right now, as people have written code for years based on this misunderstanding. Still, their original names are even moreso, and for better or worse, this backend code hasn't received as much maintenance as the rest of the compiler, lately. Actually arriving at a correct end-state will simply require us to disentangle a lot of code in order to fix, much of it pointlessly repeated in several places. Thus this is not an "actual fix", just a way to deflect further misunderstandings.
2024-10-30 14:01:37 -07:00
Jubilee
62ba25de39
Rollup merge of #132210 - notriddle:notriddle/doctest-span-hack, r=GuillaumeGomez
rustdoc: make doctest span tweak a 2024 edition change

Fixes #132203

This is a compatibility hack, because I think the new behavior is better. When an A `include_str!` B, and B `include_str!` C, the path to C should be resolved relative to B, not A. That's how `include!` itself works, so that's how `include_str!` with should work.
2024-10-30 14:01:37 -07:00
Jubilee
6b60f03f15
Rollup merge of #129383 - cjgillot:opaque-noremap, r=compiler-errors,petrochenkov
Remap impl-trait lifetimes on HIR instead of AST lowering

Current AST->HIR lowering goes out of its way to remap lifetimes for opaque types. This is complicated and leaks into upstream and downstream code.

This PR stops trying to be clever during lowering, and prefers to do this remapping during the HIR->ty lowering. The remapping computation easily fits into the bound var resolution code. Its result can be used in by `generics_of` and `hir_ty_lowering::new_opaque` to add the proper parameters and arguments.

See an example on the doc for query `opaque_captured_lifetimes`.

Based on https://github.com/rust-lang/rust/pull/129244/

Fixes https://github.com/rust-lang/rust/issues/125249
Fixes https://github.com/rust-lang/rust/issues/126850

cc `@compiler-errors` `@spastorino`
r? `@petrochenkov`
2024-10-30 14:01:36 -07:00
Michael Howell
ac7de1a0d9 Ignore Windows due to its differing path syntax 2024-10-30 12:39:05 -07:00
Michael Goulet
ec033e5bf1 Do not enforce ~const constness effects in typeck if rustc_do_mot_const_check 2024-10-30 17:41:09 +00:00
Camille GILLOT
2d74d8f333 Actually capture all in-scope lifetimes. 2024-10-30 16:22:23 +00:00