Commit Graph

33052 Commits

Author SHA1 Message Date
Nicholas Nethercote
46f4983356 Adjust the has_errors* methods.
Currently `has_errors` excludes lint errors. This commit changes it to
include lint errors.

The motivation for this is that for most places it doesn't matter
whether lint errors are included or not. But there are multiple places
where they must be includes, and only one place where they must not be
included. So it makes sense for `has_errors` to do the thing that fits
the most situations, and the new `has_errors_excluding_lint_errors`
method in the one exceptional place.

The same change is made for `err_count`. Annoyingly, this requires the
introduction of `err_count_excluding_lint_errs` for one place, to
preserve existing error printing behaviour. But I still think the change
is worthwhile overall.
2024-02-22 08:03:47 +11:00
Nicholas Nethercote
9919c3dab3 Remove EarlyDiagCtxt::abort_if_errors.
Its one use isn't necessary, because it's not possible for errors to
have been emitted at that point.
2024-02-22 08:03:47 +11:00
Nicholas Nethercote
203b4332bb Remove dead expect_error_or_delayed_bug method. 2024-02-22 08:03:47 +11:00
Nicholas Nethercote
1e16927ef3 Remove an out-of-date comment. 2024-02-22 08:03:39 +11:00
León Orell Valerian Liehr
bd7ba278e5
Rollup merge of #121396 - RalfJung:mir-const-value-inspect, r=oli-obk
make it possible for outside crates to inspect a mir::ConstValue with the interpreter

For MiniRust we need to convert MIR constant values into MiniRust constant values. However, it's not currently possible to get nice high-level access to the inerts of a `ConstValue`: we can access the raw contents (the allocation / `ScalarInt`), but if it is e.g. of enum type and we want to determine which variant is encoded, we are stuck. There's only `try_destructure_mir_constant_for_user_output` which is meant for diagnostics, so it doesn't fit.

The interpreter has all the APIs to traverse such a value, so we just need a way to get such a ConstValue into an interpreter instance. This adds the public functions necessary to make that happen.
2024-02-21 16:33:00 +01:00
León Orell Valerian Liehr
ae01e99831
Rollup merge of #121379 - nnethercote:rm-unchecked_error_guaranteed, r=oli-obk
Remove an `unchecked_error_guaranteed` call.

If we abort immediately after complaining about the obsolete `impl Trait for ..` syntax, then we avoid reaching HIR lowering. This means we can use `TyKind::Dummy` instead of `TyKind::Err`.

r? `@oli-obk`
2024-02-21 16:32:59 +01:00
León Orell Valerian Liehr
ef14c17fe1
Rollup merge of #121366 - nnethercote:rm-diagnostic_builder.rs, r=compiler-errors
Remove `diagnostic_builder.rs`

#120576 moved a big chunk of `DiagnosticBuilder`'s functionality out of `diagnostic_builder.rs` into `diagnostic.rs`, which left `DiagnosticBuilder` spread across the two files.

This PR fixes that messiness by merging what remains of `diagnostic_builder.rs` into `diagnostic.rs`.

This is part of https://github.com/rust-lang/compiler-team/issues/722.

r? `@davidtwco`
2024-02-21 16:32:59 +01:00
León Orell Valerian Liehr
8d27fc86f2
Rollup merge of #121359 - lcnr:typesystem-cleanup, r=compiler-errors
miscellaneous type system improvements

see review comments for rationale

r? `@compiler-errors`
2024-02-21 16:32:58 +01:00
León Orell Valerian Liehr
4daa43aaff
Rollup merge of #121175 - Nadrieril:simplify-or-selection, r=matthewjasper
match lowering: test one or pattern at a time

This is a bit more opinionated than the previous PRs. On the face of it this is less efficient and more complex than before, but I personally found the loop that digs into `leaf_candidates` on each iteration very confusing. Instead this does "generate code for this or-pattern" then "generate further code for each branch if needed" in two steps.

Incidentally this way we don't _require_ or patterns to be sorted at the end. It's still an important optimization but I find it clearer to not rely on it for correctness.

r? `@matthewjasper`
2024-02-21 16:32:57 +01:00
León Orell Valerian Liehr
082b97ad05
Rollup merge of #121044 - compiler-errors:mbe-async-trait-bounds, r=fmease
Support async trait bounds in macros

r? fmease

