Commit Graph

242559 Commits

Author SHA1 Message Date
Matthew Jasper
7832ebbd4f Handle context for const patterns correctly 2024-01-05 10:00:59 +00:00
Matthew Jasper
26f48b4cba Stabilize THIR unsafeck 2024-01-05 10:00:59 +00:00
Matthew Jasper
982b49494e Remove revisions for THIR unsafeck
This is to make the diff when stabilizing it easier to review.
2024-01-05 09:30:27 +00:00
bors
5113ed28ea Auto merge of #118297 - shepmaster:warn-dead-tuple-fields, r=WaffleLapkin
Merge `unused_tuple_struct_fields` into `dead_code`

This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group.

[Discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Moving.20.60unused_tuple_struct_fields.60.20from.20allow.20to.20warn)
2024-01-05 04:51:55 +00:00
bors
a59a98024e Auto merge of #118861 - Veykril:r-a-in-tree, r=onur-ozkan
Set the `in-rust-tree` feature for all rust-analyzer{-proc-macro-srv} steps

Some context: This came up in https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/libraryfying.20match.20checking.3F where `test` and `check` behaved differently for rust-analyzer
r? `@onur-ozkan`
2024-01-05 02:53:45 +00:00
bors
791a53f380 Auto merge of #117213 - oli-obk:check_item_type_cleanup, r=estebank
Reorder check_item_type diagnostics so they occur next to the corresponding `check_well_formed` diagnostics

The first commit is just a cleanup.

The second commit moves most checks from `check_mod_item_types` into `check_well_formed`, invoking the checks in lockstep per-item instead of iterating over all items twice.
2024-01-05 00:04:08 +00:00
bors
f688dd684f Auto merge of #119569 - matthiaskrgr:rollup-4packja, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag)
 - #119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.)
 - #119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args)
 - #119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans)
 - #119362 (Make `derive(Trait)` suggestion more accurate)
 - #119397 (Recover parentheses in range patterns)
 - #119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`)
 - #119539 (Fix typos)
 - #119540 (Don't synthesize host effect args inside trait object types)
 - #119555 (Add codegen test for RVO on MaybeUninit)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-04 21:44:14 +00:00
bors
4c5ce1f0d5 Auto merge of #119578 - matthiaskrgr:rollup-42yizmx, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #117636 (add test for #117626)
 - #118704 (Promote `riscv32{im|imafc}` targets to tier 2)
 - #119184 (Switch from using `//~ERROR` annotations with `--error-format` to `error-pattern`)
 - #119325 (custom mir: make it clear what the return block is)
 - #119391 (Use Result::flatten in catch_with_exit_code)
 - #119431 (Support reg_addr register class in s390x inline assembly)
 - #119475 (Remove libtest's dylib)
 - #119532 (Make offset_of field parsing use metavariable which handles any spacing)
 - #119553 (stop feed vis when cant access for trait item)
 - #119574 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-04 19:44:14 +00:00
Matthias Krüger
657937850b
Rollup merge of #119574 - RalfJung:miri, r=oli-obk
Miri subtree update

r? `@ghost`
2024-01-04 15:34:01 +01:00
Matthias Krüger
ee882d628f
Rollup merge of #119553 - bvanjoi:fix-119463, r=petrochenkov
stop feed vis when cant access for trait item

Fixes #119463

It's not necessary to feed visibility when use a private trait.

r? ``@petrochenkov``
2024-01-04 15:34:01 +01:00
Matthias Krüger
e306cfb115
Rollup merge of #119532 - GKFX:offset-of-parse-expr, r=est31
Make offset_of field parsing use metavariable which handles any spacing

As discussed at and around comments https://github.com/rust-lang/rust/issues/106655#issuecomment-1793485081 and https://github.com/rust-lang/rust/issues/106655#issuecomment-1793774183, the current arguments to offset_of do not accept all the whitespace combinations: `0. 1.1.1` and `0.1.1. 1` are currently treated specially in `tests/ui/offset-of/offset-of-tuple-nested.rs`.

