Commit Graph

12705 Commits

Author SHA1 Message Date
bors 5ad98b4026 Auto merge of #129257 - ChrisDenton:rename-null-descriptor, r=jieyouxu
Allow rust staticlib to work with MSVC's /WHOLEARCHIVE

This fixes #129020 by renaming the `__NULL_IMPORT_DESCRIPTOR` to prevent conflicts.

try-job: dist-i686-msvc
2024-08-22 15:53:02 +00:00
bors 8269be147b Auto merge of #129398 - matthiaskrgr:rollup-50l01ry, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #128432 (WASI: forbid `unsafe_op_in_unsafe_fn` for `std::{os, sys}`)
 - #129373 (Add missing module flags for CFI and KCFI sanitizers)
 - #129374 (Use `assert_unsafe_precondition!` in `AsciiChar::digit_unchecked`)
 - #129376 (Change `assert_unsafe_precondition` docs to refer to `check_language_ub`)
 - #129382 (Add `const_cell_into_inner` to `OnceCell`)
 - #129387 (Advise against removing the remaining Python scripts from `tests/run-make`)
 - #129388 (Do not rely on names to find lifetimes.)
 - #129395 (Pretty-print own args of existential projections (dyn-Trait w/ GAT constraints))

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-22 08:20:49 +00:00
Matthias Krüger 9d39b59862
Rollup merge of #129395 - fmease:pp-dyn-w-gat, r=compiler-errors
Pretty-print own args of existential projections (dyn-Trait w/ GAT constraints)

Previously we would just drop them. This bug isn't that significant as it can only be triggered by user code that constrains GATs inside trait object types which is currently gated under the interim feature `generic_associated_types_extended` (whose future is questionable) or on stable if the GATs are 'disabled' in dyn-Trait via `where Self: Sized` (in which case the assoc type bindings get ignored anyway (and trigger the warn-by-default lint `unused_associated_type_bounds`)), so yeah.

Affects diagnostic output and output of `std::any::type_name{_of_val}`.
2024-08-22 08:17:23 +02:00
Matthias Krüger 8b3ca7918c
Rollup merge of #129388 - cjgillot:region-def-id, r=compiler-errors
Do not rely on names to find lifetimes.

For some reason, we were trying to find the lifetime parameter from its name, instead of using the def_id we have.

This PR uses it instead. This changes some ui tests, I think to be more sensible.
2024-08-22 08:17:23 +02:00
Matthias Krüger d24e6b7e61
Rollup merge of #129387 - Zalathar:python-apologia, r=jieyouxu
Advise against removing the remaining Python scripts from `tests/run-make`