This is similar to your work on const trait bounds. This theoretically regresses `impl async $ident:ident` in macros, but I doubt this is occurring in practice.
2024-02-21 16:32:56 +01:00
Ralf Jung
9eabdc2a4c make it possible for outside crates to inspect a mir::ConstValue with the interpreter 2024-02-21 14:32:52 +01:00
bors
1d447a9946 Auto merge of #121383 - Dylan-DPC:rollup-735p4u4, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #121208 (Convert `delayed_bug`s to `bug`s.)
 - #121288 (make rustc_expand translatable)
 - #121304 (Add docs for extension proc-macro)
 - #121328 (Make --verbose imply -Z write-long-types-to-disk=no)
 - #121338 (Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect)
 - #121361 (diagnostic items for legacy numeric modules)
 - #121375 (Print proper relative path for descriptive name check)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-21 12:09:22 +00:00
Nadrieril
c1514a6324 Test one or pattern at a time 2024-02-21 11:35:44 +01:00
Nadrieril
780beda83c Tweak block management 2024-02-21 11:25:11 +01:00
bors
bb8b11e67d Auto merge of #120718 - saethlin:reasonable-fast-math, r=nnethercote
Add "algebraic" fast-math intrinsics, based on fast-math ops that cannot return poison

Setting all of LLVM's fast-math flags makes our fast-math intrinsics very dangerous, because some inputs are UB. This set of flags permits common algebraic transformations, but according to the [LangRef](https://llvm.org/docs/LangRef.html#fastmath), only the flags `nnan` (no nans) and `ninf` (no infs) can produce poison.

And this uses the algebraic float ops to fix https://github.com/rust-lang/rust/issues/120720

cc `@orlp`
2024-02-21 09:43:33 +00:00
Dylan DPC
e10b3b88b4
Rollup merge of #121338 - jieyouxu:ambiguous_wide_pointer_comparisons_suggestion, r=Nadrieril
Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect

In certain cases like #121330, it is possible to have more than one suggestion from the `ambiguous_wide_pointer_comparisons` lint (which before this PR are `MachineApplicable`). When this gets passed to rustfix, rustfix makes *multiple* changes according to the suggestions which result in incorrect code.

This is a temporary workaround. The real long term solution to problems like these is to address <https://github.com/rust-lang/rust/issues/53934>.

This PR also includes a drive-by edit to the panic message emitted by compiletest because "ui" test suite now uses `//`@`` directives.

Fixes #121330.
2024-02-21 08:55:58 +00:00
Dylan DPC
4a205bba5e
Rollup merge of #121328 - ffmancera:ff/verbose_long_type, r=compiler-errors
Make --verbose imply -Z write-long-types-to-disk=no

When shortening the type it is necessary to take into account the `--verbose` flag, if it is activated, we must always show the entire type and not write it in a file.

Fixes: https://github.com/rust-lang/rust/issues/119130
2024-02-21 08:55:57 +00:00
Dylan DPC
94e459f1a9
Rollup merge of #121304 - compiler-errors:ext, r=nnethercote
Add docs for extension proc-macro

r? nnethercote
2024-02-21 08:55:57 +00:00
Dylan DPC
4840785cf8
Rollup merge of #121288 - tshepang:make-expand-translatable, r=michaelwoerister
make rustc_expand translatable

these are the last of the easy ones
2024-02-21 08:55:56 +00:00
Dylan DPC
d5206c6ecd
Rollup merge of #121208 - nnethercote:delayed_bug-to-bug, r=lcnr
Convert `delayed_bug`s to `bug`s.

I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment.

I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit.

This is too dangerous to merge. Increased coverage (fuzzing or a crater run) would likely hit more cases. But it might be useful for people to look at and think about which paths are genuinely unreachable.

r? `@ghost`
2024-02-21 08:55:56 +00:00
bors
7168c13579 Auto merge of #120588 - alexcrichton:wasm-rmeta-object, r=wesleywiser,bjorn3
wasm: Store rlib metadata in wasm object files

The goal of this commit is to remove warnings using LLVM tip-of-tree `wasm-ld`. In llvm/llvm-project#78658 the `wasm-ld` LLD driver no longer looks at archive indices and instead looks at all the objects in archives. Previously `lib.rmeta` files were simply raw rustc metadata bytes, not wasm objects, meaning that `wasm-ld` would emit a warning indicating so.

