Commit Graph

164736 Commits

Author SHA1 Message Date
Dylan DPC
30b4182fa7
Rollup merge of #94984 - ericseppanen:cstr_from_bytes, r=Mark-Simulacrum
add `CStr` method that accepts any slice containing a nul-terminated string

I haven't created an issue (tracking or otherwise) for this yet; apologies if my approach isn't correct. This is my first code contribution.

This change adds a member fn that converts a slice into a `CStr`; it is intended to be safer than `from_ptr` (which is unsafe and may read out of bounds), and more useful than `from_bytes_with_nul` (which requires that the caller already know where the nul byte is).

The reason I find this useful is for situations like this:
```rust
let mut buffer = [0u8; 32];
unsafe {
    some_c_function(buffer.as_mut_ptr(), buffer.len());
}
let result = CStr::from_bytes_with_nul(&buffer).unwrap();
```

This code above returns an error with `kind = InteriorNul`, because `from_bytes_with_nul` expects that the caller has passed in a slice with the NUL byte at the end of the slice. But if I just got back a nul-terminated string from some FFI function, I probably don't know where the NUL byte is.

I would wish for a `CStr` constructor with the following properties:
- Accept `&[u8]` as input
- Scan for the first NUL byte and return the `CStr` that spans the correct sub-slice (see [future note below](https://github.com/rust-lang/rust/pull/94984#issuecomment-1070754281)).
- Return an error if no NUL byte is found within the input slice

I asked on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/CStr.20from.20.26.5Bu8.5D.20without.20knowing.20the.20NUL.20location.3F) whether this sounded like a good idea, and got a couple of positive-sounding responses from ``@joshtriplett`` and ``@AzureMarker.``

This is my first draft, so feedback is welcome.

A few issues that definitely need feedback:

1. Naming. ``@joshtriplett`` called this `from_bytes_with_internal_nul` on Zulip, but after staring at all of the available methods, I believe that this function is probably what end users want (rather than the existing fn `from_bytes_with_nul`). Giving it a simpler name (**`from_bytes`**) implies that this should be their first choice.
2. Should I add a similar method on `CString` that accepts `Vec<u8>`? I'd assume the answer is probably yes, but I figured I'd try to get early feedback before making this change bigger.
3. What should the error type look like? I made a unit struct since `CStr::from_bytes` can only fail in one obvious way, but if I need to do this for `CString` as well then that one may want to return `FromVecWithNulError`. And maybe that should dictate the shape of the `CStr` error type also?

Also, cc ``@poliorcetics`` who wrote #73139 containing similar fns.
2022-03-19 02:02:02 +01:00
Dylan DPC
463e516b0c
Rollup merge of #93692 - mfrw:mfrw/document-keyword-in, r=dtolnay
keyword_docs: document use of `in` with `pub` keyword

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>

Fixes: #93609
2022-03-19 02:02:02 +01:00
Dylan DPC
fe55eee9a5
Rollup merge of #93263 - sunfishcode:sunfishcode/detatched-console-handle, r=dtolnay
Consistently present absent stdio handles on Windows as NULL handles.

This addresses #90964 by making the std API consistent about presenting
absent stdio handles on Windows as NULL handles. Stdio handles may be
absent due to `#![windows_subsystem = "windows"]`, due to the console
being detached, or due to a child process having been launched from a
parent where stdio handles are absent.

Specifically, this fixes the case of child processes of parents with absent
stdio, which previously ended up with `stdin().as_raw_handle()` returning
`INVALID_HANDLE_VALUE`, which was surprising, and which overlapped with an
unrelated valid handle value. With this patch, `stdin().as_raw_handle()`
now returns null in these situation, which is consistent with what it
does in the parent process.

And, document this in the "Windows Portability Considerations" sections of
the relevant documentation.
2022-03-19 02:02:01 +01:00
Dylan DPC
e9f63fdf86
Rollup merge of #92663 - cuviper:generic-write-cursor, r=dtolnay
Implement `Write for Cursor<[u8; N]>`, plus `A: Allocator` cursor support

This implements `Write for Cursor<[u8; N]>`, and also adds support for generic `A: Allocator` in `Box` and `Vec` cursors.

This was inspired by a user questioning why they couldn't write a `Cursor<[u8; N]>`:
https://users.rust-lang.org/t/why-vec-and-not-u8-makes-cursor-have-write/68210

Related history:
- #27197 switched `AsRef<[u8]>` for reading and seeking
- #67415 tried to use `AsMut<[u8]>` for writing, but did not specialize `Vec`.
2022-03-19 02:02:00 +01:00
Dylan DPC
a87590e34e
Rollup merge of #92612 - atopia:update-lib-l4re, r=dtolnay
Update stdlib for the l4re target

This PR contains the work by ``@humenda`` and myself to update standard library support for the x86_64-unknown-l4re-uclibc tier 3 target, split out from  humenda/rust as requested in #85967. The changes have been rebased on current master and updated in follow up commits by myself. The publishing of the changes is authorized and preferred by the original author. To preserve attribution, when standard library changes were introduced as part of other changes to the compiler, I have kept the changes concerning the standard library and altered the commit messages as indicated. Any incompatibilities have been remedied in follow up commits, so that the PR as a whole should result in a clean update of the target.
2022-03-19 02:01:59 +01:00
Dylan DPC
ba2d5ede70
Rollup merge of #92519 - ChrisDenton:command-maybe-verbatim, r=dtolnay
Use verbatim paths for `process::Command` if necessary

In #89174, the standard library started using verbatim paths so longer paths are usable by default. However, `Command` was originally left out because of the way `CreateProcessW` was being called. This was changed as a side effect of #87704 so now `Command` paths can be converted to verbatim too (if necessary).
2022-03-19 02:01:59 +01:00
Eric Seppanen
d5fe4cad5a add CStr::from_bytes_until_nul
This adds a member fn that converts a slice into a CStr; it is intended
to be safer than from_ptr (which is unsafe and may read out of bounds),
and more useful than from_bytes_with_nul (which requires that the caller
already know where the nul byte is).

feature gate: cstr_from_bytes_until_nul

Also add an error type FromBytesUntilNulError for this fn.
2022-03-18 15:46:49 -07:00
bors
9b701e7eaa Auto merge of #95090 - matthiaskrgr:rollup-pho6x6s, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #94115 (Let `try_collect` take advantage of `try_fold` overrides)
 - #94295 (Always evaluate all cfg predicate in all() and any())
 - #94848 (Compare installed browser-ui-test version to the one used in CI)
 - #94993 (Add test for >65535 hashes in lexing raw string)
 - #95017 (Derive Eq for std::cmp::Ordering, instead of using manual impl.)
 - #95058 (Add use of bool::then in sys/unix/process)
 - #95083 (Document that `Option<extern "abi" fn>` discriminant elision applies for any ABI)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-18 22:10:55 +00:00
David Tolnay
7d44316bcf
Bump impl Write for Cursor<[u8; N]> to 1.61 2022-03-18 15:04:37 -07:00
Matthias Krüger
9c40db22ff
Rollup merge of #95083 - danielhenrymantilla:patch-2, r=RalfJung
Document that `Option<extern "abi" fn>` discriminant elision applies for any ABI

The current phrasing was not very clear on that aspect.

r? `@RalfJung`

`@rustbot` modify labels: A-docs A-ffi
2022-03-18 21:50:50 +01:00
Matthias Krüger
c8cf9e3a8f
Rollup merge of #95058 - wcampbell0x2a:use-then-in-unix-process, r=dtolnay
Add use of bool::then in sys/unix/process

Remove `else { None }` in favor of using `bool::then()`
2022-03-18 21:50:49 +01:00
Matthias Krüger
4ead6d9dc7
Rollup merge of #95017 - zachs18:cmp_ordering_derive_eq, r=Dylan-DPC
Derive Eq for std::cmp::Ordering, instead of using manual impl.

This allows consts of type Ordering to be used in patterns, and with feature(adt_const_params) allows using `Ordering` as a const generic parameter.

Currently, `std::cmp::Ordering` implements `Eq` using a manually written `impl Eq for Ordering {}`, instead of `derive(Eq)`. This means that it does not implement `StructuralEq`.

This commit removes the manually written impl, and adds `derive(Eq)` to `Ordering`, so that it will implement `StructuralEq`.
2022-03-18 21:50:48 +01:00
Matthias Krüger
c27192041a
Rollup merge of #94993 - GrishaVar:too-many-hashes-test, r=Dylan-DPC
Add test for >65535 hashes in lexing raw string
2022-03-18 21:50:48 +01:00
Matthias Krüger
0f002eb4c6
Rollup merge of #94848 - GuillaumeGomez:browser-ui-test-version, r=Mark-Simulacrum
Compare installed browser-ui-test version to the one used in CI

I happened a few times to run into (local) rustdoc GUI tests errors because I forgot to update my browser-ui-test version. I know at least two others who encountered the same problem so I think emitting a warning to let us know about this version mismatch would make it easier to figure out.

So now, I'm not too sure that this PR is the right approach because it requires to parse a Dockerfile, which feels pretty bad. I had the idea to instead store the browser-ui-test version into a docker ARG like:

```docker
ARG BROWSER_UI_TEST_VERSION=0.8.0
```

And then use it as such in the command to make the parsing more reliable.

Or we could store this version into a file and import this file into the Dockerfile and read it from the builder.

Any preference or maybe another solution?

r? ``@Mark-Simulacrum``
2022-03-18 21:50:47 +01:00
Matthias Krüger
d15006ceca
Rollup merge of #94295 - Urgau:cfg-always-eval-all-predicate, r=petrochenkov
Always evaluate all cfg predicate in all() and any()

This pull-request adjust the handling of the `all()` and `any()` to always evaluate every cfg predicate because not doing so result in accepting incorrect `cfg`:

```rust
#[cfg(any(unix, foo::bar))] // Should error on foo::bar, but does not on unix platform (but does on non unix platform)
fn foo1() {}

#[cfg(all(foo, foo::bar))] // Should error on foo::bar, but does not
fn foo2() {}

#[cfg(all(foo::bar, foo))] // Correctly error on foo::bar
fn foo3() {}

#[cfg(any(foo::bar, foo))] // Correctly error on foo::bar
fn foo4() {}
```
This pull-request take the side to directly turn it into a hard error instead of having a future incompatibility lint because the combination to get this incorrect behavior is unusual and highly probable that some code have this without noticing.

A [search](https://cs.github.com/?scopeName=All+repos&scope=&q=lang%3Arust+%2Fany%5C%28%5Ba-zA-Z%5D%2C+%5Ba-zA-Z%5D%2B%3A%3A%5Ba-zA-Z%5D%2B%2F) on Github reveal no such instance nevertheless a Crater run should probably be done before merging this.

This was discover in https://github.com/rust-lang/rust/pull/94175 when trying to lint on the second predicate. Also note that this seems to have being introduce with Rust 1.27.0: https://rust.godbolt.org/z/KnfqKv15f.

r? `@petrochenkov`
2022-03-18 21:50:46 +01:00
Matthias Krüger
c183d4a510
Rollup merge of #94115 - scottmcm:iter-process-by-ref, r=yaahc
Let `try_collect` take advantage of `try_fold` overrides

No public API changes.

With this change, `try_collect` (#94047) is no longer going through the `impl Iterator for &mut impl Iterator`, and thus will be able to use `try_fold` overrides instead of being forced through `next` for every element.

Here's the test added, to see that it fails before this PR (once a new enough nightly is out): https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=462f2896f2fed2c238ee63ca1a7e7c56

This might as well go to the same person as my last `try_process` PR  (#93572), so
r? ``@yaahc``
2022-03-18 21:50:44 +01:00
Daniel Henry-Mantilla
156734dda0
Document that Option<extern "abi" fn> discriminant elision applies for any ABI
The current phrasing was not very clear on that aspect.
2022-03-18 18:14:34 +01:00
bors
1bfe40d11c Auto merge of #95068 - TaKO8Ki:use-create-snapshot-for-diagnostic, r=davidtwco
Use `Parser.create_snapshot_for_diagnostic` instead of `Parser.clone()`

Use [`create_snapshot_for_diagnostic`](cd11905716/compiler/rustc_parse/src/parser/diagnostics.rs (L214-L223)) I implemented in https://github.com/rust-lang/rust/pull/94731 instead of `self.clone()` to avoid duplicate unclosed delims errors being emitted when the `Parser` is dropped.
2022-03-18 14:50:29 +00:00
bors
a8adf7685a Auto merge of #95067 - nnethercote:parse_tt-more-refactoring, r=petrochenkov
Still more refactoring of `parse_tt`

r? `@petrochenkov`
2022-03-18 12:34:05 +00:00
Guillaume Gomez
c8158e9f40 Run rustdoc GUI tests when browser-ui-test version is updated 2022-03-18 10:50:53 +01:00
Guillaume Gomez
1ddbae372f Compare installed browser-ui-test version to the one used in CI 2022-03-18 10:49:50 +01:00
Takayuki Maeda
201a86046c use self.create_snapshot_for_diagnostic instead of self.clone() 2022-03-18 16:56:43 +09:00
Nicholas Nethercote
440a685575 Rename TtSeq as TtSlice.
It's a better name because (a) it holds a slice, and (b) "sequence" has
other meanings in this file.
2022-03-18 17:47:08 +11:00
Nicholas Nethercote
f43028d06f Tweak a bunch of comments.
I've been staring at these enough lately that they're annoying me, let's
make them better.
2022-03-18 17:22:34 +11:00
bors
691d1c1e12 Auto merge of #95065 - matthiaskrgr:rollup-75i6oz5, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #95013 (Update browser-ui-test version to 0.8.2)
 - #95039 (Make negative coherence work when there's impl negative on super predicates)
 - #95047 (Refactor: remove an unnecessary pattern for ignoring all parts)
 - #95048 (update Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-18 05:26:14 +00:00
Matthias Krüger
d3dc65be66
Rollup merge of #95048 - RalfJung:miri, r=RalfJung
update Miri

Let's get those SIMD intrinsics out there. :)
r? `@ghost`
2022-03-18 05:21:57 +01:00
Matthias Krüger
7ec0c2f633
Rollup merge of #95047 - TaKO8Ki:remove-unnecessary-pattern-for-ignoring-all-parts, r=wesleywiser
Refactor: remove an unnecessary pattern for ignoring all parts
2022-03-18 05:21:56 +01:00
Matthias Krüger
588d389dc5
Rollup merge of #95039 - spastorino:overlap-super-predicates, r=nikomatsakis
Make negative coherence work when there's impl negative on super predicates

r? `@nikomatsakis`
2022-03-18 05:21:55 +01:00
Matthias Krüger
0e1b897d91
Rollup merge of #95013 - GuillaumeGomez:browser-ui-test-v, r=notriddle
Update browser-ui-test version to 0.8.2

It brings mostly debugging improvements: it doesn't stop at the first failing command but rather at the first "fatal error".

r? `@notriddle`
2022-03-18 05:21:54 +01:00
Nicholas Nethercote
14875a5564 Reorder cases in parse_tt_inner.
I find the new order easier to read: within a matcher; past the end of a
repetition; at end of input. It also reduces the indentation level by
one for
2022-03-18 14:21:13 +11:00
Nicholas Nethercote
83044714a1 Only modify eof_items if token == Eof.
Because that's the condition under which `eof_items` is used.
2022-03-18 14:11:01 +11:00
Nicholas Nethercote
8bd1bcad58 Factor out some code into MatcherPos::repetition.
Also move `create_matches` within `impl MatcherPos`, because it's only
used within that impl block.
2022-03-18 14:09:02 +11:00
bors
d6f3a4ecb4 Auto merge of #88098 - Amanieu:oom_panic, r=nagisa
Implement -Z oom=panic

This PR removes the `#[rustc_allocator_nounwind]` attribute on `alloc_error_handler` which allows it to unwind with a panic instead of always aborting. This is then used to implement `-Z oom=panic` as per RFC 2116 (tracking issue #43596).

Perf and binary size tests show negligible impact.
2022-03-18 03:01:46 +00:00
Nicholas Nethercote
5bbbee5ba7 Add two useful assertions. 2022-03-18 13:57:11 +11:00
bors
cd11905716 Auto merge of #95056 - Dylan-DPC:rollup-swtuw2n, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #91133 (Improve `unsafe` diagnostic)
 - #93222 (Make ErrorReported impossible to construct outside `rustc_errors`)
 - #93745 (Stabilize ADX target feature)
 - #94309 ([generator_interior] Be more precise with scopes of borrowed places)
 - #94698 (Remove redundant code from copy-suggestions)
 - #94731 (Suggest adding `{ .. }` around a const function call with arguments)
 - #94960 (Fix many spelling mistakes)
 - #94982 (Add deprecated_safe feature gate and attribute, cc #94978)
 - #94997 (debuginfo: Fix ICE when generating name for type that produces a layout error.)
 - #95000 (Fixed wrong type name in comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-18 00:35:19 +00:00
wcampbell
b1f3179804 feat: Add use of bool::then in sys/unix/process
Remove else { None } in favor of using bool::then()
2022-03-17 19:12:09 -04:00
Dylan DPC
4493826d07
Rollup merge of #95000 - fee1-dead:fee1-dead-patch-1, r=Mark-Simulacrum
Fixed wrong type name in comment

95kth issue/pr!
2022-03-17 22:55:08 +01:00
Dylan DPC
e55400ca27
Rollup merge of #94997 - michaelwoerister:fix-enum-type-name-layout-error, r=wesleywiser
debuginfo: Fix ICE when generating name for type that produces a layout error.

Fixes https://github.com/rust-lang/rust/issues/94961.
2022-03-17 22:55:07 +01:00
Dylan DPC
0c73b252eb
Rollup merge of #94982 - skippy10110:deprecated_safe, r=Dylan-DPC
Add deprecated_safe feature gate and attribute, cc #94978
2022-03-17 22:55:06 +01:00
Dylan DPC
270a41c33e
Rollup merge of #94960 - codehorseman:master, r=oli-obk
Fix many spelling mistakes

Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-17 22:55:05 +01:00
Dylan DPC
5eb3433ed5
Rollup merge of #94731 - TaKO8Ki:const-generic-expr-recovery, r=davidtwco,oli-obk
Suggest adding `{ .. }` around a const function call with arguments

closes #91020
2022-03-17 22:55:04 +01:00
Dylan DPC
a8956e6618
Rollup merge of #94698 - WaffleLapkin:simplify-copy-suggestions, r=estebank
Remove redundant code from copy-suggestions

Follow up to #94375, just remove some code that is not necessary anymore. This may make the perf of such suggestions a little bit worse, but I don't think this is significant.

r? `@estebank`
2022-03-17 22:55:03 +01:00
Dylan DPC
8499a8ba88
Rollup merge of #94309 - eholk:issue-57017, r=tmandry
[generator_interior] Be more precise with scopes of borrowed places

Previously the generator interior type checking analysis would use the nearest temporary scope as the scope of a borrowed value. This ends up being overly broad for cases such as:

```rust
fn status(_client_status: &Client) -> i16 {
    200
}

fn main() {
    let client = Client;
    let g = move || match status(&client) {
        _status => yield,
    };
    assert_send(g);
}
```

In this case, the borrow `&client` could be considered in scope for the entirety of the `match` expression, meaning it would be viewed as live across the `yield`, therefore making the generator not `Send`.

In most cases, we want to use the enclosing expression as the scope for a borrowed value which will be less than or equal to the nearest temporary scope. This PR changes the analysis to use the enclosing expression as the scope for most borrows, with the exception of borrowed RValues which are true temporary values that should have the temporary scope. There's one further exception where borrows of a copy such as happens in autoref cases also should be ignored despite being RValues.

Joint work with `@nikomatsakis`

Fixes #57017

r? `@tmandry`
2022-03-17 22:55:02 +01:00
Dylan DPC
07121c88ad
Rollup merge of #93745 - tarcieri:stabilize-adx, r=cjgillot
Stabilize ADX target feature

This is a continuation of #60109, which noted that while the ADX intrinsics were stabilized, the corresponding target feature never was.

This PR follows the same general structure and stabilizes the ADX target feature.

See also https://github.com/rust-lang/rust/issues/44839 - tracking issue for target feature
2022-03-17 22:55:01 +01:00
Dylan DPC
7e1415ea80
Rollup merge of #93222 - mark-i-m:errorreported, r=oli-obk
Make ErrorReported impossible to construct outside `rustc_errors`

There are a few places were we have to construct it, though, and a few
places that are more invasive to change. To do this, we create a
constructor with a long obvious name.

cc #69426 `@varkor` `@eddyb` `@estebank`

I actually didn't see that I was assigned to this issue until now...
2022-03-17 22:55:00 +01:00
Dylan DPC
c8133f6f5e
Rollup merge of #91133 - terrarier2111:unsafe-diagnostic, r=jackh726
Improve `unsafe` diagnostic

This fixes: https://github.com/rust-lang/rust/issues/90880
I didn't use the exact proposed messages though.
2022-03-17 22:54:59 +01:00
bors
4ca56d2b7b Auto merge of #95020 - compiler-errors:late-debuginfo, r=jackh726
erase late-bound regions in dyn projection types for debuginfo

simply skipping the binder leaves late-bound regions that will cause debug assertions to fail when checking the layout of the projection ty, so let's erase the regions instead.

sorry for taking so long to put this up, had trouble getting rustc set up on a new computer.

fixes #94998
2022-03-17 21:54:25 +00:00
Niko Matsakis
89a00cc8ae
Update compiler/rustc_trait_selection/src/traits/coherence.rs 2022-03-17 16:51:30 -04:00
bors
58f11791af Auto merge of #95050 - ehuss:fix-cmake-build, r=Mark-Simulacrum
Fix cmake build.

This is an attempt to fix the cmake build. For some reason, it has recently started failing with a permission denied trying to overwrite `/tmp/build.log`.  This file exists from the `build-toolchains.sh` step, which is owned by the rustbuild user. I think there is some behavior where a sticky `/tmp` directory doesn't allow overwriting files owned by other users even when running as root.  I do not know why this has suddenly started, and I can't reproduce locally with my own docker setup. However, this fix seems to work on CI.
2022-03-17 18:52:14 +00:00
Eric Huss
8322cdb1da Fix cmake build. 2022-03-17 11:43:38 -07:00