Commit Graph

34623 Commits

Author SHA1 Message Date
bors 6bb6b816bf Auto merge of #122046 - Nadrieril:integrate-or-pats2, r=matthewjasper
match lowering: handle or-patterns one layer at a time

`create_or_subcandidates` and `merge_trivial_subcandidates` both call themselves recursively to handle nested or-patterns, which is hard to follow. In this PR I avoid the need for that; we now process a single "layer" of or-patterns at a time.

By calling back into `match_candidates`, we only need to expand one layer at a time. Conversely, since we always try to simplify a layer that we just expanded (thanks to https://github.com/rust-lang/rust/pull/123067), we only have to merge one layer at a time.

r? `@matthewjasper`
2024-04-01 12:31:27 +00:00
bors 3d5528c287 Auto merge of #123310 - compiler-errors:nested-static-codegen-attrs, r=oli-obk
Don't inherit codegen attrs from parent static

Putting this up partly for discussion and partly for review. Specifically, in #121644, `@oli-obk` designed a system that creates new static items for representing nested allocations in statics. However, in that PR, oli made it so that these statics inherited the codegen attrs from the parent.

This causes problems such as colliding symbols with `#[export_name]` and ICEs with `#[no_mangle]` since these synthetic statics have no `tcx.item_name(..)`.

So the question is, is there any case where we *do* want to inherit codegen attrs from the parent? The only one that seems a bit suspicious is the thread-local attribute. And there may be some interesting interactions with the coverage attributes as well...

Fixes (after backport) #123274. Fixes #123243. cc #121644.

r? `@oli-obk` cc `@nnethercote` `@RalfJung` (reviewers on that pr)
2024-04-01 09:22:01 +00:00
bors 7f84ede33d Auto merge of #122663 - beetrees:non-unicode-env-error, r=TaKO8Ki
Fix error message for `env!` when env var is not valid Unicode

Currently (without this PR) the `env!` macro emits an ```environment variable `name` not defined at compile time``` error when the environment variable is defined, but not a valid Unicode string. This PR introduces a separate more accurate error message, and a test to verify this behaviour.

For reference, before this PR, the new test would have outputted:
```
error: environment variable `NON_UNICODE_VAR` not defined at compile time
 --> non_unicode_env.rs:2:13
  |
2 |     let _ = env!("NON_UNICODE_VAR");
  |             ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: use `std::env::var("NON_UNICODE_VAR")` to read the variable at run time
  = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error
```

whereas with this PR, the test ouputs:
```
error: environment variable `NON_UNICODE_VAR` is not a valid Unicode string
 --> non_unicode_env.rs:2:13
  |
2 |     let _ = env!("NON_UNICODE_VAR");
  |             ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error
```
2024-04-01 05:18:51 +00:00
beetrees 0bbaa2505b
Fix error message for `env!` when env var is not valid Unicode 2024-04-01 05:44:45 +01:00
bors defef8658e Auto merge of #122972 - beetrees:use-align-type, r=fee1-dead
Use the `Align` type when parsing alignment attributes

Use the `Align` type in `rustc_attr::parse_alignment`, removing the need to call `Align::from_bytes(...).unwrap()` later in the compilation process.
2024-04-01 03:16:45 +00:00
Michael Goulet 4ff8a9bd6b Don't inherit codegen attrs from parent static 2024-03-31 22:34:00 -04:00
beetrees 6e5f1dacf3
Use the `Align` type when parsing alignment attributes 2024-04-01 03:05:55 +01:00
bors bf71daedc2 Auto merge of #121851 - michaelwoerister:mcp-533-effective-vis, r=cjgillot
Use FxIndexMap instead FxHashMap to stabilize iteration order in EffectiveVisibilities

Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).
2024-03-31 16:22:38 +00:00
Matthias Krüger f04d068adc
Rollup merge of #123242 - Nadrieril:require-contiguous-enum-indices, r=compiler-errors
pattern analysis: Require enum indices to be contiguous

We had a cfg-hack to allow rust-analyzer to use non-contiguous indices for its enum variants. Unfortunately this no longer works if r-a uses the in-tree version of the crate.

This PR removes the hack, and on the r-a side we'll have to use contiguous indices but that's not too hard.

r? `@compiler-errors`
2024-03-31 11:50:41 +02:00
Matthias Krüger d77608b4b9
Rollup merge of #123211 - compiler-errors:V, r=estebank
Stop calling visitors `V`

Renames some visitors which currently have the unhelpful name of `V`. It's not self-documenting, and there is no situation where saving a few bytes in source code helps anyone.