WebAssembly targets previously passed `--fatal-warnings` to `wasm-ld` by default which meant that if Rust were to update to LLVM 18 then all wasm targets would not work. This immediate blocker was resolved in rust-lang/rust#120278 which removed `--fatal-warnings` which enabled a theoretical update to LLVM 18 for wasm targets. This current state is ok-enough for now because rustc squashes all linker output by default if it doesn't fail. This means, for example, that rustc squashes all the linker warnings coming out of `wasm-ld` about `lib.rmeta` files with LLVM 18. This again isn't a pressing issue because the information is all hidden, but it runs the risk of being annoying if another linker error were to happen and then the output would have all these unrelated warnings that couldn't be fixed.

Thus, this PR comes into the picture. The goal of this PR is to resolve these warnings by using the WebAssembly object file format on wasm targets instead of using raw rustc metadata. When I first implemented the rlib-in-objects scheme in #84449 I remember either concluding that `wasm-ld` would either include the metadata in the output or I thought we didn't have to do anything there at all. I think I was wrong on both counts as `wasm-ld` does not include the metadata in the final output unless the object is referenced and we do actually need to do something to resolve these warnings.

This PR updates the object file format containing rustc metadata on WebAssembly targets to be an actual WebAssembly file. To avoid bringing in any new dependencies I've opted to hand-code this encoding at this time. If the object gets more complicated though it'd probably be best to pull in `wasmparser` and `wasm-encoder`. For now though there's two adjacent functions reading/writing wasm.

The only caveat I know of with this is that if `wasm-ld` does indeed look at the object file then the metadata will be included in the final output. I believe the only thing that could cause that at this time is `--whole-archive` which I don't think is passed for rlibs. I would clarify that I'm not 100% certain about this, however.
2024-02-21 07:14:52 +00:00
Nicholas Nethercote
09ca866738 Remove an unchecked_error_guaranteed call.
If we abort immediately after complaining about the obsolete `impl Trait
for ..` syntax, then we avoid reaching HIR lowering. This means we can
use `TyKind::Dummy` instead of `TyKind::Err`.
2024-02-21 17:02:30 +11:00
Michael Goulet
62e7414a19 Docs for extension proc-macro 2024-02-21 05:32:08 +00:00
bors
096598dc79 Auto merge of #121172 - Nadrieril:simplify-empty-selection, r=matthewjasper
match lowering: simplify empty candidate selection

In match lowering, `match_simplified_candidates` is tasked with removing candidates that are fully matched and linking them up properly. The code that does that was needlessly complicated; this PR simplifies it.

The overall change isn't big but I split it up into tiny commits to convince myself that I was correctly preserving behavior. The test changes are all due to the first commit. Let me know if you'd prefer me to split up the PR to make reviewing easier.

r? `@matthewjasper`
2024-02-21 03:11:24 +00:00
bors
4e65074933 Auto merge of #120904 - Nadrieril:match-lowering-intermediate-repr, r=matthewjasper
match lowering: eagerly simplify match pairs

This removes one important complication from match lowering. Before this, match pair simplification (which includes collecting bindings and type ascriptions) was intertwined with the whole match lowering algorithm.

I'm avoiding this by storing in each `MatchPair` the sub-`MatchPair`s that correspond to its subfields. This makes it possible to simplify everything (except or-patterns) in `Candidate::new()`.

This should open up further simplifications. It will also give us proper control over the order of bindings.

r? `@matthewjasper`
2024-02-21 01:11:34 +00:00
Nicholas Nethercote
1407057b16 Remove some no-longer-needed pub(crate) markers. 2024-02-21 11:03:33 +11:00
Nicholas Nethercote
8f20a54c6d Merge diagnostic_builder.rs into diagnostic.rs.
Because:
- `diagnostic_builder.rs` is small (282 lines),
- `Diagnostic` and `DiagnosticBuilder` are closely related types, and
- there's already an `impl DiagnosticBuilder` block in `diagnostic.rs`.

At the same time, reorder a few of things already in `diagnostic.rs`,
e.g. move `struct Diagnostic` just before `impl Diagnostic`.

