about summary refs log tree commit diff
path: root/src
AgeCommit message (Collapse)AuthorLines
2022-02-22Stabilize Termination and ExitCodeJane Lusby-2/+0
2022-02-16Rollup merge of #94054 - lnicola:rust-analyzer-2022-02-16, r=lnicolaMatthias Krüger-22/+16
:arrow_up: rust-analyzer r? ``@ghost``
2022-02-16Rollup merge of #94045 - ehuss:update-books, r=ehussMatthias Krüger-0/+0
Update books ## nomicon 3 commits in 9493715a6280a1f74be759c7e1ef9999b5d13e6f..90993eeac93dbf9388992de92965f99cf6f29a03 2022-01-27 19:00:32 -0800 to 2022-02-13 12:44:12 +0900 - Fix a small typo in exception-safety.md (rust-lang/nomicon#341) - Make `Vec::new` public in vec-alloc.md (rust-lang/nomicon#336) - Fix a syntax error in leaking.md (rust-lang/nomicon#335) ## reference 6 commits in 411c2f0d5cebf48453ae2d136ad0c5e611d39aec..70fc73a6b908e08e66aa0306856c5211312f6c05 2022-01-30 12:46:37 -0800 to 2022-02-14 19:33:01 -0800 - Document pre-Rust-2021 special case for IntoIterator method lookup (rust-lang/reference#1154) - Mention std::is_aarch64_feature_detected (rust-lang/reference#1061) - Fix link to the Bastion of the Turbofish (rust-lang/reference#1161) - Improve associated constant item CTFE timing section (rust-lang/reference#1147) - document `#![feature(const_generics_defaults)]` (rust-lang/reference#1098) - Update patterns allowed in @ patterns (rust-lang/reference#1158) ## book 6 commits in 98904efaa4fc968db8ff59cf2744d9f7ed158166..67b768c0b660a069a45f0e5d8ae2f679df1022ab 2022-01-29 21:22:31 -0500 to 2022-02-09 21:52:41 -0500 - Snapshot of ch18 for nostarch - Remove mention of destructuring references as that's not covered currently - Add note that exhaustiveness checking doesn't extend to match guards - Change match guard example to actually be unexpressable with patterns alone - Corrected listing number from 9-10 to 9-13 - Remove duplicate paragraph after No Starch related changes ## rustc-dev-guide 3 commits in 8763adb62c712df69b1d39ea3e692b6d696cc4d9..62f58394ba7b203f55ac35ddcc4c0b79578f5706 2022-01-26 14:01:40 -0800 to 2022-02-11 08:42:50 -0500 - Correction, building stage3 compiler (rust-lang/rustc-dev-guide#1298) - Triage some date references (rust-lang/rustc-dev-guide#1293) - mention test folders for cfg(bootstrap) (rust-lang/rustc-dev-guide#1294)
2022-02-16Rollup merge of #94037 - tmiasko:verbose, r=Mark-SimulacrumMatthias Krüger-8/+23
Fix inconsistent symbol mangling with -Zverbose Always skip arguments that are the defaults of their respective parameters, to avoid generating inconsistent symbols for builds with `-Zverbose` flag and without it.
2022-02-16Rollup merge of #94027 - GuillaumeGomez:update-browser-ui-test, r=notriddleMatthias Krüger-2/+2
Update browser UI test version Might help a bit with https://github.com/rust-lang/rust/issues/93784 (still need to figure out what's going on with the driver). r? ```@notriddle```
2022-02-16Rollup merge of #94020 - tmiasko:pp, r=oli-obkMatthias Krüger-0/+72
Support pretty printing of invalid constants Make it possible to pretty print invalid constants by introducing a fallible variant of `destructure_const` and falling back to debug formatting when it fails. Closes #93688.
2022-02-16Rollup merge of #94015 - GuillaumeGomez:check-option, r=notriddleMatthias Krüger-1/+14
rustdoc --check option documentation Part of #92763. r? ```@notriddle```
2022-02-16Rollup merge of #93382 - GuillaumeGomez:search-input-padding, r=jshaMatthias Krüger-1/+1
Add a bit more padding in search box As asked in https://github.com/rust-lang/rust/pull/93113#issuecomment-1021565703, here is a bit more padding. You can check it [here](https://rustdoc.crud.net/imperio/search-input-padding/foo/index.html). r? `@camelid`
2022-02-16:arrow_up: rust-analyzerLaurențiu Nicola-22/+16
2022-02-16Auto merge of #94044 - ehuss:update-cargo, r=ehussbors-0/+0
Update cargo 5 commits in c082648646cbb2be266df9ecbcdc253058158d68..ea2a21c994ca1e4d4c49412827b3cf4dcb158b1d 2022-02-08 14:55:05 +0000 to 2022-02-15 04:24:07 +0000 - cargo-new should not add ignore rule on Cargo.lock inside subdirs (rust-lang/cargo#10379) - Add a badge for github actions (rust-lang/cargo#10385) - Remove outdated badges (rust-lang/cargo#10380) - Remove `strip = "off"` (and undocumented `strip = "n"`/`strip = "no"`) (rust-lang/cargo#10376) - Fix unmatched backticks (rust-lang/cargo#10375)
2022-02-15Update cargoEric Huss-0/+0
2022-02-15Update booksEric Huss-0/+0
2022-02-16Auto merge of #93800 - b-naber:static-initializers-mir-val, r=oli-obkbors-43/+6
Treat static refs as `mir::ConstantKind::Val` With the upcoming introduction of Valtrees we want to treat more values as `mir::ConstantKind::Val` directly. r? `@lcnr` cc `@oli-obk`
2022-02-16Fix inconsistent symbol mangling with -ZverboseTomasz Miąsko-8/+23
Always skip arguments that are the defaults of their respective parameters, to avoid generating inconsistent symbols for builds with `-Zverbose` flag and without it.
2022-02-16Support pretty printing of invalid constantsTomasz Miąsko-0/+72
Make it possible to pretty print invalid constants by introducing a fallible variant of `destructure_const` and falling back to debug formatting when it fails.
2022-02-15try to bless 32bit mir tests manuallyb-naber-11/+2
2022-02-15Auto merge of #93439 - abrown:cf-protection, r=nagisabors-0/+78
Add support for control-flow protection This change adds a flag for configuring control-flow protection in the LLVM backend. In Clang, this flag is exposed as `-fcf-protection` with options `none|branch|return|full`. This convention is followed for `rustc`, though as a codegen option: `rustc -Z cf-protection=<none|branch|return|full>`. Tracking issue for future work is #93754.
2022-02-15Add documentation for rustdoc --check optionGuillaume Gomez-0/+11
2022-02-15Fix GUI testGuillaume Gomez-1/+1
2022-02-15Update browser-ui-test versionGuillaume Gomez-1/+1
2022-02-15bless mir-opt testsb-naber-4/+147
2022-02-15bless testsb-naber-179/+8
2022-02-15Auto merge of #93820 - compiler-errors:gat-wfcheck, r=jackh726bors-4/+34
Rework GAT `where` clause check rework the GAT where check to use a fixed-point algorithm, and check all GATs in a trait at once fixes #93278 r? `@jackh726` cc `@nikomatsakis`
2022-02-15Add removed comments back in self-outlives-lintMichael Goulet-15/+18
2022-02-15add test for issue-93278, blessMichael Goulet-17/+44
2022-02-15Rollup merge of #94014 - flip1995:clippy_transmute_lint_regroup, r=dtolnayMatthias Krüger-3/+2
Move transmute_undefined_repr back to nursery There's still open discussion if this lint is ready to be enabled by default. We want to give us more time to figure this out and prevent this lint from getting to stable as an enabled-by-default lint. cc https://github.com/rust-lang/rust-clippy/pull/8432 r? `@Manishearth` `@dtolnay` I think this is the way to go here. We can re-enable this lint with the next sync, if we should decide to do so. But I would hold of for this release. We have until Friday (beta branching) to decide if we want to merge this.
2022-02-15Rollup merge of #93999 - barzamin:suggest-raw-strings, r=jackh726Matthias Krüger-0/+29
suggest using raw strings when invalid escapes appear in literals i'd guess about 70% of "bad escape" cases occur when someone meant to use a raw string literal because they're passing it directly to `Regex::new()`. this emits an advisory (`Applicability::MaybeIncorrect`) `help:` suggestion to the user that they use an `r""` string, on top of the normal notes about looking at the string literal documentation/spec.
2022-02-15Auto merge of #93148 - nnethercote:Uniq, r=fee1-deadbors-108/+109
Overhaul interning. A number of types are interned and `eq` and `hash` are implemented on the pointer rather than the contents. But this is not well enforced within the type system like you might expect. This PR introduces a new type `Interned` which encapsulates this concept more rigorously, and uses it to convert a couple of the less common interned types. r? `@fee1-dead`
2022-02-15Clean up rustdoc command line args docGuillaume Gomez-1/+3
2022-02-15Move transmute_undefined_repr back to nurseryflip1995-3/+2
There's still open discussion if this lint is ready to be enabled by default. We want to give us more time to figure this out and prevent this lint from getting to stable as an enabled-by-default lint.
2022-02-15Auto merge of #93176 - danielhenrymantilla:stack-pinning-macro, r=m-ou-sebors-0/+117
Add a stack-`pin!`-ning macro to `core::pin`. - https://github.com/rust-lang/rust/issues/93178 `pin!` allows pinning a value to the stack. Thanks to being implemented in the stdlib, which gives access to `macro` macros, and to the private `.pointer` field of the `Pin` wrapper, [it was recently discovered](https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async-foundations/topic/pin!.20.E2.80.94.20the.20.22definitive.22.20edition.20.28a.20rhs-compatible.20pin-nin.2E.2E.2E/near/268731241) ([archive link](https://zulip-archive.rust-lang.org/stream/187312-wg-async-foundations/topic/A.20rhs-compatible.20pin-ning.20macro.html#268731241)), contrary to popular belief, that it is actually possible to implement and feature such a macro: ```rust let foo: Pin<&mut PhantomPinned> = pin!(PhantomPinned); stuff(foo); ``` or, directly: ```rust stuff(pin!(PhantomPinned)); ``` - For context, historically, this used to require one of the two following syntaxes: - ```rust let foo = PhantomPinned; pin!(foo); stuff(foo); ``` - ```rust pin! { let foo = PhantomPinned; } stuff(foo); ``` This macro thus allows, for instance, doing things like: ```diff fn block_on<T>(fut: impl Future<Output = T>) -> T { // Pin the future so it can be polled. - let mut fut = Box::pin(fut); + let mut fut = pin!(fut); // Create a new context to be passed to the future. let t = thread::current(); let waker = Arc::new(ThreadWaker(t)).into(); let mut cx = Context::from_waker(&waker); // Run the future to completion. loop { match fut.as_mut().poll(&mut cx) { Poll::Ready(res) => return res, Poll::Pending => thread::park(), } } } ``` - _c.f._, https://doc.rust-lang.org/1.58.1/alloc/task/trait.Wake.html And so on, and so forth. I don't think such an API can get better than that, barring full featured language support (`&pin` references or something), so I see no reason not to start experimenting with featuring this in the stdlib already 🙂 - cc `@rust-lang/wg-async-foundations` \[EDIT: this doesn't seem to have pinged anybody 😩, thanks `@yoshuawuyts` for the real ping\] r? `@joshtriplett` ___ # Docs preview https://user-images.githubusercontent.com/9920355/150605731-1f45c2eb-c9b0-4ce3-b17f-2784fb75786e.mp4 ___ # Implementation The implementation ends up being dead simple (so much it's embarrassing): ```rust pub macro pin($value:expr $(,)?) { Pin { pointer: &mut { $value } } } ``` _and voilà_! - The key for it working lies in [the rules governing the scope of anonymous temporaries](https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension). <details><summary>Comments and context</summary> This is `Pin::new_unchecked(&mut { $value })`, so, for starters, let's review such a hypothetical macro (that any user-code could define): ```rust macro_rules! pin {( $value:expr ) => ( match &mut { $value } { at_value => unsafe { // Do not wrap `$value` in an `unsafe` block. $crate::pin::Pin::<&mut _>::new_unchecked(at_value) }} )} ``` Safety: - `type P = &mut _`. There are thus no pathological `Deref{,Mut}` impls that would break `Pin`'s invariants. - `{ $value }` is braced, making it a _block expression_, thus **moving** the given `$value`, and making it _become an **anonymous** temporary_. By virtue of being anonynomous, it can no longer be accessed, thus preventing any attemps to `mem::replace` it or `mem::forget` it, _etc._ This gives us a `pin!` definition that is sound, and which works, but only in certain scenarios: - If the `pin!(value)` expression is _directly_ fed to a function call: `let poll = pin!(fut).poll(cx);` - If the `pin!(value)` expression is part of a scrutinee: ```rust match pin!(fut) { pinned_fut => { pinned_fut.as_mut().poll(...); pinned_fut.as_mut().poll(...); }} // <- `fut` is dropped here. ``` Alas, it doesn't work for the more straight-forward use-case: `let` bindings. ```rust let pinned_fut = pin!(fut); // <- temporary value is freed at the end of this statement pinned_fut.poll(...) // error[E0716]: temporary value dropped while borrowed // note: consider using a `let` binding to create a longer lived value ``` - Issues such as this one are the ones motivating https://github.com/rust-lang/rfcs/pull/66 This makes such a macro incredibly unergonomic in practice, and the reason most macros out there had to take the path of being a statement/binding macro (_e.g._, `pin!(future);`) instead of featuring the more intuitive ergonomics of an expression macro. Luckily, there is a way to avoid the problem. Indeed, the problem stems from the fact that a temporary is dropped at the end of its enclosing statement when it is part of the parameters given to function call, which has precisely been the case with our `Pin::new_unchecked()`! For instance, ```rust let p = Pin::new_unchecked(&mut <temporary>); ``` becomes: ```rust let p = { let mut anon = <temporary>; &mut anon }; ``` However, when using a literal braced struct to construct the value, references to temporaries can then be taken. This makes Rust change the lifespan of such temporaries so that they are, instead, dropped _at the end of the enscoping block_. For instance, ```rust let p = Pin { pointer: &mut <temporary> }; ``` becomes: ```rust let mut anon = <temporary>; let p = Pin { pointer: &mut anon }; ``` which is *exactly* what we want. Finally, we don't hit problems _w.r.t._ the privacy of the `pointer` field, or the unqualified `Pin` name, thanks to `decl_macro`s being _fully_ hygienic (`def_site` hygiene). </details> ___ # TODO - [x] Add compile-fail tests with attempts to break the `Pin` invariants thanks to the macro (_e.g._, try to access the private `.pointer` field, or see what happens if such a pin is used outside its enscoping scope (borrow error)); - [ ] Follow-up stuff: - [ ] Try to experiment with adding `pin!` to the prelude: this may require to be handled with some extra care, as it may lead to issues reminiscent of those of `assert_matches!`: https://github.com/rust-lang/rust/issues/82913 - [x] Create the tracking issue.
2022-02-15Auto merge of #93918 - jonhoo:bootstrap-native-envflags, r=Mark-Simulacrumbors-31/+66
bootstrap: tidy up flag handling for llvm build This tidies up the logic in `src/bootstrap/native.rs` such that: - `CMAKE_*_LINKER_FLAGS` is not overridden if we add to it twice. - `CMAKE_*_FLAGS` also include the standard `*FLAGS` environment variables, which CMake respects when we _don't_ set `CMAKE_*_FLAGS`. - `llvm.ldflags` from `config.toml` appends to the ldflags Rust's bootstrap logic adds, rather than replacing them. It also takes a second stab at #89983 by moving `-static-libstdc++` to just be passed as a linker flag, since that's what it is. Fixes #93880. Fixes #70468. Closes #89983.
2022-02-15Overhaul `Const`.Nicholas Nethercote-18/+18
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as this: ``` pub struct Const<'tcx>(&'tcx Interned<ConstS>); ``` This now matches `Ty` and `Predicate` more closely, including using pointer-based `eq` and `hash`. Notable changes: - `mk_const` now takes a `ConstS`. - `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a we need separate arena for it, because we can't use the `Dropless` one any more. - Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes - Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes. - Lots of tedious sigil fiddling.
2022-02-15Overhaul `RegionKind` and `Region`.Nicholas Nethercote-12/+12
Specifically, change `Region` from this: ``` pub type Region<'tcx> = &'tcx RegionKind; ``` to this: ``` pub struct Region<'tcx>(&'tcx Interned<RegionKind>); ``` This now matches `Ty` and `Predicate` more closely. Things to note - Regions have always been interned, but we haven't been using pointer-based `Eq` and `Hash`. This is now happening. - I chose to impl `Deref` for `Region` because it makes pattern matching a lot nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`. - Various methods are moved from `RegionKind` to `Region`. - There is a lot of tedious sigil changes. - A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`. - A couple of test outputs change slightly, I'm not sure why, but the new outputs are a little better.
2022-02-15Overhaul `TyS` and `Ty`.Nicholas Nethercote-78/+79
Specifically, change `Ty` from this: ``` pub type Ty<'tcx> = &'tcx TyS<'tcx>; ``` to this ``` pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>); ``` There are two benefits to this. - It's now a first class type, so we can define methods on it. This means we can move a lot of methods away from `TyS`, leaving `TyS` as a barely-used type, which is appropriate given that it's not meant to be used directly. - The uniqueness requirement is now explicit, via the `Interned` type. E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather than via `TyS`, which wasn't obvious at all. Much of this commit is boring churn. The interesting changes are in these files: - compiler/rustc_middle/src/arena.rs - compiler/rustc_middle/src/mir/visit.rs - compiler/rustc_middle/src/ty/context.rs - compiler/rustc_middle/src/ty/mod.rs Specifically: - Most mentions of `TyS` are removed. It's very much a dumb struct now; `Ty` has all the smarts. - `TyS` now has `crate` visibility instead of `pub`. - `TyS::make_for_test` is removed in favour of the static `BOOL_TY`, which just works better with the new structure. - The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned` (pointer-based, for the `Equal` case) and partly on `TyS` (contents-based, for the other cases). - There are many tedious sigil adjustments, i.e. adding or removing `*` or `&`. They seem to be unavoidable.
2022-02-15Auto merge of #93863 - pierwill:fix-93676, r=Mark-Simulacrumbors-2/+3
Update `sha1`, `sha2`, and `md-5` dependencies This replaces the deprecated [`cpuid-bool`](https://crates.io/crates/cpuid-bool) dependency with [`cpufeatures`](https://crates.io/crates/cpufeatures), while adding [`crypto-common`](https://crates.io/crates/crypto-common) as a new dependency. Closes #93676.
2022-02-15Auto merge of #93752 - eholk:drop-tracking-break-continue, r=nikomatsakisbors-0/+19
Generator drop tracking: improve break and continue handling This PR fixes two related issues. One, sometimes break or continue have a block target instead of an expression target. This seems to mainly happen with try blocks. Since the drop tracking analysis only works on expressions, if we see a block target for break or continue, we substitute the last expression of the block as the target instead. Two, break and continue were incorrectly being treated as the same, so continue would also show up as an exit from the loop or block. This patch corrects the way continue is handled by keeping a stack of loop entry points and uses those to find the target of the continue. Fixes #93197 r? `@nikomatsakis`
2022-02-14suggest using raw string literals when invalid escapes appearErin Petra Sofiya Moon-0/+29
i'd guess about 70% of "bad escape" cases occur when someone meant to use a raw string literal because they're passing it directly to Regex::new(). this emits an advisory (Applicability::MaybeIncorrect) help: suggestion to the user that they use an r"" string, on top of the normal notes about looking at the string literal documentation/spec.
2022-02-14Auto merge of #93652 - spastorino:fix-negative-overlap-check-regions, ↵bors-6/+48
r=nikomatsakis Fix negative overlap check regions r? `@nikomatsakis`
2022-02-14Add support for control-flow protectionAndrew Brown-0/+78
This change adds a flag for configuring control-flow protection in the LLVM backend. In Clang, this flag is exposed as `-fcf-protection` with options `none|branch|return|full`. This convention is followed for `rustc`, though as a codegen option: `rustc -Z cf-protection=<none|branch|return|full>`. Co-authored-by: BlackHoleFox <blackholefoxdev@gmail.com>
2022-02-14Mark `unsafe_pin_internals` as `incomplete`.Daniel Henry-Mantilla-0/+31
This thus still makes it technically possible to enable the feature, and thus to trigger UB without `unsafe`, but this is fine since incomplete features are known to be potentially unsound (labelled "may not be safe"). This follows from the discussion at https://github.com/rust-lang/rust/pull/93176#discussion_r799413561
2022-02-14Add failing test that should passSantiago Pastorino-0/+23
2022-02-14Update `macro:print` typed-query rustdoc test to include `pin!` resultsDaniel Henry-Mantilla-0/+2
2022-02-14Write {ui,} tests for `pin_macro` and `pin!`Daniel Henry-Mantilla-0/+84
2022-02-14Properly check regions on negative overlap checkSantiago Pastorino-6/+25
2022-02-14Auto merge of #93298 - lcnr:issue-92113, r=cjgillotbors-4/+74
make `find_similar_impl_candidates` even fuzzier continues the good work of `@BGR360` in #92223. I might have overshot a bit and we're now slightly too fuzzy :sweat_smile: with this we can now also simplify `simplify_type`, which is nice :3
2022-02-14Auto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnrbors-11/+11
Make `Res::SelfTy` a struct variant and update docs I found pattern matching on a `(Option<DefId>, Option<(DefId, bool)>)` to not be super readable, additionally the doc comments on the types in a tuple variant aren't visible anywhere at use sites as far as I can tell (using rust analyzer + vscode) The docs incorrectly assumed that the `DefId` in `Option<(DefId, bool)>` would only ever be for an impl item and I also found the code examples to be somewhat unclear about which `DefId` was being talked about. r? `@lcnr` since you reviewed the last PR changing these docs
2022-02-14update two rustdoc commentsEllen-3/+3
2022-02-14further update `fuzzy_match_tys`lcnr-31/+58
2022-02-14fuzzify `fuzzy_match_tys`lcnr-18/+30