Commit Graph

39580 Commits

Author SHA1 Message Date
Matthias Krüger
c52d58dce1
Rollup merge of #130496 - jder:issue-130400, r=compiler-errors
Fix circular fn_sig queries to correct number of args for methods

Fixes #130400. This was a [debug assert](28e8f01c2a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs (L2557)) added to some argument error reporting code in #129320 which verified that the number of params (from the HIR) matched the `matched_inputs` which ultimately come from ty::FnSig. In the reduced test case:

```
fn foo(&mut self) -> _ {
    foo()
}
```

There is a circular dependency computing the ty::FnSig -- when trying to compute it, we try to figure out the return value, which again depends on this ty::FnSig. In #105162, this was supported by short-circuiting the cycle by synthesizing a FnSig with error types for parameters. The [code in question](https://github.com/rust-lang/rust/pull/105162/files#diff-a65feec6bfffb19fbdc60a80becd1030c82a56c16b177182cd277478fdb04592R44) computes the number of parameters by taking the number of parameters from the hir::FnDecl and adding 1 if there is an implicit self parameter.

I might be missing a subtlety here, but AFAICT the adjustment for implicit self args is unnecessary and results in one too many args. For example, for this non-errorful code:

```
trait Foo {
    fn bar(&self) {}
}
```

The resulting hir::FnDecl and ty::FnSig both have the same number of inputs -- 1. So, this PR removes that adjustment and adds a test for the debug ICE.

r? `@compiler-errors`
2024-09-18 04:42:32 +02:00
Matthias Krüger
32c4d4112c
Rollup merge of #130489 - compiler-errors:raw-lt-lint, r=jieyouxu
Ensure that `keyword_ident` lint doesn't trigger on `'r#kw` lifetime

Fixes #130486
2024-09-18 04:42:31 +02:00
Matthias Krüger
09b255d3d4
Rollup merge of #130116 - veera-sivarajan:freeze-suggestions, r=chenyukang
Implement a Method to Seal `DiagInner`'s Suggestions

This PR adds a method on `DiagInner` called `.seal_suggestions()` to prevent new suggestions from being added while preserving existing suggestions.

This is useful because currently there is no way to prevent new suggestions from being added to a diagnostic. `.disable_suggestions()` is the closest but it gets rid of all suggestions before and after the call.

Therefore, `.seal_suggestions()` can be used when, for example, misspelled keyword is detected and reported. In such cases, we may want to prevent other suggestions from being added to the diagnostic, as they would likely be meaningless once the misspelled keyword is identified. For context: https://github.com/rust-lang/rust/pull/129899#discussion_r1741307132

To store an additional state, the type of the `suggestions` field in `DiagInner` was changed into a three variant enum. While this change affects files across different crates, care was taken to preserve the existing code's semantics. This is validated by the fact that all UI tests pass without any modifications.

r? chenyukang
2024-09-18 04:42:31 +02:00
Jesse Rusak
3cb1f334b8 Fix circular fn_sig queries to return the correct number of arguments for methods 2024-09-17 20:54:04 -04:00
Michael Goulet
5de89bb011 Store raw ident span for raw lifetime 2024-09-17 16:43:18 -04:00
bors
28e8f01c2a Auto merge of #130483 - matthiaskrgr:rollup-q1r0g0y, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #129477 (Fix fluent diagnostics)
 - #129674 (Add new_cyclic_in for Rc and Arc)
 - #130452 (Update Trusty target maintainers)
 - #130467 (Miri subtree update)
 - #130477 (Revert #129749 to fix segfault in LLVM)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-17 19:37:03 +00:00
Matthias Krüger
f8090dda64
Rollup merge of #130477 - tmandry:revert-llvm-20-lto, r=tmandry
Revert #129749 to fix segfault in LLVM

This reverts commit 8c7a7e346b, reversing changes made to a00bd75b6c.

