Skip to content

Commit

Permalink
Auto merge of rust-lang#97000 - matthiaskrgr:rollup-qh3lhu8, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#96932 (Clarify what values `BorrowedHandle`, `OwnedHandle` etc. can hold.)
 - rust-lang#96948 (Add test of matches macro for trailing commas)
 - rust-lang#96988 (Fix platform support links.)
 - rust-lang#96989 (Be more precise than DefPathData::Misc.)
 - rust-lang#96993 (rustdoc: fix GUI crash when searching for magic JS property values)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 13, 2022
2 parents 925e774 + 5a111df commit f001f93
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 56 deletions.
14 changes: 8 additions & 6 deletions compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,16 @@ pub enum DefPathData {
// they are treated specially by the `def_path` function.
/// The crate root (marker).
CrateRoot,
// Catch-all for random `DefId` things like `DUMMY_NODE_ID`.
Misc,

// Different kinds of items and item-like things:
/// An impl.
Impl,
/// An `extern` block.
ForeignMod,
/// A `use` item.
Use,
/// A global asm item.
GlobalAsm,
/// Something in the type namespace.
TypeNs(Symbol),
/// Something in the value namespace.
Expand Down Expand Up @@ -443,9 +445,8 @@ impl DefPathData {
match *self {
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),

Impl | ForeignMod | CrateRoot | Misc | ClosureExpr | Ctor | AnonConst | ImplTrait => {
None
}
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | ClosureExpr | Ctor | AnonConst
| ImplTrait => None,
}
}

