- 16 5月, 2021 5 次提交
-
-
由 hi-rustin 提交于
-
由 bors 提交于
Do not allocate or unwind after fork ### Objective scenarios * Make (simple) panics safe in `Command::pre_exec_hook`, including most `panic!` calls, `Option::unwrap`, and array bounds check failures. * Make it possible to `libc::fork` and then safely panic in the child (needed for the above, but this requirement means exposing the new raw hook API which the `Command` implementation needs). * In singlethreaded programs, where panic in `pre_exec_hook` is already memory-safe, prevent the double-unwinding malfunction #79740. I think we want to make panic after fork safe even though the post-fork child environment is only experienced by users of `unsafe`, beause the subset of Rust in which any panic is UB is really far too hazardous and unnatural. #### Approach * Provide a way for a program to, at runtime, switch to having panics abort. This makes it possible to panic without making *any* heap allocations, which is needed because on some platforms malloc is UB in a child forked from a multithreaded program (see https://github.com/rust-lang/rust/pull/80263#issuecomment-774272370, and maybe also the SuS [spec](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html)). * Make that change in the child spawned by `Command`. * Document the rules comprehensively enough that a programmer has a fighting chance of writing correct code. * Test that this all works as expected (and in particular, that there aren't any heap allocations we missed) Fixes #79740 #### Rejected (or previously attempted) approaches * Change the panic machinery to be able to unwind without allocating, at least when the payload and message are both `'static`. This seems like it would be even more subtle. Also that is a potentially-hot path which I don't want to mess with. * Change the existing panic hook mechanism to not convert the message to a `String` before calling the hook. This would be a surprising change for existing code and would not be detected by the type system. * Provide a `raw_panic_hook` function to intercept panics in a way that doesn't allocate. (That was an earlier version of this MR.) ### History This MR could be considered a v2 of #80263. Thanks to everyone who commented there. In particular, thanks to `@m-ou-se,` `@Mark-Simulacrum` and `@hyd-dev.` (Tagging you since I think you might be interested in this new MR.) Compared to #80263, this MR has very substantial changes and additions. Additionally, I have recently (2021-04-20) completely revised this series following very helpful comments from `@m-ou-se.` r? `@m-ou-se`
-
由 bors 提交于
Remove some unncessary spaces from pretty-printed tokenstream output In addition to making the output look nicer for all crates, this also aligns the pretty-printing output with what the `rental` crate expects. This will allow us to eventually disable a backwards-compat hack in a follow-up PR. See https://github.com/rust-lang/rust/issues/84428 for some background information about why we want to make this change. Note that this change would be desirable (but not particularly necessary) even if `rental` didn't exist, so we're not adding any crate-specific hacks into the compiler.
-
由 bors 提交于
Rollup of 4 pull requests Successful merges: - #84751 (str::is_char_boundary - slight optimization) - #85185 (Generate not more docs than necessary) - #85324 (Warn about unused `pub` fields in non-`pub` structs) - #85329 (fix version_str comment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
-
由 Aaron Hill 提交于
In addition to making the output look nicer for all crates, this also aligns the pretty-printing output with what the `rental` crate expects. This will allow us to eventually disable a backwards-compat hack in a follow-up PR.
-
- 15 5月, 2021 35 次提交
-
-
由 Guillaume Gomez 提交于
fix version_str comment This version string is ultimately generated here https://github.com/rust-lang/rust/blob/87423fbc6af5aae2b5f6d0a11f2a0c60c7c22e98/src/bootstrap/channel.rs#L72 and I don't think it includes the `rustc` prefix. That also matches its use here https://github.com/rust-lang/rust/blob/ac923d94f86a6f7c881ecbedcd0a68d7986a35bd/compiler/rustc_driver/src/lib.rs#L758
-
由 Guillaume Gomez 提交于
Warn about unused `pub` fields in non-`pub` structs This pull request fixes #85255. The current implementation of dead code analysis is too prudent because it marks all `pub` fields of structs as live, even though they cannot be accessed from outside of the current crate if the struct itself only has restricted or private visibility. I have changed this behavior to take the containing struct's visibility into account when looking at field visibility and liveness. This also makes dead code warnings more consistent; consider the example given in #85255: ```rust struct Foo { a: i32, pub b: i32, } struct Bar; impl Bar { fn a(&self) -> i32 { 5 } pub fn b(&self) -> i32 { 6 } } fn main() { let _ = Foo { a: 1, b: 2 }; let _ = Bar; } ``` Current nightly already warns about `Bar::b()`, even though it is `pub` (but `Bar` is not). It should therefore also warn about `Foo::b`, which it does with the changes in this PR.
-
由 Guillaume Gomez 提交于
Generate not more docs than necessary This is something that `@Nemo157` was talking about: they wanted that when using `x.py doc std`, it only generated `std` (and the crates "before" it). r? `@Mark-Simulacrum`
-
由 Guillaume Gomez 提交于
str::is_char_boundary - slight optimization Current `str::is_char_boundary` implementation emits slightly more instructions, because it includes an additional branch for `index == s.len()` ```rust pub fn is_char_boundary(s: &str, index: usize) -> bool { if index == 0 || index == s.len() { return true; } match s.as_bytes().get(index) { None => false, Some(&b) => (b as i8) >= -0x40, } } ``` Just changing the place of `index == s.len()` merges it with `index < s.len()` from `s.as_bytes().get(index)` ```rust pub fn is_char_boundary2(s: &str, index: usize) -> bool { if index == 0 { return true; } match s.as_bytes().get(index) { // For some reason, LLVM likes this comparison here more None => index == s.len(), // This is bit magic equivalent to: b < 128 || b >= 192 Some(&b) => (b as i8) >= -0x40, } } ``` This one has better codegen on every platform, except powerpc <details><summary>x86 codegen</summary> <p> ```nasm example::is_char_boundary: mov al, 1 test rdx, rdx je .LBB0_5 cmp rsi, rdx je .LBB0_5 cmp rsi, rdx jbe .LBB0_3 cmp byte ptr [rdi + rdx], -65 setg al .LBB0_5: ret .LBB0_3: xor eax, eax ret example::is_char_boundary2: test rdx, rdx je .LBB1_1 cmp rsi, rdx jbe .LBB1_4 cmp byte ptr [rdi + rdx], -65 setg al ret .LBB1_1: ; technically this branch is the same as LBB1_4 mov al, 1 ret .LBB1_4: sete al ret ``` </p> </details> <details><summary>aarch64 codegen</summary> <p> ```as example::is_char_boundary: mov x8, x0 mov w0, #1 cbz x2, .LBB0_4 cmp x1, x2 b.eq .LBB0_4 b.ls .LBB0_5 ldrsb w8, [x8, x2] cmn w8, #65 cset w0, gt .LBB0_4: ret .LBB0_5: mov w0, wzr ret example::is_char_boundary2: cbz x2, .LBB1_3 cmp x1, x2 b.ls .LBB1_4 ldrsb w8, [x0, x2] cmn w8, #65 cset w0, gt ret .LBB1_3: mov w0, #1 ret .LBB1_4: cset w0, eq ret ``` </p> </details> <details><summary>riscv64gc codegen</summary> <p> example::is_char_boundary: seqz a3, a2 xor a4, a1, a2 seqz a4, a4 or a4, a4, a3 addi a3, zero, 1 bnez a4, .LBB0_3 bgeu a2, a1, .LBB0_4 add a0, a0, a2 lb a0, 0(a0) addi a1, zero, -65 slt a3, a1, a0 .LBB0_3: mv a0, a3 ret .LBB0_4: mv a0, zero ret example::is_char_boundary2: beqz a2, .LBB1_3 bgeu a2, a1, .LBB1_4 add a0, a0, a2 lb a0, 0(a0) addi a1, zero, -65 slt a0, a1, a0 ret .LBB1_3: addi a0, zero, 1 ret .LBB1_4: xor a0, a1, a2 seqz a0, a0 ret </p> </details> [Link to godbolt](https://godbolt.org/z/K8avEz8Gr) `@rustbot` label: A-codegen
-
由 Guillaume Gomez 提交于
-
由 bors 提交于
Convert rustfmt from a submodule to a subtree r? `@calebcartwright` cc `@Manishearth` `@Mark-Simulacrum` The motivation is that submodule updates cause rustfmt to not be available on nightly a lot; most recently it was unavailable for over 10 days, causing the beta release to be delayed. Additionally this is much less work on the part of the rustfmt maintainers to keep the rustfmt compiling, since now people making breaking changes will be responsible for fixing them. I kept the rustfmt git history so it looks like there are thousands of commits. The important commits are https://github.com/rust-lang/rust/compare/851dee3af9404bf399c3c4ffefe5105edb3debad~..pull/82208/head. This adds about 10 MB of git history, which is not terribly much compared to the 702 MB that already exist. - Add `src/tools/rustfmt` to `x.py check` - Fix CRLF issues with rustfmt tests (see commit for details) - Use `rustc_private` instead of crates.io dependencies This was already switched upstream and would have landed in the next submodule bump anyway. This just updates Cargo.lock for rust-lang/rust. - Add `yansi-term` to the list of allowed dependencies. This is a false positive - rustc doesn't actually use it, only rustfmt, but because it's activated by the cargo feature of a dependency, tidy gets confused. It's fairly innocuous in any case, it's used for color printing. This would have happened in the next submodule bump. - Remove rustfmt from the list of toolstate tools. - Give a hard error if testing or building rustfmt fails. - Update log to 0.4.14 This avoids a warning about semicolons in macros; see the commit for details. - Don't add tools to the sysroot when they finish building. This is the only change that could be considered a regression - this avoids a "colliding StableCrateId" error due to a bug in resolve (https://github.com/rust-lang/rust/issues/56935). The regression is that this rebuilds dependencies more often than strictly necessary. See the commit for details. Fixes https://github.com/rust-lang/rust/issues/85226 (permanently). Closes https://github.com/rust-lang/rust/issues/82385. Helps with https://github.com/rust-lang/rust/issues/70651. Helps with https://github.com/rust-lang/rust/issues/80639.
-
由 bors 提交于
Rollup of 12 pull requests Successful merges: - #84461 (rustdoc: Remove unnecessary `StripItem` wrapper) - #85067 (Minimize amount of fake `DefId`s used in rustdoc) - #85207 (Fix typo in comment) - #85215 (coverage bug fixes and some refactoring) - #85221 (dbg macro: Discuss use in tests, and slightly clarify) - #85246 (Miner code formatting) - #85253 (swap function order for better read flow) - #85256 (Fix display for "implementors" section) - #85268 (Use my real name) - #85278 (Improve match statements) - #85289 (Fix toggle position on mobile) - #85323 (Fix eslint errors) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
-
由 Ralf Jung 提交于
-
由 Guillaume Gomez 提交于
Fix eslint errors I cherry-picked the two non-CI commits from #85285. r? ```@jsha```
-
由 Guillaume Gomez 提交于
Fix toggle position on mobile Before: ![Screenshot from 2021-05-14 14-21-27](https://user-images.githubusercontent.com/3050060/118276475-fe210300-b4c7-11eb-94f8-4e2a4e10d91e.png) ![Screenshot from 2021-05-14 14-21-30](https://user-images.githubusercontent.com/3050060/118276479-feb99980-b4c7-11eb-85db-40e9df6e9abd.png) After: ![Screenshot from 2021-05-14 15-16-54](https://user-images.githubusercontent.com/3050060/118276494-0416e400-b4c8-11eb-9479-d447928cfa62.png) ![Screenshot from 2021-05-14 15-16-59](https://user-images.githubusercontent.com/3050060/118276498-0416e400-b4c8-11eb-99f6-894276c62dfc.png) r? ```@jsha```
-
由 Guillaume Gomez 提交于
Improve match statements
-
由 Guillaume Gomez 提交于
Use my real name
-
由 Guillaume Gomez 提交于
Fix display for "implementors" section Just saw this problem when going through docs: ![Screenshot from 2021-05-13 15-20-52](https://user-images.githubusercontent.com/3050060/118131978-766fc180-b3ff-11eb-86a8-7f6d22afa675.png) This fix puts it back to normal: ![Screenshot from 2021-05-13 15-23-29](https://user-images.githubusercontent.com/3050060/118132006-7e2f6600-b3ff-11eb-9985-025a7b7c5216.png) You can see it on the `TryFrom` page for example. r? ```@Nemo157```
-
由 Guillaume Gomez 提交于
swap function order for better read flow I was reading this error message for the first time. I was a little bit confused when reading that part: ``` foo.bar(); // we can now use this method since i32 implements the Foo trait ``` At the time I was reading `// we can now use this method` I wasn't sure why. It only made sense when reading on. So swapping these parts results in a better read flow.
-
由 Guillaume Gomez 提交于
Miner code formatting
-
由 Guillaume Gomez 提交于
dbg macro: Discuss use in tests, and slightly clarify As discussed in a tangent in #82778. I chose to use [semantic newlines](https://rhodesmill.org/brandon/2012/one-sentence-per-line/) in the source text but I don't mind reformatting it.
-
由 Guillaume Gomez 提交于
coverage bug fixes and some refactoring This replaces the relevant commits (2 and 3) from PR #85082, and also corrects an error querying for coverageinfo. 1. `coverageinfo` query needs to use the same MIR as codegen I ran into an error trying to fix dead block coverage and realized the `coverageinfo` query is getting a different MIR compared to the codegenned MIR, which can sometimes be a problem during mapgen. I changed that query to use the `InstandeDef` (which includes the generic parameter substitutions, prosibly specific to const params) instead of the `DefId` (without unknown/default const substitutions). 2. Simplified body_span and filtered span code Some code cleanup extracted from future (but unfinished) commit to fix coverage in attr macro functions. 3. Spanview needs the relevant body_span used for coverage The coverage body_span doesn't always match the function body_span. r? ```@tmandry```
-
由 Guillaume Gomez 提交于
Fix typo in comment missing space in "rootseparator"
-
由 Guillaume Gomez 提交于
Minimize amount of fake `DefId`s used in rustdoc Follow up from #84707, which minimizes the amount of fake defids to the smallest amount possible. Every `FakeDefId` that is now used in the rustdoc library must be preserved and can not be replaced with a normal `DefId`.
-
由 Guillaume Gomez 提交于
rustdoc: Remove unnecessary `StripItem` wrapper
-
由 Justus K 提交于
-
由 Guillaume Gomez 提交于
-
由 Guillaume Gomez 提交于
-
由 Fabian Wolff 提交于
-
由 bors 提交于
Insignificant destructors rfc 2229 - Adds new attribute `rustc_insignificant_dtor` to annotate the drop method. - Adds a query to check if a type has a significant drop. - Updates closure analysis to check for significant drops rather than just drop. A type marked with the attribute `rustc_insignificant_dtor` is considered to not be significant. A drop is significant if it is implemented by the user or does anything that will have any observable behavior (other than freeing up memory). https://github.com/rust-lang/project-rfc-2229/issues/35
-
由 bors 提交于
Box `Impl.blanket_impl` to reduce size Blanket impls are probably not super common, and `Type` is a fairly large type, so this should reduce `Impl`'s size by a lot: `Option<Type>` is around 96 bytes, and `Option<Box<Type>>` is 8 bytes, so it's a big difference!
-
由 bors 提交于
Error out if a PR is sent to the wrong channel It happened multiple times that a PR meant to go on beta ends up being opened (and occasionally merged) to master. This PR does two things: * Moves the definition of the channel in `src/ci/channel` so it's easier for tools to read it. I was not sure whether to move it to `src/channel` (like `src/version`): ended up with `src/ci` as it's currently only used for CI, but I'm open to moving it to `src`. We'll need to update the release process after this. * Adds a check on **non-bors** builds that errors out if the base branch is not the expected one for the currently defined channel. This will not cause problems for promotion PRs, as those PRs are meant to also update the channel name. r? `@Mark-Simulacrum`
-
由 Dhruv Jauhar 提交于
-
由 Caleb Cartwright 提交于
-
由 Joshua Nelson 提交于
The previous commit could be part of the current PR.
-
由 Joshua Nelson 提交于
Previously, this would be caught by a change for modified submodules; now that rustfmt is no longer a submodule, the check needs to be explicit.
-
由 Joshua Nelson 提交于
This avoids the following warning: ``` warning: trailing semicolon in macro used in expression position --> /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.11/src/macros.rs:152:45 | 147 | / macro_rules! debug { 148 | | (target: $target:expr, $($arg:tt)+) => ( 149 | | log!(target: $target, $crate::Level::Debug, $($arg)+); 150 | | ); 151 | | ($($arg:tt)+) => ( 152 | | log!($crate::Level::Debug, $($arg)+); | | ^ 153 | | ) 154 | | } | |_- in this expansion of `debug!` | ::: src/tools/rustfmt/src/modules/visitor.rs:36:23 | 36 | Err(e) => debug!("{}", e), | --------------- in this macro invocation | = note: requested on the command line with `-W semicolon-in-expressions-from-macros` = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813> ```
-
由 Joshua Nelson 提交于
This fixes the following error: ``` error: found crates (`serde_derive` and `serde_derive`) with colliding StableCrateId values. --> /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/cargo_metadata-0.8.2/src/lib.rs:162:1 | 162 | extern crate serde_derive; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` This is a bug in resolve (https://github.com/rust-lang/rust/issues/56935) but it will be difficult to fix in the near future. This works around it in the meantime by not copying serde_derive and other dependencies to the sysroot when they're built for other tools. This rebuilds the dependencies slightly more often than necessary, but avoids the crate conflicts. This can be reverted once #56935 is fixed.
-
由 Joshua Nelson 提交于
- Add rustfmt to `x.py check` - Update Cargo.lock - Remove rustfmt from the toolstate list - Make rustfmt an in-tree tool - Give an error on `x.py test rustfmt` if rustfmt fails to build or if tests fail - Don't call `save_toolstate` when testing rustfmt
-
由 Caleb Cartwright 提交于
git-subtree-dir: src/tools/rustfmt git-subtree-mainline: e659b6de git-subtree-split: 7872306e
-