Commit graph

2752 commits

Author SHA1 Message Date
Dylan DPC 8c89601647
Rollup merge of #111494 - compiler-errors:variant-order, r=petrochenkov
Encode `VariantIdx` so we can decode ADT variants in the right order

As far as I can tell, we don't guarantee anything about the ordering of `DefId`s and module children...

The code that motivated this PR (#111483) looks something like:

```rust
#[derive(Protocol)]
pub enum Data {
    #[protocol(discriminator(0x00))]
    Disconnect(Disconnect),
    EncryptionRequest,
    /* more variants... */
}
```

The specific macro ([`protocol`](https://github.com/dylanmckay/protocol)) doesn't really matter, but as far as I can tell (from calls to `build_reduced_graph`), the presence of that `#[protocol(..)]` helper attribute causes the def-id of the `Disconnect` enum variant to be collected *after* its siblings, and it shows up after the other variants in `module_children`.

When we decode the variants for `Data` in a child crate (an example test, in this case), this means that the `Disconnect` variant is moved to the end of the variants list, and all of the other variants now have incorrect relative discriminant data, causing the ICE.

This PR fixes this by sorting manually by variant index after they are decoded. I guess there are alternative ways of fixing this, such as not reusing `module_children_non_reexports` to encode the order-sensitive ADT variants, or to do some sorting in `rustc_resolve`... but none of those seemed particularly satisfying either.

~I really struggled to create a reproduction here -- it required at least 3 crates, one of which is a proc macro, and then some code to actually compute discriminants in the child crate... Needless to say, I failed to repro this in a test, but I can confirm that it fixes the regression in #111483.~ Test exists now.

r? `@petrochenkov` but feel free to reassign. ~Again, sorry for no test, but I hope the explanation at least suggests why a fix like this is likely necessary.~ Feedback is welcome.
2023-05-13 11:05:34 +05:30
Dylan DPC 770fd738c7
Rollup merge of #111469 - Dushistov:fix-coverage-data-race, r=wesleywiser
Fix data race in llvm source code coverage

Fixes #91092 .

Before this patch, increment of counters for code coverage looks like this:
```
 movq    .L__profc__RNvCsd6wgJFC5r19_3lib6bugaga+8(%rip), %rax
 addq    $1, %rax
movq    %rax, .L__profc__RNvCsd6wgJFC5r19_3lib6bugaga+8(%rip)
```

after this patch:

```
lock            incq    .L__profc__RNvCs3JgIB2SjHh2_3lib6bugaga+8(%rip)
```
2023-05-13 11:05:34 +05:30
Dylan DPC 05ca3e31df
Rollup merge of #111451 - compiler-errors:note-cast-origin, r=b-naber
Note user-facing types of coercion failure

When coercing, for example, `Box<A>` into `Box<dyn B>`, make sure that any failure notes mention *those* specific types, rather than mentioning inner types, like "the cast from `A` to `dyn B`".

I expect end-users are often confused when we skip layers of types and only mention the "innermost" part of a coercion, especially when other notes point at HIR, e.g. #111406.
2023-05-13 11:05:33 +05:30
Dylan DPC 36125c43da
Rollup merge of #111096 - AngelicosPhosphoros:overflow_checks_issue_91130, r=petrochenkov
Add support for `cfg(overflow_checks)`

This PR adds support for detecting if overflow checks are enabled in similar fashion as `debug_assertions` are detected. Possible use-case of this, for example, if we want to use checked integer casts in builds with overflow checks, e.g.

```rust
pub fn cast(val: usize)->u16 {
    if cfg!(overflow_checks) {
        val.try_into().unwrap()
    }
    else{
        vas as _
    }
}
```

Resolves #91130.
2023-05-13 11:05:33 +05:30
Dylan DPC 6cb13585d0
Rollup merge of #110454 - oli-obk:limited_impl_trait_in_assoc_type, r=compiler-errors
Require impl Trait in associated types to appear in method signatures

This implements the limited version of TAIT that was proposed in https://github.com/rust-lang/rust/issues/107645#issuecomment-1477899536

Similar to `impl Trait` in return types, `impl Trait` in associated types may only be used within the impl block which it is a part of. To make everything simpler and forward compatible to getting desugared to a plain type alias impl trait in the future, we're requiring that any associated functions or constants that want to register hidden types must be using the associated type in their signature (type of the constant or argument/return type of the associated method. Where bounds mentioning the associated type are ignored).

We have preexisting tests checking that this works transitively across multiple associated types in situations like

```rust
impl Foo for Bar {
    type A = impl Trait;
    type B = impl Iterator<Item = Self::A>;
    fn foo() -> Self::B { ...... }
}
```
2023-05-13 11:05:32 +05:30
Scott McMurray a9570a34cd Stop checking for the absense of something that doesn't exist
A couple of codegen tests are doing
```
// CHECK-NOT: slice_index_len_fail
```

However, that function no longer exists: [the only places](https://github.com/search?q=repo%3Arust-lang%2Frust+slice_index_len_fail&type=code) it occurs in the repo are in those tests.

So this PR updates the tests to check for the absense of the functions that are actually used today to panic for out-of-bounds indexing.
2023-05-12 21:59:26 -07:00
bors 16d3e18281 Auto merge of #111447 - scottmcm:remove-more-assumes, r=thomcc
Remove useless `assume`s from `slice::iter(_mut)`

You were right in https://github.com/rust-lang/rust/pull/111395#discussion_r1190312704,
r? `@the8472`

LLVM already removes these assumes while optimizing, as can be seen in <https://rust.godbolt.org/z/KTfWKbdEM>.
2023-05-13 03:09:05 +00:00
Scott McMurray c50a2e1d17 Remove useless assumes from slice::iter(_mut) 2023-05-12 17:34:55 -07:00
Michael Goulet ff54c801f0 Encode VariantIdx so we can decode variants in the right order 2023-05-13 00:26:35 +00:00
bors 9850584a4e Auto merge of #103413 - RalfJung:phantom-dropck, r=lcnr
PhantomData: fix documentation wrt interaction with dropck

As far as I could find out, the `PhantomData`-dropck interaction *only* affects code using `may_dangle`. The documentation in the standard library has not been updated for 8 years and thus stems from a time when Rust still used "parametric dropck", before [RFC 1238](https://rust-lang.github.io/rfcs/1238-nonparametric-dropck.html). Back then what the docs said was correct, but with `may_dangle` dropck it stopped being entirely accurate and these days, with NLL, it is actively misleading.

Fixes https://github.com/rust-lang/rust/issues/102810
Fixes https://github.com/rust-lang/rust/issues/70841
Cc `@nikomatsakis` I hope what I am saying here is right.^^
2023-05-13 00:23:51 +00:00
Lukas Markeffsky 9c418e5170 allow mutating function args through &raw const 2023-05-13 00:00:51 +02:00
Michael Goulet c06e61151c do not allow inference in pred_known_to_hold_modulo_regions 2023-05-12 18:47:45 +00:00
bors 077fc26f0a Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwco
Uplift `clippy::{drop,forget}_{ref,copy}` lints

This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints.

Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted.

## `drop_ref` and `forget_ref`

The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value.

### Example

```rust
let mut lock_guard = mutex.lock();
std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex
// still locked
operation_that_requires_mutex_to_be_unlocked();
```

### Explanation

Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended.

## `drop_copy` and `forget_copy`

The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait.

### Example

```rust
let x: i32 = 42; // i32 implements Copy
std::mem::forget(x) // A copy of x is passed to the function, leaving the
                    // original unaffected
```

### Explanation

Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation.

-----

Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
2023-05-12 12:04:32 +00:00
Oli Scherer 4e92f761fe Use the opaque_types_defined_by query to cheaply check for whether a hidden type may be registered for an opaque type 2023-05-12 10:26:50 +00:00
Oli Scherer f08b517597 Require impl Trait in associated types to appear in method signatures 2023-05-12 10:24:03 +00:00
bors 0b795044c6 Auto merge of #111493 - matthiaskrgr:rollup-iw1z59b, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #111179 (Fix instrument-coverage tests by using Python to sort instantiation groups)
 - #111393 (bump windows crate 0.46 -> 0.48)
 - #111441 (Verify copies of mutable pointers in 2 stages in ReferencePropagation)
 - #111456 (Update cargo)
 - #111490 (Don't ICE in layout computation for placeholder types)
 - #111492 (use by ref TokenTree iterator to avoid a few clones)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-12 07:31:18 +00:00
Matthias Krüger 4c12f5d252
Rollup merge of #111490 - compiler-errors:layout-placeholder, r=aliemjay
Don't ICE in layout computation for placeholder types

We use `layout_of` for the built-in `PointerLike` trait to check if a type can be coerced to a `dyn*`.

Since the new solver canonicalizes parameter types to placeholders, that code needs to be able to treat placeholders like params, and for the most part it does, **except** for a call to `is_trivially_sized`. This PR fixes that.
2023-05-12 07:11:14 +02:00
Matthias Krüger ab18da61f4
Rollup merge of #111441 - cjgillot:issue-111422, r=JakobDegen
Verify copies of mutable pointers in 2 stages in ReferencePropagation

Fixes #111422

In the first stage, we mark the copies as reborrows, to be checked later.
In the second stage, we walk the reborrow chains to verify that all stages are fully replacable.

The replacement itself mirrors the check, and iterates through the reborrow chain.

r? ``````@RalfJung``````
cc ``````@JakobDegen``````
2023-05-12 07:11:13 +02:00
Matthias Krüger ea332b5937
Rollup merge of #111179 - Zalathar:sort-groups, r=Mark-Simulacrum
Fix instrument-coverage tests by using Python to sort instantiation groups

#110942 was intended to fix a set of `-Cinstrument-coverage` tests, but it ended up silently *breaking* those tests on Linux, for annoying reasons detailed at #111171.

Dealing with `diff --ignore-matching-lines` across multiple platforms has been such a hassle that I've instead written a simple Python script that can detect instantiation groups in the output of `llvm-cov show`, and sort them in a predictable order so that they can be used as snapshots for an ordinary invocation of `diff`.

This approach should be much less error-prone, because it can't accidentally ignore the wrong lines, and any unforeseen problems will tend to result in a Python exception or a failing diff.
2023-05-12 07:11:12 +02:00
bors 699a862a3d Auto merge of #111489 - compiler-errors:rollup-g3vgzss, r=compiler-errors
Rollup of 7 pull requests

Successful merges:

 - #106038 (use implied bounds when checking opaque types)
 - #111366 (Make `NonUseContext::AscribeUserTy` carry `ty::Variance`)
 - #111375 (CFI: Fix SIGILL reached via trait objects)
 - #111439 (Fix backtrace normalization in ice-bug-report-url.rs)
 - #111444 (Only warn single-use lifetime when the binders match.)
 - #111459 (Update browser-ui-test version to 0.16.0)
 - #111460 (Improve suggestion for `self: Box<self>`)

Failed merges:

 - #110454 (Require impl Trait in associated types to appear in method signatures)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-12 04:45:50 +00:00
Michael Goulet 926e874fd1 Dont check must_use on nested impl Future from fn 2023-05-12 02:08:43 +00:00
Michael Goulet 3009cb3f6b Don't ICE in layout computation for placeholder types 2023-05-12 00:58:06 +00:00
Michael Goulet 6641b49cdd
Rollup merge of #111460 - clubby789:lowercase-box-self, r=compiler-errors
Improve suggestion for `self: Box<self>`

Fixes #110642
2023-05-11 17:43:09 -07:00
Michael Goulet eead6f4703
Rollup merge of #111459 - GuillaumeGomez:update-browser-ui-test, r=notriddle
Update browser-ui-test version to 0.16.0

This new version brings one major improvement: it allows to use the original color format in checks (I plan to slowly continue converting colors back to their "original" format, ie the one used in CSS).

It also provides some improvements in some commands API.

r? `````@notriddle`````
2023-05-11 17:43:09 -07:00
Michael Goulet 7c31df9d6c
Rollup merge of #111444 - cjgillot:issue-111400, r=oli-obk
Only warn single-use lifetime when the binders match.

Fixes https://github.com/rust-lang/rust/issues/111400
2023-05-11 17:43:08 -07:00
Michael Goulet d4d15e8a74
Rollup merge of #111439 - uweigand:backtrace-normalize, r=compiler-errors
Fix backtrace normalization in ice-bug-report-url.rs

This test case currently fails on s390x, and probably other platforms where the last line of a backtrace does not contain and " at <source location>" specification.

The problem with the existing normalization lines
// normalize-stderr-test "\s*\d{1,}: .*\n" -> ""
// normalize-stderr-test "\s at .*\n" -> ""
is that \s matches all whitespace, including newlines, so the first (but not second) of these regexes may merge multiple lines.  Thus the output differs depending on which of these matches on the last line of a backtrace.

As the whitespace used in backtraces is just normal space characters, change both regexes to just match at least one space character instead:
// normalize-stderr-test " +\d{1,}: .*\n" -> ""
// normalize-stderr-test " + at .*\n" -> ""
2023-05-11 17:43:08 -07:00
Michael Goulet 691a5f3883
Rollup merge of #111375 - rcvalle:rust-cfi-fix-106547, r=bjorn3
CFI: Fix SIGILL reached via trait objects

Fix #106547 by transforming the concrete self into a reference to a trait object before emitting type metadata identifiers for trait methods.
2023-05-11 17:43:07 -07:00
Michael Goulet 341d6dfba5
Rollup merge of #106038 - aliemjay:opaque-implied, r=lcnr
use implied bounds when checking opaque types

During opaque type inference, we check for the well-formedness of the hidden type in the opaque type's own environment, not the one of the defining site, which are different in the case of TAIT.

However in the case of associated-type-impl-trait, we don't use implied bounds from the impl header. This caused us to reject the following:
```rust
trait Service<Req> {
    type Output;
    fn call(req: Req) -> Self::Output;
}

impl<'a, Req> Service<&'a Req> for u8 {
    type Output= impl Sized; // we can't prove WF of hidden type  `WF(&'a Req)` although it's implied by the impl
    //~^ ERROR type parameter Req doesn't live long enough
    fn call(req: &'a Req) -> Self::Output {
        req
    }
}
```

although adding an explicit bound would make it pass:
```diff
- impl<'a, Req> Service<&'a Req> for u8 {
+ impl<'a, Req> Service<&'a Req> for u8  where Req: 'a, {
```

I believe it should pass as we already allow the concrete type to be used:
```diff
impl<'a, Req> Service<&'a Req> for u8 {
-    type Output= impl Sized;
+    type Output= &'a Req;
```

Fixes #95922

Builds on #105982

cc ``@lcnr`` (because implied bounds)

r? ``@oli-obk``
2023-05-11 17:43:06 -07:00
Michael Goulet 14bf909e71 Note base types of coercion 2023-05-12 00:10:52 +00:00
Evgeniy A. Dushistov 6b58ff5cdf Usage of atomic counters for llvm code coverage 2023-05-12 01:40:04 +03:00
clubby789 2555f3bbcf Better diagnostics for env! where variable contains escape 2023-05-11 21:41:07 +01:00
Jubilee Young 4499daac77 Bless tests for portable-simd sync
API changes resulted in subtle MIR and impl differences
2023-05-11 12:14:57 -07:00
bjorn3 3082865e6c Ignore test on MSVC for now
I can't figure out how to link with the MSVC toolchain
2023-05-11 14:47:56 +00:00
bjorn3 8ace03e152 Fix no-alloc-shim test on MSVC 2023-05-11 14:35:10 +00:00
bjorn3 34f6a83b28 Fix test 2023-05-11 14:35:10 +00:00
bjorn3 8ea28a4132 Add test 2023-05-11 14:35:09 +00:00
bjorn3 66982a383b Prevent insta-stable no alloc shim support
You will need to add the following as replacement for the old __rust_*
definitions when not using the alloc shim.

    #[no_mangle]
    static __rust_no_alloc_shim_is_unstable: u8 = 0;
2023-05-11 14:35:09 +00:00
AngelicosPhosphoros 7c263adb2a Add support for cfg(overflow_checks)
This PR adds support for detecting if overflow checks are enabled in similar fashion as debug_assertions are detected.
Possible use-case of this, for example, if we want to use checked integer casts in builds with overflow checks, e.g.

```rust
pub fn cast(val: usize)->u16 {
    if cfg!(overflow_checks) {
        val.try_into().unwrap()
    }
    else{
        vas as _
    }
}
```

Resolves #91130.
Tracking issue: #111466.
2023-05-11 18:06:31 +04:00
clubby789 3851a4bb91 Improve error for self: Box<self> 2023-05-11 13:21:10 +01:00
Ulrich Weigand cac7e42b52 Fix backtrace normalization in ice-bug-report-url.rs
This test case currently fails on s390x, and probably other
platforms where the last line of a backtrace does not contain
and " at <source location>" specification.

The problem with the existing normalization lines
// normalize-stderr-test "\s*\d{1,}: .*\n" -> ""
// normalize-stderr-test "\s at .*\n" -> ""
is that \s matches all whitespace, including newlines, so the
first (but not second) of these regexes may merge multiple
lines.  Thus the output differs depending on which of these
matches on the last line of a backtrace.

As the whitespace used in backtraces is just normal space
characters, change both regexes to just match at least one
space character instead:
// normalize-stderr-test " +\d{1,}: .*\n" -> ""
// normalize-stderr-test " + at .*\n" -> ""
2023-05-11 13:59:38 +02:00
Bryanskiy 670f5b134e Populate effective visibilities in rustc_privacy 2023-05-11 14:51:01 +03:00
Guillaume Gomez 8e55400ec9 Convert some GUI tests color checks to use original format 2023-05-11 11:49:16 +02:00
Guillaume Gomez 0630283e9d Migrate to 0.16.0 browser-ui-test version 2023-05-11 11:34:22 +02:00
Matthias Krüger 07af55edd4
Rollup merge of #111448 - compiler-errors:rustdoc-alias-impl, r=notriddle
Use proper impl self type for alias impl in rustdoc

We don't want to use `type_of(type_alias)`, we want to use `type_of(impl)` -- this will give us the self type of the impl *properly substituted* in the case that it's an alias.

Fixes #111420
2023-05-11 07:05:29 +02:00
Matthias Krüger 968911dbc0
Rollup merge of #111432 - cjgillot:issue-111426, r=oli-obk
Use visit_assign to detect SSA locals.

I screwed up the logic in 3c43b61b87.

Fixes https://github.com/rust-lang/rust/issues/111426
2023-05-11 07:05:29 +02:00
Matthias Krüger acae72e493
Rollup merge of #111385 - durin42:vec-panik-17, r=Amanieu
vec-shrink-panik: update expectations to work on LLVM 17

For some reason, the called function is `cleanup` on LLVM 17 instead of `filter`.

r? `@Amanieu`
2023-05-11 07:05:28 +02:00
Matthias Krüger aa9adf457b
Rollup merge of #111292 - Urgau:check-cfg-issue-111291, r=petrochenkov
Fix mishandled `--check-cfg` arguments order

This PR fixes a bug in `--check-cfg` where the order of `--check-cfg=names(a)` and `--check-cfg=values(a,…)` would trip the compiler.

Fixes https://github.com/rust-lang/rust/issues/111291
cc `@taiki-e` `@petrochenkov`
2023-05-11 07:05:27 +02:00
Matthias Krüger 40d933a19a
Rollup merge of #108705 - clubby789:refutable-let-closure-borrow, r=cjgillot
Prevent ICE with broken borrow in closure

r? `@Nilstrieb`
Fixes #108683

This solution isn't ideal, I'm hoping to find a way to continue compilation without ICEing.
2023-05-11 07:05:26 +02:00
Michael Goulet 6509c42d16 Use proper impl self type for alias impl in rustdoc 2023-05-10 22:49:05 +00:00
Camille GILLOT a2fe9935ea Only warn single-use lifetime when the binders match. 2023-05-10 19:49:02 +00:00
Camille GILLOT aeac555578 Do not see through copies of mutable pointers. 2023-05-10 19:22:57 +00:00
Camille GILLOT d0d4e0237f Iteratively replace pointers. 2023-05-10 19:22:54 +00:00
Urgau e280df556d Add note to suggest using let _ = x to ignore the value 2023-05-10 19:36:02 +02:00
Urgau d23f8957ae Improve warning message by saying that it "does nothing" 2023-05-10 19:36:02 +02:00
Urgau 457fa953a2 Use label instead of note to be more consistent with other lints 2023-05-10 19:36:02 +02:00
Urgau 61ff2718f7 Adjust tests for new drop and forget lints 2023-05-10 19:36:02 +02:00
Urgau 971b9b23b5 Uplift clippy::forget_copy to rustc 2023-05-10 19:36:01 +02:00
Urgau 1ef9c163aa Uplift clippy::forget_ref to rustc 2023-05-10 19:36:01 +02:00
Urgau 156f5563c7 Uplift clippy::drop_copy to rustc 2023-05-10 19:36:01 +02:00
Urgau 28cdbc2a64 Uplift clippy::drop_ref to rustc 2023-05-10 19:36:01 +02:00
Camille GILLOT b64e9113e2 Add test. 2023-05-10 17:21:35 +00:00
b-naber 7871bec7aa add test 2023-05-10 16:03:46 +00:00
Camille GILLOT 6ad0497cc0 Use visit_assign to detect SSA locals. 2023-05-10 15:26:51 +00:00
bohan 7c1bc0353b refactor(resolve): clean up the early error return caused by non-call 2023-05-10 22:35:01 +08:00
Augie Fackler fbe479558c vec-shrink-panik: update expectations to work on LLVM 17
For some reason, the called function is `cleanup` on LLVM 17 instead of
`filter`.

r? @Amanieu
2023-05-10 09:31:33 -04:00
bors 25444e5a2e Auto merge of #111414 - matthiaskrgr:rollup-q0qoc47, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #110673 (Make alias bounds sound in the new solver (take 2))
 - #110747 (Encode types in SMIR)
 - #111095 (Correctly handle associated items of a trait inside a `#[doc(hidden)]` item)
 - #111381 (Keep encoding attributes for closures)
 - #111408 (Fix incorrect implication of transmuting slices)
 - #111410 (Switch to `EarlyBinder` for `thir_abstract_const` query)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-10 06:53:47 +00:00
Matthias Krüger d117b41409
Rollup merge of #111095 - GuillaumeGomez:fix-assoc-item-trait-inside-hidden, r=notriddle
Correctly handle associated items of a trait inside a `#[doc(hidden)]` item

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

cc `@compiler-errors`
r? `@notriddle`
2023-05-10 06:12:14 +02:00
Matthias Krüger f1922275b7
Rollup merge of #110747 - oli-obk:smirty, r=spastorino
Encode types in SMIR

The first commit makes sure we can actually store a Ty<'tcx> (with the lifetime) in the thread local and get it back out. The second commit then introduces types.

r? `@spastorino`
2023-05-10 06:12:13 +02:00
Matthias Krüger c14d912cd2
Rollup merge of #110673 - compiler-errors:alias-bounds-2, r=lcnr
Make alias bounds sound in the new solver (take 2)

Make alias bounds sound in the new solver (in a way that does not require coinduction) by only considering them for projection types whose corresponding trait refs come from a param-env candidate.

That is, given `<T as Trait>::Assoc: Bound`, we only *really* need to consider the alias bound if `T: Trait` is satisfied via a param-env candidate. If it's instead satisfied, e.g., via an user provided impl candidate or a , then that impl should have a concrete type to which we could otherwise normalize `<T as Trait>::Assoc`, and that concrete type is then responsible to prove the `Bound` on it.

Similar consideration is given to opaque types, since we only need to consider alias bounds if we're *not* in reveal-all mode, since similarly we'd be able to reveal the opaque types and prove any bounds that way.

This does not remove that hacky "eager projection replacement" logic from object bounds, which are somewhat like alias bounds. But removing this eager normalization behavior (added in #108333) would require full coinduction to be enabled. Compare to #110628, which does remove this object-bound custom logic but requires coinduction to be sound.

r? `@lcnr`
2023-05-10 06:12:13 +02:00
bors 63fc57b98e Auto merge of #106560 - bjorn3:support_staticlib_dylib_linking, r=pnkfelix
Support linking to rust dylib with --crate-type staticlib

This allows for example dynamically linking libstd, while statically linking the user crate into an executable or C dynamic library. For this two unstable flags (`-Z staticlib-allow-rdylib-deps` and `-Z staticlib-prefer-dynamic`) are introduced. Without the former you get an error. The latter is the equivalent to `-C prefer-dynamic` for the staticlib crate type to indicate that dynamically linking is preferred when both options are available, like for libstd. Care must be taken to ensure that no crate ends up being merged into two distinct staticlibs that are linked together. Doing so will cause a linker error at best and undefined behavior at worst. In addition two distinct staticlibs compiled by different rustc may not be combined under any circumstances due to some rustc private symbols not being mangled.

To successfully link a staticlib, `--print native-static-libs` can be used while compiling to ask rustc for the linker flags necessary when linking the staticlib. This is an existing flag which previously only listed native libraries. It has been extended to list rust dylibs too. Trying to locate libstd yourself to link against it is not supported and may break if for example the libstd of multiple rustc versions are put in the same directory.

For an example on how to use this see the `src/test/run-make-fulldeps/staticlib-dylib-linkage/` test.
2023-05-10 03:40:40 +00:00
asquared31415 517ea5652a tidy check to find misc files in ui tests, and clean up the results 2023-05-09 20:35:39 -04:00
bors 50dff955a9 Auto merge of #106285 - cjgillot:refprop-ssa, r=JakobDegen
Implement SSA-based reference propagation

Rust has a tendency to create a lot of short-lived borrows, in particular for method calls. This PR aims to remove those short-lived borrows with a const-propagation dedicated to pointers to local places.

This pass aims to transform the following pattern:
```
  _1 = &raw? mut? PLACE;
  _3 = *_1;
  _4 = &raw? mut? *_1;
```

Into
```
  _1 = &raw? mut? PLACE;
  _3 = PLACE;
  _4 = &raw? mut? PLACE;
```

where `PLACE` is a direct or an indirect place expression.

By removing indirection, this pass should help both dest-prop and const-prop to handle more cases.
This optimization is distinct from const-prop and dataflow const-prop since the borrow-reborrow patterns needs to preserve borrowck invariants, especially the uniqueness property of mutable references.

The pointed-to places are computed using a SSA analysis. We suppose that removable borrows are typically temporaries from autoref, so they are by construction assigned only once, and a SSA analysis is enough to catch them. For each local, we store both where and how it is used, in order to efficiently compute the all-or-nothing property. Thanks to `Derefer`, we only have to track locals, not places in general.

---

There are 3 properties that need to be upheld for this transformation to be legal:
- place constness: `PLACE` must refer to the same memory wherever it appears;
- pointer liveness: we must not introduce dereferences of dangling pointers;
- `&mut` borrow uniqueness.

## Constness

If `PLACE` is an indirect projection, if its of the form `(*LOCAL).PROJECTIONS` where:
- `LOCAL` is SSA;
- all projections in `PROJECTIONS` are constant (no dereference and no indexing).

If `PLACE` is a direct projection of a local, we consider it as constant if:
- the local is always live, or it has a single `StorageLive` that dominates all uses;
- all projections are constant.

# Liveness

When performing a substitution, we must take care not to introduce uses of dangling locals.

Using a dangling borrow is UB. Therefore, we assume that for any use of `*x`, where `x` is a borrow, the pointed-to memory is live.

Limitations:
- occurrences of `*x` in an `&raw mut? *x` are accepted;
- raw pointers are allowed to be dangling.

In those 2 case, we do not substitute anything, to be on the safe side.

**Open question:** we do not differentiate borrows of ZST and non-ZST. The UB rules may be
different depending on the layout. Having a different treatment would effectively prevent this
pass from running on polymorphic MIR, which defeats the purpose of MIR opts.

## Uniqueness

For `&mut` borrows, we also need to preserve the uniqueness property:
we must avoid creating a state where we interleave uses of `*_1` and `_2`.
To do it, we only perform full substitution of mutable borrows:
we replace either all or none of the occurrences of `*_1`.

Some care has to be taken when `_1` is copied in other locals.
```
   _1 = &raw? mut? _2;
   _3 = *_1;
   _4 = _1
   _5 = *_4
```
In such cases, fully substituting `_1` means fully substituting all of the copies.

For immutable borrows, we do not need to preserve such uniqueness property,
so we perform all the possible substitutions without removing the `_1 = &_2` statement.
2023-05-09 21:54:34 +00:00
Michael Goulet 0dbaae4165 Make alias bounds sound in the new solver 2023-05-09 20:37:50 +00:00
Ramon de C Valle 7c7b22e62c CFI: Fix SIGILL reached via trait objects
Fix #106547 by transforming the concrete self into a reference to a
trait object before emitting type metadata identifiers for trait
methods.
2023-05-09 20:04:19 +00:00
Camille GILLOT bde213cfe5 Add needs-unwind. 2023-05-09 19:39:46 +00:00
Matthias Krüger 273fbf47ab
Rollup merge of #111282 - scottmcm:remove-unneeded-assumes, r=workingjubilee
Remove some `assume`s from slice iterators that don't do anything

Because the start pointer is iterators is already a `NonNull`, we emit the appropriate `!nonnull` metadata when loading the pointer to tell LLVM that it's non-null.

Probably the best way to see that it's the metadata that's important (and not the `assume`) is to observe that LLVM actually *removes* the `assume` from the optimized IR: <https://rust.godbolt.org/z/KhE6G963n>.

(I also checked that, yes, the if-not-ZST `assume` on `end` is still doing something: it's how there's a `!nonnull` metadata on its load, even though it's an ordinary raw pointer.  The codegen test added in this PR fails if the other `assume` is  removed.)
2023-05-09 20:49:33 +02:00
Matthias Krüger 363d158cd8
Rollup merge of #111215 - BoxyUwU:resolve_anon_consts_differently, r=cjgillot
Various changes to name resolution of anon consts

Sorry this PR is kind of all over the place ^^'

Fixes #111012

- Rewrites anon const nameres to all go through `fn resolve_anon_const` explicitly instead of `visit_anon_const` to ensure that we do not accidentally resolve anon consts as if they are allowed to use generics when they aren't. Also means that we dont have bits of code for resolving anon consts that will get out of sync (i.e. legacy const generics and resolving path consts that were parsed as type arguments)
- Renames two of the `LifetimeRibKind`, `AnonConst -> ConcreteAnonConst` and `ConstGeneric -> ConstParamTy`
- Noticed while doing this that under `generic_const_exprs` all lifetimes currently get resolved to errors without any error being emitted which was causing a bunch of tests to pass without their bugs having been fixed, incidentally fixed that in this PR and marked those tests as `// known-bug:`. I'm fine to break those since `generic_const_exprs` is a very unstable incomplete feature and this PR _does_ make generic_const_exprs "less broken" as a whole, also I can't be assed to figure out what the underlying causes of all of them are. This PR reopens #77357 #83993
- Changed `generics_of` to stop providing generics and predicates to enum variant discriminant anon consts since those are not allowed to use generic parameters
- Updated the error for non 'static lifetime in const arguments and the error for non 'static lifetime in const param tys to use `derive(Diagnostic)`

I have a vague idea why const-arg-in-const-arg.rs, in-closure.rs and simple.rs have started failing which is unfortunate since these were deliberately made to work, I think lifetime resolution being broken just means this regressed at some point and nobody noticed because the tests were not testing anything :( I'm fine breaking these too for the same reason as the tests for #77357 #83993. I couldn't get `// known-bug` to work for these ICEs and just kept getting different stderr between CI and local `--bless` so I just removed them and will create an issue to track re-adding (and fixing) the bugs if this PR lands.

r? `@cjgillot` cc `@compiler-errors`
2023-05-09 20:49:32 +02:00
Matthias Krüger 985ea22489
Rollup merge of #111021 - c410-f3r:dqewdas, r=petrochenkov
Move some tests

r? ``@petrochenkov``
2023-05-09 20:49:31 +02:00
Matthias Krüger 88fbfafe9e
Rollup merge of #97320 - usbalbin:stabilize_const_ptr_read, r=m-ou-se
Stabilize const_ptr_read

Stabilizes const_ptr_read, with tracking issue #80377
2023-05-09 20:49:30 +02:00
Camille GILLOT 8e5910fdf2 Separate test cases into bbs. 2023-05-09 17:59:35 +00:00
Camille GILLOT 3c43b61b87 Do not consider borrowed Freeze locals as SSA. 2023-05-09 17:59:35 +00:00
Camille GILLOT 3490375570 Implement SSA-based reference propagation. 2023-05-09 17:59:34 +00:00
bors 3a37c2f052 Auto merge of #111371 - compiler-errors:revert-110907, r=petrochenkov
Revert "Populate effective visibilities in `rustc_privacy`"

This reverts commit cff85f22f5, cc #110907. It needs to be fixed, but there are too many issues being reported that I wanted to put up a revert until a proper fix can be committed.

Fixes a ton of issues where private but still reachable impls were missing during codegen:
Fixes #111320
Fixes #111321
Fixes #111334
Fixes #111357
Fixes #111368
Fixes #111373
Fixes #111377
Fixes #111386
Fixes #111387

`@bors` p=1

r? `@petrochenkov`
2023-05-09 15:16:17 +00:00
Dylan DPC f748bb1402
Rollup merge of #111252 - matthewjasper:min-spec-improvements, r=compiler-errors
Min specialization improvements

- Don't allow specialization impls with no items, such implementations are probably not correct and only occur as mistakes in the compiler and standard library
- Fix a missing normalization call
- Adds spans for lifetime errors from overly general specializations

Closes #79457
Closes #109815
2023-05-09 12:33:46 +05:30
Dylan DPC 8c51701b8a
Rollup merge of #111120 - chenyukang:yukang-suggest-let, r=Nilstrieb
Suggest let for possible binding with ty

Origin from https://github.com/rust-lang/rust/pull/109128#discussion_r1179866137

r? `@Nilstrieb`
2023-05-09 12:33:46 +05:30
Dylan DPC dbd090c655
Rollup merge of #110694 - est31:builtin, r=petrochenkov
Implement builtin # syntax and use it for offset_of!(...)

Add `builtin #` syntax to the parser, as well as a generic infrastructure to support both item and expression position builtin syntaxes. The PR also uses this infrastructure for the implementation of the `offset_of!` macro, added by #106934.

cc `@petrochenkov` `@DrMeepster`

cc #110680 `builtin #` tracking issue
cc #106655 `offset_of!` tracking issue
2023-05-09 12:33:45 +05:30
Dylan DPC ff30b8cb7b
Rollup merge of #110583 - Ezrashaw:tweak-make-mut-spans, r=estebank
tweak "make mut" spans when assigning to locals

Work towards fixing #106857

This PR just cleans up a lot of spans which is helpful before properly fixing the issues. Best reviewed commit-by-commit.

r? `@estebank`
2023-05-09 12:33:45 +05:30
Dylan DPC 2ecc72217b
Rollup merge of #110504 - compiler-errors:tweak-borrow-sugg, r=cjgillot
Tweak borrow suggestion span

Avoids a `span_to_snippet` call when we don't need to surround the expression in parentheses. The fact that the suggestion was using the whole span of the expression rather than just appending a `&` was prevented me from using `// run-rustfix` in another PR (https://github.com/rust-lang/rust/pull/110432#discussion_r1170500484).

Also some drive-by renames of functions that have been annoying me for a bit.
2023-05-09 12:33:44 +05:30
Dylan DPC 02a85bd038
Rollup merge of #110304 - cchiw:master, r=davidtwco
Add GNU Property Note

Fix #103001

Generates the missing property note:
```
Displaying notes found in: .note.gnu.property
  Owner                Data size 	Description
  GNU                  0x00000010	NT_GNU_PROPERTY_TYPE_0	      Properties: x86 feature: IBT
```
2023-05-09 12:33:44 +05:30
Michael Goulet e315bbf736 test for reachable private impl 2023-05-08 21:44:21 +00:00
Tomasz Miąsko 83a5a69a4c Align unsized locals
Allocate an extra space for unsized locals and manually align the
storage, since alloca doesn't support dynamic alignment.
2023-05-08 23:40:51 +02:00
bors 2f2c438dce Auto merge of #111358 - compiler-errors:rollup-yv27vrp, r=compiler-errors
Rollup of 6 pull requests

Successful merges:

 - #104070 (Prevent aborting guard from aborting the process in a forced unwind)
 - #109410 (Introduce `AliasKind::Inherent` for inherent associated types)
 - #111004 (Migrate `mir_transform` to translatable diagnostics)
 - #111118 (Suggest struct when we get colon in fileds in enum)
 - #111170 (Diagnostic args are still args if they're documented)
 - #111354 (Fix miscompilation when calling default methods on `Future`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-08 21:00:50 +00:00
Caio 0285611096 Move tests 2023-05-08 17:58:01 -03:00
bors dfe31889e1 Auto merge of #111007 - JakobDegen:nrvo, r=tmiasko
Disable nrvo mir opt

See #111005 and #110902 . The ICE can definitely be hit on stable, the miscompilation I'm not sure about. The pass makes some pretty sketchy assumptions though, and we should not have it on while that's the case.

I'm not going to work on actually fixing this, it's probably not excessively difficult though.

r? rust-lang/mir-opt
2023-05-08 18:10:26 +00:00
Michael Goulet 24ba82de4e
Rollup merge of #111170 - compiler-errors:diag-doc, r=petrochenkov
Diagnostic args are still args if they're documented

Fixes https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.60.23.5Bderive.28Diagnostic.29.5D.60.20works.20badly.20with.20docs/near/355597997

There's a lot of really strange code incongruencies between `Diagnostic` and `Subdiagnostic` derive. Perhaps those macros need some more overhaul, but I didn't really want to do it today.
2023-05-08 09:30:23 -07:00
Michael Goulet beb49671c2
Rollup merge of #111118 - chenyukang:yukang-sugg-struct, r=compiler-errors
Suggest struct when we get colon in fileds in enum

A follow-up fix for https://github.com/rust-lang/rust/pull/109128

From: https://github.com/rust-lang/rust/pull/109128#discussion_r1179304932

r? `@estebank`
2023-05-08 09:30:22 -07:00
Michael Goulet 29ac429c9b
Rollup merge of #109410 - fmease:iat-alias-kind-inherent, r=compiler-errors
Introduce `AliasKind::Inherent` for inherent associated types

Allows us to check (possibly generic) inherent associated types for well-formedness.
Type inference now also works properly.

Follow-up to #105961. Supersedes #108430.
Fixes #106722.
Fixes #108957.
Fixes #109768.
Fixes #109789.
Fixes #109790.

~Not to be merged before #108860 (`AliasKind::Weak`).~

CC `@jackh726`
r? `@compiler-errors`

`@rustbot` label T-types F-inherent_associated_types
2023-05-08 09:30:21 -07:00
Michael Goulet fcb275f85e
Rollup merge of #104070 - nbdd0121:unwind, r=Amanieu
Prevent aborting guard from aborting the process in a forced unwind

Fix #101469
2023-05-08 09:30:21 -07:00
Oli Scherer 5c6e2342f6 Encode types in SMIR 2023-05-08 14:23:19 +00:00
bors a0111af531 Auto merge of #110824 - cjgillot:const-prop-index, r=JakobDegen,oli-obk
ConstProp into PlaceElem::Index.

Noticed this while looking at keccak output MIR.

This pass aims to replace `ProjectionElem::Index` with `ProjectionElem::ConstantIndex` during ConstProp.

r? `@ghost`
2023-05-08 14:23:13 +00:00
Oli Scherer 7f74ae57e8 Create a trait to abstract over the smir API 2023-05-08 14:23:04 +00:00
Jakob Degen 8e2da80fc5 Disable nrvo mir opt 2023-05-08 03:55:41 -07:00
Yuki Okushi c145d93395
Rollup merge of #111211 - compiler-errors:negative-bounds-super, r=TaKO8Ki
Don't compute trait super bounds unless they're positive

Fixes #111207

The comment is modified to explain the rationale for why we even have this recursive call to supertraits in the first place, which doesn't apply to negative bounds since they don't elaborate at all.
2023-05-08 19:41:49 +09:00
Yuki Okushi e3eb6a87bf
Rollup merge of #105354 - BlackHoleFox:apple-deployment-printer, r=oli-obk
Add deployment-target --print flag for Apple targets

This is very useful for crates that need to know what the Apple OS deployment target is for their build scripts or inside of a build environment. Right now, the defaults just get copy/pasted around the ecosystem since they've been stable for so long. But with #104385 in progress, that won't be true anymore and everything will need to move. Ideally whenever it happens again, this could be less painful as everything can ask the compiler what its default is instead.

To show examples of the copy/paste proliferation, here's some crates and/or apps that do:
- [cc](https://github.com/rust-lang/cc-rs/pull/708/files), Soon
-  [mac-notification-sys](https://github.com/h4llow3En/mac-notification-sys/pull/46/files#diff-d0d98998092552a1d3259338c2c71e118a5b8343dd4703c0c7f552ada7f9cb42R10-R12)
- [PyO3](ccb02d1aa1/src/target.rs (L755-L758))
- [Anki](613b5c1034/build/runner/src/bundle/artifacts.rs (L49-L54))
- [jsc-rs](3776726756/xtask/src/build.rs (L402-L405))
... and probably more that a simple GitHub codesearch didn't see
2023-05-08 19:41:48 +09:00
yukang 6b76588222 suggest struct when we get colon in fileds in enum 2023-05-08 14:58:09 +08:00
yukang 5e94b5faf1 code refactor and fix wrong suggestion 2023-05-08 14:56:36 +08:00
Dylan DPC c9433a4969
Rollup merge of #111262 - ChrisDenton:normalize-msvc-output, r=cjgillot
Further normalize msvc-non-utf8-ouput

Fixes #111256 by normalizing this tests down to the essential part so that it only tests for the Unicode output we expect. Also uses a file name that should never occur outside of this test.
2023-05-08 11:39:22 +05:30
Dylan DPC aceb5d951b
Rollup merge of #111056 - JohnBobbo96:fix_box_suggestions, r=compiler-errors
Fix some suggestions where a `Box<T>` is expected.

This fixes #111011, and also adds a suggestion for boxing a unit type when a `Box<T>` was expected and an empty block was found.
2023-05-08 11:39:21 +05:30
Dylan DPC e04c9019f0
Rollup merge of #110827 - compiler-errors:issue-110761-followup, r=cjgillot
Fix lifetime suggestion for type aliases with objects in them

Fixes an issue identified in https://github.com/rust-lang/rust/issues/110761#issuecomment-1520678479

This suggestion, like many other borrowck suggestions, are very fragile and there are other ways to trigger strange behavior even after this PR, so this is just a small improvement and not a total rework 💀
2023-05-08 11:39:20 +05:30
Michael Goulet 4731a25d2d Make suggest_deref_or_ref return a multipart suggestion 2023-05-08 03:42:21 +00:00
Michael Goulet a9051d861c Tweak borrow suggestion 2023-05-08 03:36:30 +00:00
Michael Goulet a156bd7714 Make spans a bit better 2023-05-08 03:34:46 +00:00
John Bobbo 35985091cc
Fix suggestion for boxing an async closure body, and
also add a suggestion for boxing empty blocks.
2023-05-07 20:30:56 -07:00
Michael Goulet 2b9279f313 Diagnostic args are still args if they're documented 2023-05-08 03:19:54 +00:00
yukang a7fc32ceaf fix ice in suggesting 2023-05-08 11:16:17 +08:00
yukang 0bb43c63c3 Suggest let for possible binding with ty 2023-05-08 10:56:20 +08:00
bors 04c53444df Auto merge of #111309 - saethlin:InstSimplify, r=scottmcm
Rename InstCombine to InstSimplify

```
╭ ➜ ben@archlinux:~/rust
╰ ➤ rg -i instcombine
src/doc/rustc-dev-guide/src/mir/optimizations.md
134:may have been misapplied. Examples of this are `InstCombine` and `ConstantPropagation`.

src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/llvm-config.sh
38:                    instcombine instrumentation interpreter ipo irreader lanai \

tests/codegen/slice_as_from_ptr_range.rs
4:// min-llvm-version: 15.0 (because this is a relatively new instcombine)
```

r? `@scottmcm`
2023-05-08 01:28:50 +00:00
bors 613a5c95ae Auto merge of #111222 - scottmcm:constify-is_ascii, r=thomcc
Constify `[u8]::is_ascii` (unstably)

UTF-8 checking in `const fn`-stabilized back in 1.63 (#97367), but apparently somehow ASCII checking was never const-ified, despite being simpler.

New constness-tracking issue for `is_ascii`: #111090

I noticed this working on `ascii::Char`: #110998
2023-05-07 14:18:05 +00:00
Gary Guo 16abe6c83d Fix codegen test 2023-05-07 12:38:47 +01:00
Gary Guo ecd04fd1b5 Add test for unwinding past terminating POF 2023-05-07 12:38:47 +01:00
bors 0dddad0dc5 Auto merge of #111161 - compiler-errors:rtn-super, r=cjgillot
Support return-type bounds on associated methods from supertraits

Support `T: Trait<method(): Bound>` when `method` comes from a supertrait, aligning it with the behavior of associated type bounds (both equality and trait bounds).

The only wrinkle is that I have to extend `super_predicates_that_define_assoc_type` to look for *all* items, not just `AssocKind::Ty`. This will also be needed to support `feature(associated_const_equality)` as well, which is subtly broken when it comes to supertraits, though this PR does not fix those yet. There's a slight chance there's a perf regression here, in which case I guess I could split it out into a separate query.
2023-05-07 11:18:22 +00:00
Camille GILLOT a8988519d5 Propagate PlaceElem::Index. 2023-05-07 11:10:52 +00:00
Scott McMurray c8c5a587ac Tune the is_ascii implementation used for short slices 2023-05-06 22:56:43 -07:00
Yuki Okushi 61115cd753
Rollup merge of #111150 - mj10021:issue-111025-fix, r=petrochenkov
added TraitAlias to check_item() for missing_docs

As in issue #111025 the `missing_docs` was not being triggered for trait aliases.  I added `TraitAlias` to the pattern match for check_item(), and the lint seems to be behaving appropriately
2023-05-07 14:12:15 +09:00
Yuki Okushi 58597717e2
Rollup merge of #105583 - luqmana:bitcast-immediates, r=oli-obk
Operand::extract_field: only cast llval if it's a pointer and replace bitcast w/ pointercast.

Fixes #105439.

Also cc `@erikdesjardins,` looks like another place to cleanup as part of #105545
2023-05-07 14:12:14 +09:00
Zalathar 27a3ce29e3 Fix instrument-coverage tests by using Python to sort instantiation groups 2023-05-07 13:47:14 +10:00
Ben Kimock ff855547f4 Rename InstCombine to InstSimplify 2023-05-06 23:22:32 -04:00
Ali MJ Al-Nasrawy d548747c85 use implied bounds when checking opaque types 2023-05-07 01:41:20 +03:00
James Dietz fd005b06bb delete whitelist and add checks to check_item() for missing_docs
add test and bless
2023-05-06 18:31:50 -04:00
Matthias Krüger 1de257bd33
Rollup merge of #111289 - clubby789:fix-111280, r=jyn514
Check arguments length in trivial diagnostic lint

Fixes #111280
2023-05-06 23:32:03 +02:00
Matthias Krüger e4eaf319c1
Rollup merge of #111203 - Kobzol:remark-print-kind, r=tmiasko
Output LLVM optimization remark kind in `-Cremark` output

Since https://github.com/rust-lang/rust/pull/90833, the optimization remark kind has not been printed. Therefore it wasn't possible to easily determine from the log (in a programmatic way) which remark kind was produced. I think that the most interesting remarks are the missed ones, which can lead users to some code optimization.

Maybe we could also change the format closer to the "old" one:
```
note: optimization remark for tailcallelim at /checkout/src/libcore/num/mod.rs:1:0: marked this call a tail call candidate
```

I wanted to programatically parse the remarks so that they could work e.g. with https://github.com/OfekShilon/optview2. However, now that I think about it, probably the proper solution is to tell rustc to output them to YAML and then use the YAML as input for the opt remark visualization tools. The flag for enabling this does not seem to work though (https://github.com/rust-lang/rust/issues/96705#issuecomment-1117632322).

Still I think that it's good to output the remark kind anyway, it's an important piece of information.

r? ```@tmiasko```
2023-05-06 23:32:02 +02:00
Matthias Krüger bccd29611a
Rollup merge of #111077 - cjgillot:const-prop-unit, r=Mark-Simulacrum
Make more ConstProp tests unit.
2023-05-06 23:32:01 +02:00
Urgau f4ca42f573 Fix --check-cfg bug with args order when parsing 2023-05-06 18:40:47 +02:00
bors 905d5a38d6 Auto merge of #111287 - matthiaskrgr:rollup-9lzax2c, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #110577 (Use fulfillment to check `Drop` impl compatibility)
 - #110610 (Add Terminator conversion from MIR to SMIR, part #1)
 - #110985 (Fix spans in LLVM-generated inline asm errors)
 - #110989 (Make the BUG_REPORT_URL configurable by tools )
 - #111167 (debuginfo: split method declaration and definition)
 - #111230 (add hint for =< as <=)
 - #111279 (More robust debug assertions for `Instance::resolve` on built-in traits with non-standard trait items)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-06 14:16:55 +00:00
clubby789 9027d208f2 Check arguments length in trivial diagnostic lint 2023-05-06 14:42:35 +01:00
Matthias Krüger 83b29ec743
Rollup merge of #111230 - zacklukem:eq-less-to-less-eq, r=compiler-errors
add hint for =< as <=

Adds a compiler hint for when `=<` is typed instead of `<=`

Example hint:
```rust
fn foo() {
    if 1 =< 3 {
        println!("Hello, World!");
    }
}
```
```
error: expected type, found `3`
 --> main.rs:2:13
  |
2 |     if 1 =< 3 {
  |          -- ^ expected type
  |          |
  |          help: did you mean: `<=`
```

This PR only emits the suggestion if there is no space between the `=` and `<`.  This hopefully narrows the scope of when this error is emitted, however this still allows this error to be emitted in cases such as this:
```
error: expected expression, found `;`
 --> main.rs:2:18
  |
2 |     if 1 =< [i32;; 3]>::hello() {
  |          --      ^ expected expression
  |          |
  |          help: did you mean: `<=`
```

Which could be a good reason not to merge since I haven't been able to think of any other ways of narrowing the scope of this diagnostic.

closes #111128
2023-05-06 13:30:05 +02:00
Matthias Krüger f440999bb2
Rollup merge of #111167 - cuviper:type-decl-disubprogram, r=michaelwoerister
debuginfo: split method declaration and definition

When we're adding a method to a type DIE, we only want a DW_AT_declaration
there, because LLVM LTO can't unify type definitions when a child DIE is a
full subprogram definition. Now the subprogram definition gets added at the
CU level with a specification link back to the abstract declaration.

Both GCC and Clang write debuginfo this way for C++ class methods.

Fixes #109730.
Fixes #109934.
2023-05-06 13:30:05 +02:00
Matthias Krüger 8ec84dd523
Rollup merge of #110989 - jyn514:bug-report-url, r=WaffleLapkin
Make the BUG_REPORT_URL configurable by tools

This greatly simplifies how hard it is to set a custom bug report url; previously tools had to copy
the entire hook implementation.

I haven't changed clippy in case they want to make the change upstream instead of the subtree, but
I'm happy to do so here if the maintainers want - cc ````@rust-lang/clippy````

Fixes https://github.com/rust-lang/rust/issues/109486.
2023-05-06 13:30:04 +02:00
Matthias Krüger 77004eafea
Rollup merge of #110610 - spastorino:smir-terminator, r=oli-obk
Add Terminator conversion from MIR to SMIR, part #1

This adds internal MIR TerminatorKind to SMIR Terminator conversion.

r? ```@oli-obk```
2023-05-06 13:30:03 +02:00
Matthias Krüger bcc9aa01b5
Rollup merge of #110577 - compiler-errors:drop-impl-fulfill, r=lcnr
Use fulfillment to check `Drop` impl compatibility

Use an `ObligationCtxt` to ensure that a `Drop` impl does not have stricter requirements than the ADT that it's implemented for, rather than using a `SimpleEqRelation` to (more or less) syntactically equate predicates on an ADT with predicates on an impl.

r? types

### Some background

The old code reads:

```rust
// An earlier version of this code attempted to do this checking
// via the traits::fulfill machinery. However, it ran into trouble
// since the fulfill machinery merely turns outlives-predicates
// 'a:'b and T:'b into region inference constraints. It is simpler
// just to look for all the predicates directly.
```

I'm not sure what this means, but perhaps in the 8 years since that this comment was written (cc #23638) it's gotten easier to process region constraints after doing fulfillment? I don't know how this logic differs from anything we do in the `compare_impl_item` module. Ironically, later on it says:

```rust
// However, it may be more efficient in the future to batch
// the analysis together via the fulfill (see comment above regarding
// the usage of the fulfill machinery), rather than the
// repeated `.iter().any(..)` calls.
```

Also:
* Removes `SimpleEqRelation` which was far too syntactical in its relation.
* Fixes #110557
2023-05-06 13:30:03 +02:00
bors 333b920fee Auto merge of #109421 - mhammerly:extern-force-option, r=petrochenkov
Add `force` option for `--extern` flag

When `--extern force:foo=libfoo.so` is passed to `rustc` and `foo` is not actually used in the crate, ~inject an `extern crate foo;` statement into the AST~ force it to be resolved anyway in `CrateLoader::postprocess()`. This allows you to, for instance, inject a `#[panic_handler]` implementation into a `#![no_std]` crate without modifying its source so that it can be built as a `dylib`. It may also be useful for `#![panic_runtime]` or `#[global_allocator]`/`#![default_lib_allocator]` implementations.

My work previously involved integrating Rust into an existing C/C++ codebase which was built with Buck and shipped on, among other platforms, Android. When targeting Android, Buck builds all "native" code with shared linkage* so it can be loaded from Java/Kotlin. My project was not itself `#![no_std]`, but many of our dependencies were, and they would fail to build with shared linkage due to a lack of a panic handler. With this change, that project can add the new `force` option to the `std` dependency it already explicitly provides to every crate to solve this problem.

*This is an oversimplification - Buck has a couple features for aggregating dependencies into larger shared libraries, but none that I think sustainably solve this problem.

~The AST injection happens after macro expansion around where we similarly inject a test harness and proc-macro harness. The resolver's list of actually-used extern flags is populated during macro expansion, and if any of our `--extern` arguments have the `force` option and weren't already used, we inject an `extern crate` statement for them. The injection logic was added in `rustc_builtin_macros` as that's where similar injections for tests, proc-macros, and std/core already live.~

(New contributor - grateful for feedback and guidance!)
2023-05-06 11:24:37 +00:00
Scott McMurray ec3a9bcdb7 Remove some assumes from slice iterators that don't do anything 2023-05-06 00:33:32 -07:00
bors 151a070afe Auto merge of #104872 - luqmana:packed-union-align, r=oli-obk
Avoid alignment mismatch between ABI and layout for unions.

Fixes #104802
Fixes #103634

r? `@eddyb` cc `@RalfJung`
2023-05-06 07:25:50 +00:00
Yuki Okushi bc4a1198fc
Rollup merge of #111239 - TaKO8Ki:fix-111232, r=compiler-errors
Remove unnecessary attribute from a diagnostic

Fixes #111232

ref: 06ff310cf9
2023-05-06 09:09:33 +09:00
Yuki Okushi 30220be929
Rollup merge of #110780 - notriddle:notriddle/slice-index, r=GuillaumeGomez
rustdoc-search: add slices and arrays to index

This indexes them as primitives with generics, so `slice<u32>` is how you search for `[u32]`, and `array<u32>` for `[u32; 1]`. A future commit will desugar the square bracket syntax to search both arrays and slices at once.
2023-05-06 09:09:31 +09:00
Yuki Okushi 923a5a2ca7
Rollup merge of #109677 - dpaoliello:rawdylib, r=michaelwoerister,wesleywiser
Stabilize raw-dylib, link_ordinal, import_name_type and -Cdlltool

This stabilizes the `raw-dylib` feature (#58713) for all architectures (i.e., `x86` as it is already stable for all other architectures).

Changes:
* Permit the use of the `raw-dylib` link kind for x86, the `link_ordinal` attribute and the `import_name_type` key for the `link` attribute.
* Mark the `raw_dylib` feature as stable.
* Stabilized the `-Zdlltool` argument as `-Cdlltool`.
* Note the path to `dlltool` if invoking it failed (we don't need to do this if `dlltool` returns an error since it prints its path in the error message).
* Adds tests for `-Cdlltool`.
* Adds tests for being unable to find the dlltool executable, and dlltool failing.
* Fixes a bug where we were checking the exit code of dlltool to see if it failed, but dlltool always returns 0 (indicating success), so instead we need to check if anything was written to `stderr`.

NOTE: As previously noted (https://github.com/rust-lang/rust/pull/104218#issuecomment-1315895618) using dlltool within rustc is temporary, but this is not the first time that Rust has added a temporary tool use and argument: https://github.com/rust-lang/rust/pull/104218#issuecomment-1318720482

Big thanks to ``````@tbu-`````` for the first version of this PR (#104218)
2023-05-06 09:09:30 +09:00
Luqman Aden f2d81defa1 Add additional test case for repr(packed) allowing union abi opt to kick in. 2023-05-05 16:05:04 -07:00
Luqman Aden d5ab3a06d2 Add test cases for #104802. 2023-05-05 16:05:03 -07:00
Oli Scherer 23d09aebc8 Do not use scalar layout if there are ZSTs with alignment > 1 2023-05-05 16:00:12 -07:00
Luqman Aden 7b1eedaae8 Switch test back to run-pass. 2023-05-05 14:58:52 -07:00
Luqman Aden 2942121736 Update test location. 2023-05-05 14:43:20 -07:00
Matthew Jasper f46eabb9e5 Report nicer lifetime errors for specialization
Add an obligation cause for these error so that the error points to the
implementations that caused the error.
2023-05-05 22:19:56 +01:00
Boxy 73b3ce26ec improve diagnostics and bless tests 2023-05-05 21:42:54 +01:00
Matt Hammerly 812f2d75e1 add "force" option to --extern 2023-05-05 13:02:43 -07:00
est31 83b4df4e61 Add feature gate 2023-05-05 21:44:48 +02:00
est31 5eb29c7f49 Migrate offset_of from a macro to builtin # syntax 2023-05-05 21:44:13 +02:00
est31 59ecbd2cea Add parsing for builtin # in expression and item context 2023-05-05 21:44:13 +02:00
Guillaume Gomez 8de4308b43 Add regression test for #111064 2023-05-05 21:33:44 +02:00
bors 81c2459af6 Stabilize const_ptr_read 2023-05-05 20:36:21 +02:00
Charisee 68a5bb4de1 Add GNU Property Note 2023-05-05 18:32:20 +00:00
Chris Denton 26b413eb2e
Further normalize msvc-non-utf8-ouput 2023-05-05 18:54:06 +01:00
bors 4b94c23219 Auto merge of #111248 - Dylan-DPC:rollup-lbp0ui3, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #103056 (Fix `checked_{add,sub}_duration` incorrectly returning `None` when `other` has more than `i64::MAX` seconds)
 - #108801 (Implement RFC 3348, `c"foo"` literals)
 - #110773 (Reduce MIR dump file count for MIR-opt tests)
 - #110876 (Added default target cpu to `--print target-cpus` output and updated docs)
 - #111068 (Improve check-cfg implementation)
 - #111238 (btree_map: `Cursor{,Mut}::peek_prev` must agree)

Failed merges:

 - #110694 (Implement builtin # syntax and use it for offset_of!(...))

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-05 15:59:20 +00:00
Matthew Jasper fafe9e71d5 Normalize consistently for specializations 2023-05-05 16:19:18 +01:00
Matthew Jasper bd928a0b5e Disallow (min) specialization imps with no items
Such implementations are usually mistakes and are not used in the
compiler or standard library (after this commit) so forbid them with
`min_specialization`.
2023-05-05 16:19:18 +01:00
Zachary Mayhew a183ac6f90
add hint for =< as <= 2023-05-05 11:17:14 -04:00
Santiago Pastorino 4b85bea4ae
Add Assert terminator to SMIR 2023-05-05 10:34:52 -03:00
Dylan DPC ded0a9e15f
Rollup merge of #111068 - Urgau:check-cfg-improvements, r=petrochenkov
Improve check-cfg implementation

This PR makes multiple improvements into the implementation of check-cfg, it is a prerequisite to a follow-up PR that will introduce a simpler and more explicit syntax.

The 2 main area of improvements are:
 1. Internal representation of expected values:
    - now uses `FxHashSet<Option<Symbol>>` instead of `FxHashSet<Symbol>`, it made the no value expected case only possible when no values where in the `HashSet` which is now represented as `None` (same as cfg represent-it).
    - a enum with `Some` and `Any` makes it now clear if some values are expected or not, necessary for `feature` and `target_feature`.
 2. Diagnostics: Improve the diagnostics in multiple case and fix case where a missing value could have had a new name suggestion instead of the value diagnostic; and some drive by improvements

I highly recommend reviewing commit by commit.

r? `@petrochenkov`
2023-05-05 18:40:35 +05:30
Dylan DPC de7e29e593
Rollup merge of #110773 - mj10021:issue-109502-fix, r=oli-obk
Reduce MIR dump file count for MIR-opt tests

As referenced in issue #109502 , mir-opt tests previously used the -Zdump-mir=all flag, which generates very large output.  This PR only dumps the passes under test, greatly reducing dump output.
2023-05-05 18:40:34 +05:30
Dylan DPC 4891f02cff
Rollup merge of #108801 - fee1-dead-contrib:c-str, r=compiler-errors
Implement RFC 3348, `c"foo"` literals

RFC: https://github.com/rust-lang/rfcs/pull/3348
Tracking issue: #105723
2023-05-05 18:40:33 +05:30
bors 4a18324a4d Auto merge of #111113 - scottmcm:assume-align-offset, r=thomcc
`assume` the runtime range of `align_offset`

Found when I saw code with `align_to` having extraneous checks.

Demo that LLVM can't do this today: <https://rust.godbolt.org/z/6dnG749bq>

(It's filed as https://github.com/llvm/llvm-project/issues/62502.)
2023-05-05 12:50:59 +00:00
Scott McMurray a1e5c65aa4 assume the runtime range of align_offset
Found when I saw code with `align_to` having extraneous checks.
2023-05-05 04:22:51 -07:00
Ezra Shaw 3e64e986fe
fix trait definition spans in "make mut" suggestion 2023-05-05 23:11:54 +12:00
Urgau 53647845b9 Improve check-cfg diagnostics (part 2) 2023-05-05 13:06:48 +02:00
Urgau a5f8dba4cd Improve check-cfg diagnostics (part 1) 2023-05-05 13:06:48 +02:00
Ezra Shaw 87a1b3840e
tweak spans for ref mut suggestion 2023-05-05 22:40:05 +12:00
Ezra Shaw 57c6a3183c
tweak "make mut" spans (No. 3) 2023-05-05 22:40:05 +12:00
Ezra Shaw 9624d2b08e
tweak "make mut" spans (No. 2) 2023-05-05 22:40:05 +12:00
Ezra Shaw fd8aa5ec7d
tweak "make mut" spans when assigning to locals 2023-05-05 22:40:04 +12:00
Takayuki Maeda 0a64dac604 remove unnecessary attribute from a diagnostic 2023-05-05 17:28:52 +09:00
BlackHoleFox a427d418fd Add deployment-target --print flag for Apple targets 2023-05-05 01:22:17 -05:00
Yuki Okushi b2ee088c73
Rollup merge of #111052 - nnethercote:fix-ice-test, r=Nilstrieb
Fix problems with backtraces in two ui tests.

`default-backtrace-ice.rs` started started failing for me recently,
because on my Ubuntu 23.04 system there are 100 stack frames, and the
current stack filtering pattern doesn't match on a stack frame with a
three digit number.

`issue-86800.rs` can also be improved, backtrace-wise.

r? `@Nilstrieb`
2023-05-05 12:46:26 +09:00
James Dietz c19959f4c3 add passes to miroptfiles struct and passed to -zdump-mir args
blessed new test
2023-05-04 18:56:32 -04:00
Camille GILLOT 1ffe9059c3 Reject borrows of projections in ConstProp. 2023-05-04 21:51:44 +00:00
Camille GILLOT e2caebc4a6 Add tests. 2023-05-04 21:50:46 +00:00
Nicholas Nethercote f20738dfb9 Improve filtering in default-backtrace-ice.rs.
This test is supposed to ensure that full backtraces are used for ICEs.
But it doesn't actually do that -- the filtering done cannot distinguish
between a full backtrace versus a short backtrace.

So this commit changes the filtering to preserve the existence of
`__rust_{begin,end}_short_backtrace` markers, which only appear in full
backtraces. This change means the test now tests what it is supposed to
test.

Also, the existing filtering included a rule that excluded any line
starting with two spaces. This was too strong because it filtered out
some parts of the error message. (This was not a showstopper). It was
also not strong enough because it didn't work with three digit stack
frame numbers, which just started seeing after upgrading my Ubuntu
distro to 23.04 machine (this *was* a showstopper).

So the commit replaces that rule with two more precise rules, one for
lines with stack frame numbers, and one for "at ..." lines.
2023-05-05 07:18:06 +10:00
Nicholas Nethercote 8702591e74 Don't print backtrace on ICEs in issue-86800.rs.
Because it then just has to be filtered out.

This change makes this test more like these other tests:
- tests/ui/treat-err-as-bug/err.rs
- tests/ui/treat-err-as-bug/delay_span_bug.rs
- tests/ui/mir/validate/storage-live.rs
- tests/ui/associated-inherent-types/bugs/ice-substitution.rs
- tests/ui/layout/valid_range_oob.rs
2023-05-05 07:04:06 +10:00
Michael Goulet 2e346b6f3f Even more tests 2023-05-04 18:06:07 +00:00
Michael Goulet 9d44f9b4e2 Add test for #110557 2023-05-04 18:06:07 +00:00
Michael Goulet 930eece9d3 Don't compute trait super bounds unless they're positive 2023-05-04 17:24:13 +00:00
Matthias Krüger c0ca84b006
Rollup merge of #111100 - BoxyUwU:array_repeat_expr_wf, r=compiler-errors
check array type of repeat exprs is wf

Fixes #111091

Also makes sure that we actually renumber regions in the length of repeat exprs which we previously weren't doing and would cause ICEs in `adt_const_params` + `generic_const_exprs` from attempting to prove the wf goals when the length was an unevaluated constant with `'erased` in the `ty` field of `Const`

The duplicate errors are caused by the fact that `const_arg_to_const`/`array_len_to_const` in `FnCtxt` adds a `WellFormed` goal for the created `Const` which is also checked by the added `WellFormed(array_ty)`. I don't want to change this to just emit a `T: Sized` goal for the element type since that would ignore `ConstArgHasType` wf requirements and generally uncomfortable with the idea of trying to sync up `wf::obligations` for arrays and the code in hir typeck for repeat exprs.

r? `@compiler-errors`
2023-05-04 19:18:21 +02:00
Matthias Krüger ea0b6504fa
Rollup merge of #111009 - scottmcm:ascii-char, r=BurntSushi
Add `ascii::Char` (ACP#179)

ACP second: https://github.com/rust-lang/libs-team/issues/179#issuecomment-1527900570
New tracking issue: https://github.com/rust-lang/rust/issues/110998

For now this is an `enum` as `@kupiakos` [suggested](https://github.com/rust-lang/libs-team/issues/179#issuecomment-1527959724), with the variants under a different feature flag.

There's lots more things that could be added here, and place for further doc updates, but this seems like a plausible starting point PR.

I've gone through and put an `as_ascii` next to every `is_ascii`: on `u8`, `char`, `[u8]`, and `str`.

As a demonstration, made a commit updating some formatting code to use this: https://github.com/scottmcm/rust/commit/ascii-char-in-fmt (I don't want to include that in this PR, though, because that brings in perf questions that don't exist if this is just adding new unstable APIs.)
2023-05-04 19:18:21 +02:00
Matthias Krüger 8d66f01ab5
Rollup merge of #110982 - cjgillot:elided-self-const, r=petrochenkov
Do not recurse into const generic args when resolving self lifetime elision.

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

r? `@petrochenkov`
2023-05-04 19:18:20 +02:00
Matthias Krüger 0ac8ebdf11
Rollup merge of #110826 - cjgillot:place-mention-use, r=JakobDegen,lcnr
Make PlaceMention a non-mutating use.

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

r? `@JakobDegen`

I don't agree with your statement in https://github.com/rust-lang/rust/issues/110781#issuecomment-1520841434. I suggest that we start fixing `PlaceContext` to be accurate enough for optimizations to use it. This structure is very convenient to use in visitors, and we perhaps have an opportunity to make it less of a footgun.
2023-05-04 19:18:19 +02:00
Matthias Krüger bf72b64b96
Rollup merge of #110651 - durin42:xunit-stdout, r=cuviper
libtest: include test output in junit xml reports

Fixes #110336.
2023-05-04 19:18:18 +02:00
León Orell Valerian Liehr 61e1eda6db
IAT: Rustdoc integration 2023-05-04 16:59:11 +02:00
León Orell Valerian Liehr 46ec348611
IAT: Add a few regression tests 2023-05-04 16:59:10 +02:00
León Orell Valerian Liehr e8139dfd5a
IAT: Introduce AliasKind::Inherent 2023-05-04 16:59:10 +02:00
Jakub Beránek 00ac29d7b2
Output LLVM optimization remark kind in -Cremark output 2023-05-04 15:39:21 +02:00
Boxy c04106f9f1 check array type of repeat exprs is wf 2023-05-04 11:22:40 +01:00
Matthias Krüger b4d992fec7
Rollup merge of #111103 - BoxyUwU:normal_fold_with_gce_norm, r=compiler-errors
correctly recurse when expanding anon consts

recursing with `super_fold_with` is wrong in case `bac` is itself normalizable, the test that was supposed to test for this being wrong did not actually test for this in reality because of the usage of `{ (N) }` instead of `{{ N }}`. The former resulting in a simple `ConstKind::Param` instead of `ConstKind::Unevaluated`. Tbh generally this test seems very brittle and it will be a lot easier to test once we have normalization of assoc consts since then we can just test that `T::ASSOC` normalizes to some `U::OTHER` which normalizes to some third thing.

r? `@compiler-errors`
2023-05-04 08:09:07 +02:00
Matthias Krüger f2bc7e0684
Rollup merge of #111094 - bjorn3:fix_test_annotations, r=jyn514
Add needs-unwind annotations to tests that need stack unwinding

This allows filtering them out when running the rustc test suite for cg_clif.
2023-05-04 08:09:06 +02:00
Matthias Krüger b194b43bd1
Rollup merge of #111039 - compiler-errors:foreign-span-rpitit, r=tmiasko
Encode def span for foreign return-position `impl Trait` in trait

Fixes #111031, yet another def-span encoding issue :/

Includes a smaller repro than the issue, but I can confirm it ICEs:

```
query stack during panic:
#0 [def_span] looking up span for `rpitit::Foo::bar::{opaque#0}`
#1 [object_safety_violations] determining object safety of trait `rpitit::Foo`
#2 [check_is_object_safe] checking if trait `rpitit::Foo` is object safe
#3 [typeck] type-checking `main`
#4 [used_trait_imports] finding used_trait_imports `main`
#5 [analysis] running analysis passes on this crate
```

Luckily since this only affects nightly, this desn't need to be backported.
2023-05-04 08:09:05 +02:00
Matthias Krüger 1187ce7213
Rollup merge of #111020 - cjgillot:validate-self-ctor, r=petrochenkov
Validate resolution for SelfCtor too.

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

r? `@petrochenkov`
2023-05-04 08:09:04 +02:00
Matthias Krüger 6fca1a9259
Rollup merge of #110859 - compiler-errors:no-negative-drop-impls, r=oli-obk
Explicitly reject negative and reservation drop impls

Fixes #110858

It doesn't really make sense for a type to have a `!Drop` impl. Or at least, I don't want us to implicitly assign a meaning to it by the way the compiler *currently* handles it (incompletely), and rather I would like to see a PR (or an RFC...) assign a meaning to `!Drop` if we actually wanted one for it.
2023-05-04 08:09:03 +02:00
Scott McMurray 8c781b0906 Add the basic ascii::Char type 2023-05-03 22:09:33 -07:00
Manish Goregaokar 48c78248a3
Rollup merge of #111146 - petrochenkov:decident, r=compiler-errors
rustc_middle: Fix `opt_item_ident` for non-local def ids

Noticed while working on https://github.com/rust-lang/rust/pull/110855.
2023-05-03 16:42:51 -07:00
Manish Goregaokar 09839bfdb1
Rollup merge of #110928 - loongarch-rs:tests, r=petrochenkov
tests: Add tests for LoongArch64
2023-05-03 16:42:49 -07:00
Manish Goregaokar ceef7e5ced
Rollup merge of #110371 - notriddle:notriddle/search-corrections, r=GuillaumeGomez
rustdoc: restructure type search engine to pick-and-use IDs

Fixes #110029

Preview: https://notriddle.com/rustdoc-demo-html-3/search-corrections/std/index.html?search=-%3E%20streaming

![image](https://user-images.githubusercontent.com/1593513/233494900-ae77d5b4-e395-41f8-bbac-53ee55bb4a76.png)

This change makes it so, instead of mixing string distance with type unification, function signature search works by mapping names to IDs at the start, reporting to the user any cases where it had to make corrections, and then matches with IDs when going through the items.

This only changes function searches. Name searches are left alone, and corrections are only done when there's a single item in the search query.
2023-05-03 16:42:49 -07:00
Manish Goregaokar 38bbc39895
Rollup merge of #105452 - rcvalle:rust-cfi-3, r=bjorn3
Add cross-language LLVM CFI support to the Rust compiler

This PR adds cross-language LLVM Control Flow Integrity (CFI) support to the Rust compiler by adding the `-Zsanitizer-cfi-normalize-integers` option to be used with Clang `-fsanitize-cfi-icall-normalize-integers` for normalizing integer types (see https://reviews.llvm.org/D139395).

It provides forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space). For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler, see design document in the tracking issue #89653.

Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and -Zsanitizer-cfi-normalize-integers, and requires proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto).

Thank you again, ``@bjorn3,`` ``@nikic,`` ``@samitolvanen,`` and the Rust community for all the help!
2023-05-03 16:42:48 -07:00
Manish Goregaokar 84d8159ebf
Rollup merge of #97594 - WaffleLapkin:array_tuple_conv, r=ChrisDenton
Implement tuple<->array convertions via `From`

This PR adds the following impls that convert between homogeneous tuples and arrays of the corresponding lengths:
```rust
impl<T> From<[T; 1]> for (T,) { ... }
impl<T> From<[T; 2]> for (T, T) { ... }
/* ... */
impl<T> From<[T; 12]> for (T, T, T, T, T, T, T, T, T, T, T, T) { ... }

impl<T> From<(T,)> for [T; 1] { ... }
impl<T> From<(T, T)> for [T; 2] { ... }
/* ... */
impl<T> From<(T, T, T, T, T, T, T, T, T, T, T, T)> for [T; 12] { ... }
```

IMO these are quite uncontroversial but note that they are, just like any other trait impls, insta-stable.
2023-05-03 16:42:47 -07:00
Josh Stone 10b69dde3f debuginfo: split method declaration and definition
When we're adding a method to a type DIE, we only want a DW_AT_declaration
there, because LLVM LTO can't unify type definitions when a child DIE is a
full subprogram definition. Now the subprogram definition gets added at the
CU level with a specification link back to the abstract declaration.
2023-05-03 15:52:31 -07:00
Ramon de C Valle 004aa15b47 Add cross-language LLVM CFI support to the Rust compiler
This commit adds cross-language LLVM Control Flow Integrity (CFI)
support to the Rust compiler by adding the
`-Zsanitizer-cfi-normalize-integers` option to be used with Clang
`-fsanitize-cfi-icall-normalize-integers` for normalizing integer types
(see https://reviews.llvm.org/D139395).

It provides forward-edge control flow protection for C or C++ and Rust
-compiled code "mixed binaries" (i.e., for when C or C++ and Rust
-compiled code share the same virtual address space). For more
information about LLVM CFI and cross-language LLVM CFI support for the
Rust compiler, see design document in the tracking issue #89653.

Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and
-Zsanitizer-cfi-normalize-integers, and requires proper (i.e.,
non-rustc) LTO (i.e., -Clinker-plugin-lto).
2023-05-03 22:41:29 +00:00
Santiago Pastorino 7dd59fceef
Add Drop terminator to SMIR 2023-05-03 18:38:15 -03:00
Michael Goulet 76802e31a1 Error message for ambiguous RTN from super bounds 2023-05-03 21:09:50 +00:00
Michael Goulet 20a83144b2 Support RTN on associated methods from supertraits 2023-05-03 19:41:15 +00:00
Dylan DPC 887dffc447
Rollup merge of #111086 - nnethercote:rm-MemEncoder, r=cjgillot
Remove `MemEncoder`

`MemEncoder` only has one non-test use, and `FileEncoder` would be more appropriate there anyway.

r? ``@cjgillot``
2023-05-04 00:17:26 +05:30
Dylan DPC fce0741fe9
Rollup merge of #111062 - clubby789:invalid-repr-unchecked, r=petrochenkov
Don't bail out early when checking invalid `repr` attr

Fixes #111051

An invalid repr delays a bug. If there are other invalid attributes on the item, we emit a warning and exit without re-checking the repr here, so no error is emitted and the delayed bug ICEs
2023-05-04 00:17:25 +05:30
Dylan DPC 8b7080b15b
Rollup merge of #110943 - RalfJung:interpret-unsized-arg-ice, r=oli-obk
interpret: fail more gracefully on uninit unsized locals

r? `@oli-obk`

Fixes https://github.com/rust-lang/rust/issues/68538
2023-05-04 00:17:25 +05:30
Dylan DPC a2e4dab3aa
Rollup merge of #110874 - compiler-errors:index-op-specific, r=oli-obk
Adjust obligation cause code for `find_and_report_unsatisfied_index_impl`

Makes the error message a bit easier to read.
2023-05-04 00:17:24 +05:30
Dylan DPC 80df4ab403
Rollup merge of #110791 - compiler-errors:negative-bounds, r=oli-obk
Implement negative bounds for internal testing purposes

Implements partial support the `!` negative polarity on trait bounds. This is incomplete, but should allow us to at least be able to play with the feature.

Not even gonna consider them as a public-facing feature, but I'm implementing them because would've been nice to have in UI tests, for example in #110671.
2023-05-04 00:17:23 +05:30
Camille GILLOT 8972a23f48 Do not recurse into const generic args when resolving self lifetime elision. 2023-05-03 18:07:53 +00:00
Camille GILLOT 83453408a0 Validate resolution for SelfCtor too. 2023-05-03 17:55:27 +00:00
Vadim Petrochenkov 6f6c379ee0 rustc_middle: Fix opt_item_ident for non-local def ids 2023-05-03 20:09:10 +03:00
Nicholas Nethercote 6b62f37402 Restrict From<S> for {D,Subd}iagnosticMessage.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.

This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.

As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.
2023-05-03 08:44:39 +10:00
Michael Goulet 03469c3f2e Make negative trait bounds work with the old trait solver 2023-05-02 22:36:25 +00:00
Michael Goulet 86f50b9f5c Disallow associated type constraints on negative bounds 2023-05-02 22:36:24 +00:00
Michael Goulet 6e01e910cb Implement negative bounds 2023-05-02 22:36:24 +00:00
Boxy 4d0887e1a2 correctly recurse when expanding anon consts 2023-05-02 18:42:55 +01:00
Camille GILLOT a4ef2f5fca Make ConstProp tests unit. 2023-05-02 16:46:56 +00:00
Maybe Waffle 36f86936b2 --bless tests 2023-05-02 14:48:39 +00:00
bjorn3 8a08514dbd Add needs-unwind annotations to tests that need stack unwinding 2023-05-02 12:07:55 +00:00
Deadbeef 6d905a8cc1 fix tidy 2023-05-02 10:32:08 +00:00
Deadbeef abb181dfd9 make it semantic error 2023-05-02 10:32:08 +00:00
Deadbeef bf3ca5979e try gating early, add non-ascii test 2023-05-02 10:32:08 +00:00
Deadbeef a49570fd20 fix TODO comments 2023-05-02 10:32:07 +00:00
Deadbeef 76d1f93896 update and add a few tests 2023-05-02 10:30:09 +00:00
bors 98c33e47a4 Auto merge of #109128 - chenyukang:yukang/remove-type-ascription, r=estebank
Remove type ascription from parser and diagnostics

Mostly based on https://github.com/rust-lang/rust/pull/106826

Part of #101728

r? `@estebank`
2023-05-02 09:41:35 +00:00
bors 7b99493492 Auto merge of #111089 - Dylan-DPC:rollup-b8oj6du, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #105076 (Refactor core::char::EscapeDefault and co. structures)
 - #108161 (Add `ConstParamTy` trait)
 - #108668 (Stabilize debugger_visualizer)
 - #110512 (Fix elaboration with associated type bounds)
 - #110895 (Remove `all` in target_thread_local cfg)
 - #110955 (uplift `clippy::clone_double_ref` as `suspicious_double_ref_op`)
 - #111048 (Mark`feature(return_position_impl_trait_in_trait)` and`feature(async_fn_in_trait)` as not incomplete)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-02 06:36:44 +00:00
Dylan DPC 2e3373c231
Rollup merge of #111048 - compiler-errors:rpitit-not-incomplete, r=jackh726
Mark`feature(return_position_impl_trait_in_trait)` and`feature(async_fn_in_trait)` as not incomplete

I think they've graduated, since as far as I'm aware, they don't cause compiler crashes or unsoundness anymore.
2023-05-02 11:44:53 +05:30
Dylan DPC 40c4ed4994
Rollup merge of #110955 - fee1-dead-contrib:sus-operation, r=compiler-errors
uplift `clippy::clone_double_ref` as `suspicious_double_ref_op`

Split from #109842.

r? ``@compiler-errors``
2023-05-02 11:44:52 +05:30
Dylan DPC be4f9f5bec
Rollup merge of #110512 - compiler-errors:fix-elaboration-with-associated-type-bounds, r=spastorino
Fix elaboration with associated type bounds

When computing a trait's supertrait predicates, do not add any associated type *trait* bounds to that list of supertrait predicates. This is because supertrait predicates are expected to have the same `Self` type as the trait.

For example, given:

```rust
trait Foo: Bar<Assoc: Send>
```

Before, we would compute that the supertrait predicates of `T: Foo` are `T: Bar` and `<T as Bar>::Assoc: Send`. However, the last bound is a trait predicate for a totally different type than `T`, and existing code that uses supertrait bounds such as vtable construction, closure fn signature deduction, etc. all rely on the invariant that we have a list of predicates for self type `T`.

Fixes #76593

The reason for all the extra diagnostic noise is that we're recomputing predicates with a different filter now. These diagnostics should be deduplicated for any end-user though.

---

This does bring up an interesting question -- is the predicate `<T as Bar>::Assoc: Send` an implied bound of `T: Foo`? Because currently the only bounds implied by a (non-alias) trait are its supertraits. I guess I could fix this too, but it would require even more changes, and I'm inclined to punt this question along.
2023-05-02 11:44:51 +05:30
Dylan DPC f379a58bf2
Rollup merge of #108668 - gibbyfree:stabilizedebuggervisualizer, r=wesleywiser
Stabilize debugger_visualizer

This stabilizes the `debugger_visualizer` attribute (#95939).

* Marks the `debugger_visualizer` feature as `accepted`.
* Marks the `debugger_visualizer` attribute as `ungated`.
* Deletes feature gate test, removes feature gate from other tests.

Closes #95939
2023-05-02 11:44:51 +05:30
Dylan DPC b727132e23
Rollup merge of #108161 - WaffleLapkin:const_param_ty, r=BoxyUwU
Add `ConstParamTy` trait

This is a bit sketch, but idk.
r? `@BoxyUwU`

Yet to be done:
- [x] ~~Figure out if it's okay to implement `StructuralEq` for primitives / possibly remove their special casing~~ (it should be okay, but maybe not in this PR...)
- [ ] Maybe refactor the code a little bit
- [x] Use a macro to make impls a bit nicer

Future work:
- [ ] Actually™ use the trait when checking if a `const` generic type is allowed
- [ ] _Really_ refactor the surrounding code
- [ ] Refactor `marker.rs` into multiple modules for each "theme" of markers
2023-05-02 11:44:50 +05:30
Michael Goulet 7411468ff8 Mark RPITIT and AFIT as no longer incomplete 2023-05-02 05:04:50 +00:00
bors 5133e15459 Auto merge of #109521 - tmiasko:const-prop-validation, r=wesleywiser
Don't validate constants in const propagation

Validation is neither necessary nor desirable.

The constant validation is already omitted at mir-opt-level >= 3, so there there are not changes in MIR test output (the propagation of invalid constants is covered by an existing test in tests/mir-opt/const_prop/invalid_constant.rs).
2023-05-02 03:42:37 +00:00
jyn 2469afef1a Make the BUG_REPORT_URL configurable by tools
This greatly simplifies how hard it is to set a custom bug report url; previously tools had to copy
the entire hook implementation.

- Switch clippy to the new hook

  This also adds a `extra_info` callback so clippy can include its own version number, which differs
  from rustc's.

- Call `install_ice_hook` in rustfmt
2023-05-01 21:44:04 -05:00
Nicholas Nethercote 8d359e4385 Move some Encodable/Decodable tests.
Round-trip encoding/decoding of many types is tested in
`compiler/rustc_serialize/tests/opaque.rs`. There is also a small amount
of encoding/decoding testing in three files in `tests/ui-fulldeps`.

There is no obvious reason why these three files are necessary. They
were originally added in 2014. Maybe it wasn't possible for a proc
macro to run in a unit test back then?

This commit just moves the testing from those three files into the unit
test.
2023-05-02 12:02:32 +10:00
bors 1cb63572d2 Auto merge of #106075 - nbdd0121:ffi-unwind, r=joshtriplett
Partial stabilisation of `c_unwind`

The stabilisation report is at https://github.com/rust-lang/rust/issues/74990#issuecomment-1363473645

cc `@rust-lang/wg-ffi-unwind`
2023-05-02 00:45:04 +00:00
Gibby Free c9653a6b0b fix stderrs 2023-05-01 13:37:15 -07:00
Gibby Free b00e5f37f3 remove bootstrap from tests 2023-05-01 13:37:15 -07:00