Commit Graph

165541 Commits

Author SHA1 Message Date
Antonio Yang
3a0ae49135 Refactor after review
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-03-29 20:34:13 +08:00
Guillaume Gomez
8071332d83 Merge ItemKind::TyMethodItem branch with ItemKind::FunctionItem and ItemKind::MethodItem in fn_header function 2022-03-29 12:09:42 +02:00
bors
e2301ca543 Auto merge of #95375 - MarcusCalhoun-Lopez:i686_apple_darwin, r=m-ou-se
Fix build on i686-apple-darwin systems

Replace `target_arch = "x86_64"` with `not(target_arch = "aarch64")` so that i686-apple-darwin systems dynamically choose implementation.
2022-03-29 10:08:03 +00:00
Guillaume Gomez
fd48ea02af Add test to ensure foreign functions from dependencies are correctly handled 2022-03-29 11:46:57 +02:00
Guillaume Gomez
2c4ce9d2dc Remove header field from clean::Function 2022-03-29 11:46:57 +02:00
bors
abf0ec8383 Auto merge of #95257 - compiler-errors:fn-borrow, r=lcnr
Add suggestion to borrow `Fn` and `FnMut` params/opaque/closures instead of move

I think that Closure/ParamTy/Opaque are all "opaque" enough that it's meaningful to suggest borrowing them instead of moving them at their usage sites when we see a move error. See the attached issue for example.

Is this suggestion too general? I could perhaps use the move site information to limit this to places like fn calls, but I don't know enough about mir borrowck to know if that's an easy change.

Fixes #90828
2022-03-29 07:27:14 +00:00
Laurențiu Nicola
acb9b7e842 ⬆️ rust-analyzer 2022-03-29 08:31:05 +03:00
Michael Goulet
ac95e80186 Suggest function borrow ignoring needs_note
`needs_note` is false if we've already suggested why the type is Copy...
but that has nothing to do with the diagnostic.
2022-03-28 22:27:07 -07:00
Michael Goulet
a9b02e13a6 drive-by: move Copy bound suggestion to its own function 2022-03-28 22:27:07 -07:00
Michael Goulet
0f3c2933e0 Add suggestion to borrow opaque Fn and FnMut instead of move 2022-03-28 22:27:06 -07:00
bors
14328e654a Auto merge of #95423 - ehuss:update-books, r=ehuss
Update books

## nomicon

