Commit Graph

234948 Commits

Author SHA1 Message Date
Matthias Krüger
0c45018473
Rollup merge of #116231 - DaniPopes:simpler-lint-array, r=Nilstrieb
Remove `rustc_lint_defs::lint_array`
2023-09-29 10:11:13 +02:00
Matthias Krüger
e814f1e3c0
Rollup merge of #116201 - Jarcho:noop_fix, r=fee1-dead
Fix `noop_method_call` detection

This needs to be merged before #116198 can compile. The error occurs before the compiler is built so this needs to be a separate PR.
2023-09-29 10:11:12 +02:00
Matthias Krüger
f777e8cf22
Rollup merge of #116133 - pouriya:refactor-bootstrap.py, r=albertlarsan68
ref(bootstrap.py): add `eprint` function

Implemented a 3-line function called `eprint` which is just like `print` but for `stderr`. So each `print(..., file=sys.stderr)` becomes `eprint(...)`.

<br/>

Testing `eprint` function:
```sh
$ cat eprint.py
```
```python
import sys

def eprint(*args, **kwargs):
	kwargs['file'] = sys.stderr
	print(*args, **kwargs)

eval('eprint({})'.format(sys.argv[1]))
```
```sh
$ python3 eprint.py '"hello"'
hello
$
```
```sh
$ python3 eprint.py '"hello"' 2>/dev/null
$
```
```sh
$ python3 eprint.py '"hello", "world", flush=True, file=sys.stdout'
hello world
$
```
```sh
$ python3 eprint.py '"hello", "world", flush=True, file=sys.stdout' 2>/dev/null
$
```
2023-09-29 10:11:12 +02:00
bors
c1f86f0bc8 Auto merge of #116089 - estebank:issue-115992-2, r=compiler-errors
When suggesting `self.x` for `S { x }`, use `S { x: self.x }`

Fix #115992.

r? `@compiler-errors`

Follow up to #116086.
2023-09-29 05:45:18 +00:00
bors
a327e753bc Auto merge of #115986 - onur-ozkan:fix-cross-compilation-lto-problem, r=wesleywiser
allow LTO on `proc-macro` crates with `-Zdylib-lto`

ref https://github.com/rust-lang/rust/pull/115986#issuecomment-1732316361

Fixes #110296
2023-09-29 03:57:17 +00:00
bors
60bb5192d1 Auto merge of #115843 - lcnr:bb-provisional-cache, r=compiler-errors
new solver: remove provisional cache

The provisional cache is a performance optimization if there are large, interleaving cycles. Such cycles generally do not exist. It is incredibly complex and unsound in all trait solvers which have one: the old solver, chalk, and the new solver ([link](https://github.com/rust-lang/rust/blob/master/tests/ui/traits/new-solver/cycles/inductive-not-on-stack.rs)).

Given the assumption that it is not perf-critical and also incredibly complex, remove it from the new solver, only checking whether a goal is on the stack. While writing this, I uncovered two additional soundness bugs, see the inline comments for them.

r? `@compiler-errors`
2023-09-29 02:09:40 +00:00
bors
958c2b87d8 Auto merge of #115821 - obeis:hir-analysis-migrate-diagnostics-5, r=compiler-errors
Migrate `rustc_hir_analysis` to session diagnostic [Part 5]

Finishing `coherence/builtin.rs` file
2023-09-29 00:24:57 +00:00
bors
7b4d9e155f Auto merge of #115659 - compiler-errors:itp, r=cjgillot
Stabilize `impl_trait_projections`

Closes #115659

## TL;DR:

This allows us to mention `Self` and `T::Assoc` in async fn and return-position `impl Trait`, as you would expect you'd be able to.

Some examples:
```rust
#![feature(return_position_impl_trait_in_trait, async_fn_in_trait)]
// (just needed for final tests below)

// ---------------------------------------- //

struct Wrapper<'a, T>(&'a T);

impl Wrapper<'_, ()> {
    async fn async_fn() -> Self {
        //^ Previously rejected because it returns `-> Self`, not `-> Wrapper<'_, ()>`.
        Wrapper(&())
    }

    fn impl_trait() -> impl Iterator<Item = Self> {
        //^ Previously rejected because it mentions `Self`, not `Wrapper<'_, ()>`.
        std::iter::once(Wrapper(&()))
    }
}

// ---------------------------------------- //

