Commit Graph

1056 Commits

Author SHA1 Message Date
Matthias Krüger
0dc12b9dec
Rollup merge of #108584 - GuillaumeGomez:rustdoc-search-background, r=notriddle
Put backtick content from rustdoc search errors into a <code> elements

Some screenshots of the result:

![Screenshot from 2023-02-28 22-37-09](https://user-images.githubusercontent.com/3050060/221990290-fa84f1cf-5a64-4ce5-8433-ee36cedf4c00.png)
![Screenshot from 2023-02-28 22-36-59](https://user-images.githubusercontent.com/3050060/221990298-f8177eeb-894b-4fce-a6fc-06d17c8b7ca2.png)
![Screenshot from 2023-02-28 22-36-51](https://user-images.githubusercontent.com/3050060/221990301-41bffd64-d041-41f1-995a-983925b1fbb1.png)

You can test it [here](https://rustdoc.crud.net/imperio/rustdoc-search-background/foo/index.html?search=%22).

r? ```@notriddle```
2023-03-02 23:05:29 +01:00
Matthias Krüger
13640e337a
Rollup merge of #108573 - kornelski:runtimeenvs, r=WaffleLapkin
Explain compile-time vs run-time difference in env!() error message

This PR is clarifying error message of `env!()` based on this user question: https://users.rust-lang.org/t/environment-variable-out-dir-is-undefined/90067

It makes it clear that `env!()` is for env variables defined at compile-time. There's special-case help text for common Cargo build script variables.

I've also rearranged the code to avoid allocating error message on the happy path when the env var is defined.
2023-03-02 23:05:29 +01:00
Matthias Krüger
564715a5b7
Rollup merge of #108557 - Nathan-Fenner:nathanf/adjust-error-span-fix-Some, r=WaffleLapkin
Point error span at Some constructor argument when trait resolution fails

This is a follow up to #108254 and #106477 which extends error span refinement to handle a case which I mistakenly believed was handled in #106477. The goal is to refine the error span depicted below:

```rs
trait Fancy {}
impl <T> Fancy for Option<T> where T: Iterator {}

fn want_fancy<F>(f: F) where F: Fancy {}

fn example() {
    want_fancy(Some(5));
//  (BEFORE)   ^^^^^^^ `{integer}` is not an iterator
//  (AFTER)         ^  `{integer}` is not an iterator
}
```

I had used a (slightly more complex) example as an illustrative example in #108254 , but hadn't actually turned it into a test, because I had (incorrectly) believed at the time it was covered by existing behavior. It turns out that `Some` is slightly "special" in that it resolves differently from the other `enum` constructors I had tried, and therefore this test was actually broken.

I've now updated the tests to include this example, and fixed the code to correctly resolve the `Some` constructor so that the span of the error is reduced.
2023-03-02 23:05:28 +01:00
bors
13471d3b20 Auto merge of #108654 - LeSeulArtichaut:revert-99767, r=compiler-errors
Revert stabilization of `#![feature(target_feature_11)]`

This reverts #99767 due to the presence of bugs #108645 and #108646.

cc `@joshtriplett`
cc tracking issue #69098
r? `@ghost`
2023-03-02 17:38:31 +00:00
bors
7e966bcd03 Auto merge of #108640 - matthiaskrgr:rollup-rii4t5t, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #108516 (Restrict `#[rustc_box]` to `Box::new` calls)
 - #108575 (Erase **all** regions when probing for associated types on ambiguity in astconv)
 - #108585 (Run compiler test suite in parallel on Fuchsia)
 - #108606 (Add test case for mismatched open/close delims)
 - #108609 (Highlight whole expression for E0599)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-02 14:04:22 +00:00
Léo Lanteri Thauvin
bfe5189904 Revert "Stabilize #![feature(target_feature_11)]"
This reverts commit b379d216ee.
2023-03-02 13:41:17 +01:00
Guillaume Gomez
cfb4af87e3 Add GUI test for rustdoc search errors background 2023-03-02 12:59:04 +01:00
Matthias Krüger
832987bb1e
Rollup merge of #108609 - clubby789:e0599-highlight, r=estebank
Highlight whole expression for E0599

Fixes #108603

This adds a secondary label to highlight the whole expression leading to the error. It also prevents empty labels being recognised as 'unexpected' by compiletest - otherwise, tests with NOTE annotations would pick up empty labels.

`@rustbot` label +A-diagnostics
2023-03-02 07:24:02 +01:00
Matthias Krüger
c09a9a69e2
Rollup merge of #108606 - chenyukang:yukang/fix-104367, r=compiler-errors
Add test case for mismatched open/close delims

Fixes #104367
Fixes #105209

After landing https://github.com/rust-lang/rust/pull/108297, these issues are resolved.
2023-03-02 07:24:02 +01:00
Matthias Krüger
91dafebc91
Rollup merge of #108575 - compiler-errors:erase, r=estebank
Erase **all** regions when probing for associated types on ambiguity in astconv

Fixes #108562
2023-03-02 07:24:01 +01:00
Matthias Krüger
c9c9283c6a
Rollup merge of #108516 - clubby789:rustc-box-restrict, r=compiler-errors
Restrict `#[rustc_box]` to `Box::new` calls

Currently, `#[rustc_box]` can be applied to any call expression with a single argument. This PR only allows it to be applied to calls to `Box::new`
2023-03-02 07:24:00 +01:00
bors
18caf88956 Auto merge of #107879 - icedrocket:update-llvm, r=cuviper
Update LLVM submodule

Fixes #105626
2023-03-02 05:27:32 +00:00
clubby789
d845769557 Restrict #[rustc_box] to Box::new calls 2023-03-02 02:42:19 +00:00
bors
864b6258fc Auto merge of #106673 - flba-eb:add_qnx_nto_stdlib, r=workingjubilee
Add support for QNX Neutrino to standard library

This change:

- adds standard library support for QNX Neutrino (7.1).
- upgrades `libc` to version `0.2.139` which supports QNX Neutrino

`@gh-tr`

⚠️ Backtraces on QNX require https://github.com/rust-lang/backtrace-rs/pull/507 which is not yet merged! (But everything else works without these changes) ⚠️

Tested mainly with a x86_64 virtual machine (see qnx-nto.md) and partially with an aarch64 hardware (some tests fail due to constrained resources).
2023-03-02 02:41:42 +00:00
bors
0b4ba4cf0e Auto merge of #108483 - scottmcm:unify-bytewise-eq-traits, r=the8472
Merge two different equality specialization traits in `core`

Arrays and slices each had their own version of this, without a matching set of `impl`s.

Merge them into one (still-`pub(crate)`) `cmp::BytewiseEq` trait, so we can stop doing all these things twice.

And that means that the `[T]::eq` → `memcmp` specialization picks up a bunch of types where that previously only worked for arrays, so examples like <https://rust.godbolt.org/z/KjsG8MGGT> will use it now instead of emitting loops.

r? the8472
2023-03-01 23:34:37 +00:00
Scott McMurray
44eec1d9b0 Merge two different equality specialization traits in core 2023-03-01 14:42:06 -08:00
bors
f77bfb7336 Auto merge of #108620 - Dylan-DPC:rollup-o5c4evy, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #108143 (rustdoc: search by macro when query ends with `!`)
 - #108394 (Make `x doc --open` work on every book)
 - #108427 (Recover from for-else and while-else)
 - #108462 (Fix `VecDeque::append` capacity overflow for ZSTs)
 - #108568 (Make associated_item_def_ids for traits use an unstable option to also return associated types for RPITITs)
 - #108604 (Add regression test for #107280)
 - #108605 (Add regression test for #105821)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-01 18:51:29 +00:00
Dylan DPC
02e4eefd88
Rollup merge of #108605 - JohnTitor:issue-105821, r=compiler-errors
Add regression test for #105821

Closes #105821
r? compiler-errors
2023-03-01 23:40:22 +05:30
Dylan DPC
0ed76b473f
Rollup merge of #108604 - JohnTitor:issue-107280, r=compiler-errors
Add regression test for #107280

Closes #107280
r? compiler-errors
2023-03-01 23:40:21 +05:30
Dylan DPC
9d132f77ae
Rollup merge of #108568 - spastorino:new-rpitit-flag, r=compiler-errors
Make associated_item_def_ids for traits use an unstable option to also return associated types for RPITITs

r? `@compiler-errors`
2023-03-01 23:40:21 +05:30
Dylan DPC
27fa7b5e6d
Rollup merge of #108427 - y21:for-else-diagnostic, r=compiler-errors
Recover from for-else and while-else

This recovers from attempts at writing for-else or while-else loops, which might help users coming from e.g. Python.
```rs
for _ in 0..0 {
  // ...
} else {
  // ...
}
```
Combined with trying to store it in a let binding, the current diagnostic can be a bit confusing. It mentions let-else and suggests wrapping the loop in parentheses, which the user probably doesn't want. let-else doesn't make sense for `for` and `while` loops, as they are of type `()` (which already is an irrefutable pattern and doesn't need let-else).
<details>
<summary>Current diagnostic</summary>

```rs
error: right curly brace `}` before `else` in a `let...else` statement not allowed
 --> src/main.rs:4:5
  |
4 |     } else {
  |     ^
  |
help: wrap the expression in parentheses
  |
2 ~     let _x = (for _ in 0..0 {
3 |
4 ~     }) else {
  |
```
</details>

Some questions:
- Can the wording for the error message be improved? Would "for...else loops are not allowed" fit better?
- Should we be more "conservative" in case we want to support this in the future (i.e. say "for...else loops are **currently** not allowed/supported")?
- Is there a better way than storing a `&'static str` for the loop type? It is used for substituting the placeholder in the locale file (since it can emit either `for...else` or `while...else`). Maybe there is an enum I could use that I couldn't find
2023-03-01 23:40:19 +05:30
Dylan DPC
f03e5345aa
Rollup merge of #108143 - notriddle:notriddle/filter-exclamation-macro, r=GuillaumeGomez
rustdoc: search by macro when query ends with `!`

Related to #96399

Note: the `never` type alias is tested in [`/tests/rustdoc-js-std/alias-3.js`](08ad401633/tests/rustdoc-js-std/alias-3.js)

## Before

![image](https://user-images.githubusercontent.com/1593513/219504192-54cc0753-ff97-4a37-ad4a-8ae915181325.png)

## After

![image](https://user-images.githubusercontent.com/1593513/219504251-589a7e11-1e7b-4b7b-879d-1b564080017c.png)
2023-03-01 23:40:18 +05:30
clubby789
6c2a952b56 Highlight whole expression for E0599 2023-03-01 16:57:11 +00:00
Santiago Pastorino
e74f50ecc2
Add unstable option new_rpitit to be used for new RPITIT lowering system 2023-03-01 12:56:39 -03:00
bors
609496eecf Auto merge of #108446 - Zoxc:named-allocs, r=oli-obk
Name LLVM anonymous constants by a hash of their contents

This makes the names stable between different versions of a crate unlike the `AllocId` naming, making LLVM IR comparisons with `llvm-diff` more practical.
2023-03-01 15:36:15 +00:00
yukang
a641229916 Add testcase for issue 105209 2023-03-01 13:28:12 +00:00
yukang
94a200b6a9 Fix #104367, add test case for mismatched open/close delims 2023-03-01 13:14:30 +00:00
Yuki Okushi
50d35c1740
Add regression test for #105821
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-03-01 22:01:12 +09:00
Yuki Okushi
964234654d
Add regression test for #107280
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-03-01 21:58:27 +09:00
bors
5423745db8 Auto merge of #105871 - llogiq:option-as-slice, r=scottmcm
Add `Option::as_`(`mut_`)`slice`

This adds the following functions:

* `Option<T>::as_slice(&self) -> &[T]`
* `Option<T>::as_mut_slice(&mut self) -> &[T]`

The `as_slice` and `as_mut_slice_mut` functions benefit from an optimization that makes them completely branch-free. ~~Unfortunately, this optimization is not available on by-value Options, therefore the `into_slice` implementations use the plain `match` + `slice::from_ref` approach.~~

Note that the optimization's soundness hinges on the fact that either the niche optimization makes the offset of the `Some(_)` contents zero or the mempory layout of `Option<T>` is equal to that of `Option<MaybeUninit<T>>`.

The idea has been discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Option.3A.3Aas_slice). Notably the idea for the `as_slice_mut` and `into_slice´ methods came from `@cuviper` and `@Sp00ph` hardened the optimization against niche-optimized Options.

The [rust playground](https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=74f8e4239a19f454c183aaf7b4a969e0) shows that the generated assembly of the optimized method is basically only a copy while the naive method generates code containing a `test dx, dx` on x86_64.

---

EDIT from reviewer: ACP is https://github.com/rust-lang/libs-team/issues/150
2023-03-01 12:32:57 +00:00
y21
0758c05c97 recover from for-else and while-else 2023-03-01 13:26:59 +01:00
bors
bcb610da7f Auto merge of #108587 - matthiaskrgr:rollup-rw6po59, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #108376 (compiler/rustc_session: fix sysroot detection logic)
 - #108400 (add llvm cgu instructions stats to perf)
 - #108496 (fix #108495, postfix decrement and prefix decrement has no warning)
 - #108505 (Further unify validity intrinsics)
 - #108520 (Small cleanup to `one_bound_for_assoc_type`)
 - #108560 (Some `infer/mod.rs` cleanups)
 - #108563 (Make mailmap more correct)
 - #108564 (Fix `x clean` with specific paths)
 - #108571 (Add contains_key to SortedIndexMultiMap)
 - #108578 (Update Fuchsia platform team members)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-01 06:23:19 +00:00
Matthias Krüger
1c3cc8bba5
Rollup merge of #108496 - nx2k3:issue-108495-dec, r=WaffleLapkin
fix #108495, postfix decrement and prefix decrement has no warning

Fixes #108495
2023-03-01 01:21:56 +01:00
Matthias Krüger
19604c2362
Rollup merge of #108554 - compiler-errors:late-bound-object-default, r=oli-obk
Only look for param in item's generics if it actually comes from generics

Record whether a `hir::GenericParam` comes from an item's generics, or from a `for<...>` binder. Then, only look for the param in `object_lifetime_default` if it actually comes from the item's generics.

Fixes #108177
2023-03-01 01:20:25 +01:00
Matthias Krüger
b2dc8c505c
Rollup merge of #108551 - compiler-errors:rpitit-bad-spec, r=oli-obk
Descriptive error when users try to combine RPITIT/AFIT with specialization

Previously we failed with some esoteric error like:

```
error[E0053]: method `foo` has an incompatible type for trait
  --> $DIR/dont-project-to-specializable-projection.rs:14:35
   |
LL |     default async fn foo(_: T) -> &'static str {
   |                                   ^^^^^^^^^^^^ expected associated type, found future
   |
note: type in trait
  --> $DIR/dont-project-to-specializable-projection.rs:10:27
   |
LL |     async fn foo(_: T) -> &'static str;
   |                           ^^^^^^^^^^^^
   = note: expected signature `fn(_) -> impl Future<Output = &'static str>`
              found signature `fn(_) -> impl Future<Output = &'static str>`
```

Now we error like:

```
error: async associated function in trait cannot be specialized
  --> $DIR/dont-project-to-specializable-projection.rs:14:5
   |
LL |     default async fn foo(_: T) -> &'static str {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: specialization behaves in inconsistent and surprising ways with `#![feature(async_fn_in_trait)]`, and for now is disallowed
```
2023-03-01 01:20:24 +01:00
Matthias Krüger
78f9bb11fe
Rollup merge of #108550 - clubby789:remove-disjoint, r=compiler-errors
Remove the `capture_disjoint_fields` feature

As best I can tell, this was stabilized for Edition 2021 in #88126 but the feature was never removed.
2023-03-01 01:20:24 +01:00
Matthias Krüger
371904bba6
Rollup merge of #108297 - chenyukang:yukang/delim-error-exit, r=petrochenkov
Exit when there are unmatched delims to avoid noisy diagnostics

From https://github.com/rust-lang/rust/pull/104012#issuecomment-1311764832
r? ``@petrochenkov``
2023-03-01 01:20:22 +01:00
Andre Bogus
41da875fae Add Option::as_slice(_mut)
This adds the following functions:

* `Option<T>::as_slice(&self) -> &[T]`
* `Option<T>::as_slice_mut(&mut self) -> &[T]`

The `as_slice` and `as_slice_mut` functions benefit from an
optimization that makes them completely branch-free.

Note that the optimization's soundness hinges on the fact that either
the niche optimization makes the offset of the `Some(_)` contents zero
or the mempory layout of `Option<T>` is equal to that of
`Option<MaybeUninit<T>>`.
2023-03-01 00:05:31 +01:00
Nathan Fenner
f0212e6532 Fix error spans for arguments to tuple enum constructors 2023-02-28 14:58:14 -08:00
Michael Goulet
cb9852b8e6 Erase **all** regions when probing for associated types in astconv 2023-02-28 17:29:46 +00:00
Kornel
2407b0c578 Explain compile-time vs run-time difference in env!() error message 2023-02-28 16:44:59 +00:00
Maybe Waffle
031206bc1d micro fmt changes 2023-02-28 19:28:14 +04:00
Florian Bartels
3ce2cd059f
Add QNX Neutrino support to libstd
Co-authored-by: gh-tr <troach@qnx.com>
2023-02-28 15:59:47 +01:00
Nathan Fenner
2566b4105d Point error span at Some constructor argument when trait resolution fails 2023-02-27 23:58:35 -08:00
yukang
65ad5f8de7 remove duplicated diagnostic for unclosed delimiter 2023-02-28 07:57:17 +00:00
yukang
f01d0c02e7 Exit when there are unmatched delims to avoid noisy diagnostics 2023-02-28 07:55:19 +00:00
Michael Goulet
f851a8aefa Only look for param in generics if it actually comes from generics 2023-02-28 06:27:56 +00:00
Michael Goulet
ecac8fd5af Descriptive error when users try to combine RPITIT/AFIT with specialization 2023-02-28 02:03:43 +00:00
clubby789
f83ce99c32 Remove the capture_disjoint_fields feature 2023-02-28 01:21:15 +00:00
bors
b583ede652 Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebank
Stabilize `#![feature(target_feature_11)]`

## Stabilization report

### Summary

Allows for safe functions to be marked with `#[target_feature]` attributes.

Functions marked with `#[target_feature]` are generally considered as unsafe functions: they are unsafe to call, cannot be assigned to safe function pointers, and don't implement the `Fn*` traits.

However, calling them from other `#[target_feature]` functions with a superset of features is safe.

```rust
// Demonstration function
#[target_feature(enable = "avx2")]
fn avx2() {}

fn foo() {
    // Calling `avx2` here is unsafe, as we must ensure
    // that AVX is available first.
    unsafe {
        avx2();
    }
}

#[target_feature(enable = "avx2")]
fn bar() {
    // Calling `avx2` here is safe.
    avx2();
}
```

### Test cases

Tests for this feature can be found in [`src/test/ui/rfcs/rfc-2396-target_feature-11/`](b67ba9ba20/src/test/ui/rfcs/rfc-2396-target_feature-11/).

### Edge cases

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

Closures defined inside functions marked with `#[target_feature]` inherit the target features of their parent function. They can still be assigned to safe function pointers and implement the appropriate `Fn*` traits.

```rust
#[target_feature(enable = "avx2")]
fn qux() {
    let my_closure = || avx2(); // this call to `avx2` is safe
    let f: fn() = my_closure;
}
```

This means that in order to call a function with `#[target_feature]`, you must show that the target-feature is available while the function executes *and* for as long as whatever may escape from that function lives.

### Documentation

- Reference: https://github.com/rust-lang/reference/pull/1181

---
cc tracking issue #69098
r? `@ghost`
2023-02-28 01:14:56 +00:00