Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f8c27df

Browse files
committedMar 24, 2025
Auto merge of rust-lang#138901 - matthiaskrgr:rollup-qbbanhr, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#138662 (Implement some basics in UEFI fs) - rust-lang#138800 (remove remnants of const_box feature) - rust-lang#138821 (match lowering cleanup: remove unused unsizing logic from `non_scalar_compare`) - rust-lang#138864 (Rework `--print` options documentation) - rust-lang#138868 (Add do_not_recommend typo help) - rust-lang#138882 (`with_scope` is only ever used for ast modules) - rust-lang#138894 (Update books) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4510e86 + 4202bf9 commit f8c27df

File tree

14 files changed

+342
-190
lines changed

14 files changed

+342
-190
lines changed
 

‎compiler/rustc_middle/src/thir.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,9 @@ pub enum PatKind<'tcx> {
800800
},
801801

802802
/// One of the following:
803-
/// * `&str`/`&[u8]` (represented as a valtree), which will be handled as a string/slice pattern
804-
/// and thus exhaustiveness checking will detect if you use the same string/slice twice in
805-
/// different patterns.
803+
/// * `&str` (represented as a valtree), which will be handled as a string pattern and thus
804+
/// exhaustiveness checking will detect if you use the same string twice in different
805+
/// patterns.
806806
/// * integer, bool, char or float (represented as a valtree), which will be handled by
807807
/// exhaustiveness to cover exactly its own value, similar to `&str`, but these values are
808808
/// much simpler.

‎compiler/rustc_mir_build/src/builder/matches/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1326,8 +1326,8 @@ enum TestKind<'tcx> {
13261326
Eq {
13271327
value: Const<'tcx>,
13281328
// Integer types are handled by `SwitchInt`, and constants with ADT
1329-
// types are converted back into patterns, so this can only be `&str`,
1330-
// `&[T]`, `f32` or `f64`.
1329+
// types and `&[T]` types are converted back into patterns, so this can
1330+
// only be `&str`, `f32` or `f64`.
13311331
ty: Ty<'tcx>,
13321332
},
13331333

‎compiler/rustc_mir_build/src/builder/matches/test.rs

+19-89
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::sync::Arc;
1111
use rustc_data_structures::fx::FxIndexMap;
1212
use rustc_hir::{LangItem, RangeEnd};
1313
use rustc_middle::mir::*;
14-
use rustc_middle::ty::adjustment::PointerCoercion;
1514
use rustc_middle::ty::util::IntTypeExt;
1615
use rustc_middle::ty::{self, GenericArg, Ty, TyCtxt};
1716
use rustc_middle::{bug, span_bug};
@@ -178,21 +177,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
178177
_ => {}
179178
}
180179