This commit only moves code around. There are no functional changes.
2024-02-21 11:03:31 +11:00
Nicholas Nethercote
2903bbbc15 Convert bugs back to delayed_bugs.
This commit undoes some of the previous commit's mechanical changes,
based on human judgment.
2024-02-21 10:35:54 +11:00
Nicholas Nethercote
010f3944e0 Convert delayed_bugs to bugs.
I have a suspicion that quite a few delayed bug paths are impossible to
reach, so I did an experiment.

I converted every `delayed_bug` to a `bug`, ran the full test suite,
then converted back every `bug` that was hit. A surprising number were
never hit.

The next commit will convert some more back, based on human judgment.
2024-02-21 10:20:05 +11:00
Fernando Fernandez Mancera
e35481f90b Suggest using --verbose when writing type to a file 2024-02-20 23:48:59 +01:00
lcnr
5fb67e2ad4 some type system cleanup 2024-02-20 20:42:10 +01:00
Matthias Krüger
433180e0cb
Rollup merge of #121350 - compiler-errors:resolve, r=oli-obk
Fix stray trait mismatch in `resolve_associated_item` for `AsyncFn`

Copy-paste error meant that we were calling `fn_trait_kind_from_def_id` instead of `async_fn_trait_kind_from_def_id`. But turns out we don't even need to do that, since we already matched the trait def id above.

Fixes #121306

r? oli-obk
2024-02-20 19:35:42 +01:00
Matthias Krüger
532b3eacb7
Rollup merge of #121344 - fmease:lta-constr-by-input, r=oli-obk
Expand weak alias types before collecting constrained/referenced late bound regions + refactorings

Fixes #114220.
Follow-up to #120780.

r? `@oli-obk`
2024-02-20 19:35:41 +01:00
Matthias Krüger
e3ff2a8e38
Rollup merge of #121323 - compiler-errors:raw-param-types, r=oli-obk
Don't use raw parameter types in `find_builder_fn`

We shouldn't really ever be using `EarlyBinder::skip_binder` then performing type equality, since param types will never be equal to other types. When checking compatibility with the signature, we instead create some fresh args.

Fixes #121314
2024-02-20 19:35:41 +01:00
Matthias Krüger
d43fd29bf2
Rollup merge of #121322 - compiler-errors:next-solver-fulfillment-ice, r=lcnr
Don't ICE when hitting overflow limit in fulfillment loop in next solver

As the title says, let's not ICE when hitting the overflow limit in fulfill. On the other hand, we don't want to treat these as true errors, since it means that whether something is considered a true error or an ambiguity is dependent on overflow handling in the solver, which seems not worth it.

Now that we use the presence of true errors in fulfillment for implicit negative coherence, we especially don't want to tie together coherence and overflow.

I guess I could also drain these errors out of fulfillment and put them into some `ambiguities` storage so we could return them in `select_all_or_error` without having to re-process them every time we call `select_where_possible`. Let me know if that's desired.

r? lcnr
2024-02-20 19:35:40 +01:00
Ben Kimock
cc73b71e8e Add "algebraic" versions of the fast-math intrinsics 2024-02-20 12:39:03 -05:00
Alex Crichton
6181f3a566 wasm: Store rlib metadata in wasm object files
The goal of this commit is to remove warnings using LLVM tip-of-tree
`wasm-ld`. In llvm/llvm-project#78658 the `wasm-ld` LLD driver no longer
looks at archive indices and instead looks at all the objects in
archives. Previously `lib.rmeta` files were simply raw rustc metadata
bytes, not wasm objects, meaning that `wasm-ld` would emit a warning
indicating so.

WebAssembly targets previously passed `--fatal-warnings` to `wasm-ld` by
default which meant that if Rust were to update to LLVM 18 then all wasm
targets would not work. This immediate blocker was resolved in
rust-lang/rust#120278 which removed `--fatal-warnings` which enabled a
theoretical update to LLVM 18 for wasm targets. This current state is
ok-enough for now because rustc squashes all linker output by default if
it doesn't fail. This means, for example, that rustc squashes all the
linker warnings coming out of `wasm-ld` about `lib.rmeta` files with
LLVM 18. This again isn't a pressing issue because the information is
all hidden, but it runs the risk of being annoying if another linker
error were to happen and then the output would have all these unrelated
warnings that couldn't be fixed.

