From d8ef340d997a0f9d29f2372eda95a9d11bb0fcb8 Mon Sep 17 00:00:00 2001 From: Sam Robinson-Adams Date: Wed, 18 May 2022 15:10:18 +0100 Subject: [PATCH 1/6] Fix rusty grammar in `std::error::Reporter` docs I initially saw "print's" instead of "prints" at the start of the doc comment for `std::error::Reporter`, while reading the docs for that type. Then I figured 'probably more where that came from', so, as well as correcting the foregoing to "prints", I've patched up these three minor solecisms (well, two [types](https://en.wikipedia.org/wiki/Type%E2%80%93token_distinction), three [tokens](https://en.wikipedia.org/wiki/Type%E2%80%93token_distinction)): - One use of the indicative which should be subjunctive - indeed the sentence immediately following it, which mirrors its structure, _does_ use the subjunctive ([L871](https://github.com/rust-lang/rust/blob/master/library/std/src/error.rs?plain=1#L871)). Replaced with the subjunctive. - Two separate clauses joined with commas ([L975](https://github.com/rust-lang/rust/blob/master/library/std/src/error.rs?plain=1#L975), [L1023](https://github.com/rust-lang/rust/blob/master/library/std/src/error.rs?plain=1#L1023)). Replaced the first with a semicolon and the second with a period. Admittedly those judgements are pretty much 100% subjective, based on my sense of how the sentences flowed into each other (though ofc the _replacement of the comma itself_ is not subjective or opinion-based). I know this is silly and finicky, but I hope it helps tidy up the docs a bit for future readers! --- library/std/src/error.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/std/src/error.rs b/library/std/src/error.rs index 361163d197005..438304e1664cb 100644 --- a/library/std/src/error.rs +++ b/library/std/src/error.rs @@ -863,12 +863,12 @@ impl dyn Error + Send + Sync { } } -/// An error reporter that print's an error and its sources. +/// An error reporter that prints an error and its sources. /// /// Report also exposes configuration options for formatting the error chain, either entirely on a /// single line, or in multi-line format with each cause in the error chain on a new line. /// -/// `Report` only requires that the wrapped error implements `Error`. It doesn't require that the +/// `Report` only requires that the wrapped error implement `Error`. It doesn't require that the /// wrapped error be `Send`, `Sync`, or `'static`. /// /// # Examples @@ -972,7 +972,7 @@ impl dyn Error + Send + Sync { /// /// ## Return from `main` /// -/// `Report` also implements `From` for all types that implement [`Error`], this when combined with +/// `Report` also implements `From` for all types that implement [`Error`]; this when combined with /// the `Debug` output means `Report` is an ideal starting place for formatting errors returned /// from `main`. /// @@ -1020,7 +1020,7 @@ impl dyn Error + Send + Sync { /// ``` /// /// **Note**: `Report`s constructed via `?` and `From` will be configured to use the single line -/// output format, if you want to make sure your `Report`s are pretty printed and include backtrace +/// output format. If you want to make sure your `Report`s are pretty printed and include backtrace /// you will need to manually convert and enable those flags. /// /// ```should_panic From 83abb7c18f999617d08f8b715f0c7256b3f09e7c Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 20 May 2022 11:16:30 -0700 Subject: [PATCH 2/6] Fix `Display` for `cell::{Ref,RefMut}` These guards changed to pointers in #97027, but their `Display` was formatting that field directly, which made it show the raw pointer value. Now we go through `Deref` to display the real value again. --- library/core/src/cell.rs | 4 ++-- library/core/tests/cell.rs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 5448ced803a09..9884b7f404e3d 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -1487,7 +1487,7 @@ impl<'b, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized> for Ref<'b, #[stable(feature = "std_guard_impls", since = "1.20.0")] impl fmt::Display for Ref<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.value.fmt(f) + (**self).fmt(f) } } @@ -1735,7 +1735,7 @@ impl<'b, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized> for RefM #[stable(feature = "std_guard_impls", since = "1.20.0")] impl fmt::Display for RefMut<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.value.fmt(f) + (**self).fmt(f) } } diff --git a/library/core/tests/cell.rs b/library/core/tests/cell.rs index f15e03076caf7..7b77b2134ccd7 100644 --- a/library/core/tests/cell.rs +++ b/library/core/tests/cell.rs @@ -73,11 +73,13 @@ fn ref_and_refmut_have_sensible_show() { let refcell = RefCell::new("foo"); let refcell_refmut = refcell.borrow_mut(); - assert!(format!("{refcell_refmut:?}").contains("foo")); + assert_eq!(format!("{refcell_refmut}"), "foo"); // Display + assert!(format!("{refcell_refmut:?}").contains("foo")); // Debug drop(refcell_refmut); let refcell_ref = refcell.borrow(); - assert!(format!("{refcell_ref:?}").contains("foo")); + assert_eq!(format!("{refcell_ref}"), "foo"); // Display + assert!(format!("{refcell_ref:?}").contains("foo")); // Debug drop(refcell_ref); } From 88126034a41916e24c027af98606af768df5b5a4 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 20 May 2022 12:25:05 -0700 Subject: [PATCH 3/6] Omit stdarch workspace from rust-src The path `library/stdarch/crates/Cargo.toml` does not exist. This was introduced in #94907. --- src/bootstrap/dist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 16727f4398dff..f7b885a5063d3 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -814,7 +814,7 @@ impl Step for Src { "library/backtrace/crates", // these are 30MB combined and aren't necessary for building // the standard library. - "library/stdarch/crates/Cargo.toml", + "library/stdarch/Cargo.toml", "library/stdarch/crates/stdarch-verify", "library/stdarch/crates/intrinsic-test", ], From 075429f76b51b7dcc1875319412d1290fe263976 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 21 May 2022 00:18:50 +0200 Subject: [PATCH 4/6] Recover when resolution did not resolve lifetimes. --- compiler/rustc_ast_lowering/src/lib.rs | 20 ++++++------- src/test/ui/lifetimes/issue-97193.rs | 9 ++++++ src/test/ui/lifetimes/issue-97193.stderr | 28 ++++++++++++++++++ src/test/ui/lifetimes/issue-97194.rs | 10 +++++++ src/test/ui/lifetimes/issue-97194.stderr | 36 ++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 src/test/ui/lifetimes/issue-97193.rs create mode 100644 src/test/ui/lifetimes/issue-97193.stderr create mode 100644 src/test/ui/lifetimes/issue-97194.rs create mode 100644 src/test/ui/lifetimes/issue-97194.stderr diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index c143266f6c1de..b76e3c4bd469e 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1169,15 +1169,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)), TyKind::Rptr(ref region, ref mt) => { let region = region.unwrap_or_else(|| { - let Some(LifetimeRes::ElidedAnchor { start, end }) = self.resolver.get_lifetime_res(t.id) else { - panic!() + let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) = + self.resolver.get_lifetime_res(t.id) + { + debug_assert_eq!(start.plus(1), end); + start + } else { + self.resolver.next_node_id() }; - debug_assert_eq!(start.plus(1), end); let span = self.sess.source_map().next_point(t.span.shrink_to_lo()); - Lifetime { - ident: Ident::new(kw::UnderscoreLifetime, span), - id: start, - } + Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id } }); let lifetime = self.lower_lifetime(®ion); hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx)) @@ -1836,10 +1837,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime { let span = self.lower_span(l.ident.span); let ident = self.lower_ident(l.ident); - let res = self - .resolver - .get_lifetime_res(l.id) - .unwrap_or_else(|| panic!("Missing resolution for lifetime {:?} at {:?}", l, span)); + let res = self.resolver.get_lifetime_res(l.id).unwrap_or(LifetimeRes::Error); self.new_named_lifetime_with_res(l.id, span, ident, res) } diff --git a/src/test/ui/lifetimes/issue-97193.rs b/src/test/ui/lifetimes/issue-97193.rs new file mode 100644 index 0000000000000..6c82c29dd9d48 --- /dev/null +++ b/src/test/ui/lifetimes/issue-97193.rs @@ -0,0 +1,9 @@ +extern "C" { + fn a(&mut self) { + //~^ ERROR incorrect function inside `extern` block + //~| ERROR `self` parameter is only allowed in associated functions + fn b(buf: &Self) {} + } +} + +fn main() {} diff --git a/src/test/ui/lifetimes/issue-97193.stderr b/src/test/ui/lifetimes/issue-97193.stderr new file mode 100644 index 0000000000000..21be543ccf9ce --- /dev/null +++ b/src/test/ui/lifetimes/issue-97193.stderr @@ -0,0 +1,28 @@ +error: incorrect function inside `extern` block + --> $DIR/issue-97193.rs:2:8 + | +LL | extern "C" { + | ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body +LL | fn a(&mut self) { + | ________^____________- + | | | + | | cannot have a body +LL | | +LL | | +LL | | fn b(buf: &Self) {} +LL | | } + | |_____- help: remove the invalid body: `;` + | + = help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block + = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html + +error: `self` parameter is only allowed in associated functions + --> $DIR/issue-97193.rs:2:10 + | +LL | fn a(&mut self) { + | ^^^^^^^^^ not semantically valid as function parameter + | + = note: associated functions are those in `impl` or `trait` definitions + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/lifetimes/issue-97194.rs b/src/test/ui/lifetimes/issue-97194.rs new file mode 100644 index 0000000000000..accb4a9983071 --- /dev/null +++ b/src/test/ui/lifetimes/issue-97194.rs @@ -0,0 +1,10 @@ +extern "C" { + fn bget(&self, index: [usize; Self::DIM]) -> bool { + //~^ ERROR incorrect function inside `extern` block + //~| ERROR `self` parameter is only allowed in associated functions + //~| ERROR use of undeclared type `Self` + type T<'a> = &'a str; + } +} + +fn main() {} diff --git a/src/test/ui/lifetimes/issue-97194.stderr b/src/test/ui/lifetimes/issue-97194.stderr new file mode 100644 index 0000000000000..15ad5aadf9fdd --- /dev/null +++ b/src/test/ui/lifetimes/issue-97194.stderr @@ -0,0 +1,36 @@ +error: incorrect function inside `extern` block + --> $DIR/issue-97194.rs:2:8 + | +LL | extern "C" { + | ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body +LL | fn bget(&self, index: [usize; Self::DIM]) -> bool { + | ________^^^^___________________________________________- + | | | + | | cannot have a body +LL | | +LL | | +LL | | +LL | | type T<'a> = &'a str; +LL | | } + | |_____- help: remove the invalid body: `;` + | + = help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block + = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html + +error: `self` parameter is only allowed in associated functions + --> $DIR/issue-97194.rs:2:13 + | +LL | fn bget(&self, index: [usize; Self::DIM]) -> bool { + | ^^^^^ not semantically valid as function parameter + | + = note: associated functions are those in `impl` or `trait` definitions + +error[E0433]: failed to resolve: use of undeclared type `Self` + --> $DIR/issue-97194.rs:2:35 + | +LL | fn bget(&self, index: [usize; Self::DIM]) -> bool { + | ^^^^ use of undeclared type `Self` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0433`. From 3b70c29103cce7b03b6f0fe465e1197a3b212179 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 21 May 2022 11:15:28 +0200 Subject: [PATCH 5/6] Fix typo in futex RwLock::write_contended. I wrote `state` where I should've used `s`. This removes the unnecessary `s` variable to prevent that mistake. Fortunately, this typo didn't affect the correctness of the lock, as the second half of the condition (!has_writers_waiting) is enough for correctness, which explains why this mistake didn't show up during testing. --- library/std/src/sys/unix/locks/futex_rwlock.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/unix/locks/futex_rwlock.rs b/library/std/src/sys/unix/locks/futex_rwlock.rs index 57f6d58840db1..5ff1aba79747a 100644 --- a/library/std/src/sys/unix/locks/futex_rwlock.rs +++ b/library/std/src/sys/unix/locks/futex_rwlock.rs @@ -208,9 +208,8 @@ impl RwLock { // Don't go to sleep if the lock has become available, // or if the writers waiting bit is no longer set. - let s = self.state.load(Relaxed); - if is_unlocked(state) || !has_writers_waiting(s) { - state = s; + state = self.state.load(Relaxed); + if is_unlocked(state) || !has_writers_waiting(state) { continue; } From 0c92d1c7f3d6df0ddb2227fce4c89135ef4a9bcd Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 21 May 2022 16:21:44 -0500 Subject: [PATCH 6/6] Fix typo in Mir phase docs --- compiler/rustc_middle/src/mir/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 7b68b1d755df7..1eca22d3812cb 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -189,7 +189,7 @@ pub enum MirPhase { /// /// Beginning with this phase, the following variants are disallowed: /// * [`TerminatorKind::Yield`](terminator::TerminatorKind::Yield) - /// * [`TerminatorKind::GeneratorDrop](terminator::TerminatorKind::GeneratorDrop) + /// * [`TerminatorKind::GeneratorDrop`](terminator::TerminatorKind::GeneratorDrop) GeneratorsLowered = 5, Optimized = 6, }