Commit Graph

28098 Commits

Author SHA1 Message Date
David Tolnay
fe50c5359e
Update some more cases of "type" -> "$message_type" 2023-11-20 16:02:59 -08:00
Jeremy Fitzhardinge
8f0845862c Use $message_type as the tag
`type` turned out to be controversial.
2023-10-13 15:50:01 -07:00
Jeremy Fitzhardinge
00adbb2d5a Use serde_json::to_writer for JsonEmitter::emit
Avoids an unnecessary intermediate string.
2023-09-19 14:17:02 -07:00
Jeremy Fitzhardinge
62ad57b95a Make sure nested Diagnostics in FutureIncompat are also typed for consistency. 2023-09-19 14:17:02 -07:00
Jeremy Fitzhardinge
5c8170656b Add type field to json diagnostic outputs
Currently the json-formatted outputs have no way to unambiguously
determine which kind of message is being output. A consumer can look for
specific fields in the json object (eg "message"), but there's no
guarantee that in future some other kind of output will have a field of
the same name.

This PR adds a `"type"` field to add json outputs which can be used to
unambiguously determine which kind of output it is. The mapping is:

diagnostic: regular compiler diagnostics
artifact: artifact notifications
future_incompat: Report of future incompatibility
unused_extern: Unused crate warnings/errors

This matches the "internally tagged" representation for serde enums.
2023-09-19 14:17:02 -07:00
bors
ac5ac4754a Auto merge of #115979 - GuillaumeGomez:rollup-06ujzgh, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #113383 (style-guide: Add section on bugs, and resolving bugs)
 - #115499 (rustc_target/riscv: Fix passing of transparent unions with only one non-ZST member)
 - #115801 (Detect cycle errors hidden by opaques during monomorphization)
 - #115947 (Custom code classes in docs warning)
 - #115957 (fix mismatched symbols)
 - #115958 (explain mysterious addition in float minimum/maximum)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-19 18:52:10 +00:00
Guillaume Gomez
0060db74f9
Rollup merge of #115801 - compiler-errors:async-cycle-mono, r=oli-obk
Detect cycle errors hidden by opaques during monomorphization

Opaque types may reveal to projections, which themselves normalize to opaques. We don't currently normalize when checking that opaques are cyclical, and we may also not know that the opaque is cyclical until monomorphization (see `tests/ui/type-alias-impl-trait/mututally-recursive-overflow.rs`).

Detect cycle errors in `normalize_projection_ty` and report a fatal overflow (in the old solver). Luckily, this is already detected as a fatal overflow in the new solver.

Fixes #112047
2023-09-19 20:23:19 +02:00
Guillaume Gomez
edd7be59da
Rollup merge of #115499 - msizanoen1:riscv-fix-transparent-union-abi, r=bjorn3
rustc_target/riscv: Fix passing of transparent unions with only one non-ZST member

This ensures that `MaybeUninit<T>` has the same ABI as `T` when passed through an `extern "C"` function.

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

r? `@RalfJung`
2023-09-19 20:23:19 +02:00
bors
42f5828b01 Auto merge of #115627 - compiler-errors:icedump-no-std, r=m-ou-se
Don't modify libstd to dump rustc ICEs

Do a much simpler thing and just dump a `std::backtrace::Backtrace` to file.

r? `@estebank` `@oli-obk`

Fixes #115610
2023-09-19 16:56:25 +00:00
bors
0692db1a90 Auto merge of #115865 - RalfJung:mir-mod, r=oli-obk
move things out of mir/mod.rs

This moves a bunch of things out of `mir/mod.rs`:
- all const-related stuff to a new file consts.rs
- all statement/place/operand-related stuff to a new file statement.rs
- all pretty-printing related stuff to pretty.rs

`mod.rs` started out with 3100 lines and ends up with 1600. :)

Also there was some pretty-printing stuff in terminator.rs, that also got moved to pretty.rs, and I reordered things in pretty.rs so that it can be grouped by functionality.

Only the commit "use pretty_print_const_value from MIR constant 'extra' printing" has any behavior changes; it resolves the issue of having a fancy and a very crude pretty-printer for `ConstValue`.

r? `@oli-obk`
2023-09-19 13:22:48 +00:00
msizanoen
751ecde064 rustc_target/riscv: Fix passing of transparent unions with only one non-ZST member
This ensures that `MaybeUninit<T>` has the same ABI as `T` when passed
through an `extern "C"` function.

