Skip to content

Commit 1f9fad5

Browse files
committed
Auto merge of rust-lang#138856 - matthiaskrgr:rollup-o5c20kr, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#138236 (uefi: Add OwnedEvent abstraction) - rust-lang#138293 (rustdoc: Gate unstable `doc(cfg())` predicates) - rust-lang#138509 (Add test to ensure no index out of bounds panic (rust-lang#135474)) - rust-lang#138631 (Update test for SGX now implementing `read_buf`) - rust-lang#138662 (Implement some basics in UEFI fs) - rust-lang#138837 (resolve: Avoid remaining unstable iteration) - rust-lang#138849 (doc: rename reference #create-a-configtoml to #create-a-bootstraptoml) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 97fc1f6 + 9d2bb2b commit 1f9fad5

File tree

15 files changed

+234
-81
lines changed

15 files changed

+234
-81
lines changed

bootstrap.example.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Sample TOML configuration file for building Rust.
22
#
33
# To configure bootstrap, run `./configure` or `./x.py setup`.
4-
# See https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#create-a-configtoml for more information.
4+
# See https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#create-a-bootstraptoml for more information.
55
#
66
# All options are commented out by default in this file, and they're commented
77
# out with their default values. The build system by default looks for
@@ -446,7 +446,7 @@
446446
# a specific version.
447447
#ccache = false
448448

449-
# List of paths to exclude from the build and test processes.
449+
# List of paths to exclude from the build and test processes.
450450
# For example, exclude = ["tests/ui", "src/tools/tidy"].
451451
#exclude = []
452452

compiler/rustc_resolve/src/late.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl RibKind<'_> {
272272
/// resolving, the name is looked up from inside out.
273273
#[derive(Debug)]
274274
pub(crate) struct Rib<'ra, R = Res> {
275-
pub bindings: FxHashMap<Ident, R>,
275+
pub bindings: FxIndexMap<Ident, R>,
276276
pub patterns_with_skipped_bindings: UnordMap<DefId, Vec<(Span, Result<(), ErrorGuaranteed>)>>,
277277
pub kind: RibKind<'ra>,
278278
}
@@ -1642,8 +1642,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
16421642

16431643
// Allow all following defaults to refer to this type parameter.
16441644
let i = &Ident::with_dummy_span(param.ident.name);
1645-
forward_ty_ban_rib.bindings.remove(i);
1646-
forward_ty_ban_rib_const_param_ty.bindings.remove(i);
1645+
forward_ty_ban_rib.bindings.swap_remove(i);
1646+
forward_ty_ban_rib_const_param_ty.bindings.swap_remove(i);
16471647
}
16481648
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
16491649
// Const parameters can't have param bounds.
@@ -1678,8 +1678,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
16781678

16791679
// Allow all following defaults to refer to this const parameter.
16801680
let i = &Ident::with_dummy_span(param.ident.name);
1681-
forward_const_ban_rib.bindings.remove(i);
1682-
forward_const_ban_rib_const_param_ty.bindings.remove(i);
1681+
forward_const_ban_rib.bindings.swap_remove(i);
1682+
forward_const_ban_rib_const_param_ty.bindings.swap_remove(i);
16831683
}
16841684
}
16851685
}
@@ -2888,7 +2888,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28882888
break;
28892889
}
28902890

2891-
#[allow(rustc::potential_query_instability)] // FIXME
28922891
seen_bindings
28932892
.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
28942893
}
@@ -4003,7 +4002,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
40034002
}
40044003
}
40054004

