Skip to content

Commit d192d20

Browse files
committed
Auto merge of rust-lang#138859 - matthiaskrgr:rollup-9s1a68j, r=matthiaskrgr
Rollup of 6 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#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 aa8f0fd + deea1a5 commit d192d20

File tree

14 files changed

+173
-69
lines changed

14 files changed

+173
-69
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/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
@@ -46,17 +46,17 @@ pub(crate) unsafe fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {
4646
unsafe { uefi::env::init_globals(image_handle, system_table) };
4747

4848
// Register exit boot services handler
49-
match helpers::create_event(
49+
match helpers::OwnedEvent::new(
5050
r_efi::efi::EVT_SIGNAL_EXIT_BOOT_SERVICES,
5151
r_efi::efi::TPL_NOTIFY,
5252
Some(exit_boot_service_handler),
53-
crate::ptr::null_mut(),
53+
None,
5454
) {
5555
Ok(x) => {
5656
if EXIT_BOOT_SERVICE_EVENT
5757
.compare_exchange(
5858
crate::ptr::null_mut(),
59-
x.as_ptr(),
59+
x.into_raw(),
6060
Ordering::Release,
6161
Ordering::Acquire,
6262
)
@@ -76,7 +76,7 @@ pub unsafe fn cleanup() {
7676
if let Some(exit_boot_service_event) =
7777
NonNull::new(EXIT_BOOT_SERVICE_EVENT.swap(crate::ptr::null_mut(), Ordering::Acquire))
7878
{
79-
let _ = unsafe { helpers::close_event(exit_boot_service_event) };
79+
let _ = unsafe { helpers::OwnedEvent::from_raw(exit_boot_service_event.as_ptr()) };
8080
}
8181
}
8282

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

148148
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
}

src/librustdoc/clean/types.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,13 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
10681068
.meta_item()
10691069
.and_then(|item| rustc_expand::config::parse_cfg(item, sess))
10701070
{
1071+
// The result is unused here but we can gate unstable predicates
1072+
rustc_attr_parsing::cfg_matches(
1073+
cfg_mi,
1074+
tcx.sess,
1075+
rustc_ast::CRATE_NODE_ID,
1076+
Some(tcx.features()),
1077+
);
10711078
match Cfg::parse(cfg_mi) {
10721079
Ok(new_cfg) => cfg &= new_cfg,
10731080
Err(e) => {

src/librustdoc/doctest/rust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl HirCollector<'_> {
9898
let ast_attrs = self.tcx.hir_attrs(self.tcx.local_def_id_to_hir_id(def_id));
9999
if let Some(ref cfg) =
100100
extract_cfg_from_attrs(ast_attrs.iter(), self.tcx, &FxHashSet::default())
101-
&& !cfg.matches(&self.tcx.sess.psess, Some(self.tcx.features()))
101+
&& !cfg.matches(&self.tcx.sess.psess)
102102
{
103103
return;
104104
}

tests/rustdoc-ui/doc-cfg-check-cfg.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Ensure that `doc(cfg())` respects `check-cfg`
2+
// Currently not properly working
3+
#![feature(doc_cfg)]
4+
#![deny(unexpected_cfgs)]
5+
6+
//@revisions: no_check cfg_empty cfg_foo
7+
//@[cfg_empty] compile-flags: --check-cfg cfg()
8+
//@[cfg_foo] compile-flags: --check-cfg cfg(foo)
9+
10+
//@[no_check] check-pass
11+
//@[cfg_empty] check-pass
12+
//@[cfg_empty] known-bug: #138358
13+
//@[cfg_foo] check-pass
14+
15+
#[doc(cfg(foo))]
16+
pub fn foo() {}

tests/rustdoc-ui/doc-cfg-unstable.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// #138113: rustdoc didn't gate unstable predicates inside `doc(cfg(..))`
2+
#![feature(doc_cfg)]
3+
4+
// `cfg_boolean_literals`
5+
#[doc(cfg(false))] //~ ERROR `cfg(false)` is experimental and subject to change
6+
pub fn cfg_boolean_literals() {}
7+
8+
// `cfg_version`
9+
#[doc(cfg(sanitize = "thread"))] //~ ERROR `cfg(sanitize)` is experimental and subject to change
10+
pub fn cfg_sanitize() {}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0658]: `cfg(false)` is experimental and subject to change
2+
--> $DIR/doc-cfg-unstable.rs:5:11
3+
|
4+
LL | #[doc(cfg(false))]
5+
| ^^^^^
6+
|
7+
= note: see issue #131204 <https://github.com/rust-lang/rust/issues/131204> for more information
8+
= help: add `#![feature(cfg_boolean_literals)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0658]: `cfg(sanitize)` is experimental and subject to change
12+
--> $DIR/doc-cfg-unstable.rs:9:11
13+
|
14+
LL | #[doc(cfg(sanitize = "thread"))]
15+
| ^^^^^^^^^^^^^^^^^^^
16+
|
17+
= note: see issue #39699 <https://github.com/rust-lang/rust/issues/39699> for more information
18+
= help: add `#![feature(cfg_sanitize)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
21+
error: aborting due to 2 previous errors
22+
23+
For more information about this error, try `rustc --explain E0658`.
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fn retry() -> impl Sized {}
2+
3+
struct Core<T>(T);
4+
5+
impl Core<XXX> { //~ ERROR cannot find type `XXX` in this scope
6+
pub fn spawn(self) {}
7+
}
8+
9+
fn main() {
10+
let core = Core(1);
11+
core.spawn(retry()); //~ ERROR this method takes 0 arguments but 1 argument was supplied
12+
}

0 commit comments

Comments
 (0)