Fixes https://github.com/rust-lang/rust/issues/115481.
2023-09-19 12:06:33 +02:00
Guillaume Gomez
f1edecfaab
Rollup merge of #115924 - compiler-errors:non-exhaustive-1-zst, r=RalfJung
Don't complain on a single non-exhaustive 1-ZST

r? RalfJung, though you mentioned being busy, so feel free to reassign.

This doesn't actually attempt to make the diagnostic better, so when we have two non-exhaustive 1-ZSTs in a struct, we still just point to one. 🤷

Fixes #115922
2023-09-19 11:35:51 +02:00
Guillaume Gomez
c452090597
Rollup merge of #115625 - compiler-errors:hrtb-infer-err, r=b-naber
Explain HRTB + infer limitations of old solver

Add a helpful message when we hit the limitation of the old trait solver where we don't properly normalize GATs with infer vars + bound vars, leading to too-eagerly reporting trait errors that would be later satisfied due to inference.
2023-09-19 11:35:50 +02:00
Guillaume Gomez
66b7bdf279
Rollup merge of #114941 - compiler-errors:inline-shadowed-by-dyn, r=lcnr
Don't resolve generic impls that may be shadowed by dyn built-in impls

**NOTE:** This is a hack. This is not trying to be a general fix for the issue that we've allowed overlapping built-in trait object impls and user-written impls for quite a long time, and traits like `Any` rely on this (#57893) -- this PR specifically aims to mitigate a new unsoundness that is uncovered by the MIR inliner (#114928) that interacts with this pre-existing issue.

Builtin `dyn Trait` impls may overlap with user-provided blanket impls (`impl<T: ?Sized> Trait for T`) in generic contexts. This leads to bugs when instances are resolved in polymorphic contexts, since we typically prefer object candidates over impl candidates.

This PR implements a (hacky) heuristic to `resolve_associated_item` to account for that unfortunate hole in the type system -- we now bail with ambiguity if we try to resolve a non-rigid instance whose self type is not known to be sized. This makes sure we can still inline instances like `impl<T: Sized> Trait for T`, which can never overlap with `dyn Trait`'s built-in impl, but we avoid inlining an impl that may be shadowed by a `dyn Trait`.

Fixes #114928
2023-09-19 11:35:50 +02:00
Ralf Jung
d14e601661 comment on the difference between mir::ConstantKind::Unevaluated and mir::ConstantKind::Ty(ty::ConstKind::Unevaluated) 2023-09-19 11:11:03 +02:00
Ralf Jung
5a0a1ff0cd move ConstValue into mir
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-19 11:11:02 +02:00
Ralf Jung
be8f5f6e7f organize mir pretty.rs and move more things into it; move statement-related things out of mir/mod.rs 2023-09-19 11:06:32 +02:00
Ralf Jung
57444cf9f3 use pretty_print_const_value from MIR constant 'extra' printing 2023-09-19 11:06:32 +02:00
Ralf Jung
10a822be38 move some MIR const pretty-printing into pretty.rs 2023-09-19 11:06:32 +02:00
Ralf Jung
49f5b17cdb more MIR const types to separate file 2023-09-19 11:06:27 +02:00
Michael Goulet
fd36553aa7 Don't complain on a single non-exhaustive 1-zst 2023-09-19 06:01:24 +00:00
Michael Goulet
a30ad3a5a6 Don't resolve generic instances if they may be shadowed by dyn 2023-09-19 05:42:23 +00:00
Michael Goulet
976d377f7f Explain HRTB + infer limitations of old solver 2023-09-19 05:14:14 +00:00
bors
af78bae565 Auto merge of #115289 - compiler-errors:adjust-comments, r=estebank
Add some needed comments in `adjust_fulfillment_errors.rs`

r? `@estebank`
2023-09-19 03:52:48 +00:00
bors
19dd953540 Auto merge of #115644 - danakj:catalyst-asan, r=cjgillot,thomcc
Enable ASAN/LSAN/TSAN for *-apple-ios-macabi

The -macabi targets are iOS running on MacOS, and they use the runtime libraries for MacOS, thus they have the same sanitizers available as the *-apple-darwin targets.

This is based on the work of aacf3213b1.

