Skip to content

Rollup of 8 pull requests #140608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
60218be
Remove backtrace dep from anyhow in features status dump tool
LegNeato May 1, 2025
bfe3d54
User type annotations for free consts in pattern position
BoxyUwU May 1, 2025
951412e
PassWrapper: adapt for llvm/llvm-project@f137c3d592e96330e450a8fd63ef…
erickt May 1, 2025
17d74d6
Use present indicative tense in std::io::pipe() API docs
ebkalderon May 1, 2025
042a556
Change signature of File::try_lock and File::try_lock_shared
cberner Apr 4, 2025
1d11ee2
Implement error::Error for TryLockError
cberner Apr 6, 2025
842858f
linker: Quote symbol names in .def files
petrochenkov Apr 30, 2025
dcee18b
Add a regression test
moxian May 1, 2025
882c74d
Remove fake `BoxMarker`s.
nnethercote Apr 29, 2025
3896ad0
Remove opaque type printing.
nnethercote Apr 29, 2025
760cf8d
Fix hir pretty-printing of `global_asm!`.
nnethercote Apr 29, 2025
aa7bb1c
Enable `BoxMarker` drop checking.
nnethercote Apr 29, 2025
e1a177b
Improve hir pretty-printing of attributes.
nnethercote Apr 30, 2025
809e5b5
Fix some hir pretty-printing over-indenting.
nnethercote Apr 30, 2025
9af0842
Avoid an indent for labelled loops.
nnethercote Apr 30, 2025
69e0844
Rollup merge of #139343 - cberner:filelock_wouldblock, r=workingjubilee
matthiaskrgr May 3, 2025
ca67f4d
Rollup merge of #140505 - petrochenkov:expquote, r=bjorn3
matthiaskrgr May 3, 2025
9ff7455
Rollup merge of #140534 - erickt:llvm-21, r=cuviper
matthiaskrgr May 3, 2025
b803f45
Rollup merge of #140546 - LegNeato:anyhowbacktrace, r=jieyouxu
matthiaskrgr May 3, 2025
6cf4fd3
Rollup merge of #140548 - BoxyUwU:gci_patterns_user_ty_annotation, r=…
matthiaskrgr May 3, 2025
422dfe6
Rollup merge of #140564 - ebkalderon:use-present-indicative-in-std-io…
matthiaskrgr May 3, 2025
5f9330c
Rollup merge of #140568 - moxian:reg-140545, r=compiler-errors
matthiaskrgr May 3, 2025
185f9e0
Rollup merge of #140606 - nnethercote:hir-pp, r=dtolnay
matthiaskrgr May 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ name = "anyhow"
version = "1.0.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
dependencies = [
"backtrace",
]

