Commit Graph

8404 Commits

Author SHA1 Message Date
Matthias Krüger 53f5294c0f
Rollup merge of #129340 - stephen-lazaro:u/slazaro/issue-129274, r=compiler-errors
Remove Duplicate E0381 Label

Aims to resolve https://github.com/rust-lang/rust/issues/129274, and adds a test for the case.

Essentially, we are duplicating this span for some reason. For now, I'm just using a set to collect the spans rather than the vec. I imagine there's probably no real reason to inspect duplicates in this area, but if I'm wrong I can adjust to collect "seen spans" in just the point where this label is applied.

I'm not sure why it's producing duplicate spans. Looks like this has been this way for a while? I think it gives the duplicate label on 1.75.0 for example.
2024-08-27 00:42:00 +02:00
Matthias Krüger d4d4b6b4fa
Rollup merge of #129250 - estebank:issue-129205, r=compiler-errors
Do not ICE on non-ADT rcvr type when looking for crate version collision

When looking for multiple versions of the same crate, do not blindly construct the receiver type.

Follow up to #128786.
Fixes #129205
Fixes #129216
2024-08-27 00:42:00 +02:00
Matthias Krüger 29923b6801
Rollup merge of #129032 - jswrenn:transmute-method, r=compiler-errors
Document & implement the transmutation modeled by `BikeshedIntrinsicFrom`

Documents that `BikeshedIntrinsicFrom` models transmute-via-union, which is slightly more expressive than the transmute-via-cast implemented by `transmute_copy`. Additionally, we provide an implementation of transmute-via-union as a method on the `BikeshedIntrinsicFrom` trait with additional documentation on the boundary between trait invariants and caller obligations.

Whether or not transmute-via-union is the right kind of transmute to model remains up for discussion [1]. Regardless, it seems wise to document the present behavior.