Closes #113935.
2023-09-19 01:47:23 +00:00
Matthias Krüger
3cf5a6beaa
Rollup merge of #115930 - Zalathar:spans-bug, r=compiler-errors
coverage: Fix an unstable-sort inconsistency in coverage spans

This code was calling `sort_unstable_by`, but failed to impose a total order on the initial spans. That resulted in unpredictable handling of closure spans, producing inconsistencies in the coverage maps and in user-visible coverage reports.

This PR fixes the problem by always sorting closure spans before otherwise-identical non-closure spans, and also switches to a stable sort in case the ordering is still not total.

---

In addition to the fix itself, this PR also contains a cleanup to the comparison function that I was working on when I discovered the bug.
2023-09-19 01:29:42 +02:00
Matthias Krüger
970ee09c22
Rollup merge of #115879 - clubby789:migrate-hir-typeck-cast, r=compiler-errors
Migrate diagnostics in `hir_typeck/src/cast.rs`
2023-09-19 01:29:42 +02:00
Matthias Krüger
48c605129b
Rollup merge of #115873 - BoxyUwU:tykind_adt_debug, r=oli-obk
Make `TyKind::Adt`'s `Debug` impl be more pretty

Currently `{:?}` on `Ty` for a `TyKind::Adt` would print as `Adt(Foo, [])`. This PR changes it to be `Foo` when there are no generics or `Foo<T>`/`Foo<T, U>` when there _are_ generics. Example from debug log:
`├─0ms DEBUG rustc_hir_analysis::astconv return=Bar<T/#0, U/#1>`

I should have done this in my initial PR for a prettier TyKind: Debug impl but I thought I would need to be accessing generics_of to figure out where in the "path" the generics would have to go??? but no, adts literally only have a single place the generics can go (on the end). Feel a bit silly about this :)

r? `@oli-obk`
2023-09-19 01:29:41 +02:00
Matthias Krüger
0eec5e3d0c
Rollup merge of #115869 - ferrocene:pa-fix-tests-cargo-remap, r=compiler-errors
Avoid blessing cargo deps's source code in ui tests

Before this PR, the source code of dependencies was included in UI test error messages whenever possible. Unfortunately, "whenever possible" means in some cases the source code wouldn't be injected, resulting in a test failure.

One such case is when `$CARGO_HOME` is remapped to something that is not present on disk [^1]. As the remapped path doesn't exist on disk, the source code wouldn't be showed in `tests/ui/issues/issue-21763.rs`:

```diff
    = note: required for `hashbrown::raw::RawTable<(Rc<()>, Rc<()>)>` to implement `Send`
 note: required because it appears within the type `HashMap<Rc<()>, Rc<()>, RandomState>`
   --> $HASHBROWN_SRC_LOCATION
-   |
-LL | pub struct HashMap<K, V, S = DefaultHashBuilder, A: Allocator + Clone = Global> {
-   |            ^^^^^^^
 note: required because it appears within the type `HashMap<Rc<()>, Rc<()>>`
   --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
 note: required by a bound in `foo`
```

This PR fixes the problem by always hiding dependencies source code in the error messages generated during UI tests. This is implemented with a new internal flag, `-Z ignore-directory-in-diagnostics-source-blocks=$path`, which compiletest passes during UI tests. Once this is merged, remapping the Cargo home will be supported.

This PR is best reviewed commit-by-commit.

[^1]: After being puzzled for a bit, I discovered why this never impacted `rust-lang/rust`: we don't remap `$CARGO_HOME` 😅. Instead, we set `$CARGO_HOME` to `/cargo` in CI, which sort-of-but-not-really achieves the same effect.
2023-09-19 01:29:41 +02:00
bors
65ea825f40 Auto merge of #115940 - matthiaskrgr:rollup-5ps9ln1, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #109409 (Add `minmax{,_by,_by_key}` functions to `core::cmp`)
 - #115494 (get rid of duplicate primitive_docs)
 - #115663 (ci: actions/checkout@v3 to actions/checkout@v4)
 - #115762 (Explain revealing of opaque types in layout_of ParamEnv)
 - #115891 (simplify inject_impl_of_structural_trait)
 - #115932 (Expand infra-ci reviewer list)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-18 21:29:56 +00:00