trait Trait<'a> {
    type Assoc;
    fn new() -> Self::Assoc;
}
impl Trait<'_> for () {
    type Assoc = ();
    fn new() {}
}

impl<'a, T: Trait<'a>> Wrapper<'a, T> {
    async fn mk_assoc() -> T::Assoc {
        //^ Previously rejected because `T::Assoc` doesn't mention `'a` in the HIR,
        //  but ends up resolving to `<T as Trait<'a>>::Assoc`, which does rely on `'a`.
        // That's the important part -- the elided trait.
        T::new()
    }

    fn a_few_assocs() -> impl Iterator<Item = T::Assoc> {
        //^ Previously rejected for the same reason
        [T::new(), T::new(), T::new()].into_iter()
    }
}

// ---------------------------------------- //

trait InTrait {
    async fn async_fn() -> Self;

    fn impl_trait() -> impl Iterator<Item = Self>;
}

impl InTrait for &() {
    async fn async_fn() -> Self { &() }
    //^ Previously rejected just like inherent impls

    fn impl_trait() -> impl Iterator<Item = Self> {
        //^ Previously rejected just like inherent impls
        [&()].into_iter()
    }
}
```

## Technical:

Lifetimes in return-position `impl Trait` (and `async fn`) are duplicated as early-bound generics local to the opaque in order to make sure we are able to substitute any late-bound lifetimes from the function in the opaque's hidden type. (The [dev guide](https://rustc-dev-guide.rust-lang.org/return-position-impl-trait-in-trait.html#aside-opaque-lifetime-duplication) has a small section about why this is necessary -- this was written for RPITITs, but it applies to all RPITs)

Prior to #103491, all of the early-bound lifetimes not local to the opaque were replaced with `'static` to avoid issues where relating opaques caused their *non-captured* lifetimes to be related. This `'static` replacement led to strange and possibly unsound behaviors (https://github.com/rust-lang/rust/issues/61949#issuecomment-508836314) (https://github.com/rust-lang/rust/issues/53613) when referencing the `Self` type alias in an impl or indirectly referencing a lifetime parameter via a projection type (via a `T::Assoc` projection without an explicit trait), since lifetime resolution is performed on the HIR, when neither `T::Assoc`-style projections or `Self` in impls are expanded.

Therefore an error was implemented in #62849 to deny this subtle behavior as a known limitation of the compiler. It was attempted by `@cjgillot` to fix this in #91403, which was subsequently unlanded. Then it was re-attempted to much success (🎉) in #103491, which is where we currently are in the compiler.

The PR above (#103491) fixed this issue technically by *not* replacing the opaque's parent lifetimes with `'static`, but instead using variance to properly track which lifetimes are captured and are not. The PR gated any of the "side-effects" of the PR behind a feature gate (`impl_trait_projections`) presumably to avoid having to involve T-lang or T-types in the PR as well. `@cjgillot` can clarify this if I'm misunderstanding what their intention was with the feature gate.

