Commit Graph

13196 Commits

Author SHA1 Message Date
Jubilee f9b8ef0687
Rollup merge of #130533 - compiler-errors:never-pat-unsafeck, r=Nadrieril
Never patterns constitute a read for unsafety

This code is otherwise unsound if we don't emit an unsafety error here. Noticed when fixing #130528, but it's totally unrelated.

r? `@Nadrieril`
2024-09-18 23:40:30 -07:00
Jubilee 944df8e40f
Rollup merge of #130531 - compiler-errors:thir-unsafeck-param, r=Urgau
Check params for unsafety in THIR

Self-explanatory. I'm not surprised this was overlooked, given the way that THIR visitors work. Perhaps we should provide a better entrypoint.

Fixes #130528
2024-09-18 23:40:29 -07:00
bors df7f77811c Auto merge of #123877 - ShE3py:expr-in-pats-2, r=fmease
Further improve diagnostics for expressions in pattern position

Follow-up of #118625, see #121697.

```rs
fn main() {
    match 'b' {
        y.0.0.1.z().f()? as u32 => {},
    }
}
```
Before:
```
error: expected one of `=>`, ``@`,` `if`, or `|`, found `.`
 --> src/main.rs:3:10
  |
3 |         y.0.0.1.z().f()? as u32 => {},
  |          ^ expected one of `=>`, ``@`,` `if`, or `|`
```
After:
```
error: expected a pattern, found an expression
 --> src/main.rs:3:9
  |
3 |         y.0.0.1.z().f()? as u32 => {},
  |         ^^^^^^^^^^^^^^^^^^^^^^^ arbitrary expressions are not allowed in patterns
  |
help: consider moving the expression to a match arm guard
  |
3 |         val if val == y.0.0.1.z().f()? as u32 => {},
  |         ~~~ +++++++++++++++++++++++++++++++++
help: consider extracting the expression into a `const`
  |
2 +     const VAL: /* Type */ = y.0.0.1.z().f()? as u32;
3 ~     match 'b' {
4 ~         VAL => {},
  |
help: consider wrapping the expression in an inline `const` (requires `#![feature(inline_const_pat)]`)
  |
3 |         const { y.0.0.1.z().f()? as u32 } => {},
  |         +++++++                         +
```

---

r? fmease
`@rustbot` label +A-diagnostics +A-parser +A-patterns +C-enhancement
2024-09-19 00:36:33 +00:00
Michael Goulet e138e8760d Never patterns constitute a read for unsafety 2024-09-18 19:17:38 -04:00
Jubilee d972605735
Rollup merge of #130487 - cuviper:min-llvm-18, r=nikic
Update the minimum external LLVM to 18

With this change, we'll have stable support for LLVM 18 and 19.
For reference, the previous increase to LLVM 17 was #122649.

cc `@rust-lang/wg-llvm`
r? nikic
2024-09-18 14:32:27 -07:00
Jubilee b33dd7dc88
Rollup merge of #130450 - workingjubilee:these-names-are-indirect, r=bjorn3
Reduce confusion about `make_indirect_byval` by renaming it

As part of doing so, remove the incorrect handling of the wasm target's `make_indirect_byval` (i.e. using it at all).
2024-09-18 14:32:25 -07:00
Jubilee 2eb65a6667
Rollup merge of #129422 - compiler-errors:repr-rust, r=fmease
Gate `repr(Rust)` correctly on non-ADT items

#114201 added `repr(Rust)` but didn't add any attribute validation to it like `repr(C)` has, to only allow it on ADT items.

I consider this code to be nonsense, for example:
```
#[repr(Rust)]
fn foo() {}
```

Reminder that it's different from `extern "Rust"`, which *is* valid on function items. But also this now disallows `repr(Rust)` on modules, impls, traits, etc.

I'll crater it, if it looks bad then I'll add an FCW.

---

https://github.com/rust-lang/rust/labels/relnotes: Compatibility (minor breaking change).
2024-09-18 14:32:24 -07:00
Jubilee 2a1dd3575f
Rollup merge of #127988 - estebank:dupe-derive-params, r=fmease
Do not ICE with incorrect empty suggestion

When we have two types with the same name, one without type parameters and the other with type parameters and a derive macro, we were before incorrectly suggesting to remove type parameters from the former, which ICEd because we were suggesting to remove nothing. We now gate against this.

The output is still not perfect. E0107 should explicitly detect this case and provide better context, but for now let's avoid the ICE.

Fix #108748.
2024-09-18 14:32:24 -07:00
Josh Stone 6fd8a50680 Update the minimum external LLVM to 18 2024-09-18 13:53:31 -07:00
Michael Goulet 12f2bcde63 Check params for unsafety in THIR 2024-09-18 16:45:48 -04:00
Jubilee Young 51718e8eca tests: Move wasm32 to transparent-opaque-ptr.rs test 2024-09-18 12:31:51 -07:00
Jubilee Young b75711df12 tests: Remove test for wrong wasm codegen 2024-09-18 12:28:55 -07:00
Lieselotte db09345ef6
Add suggestions for expressions in patterns 2024-09-18 20:38:43 +02:00
Lieselotte c2047219b5
Recover more expressions in patterns 2024-09-18 20:37:56 +02:00
León Orell Valerian Liehr 682c5f485b
Explicitly mark a hack as a HACK and elaborate its comment 2024-09-18 19:36:44 +02:00
Esteban Küber bd8e88fd7b
Do not ICE with incorrect empty suggestion
When we have two types with the same name, one without type parameters and the other with type parameters and a derive macro, we were before incorrectly suggesting to remove type parameters from the former, which ICEd because we were suggesting to remove nothing. We now gate against this.

The output is still not perfect. E0107 should explicitly detect this case and provide better context, but for now let's avoid the ICE.
2024-09-18 19:21:07 +02:00
Matthias Krüger 00c4be3df8
Rollup merge of #130507 - Urgau:check-cfg-raw-keywords, r=jieyouxu
Improve handling of raw-idents in check-cfg

This PR improves the handling of raw-idents in the check-cfg diagnostics.

In particular the list of expected names and the suggestion now correctly take into account the "keyword-ness" of the ident, and correctly prefix the ident with `r#` when necessary.