Stacked on top of #123202 due to conflict.
2024-03-31 11:50:40 +02:00
bors c93b17d6d2 Auto merge of #123236 - klensy:tracing-tree-bump, r=Mark-Simulacrum
bump tracing-tree to 0.3

Only change in `tracing-tree` is https://github.com/davidbarsky/tracing-tree/pull/76
* dedupes `tracing-log`
* dupes `nu-ansi-term`
2024-03-31 06:21:53 +00:00
bors 5baf1e13f5 Auto merge of #122459 - Nadrieril:sort-eq, r=oli-obk
match lowering: sort `Eq` candidates in the failure case too

This is a slight tweak to MIR gen of matches. Take a match like:
```rust
match (s, flag) {
    ("a", _) if foo() => 1,
    ("b", true) => 2,
    ("a", false) => 3,
    (_, true) => 4,
    _ => 5,
}
```
If we switch on `s == "a"`, the first candidate matches, and we learn almost nothing about the second candidate. So there's a choice:
1. (what we do today) stop sorting candidates, keep the "b" case grouped with everything below. This could allow us to be clever here and test on `flag == true` next.
2. (what this PR does) sort "b" into the failure case. The "b" will be alone (fewer opportunities for picking a good test), but that means the two "a" cases require a single test.

Today, we aren't clever in which tests we pick, so this is an unambiguous win. In a future where we pick tests better, idk. Grouping tests as much as possible feels like a generally good strategy.

This was proposed in https://github.com/rust-lang/rust/issues/29623 (9 years ago :D)
2024-03-31 02:12:50 +00:00
bors 70714e38f2 Auto merge of #123106 - maurer:cfi-closures, r=compiler-errors
CFI: Abstract Closures and Coroutines

This will abstract coroutines in a moment, it's just abstracting closures for now to show `@rcvalle`

This uses the same principal as the methods on traits - figure out the `dyn` type representing the fn trait, instantiate it, and attach that alias set. We're essentially just computing how we would be called in a dynamic context, and attaching that.
2024-03-30 17:56:26 +00:00
Matthew Maurer 8cc9a912d7 CFI: Rewrite closure and coroutine instances to their trait method
Similar to methods on a trait object, the most common way to indirectly
call a closure or coroutine is through the vtable on the appropriate
trait. This uses the same approach as we use for trait methods, after
backing out the trait arguments from the type.
2024-03-30 16:40:38 +00:00
Matthew Maurer e974570c42 CFI: Only encode Coroutine Parent Args
Fixes #122705
2024-03-30 16:39:51 +00:00
Nadrieril 75d2e67ed2 Sort `Eq` candidates in the failure case too 2024-03-30 17:37:15 +01:00
bors ef49365102 Auto merge of #123207 - Urgau:improve_ambi_non_null, r=Nadrieril
Add support for `NonNull`s in the `ambiguous_wide_ptr_comparisions` lint

This PR add support for `NonNull` pointers in the `ambiguous_wide_ptr_comparisions` lint.

