Skip to content

Commit 7e6d6e5

Browse files
committed
Auto merge of #75609 - tmandry:rollup-yrcmgke, r=tmandry
Rollup of 10 pull requests Successful merges: - #74204 (Don't visit foreign function bodies when lowering ast to hir) - #74314 (rustc_typeck: construct {Closure,Generator}Substs more directly.) - #74346 (Use LocalDefId instead of HirId for reachable_set elements.) - #74399 (Move DelaySpanBugEmitted to ty::context) - #75177 (Add regression test for issue-66768) - #75223 (Add #[track_caller] to `Session::delay_span_bug`) - #75423 (Move to intra-doc links for /library/core/src/hint.rs) - #75485 (pin docs: add some forward references) - #75569 (Bump minor version of emsdk to 1.38.47) - #75596 (Switch to intra-doc links in /sys/windows/ext/{ffi,fs,process}.rs) Failed merges: r? @ghost
2 parents 9b4db69 + e46b1ef commit 7e6d6e5

File tree

20 files changed

+455
-196
lines changed

20 files changed

+455
-196
lines changed

library/core/src/hint.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::intrinsics;
2424
/// Otherwise, consider using the [`unreachable!`] macro, which does not allow
2525
/// optimizations but will panic when executed.
2626
///
27-
/// [`unreachable!`]: ../macro.unreachable.html
2827
///
2928
/// # Example
3029
///
@@ -61,7 +60,7 @@ pub const unsafe fn unreachable_unchecked() -> ! {
6160
/// **Note**: On platforms that do not support receiving spin-loop hints this function does not
6261
/// do anything at all.
6362
///
64-
/// [`core::sync::atomic::spin_loop_hint`]: ../sync/atomic/fn.spin_loop_hint.html
63+
/// [`core::sync::atomic::spin_loop_hint`]: crate::sync::atomic::spin_loop_hint
6564
#[inline]
6665
#[unstable(feature = "renamed_spin_loop", issue = "55002")]
6766
pub fn spin_loop() {

library/core/src/pin.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
//! as moving an object with pointers to itself will invalidate them, which could cause undefined
77
//! behavior.
88
//!
9-
//! A [`Pin<P>`] ensures that the pointee of any pointer type `P` has a stable location in memory,
10-
//! meaning it cannot be moved elsewhere and its memory cannot be deallocated
11-
//! until it gets dropped. We say that the pointee is "pinned".
9+
//! At a high level, a [`Pin<P>`] ensures that the pointee of any pointer type
10+
//! `P` has a stable location in memory, meaning it cannot be moved elsewhere
11+
//! and its memory cannot be deallocated until it gets dropped. We say that the
12+
//! pointee is "pinned". Things get more subtle when discussing types that
13+
//! combine pinned with non-pinned data; [see below](#projections-and-structural-pinning)
14+
//! for more details.
1215
//!
1316
//! By default, all types in Rust are movable. Rust allows passing all types by-value,
1417
//! and common smart-pointer types such as [`Box<T>`] and `&mut T` allow replacing and
@@ -61,6 +64,10 @@
6164
//!
6265
//! # Example: self-referential struct
6366
//!
67+
//! Before we go into more details to explain the guarantees and choices
68+
//! associated with `Pin<T>`, we discuss some examples for how it might be used.
69+
//! Feel free to [skip to where the theoretical discussion continues](#drop-guarantee).
70+
//!
6471
//! ```rust
6572
//! use std::pin::Pin;
6673
//! use std::marker::PhantomPinned;

library/std/src/sys/windows/ext/ffi.rs

+6-21
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
//! [`OsString`] is the Rust wrapper for owned strings in the
3131
//! preferred representation of the operating system. On Windows,
3232
//! this struct gets augmented with an implementation of the
33-
//! [`OsStringExt`] trait, which has a [`from_wide`] method. This
33+
//! [`OsStringExt`] trait, which has a [`OsStringExt::from_wide`] method. This
3434
//! lets you create an [`OsString`] from a `&[u16]` slice; presumably
3535
//! you get such a slice out of a `WCHAR` Windows API.
3636
//!
3737
//! Similarly, [`OsStr`] is the Rust wrapper for borrowed strings from
3838
//! preferred representation of the operating system. On Windows, the
39-
//! [`OsStrExt`] trait provides the [`encode_wide`] method, which
39+
//! [`OsStrExt`] trait provides the [`OsStrExt::encode_wide`] method, which
4040
//! outputs an [`EncodeWide`] iterator. You can [`collect`] this
4141
//! iterator, for example, to obtain a `Vec<u16>`; you can later get a
4242
//! pointer to this vector's contents and feed it to Windows APIs.
@@ -47,15 +47,8 @@
4747
//! ill-formed UTF-16.
4848
//!
4949
//! [ill-formed-utf-16]: https://simonsapin.github.io/wtf-8/#ill-formed-utf-16
50-
//! [`OsString`]: ../../../ffi/struct.OsString.html
51-
//! [`OsStr`]: ../../../ffi/struct.OsStr.html
52-
//! [`OsStringExt`]: trait.OsStringExt.html
53-
//! [`OsStrExt`]: trait.OsStrExt.html
54-
//! [`EncodeWide`]: struct.EncodeWide.html
55-
//! [`from_wide`]: trait.OsStringExt.html#tymethod.from_wide
56-
//! [`encode_wide`]: trait.OsStrExt.html#tymethod.encode_wide
57-
//! [`collect`]: ../../../iter/trait.Iterator.html#method.collect
58-
//! [U+FFFD]: ../../../char/constant.REPLACEMENT_CHARACTER.html
50+
//! [`collect`]: crate::iter::Iterator::collect
51+
//! [U+FFFD]: crate::char::REPLACEMENT_CHARACTER
5952
6053
#![stable(feature = "rust1", since = "1.0.0")]
6154

@@ -68,14 +61,12 @@ use crate::sys_common::{AsInner, FromInner};
6861
pub use crate::sys_common::wtf8::EncodeWide;
6962

7063
/// Windows-specific extensions to [`OsString`].
71-
///
72-
/// [`OsString`]: ../../../../std/ffi/struct.OsString.html
7364
#[stable(feature = "rust1", since = "1.0.0")]
7465
pub trait OsStringExt {
7566
/// Creates an `OsString` from a potentially ill-formed UTF-16 slice of
7667
/// 16-bit code units.
7768
///
78-
/// This is lossless: calling [`encode_wide`] on the resulting string
69+
/// This is lossless: calling [`OsStrExt::encode_wide`] on the resulting string
7970
/// will always return the original code units.
8071
///
8172
/// # Examples
@@ -89,8 +80,6 @@ pub trait OsStringExt {
8980
///
9081
/// let string = OsString::from_wide(&source[..]);
9182
/// ```
92-
///
93-
/// [`encode_wide`]: ./trait.OsStrExt.html#tymethod.encode_wide
9483
#[stable(feature = "rust1", since = "1.0.0")]
9584
fn from_wide(wide: &[u16]) -> Self;
9685
}
@@ -103,14 +92,12 @@ impl OsStringExt for OsString {
10392
}
10493

10594
/// Windows-specific extensions to [`OsStr`].
106-
///
107-
/// [`OsStr`]: ../../../../std/ffi/struct.OsStr.html
10895
#[stable(feature = "rust1", since = "1.0.0")]
10996
pub trait OsStrExt {
11097
/// Re-encodes an `OsStr` as a wide character sequence, i.e., potentially
11198
/// ill-formed UTF-16.
11299
///
113-
/// This is lossless: calling [`OsString::from_wide`] and then
100+
/// This is lossless: calling [`OsStringExt::from_wide`] and then
114101
/// `encode_wide` on the result will yield the original code units.
115102
/// Note that the encoding does not add a final null terminator.
116103
///
@@ -128,8 +115,6 @@ pub trait OsStrExt {
128115
/// let result: Vec<u16> = string.encode_wide().collect();
129116
/// assert_eq!(&source[..], &result[..]);
130117
/// ```
131-
///
132-
/// [`OsString::from_wide`]: ./trait.OsStringExt.html#tymethod.from_wide
133118
#[stable(feature = "rust1", since = "1.0.0")]
134119
fn encode_wide(&self) -> EncodeWide<'_>;
135120
}

library/std/src/sys/windows/ext/fs.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use crate::path::Path;
88
use crate::sys;
99
use crate::sys_common::{AsInner, AsInnerMut};
1010

11-
/// Windows-specific extensions to [`File`].
12-
///
13-
/// [`File`]: ../../../fs/struct.File.html
11+
/// Windows-specific extensions to [`fs::File`].
1412
#[stable(feature = "file_offset", since = "1.15.0")]
1513
pub trait FileExt {
1614
/// Seeks to a given position and reads a number of bytes.
@@ -94,8 +92,6 @@ impl FileExt for fs::File {
9492
}
9593

9694
/// Windows-specific extensions to [`fs::OpenOptions`].
97-
///
98-
/// [`fs::OpenOptions`]: ../../../../std/fs/struct.OpenOptions.html
9995
#[stable(feature = "open_options_ext", since = "1.10.0")]
10096
pub trait OpenOptionsExt {
10197
/// Overrides the `dwDesiredAccess` argument to the call to [`CreateFile`]
@@ -295,7 +291,6 @@ impl OpenOptionsExt for OpenOptions {
295291
/// The data members that this trait exposes correspond to the members
296292
/// of the [`BY_HANDLE_FILE_INFORMATION`] structure.
297293
///
298-
/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html
299294
/// [`BY_HANDLE_FILE_INFORMATION`]:
300295
/// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-by_handle_file_information
301296
#[stable(feature = "metadata_ext", since = "1.1.0")]
@@ -499,11 +494,9 @@ impl MetadataExt for Metadata {
499494
}
500495
}
501496

502-
/// Windows-specific extensions to [`FileType`].
497+
/// Windows-specific extensions to [`fs::FileType`].
503498
///
504499
/// On Windows, a symbolic link knows whether it is a file or directory.
505-
///
506-
/// [`FileType`]: ../../../../std/fs/struct.FileType.html
507500
#[unstable(feature = "windows_file_type_ext", issue = "none")]
508501
pub trait FileTypeExt {
509502
/// Returns `true` if this file type is a symbolic link that is also a directory.

library/std/src/sys/windows/ext/process.rs

-4
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ impl IntoRawHandle for process::ChildStderr {
7373
}
7474

7575
/// Windows-specific extensions to [`process::ExitStatus`].
76-
///
77-
/// [`process::ExitStatus`]: ../../../../std/process/struct.ExitStatus.html
7876
#[stable(feature = "exit_status_from", since = "1.12.0")]
7977
pub trait ExitStatusExt {
8078
/// Creates a new `ExitStatus` from the raw underlying `u32` return value of
@@ -91,8 +89,6 @@ impl ExitStatusExt for process::ExitStatus {
9189
}
9290

9391
/// Windows-specific extensions to the [`process::Command`] builder.
94-
///
95-
/// [`process::Command`]: ../../../../std/process/struct.Command.html
9692
#[stable(feature = "windows_process_extensions", since = "1.16.0")]
9793
pub trait CommandExt {
9894
/// Sets the [process creation flags][1] to be passed to `CreateProcess`.

src/ci/docker/scripts/emscripten.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ exit 1
1919

2020
git clone https://github.com/emscripten-core/emsdk.git /emsdk-portable
2121
cd /emsdk-portable
22-
hide_output ./emsdk install 1.38.46-upstream
23-
./emsdk activate 1.38.46-upstream
22+
hide_output ./emsdk install 1.38.47-upstream
23+
./emsdk activate 1.38.47-upstream

src/librustc_ast_lowering/item.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::Arena;
55
use rustc_ast::ast::*;
66
use rustc_ast::node_id::NodeMap;
77
use rustc_ast::ptr::P;
8-
use rustc_ast::visit::{self, AssocCtxt, Visitor};
8+
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
99
use rustc_data_structures::fx::FxHashSet;
1010
use rustc_errors::struct_span_err;
1111
use rustc_hir as hir;
@@ -75,6 +75,18 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
7575
}
7676
}
7777

78+
fn visit_fn(&mut self, fk: FnKind<'a>, sp: Span, _: NodeId) {
79+
match fk {
80+
FnKind::Fn(FnCtxt::Foreign, _, sig, _, _) => {
81+
self.visit_fn_header(&sig.header);
82+
visit::walk_fn_decl(self, &sig.decl);
83+
// Don't visit the foreign function body even if it has one, since lowering the
84+
// body would have no meaning and will have already been caught as a parse error.
85+
}
86+
_ => visit::walk_fn(self, fk, sp),
87+
}
88+
}
89+
7890
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
7991
self.lctx.with_hir_id_owner(item.id, |lctx| match ctxt {
8092
AssocCtxt::Trait => {

src/librustc_codegen_ssa/back/symbol_export.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
6161
let mut reachable_non_generics: DefIdMap<_> = tcx
6262
.reachable_set(LOCAL_CRATE)
6363
.iter()
64-
.filter_map(|&hir_id| {
64+
.filter_map(|&def_id| {
6565
// We want to ignore some FFI functions that are not exposed from
6666
// this crate. Reachable FFI functions can be lumped into two
6767
// categories:
@@ -75,9 +75,8 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
7575
//
7676
// As a result, if this id is an FFI item (foreign item) then we only
7777
// let it through if it's included statically.
78-
match tcx.hir().get(hir_id) {
78+
match tcx.hir().get(tcx.hir().local_def_id_to_hir_id(def_id)) {
7979
Node::ForeignItem(..) => {
80-
let def_id = tcx.hir().local_def_id(hir_id);
8180
tcx.is_statically_included_foreign_item(def_id).then_some(def_id)
8281
}
8382

@@ -87,7 +86,6 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
8786
..
8887
})
8988
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) => {
90-
let def_id = tcx.hir().local_def_id(hir_id);
9189
let generics = tcx.generics_of(def_id);
9290
if !generics.requires_monomorphization(tcx)
9391
// Functions marked with #[inline] are codegened with "internal"
@@ -361,7 +359,7 @@ fn upstream_drop_glue_for_provider<'tcx>(
361359

362360
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
363361
if let Some(def_id) = def_id.as_local() {
364-
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().local_def_id_to_hir_id(def_id))
362+
!tcx.reachable_set(LOCAL_CRATE).contains(&def_id)
365363
} else {
366364
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
367365
}

src/librustc_middle/query/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,8 @@ rustc_queries! {
740740
}
741741

742742
Other {
743-
query reachable_set(_: CrateNum) -> &'tcx HirIdSet {
743+
query reachable_set(_: CrateNum) -> FxHashSet<LocalDefId> {
744+
storage(ArenaCacheSelector<'tcx>)
744745
desc { "reachability" }
745746
}
746747

src/librustc_middle/ty/consts/kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub enum ConstKind<'tcx> {
3434

3535
/// A placeholder for a const which could not be computed; this is
3636
/// propagated to avoid useless error messages.
37-
Error(ty::sty::DelaySpanBugEmitted),
37+
Error(ty::DelaySpanBugEmitted),
3838
}
3939

4040
#[cfg(target_arch = "x86_64")]

src/librustc_middle/ty/context.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ use std::mem;
6565
use std::ops::{Bound, Deref};
6666
use std::sync::Arc;
6767

68+
/// A type that is not publicly constructable. This prevents people from making `TyKind::Error`
69+
/// except through `tcx.err*()`, which are in this module.
70+
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
71+
#[derive(TyEncodable, TyDecodable, HashStable)]
72+
pub struct DelaySpanBugEmitted(());
73+
6874
type InternedSet<'tcx, T> = ShardedHashMap<Interned<'tcx, T>, ()>;
6975

7076
pub struct CtxtInterners<'tcx> {
@@ -1171,18 +1177,15 @@ impl<'tcx> TyCtxt<'tcx> {
11711177
#[track_caller]
11721178
pub fn ty_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Ty<'tcx> {
11731179
self.sess.delay_span_bug(span, msg);
1174-
self.mk_ty(Error(super::sty::DelaySpanBugEmitted(())))
1180+
self.mk_ty(Error(DelaySpanBugEmitted(())))
11751181
}
11761182

11771183
/// Like `err` but for constants.
11781184
#[track_caller]
11791185
pub fn const_error(self, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
11801186
self.sess
11811187
.delay_span_bug(DUMMY_SP, "ty::ConstKind::Error constructed but no error reported.");
1182-
self.mk_const(ty::Const {
1183-
val: ty::ConstKind::Error(super::sty::DelaySpanBugEmitted(())),
1184-
ty,
1185-
})
1188+
self.mk_const(ty::Const { val: ty::ConstKind::Error(DelaySpanBugEmitted(())), ty })
11861189
}
11871190

11881191
pub fn consider_optimizing<T: Fn() -> String>(&self, msg: T) -> bool {

src/librustc_middle/ty/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub use self::sty::{Binder, BoundTy, BoundTyKind, BoundVar, DebruijnIndex, INNER
6060
pub use self::sty::{BoundRegion, EarlyBoundRegion, FreeRegion, Region};
6161
pub use self::sty::{CanonicalPolyFnSig, FnSig, GenSig, PolyFnSig, PolyGenSig};
6262
pub use self::sty::{ClosureSubsts, GeneratorSubsts, TypeAndMut, UpvarSubsts};
63+
pub use self::sty::{ClosureSubstsParts, GeneratorSubstsParts};
6364
pub use self::sty::{ConstVid, FloatVid, IntVid, RegionVid, TyVid};
6465
pub use self::sty::{ExistentialPredicate, InferTy, ParamConst, ParamTy, ProjectionTy};
6566
pub use self::sty::{ExistentialProjection, PolyExistentialProjection};
@@ -72,8 +73,8 @@ pub use self::binding::BindingMode::*;
7273

7374
pub use self::context::{tls, FreeRegionInfo, TyCtxt};
7475
pub use self::context::{
75-
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, ResolvedOpaqueTy,
76-
UserType, UserTypeAnnotationIndex,
76+
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
77+
DelaySpanBugEmitted, ResolvedOpaqueTy, UserType, UserTypeAnnotationIndex,
7778
};
7879
pub use self::context::{
7980
CtxtInterners, GeneratorInteriorTypeCause, GlobalCtxt, Lift, TypeckResults,

src/librustc_middle/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rustc_hir as hir;
4343
use rustc_hir::def::DefKind;
4444
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId};
4545
use rustc_hir::lang_items::{LangItem, LanguageItems};
46-
use rustc_hir::{Crate, HirIdSet, ItemLocalId, TraitCandidate};
46+
use rustc_hir::{Crate, ItemLocalId, TraitCandidate};
4747
use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec};
4848
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
4949
use rustc_session::utils::NativeLibKind;

0 commit comments

Comments
 (0)