Commit Graph

39901 Commits

Author SHA1 Message Date
David Lattimore
f48194ea55 Replace -Z default-hidden-visibility with -Z default-visibility
MCP: https://github.com/rust-lang/compiler-team/issues/782

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2024-10-01 22:32:13 +10:00
Matthias Krüger
5df1123b39
Rollup merge of #131038 - onkoe:fix/adt_const_params_leak_118179, r=compiler-errors
Fix `adt_const_params` leaking `{type error}` in error msg

Fixes the confusing diagnostic described in #118179. (users would see `{type error}` in some situations, which is pretty weird)

`adt_const_params` tracking issue: #95174
2024-09-30 18:25:14 +02:00
Matthias Krüger
dc1ccc5264
Rollup merge of #131035 - dingxiangfei2009:tweak-if-let-rescope-lint, r=jieyouxu
Preserve brackets around if-lets and skip while-lets

r? `@jieyouxu`

Tracked by #124085

Fresh out of #129466, we have discovered 9 crates that the lint did not successfully migrate because the span of `if let` includes the surrounding brackets `(..)` like the following, which surprised me a bit.

```rust
if (if let .. { .. } else { .. }) {
// ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// the span somehow includes the surrounding brackets
}
```

There is one crate that failed the migration because some suggestion spans cross the macro expansion boundaries. Surely there is no way to patch them with `match` rewrite. To handle this case, we will instead require all spans to be tested for admissibility as suggestion spans.

Besides, there are 4 false negative cases discovered with desugared-`while let`. We don't need to lint them, because the `else` branch surely contains exactly one statement because the drop order is not changed whatsoever in this case.

```rust
while let Some(value) = droppy().get() {
..
}
// is desugared into
loop {
    if let Some(value) = droppy().get() {
        ..
    } else {
        break;
        // here can be nothing observable in this block
    }
}
```

I believe this is the one and only false positive that I have found. I think we have finally nailed all the corner cases this time.
2024-09-30 18:25:14 +02:00
Ding Xiang Fei
ed5443fcdf
apply suggestions 2024-09-30 22:21:45 +08:00
Matthias Krüger
90fdb11f51
Rollup merge of #131057 - Urgau:cfg-erronous-unsafe, r=jieyouxu
Reject leading unsafe in `cfg!(...)` and `--check-cfg`

This PR reject leading unsafe in `cfg!(...)` and `--check-cfg`.

Fixes (after-backport) https://github.com/rust-lang/rust/issues/131055
r? `@jieyouxu`
2024-09-30 14:33:46 +02:00
Urgau
9cb540a13c Reject leading unsafe in cfg!(...) and --check-cfg. 2024-09-30 12:15:08 +02:00
Barrett Ray
c5598d6a9e fix(hir_analysis/wfcheck): don't leak {type error}
avoid `{type error}` being leaked in user-facing messages,
particularly when using the `adt_const_params` feature
2024-09-29 23:40:43 -05:00
bors
4e91cedaed Auto merge of #129499 - fee1-dead-contrib:supereffects, r=compiler-errors
properly elaborate effects implied bounds for super traits

Summary: This PR makes it so that we elaborate `<T as Tr>::Fx: EffectsCompat<somebool>` into `<T as SuperTr>::Fx: EffectsCompat<somebool>` when we know that `trait Tr: ~const SuperTr`.

Some discussion at https://github.com/rust-lang/project-const-traits/issues/2.

r? project-const-traits
`@rust-lang/project-const-traits:` how do we feel about this approach?
2024-09-30 00:30:09 +00:00
Ding Xiang Fei
6d1a25ad7e
preserve brackets around if-lets and skip while-lets 2024-09-30 04:21:10 +08:00
Matthias Krüger
a0ae32d6a2
Rollup merge of #130990 - RalfJung:mir-const-normalize, r=compiler-errors
try to get rid of mir::Const::normalize

It was easy to make this compile, let's see if anything breaks...