Since we're not replacing (possibly *invariant*!) lifetimes with `'static` anymore, there are no more soundness concerns here. Therefore, this PR removes the feature gate.

Tests:
* `tests/ui/async-await/feature-self-return-type.rs`
* `tests/ui/impl-trait/feature-self-return-type.rs`
* `tests/ui/async-await/issues/issue-78600.rs`
* `tests/ui/impl-trait/capture-lifetime-not-in-hir.rs`

---

r? cjgillot on the impl (not much, just removing the feature gate)

I'm gonna mark this as FCP for T-lang and T-types.
2023-09-28 21:35:18 +00:00
DaniPopes
f1b7484160
Remove rustc_lint_defs::lint_array 2023-09-28 23:01:25 +02:00
bors
1393ef1fa0 Auto merge of #116199 - Urgau:simplify-invalid_ref_casting, r=cjgillot
Simplify some of the logic in the `invalid_reference_casting` lint

This PR simplifies 2 areas of the logic for the `invalid_reference_casting` lint:
 - The init detection: we now use the newly added `expr_or_init` function instead of a manual detection
 - The ref-to-mut-ptr casting detection logic: I simplified this logic by caring less hardly about the order of the casting operations

Those two simplifications permits us to detect more cases, as can be seen in the test output changes.
2023-09-28 19:44:14 +00:00
bors
42faef503f Auto merge of #116227 - nikic:update-llvm-14, r=cuviper
Update LLVM submodule

Update LLVM submodule to pull in additional 17.x backports.

Fixes https://github.com/rust-lang/rust/issues/115970.
Fixes miscompile from https://github.com/rust-lang/rust/pull/115554.
Fixes miscompile from https://github.com/rust-lang/rust/pull/102099.
Fixes inlining regressions mentioned at https://github.com/rust-lang/llvm-project/pull/153.
2023-09-28 17:16:47 +00:00
bors
925f844164 Auto merge of #116230 - matthiaskrgr:rollup-hi1ciwy, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #116191 (Add regression test for rust-lang#56098)
 - #116214 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names)
 - #116221 (core/slice: Fix inconsistency between docs for `rotate_left` and `rotate_right`)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-28 15:24:06 +00:00
Matthias Krüger
ff958ae3e4
Rollup merge of #116221 - ArchUsr64:patch-1, r=ChrisDenton
core/slice: Fix inconsistency between docs for `rotate_left` and `rotate_right`

A minor fix for documentation inconsistency as shown below:
## Before:
![2023_09_28_0k3_Kleki](https://github.com/rust-lang/rust/assets/83179501/569a49d3-0d72-49ac-92a2-ef5e1d94130b)
## After:
![image](https://github.com/rust-lang/rust/assets/83179501/afd0c8d7-6fb7-4878-801b-b47c8fe23c7d)
Docs url: https://doc.rust-lang.org/stable/core/primitive.slice.html#method.rotate_left
2023-09-28 15:58:44 +02:00
Matthias Krüger
efc938312c
Rollup merge of #116214 - notriddle:master, r=aDotInTheVoid
rustdoc: rename `issue-\d+.rs` tests to have meaningful names
2023-09-28 15:58:44 +02:00
Matthias Krüger
ba0d97797a
Rollup merge of #116191 - apekros:issue-56098, r=petrochenkov
Add regression test for rust-lang#56098

Closes #56098
2023-09-28 15:58:43 +02:00
bors
dd91aba2fd Auto merge of #114882 - ChrisDenton:riddle-me, r=dtolnay
Update windows ffi bindings

Bump `windows-bindgen` to version 0.51.1. This brings with it some changes to the generated FFI bindings, but little that affects the code.

One change that does have more of an impact is `SOCKET` being `usize` instead of either `u64` or `u32` (as is used in std's public `SOCKET` type). However, it's now easy enough to abstract over that difference.

Finally I added a few new bindings that are likely to be used in pending PRs, mostly to make sure they're ok with the new metadata.

r? libs
2023-09-28 13:35:36 +00:00
Jason Newcomb
66bc682cab Fix noop_method_call detection for new diagnostic items 2023-09-28 08:22:59 -04:00
bors
c01d8d238c Auto merge of #114428 - ChaiTRex:master, r=dtolnay
Convert `Into<ExitStatus> for ExitStatusError` to `From<ExitStatusError> for ExitStatus` in `std::process`

Implementing suggestion from https://github.com/rust-lang/rust/issues/84908#issuecomment-912352902:

> I believe the impl on ExitStatusError should be
>
> ```rust
> impl From<ExitStatusError> for ExitStatus
> ```
>
> rather than
>
> ```rust
> impl Into<ExitStatus> for ExitStatusError
> ```
>
> (there is generally never anything implemented as `Into` first, because implementing `From` reflexively provides `Into`)
2023-09-28 11:47:54 +00:00
Nikita Popov
b325e9c60d Update LLVM submodule 2023-09-28 13:41:02 +02:00
bors
e2d6aa77ed Auto merge of #98704 - vthib:impl-from-raw-for-childstd-structs, r=dtolnay
Implement From<OwnedFd/Handle> for ChildStdin/out/err object

## Summary

Comments in `library/std/src/process.rs` ( ab08639e59 ) indicates that `ChildStdin`, `ChildStdout`, `ChildStderr` implements some traits that are not actually implemented: `FromRawFd`, `FromRawHandle`, and the `From<OwnedFd>/From<OwnedHandle>` from the io_safety feature.

In this PR I implement `FromRawHandle` and `FromRawFd` for those 3 objects.

## Usecase

I have a usecase where those implementations are basically needed. I want to customize
in the `Command::spawn` API how the pipes for the parent/child communications are created (mainly to strengthen the security attributes on them). I can properly setup the pipes,
and the "child" handles can be provided to `Child::spawn` easily using `Stdio::from_raw_handle`. However, there is no way to generate the `ChildStd*` objects from the raw handle of the created name pipe, which would be very useful to still expose the same API
than in other OS (basically a `spawn(...) -> (Child, ChildStdin, ChildStdout, ChildSterr)`, where on windows this is customized), and to for example use `tokio::ChildStdin::from_std` afterwards.

## Questions

* Are those impls OK to add? I have searched to see if those impls were missing on purpose, or if it was just never implemented because never needed. I haven't found any indication on why they couldn't be added, although the user clearly has to be very careful that the handle provided makes sense (i think, mainly that it is in overlapped mode for windows).
* If this change is ok, adding the impls for the io_safety feature would probably be best, or should it be done in another PR?
* I just copy-pasted the `#[stable(...)]` attributes, but the `since` value has to be updated, I'm not sure to which value.
2023-09-28 09:59:03 +00:00
bors
6e09cff6d7 Auto merge of #116222 - matthiaskrgr:rollup-dnag90q, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #112959 (Change the wording in `std::fmt::Write::write_str`)
 - #115535 (format doc-comment code examples in std::process)
 - #115888 (fix a comment about assert_receiver_is_total_eq)
 - #116211 (more clippy complextity fixes )
 - #116213 (Document -Zlink-native-libraries)
 - #116215 (Tweak wording of missing angle backets in qualified path)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-28 08:05:39 +00:00