bors
cebb9cfd4f Auto merge of #115748 - RalfJung:post-mono, r=oli-obk
move required_consts check to general post-mono-check function

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) https://github.com/rust-lang/rust/issues/115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? `@oli-obk`
2023-09-18 19:41:21 +00:00
Boxy
b2bf4b66f8 make more pretty 2023-09-18 17:29:13 +01:00
Matthias Krüger
864f7aafe4
Rollup merge of #115891 - RalfJung:structural-trait-derive, r=nnethercote
simplify inject_impl_of_structural_trait

There's a comment at `inject_impl_of_structural_trait` saying we cannot use `TraitDef`, but that comment is outdated -- we *can* use `TraitDef` nowadays since it has the `skip_path_as_bound` flag. (The flag needed some fixing, though.)
2023-09-18 18:27:20 +02:00
Oli Scherer
ee59531dfc Explain with_reveal_all_normalized usage 2023-09-18 15:17:52 +00:00
clubby789
9c5de75ce1 Migrate 'cast enum with drop to int' diagnostic 2023-09-18 14:07:05 +00:00
clubby789
80a9699117 Migrate 'trivial cast' lint 2023-09-18 14:07:05 +00:00
clubby789
82471e9f6c Migrate 'casting unknown pointer' diagnostic 2023-09-18 14:07:05 +00:00
clubby789
94920cc6e0 Migrate 'int to fat pointer' cast diagnostic 2023-09-18 14:07:03 +00:00
clubby789
c2841e2a1e Migrate 'cast to bool' diagnostic 2023-09-18 14:03:57 +00:00
clubby789
dcb3e70861 Migrate 'is_empty' diagnostics 2023-09-18 14:03:57 +00:00
clubby789
6496181208 Migrate 'lossy int2ptr cast' diagnostic 2023-09-18 14:03:57 +00:00
clubby789
bf693d1743 Migrate 'lossy ptr2int cast' diagnostic 2023-09-18 14:03:57 +00:00
danakj
4eb1b52794 Enable ASAN/LSAN/TSAN for *-apple-ios-macabi
The -macabi targets are iOS running on MacOS, and they use the runtime
libraries for MacOS, thus they have the same sanitizers available as the
*-apple-darwin targets.
2023-09-18 09:38:12 -04:00
Zalathar
01b67f4b26 coverage: Simplify sorting of coverage spans extracted from MIR
Switching to `Ordering::then_with` makes control-flow less complicated, and
there is no need to use `partial_cmp` here.
2023-09-18 23:15:25 +10:00
Zalathar
4690f97099 coverage: Fix an unstable-sort inconsistency in coverage spans
This code was calling `sort_unstable_by`, but failed to impose a total order on
the initial spans. That resulted in unpredictable handling of closure spans,
producing inconsistencies in the coverage maps and in user-visible coverage
reports.

This patch fixes the problem by always sorting closure spans before
otherwise-identical non-closure spans, and also switches to a stable sort in
case the ordering is still not total.
2023-09-18 21:28:56 +10:00
Matthias Krüger
c101c5fa50
Rollup merge of #115908 - cjgillot:lint-noclone, r=oli-obk
Do not clone MIR for const-prop lint.

Addresses https://github.com/rust-lang/rust/pull/115797#issuecomment-1721250533
2023-09-18 13:02:20 +02:00
Matthias Krüger
0d29cdd187
Rollup merge of #115907 - RalfJung:interner-check, r=compiler-errors
nop_lift macros: ensure that we are using the right interner

Right now someone could put down the wrong list name when using these macros, and everything would still build. Nothing does a type-check to ensure that the `$set` contains element of type `Self::Lifted`. Let's fix that.

For lists this is fairly easy; for the other interners we need to unwrap some newtypes which makes this more complicated.
2023-09-18 13:02:19 +02:00
Matthias Krüger
944c4134d2
Rollup merge of #115838 - lcnr:added-goals, r=compiler-errors
inspect: closer to proof trees for coherence

a continuation of #115751. Now explicitly store the added goals

r? ```@compiler-errors```
2023-09-18 13:02:18 +02:00
Ralf Jung
0522bde4bc simplify inject_impl_of_structural_trait 2023-09-18 07:45:46 +02:00
Nicholas Nethercote
abe2a68acd Remove more unused Lift impls. 2023-09-18 09:37:10 +10:00