3 commits in f6d6126fc96ecf4a7f7d22da330df9506293b0d0..11f1165e8a2f5840467e748c8108dc53c948ee9a
2022-02-26 02:21:21 +0900 to 2022-03-19 16:02:00 -0400
- Make the Vec impl be slightly more careful with ZSTs and alignment.
- implement `IntoIterator` for `Vec` (rust-lang/nomicon#337)
- Add an explanation shared to exclusive transmute (rust-lang/nomicon#344)

## reference

2 commits in 0a2fe6651fbccc6416c5110fdf5b93fb3cb29247..c97d14fa6fed0baa9255432b8a93cb70614f80e3
2022-03-15 09:32:25 -0700 to 2022-03-19 18:18:10 -0700
- Fixed inconsistency in the usage of semicolon at end of scopes (rust-lang/reference#1182)
- Document ADX `target_feature` (rust-lang/reference#1172)

## book

23 commits in 036e88a4f135365de85358febe5324976a56030a..ea90bbaf53ba64ef4e2da9ac2352b298aec6bec8
2022-03-04 21:53:33 -0500 to 2022-03-28 21:59:34 -0400
- Fix nostarch snapshot
- Snapshot of chapter 7 for nostarch
- Add a forward reference to chapter 14, another example of pub use
- Clarify pub use example. Fixes rust-lang/book#2716.
- Fancy quotes
- Fix incorrectly worded sentence. Fixes rust-lang/book#3086.
- Reword description of how a listing came to be
- Call out binary+library crate practices
- Define binary and library crates more explicitly
- Clarify when a path is a crate name and when it should be literal crate
- Make it clearer the outer `mod` doesn't move to the file
- Don't wrap this example in main when copying. Fixes rust-lang/book#2930.
- Try to make clearer that `mod` is not an `import`
- Mention mod.rs file naming scheme
- Explain why submodule subdirectories are needed more
- Rename a separate example of serve_order to deliver_order
- Show an example that `use` only applies in its own scope
- quick modules guide
- Tweak a snippet of ch18-03
- Propagating edits to chapter 10 back
- Responses to nostarch questions of chapter 10
- Update src/ch04-01-what-is-ownership.md
- Add Danish translation link. Connects to rust-lang/book#3079.

## rust-by-example

2 commits in d504324f1e7dc7edb918ac39baae69f1f1513b8e..ec954f35eedf592cd173b21c05a7f80a65b61d8a
2022-03-07 09:26:32 -0300 to 2022-03-22 11:09:06 -0300
- PathBuf details and example (rust-lang/rust-by-example#1519)
- Move allow dead code attribute and add comment (rust-lang/rust-by-example#1518)

## rustc-dev-guide

1 commits in 0e4b961a9c708647bca231430ce1b199993e0196..155126b1d2e2cb01ddb1d7ba9489b90d7cd173ad
2022-03-14 08:40:37 -0700 to 2022-03-22 14:34:21 +0100
- update section for type system constants (rust-lang/rustc-dev-guide#1329)

## embedded-book

1 commits in d5fc1bce3f8eb398f9c25f1b15e0257d7537cd41..a6de8b6e3ea5d4f0de8b7b9a7e5c1405dc2c2ddb
2022-01-24 07:13:31 +0000 to 2022-03-17 21:21:39 +0000
- Update OpenOCD install instruction for rust-embedded/book#313  (rust-embedded/book#314)
2022-03-29 05:15:58 +00:00
Eric Huss
565669fb5b Update books 2022-03-28 22:16:31 -07:00
Takayuki Maeda
f2506c911b use format-args-capture and remove an unnecessary nested block 2022-03-29 12:18:22 +09:00
Caleb Cartwright
e0c7b7d5d3 tests: ignore cargo fmt test for rust-lang/rust runs 2022-03-28 21:33:45 -05:00
Caleb Cartwright
4fecede7fd Revert "Use cargo-fmt in self_tests"
This reverts commit c63d42e804.
2022-03-28 21:33:45 -05:00
bors
ad5b6f6b72 Auto merge of #95417 - ehuss:doc-no_std-error, r=Dylan-DPC
bootstrap: better error message for no_std docs

Currently if one tries to build std documentation for a no_std target, you get a confusing error message:

`error: The argument '--package [<SPEC>...]' was provided more than once, but cannot be used multiple times`

This is because [`std_cargo`](600ec28483/src/bootstrap/compile.rs (L299-L305)) has a built-in `-p alloc` argument that conflicts with the `cargo rustdoc` command used in the Std doc step.

This just adds a better error message in this scenario. It may be possible to fix this correctly, but that would likely be a bit more of an invasive change that I don't have time for right now.
2022-03-29 01:09:22 +00:00
bors
c1230e137b Auto merge of #95249 - HeroicKatora:set-ptr-value, r=dtolnay
Refactor set_ptr_value as with_metadata_of

Replaces `set_ptr_value` (#75091) with methods of reversed argument order:

```rust
impl<T: ?Sized> *mut T {
    pub fn with_metadata_of<U: ?Sized>(self, val: *mut U) -> *mut U;
}

impl<T: ?Sized> *const T {
    pub fn with_metadata_of<U: ?Sized>(self, val: *const U) -> *const U;
}
```

By reversing the arguments we achieve several clarifications:

- The function closely resembles `cast` with an argument to
  initialize the metadata. This is easier to teach and answers a long
  outstanding question that had restricted cast to `Sized` pointee
  targets. See multiples reviews of
  <https://github.com/rust-lang/rust/pull/47631>
- The 'object identity', in the form of provenance, is now preserved
  from the receiver argument to the result. This helps explain the method as
  a builder-style, instead of some kind of setter that would modify
  something in-place. Ensuring that the result has the identity of the
  `self` argument is also beneficial for an intuition of effects.
- An outstanding concern, 'Correct argument type', is avoided by not
  committing to any specific argument type. This is consistent with cast
  which does not require its receiver to be a 'raw address'.

Hopefully the usage examples in `sync/rc.rs` serve as sufficient examples of the style to convince the reader of the readability improvements of this style, when compared to the previous order of arguments.

I want to take the opportunity to motivate inclusion of this method _separate_ from metadata API, separate from `feature(ptr_metadata)`. It does _not_ involve the `Pointee` trait in any form. This may be regarded as a very, very light form that does not commit to any details of the pointee trait, or its associated metadata. There are several use cases for which this is already sufficient and no further inspection of metadata is necessary.

- Storing the coercion of `*mut T` into `*mut dyn Trait` as a way to dynamically cast some an arbitrary instance of the same type to a dyn trait instance. In particular, one can have a field of type `Option<*mut dyn io::Seek>` to memorize if a particular writer is seekable. Then a method `fn(self: &T) -> Option<&dyn Seek>` can be provided, which does _not_ involve the static trait bound `T: Seek`. This makes it possible to create an API that is capable of utilizing seekable streams and non-seekable streams (instead of a possible less efficient manner such as more buffering) through the same entry-point.

- Enabling more generic forms of unsizing for no-`std` smart pointers. Using the stable APIs only few concrete cases are available. One can unsize arrays to `[T]` by `ptr::slice_from_raw_parts` but unsizing a custom smart pointer to, e.g., `dyn Iterator`, `dyn Future`, `dyn Debug`, can't easily be done generically. Exposing `with_metadata_of` would allow smart pointers to offer their own `unsafe` escape hatch with similar parameters where the caller provides the unsized metadata. This is particularly interesting for embedded where `dyn`-trait usage can drastically reduce code size.
2022-03-28 22:47:31 +00:00
Nicholas Nethercote
df6ead557d Add a useful assertion. 2022-03-29 08:00:26 +11:00
Marcus Calhoun-Lopez
8c18844324 Fix build on i686-apple-darwin systems
On 32-bit systems, fdopendir is called `_fdopendir$INODE64$UNIX2003`.
On 64-bit systems, fdopendir is called `_fdopendir$INODE64`.
2022-03-28 12:52:14 -07:00
Marcus Calhoun-Lopez
c2d5c64132 Fix build on i686-apple-darwin systems
Replace `target_arch = "x86_64"` with `not(target_arch = "aarch64")` so that i686-apple-darwin systems dynamically choose implementation.
2022-03-28 12:52:14 -07:00
Eric Huss
935e281959 bootstrap: better error message for no_std docs 2022-03-28 12:13:18 -07:00
Michael Howell
757ab6b55c diagnostics: add regression test for #82081 2022-03-28 11:48:14 -07:00
Michael Howell
a063b3a4b6 diagnostics: do not suggest map.iter_mut()() 2022-03-28 11:48:14 -07:00
bors
ee915c34e2 Auto merge of #95414 - Dylan-DPC:rollup-9hbshd0, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #93787 (parallel_compiler: hide dependencies behind feature)
 - #95318 (diagnostics: correct generic bounds with doubled colon)
 - #95328 (Fix yet another Box<T, A> ICE)
 - #95397 (Link to std::io's platform-specific behavior disclaimer)
 - #95407 (Inline u8::is_utf8_char_boundary)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-28 18:42:59 +00:00
Dylan DPC
1f33cd1827
Rollup merge of #95407 - xfix:inline-u8-is_utf8_char_boundary, r=scottmcm
Inline u8::is_utf8_char_boundary

Since Rust beta, Rust is incapable of inlining this function in the following example function.

```rust
pub fn safe_substr_to(s: &str, mut length: usize) -> &str {
    loop {
        if let Some(s) = s.get(..length) {
            return s;
        }
        length -= 1;
    }
}
```

When compiled with beta or nightly compiler on Godbolt with `-C opt-level=3` flag it prints the following assembly.

```asm
example::safe_substr_to:
        push    r15
        push    r14
        push    r12
        push    rbx
        push    rax
        mov     r14, rdi
        test    rdx, rdx
        je      .LBB0_8
        mov     rbx, rdx
        mov     r15, rsi
        mov     r12, qword ptr [rip + core::num::<impl u8>::is_utf8_char_boundary@GOTPCREL]
        jmp     .LBB0_4
.LBB0_2:
        je      .LBB0_9
.LBB0_3:
        add     rbx, -1
        je      .LBB0_8
.LBB0_4:
        cmp     rbx, r15
        jae     .LBB0_2
        movzx   edi, byte ptr [r14 + rbx]
        call    r12
        test    al, al
        je      .LBB0_3
        mov     r15, rbx
        jmp     .LBB0_9
.LBB0_8:
        xor     r15d, r15d
.LBB0_9:
        mov     rax, r14
        mov     rdx, r15
        add     rsp, 8
        pop     rbx
        pop     r12
        pop     r14
        pop     r15
        ret
```

`qword ptr [rip + core::num::<impl u8>::is_utf8_char_boundary@GOTPCREL]` is not inlined. `-C remark=all` outputs the following message:

```
note: /rustc/7bccde19767082c7865a12902fa614ed4f8fed73/library/core/src/str/mod.rs:214:25: inline: _ZN4core3num20_$LT$impl$u20$u8$GT$21is_utf8_char_boundary17hace9f12f5ba07a7fE will not be inlined into _ZN4core3str21_$LT$impl$u20$str$GT$16is_char_boundary17hf2587e9a6b8c5e43E because its definition is unavailable
```

Stable compiler outputs more reasonable code:

```asm
example::safe_substr_to:
        mov     rcx, rdx
        mov     rax, rdi
        test    rdx, rdx
        je      .LBB0_9
        mov     rdx, rsi
        jmp     .LBB0_4
.LBB0_2:
        cmp     rdx, rcx
        je      .LBB0_7
.LBB0_3:
        add     rcx, -1
        je      .LBB0_9
.LBB0_4:
        cmp     rcx, rdx
        jae     .LBB0_2
        cmp     byte ptr [rax + rcx], -64
        jl      .LBB0_3
        mov     rdx, rcx
.LBB0_7:
        ret
.LBB0_9:
        xor     edx, edx
        ret
```
2022-03-28 20:41:53 +02:00
Dylan DPC
4c8bc046b9
Rollup merge of #95397 - dtolnay:disclaimer, r=m-ou-se
Link to std::io's platform-specific behavior disclaimer

This PR adds some links in standard library documentation to point to https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior.

> ### Platform-specific behavior
>
> Many I/O functions throughout the standard library are documented to indicate what various library or syscalls they are delegated to. This is done to help applications both understand what’s happening under the hood as well as investigate any possibly unclear semantics. Note, however, that this is informative, not a binding contract. The implementation of many of these functions are subject to change over time and may call fewer or more syscalls/library functions.

Many of the `std::fs` APIs already link to this disclaimer when discussing system calls.
2022-03-28 20:41:52 +02:00
Dylan DPC
ce319ac1a2
Rollup merge of #95328 - DrMeepster:box_gep_err, r=oli-obk
Fix yet another Box<T, A> ICE

Fixes #95036.

This widens the special case from #94414 to make sure that boxes with a custom allocator are never directly dereferenced.
2022-03-28 20:41:51 +02:00
Dylan DPC
e10d5039bc
Rollup merge of #95318 - rust-lang:notriddle/issue-95208, r=wesleywiser
diagnostics: correct generic bounds with doubled colon

Fixes #95208
2022-03-28 20:41:50 +02:00
Dylan DPC
72770efcb0
Rollup merge of #93787 - klensy:really-not-a-features, r=wesleywiser
parallel_compiler: hide dependencies behind feature

Separate dependencies for `parallel_compiler` feature, so they will not be compiled if feature not selected, reducing number of compiled crates from 238 to 224.
2022-03-28 20:41:49 +02:00
Oli Scherer
638f84d782 rebase fallout 2022-03-28 17:22:42 +00:00
Oli Scherer
b262c7c2da Add test for revealing auto traits in the defining scope 2022-03-28 17:09:50 +00:00
Oli Scherer
5d3941878e Add some tests showcasing further differences between TAIT and RPIT 2022-03-28 17:09:40 +00:00
Oli Scherer
88296432d3 Bless ui tests 2022-03-28 17:09:29 +00:00
Oli Scherer
360edd611d Also use the RPIT back compat hack in trait projection 2022-03-28 17:09:00 +00:00
Oli Scherer
dc35d584a9 Show that the behaviour is the same for RPIT and TAIT 2022-03-28 17:08:50 +00:00
Oli Scherer
e82b0cde4e Add a test showing that a similar example compiles 2022-03-28 17:08:40 +00:00
Oli Scherer
7b4f715979 Added another folder to the ui dir 2022-03-28 17:08:28 +00:00
Oli Scherer
2aa49d4005 Fix mixing lazy TAIT and RPIT in their defining scopes 2022-03-28 17:02:21 +00:00
Oli Scherer
4f6e27d4cf Add regression test 2022-03-28 17:02:08 +00:00
Oli Scherer
3cce66c544 Add another regression test 2022-03-28 17:01:57 +00:00
Oli Scherer
6596e9dfcf Test that TAIT and RPIT are in sync 2022-03-28 17:01:23 +00:00
Oli Scherer
53c96ed528 Add some tests around recursion and "revealing" 2022-03-28 17:01:09 +00:00
Oli Scherer
1f46f771a6 Remove some special code handling TAIT being passed through if and match
This is not necessary for RPIT anymore, since we reverted that to using inference vars.
2022-03-28 17:00:29 +00:00
Oli Scherer
02536fe18b The hack isn't necessary for back compat anymore 2022-03-28 16:59:56 +00:00
Oli Scherer
7f933de194 Merge two duplicates of the same logic into a common function 2022-03-28 16:59:11 +00:00
Oli Scherer
2bf63a5011 Add regression tests 2022-03-28 16:58:59 +00:00
Oli Scherer
1163aa7e72 Remove opaque type obligation and just register opaque types as they are encountered.
This also registers obligations for the hidden type immediately.
2022-03-28 16:57:45 +00:00
Noa
97c58e8a87 Touch up ExitCode docs 2022-03-28 09:54:57 -07:00
Oli Scherer
86e1860495 Revert to inference variable based hidden type computation for RPIT 2022-03-28 16:53:47 +00:00
Konrad Borowski
12c085a057 Inline u8::is_utf8_char_boundary 2022-03-28 18:37:11 +02:00