Matthias Krüger
86d5939aba
Rollup merge of #116215 - estebank:parse-type-angle-bracket-tweak, r=compiler-errors
Tweak wording of missing angle backets in qualified path
2023-09-28 09:14:07 +02:00
Matthias Krüger
be51067b4a
Rollup merge of #116213 - tmandry:doclnl, r=ehuss
Document -Zlink-native-libraries

Originally added in #70095.
2023-09-28 09:14:07 +02:00
Matthias Krüger
fa5b2fe2f5
Rollup merge of #116211 - matthiaskrgr:clippy3, r=compiler-errors
more clippy complextity fixes

redundant_guards, useless_format, clone_on_copy
2023-09-28 09:14:06 +02:00
Matthias Krüger
698448c0cd
Rollup merge of #115888 - RalfJung:assert_receiver_is_total_eq, r=dtolnay
fix a comment about assert_receiver_is_total_eq

"a type implements #[deriving]" doesn't make any sense, so I assume they meant "implement `Eq`"? Also the attribute is called `derive`.
2023-09-28 09:14:06 +02:00
Matthias Krüger
0e338d7e23
Rollup merge of #115535 - tshepang:patch-2, r=dtolnay
format doc-comment code examples in std::process
2023-09-28 09:14:05 +02:00
Matthias Krüger
980fba7345
Rollup merge of #112959 - tbu-:pr_fmt_error_wording, r=dtolnay
Change the wording in `std::fmt::Write::write_str`

Refer to the error instead of expanding its name.
2023-09-28 09:14:05 +02:00
David Tolnay
9bdf9e754e
Update stability attribute for child stream From impls 2023-09-28 00:13:02 -07:00
Anshul
5e26e8c5bd
changed 'rotate' to 'rotating' 2023-09-28 11:58:37 +05:30
bors
46da927abb Auto merge of #114041 - nvzqz:nvzqz/shared_from_array, r=dtolnay
Implement `From<[T; N]>` for `Rc<[T]>` and `Arc<[T]>`

Given that `Box<[T]>` already has this conversion, the shared counterparts should also have it.
2023-09-28 06:16:01 +00:00
David Tolnay
e2f7032408
Fix "unresolved link to std::fmt::Error"
error: unresolved link to `std::fmt::Error`
       --> library/core/src/fmt/mod.rs:115:52
        |
    115 |     /// This function will return an instance of [`std::fmt::Error`] on error.
        |
        |
        = note: `-D rustdoc::broken-intra-doc-links` implied by `-D warnings`
2023-09-27 22:55:34 -07:00
bors
aeaa5c30e5 Auto merge of #111278 - EFanZh:implement-from-array-refs-for-vec, r=dtolnay
Implement `From<{&,&mut} [T; N]>` for `Vec<T>` where `T: Clone`

Currently, if `T` implements `Clone`, we can create a `Vec<T>` from an `&[T]` or an `&mut [T]`, can we also support creating a `Vec<T>` from an `&[T; N]` or an `&mut [T; N]`? Also, do I need to add `#[inline]` to the implementation?

