Skip to content

Commit 5fe04cb

Browse files
committed
Auto merge of #140608 - matthiaskrgr:rollup-twv6muy, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #139343 (Change signature of File::try_lock and File::try_lock_shared) - #140505 (linker: Quote symbol names in .def files) - #140534 (PassWrapper: adapt for llvm/llvm-project@f137c3d592e96330e450a8fd63ef…) - #140546 (Remove backtrace dep from anyhow in features status dump tool) - #140548 (Emit user type annotations for free consts in pattern position) - #140564 (Use present indicative tense in std::io::pipe() API docs) - #140568 (Add regression test for #140545) - #140606 (Improve hir pretty printing) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2ad5f86 + 185f9e0 commit 5fe04cb

File tree

35 files changed

+316
-167
lines changed

35 files changed

+316
-167
lines changed

Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ name = "anyhow"
161161
version = "1.0.97"
162162
source = "registry+https://github.com/rust-lang/crates.io-index"
163163
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
164-
dependencies = [
165-
"backtrace",
166-
]
167164

168165
[[package]]
169166
name = "ar_archive_writer"

compiler/rustc_ast_pretty/src/pp.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@ struct BufEntry {
244244
// forgotten will trigger a panic in `drop`. (Closing a box more than once
245245
// isn't possible because `BoxMarker` doesn't implement `Copy` or `Clone`.)
246246
//
247-
// FIXME(nnethercote): the panic in `drop` is currently disabled because a few
248-
// places fail to close their boxes. It can be enabled once they are fixed.
249-
//
250247
// Note: it would be better to make open/close mismatching impossible and avoid
251248
// the need for this marker type altogether by having functions like
252249
// `with_ibox` that open a box, call a closure, and then close the box. That
@@ -261,8 +258,7 @@ impl !Copy for BoxMarker {}
261258

262259
impl Drop for BoxMarker {
263260
fn drop(&mut self) {
264-
// FIXME(nnethercote): enable once the bad cases are fixed
265-
//panic!("BoxMarker not ended with `Printer::end()`");
261+
panic!("BoxMarker not ended with `Printer::end()`");
266262
}
267263
}
268264

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast::{
1313

1414
use crate::pp::Breaks::Inconsistent;
1515
use crate::pprust::state::fixup::FixupContext;
16-
use crate::pprust::state::{AnnNode, BoxMarker, INDENT_UNIT, PrintState, State};
16+
use crate::pprust::state::{AnnNode, INDENT_UNIT, PrintState, State};
1717

1818
impl<'a> State<'a> {
1919
fn print_else(&mut self, els: Option<&ast::Expr>) {
@@ -485,12 +485,12 @@ impl<'a> State<'a> {
485485
self.print_block_with_attrs(body, attrs, cb, ib);
486486
}
487487
ast::ExprKind::Loop(blk, opt_label, _) => {
488+
let cb = self.cbox(0);
489+
let ib = self.ibox(0);
488490
if let Some(label) = opt_label {
489491
self.print_ident(label.ident);
490492
self.word_space(":");
491493
}
492-
let cb = self.cbox(0);
493-
let ib = self.ibox(0);
494494
self.word_nbsp("loop");
495495
self.print_block_with_attrs(blk, attrs, cb, ib);
496496
}
@@ -542,15 +542,6 @@ impl<'a> State<'a> {
542542
self.print_fn_params_and_ret(fn_decl, true);
543543
self.space();
544544
self.print_expr(body, FixupContext::default());
545-
// FIXME(nnethercote): Bogus. Reduce visibility of `ended` once it's fixed.
546-
let fake_ib = BoxMarker;
547-
self.end(fake_ib);
548-
549-
// A box will be closed by print_expr, but we didn't want an overall
550-
// wrapper so we closed the corresponding opening. so create an
551-
// empty box to satisfy the close.
552-
// FIXME(nnethercote): Bogus.
553-
let _ib = self.ibox(0);
554545
}
555546
ast::ExprKind::Block(blk, opt_label) => {
556547
if let Some(label) = opt_label {

compiler/rustc_codegen_ssa/src/back/linker.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,9 @@ impl<'a> Linker for GccLinker<'a> {
816816
writeln!(f, "EXPORTS")?;
817817
for symbol in symbols {
818818
debug!(" _{symbol}");
819-
writeln!(f, " {symbol}")?;
819+
// Quote the name in case it's reserved by linker in some way
820+
// (this accounts for names with dots in particular).
821+
writeln!(f, " \"{symbol}\"")?;
820822
}
821823
};
822824
if let Err(error) = res {

compiler/rustc_hir_pretty/src/lib.rs

+12-25
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl<'a> State<'a> {
110110
}
111111
self.print_attr_item(&unparsed, unparsed.span);
112112
self.word("]");
113+
self.hardbreak()
113114
}
114115
hir::Attribute::Parsed(AttributeKind::DocComment { style, kind, comment, .. }) => {
115116
self.word(rustc_ast_pretty::pprust::state::doc_comment_to_string(
@@ -183,7 +184,7 @@ impl<'a> State<'a> {
183184
Node::Ty(a) => self.print_type(a),
184185
Node::AssocItemConstraint(a) => self.print_assoc_item_constraint(a),
185186
Node::TraitRef(a) => self.print_trait_ref(a),
186-
Node::OpaqueTy(o) => self.print_opaque_ty(o),
187+
Node::OpaqueTy(_) => panic!("cannot print Node::OpaqueTy"),
187188
Node::Pat(a) => self.print_pat(a),
188189
Node::TyPat(a) => self.print_ty_pat(a),
189190
Node::PatField(a) => self.print_patfield(a),
@@ -654,10 +655,11 @@ impl<'a> State<'a> {
654655
self.bclose(item.span, cb);
655656
}
656657
hir::ItemKind::GlobalAsm { asm, .. } => {
657-
// FIXME(nnethercote): `ib` is unclosed
658-
let (cb, _ib) = self.head("global_asm!");
658+
let (cb, ib) = self.head("global_asm!");
659659
self.print_inline_asm(asm);
660-
self.end(cb)
660+
self.word(";");
661+
self.end(cb);
662+
self.end(ib);
661663
}
662664
hir::ItemKind::TyAlias(ident, ty, generics) => {
663665
let (cb, ib) = self.head("type");
@@ -764,14 +766,6 @@ impl<'a> State<'a> {
764766
self.print_path(t.path, false);
765767
}
766768

767-
fn print_opaque_ty(&mut self, o: &hir::OpaqueTy<'_>) {
768-
// FIXME(nnethercote): `cb` and `ib` are unclosed
769-
let (_cb, _ib) = self.head("opaque");
770-
self.word("{");
771-
self.print_bounds("impl", o.bounds);
772-
self.word("}");
773-
}
774-
775769
fn print_formal_generic_params(&mut self, generic_params: &[hir::GenericParam<'_>]) {
776770
if !generic_params.is_empty() {
777771
self.word("for");
@@ -1509,7 +1503,7 @@ impl<'a> State<'a> {
15091503
}
15101504
hir::ExprKind::DropTemps(init) => {
15111505
// Print `{`:
1512-
let cb = self.cbox(INDENT_UNIT);
1506+
let cb = self.cbox(0);
15131507
let ib = self.ibox(0);
15141508
self.bopen(ib);
15151509

@@ -1532,16 +1526,18 @@ impl<'a> State<'a> {
15321526
self.print_if(test, blk, elseopt);
15331527
}
15341528
hir::ExprKind::Loop(blk, opt_label, _, _) => {
1529+
let cb = self.cbox(0);
1530+
let ib = self.ibox(0);
15351531
if let Some(label) = opt_label {
15361532
self.print_ident(label.ident);
15371533
self.word_space(":");
15381534
}
1539-
let (cb, ib) = self.head("loop");
1535+
self.word_nbsp("loop");
15401536
self.print_block(blk, cb, ib);
15411537
}
15421538
hir::ExprKind::Match(expr, arms, _) => {
1543-
let cb = self.cbox(INDENT_UNIT);
1544-
let ib = self.ibox(INDENT_UNIT);
1539+
let cb = self.cbox(0);
1540+
let ib = self.ibox(0);
15451541
self.word_nbsp("match");
15461542
self.print_expr_as_cond(expr);
15471543
self.space();
@@ -1572,15 +1568,6 @@ impl<'a> State<'a> {
15721568

15731569
// This is a bare expression.
15741570
self.ann.nested(self, Nested::Body(body));
1575-
// FIXME(nnethercote): this is bogus
1576-
let fake_ib = BoxMarker;
1577-
self.end(fake_ib);
1578-
1579-
// A box will be closed by `print_expr`, but we didn't want an overall
1580-
// wrapper so we closed the corresponding opening. so create an
1581-
// empty box to satisfy the close.
1582-
// FIXME(nnethercote): this is bogus, and `print_expr` is missing
1583-
let _ib = self.ibox(0);
15841571
}
15851572
hir::ExprKind::Block(blk, opt_label) => {
15861573
if let Some(label) = opt_label {

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,13 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
512512
#endif
513513
}
514514

515+
#if LLVM_VERSION_GE(21, 0)
516+
TargetMachine *TM = TheTarget->createTargetMachine(Trip, CPU, Feature,
517+
Options, RM, CM, OptLevel);
518+
#else
515519
TargetMachine *TM = TheTarget->createTargetMachine(
516520
Trip.getTriple(), CPU, Feature, Options, RM, CM, OptLevel);
521+
#endif
517522
return wrap(TM);
518523
}
519524

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
553553
let res = self.typeck_results.qpath_res(qpath, id);
554554

555555
let (def_id, user_ty) = match res {
556-
Res::Def(DefKind::Const, def_id) => (def_id, None),
557-
Res::Def(DefKind::AssocConst, def_id) => {
556+
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
558557
(def_id, self.typeck_results.user_provided_types().get(id))
559558
}
560559

library/std/src/fs.rs

+60-11
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
mod tests;
2222

2323
use crate::ffi::OsString;
24-
use crate::fmt;
2524
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
2625
use crate::path::{Path, PathBuf};
2726
use crate::sealed::Sealed;
2827
use crate::sync::Arc;
2928
use crate::sys::fs as fs_imp;
3029
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
3130
use crate::time::SystemTime;
31+
use crate::{error, fmt};
3232

3333
/// An object providing access to an open file on the filesystem.
3434
///
@@ -116,6 +116,22 @@ pub struct File {
116116
inner: fs_imp::File,
117117
}
118118

119+
/// An enumeration of possible errors which can occur while trying to acquire a lock
120+
/// from the [`try_lock`] method and [`try_lock_shared`] method on a [`File`].
121+
///
122+
/// [`try_lock`]: File::try_lock
123+
/// [`try_lock_shared`]: File::try_lock_shared
124+
#[unstable(feature = "file_lock", issue = "130994")]
125+
pub enum TryLockError {
126+
/// The lock could not be acquired due to an I/O error on the file. The standard library will
127+
/// not return an [`ErrorKind::WouldBlock`] error inside [`TryLockError::Error`]
128+
///
129+
/// [`ErrorKind::WouldBlock`]: io::ErrorKind::WouldBlock
130+
Error(io::Error),
131+
/// The lock could not be acquired at this time because it is held by another handle/process.
132+
WouldBlock,
133+
}
134+
119135
/// Metadata information about a file.
120136
///
121137
/// This structure is returned from the [`metadata`] or
@@ -352,6 +368,30 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result
352368
inner(path.as_ref(), contents.as_ref())
353369
}
354370

371+
#[unstable(feature = "file_lock", issue = "130994")]
372+
impl error::Error for TryLockError {}
373+
374+
#[unstable(feature = "file_lock", issue = "130994")]
375+
impl fmt::Debug for TryLockError {
376+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
377+
match self {
378+
TryLockError::Error(err) => err.fmt(f),
379+
TryLockError::WouldBlock => "WouldBlock".fmt(f),
380+
}
381+
}
382+
}
383+
384+
#[unstable(feature = "file_lock", issue = "130994")]
385+
impl fmt::Display for TryLockError {
386+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
387+
match self {
388+
TryLockError::Error(_) => "lock acquisition failed due to I/O error",
389+
TryLockError::WouldBlock => "lock acquisition failed because the operation would block",
390+
}
391+
.fmt(f)
392+
}
393+
}
394+
355395
impl File {
356396
/// Attempts to open a file in read-only mode.
357397
///
@@ -734,8 +774,8 @@ impl File {
734774

735775
/// Try to acquire an exclusive lock on the file.
736776
///
737-
/// Returns `Ok(false)` if a different lock is already held on this file (via another
738-
/// handle/descriptor).
777+
/// Returns `Err(TryLockError::WouldBlock)` if a different lock is already held on this file
778+
/// (via another handle/descriptor).
739779
///
740780
/// This acquires an exclusive lock; no other file handle to this file may acquire another lock.
741781
///
@@ -777,23 +817,27 @@ impl File {
777817
///
778818
/// ```no_run
779819
/// #![feature(file_lock)]
780-
/// use std::fs::File;
820+
/// use std::fs::{File, TryLockError};
781821
///
782822
/// fn main() -> std::io::Result<()> {
783823
/// let f = File::create("foo.txt")?;
784-
/// f.try_lock()?;
824+
/// match f.try_lock() {
825+
/// Ok(_) => (),
826+
/// Err(TryLockError::WouldBlock) => (), // Lock not acquired
827+
/// Err(TryLockError::Error(err)) => return Err(err),
828+
/// }
785829
/// Ok(())
786830
/// }
787831
/// ```
788832
#[unstable(feature = "file_lock", issue = "130994")]
789-
pub fn try_lock(&self) -> io::Result<bool> {
833+
pub fn try_lock(&self) -> Result<(), TryLockError> {
790834
self.inner.try_lock()
791835
}
792836

793837
/// Try to acquire a shared (non-exclusive) lock on the file.
794838
///
795-
/// Returns `Ok(false)` if an exclusive lock is already held on this file (via another
796-
/// handle/descriptor).
839+
/// Returns `Err(TryLockError::WouldBlock)` if a different lock is already held on this file
840+
/// (via another handle/descriptor).
797841
///
798842
/// This acquires a shared lock; more than one file handle may hold a shared lock, but none may
799843
/// hold an exclusive lock at the same time.
@@ -834,16 +878,21 @@ impl File {
834878
///
835879
/// ```no_run
836880
/// #![feature(file_lock)]
837-
/// use std::fs::File;
881+
/// use std::fs::{File, TryLockError};
838882
///
839883
/// fn main() -> std::io::Result<()> {
840884
/// let f = File::open("foo.txt")?;
841-
/// f.try_lock_shared()?;
885+
/// match f.try_lock_shared() {
886+
/// Ok(_) => (),
887+
/// Err(TryLockError::WouldBlock) => (), // Lock not acquired
888+
/// Err(TryLockError::Error(err)) => return Err(err),
889+
/// }
890+
///
842891
/// Ok(())
843892
/// }
844893
/// ```
845894
#[unstable(feature = "file_lock", issue = "130994")]
846-
pub fn try_lock_shared(&self) -> io::Result<bool> {
895+
pub fn try_lock_shared(&self) -> Result<(), TryLockError> {
847896
self.inner.try_lock_shared()
848897
}
849898

0 commit comments

Comments
 (0)