Commit graph

168271 commits

Author SHA1 Message Date
Scott McMurray bb7b844d7c Rename unsigned_offset_from to sub_ptr 2022-05-11 17:16:25 -07:00
Scott McMurray 003b954a43 Apply CR suggestions; add real tracking issue 2022-05-11 17:16:25 -07:00
Scott McMurray 06817d1bb3 Add unsigned_offset_from on pointers
Like we have `add`/`sub` which are the `usize` version of `offset`, this adds the `usize` equivalent of `offset_from`.  Like how `.add(d)` replaced a whole bunch of `.offset(d as isize)`, you can see from the changes here that it's fairly common that code actually knows the order between the pointers and *wants* a `usize`, not an `isize`.

As a bonus, this can do `sub nuw`+`udiv exact`, rather than `sub`+`sdiv exact`, which can be optimized slightly better because it doesn't have to worry about negatives.  That's why the slice iterators weren't using `offset_from`, though I haven't updated that code in this PR because slices are so perf-critical that I'll do it as its own change.

This is an intrinsic, like `offset_from`, so that it can eventually be allowed in CTFE.  It also allows checking the extra safety condition -- see the test confirming that CTFE catches it if you pass the pointers in the wrong order.
2022-05-11 17:16:25 -07:00
Scott McMurray 4bb15b3797 Add a debug check for ordering, and check for isize overflow in CTFE 2022-05-11 17:16:25 -07:00
Scott McMurray e76b3f3b5b Rename unsigned_offset_from to sub_ptr 2022-05-11 17:16:25 -07:00
Scott McMurray 89a18cb600 Add unsigned_offset_from on pointers
Like we have `add`/`sub` which are the `usize` version of `offset`, this adds the `usize` equivalent of `offset_from`.  Like how `.add(d)` replaced a whole bunch of `.offset(d as isize)`, you can see from the changes here that it's fairly common that code actually knows the order between the pointers and *wants* a `usize`, not an `isize`.

As a bonus, this can do `sub nuw`+`udiv exact`, rather than `sub`+`sdiv exact`, which can be optimized slightly better because it doesn't have to worry about negatives.  That's why the slice iterators weren't using `offset_from`, though I haven't updated that code in this PR because slices are so perf-critical that I'll do it as its own change.

This is an intrinsic, like `offset_from`, so that it can eventually be allowed in CTFE.  It also allows checking the extra safety condition -- see the test confirming that CTFE catches it if you pass the pointers in the wrong order.
2022-05-11 17:16:25 -07:00
bors 0cd939e36c Auto merge of #96150 - est31:unused_macro_rules, r=petrochenkov
Implement a lint to warn about unused macro rules

This implements a new lint to warn about unused macro rules (arms/matchers), similar to the `unused_macros` lint added by #41907 that warns about entire macros.

```rust
macro_rules! unused_empty {
    (hello) => { println!("Hello, world!") };
    () => { println!("empty") }; //~ ERROR: 1st rule of macro `unused_empty` is never used
}

fn main() {
    unused_empty!(hello);
}
```

Builds upon #96149 and #96156.

Fixes #73576
2022-05-12 00:08:08 +00:00
Gary Guo c586bc3d76 Prevent unwinding when -C panic=abort is used regardless declared ABI 2022-05-12 00:03:48 +01:00
bors cb9cb4d4e1 Auto merge of #96806 - cjgillot:codegen-fulfill-nice, r=oli-obk
Gracefully fail to resolve associated items instead of `delay_span_bug`.

`codegen_fulfill_obligation` is used during instance resolution for trait items.

In case of insufficient normalization issues during MIR inlining, it caused ICEs.
It's better to gracefully refuse to resolve the associated item, and let the caller decide what to do with this.

Split from https://github.com/rust-lang/rust/pull/91743
Closes #69121
Closes #73021
Closes #88599
Closes #93008
Closes #93248
Closes #94680
Closes #96170
r? `@oli-obk`
2022-05-11 21:39:02 +00:00
Aaron Hill 6b747aa397
Remove PartialOrd/Ord impl for PlaceRef
This is a new attempt at #93315. It removes one usage
of the `Ord` impl for `DefId`, which should make it easier
to eventually remove that impl.
2022-05-11 16:22:23 -04:00
bors 6dd68402c5 Auto merge of #96220 - RalfJung:scalar-no-padding, r=oli-obk
tighten sanity checks around Scalar and ScalarPair