Fixes https://github.com/rust-lang/rust/issues/121264
r? `@Nadrieril` (since you just reviewed #121268, feel free to reassign)
2024-03-30 15:53:28 +00:00
Nadrieril e1b8441899 Require enum indices to be contiguous 2024-03-30 16:22:43 +01:00
Michael Goulet bda301ead8 Stop calling visitors V 2024-03-30 11:13:33 -04:00
klensy 71ea506d3d bump tracing-tree to 0.3
Only change is https://github.com/davidbarsky/tracing-tree/pull/76
dedupes tracing-log
dupes nu-ansi-term
2024-03-30 17:39:43 +03:00
bors 1852728224 Auto merge of #123230 - matthiaskrgr:rollup-4twuzj4, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #121573 (unix_sigpipe: Add test for SIGPIPE disposition in child processes)
 - #123170 (Replace regions in const canonical vars' types with `'static` in next-solver canonicalizer)
 - #123200 (KCFI: Require -C panic=abort)
 - #123201 (Improve wording in std::any explanation)
 - #123224 (compiletest: print reason for failing to read tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-30 13:51:24 +00:00
Matthias Krüger 3afd111489
Rollup merge of #123200 - maurer:kcfi-abort, r=compiler-errors
KCFI: Require -C panic=abort

While the KCFI scheme is not incompatible with unwinding, LLVM's `invoke` instruction does not currently support KCFI bundles. While it likely will in the near future, we won't be able to assume that in Rust for a while.

We encountered this problem while [turning on closure support](https://github.com/rust-lang/rust/pull/123106#issuecomment-2027436640).

r? ``@workingjubilee``
2024-03-30 14:30:50 +01:00
Matthias Krüger 93f1443280
Rollup merge of #123170 - compiler-errors:const-statics, r=lcnr
Replace regions in const canonical vars' types with `'static` in next-solver canonicalizer

We shouldn't ever have non-static regions in consts on stable (or really any regions at all, lol).

The test I committed is less minimal than, e.g., https://github.com/rust-lang/rust/issues/123155?notification_referrer_id=NT_kwDOADgQyrMxMDAzNDU4MDI0OTozNjc0MzE0#issuecomment-2025472029 -- however, I believe that it actually portrays the underlying issue here a bit better than that one.

In the linked issue, we end up emitting a normalizes-to predicate for a const placeholder because we don't actually unify `false` and `""`. In the test I committed, we emit a normalizes-to predicate as a part of actually solving a negative coherence goal.

Fixes #123155
Fixes #118783

r? lcnr
2024-03-30 14:30:49 +01:00
bors 40116ad1ed Auto merge of #123214 - compiler-errors:subst, r=estebank
Assert that ADTs have the right number of args

We're doing it for many other types, let's also do ADTs 😇
2024-03-30 11:48:31 +00:00
bors 7e0ed43287 Auto merge of #123202 - estebank:issue-123009, r=compiler-errors
Do not attempt to write `ty::Err` on binding that isn't from current HIR Owner

Fix #123009. Follow up to #122119.
2024-03-30 08:38:48 +00:00
bors 50e3d6296d Auto merge of #123012 - maurer:cfi-supertraits, r=compiler-errors
CFI: Support calling methods on supertraits

Automatically adjust `Virtual` calls to supertrait functions to use the supertrait's trait object type as the receiver rather than the child trait.

cc `@compiler-errors` - this is the next usage of `trait_object_ty` I intend to have, so I thought it might be relevant while reviewing the existing one.
2024-03-30 06:38:18 +00:00
Michael Goulet f487d83390 Stop doing so much to handle subdiagnostics 2024-03-29 22:23:10 -04:00
Michael Goulet bc1f1ef2c8 Stop removing substs from Adt type in coherence 2024-03-29 21:21:52 -04:00
Michael Goulet 5e2c549772 Assert that ADTs have the right number of substs 2024-03-29 20:40:47 -04:00
Aria Beingessner ea92faec49 stabilize ptr.is_aligned, move ptr.is_aligned_to to a new feature gate
This is an alternative to #121920
2024-03-29 19:59:46 -04:00
Urgau 16d11c539f Add support for NonNull in ambiguous_wide_ptr_comparisions 2024-03-29 22:02:07 +01:00
Esteban Küber d54e9833e3 Do not attempt to write `ty::Err` on binding that isn't from current HIR Owner
Fix #123009.
2024-03-29 19:05:54 +00:00
bors af4a5a13a1 Auto merge of #121268 - Urgau:improve_ambi_wide_ptr_cmps, r=Nadrieril
Add detection of [Partial]Ord methods in the `ambiguous_wide_pointer_comparisons` lint

Partially addresses https://github.com/rust-lang/rust/issues/121264 by adding diagnostics items for PartialOrd and Ord methods, detecting such diagnostics items as "binary operation" and suggesting the correct replacement.

I also took the opportunity to change the suggestion to use new methods `.cast()` on `*mut T` an d `*const T`.
2024-03-29 18:23:57 +00:00
Matthew Maurer d301f40c84 CFI: Encode Virtual calls as calls through the defining trait
For example, if `trait Foo: Bar`, and we try to call a method from `Bar`
on `dyn Foo`, encode the callsite as passing a `dyn Bar`, not a `dyn
Foo`.
2024-03-29 18:15:41 +00:00
Matthew Maurer 29c1a2b9e9 KCFI: Require -C panic=abort
While the KCFI scheme is not incompatible with unwinding, LLVM's
`invoke` instruction does not currently support KCFI bundles. While it
likely will in the near future, we won't be able to assume that in Rust
for a while.
2024-03-29 16:35:58 +00:00
bors 399fa2f6e4 Auto merge of #123194 - matthiaskrgr:rollup-vhdc8hw, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #123176 (Normalize the result of `Fields::ty_with_args`)
 - #123186 (copy any file from stage0/lib to stage0-sysroot/lib)
 - #123187 (Forward port 1.77.1 release notes)
 - #123188 (compiler: fix few unused_peekable and needless_pass_by_ref_mut clippy lints)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-29 16:02:04 +00:00
Urgau d4b514f982 Add detection of [Partial]Ord methods to the ambiguous wide ptr cmp lint 2024-03-29 16:36:17 +01:00
Urgau 4a9f3cac88 Add diagnostic items for Ord and PartialOrd methods 2024-03-29 16:25:41 +01:00
Matthias Krüger 8d820c0c47
Rollup merge of #123188 - klensy:clippy-me2, r=Nilstrieb
compiler: fix few unused_peekable and needless_pass_by_ref_mut clippy lints

This fixes few instances of `unused_peekable` and `needless_pass_by_ref_mut`. While i expected to fix more warnings, `needless_pass_by_ref_mut` produced too much for one PR, so i stopped here.

Better reviewed commit by commit, as fixes splitted by chunks.
2024-03-29 15:17:11 +01:00
Matthias Krüger 73a4208638
Rollup merge of #123176 - celinval:smir-field-ty, r=oli-obk
Normalize the result of `Fields::ty_with_args`

We were only instantiating before, which would leak an AliasTy. I added a test case that reproduce the issue seen here:

https://github.com/model-checking/kani/issues/3113

r? ``@oli-obk``
2024-03-29 15:17:10 +01:00
bors 685927aae6 Auto merge of #122450 - Urgau:simplify-trim-paths-feature, r=michaelwoerister
Simplify trim-paths feature by merging all debuginfo options together

This PR simplifies the trim-paths feature by merging all debuginfo options together, as described in https://github.com/rust-lang/rust/issues/111540#issuecomment-1994010274.

And also do some correctness fixes found during the review.

cc `@weihanglo`
r? `@michaelwoerister`
2024-03-29 14:00:21 +00:00
bors 45796d1c24 Auto merge of #123080 - Jules-Bertholet:mut-ref-mut, r=Nadrieril
Match ergonomics 2024: implement mutable by-reference bindings

Implements the mutable by-reference bindings portion of match ergonomics 2024 (#123076), with the `mut ref`/`mut ref mut` syntax, under feature gate `mut_ref`.

r? `@Nadrieril`

`@rustbot` label A-patterns A-edition-2024
2024-03-29 11:08:11 +00:00
bors 58dcd1fdb9 Auto merge of #123071 - rcvalle:rust-cfi-fix-method-fn-ptr-cast, r=compiler-errors
CFI: Fix methods as function pointer cast

Fix casting between methods and function pointers by assigning a secondary type id to methods with their concrete self so they can be used as function pointers.

This was split off from #116404.

cc `@compiler-errors` `@workingjubilee`
2024-03-29 09:04:05 +00:00
bors 760e567af5 Auto merge of #122975 - DianQK:simplify_ub_check, r=saethlin
Eliminate `UbChecks` for non-standard libraries

 The purpose of this PR is to allow other passes to treat `UbChecks` as constants in MIR for optimization after #122629.

r? RalfJung
2024-03-29 02:25:43 +00:00
bors db2f9759f4 Auto merge of #122671 - Mark-Simulacrum:const-panic-msg, r=Nilstrieb
Codegen const panic messages as function calls

This skips emitting extra arguments at every callsite (of which there
can be many). For a librustc_driver build with overflow checks enabled,
this cuts 0.7MB from the resulting shared library (see [perf]).

A sample improvement from nightly:

```
        leaq    str.0(%rip), %rdi
        leaq    .Lalloc_d6aeb8e2aa19de39a7f0e861c998af13(%rip), %rdx
        movl    $25, %esi
        callq   *_ZN4core9panicking5panic17h17cabb89c5bcc999E@GOTPCREL(%rip)
```

to this PR:

```
        leaq    .Lalloc_d6aeb8e2aa19de39a7f0e861c998af13(%rip), %rdi
        callq   *_RNvNtNtCsduqIKoij8JB_4core9panicking11panic_const23panic_const_div_by_zero@GOTPCREL(%rip)
```

[perf]: https://perf.rust-lang.org/compare.html?start=a7e4de13c1785819f4d61da41f6704ed69d5f203&end=64fbb4f0b2d621ff46d559d1e9f5ad89a8d7789b&stat=instructions:u
2024-03-29 00:24:01 +00:00
Celina G. Val a325bce3cd Normalize the result of Fields::ty_with_args
We were only instantiating before, which would leak an AliasTy.
I added a test case that reproduce the issue seen here:

https://github.com/model-checking/kani/issues/3113
2024-03-28 13:22:10 -07:00
Urgau fefb8f1f9c Replace Session should_remap_filepaths with filename_display_preference 2024-03-28 18:47:26 +01:00
Urgau 4f4fa42b0e Introduce `FileNameMapping::to_real_filename` and use it everywhere 2024-03-28 18:47:26 +01:00
Urgau ee2898d3f1 Make local_crate_source_file return a RealFileName
so it can be remapped (or not) by callers
2024-03-28 18:47:26 +01:00
Urgau 106146fd95 Replace `RemapFileNameExt::for_codegen` with explicit calls 2024-03-28 18:47:26 +01:00