180+
assert_eq!(expect_ty, ty);
181181
if !ty.is_scalar() {
182182
// Use `PartialEq::eq` instead of `BinOp::Eq`
183183
// (the binop can only handle primitives)
184-
self.non_scalar_compare(
184+
// Make sure that we do *not* call any user-defined code here.
185+
// The only type that can end up here is string literals, which have their
186+
// comparison defined in `core`.
187+
// (Interestingly this means that exhaustiveness analysis relies, for soundness,
188+
// on the `PartialEq` impl for `str` to b correct!)
189+
match *ty.kind() {
190+
ty::Ref(_, deref_ty, _) if deref_ty == self.tcx.types.str_ => {}
191+
_ => {
192+
span_bug!(source_info.span, "invalid type for non-scalar compare: {ty}")
193+
}
194+
};
195+
self.string_compare(
185196
block,
186197
success_block,
187198
fail_block,
188199
source_info,
189200
expect,
190-
expect_ty,
191201
Operand::Copy(place),
192-
ty,
193202
);
194203
} else {
195-
assert_eq!(expect_ty, ty);
196204
self.compare(
197205
block,
198206
success_block,
@@ -370,97 +378,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
370378
);
371379
}
372380

373-
/// Compare two values using `<T as std::compare::PartialEq>::eq`.
374-
/// If the values are already references, just call it directly, otherwise
375-
/// take a reference to the values first and then call it.
376-
fn non_scalar_compare(
381+
/// Compare two values of type `&str` using `<str as std::cmp::PartialEq>::eq`.
382+
fn string_compare(
377383
&mut self,
378384
block: BasicBlock,
379385
success_block: BasicBlock,
380386
fail_block: BasicBlock,
381387
source_info: SourceInfo,
382-
mut expect: Operand<'tcx>,
383-
expect_ty: Ty<'tcx>,
384-
mut val: Operand<'tcx>,
385-
mut ty: Ty<'tcx>,
388+
expect: Operand<'tcx>,
389+
val: Operand<'tcx>,
386390
) {
387-
// If we're using `b"..."` as a pattern, we need to insert an
388-
// unsizing coercion, as the byte string has the type `&[u8; N]`.
389-
//
390-
// We want to do this even when the scrutinee is a reference to an
391-
// array, so we can call `<[u8]>::eq` rather than having to find an
392-
// `<[u8; N]>::eq`.
393-
let unsize = |ty: Ty<'tcx>| match ty.kind() {
394-
ty::Ref(region, rty, _) => match rty.kind() {
395-
ty::Array(inner_ty, n) => Some((region, inner_ty, n)),
396-
_ => None,
397-
},
398-
_ => None,
399-
};
400-
let opt_ref_ty = unsize(ty);
401-
let opt_ref_test_ty = unsize(expect_ty);
402-
match (opt_ref_ty, opt_ref_test_ty) {
403-
// nothing to do, neither is an array
404-
(None, None) => {}
405-
(Some((region, elem_ty, _)), _) | (None, Some((region, elem_ty, _))) => {
406-
let tcx = self.tcx;
407-
// make both a slice
408-
ty = Ty::new_imm_ref(tcx, *region, Ty::new_slice(tcx, *elem_ty));
409-
if opt_ref_ty.is_some() {
410-
let temp = self.temp(ty, source_info.span);
411-
self.cfg.push_assign(
412-
block,
413-
source_info,
414-
temp,
415-
Rvalue::Cast(
416-
CastKind::PointerCoercion(
417-
PointerCoercion::Unsize,
418-
CoercionSource::Implicit,
419-
),
420-
val,
421-
ty,
422-
),
423-
);
424-
val = Operand::Copy(temp);
425-
}
426-
if opt_ref_test_ty.is_some() {
427-
let slice = self.temp(ty, source_info.span);
428-
self.cfg.push_assign(
429-
block,
430-
source_info,
431-
slice,
432-
Rvalue::Cast(
433-
CastKind::PointerCoercion(
434-
PointerCoercion::Unsize,
435-
CoercionSource::Implicit,
436-
),
437-
expect,
438-
ty,
439-
),
440-
);
441-
expect = Operand::Move(slice);
442-
}
443-
}
444-
}
445-
446-
// Figure out the type on which we are calling `PartialEq`. This involves an extra wrapping
447-
// reference: we can only compare two `&T`, and then compare_ty will be `T`.
448-
// Make sure that we do *not* call any user-defined code here.
449-
// The only types that can end up here are string and byte literals,
450-
// which have their comparison defined in `core`.
451-
// (Interestingly this means that exhaustiveness analysis relies, for soundness,
452-
// on the `PartialEq` impls for `str` and `[u8]` to b correct!)
453-
let compare_ty = match *ty.kind() {
454-
ty::Ref(_, deref_ty, _)
455-
if deref_ty == self.tcx.types.str_ || deref_ty != self.tcx.types.u8 =>
456-
{
457-
deref_ty
458-
}
459-
_ => span_bug!(source_info.span, "invalid type for non-scalar compare: {}", ty),
460-
};
461-
391+
let str_ty = self.tcx.types.str_;
462392
let eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, Some(source_info.span));
463-
let method = trait_method(self.tcx, eq_def_id, sym::eq, [compare_ty, compare_ty]);
393+
let method = trait_method(self.tcx, eq_def_id, sym::eq, [str_ty, str_ty]);
464394

465395
let bool_ty = self.tcx.types.bool;
466396
let eq_result = self.temp(bool_ty, source_info.span);

‎compiler/rustc_resolve/src/late.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -1544,20 +1544,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
15441544
ret
15451545
}
15461546