Reported in https://github.com/rust-lang/rust/pull/129749#issuecomment-2354417960. `@nikic's` theory is that the LLVM API changed in a way that makes it impossible to use concurrently from multiple threads (https://github.com/llvm/llvm-project/pull/106427#issuecomment-2354783802). I pinged `@krasimirgg` who was fine with reverting.

r? `@rust-lang/wg-llvm`
2024-09-17 20:45:51 +02:00
Matthias Krüger
8b36ecba97
Rollup merge of #129477 - Xiretza:fix-fluent-diagnostics, r=compiler-errors
Fix fluent diagnostics

This line number calculation was both wrong and unnecessary.
2024-09-17 20:45:49 +02:00
Matthias Krüger
065690e186
Rollup merge of #130469 - compiler-errors:wc-obj-safety, r=jackh726
Mark `where_clauses_object_safety` as removed

r? lcnr
2024-09-17 17:28:35 +02:00
Matthias Krüger
d5a081981d
Rollup merge of #130458 - nnethercote:rustc_codegen_ssa-cleanups, r=jieyouxu
`rustc_codegen_ssa` cleanups

Just some minor improvements I found while reading through this code.

r? ``@jieyouxu``
2024-09-17 17:28:35 +02:00
Matthias Krüger
02b1776cd3
Rollup merge of #130440 - compiler-errors:rpitit-opaque-hidden, r=jieyouxu
Don't ICE in `opaque_hidden_inferred_bound` lint for RPITIT in trait with no default method body

Inline comment should explain the fix.

Fixes #130422
2024-09-17 17:28:34 +02:00
Matthias Krüger
c896f06bdb
Rollup merge of #130314 - compiler-errors:mac-prec, r=davidtwco
Use the same precedence for all macro-like exprs

No need to make these have a different precedence since they're all written like `whatever!(expr)`, and it makes it simpler when adding new macro-based built-in operators in the future.
2024-09-17 17:28:33 +02:00
Matthias Krüger
62f2ec9b59
Rollup merge of #130275 - compiler-errors:extern-crate, r=lcnr
Don't call `extern_crate` when local crate name is the same as a dependency and we have a trait error

#124944 implemented logic to point out when a trait bound failure involves a *trait* and *type* who come from identically named but different crates. This logic calls the `extern_crate` query which is not valid on `LOCAL_CRATE` cnum, so let's filter that out eagerly.

Fixes #130272
Fixes #129184
2024-09-17 17:28:33 +02:00
Matthias Krüger
ddcb9c132a
Rollup merge of #130201 - compiler-errors:foreign-synthetic-body, r=lcnr
Encode `coroutine_by_move_body_def_id` in crate metadata

We synthesize the MIR for a by-move body for the `FnOnce` implementation of async closures. It can be accessed with the `coroutine_by_move_body_def_id` query. We weren't encoding this query in the metadata though, nor were we properly recording that synthetic MIR in `mir_keys`, so the `optimized_mir` wasn't getting encoded either!

Stacked on top is a fix to consider `DefKind::SyntheticCoroutineBody` to return true in several places I missed. Specifically, we should consider the def-kind in `fn DefKind::is_fn_like()`, since that's what we were using to make sure we ensure `query mir_inliner_callees` before the MIR gets stolen for the body. This led to some CI failures that were caught by miri but which I added a test for.
2024-09-17 17:28:32 +02:00
Matthias Krüger
732ad59779
Rollup merge of #129988 - arnaudgolfouse:modify-locale_resources, r=davidtwco
Use `Vec` in `rustc_interface::Config::locale_resources`

This allows a third-party tool to injects its own resources, when receiving the config via `rustc_driver::Callbacks::config`.
2024-09-17 17:28:32 +02:00
Matthias Krüger
fe3428d9ac
Rollup merge of #128961 - GKFX:issue-128930-explain-missing-option, r=jieyouxu
Fix #128930: Print documentation of CLI options missing their arg

