Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3336,6 +3336,7 @@ dependencies = [
"libc",
"object 0.37.3",
"regex",
"rustdoc-json-types",
"serde_json",
"similar",
"wasmparser 0.236.1",
Expand Down
5 changes: 4 additions & 1 deletion library/core/src/ops/try_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,14 @@ pub const trait Residual<O>: Sized {
/// but importantly not on the contextual type the way it would be if
/// we called `<_ as FromResidual>::from_residual(r)` directly.
#[unstable(feature = "try_trait_v2_residual", issue = "91285")]
#[rustc_const_unstable(feature = "const_try_residual", issue = "91285")]
// needs to be `pub` to avoid `private type` errors
#[expect(unreachable_pub)]
#[inline] // FIXME: force would be nice, but fails -- see #148915
#[lang = "into_try_type"]
pub fn residual_into_try_type<R: Residual<O>, O>(r: R) -> <R as Residual<O>>::TryType {
pub const fn residual_into_try_type<R: [const] Residual<O>, O>(
r: R,
) -> <R as Residual<O>>::TryType {
FromResidual::from_residual(r)
}

Expand Down
5 changes: 2 additions & 3 deletions library/std/src/sys/net/connection/uefi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ impl TcpStream {
}

pub fn read_vectored(&self, buf: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
// FIXME: UEFI does support vectored read, so implement that.
crate::io::default_read_vectored(|b| self.read(b), buf)
self.inner.read_vectored(buf, self.read_timeout()?)
}

pub fn is_read_vectored(&self) -> bool {
false
true
}

pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
Expand Down
12 changes: 11 additions & 1 deletion library/std/src/sys/net/connection/uefi/tcp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::tcp4;
use crate::io::{self, IoSlice};
use crate::io::{self, IoSlice, IoSliceMut};
use crate::net::SocketAddr;
use crate::ptr::NonNull;
use crate::sys::{helpers, unsupported};
Expand Down Expand Up @@ -44,6 +44,16 @@ impl Tcp {
}
}

pub(crate) fn read_vectored(
&self,
buf: &mut [IoSliceMut<'_>],
timeout: Option<Duration>,
) -> io::Result<usize> {
match self {
Self::V4(client) => client.read_vectored(buf, timeout),
}
}

pub(crate) fn ttl(&self) -> io::Result<u32> {
match self {
Self::V4(client) => client.get_mode_data().map(|x| x.time_to_live.into()),
Expand Down
68 changes: 56 additions & 12 deletions library/std/src/sys/net/connection/uefi/tcp4.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use r_efi::efi::{self, Status};
use r_efi::protocols::tcp4;

use crate::io::{self, IoSlice};
use crate::io::{self, IoSlice, IoSliceMut};
use crate::net::SocketAddrV4;
use crate::ptr::NonNull;
use crate::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -193,30 +193,74 @@ impl Tcp4 {
}

pub(crate) fn read(&self, buf: &mut [u8], timeout: Option<Duration>) -> io::Result<usize> {
let evt = unsafe { self.create_evt() }?;
let completion_token =
tcp4::CompletionToken { event: evt.as_ptr(), status: Status::SUCCESS };
let data_len = u32::try_from(buf.len()).unwrap_or(u32::MAX);

let fragment = tcp4::FragmentData {
fragment_length: data_len,
fragment_buffer: buf.as_mut_ptr().cast::<crate::ffi::c_void>(),
};
let mut tx_data = tcp4::ReceiveData {
let mut rx_data = tcp4::ReceiveData {
urgent_flag: r_efi::efi::Boolean::FALSE,
data_length: data_len,
fragment_count: 1,
fragment_table: [fragment],
};

let protocol = self.protocol.as_ptr();
let mut token = tcp4::IoToken {
completion_token,
packet: tcp4::IoTokenPacket {
rx_data: (&raw mut tx_data).cast::<tcp4::ReceiveData<0>>(),
},
self.read_inner((&raw mut rx_data).cast(), timeout).map(|_| data_len as usize)
}

pub(crate) fn read_vectored(
&self,
buf: &[IoSliceMut<'_>],
timeout: Option<Duration>,
) -> io::Result<usize> {
let mut data_length = 0u32;
let mut fragment_count = 0u32;

// Calculate how many IoSlice in buf can be transmitted.
for i in buf {
// IoSlice length is always <= u32::MAX in UEFI.
match data_length.checked_add(u32::try_from(i.len()).expect("value is stored as a u32"))
{
Some(x) => data_length = x,
None => break,
}
fragment_count += 1;
}

let rx_data_size = size_of::<tcp4::ReceiveData<0>>()
+ size_of::<tcp4::FragmentData>() * (fragment_count as usize);
let mut rx_data = helpers::UefiBox::<tcp4::ReceiveData>::new(rx_data_size)?;
rx_data.write(tcp4::ReceiveData {
urgent_flag: r_efi::efi::Boolean::FALSE,
data_length,
fragment_count,
fragment_table: [],
});
unsafe {
// SAFETY: IoSlice and FragmentData are guaranteed to have same layout.
crate::ptr::copy_nonoverlapping(
buf.as_ptr().cast(),
(*rx_data.as_mut_ptr()).fragment_table.as_mut_ptr(),
fragment_count as usize,
);
};

self.read_inner(rx_data.as_mut_ptr(), timeout).map(|_| data_length as usize)
}

pub(crate) fn read_inner(
&self,
rx_data: *mut tcp4::ReceiveData,
timeout: Option<Duration>,
) -> io::Result<()> {
let evt = unsafe { self.create_evt() }?;
let completion_token =
tcp4::CompletionToken { event: evt.as_ptr(), status: Status::SUCCESS };

let protocol = self.protocol.as_ptr();
let mut token = tcp4::IoToken { completion_token, packet: tcp4::IoTokenPacket { rx_data } };

let r = unsafe { ((*protocol).receive)(protocol, &mut token) };
if r.is_error() {
return Err(io::Error::from_raw_os_error(r.as_usize()));
Expand All @@ -227,7 +271,7 @@ impl Tcp4 {
if completion_token.status.is_error() {
Err(io::Error::from_raw_os_error(completion_token.status.as_usize()))
} else {
Ok(data_len as usize)
Ok(())
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
ExternalLocation::Remote(s) => Some(s.clone()),
_ => None,
},
path: self
.tcx
.used_crate_source(*crate_num)
.paths()
.next()
.expect("crate should have at least 1 path")
.clone(),
},
)
})
Expand Down Expand Up @@ -339,20 +346,21 @@ mod size_asserts {
// tidy-alphabetical-start
static_assert_size!(AssocItemConstraint, 112);
static_assert_size!(Crate, 184);
static_assert_size!(ExternalCrate, 48);
static_assert_size!(FunctionPointer, 168);
static_assert_size!(GenericArg, 80);
static_assert_size!(GenericArgs, 104);
static_assert_size!(GenericBound, 72);
static_assert_size!(GenericParamDef, 136);
static_assert_size!(Impl, 304);
// `Item` contains a `PathBuf`, which is different sizes on different OSes.
static_assert_size!(Item, 528 + size_of::<std::path::PathBuf>());
static_assert_size!(ItemSummary, 32);
static_assert_size!(PolyTrait, 64);
static_assert_size!(PreciseCapturingArg, 32);
static_assert_size!(TargetFeature, 80);
static_assert_size!(Type, 80);
static_assert_size!(WherePredicate, 160);
// tidy-alphabetical-end

// These contains a `PathBuf`, which is different sizes on different OSes.
static_assert_size!(Item, 528 + size_of::<std::path::PathBuf>());
static_assert_size!(ExternalCrate, 48 + size_of::<std::path::PathBuf>());
}
10 changes: 8 additions & 2 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
// will instead cause conflicts. See #94591 for more. (This paragraph and the "Latest feature" line
// are deliberately not in a doc comment, because they need not be in public docs.)
//
// Latest feature: Add `ItemKind::Attribute`.
pub const FORMAT_VERSION: u32 = 56;
// Latest feature: Add `ExternCrate::path`.
pub const FORMAT_VERSION: u32 = 57;

/// The root of the emitted JSON blob.
///
Expand Down Expand Up @@ -135,6 +135,12 @@ pub struct ExternalCrate {
pub name: String,
/// The root URL at which the crate's documentation lives.
pub html_root_url: Option<String>,

/// A path from where this crate was loaded.
///
/// This will typically be a `.rlib` or `.rmeta`. It can be used to determine which crate
/// this was in terms of whatever build-system invoked rustc.
pub path: PathBuf,
}

/// Information about an external (not defined in the local crate) [`Item`].
Expand Down
2 changes: 2 additions & 0 deletions src/tools/run-make-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ wasmparser = { version = "0.236", default-features = false, features = ["std", "

# Shared with bootstrap and compiletest
build_helper = { path = "../../build_helper" }
# Shared with rustdoc
rustdoc-json-types = { path = "../../rustdoc-json-types" }

[lib]
crate-type = ["lib", "dylib"]
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub mod rfs {
}

// Re-exports of third-party library crates.
pub use {bstr, gimli, libc, object, regex, serde_json, similar, wasmparser};
pub use {bstr, gimli, libc, object, regex, rustdoc_json_types, serde_json, similar, wasmparser};

// Helpers for building names of output artifacts that are potentially target-specific.
pub use crate::artifact_names::{
Expand Down
5 changes: 5 additions & 0 deletions tests/run-make/rustdoc-json-external-crate-path/dep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![no_std]

pub struct S;

pub use trans_dep::S as TransDep;
4 changes: 4 additions & 0 deletions tests/run-make/rustdoc-json-external-crate-path/entry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![no_std]

pub type FromDep = dep::S;
pub type FromTransDep = dep::TransDep;
81 changes: 81 additions & 0 deletions tests/run-make/rustdoc-json-external-crate-path/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use std::path::PathBuf;

use run_make_support::rustdoc_json_types::{Crate, ItemEnum, Path, Type, TypeAlias};
use run_make_support::{cwd, rfs, rust_lib_name, rustc, rustdoc, serde_json};

fn main() {
rustc().input("trans_dep.rs").edition("2024").crate_type("lib").run();

rustc()
.input("dep.rs")
.edition("2024")
.crate_type("lib")
.extern_("trans_dep", rust_lib_name("trans_dep"))
.run();

rustdoc()
.input("entry.rs")
.edition("2024")
.output_format("json")
.library_search_path(cwd())
.extern_("dep", rust_lib_name("dep"))
.arg("-Zunstable-options")
.run();

let bytes = rfs::read("doc/entry.json");

let krate: Crate = serde_json::from_slice(&bytes).expect("output should be valid json");

let root_item = &krate.index[&krate.root];
let ItemEnum::Module(root_mod) = &root_item.inner else { panic!("expected ItemEnum::Module") };

assert_eq!(root_mod.items.len(), 2);

let items = root_mod.items.iter().map(|id| &krate.index[id]).collect::<Vec<_>>();

let from_dep = items
.iter()
.filter(|item| item.name.as_deref() == Some("FromDep"))
.next()
.expect("there should be en item called FromDep");

let from_trans_dep = items
.iter()
.filter(|item| item.name.as_deref() == Some("FromTransDep"))
.next()
.expect("there should be en item called FromDep");

let ItemEnum::TypeAlias(TypeAlias {
type_: Type::ResolvedPath(Path { id: from_dep_id, .. }),
..
}) = &from_dep.inner
else {
panic!("Expected FromDep to be a TypeAlias");
};

let ItemEnum::TypeAlias(TypeAlias {
type_: Type::ResolvedPath(Path { id: from_trans_dep_id, .. }),
..
}) = &from_trans_dep.inner
else {
panic!("Expected FromDep to be a TypeAlias");
};

assert_eq!(krate.index.get(from_dep_id), None);
assert_eq!(krate.index.get(from_trans_dep_id), None);

let from_dep_externalinfo = &krate.paths[from_dep_id];
let from_trans_dep_externalinfo = &krate.paths[from_trans_dep_id];

let dep_crate_id = from_dep_externalinfo.crate_id;
let trans_dep_crate_id = from_trans_dep_externalinfo.crate_id;

let dep = &krate.external_crates[&dep_crate_id];
let trans_dep = &krate.external_crates[&trans_dep_crate_id];

assert_eq!(dep.name, "dep");
assert_eq!(trans_dep.name, "trans_dep");

assert_eq!(dep.path, cwd().join(rust_lib_name("dep")));
assert_eq!(trans_dep.path, cwd().join(rust_lib_name("trans_dep")));
}
3 changes: 3 additions & 0 deletions tests/run-make/rustdoc-json-external-crate-path/trans_dep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![no_std]

pub struct S;
Loading