1547-
fn with_scope<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
1548-
if let Some(module) = self.r.get_module(self.r.local_def_id(id).to_def_id()) {
1549-
// Move down in the graph.
1550-
let orig_module = replace(&mut self.parent_scope.module, module);
1551-
self.with_rib(ValueNS, RibKind::Module(module), |this| {
1552-
this.with_rib(TypeNS, RibKind::Module(module), |this| {
1553-
let ret = f(this);
1554-
this.parent_scope.module = orig_module;
1555-
ret
1556-
})
1547+
fn with_mod_rib<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
1548+
let module = self.r.expect_module(self.r.local_def_id(id).to_def_id());
1549+
// Move down in the graph.
1550+
let orig_module = replace(&mut self.parent_scope.module, module);
1551+
self.with_rib(ValueNS, RibKind::Module(module), |this| {
1552+
this.with_rib(TypeNS, RibKind::Module(module), |this| {
1553+
let ret = f(this);
1554+
this.parent_scope.module = orig_module;
1555+
ret
15571556
})
1558-
} else {
1559-
f(self)
1560-
}
1557+
})
15611558
}
15621559

15631560
fn visit_generic_params(&mut self, params: &'ast [GenericParam], add_self_upper: bool) {
@@ -2738,7 +2735,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
27382735
}
27392736

27402737
ItemKind::Mod(..) => {
2741-
self.with_scope(item.id, |this| {
2738+
self.with_mod_rib(item.id, |this| {
27422739
if mod_inner_docs {
27432740
this.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
27442741
}

‎compiler/rustc_resolve/src/macros.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_session::lint::builtin::{
2828
UNUSED_MACRO_RULES, UNUSED_MACROS,
2929
};
3030
use rustc_session::parse::feature_err;
31-
use rustc_span::edit_distance::edit_distance;
31+
use rustc_span::edit_distance::find_best_match_for_name;
3232
use rustc_span::edition::Edition;
3333
use rustc_span::hygiene::{self, AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind};
3434
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
@@ -652,13 +652,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
652652
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
653653
&& let [namespace, attribute, ..] = &*path.segments
654654
&& namespace.ident.name == sym::diagnostic
655-
&& !(attribute.ident.name == sym::on_unimplemented
656-
|| attribute.ident.name == sym::do_not_recommend)
655+
&& ![sym::on_unimplemented, sym::do_not_recommend].contains(&attribute.ident.name)
657656
{
658-
let distance =
659-
edit_distance(attribute.ident.name.as_str(), sym::on_unimplemented.as_str(), 5);
660-
661-
let typo_name = distance.map(|_| sym::on_unimplemented);
657+
let typo_name = find_best_match_for_name(
658+
&[sym::on_unimplemented, sym::do_not_recommend],
659+
attribute.ident.name,
660+
Some(5),
661+
);
662662

663663
self.tcx.sess.psess.buffer_lint(
664664
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,

‎library/alloc/src/boxed.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1149,9 +1149,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11491149
///
11501150
/// [memory layout]: self#memory-layout
11511151
#[unstable(feature = "allocator_api", issue = "32838")]
1152-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
11531152
#[inline]
1154-
pub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
1153+
pub unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
11551154
Box(unsafe { Unique::new_unchecked(raw) }, alloc)
11561155
}
11571156

@@ -1203,9 +1202,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12031202
/// [memory layout]: self#memory-layout
12041203
#[unstable(feature = "allocator_api", issue = "32838")]
12051204
// #[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
1206-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
12071205
#[inline]
1208-
pub const unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self {
1206+
pub unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self {
12091207
// SAFETY: guaranteed by the caller.
12101208
unsafe { Box::from_raw_in(raw.as_ptr(), alloc) }
12111209
}
@@ -1550,9 +1548,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
15501548
/// to call it as `Box::allocator(&b)` instead of `b.allocator()`. This
15511549
/// is so that there is no conflict with a method on the inner type.
15521550
#[unstable(feature = "allocator_api", issue = "32838")]
1553-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
15541551
#[inline]
1555-
pub const fn allocator(b: &Self) -> &A {
1552+
pub fn allocator(b: &Self) -> &A {
15561553
&b.1
15571554
}
15581555

@@ -1639,8 +1636,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
16391636
/// let bar = Pin::from(foo);
16401637
/// ```
16411638
#[stable(feature = "box_into_pin", since = "1.63.0")]
1642-
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
1643-
pub const fn into_pin(boxed: Self) -> Pin<Self>
1639+
pub fn into_pin(boxed: Self) -> Pin<Self>
16441640
where
16451641
A: 'static,
16461642
{

‎library/std/src/sys/fs/uefi.rs

+62-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use r_efi::protocols::file;
2+
13
use crate::ffi::OsString;
24
use crate::fmt;
35
use crate::hash::Hash;
@@ -22,7 +24,12 @@ pub struct ReadDir(!);
2224
pub struct DirEntry(!);
2325

2426
#[derive(Clone, Debug)]
25-
pub struct OpenOptions {}
27+
pub struct OpenOptions {
28+
mode: u64,
29+
append: bool,
30+
truncate: bool,
31+
create_new: bool,
32+
}
2633

2734
#[derive(Copy, Clone, Debug, Default)]
2835
pub struct FileTimes {}
@@ -141,15 +148,58 @@ impl DirEntry {
141148

142149
impl OpenOptions {
143150
pub fn new() -> OpenOptions {
144-
OpenOptions {}
151+
OpenOptions { mode: 0, append: false, create_new: false, truncate: false }
152+
}
153+
154+
pub fn read(&mut self, read: bool) {
155+
if read {
156+
self.mode |= file::MODE_READ;
157+
} else {
158+
self.mode &= !file::MODE_READ;
159+
}
160+
}
161+
162+
pub fn write(&mut self, write: bool) {
163+
if write {
164+
// Valid Combinations: Read, Read/Write, Read/Write/Create
165+
self.read(true);
166+
self.mode |= file::MODE_WRITE;
167+
} else {
168+
self.mode &= !file::MODE_WRITE;
169+
}
170+
}
171+
172+
pub fn append(&mut self, append: bool) {
173+
// Docs state that `.write(true).append(true)` has the same effect as `.append(true)`
174+
if append {
175+
self.write(true);
176+
}
177+
self.append = append;
145178
}
146179

147-
pub fn read(&mut self, _read: bool) {}
148-
pub fn write(&mut self, _write: bool) {}
149-
pub fn append(&mut self, _append: bool) {}
150-
pub fn truncate(&mut self, _truncate: bool) {}
151-
pub fn create(&mut self, _create: bool) {}
152-
pub fn create_new(&mut self, _create_new: bool) {}
180+
pub fn truncate(&mut self, truncate: bool) {
181+
self.truncate = truncate;
182+
}
183+
184+
pub fn create(&mut self, create: bool) {
185+
if create {
186+
self.mode |= file::MODE_CREATE;
187+
} else {
188+
self.mode &= !file::MODE_CREATE;
189+
}
190+
}
191+
192+
pub fn create_new(&mut self, create_new: bool) {
193+
self.create_new = create_new;
194+
}
195+
196+
#[expect(dead_code)]
197+
const fn is_mode_valid(&self) -> bool {
198+
// Valid Combinations: Read, Read/Write, Read/Write/Create
199+
self.mode == file::MODE_READ
200+
|| self.mode == (file::MODE_READ | file::MODE_WRITE)
201+
|| self.mode == (file::MODE_READ | file::MODE_WRITE | file::MODE_CREATE)
202+
}
153203
}
154204

155205
impl File {
@@ -311,12 +361,12 @@ pub fn stat(_p: &Path) -> io::Result<FileAttr> {
311361
unsupported()
312362
}
313363

314-
pub fn lstat(_p: &Path) -> io::Result<FileAttr> {
315-
unsupported()
364+
pub fn lstat(p: &Path) -> io::Result<FileAttr> {
365+
stat(p)
316366
}
317367

318-
pub fn canonicalize(_p: &Path) -> io::Result<PathBuf> {
319-
unsupported()
368+
pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
369+
crate::path::absolute(p)
320370
}
321371

322372
pub fn copy(_from: &Path, _to: &Path) -> io::Result<u64> {

‎src/doc/book

Submodule book updated 203 files

‎src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- [What is rustc?](what-is-rustc.md)
44
- [Command-line Arguments](command-line-arguments.md)
5+
- [Print Options](command-line-arguments/print-options.md)
56
- [Codegen Options](codegen-options/index.md)
67
- [Jobserver](jobserver.md)
78
- [Lints](lints/index.md)
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.