[1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20'kind'.20of.20transmute.20to.20model.3F/near/426331967

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

r? `@compiler-errors`

cc `@scottmcm,` `@Lokathor`
2024-08-27 00:41:59 +02:00
Esteban Küber 00c435d9b3 Do not ICE on non-ADT rcvr type when looking for crate version collision
When looking for multiple versions of the same crate, do not blindly construct the receiver type.

Follow up to #128786. Fix #129205.
2024-08-26 13:02:21 -04:00
Matthias Krüger 114e60ff79
Rollup merge of #129600 - traviscross:TC/tie-impl_trait_overcaptures-to-rust-2024, r=compiler-errors
Tie `impl_trait_overcaptures` lint to Rust 2024

The `impl_trait_overcaptures` lint is part of the migration to Rust 2024 and the Lifetime Capture Rules 2024.  Now that we've stabilized precise capturing (RFC 3617), let's tie this lint to the `rust_2024_compatibility` lint group.

Tracking:

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

r? `@compiler-errors`
2024-08-26 17:25:34 +02:00
Matthias Krüger dedfb35711
Rollup merge of #129190 - rezwanahmedsami:master, r=tgross35
Add f16 and f128 to tests/ui/consts/const-float-bits-conv.rs

Fixes #129163

try-job: x86_64-msvc
try-job: x86_64-mingw
try-job: i686-msvc
try-job: i686-mingw
2024-08-26 17:25:31 +02:00
Travis Cross 6982785f18 Tie `impl_trait_overcaptures` lint to Rust 2024
The `impl_trait_overcaptures` lint is part of the migration to Rust
2024 and the Lifetime Capture Rules 2024.  Now that we've stabilized
precise capturing (RFC 3617), let's tie this lint to the
`rust_2024_compatibility` lint group.
2024-08-26 06:46:56 +00:00
Matthias Krüger 0a8e305d91
Rollup merge of #129553 - RalfJung:const-stability, r=compiler-errors
add back test for stable-const-can-only-call-stable-const

This got accidentally removed in https://github.com/rust-lang/rust/pull/128596 (file `tests/ui/internal/internal-unstable-const.rs`). The test has little to do with "allow internal unstable" though, so add it in a file that already tests various const stability things.

Also tweak the help that suggests to add `rustc_allow_const_fn_unstable` to make it clear that this needs team approval, since it is a fairly big gun.
2024-08-26 01:49:03 +02:00
Matthias Krüger ae21236530
Rollup merge of #129519 - compiler-errors:lowering-flags, r=fmease
Remove redundant flags from `lower_ty_common` that can be inferred from the HIR

...and then get rid of `lower_ty_common`.

r? ``@fmease`` or re-roll if you're busy!
2024-08-26 01:49:01 +02:00
Matthias Krüger 6228bd6ef6
Rollup merge of #129405 - surechen:fix_span_x, r=cjgillot
Fixing span manipulation and indentation of the suggestion introduced by #126187

According to comments:
https://github.com/rust-lang/rust/pull/128084#issuecomment-2295254576
https://github.com/rust-lang/rust/pull/126187/files#r1634897691
2024-08-26 01:49:00 +02:00
Matthias Krüger 621f2726fb
Rollup merge of #129288 - compiler-errors:unsafe-fn-coercion, r=lcnr
Use subtyping for `UnsafeFnPointer` coercion, too

I overlooked this in #129059, which changed MIR typechecking to use subtyping for other fn pointer coercions.

Fixes #129285
2024-08-26 01:49:00 +02:00
Michael Goulet ecd2d11573 Remove redundant flags that can be inferred from the HIR 2024-08-25 16:21:00 -04:00
Matthias Krüger 9c59e97ded
Rollup merge of #129487 - GrigorenkoPV:repr_transparent_external_private_fields, r=compiler-errors
repr_transparent_external_private_fields: special-case some std types

Fixes #129470

```@rustbot``` label +A-lint +L-repr_transparent_external_private_fields
2024-08-25 16:51:05 +02:00
surechen 8750e24247 Fixing span manipulation and indentation of the suggestion introduced by #126187
According to comments:
https://github.com/rust-lang/rust/pull/128084#issuecomment-2295254576
https://github.com/rust-lang/rust/pull/126187/files#r1634897691
2024-08-25 20:30:06 +08:00
Ralf Jung ba24121ad6 tweak rustc_allow_const_fn_unstable hint, and add back test for stable-const-can-only-call-stable-const 2024-08-25 13:50:55 +02:00
bors 717aec0f8e Auto merge of #129521 - matthiaskrgr:rollup-uigv77m, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #128596 (stabilize const_fn_floating_point_arithmetic)
 - #129199 (make writes_through_immutable_pointer a hard error)
 - #129246 (Retroactively feature gate `ConstArgKind::Path`)
 - #129290 (Pin `cc` to 1.0.105)
 - #129323 (Implement `ptr::fn_addr_eq`)
 - #129500 (remove invalid `TyCompat` relation for effects)
 - #129501 (panicking: improve hint for Miri's RUST_BACKTRACE behavior)
 - #129505 (interpret: ImmTy: tighten sanity checks in offset logic)
 - #129510 (Fix `elided_named_lifetimes` in code)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-25 08:12:16 +00:00
Trevor Gross 2269381e0a
Rollup merge of #129429 - cjgillot:named-variance, r=compiler-errors
Print the generic parameter along with the variance in dumps.

This allows to make sure we are testing what we think we are testing.

While the tests are correct, I discovered that opaque duplicated args are in the reverse declaration order.
2024-08-24 21:03:32 -05:00
Trevor Gross 198a68df1c
Rollup merge of #128735 - jieyouxu:pr-120176-revive, r=cjgillot
Add a special case for `CStr`/`CString` in the `improper_ctypes` lint

Revives #120176. Just needed to bless a test and fix an argument, but seemed reasonable to me otherwise.

Instead of saying to "consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct", we now tell users to "Use `*const ffi::c_char` instead, and pass the value from `CStr::as_ptr()`" when the type involved is a `CStr` or a `CString`.

The suggestion is not made for `&mut CString` or `*mut CString`.

r? ``````@cjgillot`````` (since you were the reviewer of the original PR #120176, but feel free to reroll)
2024-08-24 21:03:31 -05:00
Trevor Gross dfe7d5c31e
Rollup merge of #128524 - chenyukang:yukang-fix-127930-invalid-outer-style-sugg, r=cjgillot
Don't suggest turning crate-level attributes into outer style

Fixes #127930
2024-08-24 21:03:31 -05:00
Trevor Gross 00308920ae
Rollup merge of #128467 - estebank:unsized-args, r=cjgillot
Detect `*` operator on `!Sized` expression

The suggestion is new:

```
error[E0277]: the size for values of type `str` cannot be known at compilation time
  --> $DIR/unsized-str-in-return-expr-arg-and-local.rs:15:9
   |
LL |     let x = *"";
   |         ^ doesn't have a size known at compile-time
   |
   = help: the trait `Sized` is not implemented for `str`
   = note: all local variables must have a statically known size
   = help: unsized locals are gated as an unstable feature
help: references to `!Sized` types like `&str` are `Sized`; consider not dereferencing the expression
   |
LL -     let x = *"";
LL +     let x = "";
   |
```

Fix #128199.
2024-08-24 21:03:30 -05:00
Matthias Krüger 3f5d6b2e40
Rollup merge of #129500 - fee1-dead-contrib:fxrel, r=compiler-errors
remove invalid `TyCompat` relation for effects

if the current impl uses `Maybe` (`impl const`), the parent impl must use `Maybe` (`impl const`) as well.

I'd like to rename `TyCompat` to `Sub` which is probably clearer. But it would conflict with my other PR.

r? ``@rust-lang/project-const-traits``
2024-08-24 22:14:14 +02:00
Matthias Krüger c0bedb9e5e
Rollup merge of #129246 - BoxyUwU:feature_gate_const_arg_path, r=cjgillot
Retroactively feature gate `ConstArgKind::Path`

This puts the lowering introduced by #125915 under a feature gate until we fix the regressions introduced by it. Alternative to whole sale reverting the PR since it didn't seem like a very clean revert and I think this is generally a step in the right direction and don't want to get stuck landing and reverting the PR over and over :)

cc #129137 ``@camelid,`` tests taken from there. beta is branching soon so I think it makes sense to not try and rush that fix through since it wont have much time to bake and if it has issues we can't simply revert it on beta.

Fixes #128016
2024-08-24 22:14:12 +02:00
Matthias Krüger 05b8bcc662
Rollup merge of #129199 - RalfJung:writes_through_immutable_pointer, r=compiler-errors
make writes_through_immutable_pointer a hard error

This turns the lint added in https://github.com/rust-lang/rust/pull/118324 into a hard error. This has been reported in cargo's future-compat reports since Rust 1.76 (released in February). Given that const_mut_refs is still unstable, it should be impossible to even hit this error on stable: we did accidentally stabilize some functions that can cause this error, but that got reverted in https://github.com/rust-lang/rust/pull/117905. Still, let's do a crater run just to be sure.

Given that this should only affect unstable code, I don't think it needs an FCP, but let's Cc ``@rust-lang/lang`` anyway -- any objection to making this unambiguous UB into a hard error during const-eval? This can be viewed as part of https://github.com/rust-lang/rust/pull/129195 which is already nominated for discussion.
2024-08-24 22:14:12 +02:00
Matthias Krüger 0dfdea1c45
Rollup merge of #128596 - RalfJung:const_fn_floating_point_arithmetic, r=nnethercote
stabilize const_fn_floating_point_arithmetic

Part of https://github.com/rust-lang/rust/issues/128288
Fixes https://github.com/rust-lang/rust/issues/57241

The existing test `tests/ui/consts/const_let_eq_float.rs`  ([link](https://github.com/RalfJung/rust/blob/const_fn_floating_point_arithmetic/tests/ui/consts/const_let_eq_float.rs)) covers the basics, and also Miri has extensive tests covering the interpreter's float machinery. Also, that machinery can already be used on stable inside `const`/`static` initializers, just not inside `const fn`.

This was explicitly called out in https://github.com/rust-lang/rfcs/pull/3514 so in a sense t-lang just recently already FCP'd this, but let's hear from them whether they want another FCP for the stabilization here or whether that was covered by the FCP for the RFC.
Cc ``@rust-lang/lang``

### Open items

- [x] Update the Reference: https://github.com/rust-lang/reference/pull/1566
2024-08-24 22:14:11 +02:00
Pavel Grigorenko 06f2d73b2b repr_transparent_external_private_fields: treat `rustc_pub_transparent` types as local 2024-08-24 23:05:54 +03:00
Pavel Grigorenko b9033bdd92 New `#[rustc_pub_transparent]` attribute 2024-08-24 23:05:37 +03:00
Deadbeef 378902e325 remove invalid `TyCompat` relation for effects 2024-08-24 14:24:21 +08:00
Camille GILLOT 5cef88c1f4 Print the generic parameter along with the variance in dumps. 2024-08-23 23:00:45 +00:00
Jack Wrenn 2540070fd4 document & impl the transmutation modeled by `BikeshedIntrinsicFrom`
Documents that `BikeshedIntrinsicFrom` models transmute-via-union,
which is slightly more expressive than the transmute-via-cast
implemented by `transmute_copy`. Additionally, we provide an
implementation of transmute-via-union as a method on the
`BikeshedIntrinsicFrom` trait with additional documentation on
the boundary between trait invariants and caller obligations.

Whether or not transmute-via-union is the right kind of transmute
to model remains up for discussion [1]. Regardless, it seems wise
to document the present behavior.

[1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20'kind'.20of.20transmute.20to.20model.3F/near/426331967
2024-08-23 14:37:36 +00:00
bors a60a9e567a Auto merge of #129464 - GuillaumeGomez:rollup-ckfqd7h, r=GuillaumeGomez
Rollup of 9 pull requests

Successful merges:

 - #128511 (Document WebAssembly target feature expectations)
 - #129243 (do not build `cargo-miri` by default on stable channel)
 - #129263 (Add a missing compatibility note in the 1.80.0 release notes)
 - #129276 (Stabilize feature `char_indices_offset`)
 - #129350 (adapt integer comparison tests for LLVM 20 IR changes)
 - #129408 (Fix handling of macro arguments within the `dropping_copy_types` lint)
 - #129426 (rustdoc-search: use tighter json for names and parents)
 - #129437 (Fix typo in a help diagnostic)
 - #129457 (kobzol vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-23 10:56:34 +00:00
Guillaume Gomez 81aca633bb
Rollup merge of #129408 - Urgau:macro-arg-drop_copy, r=compiler-errors
Fix handling of macro arguments within the `dropping_copy_types` lint

This PR fixes the handling of spans with different context (aka macro arguments) than the primary expression within the different `{drop,forget}ing_copy_types` and `{drop,forget}ing_references` lints.

<details>
<summary>Before</summary>

```
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
 --> drop_writeln.rs:5:5
  |
5 |     drop(writeln!(&mut msg, "test"));
  |     ^^^^^--------------------------^
  |          |
  |          argument has type `Result<(), std::fmt::Error>`
  |
  = note: `#[warn(dropping_copy_types)]` on by default
help: use `let _ = ...` to ignore the expression or result
 --> /home/[..]/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/macros/mod.rs:688:9
  |
68|         let _ =
  |         ~~~~~~~
```

</details>

<details>
<summary>With this PR</summary>

```
warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
 --> drop_writeln.rs:5:5
  |
5 |     drop(writeln!(&mut msg, "test"));
  |     ^^^^^--------------------------^
  |          |
  |          argument has type `Result<(), std::fmt::Error>`
  |
  = note: `#[warn(dropping_copy_types)]` on by default
help: use `let _ = ...` to ignore the expression or result
  |
5 -     drop(writeln!(&mut msg, "test"));
5 +     let _ = writeln!(&mut msg, "test");
  |
```

</details>

``````@rustbot`````` label +L-dropping_copy_types
2024-08-23 12:32:16 +02:00
Stephen Lazaro e91f32829c Deduplicate Spans in Uninitialized Check
Prevents reporting labels or diagnostics on spans that are produced
multiple times.
2024-08-22 09:36:14 -07:00
Michael Goulet 8eb15586c6 Don't trigger refinement lint if predicates reference errors 2024-08-22 12:34:12 -04:00
Urgau 6a878a9630 Fix handling of macro arguments within the `dropping_copy_types lint 2024-08-22 13:32:01 +02: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
Ralf Jung ebfa3e3f62 stabilize const_fn_floating_point_arithmetic 2024-08-22 08:25:54 +02: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
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
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 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
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 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