They also do not allow [forwarding individual fields as in](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=444cdf0ec02b99e8fd5fd8d8ecb312ca)
```rust
macro_rules! off {
    ($a:expr) => {
        offset_of!(m::S, 0. $a)
    }
}
```

This PR replaces the macro arguments with `($Container:ty, $($fields:expr)+ $(,)?)` which does allow any arrangement of whitespace that I could come up with and the forwarding of fields example above.

This also allows for array indexing in the future, which I think is the last future extension to the syntax suggested in the offset_of RFC.

Tracking issue for offset_of: #106655
``@rustbot`` label F-offset_of

``@est31``
2024-01-04 15:34:00 +01:00
Matthias Krüger
99a8c339f0
Rollup merge of #119475 - saethlin:remove-libtest-dylib, r=cuviper
Remove libtest's dylib

libtest.so is only used by rustdoc, and tests seem to pass locally with this change. I suppose if this is broken, the only way to find out is to make a PR.
2024-01-04 15:34:00 +01:00
Matthias Krüger
12c102ec53
Rollup merge of #119431 - taiki-e:asm-s390x-reg-addr, r=Amanieu
Support reg_addr register class in s390x inline assembly

In s390x, `r0` cannot be used as an address register (it is evaluated as zero in an address context).

Therefore, currently, in assemblies involving memory accesses, `r0` must be [marked as clobbered](1a1155653a/src/arch/s390x.rs (L58)) or [explicitly used to a non-address](1a1155653a/src/arch/s390x.rs (L135)) or explicitly use an address register to prevent `r0` from being allocated to a register for the address.

This patch adds a register class for allocating general-purpose registers, except `r0`, to make it easier to use address registers. (powerpc already has a register class (reg_nonzero) for a similar purpose.)

This is identical to the `a` constraint in LLVM and GCC:

https://llvm.org/docs/LangRef.html#supported-constraint-code-list
> a: A 32, 64, or 128-bit integer address register (excludes R0, which in an address context evaluates as zero).

https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
> a
> Address register (general purpose register except r0)

cc ``@uweigand``

r? ``@Amanieu``
2024-01-04 15:33:59 +01:00
Matthias Krüger
3d8d10d4ea
Rollup merge of #119391 - DaniPopes:catch-flatten, r=davidtwco
Use Result::flatten in catch_with_exit_code
2024-01-04 15:33:58 +01:00
Matthias Krüger
a919d97aaa
Rollup merge of #119325 - RalfJung:custom-mir, r=compiler-errors
custom mir: make it clear what the return block is

Custom MIR recently got support for specifying the "unwind action", so now there's two things coming after the actual call part of `Call` terminators. That's not very self-explaining so I propose we change the syntax to imitate keyword arguments:
```
Call(popped = Vec::pop(v), ReturnTo(drop), UnwindContinue())
```

Also fix some outdated docs and add some docs to `Call` and `Drop`.
2024-01-04 15:33:58 +01:00
Matthias Krüger
9fa0c8e1c7
Rollup merge of #119184 - Rajveer100:branch-for-issue-118752, r=davidtwco
Switch from using `//~ERROR` annotations with `--error-format` to `error-pattern`

Fixes #118752

As noticed by ```@jyn514``` while working on a patch, tests failed due to `//~ERROR` annotations used in combination with the older `--error-format` which is now `error-pattern`.
2024-01-04 15:33:57 +01:00
Matthias Krüger
08c822fab3
Rollup merge of #118704 - esp-rs:rv32-tier-2, r=davidtwco
Promote `riscv32{im|imafc}` targets to tier 2