ACP: rust-lang/libs-team#220. [Accepted]

Closes #100880.
2023-09-28 04:26:40 +00:00
bors
2ba4eb2d49 Auto merge of #116208 - matthiaskrgr:the_loop_that_wasnt, r=GuillaumeGomez
rustdoc: while -> if

we will always return once we step inside the while-loop thus `if` is sufficient here
2023-09-28 02:34:16 +00:00
bors
b9dd2ce408 Auto merge of #116204 - Alexendoo:rustc-lint-macro-paths, r=cjgillot
Use absolute paths in rustc_lint::passes macros

A cosmetic change, so the callsite doesn't have to import things. Makes nicer for us to try in clippy
2023-09-28 00:44:08 +00:00
Esteban Küber
3848ffcee7 Tweak wording of missing angle backets in qualified path 2023-09-28 00:37:20 +00:00
Michael Howell
0487237f12 rustdoc: add URLs for test issues 2023-09-27 17:22:18 -07:00
Tyler Mandry
f4ed73119a Document -Zlink-native-libraries
Originally added in #70095.
2023-09-27 17:21:38 -07:00
Michael Howell
7cd8b2c925 Rename issue-\d+.rs tests to have meaningful names 2023-09-27 17:15:37 -07:00
Michael Howell
79195d5cbb Add crate_name to test so that it can be renamed 2023-09-27 16:51:21 -07:00
bors
fbd4423b97 Auto merge of #116148 - DaniPopes:rustdoc-type-layout-ws, r=jsha
Fix whitespace in rustdoc type_layout.html

`Size: <size>` was missing a space after the colon:

![image](https://github.com/rust-lang/rust/assets/57450786/c5a672f3-a28a-4b56-91e7-a4e6ffc8106e)
2023-09-27 22:56:40 +00:00
Matthias Krüger
e8a33847fd don't clone copy types 2023-09-28 00:20:32 +02:00
Matthias Krüger
fd95627134 fix clippy::{redundant_guards, useless_format} 2023-09-27 23:49:15 +02:00
bors
e7c502d930 Auto merge of #109597 - cjgillot:gvn, r=oli-obk
Implement a global value numbering MIR optimization

The aim of this pass is to avoid repeated computations by reusing past assignments. It is based on an analysis of SSA locals, in order to perform a restricted form of common subexpression elimination.

By opportunity, this pass allows for some simplifications by combining assignments. For instance, this pass could be able to see through projections of aggregates to directly reuse the aggregate field (not in this PR).

We handle references by assigning a different "provenance" index to each `Ref`/`AddressOf` rvalue. This ensure that we do not spuriously merge borrows that should not be merged. Meanwhile, we consider all the derefs of an immutable reference to a freeze type to give the same value:
```rust
_a = *_b // _b is &Freeze
_c = *_b // replaced by _c = _a
```
2023-09-27 21:06:30 +00:00
Matthias Krüger
809ab64e97 rustdoc: while -> if
we will always return once we step inside the while-loop thus `if` is sufficient here
2023-09-27 22:07:33 +02:00
bors
7b4b1b08b6 Auto merge of #114901 - compiler-errors:style-guide-wc, r=calebcartwright
Amend style guide section for formatting where clauses in type aliases

This PR has two parts:
1. Amend wording about breaking before or after the `=`, which is a style guide bugfix to align it with current rustfmt behavior.
2. Explain how to format trailing (#89122) where clauses, which are preferred in both GATs (#90076) and type aliases (#114662).

r? `@joshtriplett`
2023-09-27 19:17:30 +00:00
Urgau
1b2c1a8583 Fix ICE by introducing an expr_or_init variant for outside bodies 2023-09-27 18:59:24 +02:00
Urgau
bd360472b1 Simplify casting logic of the invalid_reference_casting lint 2023-09-27 18:50:26 +02:00
bors
d4589a492f Auto merge of #116202 - emmanuel-ferdman:wip, r=ehuss
Update location of `personality/gcc.rs`

**PR Summary**:
PR updates the location of `personality/gcc.rs` file in the docs.
2023-09-27 16:09:54 +00:00
Emmanuel Ferdman
08c4963a32
Update location of personality 2023-09-27 18:30:33 +03:00
Alex Macleod
17b1026448 Use absolute paths in rustc_lint::passes macros
A cosmetic change, so the callsite doesn't have to import things
2023-09-27 15:06:59 +00:00