Thus, this PR comes into the picture. The goal of this PR is to resolve
these warnings by using the WebAssembly object file format on wasm
targets instead of using raw rustc metadata. When I first implemented
the rlib-in-objects scheme in #84449 I remember either concluding that
`wasm-ld` would either include the metadata in the output or I thought
we didn't have to do anything there at all. I think I was wrong on both
counts as `wasm-ld` does not include the metadata in the final output
unless the object is referenced and we do actually need to do something
to resolve these warnings.

This PR updates the object file format containing rustc metadata on
WebAssembly targets to be an actual WebAssembly file. This enables the
`wasm` feature of the `object` crate to be able to read the custom
section in the same manner as other platforms, but currently `object`
doesn't support writing wasm object files so a handwritten encoder is
used instead.

The only caveat I know of with this is that if `wasm-ld` does indeed
look at the object file then the metadata will be included in the final
output. I believe the only thing that could cause that at this time is
`--whole-archive` which I don't think is passed for rlibs. I would
clarify that I'm not 100% certain about this, however.
2024-02-20 09:31:50 -08:00
许杰友 Jieyou Xu (Joe)
4d386d9f04
Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect
It is possible to have more than one valid suggestion, which when
applied together via rustfix causes the code to no longer compile.

This is a temporary workaround; the real long term solution to these
issues is to solve <https://github.com/rust-lang/rust/issues/53934>.
2024-02-20 17:21:01 +00:00
León Orell Valerian Liehr
f515f99e91
Move the peeling function for weak alias types 2024-02-20 17:32:01 +01:00
León Orell Valerian Liehr
1b3df6f068
Use expand_weak_alias_tys when collecting constrained generics params in impls 2024-02-20 17:31:59 +01:00
León Orell Valerian Liehr
da01cced15
Expand weak alias types before collecting constrained and referenced late bound regions 2024-02-20 17:31:54 +01:00
León Orell Valerian Liehr
515d805a0e
Introduce expand_weak_alias_tys 2024-02-20 17:31:49 +01:00
León Orell Valerian Liehr
05ce209d20
Rename some normalization-related items 2024-02-20 17:30:49 +01:00
Michael Goulet
9c8b107955 Support async trait bounds in macros 2024-02-20 16:09:09 +00:00
Nadrieril
a45d8925b8 Upgrade a debug_assert to assert 2024-02-20 16:53:16 +01:00
Michael Goulet
762febdaf3 Fix stray trait mismatch in resolve_associated_item for AsyncFn 2024-02-20 15:45:05 +00:00
Nilstrieb
d61adbffe1
Rollup merge of #121318 - kadiwa4:no_assembly_in_supposedly_safe_code, r=Nilstrieb
Trigger `unsafe_code` lint on invocations of `global_asm`

`unsafe_code` already warns about things that don't involve the `unsafe` keyword, e.g. `#[no_mangle]`. This makes it warn on `core::arch::global_asm` too.

Fixes #103078
2024-02-20 15:13:55 +01:00
Nilstrieb
5540d817e3
Rollup merge of #121291 - heiher:revert-medium-cmodel, r=Nilstrieb
target: Revert default to the medium code model on LoongArch targets

This reverts commit 35dad14dfb.

Fixes #121289
2024-02-20 15:13:54 +01:00
Nilstrieb
bc7489c546
Rollup merge of #121286 - gurry:constprop-lint-rename, r=oli-obk
Rename `ConstPropLint` to `KnownPanicsLint`

`OverflowLint` is a clearer name because it communicates what the lint does instead of the underlying mechanism it uses (const propagation) which should be of secondary concern.

`OverflowLint` isn't the most accurate name because the lint looks for other errors as well such as division by zero not just overflows, but I couldn't think of another equally succinct name.

As a part of this change. I've also added/updated some of the comments.

cc ```@RalfJung``` ```@oli-obk``` for visibility in case you go looking for the lint using the old name.

Edit:

Changed the name from `OverflowLint` to `KnownPanicsLint`
2024-02-20 15:13:53 +01:00
Nilstrieb
073d2983a4
Rollup merge of #121167 - petrochenkov:unload2, r=wesleywiser
resolve: Scale back unloading of speculatively loaded crates

Fixes https://github.com/rust-lang/rust/issues/120830 and fixes https://github.com/rust-lang/rust/issues/120909 while still unblocking https://github.com/rust-lang/rust/pull/117772.

I cannot reproduce https://github.com/parasyte/crash-rustc as an UI test for some reason, but I tested all the cases linked above manually.
2024-02-20 15:13:50 +01:00