Pending the approval of [the MCP](https://github.com/rust-lang/compiler-team/issues/701).
2024-01-04 15:33:57 +01:00
Matthias Krüger
5c47d77c1e
Rollup merge of #117636 - bvanjoi:fix-117626, r=TaKO8Ki
add test for #117626

Close #117626
2024-01-04 15:33:56 +01:00
Lukas Wirth
abf08229ae Set proc-macro-test/sysroot-abi with proc-macro-srv/sysroot-abi 2024-01-04 15:12:57 +01:00
Ralf Jung
5aa15b6ee7 miri: do not forward RUSTFLAGS to deps build 2024-01-04 12:30:38 +01:00
Lukas Wirth
3e3d08c843 Set sysroot-abi flag for proc-macro-cli when in-rust-tree is set 2024-01-04 11:02:23 +01:00
Lukas Wirth
80095aac61 Add extern crate rustc_driver to proc-macro-srv-cli 2024-01-04 11:02:23 +01:00
Lukas Wirth
9a9ba92b28 Imply sysroot-abi feature when in-rust-tree is set 2024-01-04 11:02:23 +01:00
Lukas Wirth
7b41008ee0 Set the in-rust-tree` feature for all rust-analyzer{-proc-macro-srv} steps 2024-01-04 11:02:20 +01:00
Matthias Krüger
c505d760a6
Rollup merge of #119555 - Kobzol:maybeuninit-rvo-codegen-test, r=nikic
Add codegen test for RVO on MaybeUninit

Codegen test for https://github.com/rust-lang/rust/issues/90595. Currently, this only works with `-Cpanic=abort`, but hopefully in the [future](https://www.npopov.com/2024/01/01/This-year-in-LLVM-2023.html#writable-and-dead_on_unwind) it should also work in the presence of panics.

r? ``@nikic``
2024-01-04 08:33:26 +01:00
Matthias Krüger
f4335a419f
Rollup merge of #119540 - fmease:no-effect-args-inside-dyn-trait, r=compiler-errors
Don't synthesize host effect args inside trait object types

While we were indeed emitting an error for `~const` & `const` trait bounds in trait object types, we were still synthesizing host effect args for them.

Since we don't record the original trait bound modifiers for dyn-Trait in `hir::TyKind::TraitObject` (unlike we do for let's say impl-Trait, `hir::TyKind::OpaqueTy`), AstConv just assumes `ty::BoundConstness::NotConst` in `conv_object_ty_poly_trait_ref` which given `<host> dyn ~const NonConstTrait` resulted in us not realizing that `~const` was used on a non-const trait which lead to a failed assertion in the end.

Instead of updating `hir::TyKind::TraitObject` to track this kind of information, just strip the user-provided constness (similar to #119505).

Fixes #119524.
2024-01-04 08:33:26 +01:00
Matthias Krüger
0db26e081d
Rollup merge of #119539 - vuittont60:master, r=TaKO8Ki
Fix typos
2024-01-04 08:33:25 +01:00
Matthias Krüger
15c3abde1f
Rollup merge of #119417 - compiler-errors:closure-checking, r=davidtwco
Uplift some miscellaneous coroutine-specific machinery into `check_closure`

This PR uplifts some of the logic in `check_fn` that is specific to checking coroutines, which always flows through `check_closure`.

This is just some miscellaneous clean up that I've wanted to do, especially because I'm poking around this code to make it work for async closures.
2024-01-04 08:33:25 +01:00
Matthias Krüger
3325ba640c
Rollup merge of #119397 - ShE3py:pat-range-paren-recovery, r=fmease
Recover parentheses in range patterns

Before:
```rs
match n {
    (0).. => (),
    _ => ()
}
```
```
error: expected one of `=>`, `if`, or `|`, found `..`
 --> src/lib.rs:3:12
  |
3 |         (0).. => (),
  |            ^^ expected one of `=>`, `if`, or `|`
  ```
 After:
```
error: range pattern bounds cannot have parentheses
 --> main.rs:3:5
  |
3 |     (0).. => (),
  |     ^ ^
  |
help: remove these parentheses
  |
3 -     (0).. => (),
3 +     0.. => (),
  |
```

This sets the groundwork for #118625, which will extend the recovery to expressions like `(0 + 1)..` where users may tend to add parentheses to avoid dealing with precedence.

---

```@rustbot``` label +A-parser +A-patterns +A-diagnostics
2024-01-04 08:33:24 +01:00
Matthias Krüger
6526b164a3
Rollup merge of #119362 - estebank:restrict-derive-suggestion, r=fmease
Make `derive(Trait)` suggestion more accurate

Only suggest `derive(PartialEq)` when both LHS and RHS types are the same, otherwise the suggestion is not useful.
2024-01-04 08:33:24 +01:00
Matthias Krüger
3fb61ce8cc
Rollup merge of #119204 - petrochenkov:dialoc2, r=WaffleLapkin
macro_rules: Less hacky heuristic for using `tt` metavariable spans

See the big comment on `fn maybe_use_metavar_location` for a more detailed description.
2024-01-04 08:33:23 +01:00
Matthias Krüger
13840b3b1d
Rollup merge of #119195 - asquared31415:named_asm_labels_fix, r=Amanieu
Make named_asm_labels lint not trigger on unicode and trigger on format args

Someone showed me some cursed code that used format args to create named labels, and rustc wasn't linting on that.  Additionally while fixing that, I noticed that Unicode alphabetic characters were being used as part of labels, when they are not actually permitted in labels.

r? ```@Amanieu```
2024-01-04 08:33:22 +01:00
Matthias Krüger
d134a4fe60
Rollup merge of #119026 - devnexen:listener_upd, r=Mark-Simulacrum
std::net::bind using -1 for openbsd which in turn sets it to somaxconn.

trusting platform's SOMAXCONN instead of hardcoding to 128 otherwise.
2024-01-04 08:33:22 +01:00
Matthias Krüger
1f32203fd3
Rollup merge of #118521 - dpaoliello:asan, r=wesleywiser
Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag

This enables address sanitizer for x86_64-pc-windows-msvc and i686-pc-windows-msvc targets when linked with the MSVC linker (link.exe) by leveraging the `/INFERASANLIBS` option to automatically find and link in Microsoft's address sanitizer runtime: <https://learn.microsoft.com/en-us/cpp/sanitizers/asan-runtime?view=msvc-170>

Implements https://github.com/rust-lang/compiler-team/issues/702
Fixes #89339 (for MSVC targets using the MSVC linker only)
Supercedes #89369

Successful x86_64-msvc build showing the sanitizer tests working: https://github.com/rust-lang/rust/actions/runs/7228346880/job/19697628258?pr=118521
2024-01-04 08:33:21 +01:00
bors
090d5eac72 Auto merge of #119542 - lnicola:sync-from-ra2, r=lnicola
Subtree update of `rust-analyzer`

r? ghost
2024-01-04 07:23:39 +00:00
vuittont60
b2db793f30
compiler: fix typos
librustdoc: fix typos
2024-01-04 10:08:54 +08:00
Vadim Petrochenkov
e1d12c8caf macro_rules: Less hacky heuristic for using tt metavariable spans 2024-01-04 03:53:56 +03:00
Esteban Küber
2474b3708a review comments 2024-01-04 00:12:37 +00:00
Esteban Küber
7f795a5221 Make derive(Trait) suggestion more accurate
Only suggest `derive(PartialEq)` when both LHS and RHS types
are the same, otherwise the suggestion is not useful.
2024-01-03 23:49:56 +00:00
Jakub Beránek
0c56ccff04
Add codegen test for RVO on MaybeUninit
Currently, this only works with `-Cpanic=abort`.
2024-01-03 21:18:07 +01:00
bors
139fb22146 Auto merge of #119549 - fmease:rollup-jxvbfes, r=fmease
Rollup of 21 pull requests

Successful merges:

 - #119086 (Query panic!() to useful diagnostic)
 - #119239 (Remove unnecessary arm in `check_expr_yield`)
 - #119298 (suppress change-tracker warnings in CI containers)
 - #119319 (Document that File does not buffer reads/writes)
 - #119434 (rc: Take *const T in is_dangling)
 - #119444 (Rename `TyCtxt::is_closure` to `TyCtxt::is_closure_or_coroutine`)
 - #119474 (Update tracking issue of naked_functions)
 - #119476 (Pretty-print always-const trait predicates correctly)
 - #119477 (rustdoc ui: adjust tooltip z-index to be above sidebar)
 - #119479 (Remove two unused feature gates from rustc_query_impl)
 - #119487 (Minor improvements in comment on `freshen.rs`)
 - #119492 (Update books)
 - #119494 (Deny defaults for higher-ranked generic parameters)
 - #119498 (Update deadlinks of `strict_provenance` lints)
 - #119505 (Don't synthesize host effect params for trait associated functions marked const)
 - #119510 (Report I/O errors from rmeta encoding with emit_fatal)
 - #119512 (Mark myself as back from leave)
 - #119514 (coverage: Avoid a query stability hazard in `function_coverage_map`)
 - #119523 (llvm: Allow `noundef` in codegen tests)
 - #119534 (Update `thread_local` examples to use `local_key_cell_methods`)
 - #119544 (Fix: Properly set vendor in i686-win7-windows-msvc target)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-03 18:37:41 +00:00
bohan
862368db9f fallback visibility for unexpected trait item 2024-01-04 02:02:57 +08:00
Daniel Paoliello
bc3b7c9930 Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag 2024-01-03 10:00:15 -08:00
bors
1a47f5b448 Auto merge of #119485 - weihanglo:update-cargo, r=weihanglo
Update cargo

11 commits in ac6bbb33293d8d424c17ecdb42af3aac25fb7295..add15366eaf3f3eb84717d3b8b71902ca36a7c84
2023-12-26 23:22:08 +0000 to 2024-01-02 03:24:42 +0000
- chore(deps): update gix (rust-lang/cargo#13230)
- chore(deps): update alpine docker tag to v3.19 (rust-lang/cargo#13228)
- rustfix: Support inserting new lines. (rust-lang/cargo#13226)
- Fix fix::fix_in_dependency to not rely on rustc (rust-lang/cargo#13220)
- cleanup: Remove error-format special-case in `cargo fix` (rust-lang/cargo#13224)
- `cargo fix`: always inherit the jobserver (rust-lang/cargo#13225)
- Bump cargo-credential to 0.4.3 (rust-lang/cargo#13221)
- `cargo add` - fix for adding features from repository with multiple packages. (rust-lang/cargo#13213)
- Remove repetitive words (rust-lang/cargo#13216)
- Add cargo:rustc-cdylib-link-arg into RESERVED_PREFIXES list (rust-lang/cargo#13212)
- chore(doc): doc for custom subcommands look up. (rust-lang/cargo#13203)
2024-01-03 16:39:17 +00:00
León Orell Valerian Liehr
9b2a44adc2
Rollup merge of #119544 - roblabla:new-win7-targets, r=Nilstrieb
Fix: Properly set vendor in i686-win7-windows-msvc target

In #118150 , setting the `vendor` field of the `i686-win7-windows-msvc` target was forgotten, preventing us from easily checking the target using `cfg(target_vendor)`.

With this PR, we set the target vendor to "win7".
2024-01-03 16:08:33 +01:00
León Orell Valerian Liehr
a79fccc288
Rollup merge of #119534 - tgross35:thread-local-example-updates, r=JohnTitor
Update `thread_local` examples to use `local_key_cell_methods`

`local_key_cell_methods` has been stable for a while and provides a much less clunky way to interface with thread-local

Additionaly add context to the documentation about why types with interior mutability are needed.

r? libs
2024-01-03 16:08:33 +01:00
León Orell Valerian Liehr
fcec407f4a
Rollup merge of #119523 - maurer:fix-sparc-llvm-18, r=nikic
llvm: Allow `noundef` in codegen tests

LLVM 18 will automatically infer `noundef` in some situations. Adjust codegen tests to accept this.

See llvm/llvm-project#76553 for why `noundef` is being generated now.

``@rustbot`` label:+llvm-main
2024-01-03 16:08:32 +01:00
León Orell Valerian Liehr
ea39f19fab
Rollup merge of #119514 - Zalathar:query-stability, r=wesleywiser
coverage: Avoid a query stability hazard in `function_coverage_map`

When #118865 started enforcing the `rustc::potential_query_instability` lint in `rustc_codegen_llvm`, it added an exemption for this site, arguing that the entries are only used to create a list of filenames that is later sorted.

However, the list of entries also gets traversed when creating the function coverage records in LLVM IR, which may be sensitive to hash-based ordering.

This patch therefore changes `function_coverage_map` to use `FxIndexMap`, which should avoid hash-based instability by iterating in insertion order.

cc ``@Enselic``
2024-01-03 16:08:32 +01:00
León Orell Valerian Liehr
c2debecf98
Rollup merge of #119512 - oli-obk:unleave, r=oli-obk
Mark myself as back from leave
2024-01-03 16:08:31 +01:00
León Orell Valerian Liehr
a34754e7d5
Rollup merge of #119510 - saethlin:fatal-io-errors, r=WaffleLapkin,Nilstrieb
Report I/O errors from rmeta encoding with emit_fatal

https://github.com/rust-lang/rust/issues/119456 reminded me that I never did systematic testing to provoke the out-of-disk ICEs so I grepped through a recent crater run (https://github.com/rust-lang/rust/pull/119440#issuecomment-1873393963) for more out-of-disk ICEs on current master and yep there's 2 in there.

So I finally cooked up a way to provoke for these crashes. I wrote a little `cdylib` crate that has a `#[no_mangle] pub extern "C" fn write` which occasionally reports `ENOSPC`, and prints a backtrace when it does.
<details><summary><strong>code for the dylib</strong></summary>
<p>

```rust
// cargo add libc rand backtrace
use rand::Rng;

#[no_mangle]
pub extern "C" fn write(
    fd: libc::c_int,
    buf: *const libc::c_void,
    count: libc::size_t,
) -> libc::ssize_t {
    if fd > 2 && rand::thread_rng().gen::<u8>() == 0 {
        let mut count = 0;
        backtrace::trace(|frame| {
            backtrace::resolve_frame(frame, |symbol| {
                if let Some(name) = symbol.name() {
                    if count > 3 {
                        eprintln!("{}", name);
                    }
                }
                count += 1;
            });
            true
        });

        unsafe {
            *libc::__errno_location() = libc::ENOSPC;
        }
        return -1;
    } else {
        unsafe {
            let res =
                libc::syscall(libc::SYS_write, fd as usize, buf as usize, count as usize) as isize;
            if res < 0 {
                *libc::__errno_location() = -res as i32;
                -1
            } else {
                res
            }
        }
    }
}
```

</p>
</details>

Then `LD_PRELOAD` that dylib and repeatedly build a big project until it ICEs, such as with this:
```bash
while true; do
    cargo clean
    LD_PRELOAD=/home/ben/evil/target/release/libevil.so cargo +stage1 check 2> errors
    if grep "thread 'rustc' panicked" errors; then
        break
    fi
done
```
My "big project" for testing was an otherwise-empty project with `cargo add axum`.

Before this PR, the above procedure finds a crash in between 1 and 15 minutes. With this PR, I have not found a crash in 30 minutes, and I'll be leaving this to run overnight (starting now). (A night has now passed, no crashes were found)

I believe the problem is that even though since https://github.com/rust-lang/rust/pull/117301 we correctly check `FileEncoder` for errors on all paths, we use `emit_err`, so there is a window of time between the call to `emit_err` and the full error reporting where rustc believes it has emitted a valid rmeta file and will permit Cargo to launch a build for a dependent crate. Changing these calls to `emit_fatal` closes that window.

I think there are a number of other cases where `emit_err` has been used instead of the more-correct `emit_fatal` such as e51e98dde6/compiler/rustc_codegen_ssa/src/back/write.rs (L542) but unlike rmeta encoding I am not aware of those cases of those causing problems.

r? ``@WaffleLapkin``
2024-01-03 16:08:31 +01:00