r? `@compiler-errors`
2024-09-29 20:17:37 +02:00
Matthias Krüger
a061e566a6
Rollup merge of #130972 - RalfJung:const_cell_into_inner, r=dtolnay
stabilize const_cell_into_inner

This const-stabilizes
- `UnsafeCell::into_inner`
- `Cell::into_inner`
- `RefCell::into_inner`
- `OnceCell::into_inner`

`@rust-lang/wg-const-eval` this uses `rustc_allow_const_fn_unstable(const_precise_live_drops)`, so we'd be comitting to always finding *some* way to accept this code. IMO that's fine -- what these functions do is to move out the only field of a struct, and that struct has no destructor itself. The field's destructor does not get run as it gets returned to the caller.

`@rust-lang/libs-api` this was FCP'd already [years ago](https://github.com/rust-lang/rust/issues/78729#issuecomment-811409860), except that  `OnceCell::into_inner` was added to the same feature gate since then (Cc `@tgross35).` Does that mean we have to re-run the FCP? If yes, I'd honestly prefer to move `OnceCell` into its own feature gate to not risk missing the next release. (That's why it's not great to add new functions to an already FCP'd feature gate.) OTOH if this needs an FCP either way since the previous FCP was so long ago, then we might as well do it all at once.
2024-09-29 20:17:36 +02:00
Matthias Krüger
71c96cc7d5
Rollup merge of #131014 - matthiaskrgr:no_clone_on_copy, r=chenyukang
cleanup: don't clone types that are Copy
2024-09-29 16:51:56 +02:00
Matthias Krüger
af1e24b946
Rollup merge of #131013 - matthiaskrgr:unwrapordefault, r=jieyouxu
cleanup: don't manually `unwrap_or_default()`
2024-09-29 16:51:56 +02:00
Matthias Krüger
128a7d64f8
Rollup merge of #131011 - matthiaskrgr:no_into, r=jieyouxu
cleanup: don't `.into()` identical types
2024-09-29 16:51:55 +02:00
Matthias Krüger
71cd918dc7 cleanup: don't clone types that are Copy 2024-09-29 13:31:30 +02:00
Matthias Krüger
1a28599981 cleanup: don't manually unwrap_or_default() 2024-09-29 12:51:28 +02:00
Matthias Krüger
e963568585 cleanup: don't .into() identical types 2024-09-29 12:18:11 +02:00
Ralf Jung
a78fd694d4 extend comment in global_llvm_features regarding target-cpu=native handling 2024-09-29 12:16:35 +02:00
Ralf Jung
e1c09ec9a5 fix cranelift CI 2024-09-29 07:32:08 +02:00
bors
1d9162bced Auto merge of #129687 - Urgau:rfc3127-sysroot-2, r=jieyouxu
Implement RFC3137 trim-paths sysroot changes - take 2

This PR is a continuation of https://github.com/rust-lang/rust/pull/118149. Nothing really changed, except for https://github.com/rust-lang/rust/pull/129408 which I was able to trigger locally.

Original description:

> Implement parts of #111540
>
> Right now, backtraces into sysroot always shows /rustc/$hash in diagnostics, e.g.
>
> ```
> thread 'main' panicked at 'hello world', map-panic.rs:2:50
> stack backtrace:
>    0: std::panicking::begin_panic
>              at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:616:12
>    1: map_panic::main::{{closure}}
>              at ./map-panic.rs:2:50
>    2: core::option::Option<T>::map
>              at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/option.rs:929:29
>    3: map_panic::main
>              at ./map-panic.rs:2:30
>    4: core::ops::function::FnOnce::call_once
>              at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:248:5
> note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
> ```
>
> [RFC 3127 said](https://rust-lang.github.io/rfcs/3127-trim-paths.html#changing-handling-of-sysroot-path-in-rustc)
>
> > We want to change this behaviour such that, when rust-src source files can be discovered, the virtual path is discarded and therefore the local path will be embedded, unless there is a --remap-path-prefix that causes this local path to be remapped in the usual way.
>
> This PR implements this behaviour. When `rust-src` is present at compile time, rustc replaces /rustc/$hash with a real path into local rust-src with best effort. To sanitise this, users must explicitly supply `--remap-path-prefix=<path to rust-src>=foo`.

cc `@cbeuw`
Fix #105907
Fix #85463

try-job: dist-x86_64-linux
try-job: x86_64-msvc
try-job: dist-x86_64-msvc
try-job: armhf-gnu
2024-09-29 03:04:05 +00:00
Ralf Jung
c55c4c9f9d tweak Const::identity_unevaluated name and docs 2024-09-28 21:28:08 +02:00
Ralf Jung
921a5ef6d7 try to get rid of mir::Const::normalize 2024-09-28 21:15:18 +02:00
Matthias Krüger
2fca8e5ae7
Rollup merge of #130976 - matthiaskrgr:clonee, r=jieyouxu
remove couple redundant clones
2024-09-28 15:11:23 +02:00
Matthias Krüger
cfe0cff5b9
Rollup merge of #130960 - cuviper:cdylib-soname, r=petrochenkov
Only add an automatic SONAME for Rust dylibs

#126094 added an automatic relative `SONAME` to all dynamic libraries, but it was really only needed for Rust `--crate-type="dylib"`. In Fedora, it was a surprise to see `SONAME` on `"cdylib"` libraries like Python modules, especially because that generates an undesirable RPM `Provides`. We can instead add a `SONAME` just for Rust dylibs by passing the crate-type argument farther.

Ref: https://bugzilla.redhat.com/show_bug.cgi?id=2314879
2024-09-28 15:11:22 +02:00
Matthias Krüger
e174b92cb4 remove couple redundant clones 2024-09-28 13:42:37 +02:00
bors
612796c420 Auto merge of #130964 - matthiaskrgr:rollup-suriuub, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #125404 (Fix `read_buf` uses in `std`)
 - #130866 (Allow instantiating object trait binder when upcasting)
 - #130922 (Reference UNSPECIFIED instead of INADDR_ANY in join_multicast_v4)
 - #130924 (Make clashing_extern_declarations considering generic args for ADT field)
 - #130939 (rustdoc: update `ProcMacro` docs section on helper attributes)
 - #130940 (Revert space-saving operations)
 - #130944 (Allow instantiating trait object binder in ptr-to-ptr casts)
 - #130953 (Rename a few tests to make tidy happier)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-28 10:46:56 +00:00
Matthias Krüger
58d0730fb8
Rollup merge of #130944 - lukas-code:ptr-ptr-sub, r=compiler-errors
Allow instantiating trait object binder in ptr-to-ptr casts

For unsizing coercions between trait objects with the same principal, we already allow instantiating the for binder. For example, coercing `Box<dyn for<'a> Trait<'a>` to `Box<dyn Trait<'static>>` is allowed.

Since ptr-to-ptr casts will insert an unsizing coercion before the cast if possible, this has the consequence that the following compiles already:

```rust
// This compiles today.
fn cast<'b>(x: *mut dyn for<'a> Trait<'a>) -> *mut dyn Trait<'b> {
    // lowered as (roughly)
    // tmp: *mut dyn Trait<'?0> = Unsize(x)     // requires dyn for<'a> Trait<'a> <: dyn Trait<'?0>
    // ret: *mut dyn Trait<'b> = PtrToPtr(tmp)  // requires dyn Trait<'?0> == dyn Trait<'b>
    x as _
}
```

However, if no unsizing coercion is inserted then this currently fails to compile as one type is more general than the other. This PR will allow this code to compile, too, by changing ptr-to-ptr casts of pointers with vtable metadata to use sutyping instead of type equality.

```rust
// This will compile after this PR.
fn cast<'b>(x: *mut dyn for<'a> Trait<'a>) -> *mut Wrapper<dyn Trait<'b>> {
    // lowered as (roughly)
    // no Unsize here!
    // ret: *mut Wrapper<dyn Trait<'b>> = PtrToPtr(x)  // requires dyn for<'a> Trait<'a> == dyn Trait<'b>
    x as _
}
```

Note that it is already possible to work around the current restrictions and make the code compile before this PR by splitting the cast in two, so this shouldn't allow a new class of programs to compile:

```rust
// Workaround that compiles today.
fn cast<'b>(x: *mut dyn for<'a> Trait<'a>) -> *mut Wrapper<dyn Trait<'b>> {
    x as *mut dyn Trait<'_> as _
}
```

r? `@compiler-errors`
cc `@WaffleLapkin`
2024-09-28 09:35:12 +02:00
Matthias Krüger
2df6b0773e
Rollup merge of #130924 - surechen:fix_130851, r=compiler-errors
Make clashing_extern_declarations considering generic args for ADT field

In following example, G<u16> should be recognized as different from G<u32> :

```rust
#[repr(C)] pub struct G<T> { g: [T; 4] }

pub mod x { extern "C" { pub fn g(_: super::G<u16>); } }
pub mod y { extern "C" { pub fn g(_: super::G<u32>); } }
```

fixes #130851
2024-09-28 09:35:10 +02:00
Matthias Krüger
4e510daed7
Rollup merge of #130866 - compiler-errors:dyn-instantiate-binder, r=lcnr
Allow instantiating object trait binder when upcasting

This PR fixes two bugs (that probably need an FCP).

### We use equality rather than subtyping for upcasting dyn conversions

This code should be valid:

```rust
#![feature(trait_upcasting)]

trait Foo: for<'h> Bar<'h> {}
trait Bar<'a> {}

fn foo(x: &dyn Foo) {
    let y: &dyn Bar<'static> = x;
}
```
But instead:

```
error[E0308]: mismatched types
 --> src/lib.rs:7:32
  |
7 |     let y: &dyn Bar<'static> = x;
  |                                ^ one type is more general than the other
  |
  = note: expected existential trait ref `for<'h> Bar<'h>`
             found existential trait ref `Bar<'_>`
```

And so should this:

```rust
#![feature(trait_upcasting)]

fn foo(x: &dyn for<'h> Fn(&'h ())) {
    let y: &dyn FnOnce(&'static ()) = x;
}
```

But instead:

```
error[E0308]: mismatched types
 --> src/lib.rs:4:39
  |
4 |     let y: &dyn FnOnce(&'static ()) = x;
  |                                       ^ one type is more general than the other
  |
  = note: expected existential trait ref `for<'h> FnOnce<(&'h (),)>`
             found existential trait ref `FnOnce<(&(),)>`
```

Specifically, both of these fail because we use *equality* when comparing the supertrait to the *target* of the unsize goal. For the first example, since our supertrait is `for<'h> Bar<'h>` but our target is `Bar<'static>`, there's a higher-ranked type mismatch even though we *should* be able to instantiate that supertrait binder when upcasting. Similarly for the second example.

### New solver uses equality rather than subtyping for no-op (i.e. non-upcasting) dyn conversions

This code should be valid in the new solver, like it is with the old solver:

```rust
// -Znext-solver

fn foo<'a>(x: &mut for<'h> dyn Fn(&'h ())) {
   let _: &mut dyn Fn(&'a ()) = x;
}
```

But instead:

```
error: lifetime may not live long enough
 --> <source>:2:11
  |
1 | fn foo<'a>(x: &mut dyn for<'h> Fn(&'h ())) {
  |        -- lifetime `'a` defined here
2 |    let _: &mut dyn Fn(&'a ()) = x;
  |           ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
  |
  = note: requirement occurs because of a mutable reference to `dyn Fn(&())`
```

Specifically, this fails because we try to coerce `&mut dyn for<'h> Fn(&'h ())` to `&mut dyn Fn(&'a ())`, which registers an `dyn for<'h> Fn(&'h ()): dyn Fn(&'a ())` goal. This fails because the new solver uses *equating* rather than *subtyping* in `Unsize` goals.

This is *mostly* not a problem... You may wonder why the same code passes on the new solver for immutable references:

```
// -Znext-solver

fn foo<'a>(x: &dyn Fn(&())) {
   let _: &dyn Fn(&'a ()) = x; // works
}
```

That's because in this case, we first try to coerce via `Unsize`, but due to the leak check the goal fails. Then, later in coercion, we fall back to a simple subtyping operation, which *does* work.

Since `&T` is covariant over `T`, but `&mut T` is invariant, that's where the discrepancy between these two examples crops up.

---

r? lcnr or reassign :D
2024-09-28 09:35:09 +02:00
bors
851f698682 Auto merge of #130874 - klensy:bumpme, r=jieyouxu
bump few deps

Bumps cargo_metadata, thorin-dwp, windows.

Should dedupe some crates around.
2024-09-28 05:15:29 +00:00
bors
b6576e3f63 Auto merge of #130948 - GuillaumeGomez:subtree-update, r=GuillaumeGomez
GCC backend subtree update

We just finished the [last sync](https://github.com/rust-lang/rustc_codegen_gcc/pull/556) so time to sync back.

cc `@antoyo`
2024-09-28 02:48:40 +00:00
Josh Stone
f46057bf1c Only add an automatic SONAME for Rust dylibs 2024-09-27 15:53:26 -07:00
bors
83e4e18896 Auto merge of #130946 - matthiaskrgr:rollup-ia4mf0y, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #130718 (Cleanup some known-bug issues)
 - #130730 (Reorganize Test Headers)
 - #130826 (Compiler: Rename "object safe" to "dyn compatible")
 - #130915 (fix typo in triagebot.toml)
 - #130926 (Update cc to 1.1.22 in library/)
 - #130932 (etc: Add sample rust-analyzer configs for eglot & helix)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-27 21:23:29 +00:00
Guillaume Gomez
7cde7db1fc Fmt 2024-09-27 22:09:18 +02:00
Guillaume Gomez
325b70890a Merge commit '3187d32079b817522cc17413ec9185b130daf693' into subtree-update 2024-09-27 22:00:17 +02:00
Michael Goulet
d753aba3b3 Get rid of a_is_expected from ToTrace 2024-09-27 15:43:18 -04:00
Michael Goulet
4fb097a5de Instantiate binders when checking supertrait upcasting 2024-09-27 15:43:18 -04:00
Matthias Krüger
a935064fae
Rollup merge of #130826 - fmease:compiler-mv-obj-safe-dyn-compat, r=compiler-errors
Compiler: Rename "object safe" to "dyn compatible"

Completed T-lang FCP: https://github.com/rust-lang/lang-team/issues/286#issuecomment-2338905118.
Tracking issue: https://github.com/rust-lang/rust/issues/130852

Excludes `compiler/rustc_codegen_cranelift` (to be filed separately).
Includes Stable MIR.

Regarding https://github.com/rust-lang/rust/labels/relnotes, I guess I will manually open a https://github.com/rust-lang/rust/labels/relnotes-tracking-issue since this change affects everything (compiler, library, tools, docs, books, everyday language).

r? ghost
2024-09-27 21:35:08 +02:00
Lukas Markeffsky
53f45c4332 borrowck: use subtyping instead of equality for ptr-to-ptr casts 2024-09-27 21:04:32 +02:00
Matthias Krüger
966a0b76bc
Rollup merge of #130927 - lcnr:normalizes-to-comments, r=compiler-errors
update outdated comments

r? `@compiler-errors` cc `@gavinleroy`
2024-09-27 19:08:01 +02:00
Matthias Krüger
01fecf60ef
Rollup merge of #130917 - gurry:129503-ice-wrong-span-in-macros, r=chenyukang
Fix error span if arg to `asm!()` is a macro call

Fixes #129503

When the argument to `asm!()` is a macro call, e.g. `asm!(concat!("abc", "{} pqr"))`, and there's an error in the resulting template string, we do not take into account the presence of this macro call while computing the error span. This PR fixes that. Now we will use the entire thing between the parenthesis of `asm!()` as the error span in this situation e.g. for `asm!(concat!("abc", "{} pqr"))` the error span will be `concat!("abc", "{} pqr")`.
2024-09-27 19:08:01 +02:00
Matthias Krüger
a37f7f457f
Rollup merge of #130916 - cuviper:compiler-raw_ref_op, r=compiler-errors
Use `&raw` in the compiler

Like #130865 did for the standard library, we can use `&raw` in the
compiler now that stage0 supports it. Also like the other issue, I did
not make any doc or test changes at this time.
2024-09-27 19:08:00 +02:00
Matthias Krüger
fd9d961ed8
Rollup merge of #130873 - taiki-e:ppc64-atomic, r=Amanieu
rustc_target: Add powerpc64 atomic-related features

This adds the following two target features to unstable powerpc_target_feature.

- `partword-atomics`: 8-bit and 16-bit atomic instructions (`l{b,h}arx` and `st{b,h}cx.`) ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L170-L172))
- `quadword-atomics`: 128-bit atomic instructions (`lqarx` and `stqcx.`) ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L173-L175))

Both features are [available on power8+](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L408-L422), so enabled by default for `powerpc64le-*` targets.

r? `@Amanieu`

`@rustbot` label +O-PowerPC
2024-09-27 19:08:00 +02:00
Matthias Krüger
f9cd81f3d9
Rollup merge of #130435 - madsmtm:move-apple-link-args, r=petrochenkov
Move Apple linker args from `rustc_target` to `rustc_codegen_ssa`

They are dependent on the deployment target and SDK version, but having these in `rustc_target` makes it hard to introduce that dependency. Part of the work needed to do https://github.com/rust-lang/rust/issues/118204, see https://github.com/rust-lang/rust/pull/129342 for some discussion.

Tested using:
```console
./x test tests/run-make/apple-deployment-target --target="aarch64-apple-darwin,aarch64-apple-ios,aarch64-apple-ios-macabi,aarch64-apple-ios-sim,aarch64-apple-tvos,aarch64-apple-tvos-sim,aarch64-apple-visionos,aarch64-apple-visionos-sim,aarch64-apple-watchos,aarch64-apple-watchos-sim,arm64_32-apple-watchos,armv7k-apple-watchos,armv7s-apple-ios,x86_64-apple-darwin,x86_64-apple-ios,x86_64-apple-ios-macabi,x86_64-apple-tvos,x86_64-apple-watchos-sim,x86_64h-apple-darwin"
IPHONEOS_DEPLOYMENT_TARGET=10.0 ./x test tests/run-make/apple-deployment-target --target=i386-apple-ios
```

`arm64e-apple-darwin` and `arm64e-apple-ios` have not been tested, see https://github.com/rust-lang/rust/issues/130085, neither is `i686-apple-darwin`, since that requires using an x86_64 macbook, and I currently can't get mine to work, see https://github.com/rust-lang/rust/issues/130434.

CC `@petrochenkov`
2024-09-27 19:07:59 +02:00
Matthias Krüger
e76eb96a00
Rollup merge of #129087 - slanterns:option_get_or_insert_default, r=dtolnay
Stabilize `option_get_or_insert_default`

Closes: https://github.com/rust-lang/rust/issues/82901.

`@rustbot` label: +T-libs-api

r? libs-api
2024-09-27 19:07:58 +02:00
Deadbeef
7c2a24b50c properly elaborate effects implied bounds for super traits 2024-09-27 22:36:46 +08:00
lcnr
9766192545 update outdated comments 2024-09-27 13:48:11 +02:00
Urgau
8075ddb98e Implement RFC3137 trim-paths sysroot changes 2024-09-27 13:27:54 +02:00
surechen
0bf928968b Make clashing_extern_declarations considering generic args for ADT field
fixes #130851
2024-09-27 16:37:43 +08:00
klensy
26c09b6553 bump few deps
cargo_metadata, thorin-dwp, windows
2024-09-27 09:23:05 +03:00