After some recent PRs (e.g. #129185), there are only two Python scripts left in `tests/run-make`.

Having come so far, it's tempting to try to get rid of the remaining ones. But after trying that myself, I've come to the conclusion that it's not worth the extra hassle, especially if it means pulling in an XML-parsing crate just for one test.

This PR therefore leaves behind a few signpost comments to explain why getting rid of these particular scripts has low value.
2024-08-22 08:17:22 +02:00
Matthias Krüger 8f2c4d18e1
Rollup merge of #129373 - samitolvanen:cfi-module-flags, r=compiler-errors
Add missing module flags for CFI and KCFI sanitizers

Set the cfi-normalize-integers and kcfi-offset module flags when Control-Flow Integrity sanitizers are used, so functions generated by the LLVM backend use the same CFI/KCFI options as rustc.

cfi-normalize-integers tells LLVM to also use integer normalization for generated functions when -Zsanitizer-cfi-normalize-integers is used.

kcfi-offset specifies the number of prefix nops between the KCFI type hash and the function entry when -Z patchable-function-entry is used. Note that LLVM assumes all indirectly callable functions use the same number of prefix NOPs with -Zsanitizer=kcfi.
2024-08-22 08:17:20 +02:00
bors 739b1fdb15 Auto merge of #129365 - matthiaskrgr:rollup-ebwx6ya, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #127279 (use old ctx if has same expand environment during decode span)
 - #127945 (Implement `debug_more_non_exhaustive`)
 - #128941 ( Improve diagnostic-related lints: `untranslatable_diagnostic` & `diagnostic_outside_of_impl`)
 - #129070 (Point at explicit `'static` obligations on a trait)
 - #129187 (bootstrap: fix clean's remove_dir_all implementation)
 - #129231 (improve submodule updates)
 - #129264 (Update `library/Cargo.toml` in weekly job)
 - #129284 (rustdoc: animate the `:target` highlight)
 - #129302 (compiletest: use `std::fs::remove_dir_all` now that it is available)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-22 05:17:27 +00:00
León Orell Valerian Liehr 080c2ca2dc
Pretty-print own args of existential projections 2024-08-22 06:22:36 +02:00
Camille GILLOT ca7c55f050 Do not rely on names to find lifetimes. 2024-08-22 02:20:05 +00:00
Zalathar 34cdfc9b49 Advise against removing `run-make/libtest-junit/validate_junit.py`
Trying to get rid of this Python script looks tempting, because it's currently
the only Python script in the whole `run-make` suite that we actually run.

But getting rid of it would require pulling in a Rust crate to parse XML
instead, and that's probably not worth the extra hassle for a relatively-minor
test.
2024-08-22 12:13:25 +10:00
Zalathar 5fc562c5b1 Rename `foo.py` to `my_gdb_script.py`
This makes it easier for maintainers to see what the Python script is for.
2024-08-22 11:52:21 +10:00
Zalathar 7232a07f5a Explain the `run-make/debugger-visualizer-dep-info` Python script 2024-08-22 11:51:02 +10:00
Sami Tolvanen 40f1d9d154 Add missing module flags for CFI and KCFI sanitizers
Set the cfi-normalize-integers and kcfi-offset module flags when
Control-Flow Integrity sanitizers are used, so functions generated by
the LLVM backend use the same CFI/KCFI options as rustc.

cfi-normalize-integers tells LLVM to also use integer normalization
for generated functions when -Zsanitizer-cfi-normalize-integers is
used.

kcfi-offset specifies the number of prefix nops between the KCFI
type hash and the function entry when -Z patchable-function-entry is
used. Note that LLVM assumes all indirectly callable functions use the
same number of prefix NOPs with -Zsanitizer=kcfi.
2024-08-21 20:23:56 +00:00
Matthias Krüger 00e109f3d4
Rollup merge of #129364 - jswrenn:transmute-layout-errs, r=compiler-errors
safe transmute: gracefully bubble-up layout errors

Changes `.unwrap()`s to `?` to avoid ICEs. Adds ui tests.

Fixes #129327

Tracking Issue: https://github.com/rust-lang/rust/issues/99571

r​? `@compiler-errors`
2024-08-21 21:58:29 +02:00
Matthias Krüger 5a93c74a02
Rollup merge of #128727 - RalfJung:conflicting-repr-future-incompat, r=lcnr
bump conflicting_repr_hints lint to be shown in dependencies

This has been a future compatibility lint for years, let's bump it up to be shown in dependencies (so that hopefully we can then make it a hard error fairly soon).

Cc https://github.com/rust-lang/rust/issues/68585
2024-08-21 21:58:27 +02:00
Jack Wrenn e2328ebd7f safe transmute: gracefully bubble-up layout errors
Changes `.unwrap()`s to `?` to avoid ICEs. Adds ui tests.

Fixes #129327
2024-08-21 18:06:02 +00:00
Matthias Krüger ade33251f1
Rollup merge of #129284 - notriddle:notriddle/animate-target=light, r=GuillaumeGomez
rustdoc: animate the `:target` highlight

This approach is, roughly, based on how Discourse does it. It came up while discussing [some other possible sidebar changes](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/Moving.20deprecated.20items.20out.20of.20the.20way), as a design that made rapid scanning easier while avoiding the inherent trade-offs in summarizing.

https://github.com/user-attachments/assets/f7a8fec3-70a5-40a1-92ea-bfdffbd61c22
2024-08-21 19:35:14 +02:00
Matthias Krüger ffdbd9d6c8
Rollup merge of #129070 - estebank:static-trait, r=davidtwco
Point at explicit `'static` obligations on a trait

Given `trait Any: 'static` and a `struct` with a `Box<dyn Any + 'a>` field, point at the `'static` bound in `Any` to explain why `'a: 'static`.

```
error[E0478]: lifetime bound not satisfied
   --> f202.rs:2:12
    |
2   |     value: Box<dyn std::any::Any + 'a>,
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: lifetime parameter instantiated with the lifetime `'a` as defined here
   --> f202.rs:1:14
    |
1   | struct Hello<'a> {
    |              ^^
note: but lifetime parameter must outlive the static lifetime
   --> /home/gh-estebank/rust/library/core/src/any.rs:113:16
    |
113 | pub trait Any: 'static {
    |                ^^^^^^^
```

Partially address #33652.
2024-08-21 19:35:12 +02:00
Matthias Krüger 47af700fe6
Rollup merge of #128941 - GrigorenkoPV:internal-diagnostic-lints, r=davidtwco
Improve diagnostic-related lints: `untranslatable_diagnostic` & `diagnostic_outside_of_impl`

Summary:
- Made `untranslatable_diagnostic` point to problematic arguments instead of the function call
  (I found this misleading while working on some `A-translation` PRs: my first impression was that
  the methods themselves were not translation-aware and needed to be changed,
  while in reality the problem was with the hardcoded strings passed as arguments).
- Made the shared pass of `untranslatable_diagnostic` & `diagnostic_outside_of_impl` more efficient.

`@rustbot` label D-imprecise-spans A-translation
2024-08-21 19:35:11 +02:00
Matthias Krüger 221b53c9b0
Rollup merge of #127279 - bvanjoi:fix-112680, r=petrochenkov
use old ctx if has same expand environment during decode span

Fixes #112680

The root reason why #112680 failed with incremental compilation on the second attempt is the difference in `opaque` between the span of the field [`ident`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_hir_typeck/src/expr.rs#L2348) and the span in the incremental cache at `tcx.def_ident_span(field.did)`.

-  Let's call the span of `ident` as `span_a`, which is generated by [`apply_mark_internal`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/hygiene.rs#L553-L554). Its content is similar to:

```rs
span_a_ctx -> SyntaxContextData {
      opaque: span_a_ctx,
      opaque_and_semitransparent: span_a_ctx,
      // ....
}
```

- And call the span of `tcx.def_ident_span` as `span_b`, which is generated by [`decode_syntax_context`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/hygiene.rs#L1390). Its content is:

```rs
span_b_ctx -> SyntaxContextData {
      opaque: span_b_ctx,
      // note `span_b_ctx` is not same as `span_a_ctx`
      opaque_and_semitransparent: span_b_ctx,
      // ....
}
```

Although they have the same `parent` (both refer to the root) and `outer_expn`, I cannot find the specific connection between them. Therefore, I chose a solution that may not be the best: give up the incremental compile cache to ensure we can use `span_a` in this case.

r?  `@petrochenkov` Do you have any advice on this? Or perhaps this solution is acceptable?
2024-08-21 19:35:10 +02:00
Esteban Küber f5bae722be Point at explicit `'static` obligations on a trait
Given `trait Any: 'static` and a `struct` with a `Box<dyn Any + 'a>` field, point at the `'static` bound in `Any` to explain why `'a: 'static`.

```
error[E0478]: lifetime bound not satisfied
   --> f202.rs:2:12
    |
2   |     value: Box<dyn std::any::Any + 'a>,
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: lifetime parameter instantiated with the lifetime `'a` as defined here
   --> f202.rs:1:14
    |
1   | struct Hello<'a> {
    |              ^^
note: but lifetime parameter must outlive the static lifetime
   --> /home/gh-estebank/rust/library/core/src/any.rs:113:16
    |
113 | pub trait Any: 'static {
    |                ^^^^^^^
```

Partially address #33652.
2024-08-21 16:40:15 +00:00
Matthias Krüger 9bb17d345a
Rollup merge of #129281 - Nadrieril:tweak-unreachable-lint-wording, r=estebank
Tweak unreachable lint wording

Some tweaks to the notes added in https://github.com/rust-lang/rust/pull/128034.

r? `@estebank`
2024-08-21 18:15:03 +02:00
Matthias Krüger 7da4b2d82a
Rollup merge of #129179 - compiler-errors:cfi-erase-transparent, r=davidtwco
CFI: Erase regions when projecting ADT to its transparent non-1zst field

The output from `FieldDef::ty` (or `TyCtxt::type_of`) may have free regions (well, `'static`) -- erase it.

Fixes #129169
Fixes #123685
2024-08-21 18:15:02 +02:00
Matthias Krüger dea325e583
Rollup merge of #128627 - khuey:DUMMY_SP-line-no, r=nnethercote
Special case DUMMY_SP to emit line 0/column 0 locations on DWARF platforms.

Line 0 has a special meaning in DWARF. From the version 5 spec:

    The compiler may emit the value 0 in cases
    where an instruction cannot be attributed to any
    source line.

DUMMY_SP spans cannot be attributed to any line. However, because rustc internally stores line numbers starting at zero, lookup_debug_loc() adjusts every line number by one. Special casing DUMMY_SP to actually emit line 0 ensures rustc communicates to the debugger that there's no meaningful source code for this instruction, rather than telling the debugger to jump to line 1 randomly.
2024-08-21 18:15:01 +02:00
Matthias Krüger d502b1c8e4
Rollup merge of #129270 - compiler-errors:inner-generics-shadowing, r=petrochenkov
Don't consider locals to shadow inner items' generics

We don't want to consider the bindings from a `RibKind::Module` itself, because for an inner item that module will contain the local bindings from the function body or wherever else the inner item is being defined.

Fixes #129265

r? petrochenkov
2024-08-20 22:21:57 +02:00
Matthias Krüger 2e58d62fec
Rollup merge of #128932 - bvanjoi:issue-128813, r=petrochenkov
skip updating when external binding is existed

Fixes #128813

For following code:

```rs
extern crate core;

fn f() {
    use ::core;
}

macro_rules! m {
    () => {
        extern crate std as core;
    };
}

m!();

fn main() {}
```

- In the first loop, we define `extern crate core` and `use ::core` will be referred to `core` (yes, it does not consider if there are some macros that are not expanded. Ideally, this should be delayed if there are some unexpanded macros in the root, but I didn't change it like that because it seems like a huge change).
- Then `m` is expanded, which makes `extern_prelude('core')` return `std` rather than `core`, causing the inconsistency.

r? `@petrochenkov`
2024-08-20 22:21:56 +02:00
Nadrieril f30392a985 Move the "matches no value" note to be a span label 2024-08-20 21:53:47 +02:00
Ding Xiang Fei ef25fbd0b4
lint on tail expr drop order change in Edition 2024 2024-08-21 01:05:21 +08:00
bors 4d5b3b1962 Auto merge of #129239 - DianQK:codegen-rustc_intrinsic, r=saethlin
Don't generate functions with the `rustc_intrinsic_must_be_overridden` attribute

Functions with the attribute `rustc_intrinsic_must_be_overridden` never be called.

r? compiler
2024-08-20 14:15:50 +00:00
bohan df019a9f46 skip updating when external binding is existed 2024-08-20 20:34:13 +08:00
bors a971212545 Auto merge of #127672 - compiler-errors:precise-capturing, r=spastorino
Stabilize opaque type precise capturing (RFC 3617)

This PR partially stabilizes opaque type *precise capturing*, which was specified in [RFC 3617](https://github.com/rust-lang/rfcs/pull/3617), and whose syntax was amended by FCP in [#125836](https://github.com/rust-lang/rust/issues/125836).

This feature, as stabilized here, gives us a way to explicitly specify the generic lifetime parameters that an RPIT-like opaque type captures.  This solves the problem of overcapturing, for lifetime parameters in these opaque types, and will allow the Lifetime Capture Rules 2024 ([RFC 3498](https://github.com/rust-lang/rfcs/pull/3498)) to be fully stabilized for RPIT in Rust 2024.

### What are we stabilizing?

This PR stabilizes the use of a `use<'a, T>` bound in return-position impl Trait opaque types.  Such a bound fully specifies the set of generic parameters captured by the RPIT opaque type, entirely overriding the implicit default behavior.  E.g.:

```rust
fn does_not_capture<'a, 'b>() -> impl Sized + use<'a> {}
//                               ~~~~~~~~~~~~~~~~~~~~
//                This RPIT opaque type does not capture `'b`.
```

The way we would suggest thinking of `impl Trait` types *without* an explicit `use<..>` bound is that the `use<..>` bound has been *elided*, and that the bound is filled in automatically by the compiler according to the edition-specific capture rules.

All non-`'static` lifetime parameters, named (i.e. non-APIT) type parameters, and const parameters in scope are valid to name, including an elided lifetime if such a lifetime would also be valid in an outlives bound, e.g.:

```rust
fn elided(x: &u8) -> impl Sized + use<'_> { x }
```

Lifetimes must be listed before type and const parameters, but otherwise the ordering is not relevant to the `use<..>` bound.  Captured parameters may not be duplicated.  For now, only one `use<..>` bound may appear in a bounds list.  It may appear anywhere within the bounds list.

### How does this differ from the RFC?

This stabilization differs from the RFC in one respect: the RFC originally specified `use<'a, T>` as syntactically part of the RPIT type itself, e.g.:

```rust
fn capture<'a>() -> impl use<'a> Sized {}
```

However, settling on the final syntax was left as an open question.  T-lang later decided via FCP in [#125836](https://github.com/rust-lang/rust/issues/125836) to treat `use<..>` as a syntactic bound instead, e.g.:

```rust
fn capture<'a>() -> impl Sized + use<'a> {}
```

### What aren't we stabilizing?

The key goal of this PR is to stabilize the parts of *precise capturing* that are needed to enable the migration to Rust 2024.

There are some capabilities of *precise capturing* that the RFC specifies but that we're not stabilizing here, as these require further work on the type system.  We hope to lift these limitations later.

The limitations that are part of this PR were specified in the [RFC's stabilization strategy](https://rust-lang.github.io/rfcs/3617-precise-capturing.html#stabilization-strategy).

#### Not capturing type or const parameters

The RFC addresses the overcapturing of type and const parameters; that is, it allows for them to not be captured in opaque types.  We're not stabilizing that in this PR.  Since all in scope generic type and const parameters are implicitly captured in all editions, this is not needed for the migration to Rust 2024.

For now, when using `use<..>`, all in scope type and const parameters must be nameable (i.e., APIT cannot be used) and included as arguments.  For example, this is an error because `T` is in scope and not included as an argument:

```rust
fn test<T>() -> impl Sized + use<> {}
//~^ ERROR `impl Trait` must mention all type parameters in scope in `use<...>`
```

This is due to certain current limitations in the type system related to how generic parameters are represented as captured (i.e. bivariance) and how inference operates.

We hope to relax this in the future, and this stabilization is forward compatible with doing so.

#### Precise capturing for return-position impl Trait **in trait** (RPITIT)

The RFC specifies precise capturing for RPITIT.  We're not stabilizing that in this PR.  Since RPITIT already adheres to the Lifetime Capture Rules 2024, this isn't needed for the migration to Rust 2024.

The effect of this is that the anonymous associated types created by RPITITs must continue to capture all of the lifetime parameters in scope, e.g.:

```rust
trait Foo<'a> {
    fn test() -> impl Sized + use<Self>;
    //~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
}
```

To allow this involves a meaningful amount of type system work related to adding variance to GATs or reworking how generics are represented in RPITITs.  We plan to do this work separately from the stabilization.  See:

- https://github.com/rust-lang/rust/pull/124029

Supporting precise capturing for RPITIT will also require us to implement a new algorithm for detecting refining capture behavior.  This may involve looking through type parameters to detect cases where the impl Trait type in an implementation captures fewer lifetimes than the corresponding RPITIT in the trait definition, e.g.:

```rust
trait Foo {
    fn rpit() -> impl Sized + use<Self>;
}

impl<'a> Foo for &'a () {
    // This is "refining" due to not capturing `'a` which
    // is implied by the trait's `use<Self>`.
    fn rpit() -> impl Sized + use<>;

    // This is not "refining".
    fn rpit() -> impl Sized + use<'a>;
}
```

This stabilization is forward compatible with adding support for this later.

### The technical details

This bound is purely syntactical and does not lower to a [`Clause`](https://doc.rust-lang.org/1.79.0/nightly-rustc/rustc_middle/ty/type.ClauseKind.html) in the type system.  For the purposes of the type system (and for the types team's curiosity regarding this stabilization), we have no current need to represent this as a `ClauseKind`.

Since opaques already capture a variable set of lifetimes depending on edition and their syntactical position (e.g. RPIT vs RPITIT), a `use<..>` bound is just a way to explicitly rather than implicitly specify that set of lifetimes, and this only affects opaque type lowering from AST to HIR.

### FCP plan

While there's much discussion of the type system here, the feature in this PR is implemented internally as a transformation that happens before lowering to the type system layer.  We already support impl Trait types partially capturing the in scope lifetimes; we just currently only expose that implicitly.

So, in my (errs's) view as a types team member, there's nothing for types to weigh in on here with respect to the implementation being stabilized, and I'd suggest a lang-only proposed FCP (though we'll of course CC the team below).

### Authorship and acknowledgments

This stabilization report was coauthored by compiler-errors and TC.

TC would like to acknowledge the outstanding and speedy work that compiler-errors has done to make this feature happen.

compiler-errors thanks TC for authoring the RFC, for all of his involvement in this feature's development, and pushing the Rust 2024 edition forward.

### Open items

We're doing some things in parallel here.  In signaling the intention to stabilize, we want to uncover any latent issues so we can be sure they get addressed.  We want to give the maximum time for discussion here to happen by starting it while other remaining miscellaneous work proceeds.  That work includes:

- [x] Look into `syn` support.
  - https://github.com/dtolnay/syn/issues/1677
  - https://github.com/dtolnay/syn/pull/1707
- [x] Look into `rustfmt` support.
  - https://github.com/rust-lang/rust/pull/126754
- [x] Look into `rust-analyzer` support.
  - https://github.com/rust-lang/rust-analyzer/issues/17598
  - https://github.com/rust-lang/rust-analyzer/pull/17676
- [x] Look into `rustdoc` support.
  - https://github.com/rust-lang/rust/issues/127228
  - https://github.com/rust-lang/rust/pull/127632
  - https://github.com/rust-lang/rust/pull/127658
- [x] Suggest this feature to RfL (a known nightly user).
- [x] Add a chapter to the edition guide.
  - https://github.com/rust-lang/edition-guide/pull/316
- [x] Update the Reference.
  - https://github.com/rust-lang/reference/pull/1577

### (Selected) implementation history

* https://github.com/rust-lang/rfcs/pull/3498
* https://github.com/rust-lang/rfcs/pull/3617
* https://github.com/rust-lang/rust/pull/123468
* https://github.com/rust-lang/rust/issues/125836
* https://github.com/rust-lang/rust/pull/126049
* https://github.com/rust-lang/rust/pull/126753

Closes #123432.

cc `@rust-lang/lang` `@rust-lang/types`

`@rustbot` labels +T-lang +I-lang-nominated +A-impl-trait +F-precise_capturing

Tracking:

- https://github.com/rust-lang/rust/issues/123432

----

For the compiler reviewer, I'll leave some inline comments about diagnostics fallout :^)

r? compiler
2024-08-20 10:42:55 +00:00
Michael Howell 9d7574f9b0 rustdoc: animate the `:target` highlight
This approach is, roughly, based on how Discourse does it.
It came up while discussing some other possible sidebar changes,
as a design that made rapid scanning easier while avoiding the
inherent trade-offs in summarizing.
2024-08-19 18:14:35 -07:00
Kyle Huey 3c735a00f7 Add a test. 2024-08-19 17:10:43 -07:00
bors 79611d90b6 Auto merge of #122551 - RayMuir:copy_fmt, r=saethlin
Added "copy" to Debug fmt for copy operands

In MIR's debug mode (--emit mir) the printing for Operands is slightly inconsistent.

The RValues - values on the right side of an Assign - are usually printed with their Operand when they are Places.

Example:
_2 = move _3

But for arguments, the operand is omitted.

_2 = _1

I propose a change be made, to display the place with the operand.

_2 = copy _1

Move and copy have different semantics, meaning this difference is important and helpful to the user. It also adds consistency to the pretty printing.

-- EDIT --

 Consider this example Rust program and its MIR output with the **updated pretty printer.**

This was generated with the arguments --emit mir --crate-type lib -Zmir-opt-level=0 (Otherwise, it's optimised away since it's a junk program).

```rust
fn main(foo: i32) {
    let v = 10;

    if v == 20 {
        foo;
    }
    else {
        v;
    }
}
```

```MIR
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn main(_1: i32) -> () {
    debug foo => _1;
    let mut _0: ();
    let _2: i32;
    let mut _3: bool;
    let mut _4: i32;
    let _5: i32;
    let _6: i32;
    scope 1 {
        debug v => _2;
    }

    bb0: {
        StorageLive(_2);
        _2 = const 10_i32;
        StorageLive(_3);
        StorageLive(_4);
        _4 = copy _2;
        _3 = Eq(move _4, const 20_i32);
        switchInt(move _3) -> [0: bb2, otherwise: bb1];
    }

    bb1: {
        StorageDead(_4);
        StorageLive(_5);
        _5 = copy _1;
        StorageDead(_5);
        _0 = const ();
        goto -> bb3;
    }

    bb2: {
        StorageDead(_4);
        StorageLive(_6);
        _6 = copy _2;
        StorageDead(_6);
        _0 = const ();
        goto -> bb3;
    }

    bb3: {
        StorageDead(_3);
        StorageDead(_2);
        return;
    }
}
```

In this example program, we can see that when we move a place, it is preceded by "move". e.g. ``` _3 = Eq(move _4, const 20_i32);```. However, when we copy a place such as ```_5 = _1;```, it is not preceded by the operand in the original printout. I propose to change the print to include the copy ```_5 = copy _1``` as in this example.

Regarding the arguments part. When I originally submitted this PR, I was under the impression this only affected the print for arguments to a function, but actually, it affects anything that uses a copy. This is preferable anyway with regard to consistency. The PR is about making ```copy``` explicit.
2024-08-19 23:10:46 +00:00
Michael Goulet 78d0e08504 Don't consider RibKind::Module's bindings when checking generics shadowing 2024-08-19 17:24:27 -04:00
Nadrieril 36eced444e Cap the number of patterns pointed to by the lint 2024-08-19 21:57:40 +02:00
Nadrieril efb28bdd90 Add a note with a link to explain empty types 2024-08-19 21:57:37 +02:00
Nadrieril 25964b541e Reword the "unreachable pattern" explanations 2024-08-19 21:39:57 +02:00
Chris Denton 76fbf0af77
Test wholearchive on rust staticlib 2024-08-19 18:26:55 +00:00
Matthias Krüger 7b245e4506
Rollup merge of #129235 - GoldsteinE:check-may-dangle, r=compiler-errors
Check that `#[may_dangle]` is properly applied

It's only valid when applied to a type or lifetime parameter in `Drop` trait implementation.

Tracking issue: https://github.com/rust-lang/rust/issues/34761
cc https://github.com/rust-lang/rust/issues/34761#issuecomment-1208185551
2024-08-19 20:14:57 +02:00
Matthias Krüger 5ba877c262
Rollup merge of #129223 - wafarm:fix-129215, r=compiler-errors
Fix wrong argument for `get_fn_decl`

Closes #129215 (seems to be introduced in #129168)
2024-08-19 20:14:57 +02:00
Matthias Krüger 5cb30b7e9d
Rollup merge of #129217 - jswrenn:transmute-lifetimes, r=compiler-errors
safe transmute: check lifetimes

Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag.

Fixes #129097

Tracking Issue: https://github.com/rust-lang/rust/issues/99571

 r​? `@compiler-errors`
2024-08-19 20:14:56 +02:00
bors 4fe1e2bd5b Auto merge of #129218 - saethlin:gdb-supports-rust-now, r=jieyouxu
Delete debuginfo test suite infra for gdb without Rust support and lldb with Rust support

Implements https://github.com/rust-lang/rust/issues/128953

I also deleted all the `min-lldb-version: 310` comments, because the oldest compatible distro I can find is Ubuntu 16.04 which ships lldb 3.8, though of course the package that the Ubuntu maintainers put together for that is broken.

Rocky Linux 8 amusingly ships lldb 17, even though it has a similar glibc and kernel version.

This PR is multiple highly mechanical changes. Some of the commits were created by just running `sed`. You may find it easier to review each commit separately.
2024-08-19 12:16:20 +00:00
bors 45fbf41deb Auto merge of #128722 - tgross35:new-resolver-root, r=Mark-Simulacrum
Switch to using the v2 resolver in most workspaces

Pinning the resolver to v1 was done in 5abff3753a ("Explicit set workspace.resolver ...") in order to suppress warnings. Since there is no specific reason not to use the new resolver and since it fixes issues, change to `resolver = "2"` everywhere except library.
2024-08-19 09:50:33 +00:00
Trevor Gross 8a513f1720
Rollup merge of #129208 - veluca93:adt_const_fix, r=BoxyUwU
Fix order of normalization and recursion in const folding.

Fixes #126831.

Without this patch, type normalization is not always idempotent, which leads to all sorts of bugs in places that assume that normalizing a normalized type does nothing.

Tracking issue: https://github.com/rust-lang/rust/issues/95174

r? BoxyUwU
2024-08-18 23:41:49 -05:00
Trevor Gross d21b6f2715
Rollup merge of #128084 - surechen:fix_125997_v1, r=cjgillot
Suggest adding Result return type for associated method in E0277.

Recommit #126515 because I messed up during rebase,

Suggest adding Result return type for associated method in E0277.

For following:

```rust
struct A;
impl A {
    fn test4(&self) {
        let mut _file = File::create("foo.txt")?;
        //~^ ERROR the `?` operator can only be used in a method
    }
```

Suggest:

```rust
impl A {
    fn test4(&self) -> Result<(), Box<dyn std::error::Error>> {
        let mut _file = File::create("foo.txt")?;
        //~^ ERROR the `?` operator can only be used in a method

    Ok(())
    }
}
```

For #125997

r? `@cjgillot`
2024-08-18 23:41:46 -05:00
Trevor Gross f27a9b15d3
Rollup merge of #127679 - RalfJung:raw_ref_op, r=jieyouxu
Stabilize `raw_ref_op` (RFC 2582)

This stabilizes the syntax `&raw const $expr` and `&raw mut $expr`. It has existed unstably for ~4 years now, and has been exposed on stable via the `addr_of` and `addr_of_mut` macros since Rust 1.51 (released more than 3 years ago). I think it has become clear that these operations are here to stay. So it is about time we give them proper primitive syntax. This has two advantages over the macro:

- Being macros, `addr_of`/`addr_of_mut` could in theory do arbitrary magic with the expression on which they work. The only "magic" they actually do is using the argument as a place expression rather than as a value expression. Place expressions are already a subtle topic and poorly understood by many programmers; having this hidden behind a macro using unstable language features makes this even worse. Conversely, people do have an idea of what happens below `&`/`&mut`, so we can make the subtle topic a lot more approachable by connecting to existing intuition.
- The name `addr_of` is quite unfortunate from today's perspective, given that we have accepted provenance as a reality, which means that a pointer is *not* just an address. Strict provenance has a method, `addr`, which extracts the address of a pointer; using the term `addr` in two different ways is quite unfortunate. That's why this PR soft-deprecates `addr_of` -- we will wait a long time before actually showing any warning here, but we should start telling people that the "addr" part of this name is somewhat misleading, and `&raw` avoids that potential confusion.

In summary, this syntax improves developers' ability to conceptualize the operational semantics of Rust, while making a fundamental operation frequently used in unsafe code feel properly built in.

Possible questions to consider, based on the RFC and [this](https://github.com/rust-lang/rust/issues/64490#issuecomment-1163802912) great summary by `@CAD97:`

- Some questions are entirely about the semantics. The semantics are the same as with the macros so I don't think this should have any impact on this syntax PR. Still, for completeness' sake:
  - Should `&raw const *mut_ref` give a read-only pointer?
    - Tracked at: https://github.com/rust-lang/unsafe-code-guidelines/issues/257
    - I think ideally the answer is "no". Stacked Borrows says that pointer is read-only, but Tree Borrows says it is mutable.
  - What exactly does `&raw const (*ptr).field` require? Answered in [the reference](https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html): the arithmetic to compute the field offset follows the rules of `ptr::offset`, making it UB if it goes out-of-bounds. Making this a safe operation (using `wrapping_offset` rules) is considered too much of a loss for alias analysis.
- Choose a different syntax? I don't want to re-litigate the RFC. The only credible alternative that has been proposed is `&raw $place` instead of `&raw const $place`, which (IIUC) could be achieved by making `raw` a contextual keyword in a new edition. The type is named `*const T`, so the explicit `const` is consistent in that regard. `&raw expr` lacks the explicit indication of immutability. However, `&raw const expr` is quite a but longer than `addr_of!(expr)`.
- Shouldn't we have a completely new, better raw pointer type instead? Yes we all want to see that happen -- but I don't think we should block stabilization on that, given that such a nicer type is not on the horizon currently and given the issues with `addr_of!` mentioned above. (If we keep the `&raw $place` syntax free for this, we could use it in the future for that new type.)
- What about the lint the RFC talked about? It hasn't been implemented yet.  Given that the problematic code is UB with or without this stabilization, I don't think the lack of the lint should block stabilization.
  - I created an issue to track adding it: https://github.com/rust-lang/rust/issues/127724
- Other points from the "future possibilites of the RFC
  - "Syntactic sugar" extension: this has not been implemented. I'd argue this is too confusing, we should stick to what the RFC suggested and if we want to do anything about such expressions, add the lint.
  - Encouraging / requiring `&raw` in situations where references are often/definitely incorrect: this has been / is being implemented. On packed fields this already is a hard error, and for `static mut` a lint suggesting raw pointers is being rolled out.
  - Lowering of casts: this has been implemented. (It's also an invisible implementation detail.)
  - `offsetof` woes: we now have native `offset_of` so this is not relevant any more.

To be done before landing:

- [x] Suppress `unused_parens` lint around `&raw {const|mut}` expressions
  - See bottom of https://github.com/rust-lang/rust/pull/127679#issuecomment-2264073752 for rationale
  - Implementation: https://github.com/rust-lang/rust/pull/128782
- [ ] Update the Reference.
  - https://github.com/rust-lang/reference/pull/1567

Fixes https://github.com/rust-lang/rust/issues/64490

cc `@rust-lang/lang` `@rust-lang/opsem`

try-job: x86_64-msvc
try-job: test-various
try-job: dist-various-1
try-job: armhf-gnu
try-job: aarch64-apple
2024-08-18 23:41:46 -05:00
Trevor Gross 1eb1e1816d Adjust expected errors for a `rustdoc` test
`pulldown-cmark` has slightly different behavior between 0.11.0 and
0.11.2, causing one of the `unportable-markdown` tests to no longer emit
an error. Per [1], remove the error annotation and bless the output.

[1]: https://github.com/rust-lang/rust/pull/128722#issuecomment-2295522292
2024-08-18 22:52:54 -05:00
Wafarm da7dd434c8
Fix wrong argument for `get_fn_decl` 2024-08-19 11:08:51 +08:00
bors 804be74e3c Auto merge of #129228 - matthiaskrgr:oopsie, r=jieyouxu
crashes: more tests

r? `@jieyouxu`
2024-08-19 01:59:36 +00:00