4006-
fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxHashMap<Ident, Res> {
4005+
fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut FxIndexMap<Ident, Res> {
40074006
&mut self.ribs[ns].last_mut().unwrap().bindings
40084007
}
40094008

compiler/rustc_resolve/src/late/diagnostics.rs

-5
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
830830
if let Some(rib) = &self.last_block_rib
831831
&& let RibKind::Normal = rib.kind
832832
{
833-
#[allow(rustc::potential_query_instability)] // FIXME
834833
for (ident, &res) in &rib.bindings {
835834
if let Res::Local(_) = res
836835
&& path.len() == 1
@@ -1019,7 +1018,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
10191018
if let Some(err_code) = err.code {
10201019
if err_code == E0425 {
10211020
for label_rib in &self.label_ribs {
1022-
#[allow(rustc::potential_query_instability)] // FIXME
10231021
for (label_ident, node_id) in &label_rib.bindings {
10241022
let ident = path.last().unwrap().ident;
10251023
if format!("'{ident}") == label_ident.to_string() {
@@ -2265,7 +2263,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
22652263
};
22662264

22672265
// Locals and type parameters
2268-
#[allow(rustc::potential_query_instability)] // FIXME
22692266
for (ident, &res) in &rib.bindings {
22702267
if filter_fn(res) && ident.span.ctxt() == rib_ctxt {
22712268
names.push(TypoSuggestion::typo_from_ident(*ident, res));
@@ -2793,7 +2790,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
27932790
let within_scope = self.is_label_valid_from_rib(rib_index);
27942791

27952792
let rib = &self.label_ribs[rib_index];
2796-
#[allow(rustc::potential_query_instability)] // FIXME
27972793
let names = rib
27982794
.bindings
27992795
.iter()
@@ -2805,7 +2801,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
28052801
// Upon finding a similar name, get the ident that it was from - the span
28062802
// contained within helps make a useful diagnostic. In addition, determine
28072803
// whether this candidate is within scope.
2808-
#[allow(rustc::potential_query_instability)] // FIXME
28092804
let (ident, _) = rib.bindings.iter().find(|(ident, _)| ident.name == symbol).unwrap();
28102805
(*ident, within_scope)
28112806
})

library/std/src/net/tcp/tests.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,8 @@ fn read_buf() {
315315
let mut buf = BorrowedBuf::from(buf.as_mut_slice());
316316
t!(s.read_buf(buf.unfilled()));
317317
assert_eq!(buf.filled(), &[1, 2, 3, 4]);
318-
319-
// FIXME: sgx uses default_read_buf that initializes the buffer.
320-
if cfg!(not(target_env = "sgx")) {
321-
// TcpStream::read_buf should omit buffer initialization.
322-
assert_eq!(buf.init_len(), 4);
323-
}
318+
// TcpStream::read_buf should omit buffer initialization.
319+
assert_eq!(buf.init_len(), 4);
324320

325321
t.join().ok().expect("thread panicked");
326322
})

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

+61-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,57 @@ 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+
const fn is_mode_valid(&self) -> bool {
197+
// Valid Combinations: Read, Read/Write, Read/Write/Create
198+
self.mode == file::MODE_READ
199+
|| self.mode == (file::MODE_READ | file::MODE_WRITE)
200+
|| self.mode == (file::MODE_READ | file::MODE_WRITE | file::MODE_CREATE)
201+
}
153202
}
154203

155204
impl File {
@@ -311,12 +360,12 @@ pub fn stat(_p: &Path) -> io::Result<FileAttr> {
311360
unsupported()
312361
}
313362

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

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

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

library/std/src/sys/pal/uefi/helpers.rs

+53-33
Original file line numberDiff line numberDiff line change
@@ -120,39 +120,6 @@ pub(crate) fn open_protocol<T>(
120120
}
121121
}
122122

123-
pub(crate) fn create_event(
124-
signal: u32,
125-
tpl: efi::Tpl,
126-
handler: Option<efi::EventNotify>,
127-
context: *mut crate::ffi::c_void,
128-
) -> io::Result<NonNull<crate::ffi::c_void>> {
129-
let boot_services: NonNull<efi::BootServices> =
130-
boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast();
131-
let mut event: r_efi::efi::Event = crate::ptr::null_mut();
132-
let r = unsafe {
133-
let create_event = (*boot_services.as_ptr()).create_event;
134-
(create_event)(signal, tpl, handler, context, &mut event)
135-
};
136-
if r.is_error() {
137-
Err(crate::io::Error::from_raw_os_error(r.as_usize()))
138-
} else {
139-
NonNull::new(event).ok_or(const_error!(io::ErrorKind::Other, "null protocol"))
140-
}
141-
}
142-
143-
/// # SAFETY
144-
/// - The supplied event must be valid
145-
pub(crate) unsafe fn close_event(evt: NonNull<crate::ffi::c_void>) -> io::Result<()> {
146-
let boot_services: NonNull<efi::BootServices> =
147-
boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast();
148-
let r = unsafe {
149-
let close_event = (*boot_services.as_ptr()).close_event;
150-
(close_event)(evt.as_ptr())
151-
};
152-
153-
if r.is_error() { Err(crate::io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) }
154-
}
155-
156123
/// Gets the Protocol for current system handle.
157124
///
158125
/// Note: Some protocols need to be manually freed. It is the caller's responsibility to do so.
@@ -735,3 +702,56 @@ impl Drop for ServiceProtocol {
735702
}
736703
}
737704
}
705+
706+
#[repr(transparent)]
707+
pub(crate) struct OwnedEvent(NonNull<crate::ffi::c_void>);
708+
709+
impl OwnedEvent {
710+
pub(crate) fn new(
711+
signal: u32,
712+
tpl: efi::Tpl,
713+
handler: Option<efi::EventNotify>,
714+
context: Option<NonNull<crate::ffi::c_void>>,
715+
) -> io::Result<Self> {
716+
let boot_services: NonNull<efi::BootServices> =
717+
boot_services().ok_or(BOOT_SERVICES_UNAVAILABLE)?.cast();
718+
let mut event: r_efi::efi::Event = crate::ptr::null_mut();
719+
let context = context.map(NonNull::as_ptr).unwrap_or(crate::ptr::null_mut());
720+
721+
let r = unsafe {
722+
let create_event = (*boot_services.as_ptr()).create_event;
723+
(create_event)(signal, tpl, handler, context, &mut event)
724+
};
725+
726+
if r.is_error() {
727+
Err(crate::io::Error::from_raw_os_error(r.as_usize()))
728+
} else {
729+
NonNull::new(event)
730+
.ok_or(const_error!(io::ErrorKind::Other, "failed to create event"))
731+
.map(Self)
732+
}
733+
}
734+
735+
pub(crate) fn into_raw(self) -> *mut crate::ffi::c_void {
736+
let r = self.0.as_ptr();
737+
crate::mem::forget(self);
738+
r
739+
}
740+
741+
/// SAFETY: Assumes that ptr is a non-null valid UEFI event
742+
pub(crate) unsafe fn from_raw(ptr: *mut crate::ffi::c_void) -> Self {
743+
Self(unsafe { NonNull::new_unchecked(ptr) })
744+
}
745+
}
746+
747+
impl Drop for OwnedEvent {
748+
fn drop(&mut self) {
749+
if let Some(boot_services) = boot_services() {
750+
let bt: NonNull<r_efi::efi::BootServices> = boot_services.cast();
751+
unsafe {
752+
let close_event = (*bt.as_ptr()).close_event;
753+
(close_event)(self.0.as_ptr())
754+
};
755+
}
756+
}
757+
}

library/std/src/sys/pal/uefi/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ pub(crate) unsafe fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {
4747
unsafe { uefi::env::init_globals(image_handle, system_table) };
4848

4949
// Register exit boot services handler
50-
match helpers::create_event(
50+
match helpers::OwnedEvent::new(
5151
r_efi::efi::EVT_SIGNAL_EXIT_BOOT_SERVICES,
5252
r_efi::efi::TPL_NOTIFY,
5353
Some(exit_boot_service_handler),
54-
crate::ptr::null_mut(),
54+
None,
5555
) {
5656
Ok(x) => {
5757
if EXIT_BOOT_SERVICE_EVENT
5858
.compare_exchange(
5959
crate::ptr::null_mut(),
60-
x.as_ptr(),
60+
x.into_raw(),
6161
Ordering::Release,
6262
Ordering::Acquire,
6363
)
@@ -77,7 +77,7 @@ pub unsafe fn cleanup() {
7777
if let Some(exit_boot_service_event) =
7878
NonNull::new(EXIT_BOOT_SERVICE_EVENT.swap(crate::ptr::null_mut(), Ordering::Acquire))
7979
{
80-
let _ = unsafe { helpers::close_event(exit_boot_service_event) };
80+
let _ = unsafe { helpers::OwnedEvent::from_raw(exit_boot_service_event.as_ptr()) };
8181
}
8282
}
8383

@@ -143,7 +143,7 @@ pub fn abort_internal() -> ! {
143143
if let Some(exit_boot_service_event) =
144144
NonNull::new(EXIT_BOOT_SERVICE_EVENT.load(Ordering::Acquire))
145145
{
146-
let _ = unsafe { helpers::close_event(exit_boot_service_event) };
146+
let _ = unsafe { helpers::OwnedEvent::from_raw(exit_boot_service_event.as_ptr()) };
147147
}
148148

149149
if let (Some(boot_services), Some(handle)) =

src/librustdoc/clean/cfg.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{mem, ops};
88

99
use rustc_ast::{LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit};
1010
use rustc_data_structures::fx::FxHashSet;
11-
use rustc_feature::Features;
1211
use rustc_session::parse::ParseSess;
1312
use rustc_span::Span;
1413
use rustc_span::symbol::{Symbol, sym};
@@ -132,18 +131,13 @@ impl Cfg {
132131
/// Checks whether the given configuration can be matched in the current session.
133132
///
134133
/// Equivalent to `attr::cfg_matches`.
135-
// FIXME: Actually make use of `features`.
136-
pub(crate) fn matches(&self, psess: &ParseSess, features: Option<&Features>) -> bool {
134+
pub(crate) fn matches(&self, psess: &ParseSess) -> bool {
137135
match *self {
138136
Cfg::False => false,
139137
Cfg::True => true,
140-
Cfg::Not(ref child) => !child.matches(psess, features),
141-
Cfg::All(ref sub_cfgs) => {
142-
sub_cfgs.iter().all(|sub_cfg| sub_cfg.matches(psess, features))
143-
}
144-
Cfg::Any(ref sub_cfgs) => {
145-
sub_cfgs.iter().any(|sub_cfg| sub_cfg.matches(psess, features))
146-
}
138+
Cfg::Not(ref child) => !child.matches(psess),
139+
Cfg::All(ref sub_cfgs) => sub_cfgs.iter().all(|sub_cfg| sub_cfg.matches(psess)),
140+
Cfg::Any(ref sub_cfgs) => sub_cfgs.iter().any(|sub_cfg| sub_cfg.matches(psess)),
147141
Cfg::Cfg(name, value) => psess.config.contains(&(name, value)),
148142
}
149143
}

0 commit comments

Comments
 (0)