While investigating https://github.com/rust-lang/rust/issues/96185 I noticed codegen has tighter sanity checks here than Miri does, so I added some more assertions. Strangely, some of them fail, so I also needed to add a HACK... that is probably worth looking into.

This does not fix that issue, but it changes the ICE messages, making it quite clear that we have a scalar whose size is not the same as that of the surrounding layout.

r? `@oli-obk`
2022-05-11 18:34:14 +00:00
Camille GILLOT dacf1185cb Bless clippy. 2022-05-11 18:51:14 +02:00
Dan Gohman 5c60951344 Fix attribute name. 2022-05-11 09:29:08 -07:00
Dan Gohman a5077f1342 RawSocket is unsigned on Windows. 2022-05-11 09:10:33 -07:00
ludfo774 cdbfd3e011
Add test of matches macro for trailing commas 2022-05-11 16:42:16 +02:00
Dan Gohman 78806d4cfe Fix duplicate import on Windows. 2022-05-11 07:41:34 -07:00
Dan Gohman 90ff6fcd4e Add rustc_nonnull_optimization_guaranteed to Owned/Borrowed Fd/Socket
PR #94586 added support for using
`rustc_nonnull_optimization_guaranteed` on values where the "null" value
is the all-ones bitpattern.

Now that #94586 has made it to the stage0 compiler, add
`rustc_nonnull_optimization_guaranteed` to `OwnedFd`, `BorrowedFd`,
`OwnedSocket`, and `BorrowedSocket`, since these types all exclude
all-ones bitpatterns.

This allows `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`,
and `Option<BorrowedSocket>` to be used in FFI declarations, as described
in the [I/O safety RFC].