`@rustbot` labels +F-check-cfg
2024-09-18 17:49:44 +02:00
bors 82d17a4db3 Auto merge of #130500 - matthiaskrgr:rollup-lfx3bb4, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #130466 (tests: add repr/transparent test for aarch64)
 - #130468 (Make sure that def id <=> lang item map is bidirectional)
 - #130499 (Add myself to the libs review rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-18 09:25:01 +00:00
Urgau 89f04c2521 Improve handling of raw-idents in check-cfg 2024-09-18 11:07:32 +02:00
Matthias Krüger b21581d1cb
Rollup merge of #130466 - davidtwco:aarch64-transparent-test, r=jieyouxu
tests: add repr/transparent test for aarch64

Fixes #74396.

Moves `transparent-struct-ptr.rs` to `transparent-byval-struct-ptr.rs` and then adds a new `transparent-opaque-ptr.rs` for aarch64.
2024-09-18 09:03:52 +02:00
bors f6bcd094ab Auto merge of #130498 - matthiaskrgr:rollup-tg4d0zi, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #130116 (Implement a Method to Seal `DiagInner`'s Suggestions)
 - #130489 (Ensure that `keyword_ident` lint doesn't trigger on `'r#kw` lifetime)
 - #130491 (more crash tests)
 - #130496 (Fix circular fn_sig queries to correct number of args for methods)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-18 04:01:51 +00:00
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 862f3e7685
Rollup merge of #130491 - matthiaskrgr:sehsarc, r=compiler-errors
more crash tests

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
bors 60c3673456 Auto merge of #130454 - durin42:llvm-20-notrunc, r=workingjubilee
tests: allow trunc/select instructions to be missing

On LLVM 20, these instructions already get eliminated, which at least partially satisfies a TODO. I'm not talented enough at using FileCheck to try and constrain this further, but if we really want to we could copy an LLVM 20 specific version of this test that would restore it to being CHECK-NEXT: insertvalue ...

`@rustbot` label: +llvm-main
r? `@DianQK`
2024-09-18 01:27:26 +00: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
Matthias Krüger 7e8eb7aa93
Rollup merge of #130482 - spastorino:remove-known-bug-97156, r=jackh726
Remove redundant test typeid equality by subtyping

This known-bug label was a left over on #118247

r? `@jackh726`

This doesn't address #110395, I didn't investigate about it yet.
2024-09-18 00:12:19 +02:00
Matthias Krüger 12814c8aa5 more crash tests 2024-09-18 00:10:25 +02: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 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
Santiago Pastorino 65f8999026
Remove redundant test typeid equality by subtyping 2024-09-17 15:45:15 -03: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 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
Xiretza 0a253246f7 Add test for fluent diagnostics 2024-09-17 14:47:57 +00:00
Augie Fackler 9692513b7e tests: allow trunc/select instructions to be missing
On LLVM 20, these instructions already get eliminated, which at least
partially satisfies a TODO. I'm not talented enough at using FileCheck
to try and constrain this further, but if we really want to we could
copy an LLVM 20 specific version of this test that would restore it to
being CHECK-NEXT: insertvalue ...

@rustbot label: +llvm-main
2024-09-17 08:55:26 -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
David Wood 9a330742c9
tests: add repr/transparent test for aarch64
Moves `transparent-struct-ptr.rs` to `transparent-byval-struct-ptr.rs`
and then adds a new `transparent-opaque-ptr.rs` for aarch64.
2024-09-17 13:29:44 +01: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
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 07ca905420
Rollup merge of #130427 - jieyouxu:rmake-symlink, r=Kobzol
run_make_support: rectify symlink handling

Avoid confusing Unix symlinks and Windows symlinks. Since their
semantics are quite different, we should avoid trying to make it
automagic in how symlinks are created and deleted. Notably, the tests
should reflect what type of symlinks are to be created to match what std
does to make it less surprising for test readers.
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
Michael Goulet 062ff4dfda Encode coroutine_by_move_body_def_id in crate metadata 2024-09-16 19:59:04 -04:00