Commit Graph

169144 Commits

Author SHA1 Message Date
Guillaume Gomez
e0cbac6a39 Add "no-fallthrough" eslint rule 2022-06-03 11:09:23 +02:00
bors
395a09c3da Auto merge of #97553 - nbdd0121:lib, r=Mark-Simulacrum
Add `#[inline]` to `Vec`'s `Deref/DerefMut`

This should help #97552 (although I haven't verified).
2022-06-01 04:52:11 +00:00
bors
02916c4c75 Auto merge of #97435 - Patryk27:bump-compiler-builtins, r=Dylan-DPC
library/std: Bump compiler_builtins

Some neat changes include faster float conversions & fixes for AVR 🙂

(note that's it's my first time upgrading `compiler_builtins`, so I'm not 100% sure if bumping `library/std/Cargo.toml` is enough; certainly seems to be so, though.)
2022-06-01 01:49:04 +00:00
bors
6f481f8b71 Auto merge of #97600 - matthiaskrgr:rollup-yivyeu5, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #97316 (Put a bound on collection misbehavior)
 - #97578 (alloc: remove repeated word in comment)
 - #97593 (⬆️ rust-analyzer)
 - #97596 (Fixup feature name to be more consistent with others)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-31 23:24:39 +00:00
Matthias Krüger
31fccd1a44
Rollup merge of #97596 - WaffleLapkin:fixup_feature_name, r=compiler-errors
Fixup feature name to be more consistent with others

`slice_from_mut_ptr_range_const` -> `const_slice_from_mut_ptr_range`, we usually have `const` in the front.

I've made a typo in  #97419
2022-05-31 23:11:37 +02:00
Matthias Krüger
1998aefc0a
Rollup merge of #97593 - lnicola:rust-analyzer-2022-05-31, r=lnicola
⬆️ rust-analyzer

r? `@ghost`
2022-05-31 23:11:36 +02:00
Matthias Krüger
0d1e5465f3
Rollup merge of #97578 - ojeda:checkpatch, r=JohnTitor
alloc: remove repeated word in comment

Linux's `checkpatch.pl` reports:

```txt
#42544: FILE: rust/alloc/vec/mod.rs:2692:
WARNING: Possible repeated word: 'to'
+            // - Elements are :Copy so it's OK to to copy them, without doing
```

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-05-31 23:11:35 +02:00
Matthias Krüger
4f4a819fa9
Rollup merge of #97316 - CAD97:bound-misbehavior, r=dtolnay
Put a bound on collection misbehavior

As currently written, when a logic error occurs in a collection's trait parameters, this allows *completely arbitrary* misbehavior, so long as it does not cause undefined behavior in std. However, because the extent of misbehavior is not specified, it is allowed for *any* code in std to start misbehaving in arbitrary ways which are not formally UB; consider the theoretical example of a global which gets set on an observed logic error. Because the misbehavior is only bound by not resulting in UB from safe APIs and the crate-level encapsulation boundary of all of std, this makes writing user unsafe code that utilizes std theoretically impossible, as it now relies on undocumented QOI (quality of implementation) that unrelated parts of std cannot be caused to misbehave by a misuse of std::collections APIs.

In practice, this is a nonconcern, because std has reasonable QOI and an implementation that takes advantage of this freedom is essentially a malicious implementation and only compliant by the most langauage-lawyer reading of the documentation.

To close this hole, we just add a small clause to the existing logic error paragraph that ensures that any misbehavior is limited to the collection which observed the logic error, making it more plausible to prove the soundness of user unsafe code.

This is not meant to be formal; a formal refinement would likely need to mention that values derived from the collection can also misbehave after a logic error is observed, as well as define what it means to "observe" a logic error in the first place. This fix errs on the side of informality in order to close the hole without complicating a normal reading which can assume a reasonable nonmalicious QOI.

See also [discussion on IRLO][1].

[1]: https://internals.rust-lang.org/t/using-std-collections-and-unsafe-anything-can-happen/16640

r? rust-lang/libs-api ```@rustbot``` label +T-libs-api -T-libs

This technically adds a new guarantee to the documentation, though I argue as written it's one already implicitly provided.
2022-05-31 23:11:34 +02:00
bors
e094492200 Auto merge of #97582 - tmiasko:pointer-address-cast, r=oli-obk
Add a pointer to address cast kind

A pointer to address cast are often special-cased. Introduce a dedicated cast kind to make them easy distinguishable.
2022-05-31 21:06:11 +00:00
Maybe Waffle
2aef6c5436 Fixup feature name to be more consistent with others
`slice_from_mut_ptr_range_const` -> `const_slice_from_mut_ptr_range`,
we usually have `const` in the front.
2022-05-31 23:12:28 +04:00
Laurențiu Nicola
145a558785 ⬆️ rust-analyzer 2022-05-31 21:32:15 +03:00
bors
0595ea1d12 Auto merge of #97570 - JakobDegen:dse-test, r=tmiasko
Fix TLS access mir opt test and remove stale files

Thanks `@pietroalbini` for noticing that the TLS test was not doing what it was supposed to. Switched to `PreCodegen` because `SimplifyCfg` does not run on opt level 0.

Also addresses the easy part of #97564 .

r? rust-lang/mir-opt
2022-05-31 17:59:41 +00:00
bors
0a43923a86 Auto merge of #97419 - WaffleLapkin:const_from_ptr_range, r=oli-obk
Make `from{,_mut}_ptr_range` const

This PR makes the following APIs `const`:
```rust
// core::slice

pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T];
pub const unsafe fn from_mut_ptr_range<'a, T>(range: Range<*mut T>) -> &'a mut [T];
```

Tracking issue: #89792.
Feature for `from_ptr_range` as a `const fn`: `slice_from_ptr_range_const`.
Feature for `from_mut_ptr_range` as a `const fn`: `slice_from_mut_ptr_range_const`.

r? `@oli-obk`
2022-05-31 14:55:33 +00:00
bors
16a0d03698 Auto merge of #97521 - SkiFire13:clarify-vec-as-ptr, r=Dylan-DPC
Clarify the guarantees of Vec::as_ptr and Vec::as_mut_ptr when there's no allocation

Currently the documentation says they return a pointer to the vector's buffer, which has the implied precondition that the vector allocated some memory. However `Vec`'s documentation also specifies that it won't always allocate, so it's unclear whether the pointer returned is valid in that case. Of course you won't be able to read/write actual bytes to/from it since the capacity is 0, but there's an exception: zero sized read/writes. They are still valid as long as the pointer is not null and the memory it points to wasn't deallocated, but `Vec::as_ptr` and `Vec::as_mut_ptr` don't specify that's not the case. This PR thus specifies they are actually valid for zero sized reads since `Vec` is implemented to hold a dangling pointer in those cases, which is neither null nor was deallocated.
2022-05-31 12:14:51 +00:00
Miguel Ojeda
5dae6c1b96 alloc: remove repeated word in comment
Linux's `checkpatch.pl` reports:

```txt
#42544: FILE: rust/alloc/vec/mod.rs:2692:
WARNING: Possible repeated word: 'to'
+            // - Elements are :Copy so it's OK to to copy them, without doing
```

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-05-31 12:33:31 +02:00
bors
dcbd5f5134 Auto merge of #97526 - Nilstrieb:unicode-is-printable-fastpath, r=joshtriplett
Add unicode fast path to `is_printable`

Before, it would enter the full expensive check even for normal ascii characters. Now, it skips the check for the ascii characters in `32..127`. This range was checked manually from the current behavior.

I ran the `tracing` test suite in miri, and it was really slow. I looked at a profile, and miri spent most of the time in `core::char::methods::escape_debug_ext`, where half of that was dominated by `core::unicode::printable::is_printable`. So I optimized it here.

The tracing profile:
![The tracing profile](https://user-images.githubusercontent.com/48135649/170883650-23876e7b-3fd1-4e8b-9001-47672e06d914.svg)
2022-05-31 09:34:00 +00:00
Nilstrieb
3358a41acb Add unicode fast path to is_printable
Before, it would enter the full expensive check even for normal ascii
characters. Now, it skips the check for the ascii characters in
`32..127`. This range was checked manually from the current behavior.
2022-05-31 10:51:35 +02:00
bors
d35d972e69 Auto merge of #97574 - Dylan-DPC:rollup-jq850l6, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #97089 (Improve settings theme display)
 - #97229 (Document the current aliasing rules for `Box<T>`.)
 - #97371 (Suggest adding a semicolon to a closure without block)
 - #97455 (Stabilize `toowned_clone_into`)
 - #97565 (Add doc alias `memset` to `write_bytes`)
 - #97569 (Remove `memset` alias from `fill_with`.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-31 06:53:02 +00:00
Dylan DPC
efd2519e10
Rollup merge of #97569 - thomcc:fill_with_isnt_memset, r=Amanieu
Remove `memset` alias from `fill_with`.

In https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Unsafe.20and.20Safe.20versions.20of.20APIs.20both.20getting.20the.20same.20alias/near/284413029 `@Amanieu` pointed out that we had this, which is not really right.

In our guidelines we say that we will "not add an alias for a function that's only somewhat similar or related", which applies here. Memset doesn't take a closure, not even conceptually.
2022-05-31 07:57:37 +02:00
Dylan DPC
5885e6d453
Rollup merge of #97565 - lukas-code:patch-1, r=thomcc
Add doc alias `memset` to `write_bytes`

I were looking for `memset` in rust, but the docs only pointed me to `slice::fill`.

With only the old aliases, one might write code like this, which is incorrect if the memory is uninitialized.
``` Rust
core::slice::from_raw_parts(ptr, len).fill(0)
```
2022-05-31 07:57:36 +02:00
Dylan DPC
bf248c82e8
Rollup merge of #97455 - JohnTitor:stabilize-toowned-clone-into, r=dtolnay
Stabilize `toowned_clone_into`

Closes #41263
FCP has been done: https://github.com/rust-lang/rust/issues/41263#issuecomment-1100760750
2022-05-31 07:57:35 +02:00
Dylan DPC
38d8167d2e
Rollup merge of #97371 - ChayimFriedman2:closure-non-block-add-semicolon, r=oli-obk
Suggest adding a semicolon to a closure without block

This transforms `|| expr` into `|| { expr; }`.

Closes #97359.
2022-05-31 07:57:34 +02:00
Dylan DPC
9c72f16b9f
Rollup merge of #97229 - Nilstrieb:doc-box-noalias, r=dtolnay
Document the current aliasing rules for `Box<T>`.

Currently, `Box<T>` gets `noalias`, meaning it has the same rules as `&mut T`. This is sparsely documented, even though it can have quite a big impact on unsafe code using box. Therefore, these rules are documented here, with a big warning that they are not normative and subject to change, since we have not yet committed to an aliasing model and the state of `Box<T>` is especially uncertain.

If you have any suggestions and improvements, make sure to leave them here. This is mostly intended to inform people about what is currently going on (to prevent misunderstandings such as [Jon Gjengset's Box aliasing](https://www.youtube.com/watch?v=EY7Wi9fV5bk)).

This is supposed to _only document current UB_ and not add any new guarantees or rules.
2022-05-31 07:57:33 +02:00
Dylan DPC
94b8036147
Rollup merge of #97089 - GuillaumeGomez:improve-settings-theme-display, r=jsha
Improve settings theme display

This is a follow-up of #96958. In this PR, I changed how the theme radio buttons are displayed and improved their look as well.

It now looks like this:

![Screenshot from 2022-05-17 20-46-20](https://user-images.githubusercontent.com/3050060/168887703-a01e3bd5-9644-4012-ac11-2ae7bacd6be6.png)
![Screenshot from 2022-05-17 20-46-12](https://user-images.githubusercontent.com/3050060/168887707-132f8b2d-1163-462f-b7dd-f861121bdee7.png)

You can test it [here](https://rustdoc.crud.net/imperio/improve-settings-theme-display/doc/foo/index.html).

r? `@jsha`
2022-05-31 07:57:32 +02:00
bors
989b806f61 Auto merge of #96881 - est31:join_osstr, r=dtolnay
Implement [OsStr]::join

Implements join for `OsStr` and `OsString` slices:

```Rust
    let strings = [OsStr::new("hello"), OsStr::new("dear"), OsStr::new("world")];
    assert_eq!("hello dear world", strings.join(OsStr::new(" ")));
````

This saves one from converting to strings and back, or from implementing it manually.

This PR has been re-filed after #96744 was first accidentally merged and then reverted.

The change is instantly stable and thus:

r? rust-lang/libs-api `@rustbot` label +T-libs-api -T-libs

cc `@thomcc` `@m-ou-se` `@faptc`
2022-05-31 04:28:29 +00:00
bors
47365c0d65 Auto merge of #97566 - compiler-errors:rollup-qfxw4j8, r=compiler-errors
Rollup of 6 pull requests

Successful merges:

 - #89685 (refactor: VecDeques Iter fields to private)
 - #97172 (Optimize the diagnostic generation for `extern unsafe`)
 - #97395 (Miri call ABI check: ensure type size+align stay the same)
 - #97431 (don't do `Sized` and other return type checks on RPIT's real type)
 - #97555 (Source code page: line number click adds `NaN`)
 - #97558 (Fix typos in comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-31 01:17:00 +00:00
David Tolnay
e6b1003c95
BTreeSet->BTreeMap (fix copy/paste mistake in documentation)
Co-authored-by: lcnr <rust@lcnr.de>
2022-05-30 17:56:35 -07:00
Tomasz Miąsko
dff602fc18 Add a pointer to address cast kind
A pointer to address cast are often special-cased.
Introduce a dedicated cast kind to make them easy distinguishable.
2022-05-31 00:00:00 +00:00
David Tolnay
ffd7f5873e
Fix typo uniqeness -> uniqueness 2022-05-30 16:49:28 -07:00
Maybe Waffle
3a2bb78228 normalize harder 2022-05-31 03:46:04 +04:00
Jakob Degen
e60d8b631a Fix TLS access mir opt test and remove stale files 2022-05-30 16:29:36 -07:00
Thom Chiovoloni
de3ac3c3f8
Remove memset alias from fill_with. 2022-05-30 16:26:00 -07:00
Michael Goulet
b3dc31ca9c
Rollup merge of #97558 - stoeckmann:typos, r=compiler-errors
Fix typos in comment

Just two typos in HashingControls' description.
2022-05-30 15:57:31 -07:00
Michael Goulet
4c77fd30fe
Rollup merge of #97555 - GuillaumeGomez:line-number-click, r=notriddle
Source code page: line number click adds `NaN`

When you click on the parent element of the line numbers in the source code pages, it'll add `NaN` (like in https://doc.rust-lang.org/nightly/src/alloc/lib.rs.html#NaN). This PR fixes this bug.

cc ``@jsha``
r? ``@notriddle``
2022-05-30 15:57:30 -07:00
Michael Goulet
6718723c96
Rollup merge of #97431 - compiler-errors:issue-97413, r=oli-obk
don't do `Sized` and other return type checks on RPIT's real type

Fixes an ICE where we're doing `Sized` check against the RPIT's real type, instead of against the opaque type. This differs from what we're doing in MIR typeck, which causes ICE #97226.

This regressed in #96516 -- this adjusts that fix to be a bit more conservative. That PR was backported and thus the ICE is also present in stable. Not sure if it's worth to beta and/or stable backport, probably not the latter but I could believe the former.

r? `@oli-obk`

cc: another attempt to fix this ICE #97413. I believe this PR addresses the root cause.
2022-05-30 15:57:29 -07:00
Michael Goulet
12ba87b996
Rollup merge of #97395 - RalfJung:call-abi, r=oli-obk
Miri call ABI check: ensure type size+align stay the same

We should almost certainly not accept calls where caller and callee disagree on the size or alignment of the type.

The checks we do *almost* imply that, except that `ScalarPair` types can have `repr(align)` and thus differ in size/align even when they are pairs of the same primitive type.

r? ``@oli-obk``
2022-05-30 15:57:28 -07:00
Michael Goulet
22da719762
Rollup merge of #97172 - SparrowLii:unsafe_extern, r=compiler-errors
Optimize the diagnostic generation for `extern unsafe`

This PR does the following about diagnostic generation when parsing foreign mod:
1. Fixes the FIXME about avoiding depending on the error message text.
2. Continue parsing when `unsafe` is followed by `{` (just like `unsafe extern {...}`).
3. Add test case.
2022-05-30 15:57:27 -07:00
Michael Goulet
3c0b9d50ae
Rollup merge of #89685 - DeveloperC286:iter_fields_to_private, r=oli-obk
refactor: VecDeques Iter fields to private

Made the fields of VecDeque's Iter private by creating a Iter::new(...) function to create a new instance of Iter and migrating usage to use Iter::new(...).
2022-05-30 15:57:27 -07:00
bors
7be9ec2765 Auto merge of #97357 - davidtwco:diagnostic-translation-typed-subdiagnostic-simplification, r=oli-obk
errors: simplify referring to fluent attributes

To render the message of a Fluent attribute, the identifier of the Fluent message must be known. `DiagnosticMessage::FluentIdentifier` contains both the message's identifier and optionally the identifier of an attribute. Generated constants for each attribute would therefore need to be named uniquely (amongst all error messages) or be able to refer to only the attribute identifier which will be combined with a message identifier later. In this commit, the latter strategy is implemented as part of the `Diagnostic` type's functions for adding subdiagnostics of various kinds.

r? `@oli-obk`
2022-05-30 22:49:36 +00:00
Lukas
e565bb0326 Update mut_ptr.rs 2022-05-31 00:41:39 +02:00
Lukas
7a9c13985e
Update intrinsics.rs 2022-05-30 22:38:29 +00:00
Chayim Refael Friedman
6afaffb9c2 Check for can_have_side_effects() and in_external_macro() inside suggest_missing_semicolon() 2022-05-30 20:35:51 +00:00
bors
c35035cefc Auto merge of #97025 - ouz-a:mini-derefer-generator, r=davidtwco
Add validation layer for Derefer

_Follow up work to #96549 #96116 #95857 #95649_

This adds validation for Derefer making sure it is always the first projection.

r? rust-lang/mir-opt
2022-05-30 20:06:25 +00:00
Tobias Stoeckmann
56662bcdff Fix typos in comment 2022-05-30 21:21:32 +02:00
bors
4a8d2e3856 Auto merge of #97480 - conradludgate:faster-format-literals, r=joshtriplett
improve format impl for literals

The basic idea of this change can be seen here https://godbolt.org/z/MT37cWoe1.

Updates the format impl to have a fast path for string literals and the default path for regular format args.

This change will allow `format!("string literal")` to be used interchangably with `"string literal".to_owned()`.

This would be relevant in the case of `f!"string literal"` being legal (https://github.com/rust-lang/rfcs/pull/3267) in which case it would be the easiest way to create owned strings from literals, while also being just as efficient as any other impl
2022-05-30 17:39:58 +00:00
ouz-a
e71913e847 validate derefer, run derefer inside generator 2022-05-30 18:36:14 +03:00
Guillaume Gomez
d286df1402 Add line number click GUI test 2022-05-30 17:15:41 +02:00
Guillaume Gomez
16d5cdc570 Improve source-code-page.goml GUI test code 2022-05-30 17:07:21 +02:00
bors
e810f750a2 Auto merge of #97548 - Dylan-DPC:rollup-9x0va1d, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #97494 (Use Box::new() instead of box syntax in library tests)
 - #97499 (Remove "sys isn't exported yet" phrase)
 - #97504 (Ensure source file present when calculating max line number)
 - #97519 (Re-add help_on_error for download-ci-llvm)
 - #97531 (Note pattern mismatch coming from `for` loop desugaring)
 - #97545 (Reword safety comments in core/hash/sip.rs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-30 14:59:12 +00:00
Guillaume Gomez
f3eae89b33 Fix invalid line number computation when clicking on something else than a line number 2022-05-30 16:53:24 +02:00