Fix #128930. Failing to give an argument to CLI options which require it now prints something like:
```
$ rustc --print
error: Argument to option 'print' missing
       Usage:
           --print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
                               Compiler information to print on stdout
```
2024-09-17 17:28:31 +02:00
Xiretza
5b3bde953e fluent_macro: fix diagnostics for fluent parse failures
This line number calculation was both wrong and unnecessary.
2024-09-17 14:49:33 +00:00
Michael Goulet
1c3b03a170 Mark where_clauses_object_safety as removed 2024-09-17 09:44:27 -04:00
bors
e9e13a68d7 Auto merge of #129073 - compiler-errors:receiver-variance, r=lcnr
Relate receiver invariantly in method probe for `Mode::Path`

Effectively reverts part of #126128
Fixes #126227

This PR changes method probing to use equality for fully path-based method lookup, and subtyping for receiver `.` method lookup.

r? lcnr
2024-09-17 12:44:08 +00:00
bors
46b0f8bafc Auto merge of #130455 - compiler-errors:inline-ordering, r=saethlin
Remove semi-nondeterminism of `DefPathHash` ordering from inliner

Déjà vu or something because I kinda thought I had put this PR up before. I recall a discussion somewhere where I think it was `@saethlin` mentioning that this check was no longer needed since we have "proper" cycle detection. Putting that up as a PR now.

This may slighlty negatively affect inlining, since the cycle breaking here means that we still inlined some cycles when the def path hashes were ordered in certain ways, this leads to really bad nondeterminism that makes minimizing ICEs and putting up inliner bugfixes difficult.