[I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
2022-05-11 07:26:49 -07:00
bors 08b4f1be33 Auto merge of #96942 - Dylan-DPC:rollup-p8bcly2, r=Dylan-DPC
Rollup of 4 pull requests

Successful merges:

 - #91518 (Add readable rustdoc display for RISC-V target)
 - #95281 (Fix inaccurate function name in `rustc_const_eval` docs)
 - #96898 (logging: add env var to control verbose scope entry/exit logging)
 - #96936 (⬆️ rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-11 13:47:38 +00:00
Dan Gohman 2f75b4aaa6 HandleOrNull can hold null, and HandleOrInvalid can hold INVALID_HANDLE_VALUE. 2022-05-11 06:40:52 -07:00
Dylan DPC cf1d52f9cc
Rollup merge of #96936 - lnicola:rust-analyzer-2022-05-11, r=lnicola
⬆️ rust-analyzer

r? `@ghost`
2022-05-11 13:49:30 +02:00
Dylan DPC afb9171b64
Rollup merge of #96898 - RalfJung:interpret-pop-debug, r=oli-obk
logging: add env var to control verbose scope entry/exit logging

~~This got removed in https://github.com/rust-lang/rust/pull/75143, and I find this makes long traces a lot harder to read, so I propose we add this back.~~

Example trace:
```
│ │ ├─0ms  INFO rustc_const_eval::interpret::step return
│ │ ├─0ms  INFO rustc_const_eval::interpret::eval_context popping stack frame (returning from function)
│ │┌┘rustc_const_eval::interpret::eval_context::frame std::ptr::mut_ptr::<impl *mut u8>::guaranteed_eq
│ ├┘rustc_const_eval::interpret::eval_context::frame std::ptr::mut_ptr::<impl *mut u8>::is_null
│ ├─1ms  INFO rustc_const_eval::interpret::step // executing bb2
│ ├─1ms  INFO rustc_const_eval::interpret::step StorageDead(_4)
│ ├─1ms  INFO rustc_const_eval::interpret::step StorageDead(_2)
│ ├─1ms  INFO rustc_const_eval::interpret::step return
│ ├─1ms  INFO rustc_const_eval::interpret::eval_context popping stack frame (returning from function)
│┌┘rustc_const_eval::interpret::eval_context::frame std::ptr::mut_ptr::<impl *mut u8>::is_null
├┘rustc_const_eval::interpret::eval_context::frame std::sys_common::thread_local_dtor::register_dtor_fallback::run_dtors
├─178ms  INFO rustc_const_eval::interpret::step // executing bb2
├─178ms  INFO rustc_const_eval::interpret::step StorageDead(_5)

```

r? `@oli-obk`
2022-05-11 13:49:29 +02:00
Dylan DPC 0c2cee2e9d
Rollup merge of #95281 - pierwill:fix-85513, r=Dylan-DPC
Fix inaccurate function name in `rustc_const_eval` docs

Looks to me like this fixes #85513. I had trouble making a intra-docs link to `eval_place_to_op` work, though...
2022-05-11 13:49:28 +02:00
Dylan DPC 2af6677de8
Rollup merge of #91518 - luojia65:rustdoc-riscv-arch, r=GuillaumeGomez
Add readable rustdoc display for RISC-V target

This pull request adds a human readable rustdoc display for RISC-V architecture. Target configuration marked as `#[cfg(target_arch = "riscv32")]` or `#[cfg(target_arch = "riscv64")]` are pretty formatted like `RISC-V RV32` and `RISC-V RV64` in Rust docs.

Before:

![图片](https://user-images.githubusercontent.com/40385009/152681944-58d758ae-ac4f-412b-b70c-1e673a2a071e.png)

After:

![图片](https://user-images.githubusercontent.com/40385009/152681923-91d5fe75-c3b2-4ac2-865c-54eac0aefe8d.png)
2022-05-11 13:49:27 +02:00
Ralf Jung 14f6daf935 avoid computing Scalar size/align in debug builds 2022-05-11 13:32:19 +02:00
bors a85de162a5 Auto merge of #96924 - petrochenkov:nonon, r=nnethercote
ast: Introduce some traits to get AST node properties generically

And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
r? `@nnethercote` `@Aaron1011`
2022-05-11 11:06:49 +00:00
bjorn3 343c532f4f Use cfg(any()) instead of cfg(disabled)
Rustbuild uses --check-cfg without allowing disabled as cfg name
2022-05-11 10:49:31 +00:00
Takayuki Maeda daeec7e22d stop suggesting non-existing fully qualified paths 2022-05-11 19:18:02 +09:00
Vadim Petrochenkov f2b7fa4847 ast: Introduce some traits to get AST node properties generically
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
2022-05-11 12:43:27 +03:00
Guillaume Gomez dd6bb09133 Ensure that the settings CSS is loaded on the settings page 2022-05-11 11:29:21 +02:00
Guillaume Gomez 92482cabaa Remove unused CSS settings rules 2022-05-11 11:27:13 +02:00
Guillaume Gomez 84615e868b Add missing CSS file for settings page 2022-05-11 11:27:00 +02:00
Laurențiu Nicola 145bb1f64b ⬆️ rust-analyzer 2022-05-11 12:26:06 +03:00
bors f296b9a32a Auto merge of #96933 - ehuss:update-books, r=ehuss
Update books

## nomicon

9 commits in c7d8467ca9158da58ef295ae65dbf00a308752d9..10d40c59a581c66d8ecd29ad18d410bf97ed524d
2022-04-06 14:26:54 +0900 to 2022-05-07 10:45:07 +0900
- Introducing init/uninit before its use (rust-lang/nomicon#355)
- Change will to would to discuss what don't occur (rust-lang/nomicon#361)
- State that pop for length 1 is an example (rust-lang/nomicon#360)
- Correct a sentence that didn't seem to be proper (rust-lang/nomicon#358)
- Indicate that C reference are C reference (rust-lang/nomicon#357)
- Introduce and avoid dropck (rust-lang/nomicon#353)
- Rephrase improperly reduced borrows introduction (rust-lang/nomicon#352)
- Two lifetime clarification (rust-lang/nomicon#350)
- "UB" vs "Undefined Behavior" (rust-lang/nomicon#349)

## reference

9 commits in b5f6c2362baf932db9440fbfcb509b309237ee85..8e36971959ff238b5aa2575fbc7a2e09e1313e82
2022-04-10 19:19:51 -0700 to 2022-05-09 17:20:59 -0700
- Stop saying that const functions cannot use 'extern' (rust-lang/reference#1207)
- Moved the option variant imports (rust-lang/reference#1208)
- #[must_use] on traits also affects trait objects (rust-lang/reference#1203)
- Don't use PathPattern in RangePattern bounds (rust-lang/reference#1204)
- Inline assembly: Add kreg0 register class (rust-lang/reference#1205)
- Fix crate_type attribute examples (rust-lang/reference#1201)
- Say that that the default function return type is the unit type (rust-lang/reference#1199)
- Clarify guarantees provided by repr(packed) (rust-lang/reference#1163)
- Document the Termination trait for main() and test functions (rust-lang/reference#1194)

## book

43 commits in de0dbffc5812fd885700874e8d258dd334733ac4..d9415b7cbfcb4b24062683f429bd0ff535396362
2022-04-18 19:29:45 -0400 to 2022-05-09 09:10:44 -0400
- Update ch09-02-recoverable-errors-with-result.md
- Added missing be 2
- Added missing be
- Move hardcoded string into status_line to be consistent
- Fix trailing space
- Propagate tech review edits back to src
- Change "semantics" to "mechanics"; when referring to compiler behavior, rather than syntax.
- Propagate some edits to ch4 snapshot
- Suggestions from tech review
- Propagate edits to src
- Propagate edits back to nostarch version
- Clarify sentences about lock types. Fixes rust-lang/book#2937.
- Edits to edits to chapter 16
- Edits from nostarch for chapter 16
- Propagate nostarch edits back to src
- Add words to dictionary
- Propagating edits back to the nostarch snapshot
- Small wording change. Fixes rust-lang/book#3112.
- Clarify the kind of manual cleanup meant here
- Edits to edits to chapter 15
- Edits from nostarch
- Add missing word
- Improve sentence structure
- fix unidiomatic new functions in chapter 15
- Propagate nostarch ch14 to src
- Update a link and the -p publishing instructions
- Actually, I don't think we need to show the command output here
- Edits to edits to chapter 14
- Update manual regeneration instructions
- Reflect the addition of the -p flag in Cargo 1.56 in chapter 14
- Change polarity and names of variables in env var section
- Propagate nostarch edits back to ch 12
- Change environment variable and field name to perhaps be less confusing
- Responses to nostarch edits
- Merge remote-tracking branch 'origin/ch13'
- Fix rust-lang/book#3002 use noplayground with common.rs
- Propagate ch3 edits to src
- Updating chapter 3 to use new println style
- Specify loop label format. Fixes rust-lang/book#3105.
- Clarify function definition must be in an accessible scope. Fixes rust-lang/book#3003
- Addressing tech review comments, propagating other changes
- Comments from tech review
- Chapter 3, section 2 - Add explicit type annotation to example of scalar type char.

## rust-by-example

6 commits in 44a80e8d8bfc5881c9bd69a2cb3a570776ee4181..e9f93cfcf410bc092c9107b8a41a82f144c761f2
2022-04-19 07:46:28 -0300 to 2022-05-08 18:24:06 -0300
- Add empty slice example (rust-lang/rust-by-example#1538)
- Enhancement/print (rust-lang/rust-by-example#1536)
- Update cast.md (rust-lang/rust-by-example#1521)
- Update iter_any.md (rust-lang/rust-by-example#1522)
- Update tuples.md (rust-lang/rust-by-example#1524)
- fix indent in fs.md (rust-lang/rust-by-example#1535)

## rustc-dev-guide

8 commits in 043e60f4f191651e9f8bf52fa32df14defbb23d9..0c02acdb6f48f03907a02ea8e537c3272b4fde9f
2022-04-20 18:57:49 +0900 to 2022-05-10 09:45:31 -0300
- Update overview.md (rust-lang/rustc-dev-guide#1351)
- Update date references on parallel-rustc (rust-lang/rustc-dev-guide#1348)
- mention `WithOptConstParam` (rust-lang/rustc-dev-guide#1346)
- Fix format (rust-lang/rustc-dev-guide#1349)
- correct type of SubstsRef (rust-lang/rustc-dev-guide#1347)
- Document ErrorGuaranteed (rust-lang/rustc-dev-guide#1316)
- Edit "What the compiler does to your code" (rust-lang/rustc-dev-guide#1306)
- Update some date refs
2022-05-11 08:48:11 +00:00
Ralf Jung 831bd96967 rustc_log: add env var to set verbose entry/exit behavior 2022-05-11 09:14:31 +02:00
bors ee6eaabdd4 Auto merge of #96931 - JohnTitor:rollup-3um8o4j, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #96543 (Remove hacks in `make_token_stream`.)
 - #96887 (rustdoc: correct path to type alias methods)
 - #96896 (Add regression test for #68408)
 - #96900 (Fix js error)
 - #96903 (Use lifetimes on type-alias-impl-trait used in function signatures to infer output type lifetimes)
 - #96916 (simplify length count)
 - #96925 (Fix issue #95151)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-11 06:29:04 +00:00
Camille GILLOT 6cfe52c094 Gracefully fail to resolve associated items instead of delay_span_bug. 2022-05-11 08:28:02 +02:00
Eric Huss 7aa2b36bdc Update books 2022-05-10 22:27:45 -07:00
Dan Gohman 0a39e5ad36 Fix incorrect mentions of OwnedFd and BorrowedFd in Windows docs. 2022-05-10 21:56:51 -07:00
Sébastien Marie 42f8e1f879 to_timespec could be unused by some targets 2022-05-11 04:51:09 +00:00
Sébastien Marie 3cadc11d83 avoid using both Some() and ? on linux/android/freebsd code 2022-05-11 04:50:48 +00:00
Sébastien Marie f75d02d669 openbsd: convert futex timeout managment to Timespec usage 2022-05-11 04:50:23 +00:00
Dan Gohman 2bb7fdb8e1 Also document that as_raw_handle may return NULL. 2022-05-10 21:42:30 -07:00
Dan Gohman 4ce68c13bf Clarify what values BorrowedHandle, OwnedHandle etc. can hold.
Clarify that when `BorrowedHandle`, `OwnedHandle`, or `HandleOrNull`
hold the value `-1`, it always means the current process handle, and not
`INVALID_HANDLE_VALUE`.
2022-05-10 21:25:48 -07:00
Yuki Okushi 514b585757
Rollup merge of #96925 - c410-f3r:z-errors, r=JohnTitor
Fix issue #95151

Fixes  #95151

Nothing special here, just a test for a thing that used to ICE.
2022-05-11 13:16:35 +09:00
Yuki Okushi 304c116b40
Rollup merge of #96916 - matthiaskrgr:simpl_count, r=compiler-errors
simplify length count
2022-05-11 13:16:34 +09:00
Yuki Okushi 17a735b69a
Rollup merge of #96903 - oli-obk:opaque_type_lifetime_constraints, r=compiler-errors
Use lifetimes on type-alias-impl-trait used in function signatures to infer output type lifetimes

fixes https://github.com/rust-lang/rust/issues/96564

TLDR:

```rust
fn execute(ty: Ty<'_>) -> &str { todo!() }
```

(`Ty` being a type alias impl trait) used to produce the following error before this PR

```
error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
 --> src/lib.rs:4:27
  |
4 | fn execute(ty: Ty<'_>) -> &str { todo!() }
  |                           ^^^^
  |
  = note: lifetimes appearing in an associated type are not considered constrained
```
2022-05-11 13:16:34 +09:00
Yuki Okushi 95b2d37a39
Rollup merge of #96900 - GuillaumeGomez:fix-js-error, r=notriddle
Fix js error

On the source code pages, we get a JS error:

![Screenshot from 2022-05-10 16-26-53](https://user-images.githubusercontent.com/3050060/167656292-51e0b0e9-6b0c-4f94-82e0-dd8fb77adf52.png)

It's fixed in the first commit. The second one is removing an unused CSS rule and the third one is a little cleanup of a GUI test.

cc ``@jsha``
r? ``@notriddle``
2022-05-11 13:16:33 +09:00
Yuki Okushi 7bf795bc65
Rollup merge of #96896 - JohnTitor:issue-68408, r=compiler-errors
Add regression test for #68408

Closes https://github.com/rust-lang/rust/issues/68408
2022-05-11 13:16:32 +09:00
Yuki Okushi ed9faeedda
Rollup merge of #96887 - notriddle:notriddle/as-raw-fd, r=jsha
rustdoc: correct path to type alias methods

Fixes #83991
2022-05-11 13:16:31 +09:00
Yuki Okushi 81c0a2d96c
Rollup merge of #96543 - nnethercote:rm-make_token_stream-hacks, r=Aaron1011
Remove hacks in `make_token_stream`.

`make_tokenstream` has three commented hacks, and a comment at the top
referring to #67062. These hacks have no observable effect, at least as judged
by running the test suite. The hacks were added in #82608, with an explanation
[here](https://github.com/rust-lang/rust/pull/82608#issuecomment-812877329). It
appears that one of the following is true: (a) they never did anything useful,
(b) they do something useful but we have no test coverage for them, or (c)
something has changed in the meantime that means they are no longer necessary.

This commit removes the hacks and the comments, in the hope that (b) is not
true.

r? `@Aaron1011`
2022-05-11 13:16:30 +09:00