Skip to content

Commit bb5e6c9

Browse files
committed
Auto merge of rust-lang#97265 - JohnTitor:rollup-kgthnjt, r=JohnTitor
Rollup of 6 pull requests Successful merges: - rust-lang#97144 (Fix rusty grammar in `std::error::Reporter` docs) - rust-lang#97225 (Fix `Display` for `cell::{Ref,RefMut}`) - rust-lang#97228 (Omit stdarch workspace from rust-src) - rust-lang#97236 (Recover when resolution did not resolve lifetimes.) - rust-lang#97245 (Fix typo in futex RwLock::write_contended.) - rust-lang#97259 (Fix typo in Mir phase docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 09ea213 + 97e1ab0 commit bb5e6c9

File tree

11 files changed

+106
-24
lines changed

11 files changed

+106
-24
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -1168,15 +1168,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11681168
TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
11691169
TyKind::Rptr(ref region, ref mt) => {
11701170
let region = region.unwrap_or_else(|| {
1171-
let Some(LifetimeRes::ElidedAnchor { start, end }) = self.resolver.get_lifetime_res(t.id) else {
1172-
panic!()
1171+
let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1172+
self.resolver.get_lifetime_res(t.id)
1173+
{
1174+
debug_assert_eq!(start.plus(1), end);
1175+
start
1176+
} else {
1177+
self.resolver.next_node_id()
11731178
};
1174-
debug_assert_eq!(start.plus(1), end);
11751179
let span = self.sess.source_map().next_point(t.span.shrink_to_lo());
1176-
Lifetime {
1177-
ident: Ident::new(kw::UnderscoreLifetime, span),
1178-
id: start,
1179-
}
1180+
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
11801181
});
11811182
let lifetime = self.lower_lifetime(&region);
11821183
hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx))
@@ -1835,10 +1836,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18351836
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
18361837
let span = self.lower_span(l.ident.span);
18371838
let ident = self.lower_ident(l.ident);
1838-
let res = self
1839-
.resolver
1840-
.get_lifetime_res(l.id)
1841-
.unwrap_or_else(|| panic!("Missing resolution for lifetime {:?} at {:?}", l, span));
1839+
let res = self.resolver.get_lifetime_res(l.id).unwrap_or(LifetimeRes::Error);
18421840
self.new_named_lifetime_with_res(l.id, span, ident, res)
18431841
}
18441842

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub enum MirPhase {
189189
///
190190
/// Beginning with this phase, the following variants are disallowed:
191191
/// * [`TerminatorKind::Yield`](terminator::TerminatorKind::Yield)
192-
/// * [`TerminatorKind::GeneratorDrop](terminator::TerminatorKind::GeneratorDrop)
192+
/// * [`TerminatorKind::GeneratorDrop`](terminator::TerminatorKind::GeneratorDrop)
193193
GeneratorsLowered = 5,
194194
Optimized = 6,
195195
}

library/core/src/cell.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ impl<'b, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Ref<'b, U>> for Ref<'b,
14871487
#[stable(feature = "std_guard_impls", since = "1.20.0")]
14881488
impl<T: ?Sized + fmt::Display> fmt::Display for Ref<'_, T> {
14891489
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1490-
self.value.fmt(f)
1490+
(**self).fmt(f)
14911491
}
14921492
}
14931493

@@ -1735,7 +1735,7 @@ impl<'b, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<RefMut<'b, U>> for RefM
17351735
#[stable(feature = "std_guard_impls", since = "1.20.0")]
17361736
impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
17371737
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1738-
self.value.fmt(f)
1738+
(**self).fmt(f)
17391739
}
17401740
}
17411741

library/core/tests/cell.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ fn ref_and_refmut_have_sensible_show() {
7373
let refcell = RefCell::new("foo");
7474

7575
let refcell_refmut = refcell.borrow_mut();
76-
assert!(format!("{refcell_refmut:?}").contains("foo"));
76+
assert_eq!(format!("{refcell_refmut}"), "foo"); // Display
77+
assert!(format!("{refcell_refmut:?}").contains("foo")); // Debug
7778
drop(refcell_refmut);
7879

7980
let refcell_ref = refcell.borrow();
80-
assert!(format!("{refcell_ref:?}").contains("foo"));
81+
assert_eq!(format!("{refcell_ref}"), "foo"); // Display
82+
assert!(format!("{refcell_ref:?}").contains("foo")); // Debug
8183
drop(refcell_ref);
8284
}
8385

library/std/src/error.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -863,12 +863,12 @@ impl dyn Error + Send + Sync {
863863
}
864864
}
865865