r? `@cjgillot` or `@saethlin` or someone else idk
2024-09-17 09:35:10 +00:00
Nicholas Nethercote
c629538dad Merge some impl blocks. 2024-09-17 16:24:35 +10:00
Nicholas Nethercote
3ec2f121cc Rename some lifetimes.
`'mir` is not a good lifetime name in `LocalAnalyzer`, because it's used
on two unrelated fields. `'a` is more standard for a situation like this
(e.g. #130022).
2024-09-17 16:24:35 +10:00
Nicholas Nethercote
ae1f092307 Streamline coroutine_kind_label. 2024-09-17 16:24:35 +10:00
Nicholas Nethercote
b3b56d805f Remove unnecessary cx argument.
Because `bx` contains a `cx`.
2024-09-17 16:24:35 +10:00
Nicholas Nethercote
52c5de00dc Streamline bin_op_to_[if]cmp_predicate. 2024-09-17 16:24:35 +10:00
Nicholas Nethercote
cd3da000c0 Clean up formatting.
Reflow overly long comments, plus some minor whitespace improvements.
2024-09-17 16:24:35 +10:00
Nicholas Nethercote
bdacdfe95f Minimize visibilities.
This makes it much clearer which things are used outside the crate.
2024-09-17 16:24:33 +10:00
bors
c8dff289a0 Auto merge of #130456 - matthiaskrgr:rollup-h2qvk1f, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #130380 (coverage: Clarify some parts of coverage counter creation)
 - #130427 (run_make_support: rectify symlink handling)
 - #130447 (rustc_llvm: update for llvm/llvm-project@2ae968a0d9fb61606b020e898d88…)
 - #130448 (fix: Remove duplicate `LazyLock` example.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-17 03:40:29 +00:00
Michael Goulet
4beb1cf9e5 Fix a couple more DefKind discrepancies between DefKind::Closure and DefKind::SyntheticCoroutineBody 2024-09-16 22:09:42 -04:00
Matthias Krüger
264597d86c
Rollup merge of #130447 - durin42:llvm-20-fix-instrumentation-hdr, r=cuviper
rustc_llvm: update for llvm/llvm-project@2ae968a0d9fb61606b020e898d88…

…4c82dd0ed8b5

Just a simple header move.

`@rustbot` label: +llvm-main
2024-09-17 03:58:47 +02:00
Matthias Krüger
1a7fdc7d5d
Rollup merge of #130380 - Zalathar:counters, r=jieyouxu
coverage: Clarify some parts of coverage counter creation

This is a series of semi-related changes that are trying to make the `counters` module easier to read, understand, and modify.

For example, the existing code happens to avoid ever using the count for a `TerminatorKind::Yield` node as the count for its sole out-edge (since doing so would be incorrect), but doesn't do so explicitly, so seemingly-innocent changes can result in baffling test failures.

This PR also takes the opportunity to simplify some debug-logging code that was making its surrounding code disproportionately hard to read.

There should be no changes to the resulting coverage instrumentation/mappings, as demonstrated by the absence of changes to the coverage test suite.
2024-09-17 03:58:46 +02:00
Michael Goulet
8f97231d34 Remove semi-nondeterminism of DefPathHash ordering from inliner 2024-09-16 21:41:15 -04:00
bors
e2dc1a1c0f Auto merge of #129970 - lukas-code:LayoutCalculator, r=compiler-errors
layout computation: gracefully handle unsized types in unexpected locations

This PR reworks the layout computation to eagerly return an error when encountering an unsized field where a sized field was expected, rather than delaying a bug and attempting to recover a layout. This is required, because with trivially false where clauses like `[T]: Sized`, any field can possible be an unsized type, without causing a compile error.

Since this PR removes the `delayed_bug` method from the `LayoutCalculator` trait, it essentially becomes the same as the `HasDataLayout` trait, so I've also refactored the `LayoutCalculator` to be a simple wrapper struct around a type that implements `HasDataLayout`.

The majority of the diff is whitespace changes, so viewing with whitespace ignored is advised.

implements https://github.com/rust-lang/rust/pull/123169#issuecomment-2025788480

r? `@compiler-errors` or compiler

fixes https://github.com/rust-lang/rust/issues/123134
fixes https://github.com/rust-lang/rust/issues/124182
fixes https://github.com/rust-lang/rust/issues/126939
fixes https://github.com/rust-lang/rust/issues/127737
2024-09-17 01:17:48 +00:00
Tyler Mandry
472fef6a70 Revert "Rollup merge of #129749 - krasimirgg:llvm-20-lto, r=nikic"
This reverts commit 8c7a7e346b, reversing
changes made to a00bd75b6c.
2024-09-16 17:11:02 -07:00
Michael Goulet
af1ca7794a Record synthetic MIR bodies in mir_keys 2024-09-16 20:06:16 -04:00
Michael Goulet
062ff4dfda Encode coroutine_by_move_body_def_id in crate metadata 2024-09-16 19:59:04 -04:00
Augie Fackler
1e68f05109 rustc_llvm: update for llvm/llvm-project@2ae968a0d9
Just a simple header move.

@rustbot label: +llvm-main
2024-09-16 19:53:13 -04:00
Lukas Markeffsky
20d2414925 get rid of an old hack
For structs that cannot be unsized, the layout algorithm sometimes moves
unsized fields to the end of the struct, which circumvented the error
for unexpected unsized fields and returned an unsized layout anyway.

This commit makes it so that the unexpected unsized error is always
returned for structs that cannot be unsized, allowing us to remove an
old hack and fixing some old ICE.
2024-09-17 00:09:21 +02:00
Lukas Markeffsky
3db930a463 assert that unexpectedly unsized fields are sized in the param env 2024-09-17 00:06:56 +02:00
bors
c52c23b6f4 Auto merge of #130444 - matthiaskrgr:rollup-onlrjva, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #130033 (Don't call `fn_arg_names` query for non-`fn` foreign items in resolver)
 - #130282 (Do not report an excessive number of overflow errors for an ever-growing deref impl)
 - #130437 (Avoid crashing on variadic functions when producing arg-mismatch errors)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-16 20:01:52 +00:00
Matthias Krüger
14ee69c250
Rollup merge of #130437 - jder:issue-130372, r=compiler-errors
Avoid crashing on variadic functions when producing arg-mismatch errors

Fixes #130372 by accommodating how variadic functions change the argument list length between HIR body and FnDecls.

Also degrades the zip_eq to a debug_assert! to match other asserts in the area to avoid being disruptive to users. There is at least one other crash in this area I am working on in #130400 and also considering how we might refactor some of this code to hoist some of this logic up higher.

r? `@compiler-errors`
2024-09-16 21:53:07 +02:00
Matthias Krüger
852e08e9bc
Rollup merge of #130282 - compiler-errors:over-overflow, r=BoxyUwU
Do not report an excessive number of overflow errors for an ever-growing deref impl

Check that we don't first hit the recursion limit in `get_field_candidates_considering_privacy` before probing for methods when we have a method lookup failure and we want to see if `.field.method()` exists. We also silence overflow error messages if we're probing for methods for diagnostics.

Also renames some functions to make it clearer that they're only for diagnostics, and sprinkle some `Autoderef::silence_errors` around to silence unnecessary overflow errors that come from diagnostics.

Fixes #130224.
2024-09-16 21:53:07 +02:00
Matthias Krüger
7be15b850f
Rollup merge of #130033 - compiler-errors:foreign-fn-types, r=BoxyUwU
Don't call `fn_arg_names` query for non-`fn` foreign items in resolver

Fixes #130015
2024-09-16 21:53:06 +02:00
Jesse Rusak
45eceb2c57 Avoid crashing on variadic functions when producing arg-mismatch errors 2024-09-16 14:51:56 -04:00
bors
fd2c811d25 Auto merge of #130439 - matthiaskrgr:rollup-1lkzo74, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #123436 (linker: Allow MSVC to use import libraries following the Meson/MinGW convention)
 - #130410 (Don't ICE when generating `Fn` shim for async closure with borrowck error)
 - #130412 (Don't ICE when RPITIT captures more method args than trait definition)
 - #130436 (Ignore reduce-fadd-unordered on SGX platform)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-16 17:41:17 +00:00
Michael Goulet
6e982f59ab Don't ICE in opaque_hidden_inferred_bound lint for RPITIT in trait with no default method body 2024-09-16 12:35:54 -04:00
Matthias Krüger
4e68d06b52
Rollup merge of #130412 - compiler-errors:rpitit-overcapture, r=jieyouxu
Don't ICE when RPITIT captures more method args than trait definition

Make sure we don't ICE when an RPITIT captures more method args than the trait definition, which is not allowed. This was because we were using the wrong def id for error reporting.

Due to the default lifetime capture rules of RPITITs (capturing everything in scope), this is only doable if we use precise capturing, which isn't currently allowed for RPITITs anyways but we still end up reaching the relevant codepaths.

Fixes #129850
2024-09-16 18:34:01 +02:00
Matthias Krüger
9a1004c259
Rollup merge of #130410 - compiler-errors:shim-borrowck-err, r=jieyouxu
Don't ICE when generating `Fn` shim for async closure with borrowck error

Turn an assumption that I had originally written as an assert into a delayed bug, because this shim code is reachable even if we have borrowck errors via the MIR inliner.

Fixes #129262.
2024-09-16 18:34:01 +02:00
Matthias Krüger
eac6f07380
Rollup merge of #123436 - amyspark:allow-msvc-to-use-meson-and-mingw-import-libraries, r=petrochenkov
linker: Allow MSVC to use import libraries following the Meson/MinGW convention

Hi all,

This PR implements support for `MsvcLinker` to use import libraries following Meson and the MinGW toolchain's naming convention. Meson [follows the `libfoo.dll.a` naming convention](https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa) to disambiguate between static and import libraries.

This support already existed for static libraries (see #100101), but not for dynamic libraries. The latter case was added by duplicating the logic in `native_libs::find_native_static_library`, but a separate case was added in `link_dylib_by_name` for the Windows CRT libraries which must be handled by the linker itself.

See for prerequisites #129366, #126094, and #128370.

All feedback is appreciated!

Fixes #122455

cc `@sdroege` `@nirbheek`
2024-09-16 18:34:00 +02:00
Michael Goulet
57a7e514a4 Don't ICE when generating Fn shim for async closure with borrowck error 2024-09-16 10:57:58 -04:00