[[package]]
name = "ar_archive_writer"
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ struct BufEntry {
// forgotten will trigger a panic in `drop`. (Closing a box more than once
// isn't possible because `BoxMarker` doesn't implement `Copy` or `Clone`.)
//
// FIXME(nnethercote): the panic in `drop` is currently disabled because a few
// places fail to close their boxes. It can be enabled once they are fixed.
//
// Note: it would be better to make open/close mismatching impossible and avoid
// the need for this marker type altogether by having functions like
// `with_ibox` that open a box, call a closure, and then close the box. That
Expand All @@ -261,8 +258,7 @@ impl !Copy for BoxMarker {}

impl Drop for BoxMarker {
fn drop(&mut self) {
// FIXME(nnethercote): enable once the bad cases are fixed
//panic!("BoxMarker not ended with `Printer::end()`");
panic!("BoxMarker not ended with `Printer::end()`");
}
}

Expand Down
15 changes: 3 additions & 12 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_ast::{

use crate::pp::Breaks::Inconsistent;
use crate::pprust::state::fixup::FixupContext;
use crate::pprust::state::{AnnNode, BoxMarker, INDENT_UNIT, PrintState, State};
use crate::pprust::state::{AnnNode, INDENT_UNIT, PrintState, State};

impl<'a> State<'a> {
fn print_else(&mut self, els: Option<&ast::Expr>) {
Expand Down Expand Up @@ -485,12 +485,12 @@ impl<'a> State<'a> {
self.print_block_with_attrs(body, attrs, cb, ib);
}
ast::ExprKind::Loop(blk, opt_label, _) => {
let cb = self.cbox(0);
let ib = self.ibox(0);
if let Some(label) = opt_label {
self.print_ident(label.ident);
self.word_space(":");
}
let cb = self.cbox(0);
let ib = self.ibox(0);
self.word_nbsp("loop");
self.print_block_with_attrs(blk, attrs, cb, ib);
}
Expand Down Expand Up @@ -542,15 +542,6 @@ impl<'a> State<'a> {
self.print_fn_params_and_ret(fn_decl, true);
self.space();
self.print_expr(body, FixupContext::default());
// FIXME(nnethercote): Bogus. Reduce visibility of `ended` once it's fixed.
let fake_ib = BoxMarker;
self.end(fake_ib);

// A box will be closed by print_expr, but we didn't want an overall
// wrapper so we closed the corresponding opening. so create an
// empty box to satisfy the close.
// FIXME(nnethercote): Bogus.
let _ib = self.ibox(0);
}
ast::ExprKind::Block(blk, opt_label) => {
if let Some(label) = opt_label {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,9 @@ impl<'a> Linker for GccLinker<'a> {
writeln!(f, "EXPORTS")?;
for symbol in symbols {
debug!(" _{symbol}");
writeln!(f, " {symbol}")?;
// Quote the name in case it's reserved by linker in some way
// (this accounts for names with dots in particular).
writeln!(f, " \"{symbol}\"")?;
}
};
if let Err(error) = res {
Expand Down
37 changes: 12 additions & 25 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl<'a> State<'a> {
}
self.print_attr_item(&unparsed, unparsed.span);
self.word("]");
self.hardbreak()
}
hir::Attribute::Parsed(AttributeKind::DocComment { style, kind, comment, .. }) => {
self.word(rustc_ast_pretty::pprust::state::doc_comment_to_string(
Expand Down Expand Up @@ -183,7 +184,7 @@ impl<'a> State<'a> {
Node::Ty(a) => self.print_type(a),
Node::AssocItemConstraint(a) => self.print_assoc_item_constraint(a),
Node::TraitRef(a) => self.print_trait_ref(a),
Node::OpaqueTy(o) => self.print_opaque_ty(o),
Node::OpaqueTy(_) => panic!("cannot print Node::OpaqueTy"),
Node::Pat(a) => self.print_pat(a),
Node::TyPat(a) => self.print_ty_pat(a),
Node::PatField(a) => self.print_patfield(a),
Expand Down Expand Up @@ -654,10 +655,11 @@ impl<'a> State<'a> {
self.bclose(item.span, cb);
}
hir::ItemKind::GlobalAsm { asm, .. } => {
// FIXME(nnethercote): `ib` is unclosed
let (cb, _ib) = self.head("global_asm!");
let (cb, ib) = self.head("global_asm!");
self.print_inline_asm(asm);
self.end(cb)
self.word(";");
self.end(cb);
self.end(ib);
}
hir::ItemKind::TyAlias(ident, ty, generics) => {
let (cb, ib) = self.head("type");
Expand Down Expand Up @@ -764,14 +766,6 @@ impl<'a> State<'a> {
self.print_path(t.path, false);
}

fn print_opaque_ty(&mut self, o: &hir::OpaqueTy<'_>) {
// FIXME(nnethercote): `cb` and `ib` are unclosed
let (_cb, _ib) = self.head("opaque");
self.word("{");
self.print_bounds("impl", o.bounds);
self.word("}");
}

fn print_formal_generic_params(&mut self, generic_params: &[hir::GenericParam<'_>]) {
if !generic_params.is_empty() {
self.word("for");
Expand Down Expand Up @@ -1509,7 +1503,7 @@ impl<'a> State<'a> {
}
hir::ExprKind::DropTemps(init) => {
// Print `{`:
let cb = self.cbox(INDENT_UNIT);
let cb = self.cbox(0);
let ib = self.ibox(0);
self.bopen(ib);

Expand All @@ -1532,16 +1526,18 @@ impl<'a> State<'a> {
self.print_if(test, blk, elseopt);
}
hir::ExprKind::Loop(blk, opt_label, _, _) => {
let cb = self.cbox(0);
let ib = self.ibox(0);
if let Some(label) = opt_label {
self.print_ident(label.ident);
self.word_space(":");
}
let (cb, ib) = self.head("loop");
self.word_nbsp("loop");
self.print_block(blk, cb, ib);
}
hir::ExprKind::Match(expr, arms, _) => {
let cb = self.cbox(INDENT_UNIT);
let ib = self.ibox(INDENT_UNIT);
let cb = self.cbox(0);
let ib = self.ibox(0);
self.word_nbsp("match");
self.print_expr_as_cond(expr);
self.space();
Expand Down Expand Up @@ -1572,15 +1568,6 @@ impl<'a> State<'a> {

// This is a bare expression.
self.ann.nested(self, Nested::Body(body));
// FIXME(nnethercote): this is bogus
let fake_ib = BoxMarker;
self.end(fake_ib);

// A box will be closed by `print_expr`, but we didn't want an overall
// wrapper so we closed the corresponding opening. so create an
// empty box to satisfy the close.
// FIXME(nnethercote): this is bogus, and `print_expr` is missing
let _ib = self.ibox(0);
}
hir::ExprKind::Block(blk, opt_label) => {
if let Some(label) = opt_label {
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,13 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
#endif
}

#if LLVM_VERSION_GE(21, 0)
TargetMachine *TM = TheTarget->createTargetMachine(Trip, CPU, Feature,
Options, RM, CM, OptLevel);
#else
TargetMachine *TM = TheTarget->createTargetMachine(
Trip.getTriple(), CPU, Feature, Options, RM, CM, OptLevel);
#endif
return wrap(TM);
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
let res = self.typeck_results.qpath_res(qpath, id);

let (def_id, user_ty) = match res {
Res::Def(DefKind::Const, def_id) => (def_id, None),
Res::Def(DefKind::AssocConst, def_id) => {
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
(def_id, self.typeck_results.user_provided_types().get(id))
}

Expand Down
71 changes: 60 additions & 11 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
mod tests;

use crate::ffi::OsString;
use crate::fmt;
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
use crate::path::{Path, PathBuf};
use crate::sealed::Sealed;
use crate::sync::Arc;
use crate::sys::fs as fs_imp;
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
use crate::time::SystemTime;
use crate::{error, fmt};

/// An object providing access to an open file on the filesystem.
///
Expand Down Expand Up @@ -116,6 +116,22 @@ pub struct File {
inner: fs_imp::File,
}

/// An enumeration of possible errors which can occur while trying to acquire a lock
/// from the [`try_lock`] method and [`try_lock_shared`] method on a [`File`].
///
/// [`try_lock`]: File::try_lock
/// [`try_lock_shared`]: File::try_lock_shared
#[unstable(feature = "file_lock", issue = "130994")]
pub enum TryLockError {
/// The lock could not be acquired due to an I/O error on the file. The standard library will
/// not return an [`ErrorKind::WouldBlock`] error inside [`TryLockError::Error`]
///
/// [`ErrorKind::WouldBlock`]: io::ErrorKind::WouldBlock
Error(io::Error),
/// The lock could not be acquired at this time because it is held by another handle/process.
WouldBlock,
}

/// Metadata information about a file.
///
/// This structure is returned from the [`metadata`] or
Expand Down Expand Up @@ -352,6 +368,30 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result
inner(path.as_ref(), contents.as_ref())
}

#[unstable(feature = "file_lock", issue = "130994")]
impl error::Error for TryLockError {}

#[unstable(feature = "file_lock", issue = "130994")]
impl fmt::Debug for TryLockError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TryLockError::Error(err) => err.fmt(f),
TryLockError::WouldBlock => "WouldBlock".fmt(f),
}
}
}

#[unstable(feature = "file_lock", issue = "130994")]
impl fmt::Display for TryLockError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TryLockError::Error(_) => "lock acquisition failed due to I/O error",
TryLockError::WouldBlock => "lock acquisition failed because the operation would block",
}
.fmt(f)
}
}

impl File {
/// Attempts to open a file in read-only mode.
///
Expand Down Expand Up @@ -734,8 +774,8 @@ impl File {

/// Try to acquire an exclusive lock on the file.
///
/// Returns `Ok(false)` if a different lock is already held on this file (via another
/// handle/descriptor).
/// Returns `Err(TryLockError::WouldBlock)` if a different lock is already held on this file
/// (via another handle/descriptor).
///
/// This acquires an exclusive lock; no other file handle to this file may acquire another lock.
///
Expand Down Expand Up @@ -777,23 +817,27 @@ impl File {
///
/// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File;
/// use std::fs::{File, TryLockError};
///
/// fn main() -> std::io::Result<()> {
/// let f = File::create("foo.txt")?;
/// f.try_lock()?;
/// match f.try_lock() {
/// Ok(_) => (),
/// Err(TryLockError::WouldBlock) => (), // Lock not acquired
/// Err(TryLockError::Error(err)) => return Err(err),
/// }
/// Ok(())
/// }
/// ```
#[unstable(feature = "file_lock", issue = "130994")]
pub fn try_lock(&self) -> io::Result<bool> {
pub fn try_lock(&self) -> Result<(), TryLockError> {
self.inner.try_lock()
}

/// Try to acquire a shared (non-exclusive) lock on the file.
///
/// Returns `Ok(false)` if an exclusive lock is already held on this file (via another
/// handle/descriptor).
/// Returns `Err(TryLockError::WouldBlock)` if a different lock is already held on this file
/// (via another handle/descriptor).
///
/// This acquires a shared lock; more than one file handle may hold a shared lock, but none may
/// hold an exclusive lock at the same time.
Expand Down Expand Up @@ -834,16 +878,21 @@ impl File {
///
/// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File;
/// use std::fs::{File, TryLockError};
///
/// fn main() -> std::io::Result<()> {
/// let f = File::open("foo.txt")?;
/// f.try_lock_shared()?;
/// match f.try_lock_shared() {
/// Ok(_) => (),
/// Err(TryLockError::WouldBlock) => (), // Lock not acquired
/// Err(TryLockError::Error(err)) => return Err(err),
/// }
///
/// Ok(())
/// }
/// ```
#[unstable(feature = "file_lock", issue = "130994")]
pub fn try_lock_shared(&self) -> io::Result<bool> {
pub fn try_lock_shared(&self) -> Result<(), TryLockError> {
self.inner.try_lock_shared()
}

Expand Down
Loading
Loading