866-
/// An error reporter that print's an error and its sources.
866+
/// An error reporter that prints an error and its sources.
867867
///
868868
/// Report also exposes configuration options for formatting the error chain, either entirely on a
869869
/// single line, or in multi-line format with each cause in the error chain on a new line.
870870
///
871-
/// `Report` only requires that the wrapped error implements `Error`. It doesn't require that the
871+
/// `Report` only requires that the wrapped error implement `Error`. It doesn't require that the
872872
/// wrapped error be `Send`, `Sync`, or `'static`.
873873
///
874874
/// # Examples
@@ -972,7 +972,7 @@ impl dyn Error + Send + Sync {
972972
///
973973
/// ## Return from `main`
974974
///
975-
/// `Report` also implements `From` for all types that implement [`Error`], this when combined with
975+
/// `Report` also implements `From` for all types that implement [`Error`]; this when combined with
976976
/// the `Debug` output means `Report` is an ideal starting place for formatting errors returned
977977
/// from `main`.
978978
///
@@ -1020,7 +1020,7 @@ impl dyn Error + Send + Sync {
10201020
/// ```
10211021
///
10221022
/// **Note**: `Report`s constructed via `?` and `From` will be configured to use the single line
1023-
/// output format, if you want to make sure your `Report`s are pretty printed and include backtrace
1023+
/// output format. If you want to make sure your `Report`s are pretty printed and include backtrace
10241024
/// you will need to manually convert and enable those flags.
10251025
///
10261026
/// ```should_panic

library/std/src/sys/unix/locks/futex_rwlock.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ impl RwLock {
208208

209209
// Don't go to sleep if the lock has become available,
210210
// or if the writers waiting bit is no longer set.
211-
let s = self.state.load(Relaxed);
212-
if is_unlocked(state) || !has_writers_waiting(s) {
213-
state = s;
211+
state = self.state.load(Relaxed);
212+
if is_unlocked(state) || !has_writers_waiting(state) {
214213
continue;
215214
}
216215

src/bootstrap/dist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ impl Step for Src {
814814
"library/backtrace/crates",
815815
// these are 30MB combined and aren't necessary for building
816816
// the standard library.
817-
"library/stdarch/crates/Cargo.toml",
817+
"library/stdarch/Cargo.toml",
818818
"library/stdarch/crates/stdarch-verify",
819819
"library/stdarch/crates/intrinsic-test",
820820
],

src/test/ui/lifetimes/issue-97193.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extern "C" {
2+
fn a(&mut self) {
3+
//~^ ERROR incorrect function inside `extern` block
4+
//~| ERROR `self` parameter is only allowed in associated functions
5+
fn b(buf: &Self) {}
6+
}
7+
}
8+
9+
fn main() {}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: incorrect function inside `extern` block
2+
--> $DIR/issue-97193.rs:2:8
3+
|
4+
LL | extern "C" {
5+
| ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body
6+
LL | fn a(&mut self) {
7+
| ________^____________-
8+
| | |
9+
| | cannot have a body
10+
LL | |
11+
LL | |
12+
LL | | fn b(buf: &Self) {}
13+
LL | | }
14+
| |_____- help: remove the invalid body: `;`
15+
|
16+
= 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
17+
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
18+
19+
error: `self` parameter is only allowed in associated functions
20+
--> $DIR/issue-97193.rs:2:10
21+
|
22+
LL | fn a(&mut self) {
23+
| ^^^^^^^^^ not semantically valid as function parameter
24+
|
25+
= note: associated functions are those in `impl` or `trait` definitions
26+
27+
error: aborting due to 2 previous errors
28+

src/test/ui/lifetimes/issue-97194.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extern "C" {
2+
fn bget(&self, index: [usize; Self::DIM]) -> bool {
3+
//~^ ERROR incorrect function inside `extern` block
4+
//~| ERROR `self` parameter is only allowed in associated functions
5+
//~| ERROR use of undeclared type `Self`
6+
type T<'a> = &'a str;
7+
}
8+
}
9+
10+
fn main() {}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error: incorrect function inside `extern` block
2+
--> $DIR/issue-97194.rs:2:8
3+
|
4+
LL | extern "C" {
5+
| ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body
6+
LL | fn bget(&self, index: [usize; Self::DIM]) -> bool {
7+
| ________^^^^___________________________________________-
8+
| | |
9+
| | cannot have a body
10+
LL | |
11+
LL | |
12+
LL | |
13+
LL | | type T<'a> = &'a str;
14+
LL | | }
15+
| |_____- help: remove the invalid body: `;`
16+
|
17+
= 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
18+
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
19+
20+
error: `self` parameter is only allowed in associated functions
21+
--> $DIR/issue-97194.rs:2:13
22+
|
23+
LL | fn bget(&self, index: [usize; Self::DIM]) -> bool {
24+
| ^^^^^ not semantically valid as function parameter
25+
|
26+
= note: associated functions are those in `impl` or `trait` definitions
27+
28+
error[E0433]: failed to resolve: use of undeclared type `Self`
29+
--> $DIR/issue-97194.rs:2:35
30+
|
31+
LL | fn bget(&self, index: [usize; Self::DIM]) -> bool {
32+
| ^^^^ use of undeclared type `Self`
33+
34+
error: aborting due to 3 previous errors
35+
36+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)