Expand All @@ -459,7 +460,8 @@ impl DefPathData {
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
Impl => DefPathDataName::Anon { namespace: kw::Impl },
ForeignMod => DefPathDataName::Anon { namespace: kw::Extern },
Misc => DefPathDataName::Anon { namespace: sym::misc },
Use => DefPathDataName::Anon { namespace: kw::Use },
GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
ClosureExpr => DefPathDataName::Anon { namespace: sym::closure },
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,7 @@ impl<'tcx> TyCtxt<'tcx> {
.filter(|item| item.kind == AssocKind::Fn && item.defaultness.has_value())
}

/// Look up the name of a definition across crates. This does not look at HIR.
fn opt_item_name(self, def_id: DefId) -> Option<Symbol> {
if let Some(cnum) = def_id.as_crate_root() {
Some(self.crate_name(cnum))
Expand All @@ -2014,16 +2015,11 @@ impl<'tcx> TyCtxt<'tcx> {

/// Look up the name of a definition across crates. This does not look at HIR.
///
/// When possible, this function should be used for cross-crate lookups over
/// [`opt_item_name`] to avoid invalidating the incremental cache. If you
/// need to handle items without a name, or HIR items that will not be
/// serialized cross-crate, or if you need the span of the item, use
/// This method will ICE if the corresponding item does not have a name. In these cases, use
/// [`opt_item_name`] instead.
///
/// [`opt_item_name`]: Self::opt_item_name
pub fn item_name(self, id: DefId) -> Symbol {
// Look at cross-crate items first to avoid invalidating the incremental cache
// unless we have to.
self.opt_item_name(id).unwrap_or_else(|| {
bug!("item_name: no name for {:?}", self.def_path(id));
})
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
visit::walk_item(self, i);
return self.visit_macro_invoc(i.id);
}
ItemKind::GlobalAsm(..) => DefPathData::Misc,
ItemKind::GlobalAsm(..) => DefPathData::GlobalAsm,
ItemKind::Use(..) => {
return visit::walk_item(self, i);
}
Expand Down Expand Up @@ -160,11 +160,11 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
}

fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
self.create_def(id, DefPathData::Misc, use_tree.span);
self.create_def(id, DefPathData::Use, use_tree.span);
match use_tree.kind {
UseTreeKind::Simple(_, id1, id2) => {
self.create_def(id1, DefPathData::Misc, use_tree.prefix.span);
self.create_def(id2, DefPathData::Misc, use_tree.prefix.span);
self.create_def(id1, DefPathData::Use, use_tree.prefix.span);
self.create_def(id2, DefPathData::Use, use_tree.prefix.span);
}
UseTreeKind::Glob => (),
UseTreeKind::Nested(..) => {}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {

// These should never show up as `path_append` arguments.
DefPathData::CrateRoot
| DefPathData::Misc
| DefPathData::Use
| DefPathData::GlobalAsm
| DefPathData::Impl
| DefPathData::MacroNs(_)
| DefPathData::LifetimeNs(_) => {
Expand Down
31 changes: 19 additions & 12 deletions library/std/src/os/windows/io/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
/// so it can be used in FFI in places where a handle is passed as an argument,
/// it is not captured or consumed.
///
/// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
/// sometimes a valid handle value. See [here] for the full story.
/// Note that it *may* have the value `-1`, which in `BorrowedHandle` always
/// represents a valid handle value, such as [the current process handle], and
/// not `INVALID_HANDLE_VALUE`, despite the two having the same value. See
/// [here] for the full story.
///
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
/// detached from processes, or when `windows_subsystem` is used.
Expand All @@ -33,6 +35,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
/// handle, which is then borrowed under the same lifetime.
///
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
/// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
#[derive(Copy, Clone)]
#[repr(transparent)]
#[unstable(feature = "io_safety", issue = "87074")]
Expand All @@ -45,8 +48,10 @@ pub struct BorrowedHandle<'handle> {
///
/// This closes the handle on drop.
///
/// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is
/// sometimes a valid handle value. See [here] for the full story.
/// Note that it *may* have the value `-1`, which in `OwnedHandle` always
/// represents a valid handle value, such as [the current process handle], and
/// not `INVALID_HANDLE_VALUE`, despite the two having the same value. See
/// [here] for the full story.
///
/// And, it *may* have the value `NULL` (0), which can occur when consoles are
/// detached from processes, or when `windows_subsystem` is used.
Expand All @@ -59,6 +64,7 @@ pub struct BorrowedHandle<'handle> {
/// [`RegCloseKey`]: https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regclosekey
///
/// [here]: https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
/// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
#[repr(transparent)]
#[unstable(feature = "io_safety", issue = "87074")]
pub struct OwnedHandle {
Expand All @@ -75,11 +81,13 @@ pub struct OwnedHandle {
/// `NULL`. This ensures that such FFI calls cannot start using the handle without
/// checking for `NULL` first.
///
/// This type considers any value other than `NULL` to be valid, including `INVALID_HANDLE_VALUE`.
/// This is because APIs that use `NULL` as their sentry value don't treat `INVALID_HANDLE_VALUE`
/// as special.
/// This type may hold any handle value that [`OwnedHandle`] may hold. As with `OwnedHandle`, when
/// it holds `-1`, that value is interpreted as a valid handle value, such as
/// [the current process handle], and not `INVALID_HANDLE_VALUE`.
///
/// If this holds a valid handle, it will close the handle on drop.
/// If this holds a non-null handle, it will close the handle on drop.
///
/// [the current process handle]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess#remarks
#[repr(transparent)]
#[unstable(feature = "io_safety", issue = "87074")]
#[derive(Debug)]
Expand All @@ -95,11 +103,10 @@ pub struct HandleOrNull(OwnedHandle);
/// `INVALID_HANDLE_VALUE`. This ensures that such FFI calls cannot start using the handle without
/// checking for `INVALID_HANDLE_VALUE` first.
///
/// This type considers any value other than `INVALID_HANDLE_VALUE` to be valid, including `NULL`.
/// This is because APIs that use `INVALID_HANDLE_VALUE` as their sentry value may return `NULL`
/// under `windows_subsystem = "windows"` or other situations where I/O devices are detached.
/// This type may hold any handle value that [`OwnedHandle`] may hold, except that when it holds
/// `-1`, that value is interpreted to mean `INVALID_HANDLE_VALUE`.
///
/// If this holds a valid handle, it will close the handle on drop.
/// If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop.
#[repr(transparent)]
#[unstable(feature = "io_safety", issue = "87074")]
#[derive(Debug)]
Expand Down
7 changes: 7 additions & 0 deletions library/std/src/os/windows/io/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ pub trait AsRawHandle {
/// raw handle to the caller, and the handle is only guaranteed
/// to be valid while the original object has not yet been destroyed.
///
/// This function may return null, such as when called on [`Stdin`],
/// [`Stdout`], or [`Stderr`] when the console is detached.
///
/// However, borrowing is not strictly required. See [`AsHandle::as_handle`]
/// for an API which strictly borrows a handle.
///
/// [`Stdin`]: io::Stdin
/// [`Stdout`]: io::Stdout
/// [`Stderr`]: io::Stderr
#[stable(feature = "rust1", since = "1.0.0")]
fn as_raw_handle(&self) -> RawHandle;
}
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
- [Platform Support](platform-support.md)
- [Template for target-specific documentation](platform-support/TEMPLATE.md)
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
- [aarch64-unknown-none-hermitkernel](platform-support/aarch64-unknown-none-hermitkernel.md)
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
- [\*-kmc-solid_\*](platform-support/kmc-solid.md)
- [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md)
- [mips64-openwrt-linux-musl](platform-support/mips64-openwrt-linux-musl.md)
- [nvptx64-nvidia-cuda](platform-support/nvptx64-nvidia-cuda.md)
- [*-unknown-openbsd](platform-support/openbsd.md)
- [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md)
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ window.initSearch = rawSearchIndex => {
*/
let searchIndex;
let currentResults;
const ALIASES = {};
const ALIASES = Object.create(null);
const params = searchState.getQueryStringParams();

// Populate search bar with query string search term when provided,
Expand Down Expand Up @@ -1953,7 +1953,7 @@ window.initSearch = rawSearchIndex => {
}

if (aliases) {
ALIASES[crate] = {};
ALIASES[crate] = Object.create(null);
for (const alias_name in aliases) {
if (!hasOwnPropertyRustdoc(aliases, alias_name)) {
continue;
Expand Down
41 changes: 37 additions & 4 deletions src/test/mir-opt/inline/cycle.g.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,55 @@
fn g() -> () {
let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:11:8: 11:8
let _1: (); // in scope 0 at $DIR/cycle.rs:12:5: 12:12
+ let mut _2: fn() {main}; // in scope 0 at $DIR/cycle.rs:12:5: 12:12
+ let mut _5: (); // in scope 0 at $DIR/cycle.rs:6:5: 6:8
+ scope 1 (inlined f::<fn() {main}>) { // at $DIR/cycle.rs:12:5: 12:12
+ debug g => _2; // in scope 1 at $DIR/cycle.rs:5:6: 5:7
+ let _3: (); // in scope 1 at $DIR/cycle.rs:6:5: 6:8
+ let mut _4: &fn() {main}; // in scope 1 at $DIR/cycle.rs:6:5: 6:6
+ scope 2 (inlined <fn() {main} as Fn<()>>::call - shim(fn() {main})) { // at $DIR/cycle.rs:6:5: 6:8
+ }
+ }

bb0: {
StorageLive(_1); // scope 0 at $DIR/cycle.rs:12:5: 12:12
_1 = f::<fn() {main}>(main) -> bb1; // scope 0 at $DIR/cycle.rs:12:5: 12:12
// mir::Constant
// + span: $DIR/cycle.rs:12:5: 12:6
// + literal: Const { ty: fn(fn() {main}) {f::<fn() {main}>}, val: Value(Scalar(<ZST>)) }
- _1 = f::<fn() {main}>(main) -> bb1; // scope 0 at $DIR/cycle.rs:12:5: 12:12
+ StorageLive(_2); // scope 0 at $DIR/cycle.rs:12:5: 12:12
+ _2 = main; // scope 0 at $DIR/cycle.rs:12:5: 12:12
// mir::Constant
- // + span: $DIR/cycle.rs:12:5: 12:6
- // + literal: Const { ty: fn(fn() {main}) {f::<fn() {main}>}, val: Value(Scalar(<ZST>)) }
- // mir::Constant
// + span: $DIR/cycle.rs:12:7: 12:11
// + literal: Const { ty: fn() {main}, val: Value(Scalar(<ZST>)) }
+ StorageLive(_3); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ StorageLive(_4); // scope 1 at $DIR/cycle.rs:6:5: 6:6
+ _4 = &_2; // scope 1 at $DIR/cycle.rs:6:5: 6:6
+ StorageLive(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ _5 = const (); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ _3 = move (*_4)() -> [return: bb4, unwind: bb2]; // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL
}

bb1: {
+ StorageDead(_2); // scope 0 at $DIR/cycle.rs:12:5: 12:12
StorageDead(_1); // scope 0 at $DIR/cycle.rs:12:12: 12:13
_0 = const (); // scope 0 at $DIR/cycle.rs:11:8: 13:2
return; // scope 0 at $DIR/cycle.rs:13:2: 13:2
+ }
+
+ bb2 (cleanup): {
+ drop(_2) -> bb3; // scope 1 at $DIR/cycle.rs:7:1: 7:2
+ }
+
+ bb3 (cleanup): {
+ resume; // scope 1 at $DIR/cycle.rs:5:1: 7:2
+ }
+
+ bb4: {
+ StorageDead(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ StorageDead(_4); // scope 1 at $DIR/cycle.rs:6:7: 6:8
+ StorageDead(_3); // scope 1 at $DIR/cycle.rs:6:8: 6:9
+ drop(_2) -> bb1; // scope 1 at $DIR/cycle.rs:7:1: 7:2
}
}

58 changes: 54 additions & 4 deletions src/test/mir-opt/inline/cycle.main.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,72 @@
fn main() -> () {
let mut _0: (); // return place in scope 0 at $DIR/cycle.rs:16:11: 16:11
let _1: (); // in scope 0 at $DIR/cycle.rs:17:5: 17:9
+ let mut _2: fn() {g}; // in scope 0 at $DIR/cycle.rs:17:5: 17:9
+ let mut _5: (); // in scope 0 at $DIR/cycle.rs:6:5: 6:8
+ scope 1 (inlined f::<fn() {g}>) { // at $DIR/cycle.rs:17:5: 17:9
+ debug g => _2; // in scope 1 at $DIR/cycle.rs:5:6: 5:7
+ let _3: (); // in scope 1 at $DIR/cycle.rs:6:5: 6:8
+ let mut _4: &fn() {g}; // in scope 1 at $DIR/cycle.rs:6:5: 6:6
+ scope 2 (inlined <fn() {g} as Fn<()>>::call - shim(fn() {g})) { // at $DIR/cycle.rs:6:5: 6:8
+ scope 3 (inlined g) { // at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ let mut _6: fn() {main}; // in scope 3 at $DIR/cycle.rs:12:5: 12:12
+ scope 4 (inlined f::<fn() {main}>) { // at $DIR/cycle.rs:12:5: 12:12
+ debug g => _6; // in scope 4 at $DIR/cycle.rs:5:6: 5:7
+ let _7: (); // in scope 4 at $DIR/cycle.rs:6:5: 6:8
+ let mut _8: &fn() {main}; // in scope 4 at $DIR/cycle.rs:6:5: 6:6
+ scope 5 (inlined <fn() {main} as Fn<()>>::call - shim(fn() {main})) { // at $DIR/cycle.rs:6:5: 6:8
+ }
+ }
+ }
+ }
+ }

bb0: {
StorageLive(_1); // scope 0 at $DIR/cycle.rs:17:5: 17:9
_1 = f::<fn() {g}>(g) -> bb1; // scope 0 at $DIR/cycle.rs:17:5: 17:9
// mir::Constant
// + span: $DIR/cycle.rs:17:5: 17:6
// + literal: Const { ty: fn(fn() {g}) {f::<fn() {g}>}, val: Value(Scalar(<ZST>)) }
- _1 = f::<fn() {g}>(g) -> bb1; // scope 0 at $DIR/cycle.rs:17:5: 17:9
+ StorageLive(_2); // scope 0 at $DIR/cycle.rs:17:5: 17:9
+ _2 = g; // scope 0 at $DIR/cycle.rs:17:5: 17:9
// mir::Constant
- // + span: $DIR/cycle.rs:17:5: 17:6
- // + literal: Const { ty: fn(fn() {g}) {f::<fn() {g}>}, val: Value(Scalar(<ZST>)) }
- // mir::Constant
// + span: $DIR/cycle.rs:17:7: 17:8
// + literal: Const { ty: fn() {g}, val: Value(Scalar(<ZST>)) }
+ StorageLive(_3); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ StorageLive(_4); // scope 1 at $DIR/cycle.rs:6:5: 6:6
+ _4 = &_2; // scope 1 at $DIR/cycle.rs:6:5: 6:6
+ StorageLive(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ _5 = const (); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ StorageLive(_6); // scope 3 at $DIR/cycle.rs:12:5: 12:12
+ StorageLive(_7); // scope 4 at $DIR/cycle.rs:6:5: 6:8
+ StorageLive(_8); // scope 4 at $DIR/cycle.rs:6:5: 6:6
+ _8 = &_6; // scope 4 at $DIR/cycle.rs:6:5: 6:6
+ _7 = move (*_8)() -> [return: bb4, unwind: bb2]; // scope 5 at $SRC_DIR/core/src/ops/function.rs:LL:COL
}

bb1: {
+ StorageDead(_2); // scope 0 at $DIR/cycle.rs:17:5: 17:9
StorageDead(_1); // scope 0 at $DIR/cycle.rs:17:9: 17:10
_0 = const (); // scope 0 at $DIR/cycle.rs:16:11: 18:2
return; // scope 0 at $DIR/cycle.rs:18:2: 18:2
+ }
+
+ bb2 (cleanup): {
+ drop(_2) -> bb3; // scope 1 at $DIR/cycle.rs:7:1: 7:2
+ }
+
+ bb3 (cleanup): {
+ resume; // scope 1 at $DIR/cycle.rs:5:1: 7:2
+ }
+
+ bb4: {
+ StorageDead(_8); // scope 4 at $DIR/cycle.rs:6:7: 6:8
+ StorageDead(_7); // scope 4 at $DIR/cycle.rs:6:8: 6:9
+ StorageDead(_6); // scope 3 at $DIR/cycle.rs:12:5: 12:12
+ StorageDead(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ StorageDead(_4); // scope 1 at $DIR/cycle.rs:6:7: 6:8
+ StorageDead(_3); // scope 1 at $DIR/cycle.rs:6:8: 6:9
+ drop(_2) -> bb1; // scope 1 at $DIR/cycle.rs:7:1: 7:2
}
}

Loading

0 comments on commit f001f93

Please sign in to comment.