1
Fork 0

Auto merge of #138841 - matthiaskrgr:rollup-bfkls57, r=matthiaskrgr

Rollup of 8 pull requests

Successful merges:

 - #138018 (rustdoc: Use own logic to print `#[repr(..)]` attributes in JSON output.)
 - #138294 (Mark some std tests as requiring `panic = "unwind"`)
 - #138468 (rustdoc js: add nonnull helper and typecheck src-script.js)
 - #138675 (Add release notes for 1.85.1)
 - #138765 (Fix Thread::set_name on cygwin)
 - #138786 (Move some driver code around)
 - #138793 (target spec check: better error when llvm-floatabi is missing)
 - #138822 (De-Stabilize `file_lock`)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2025-03-22 23:59:01 +00:00
commit 756bff97ea
32 changed files with 256 additions and 105 deletions

View file

@ -1,3 +1,14 @@
Version 1.85.1 (2025-03-18)
==========================
<a id="1.85.1"></a>
- [Fix the doctest-merging feature of the 2024 Edition.](https://github.com/rust-lang/rust/pull/137899/)
- [Relax some `target_feature` checks when generating docs.](https://github.com/rust-lang/rust/pull/137632/)
- [Fix errors in `std::fs::rename` on Windows 10, version 1607.](https://github.com/rust-lang/rust/pull/137528/)
- [Downgrade bootstrap `cc` to fix custom targets.](https://github.com/rust-lang/rust/pull/137460/)
- [Skip submodule updates when building Rust from a source tarball.](https://github.com/rust-lang/rust/pull/137338/)
Version 1.85.0 (2025-02-20) Version 1.85.0 (2025-02-20)
========================== ==========================

View file

@ -1,3 +1,5 @@
driver_impl_cant_emit_mir = could not emit MIR: {$error}
driver_impl_ice = the compiler unexpectedly panicked. this is a bug. driver_impl_ice = the compiler unexpectedly panicked. this is a bug.
driver_impl_ice_bug_report = we would appreciate a bug report: {$bug_report_url} driver_impl_ice_bug_report = we would appreciate a bug report: {$bug_report_url}
driver_impl_ice_bug_report_internal_feature = using internal features is not supported and expected to cause internal compiler errors when used incorrectly driver_impl_ice_bug_report_internal_feature = using internal features is not supported and expected to cause internal compiler errors when used incorrectly

View file

@ -108,7 +108,7 @@ mod signal_handler {
} }
use crate::session_diagnostics::{ use crate::session_diagnostics::{
RLinkEmptyVersionNumber, RLinkEncodingVersionMismatch, RLinkRustcVersionMismatch, CantEmitMIR, RLinkEmptyVersionNumber, RLinkEncodingVersionMismatch, RLinkRustcVersionMismatch,
RLinkWrongFileType, RlinkCorruptFile, RlinkNotAFile, RlinkUnableToRead, UnstableFeatureUsage, RLinkWrongFileType, RlinkCorruptFile, RlinkNotAFile, RlinkUnableToRead, UnstableFeatureUsage,
}; };
@ -243,12 +243,17 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
return; return;
} }
let input = make_input(&default_early_dcx, &matches.free);
let has_input = input.is_some();
let (odir, ofile) = make_output(&matches); let (odir, ofile) = make_output(&matches);
drop(default_early_dcx);
let mut config = interface::Config { let mut config = interface::Config {
opts: sopts, opts: sopts,
crate_cfg: matches.opt_strs("cfg"), crate_cfg: matches.opt_strs("cfg"),
crate_check_cfg: matches.opt_strs("check-cfg"), crate_check_cfg: matches.opt_strs("check-cfg"),
input: Input::File(PathBuf::new()), input: input.unwrap_or(Input::File(PathBuf::new())),
output_file: ofile, output_file: ofile,
output_dir: odir, output_dir: odir,
ice_file, ice_file,
@ -265,16 +270,6 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
expanded_args: args, expanded_args: args,
}; };
let has_input = match make_input(&default_early_dcx, &matches.free) {
Some(input) => {
config.input = input;
true // has input: normal compilation
}
None => false, // no input: we will exit early
};
drop(default_early_dcx);
callbacks.config(&mut config); callbacks.config(&mut config);
let registered_lints = config.register_lints.is_some(); let registered_lints = config.register_lints.is_some();
@ -379,6 +374,12 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
return early_exit(); return early_exit();
} }
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
tcx.dcx().emit_fatal(CantEmitMIR { error });
}
}
Some(Linker::codegen_and_build_linker(tcx, &*compiler.codegen_backend)) Some(Linker::codegen_and_build_linker(tcx, &*compiler.codegen_backend))
}); });
@ -407,7 +408,7 @@ fn dump_feature_usage_metrics(tcxt: TyCtxt<'_>, metrics_dir: &Path) {
} }
} }
// Extract output directory and file from matches. /// Extract output directory and file from matches.
fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<OutFileName>) { fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<OutFileName>) {
let odir = matches.opt_str("out-dir").map(|o| PathBuf::from(&o)); let odir = matches.opt_str("out-dir").map(|o| PathBuf::from(&o));
let ofile = matches.opt_str("o").map(|o| match o.as_str() { let ofile = matches.opt_str("o").map(|o| match o.as_str() {

View file

@ -2,6 +2,12 @@ use std::error::Error;
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
#[derive(Diagnostic)]
#[diag(driver_impl_cant_emit_mir)]
pub struct CantEmitMIR {
pub error: std::io::Error,
}
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(driver_impl_rlink_unable_to_read)] #[diag(driver_impl_rlink_unable_to_read)]
pub(crate) struct RlinkUnableToRead { pub(crate) struct RlinkUnableToRead {

View file

@ -3,9 +3,6 @@ interface_abi_required_feature =
.note = this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! .note = this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
interface_abi_required_feature_issue = for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344> interface_abi_required_feature_issue = for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
interface_cant_emit_mir =
could not emit MIR: {$error}
interface_crate_name_does_not_match = `--crate-name` and `#[crate_name]` are required to match, but `{$crate_name}` != `{$attr_crate_name}` interface_crate_name_does_not_match = `--crate-name` and `#[crate_name]` are required to match, but `{$crate_name}` != `{$attr_crate_name}`
interface_crate_name_invalid = crate names cannot start with a `-`, but `{$crate_name}` has a leading hyphen interface_crate_name_invalid = crate names cannot start with a `-`, but `{$crate_name}` has a leading hyphen

View file

@ -73,12 +73,6 @@ pub struct TempsDirError;
#[diag(interface_out_dir_error)] #[diag(interface_out_dir_error)]
pub struct OutDirError; pub struct OutDirError;
#[derive(Diagnostic)]
#[diag(interface_cant_emit_mir)]
pub struct CantEmitMIR {
pub error: io::Error,
}
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(interface_rustc_error_fatal)] #[diag(interface_rustc_error_fatal)]
pub struct RustcErrorFatal { pub struct RustcErrorFatal {

View file

@ -1078,6 +1078,15 @@ pub(crate) fn start_codegen<'tcx>(
codegen_backend: &dyn CodegenBackend, codegen_backend: &dyn CodegenBackend,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
) -> Box<dyn Any> { ) -> Box<dyn Any> {
// Hook for UI tests.
check_for_rustc_errors_attr(tcx);
// Don't run this test assertions when not doing codegen. Compiletest tries to build
// build-fail tests in check mode first and expects it to not give an error in that case.
if tcx.sess.opts.output_types.should_codegen() {
rustc_symbol_mangling::test::report_symbol_names(tcx);
}
// Don't do code generation if there were any errors. Likewise if // Don't do code generation if there were any errors. Likewise if
// there were any delayed bugs, because codegen will likely cause // there were any delayed bugs, because codegen will likely cause
// more ICEs, obscuring the original problem. // more ICEs, obscuring the original problem.
@ -1085,9 +1094,6 @@ pub(crate) fn start_codegen<'tcx>(
guar.raise_fatal(); guar.raise_fatal();
} }
// Hook for UI tests.
check_for_rustc_errors_attr(tcx);
info!("Pre-codegen\n{:?}", tcx.debug_stats()); info!("Pre-codegen\n{:?}", tcx.debug_stats());
let (metadata, need_metadata_module) = rustc_metadata::fs::encode_and_write_metadata(tcx); let (metadata, need_metadata_module) = rustc_metadata::fs::encode_and_write_metadata(tcx);
@ -1096,20 +1102,8 @@ pub(crate) fn start_codegen<'tcx>(
codegen_backend.codegen_crate(tcx, metadata, need_metadata_module) codegen_backend.codegen_crate(tcx, metadata, need_metadata_module)
}); });
// Don't run this test assertions when not doing codegen. Compiletest tries to build
// build-fail tests in check mode first and expects it to not give an error in that case.
if tcx.sess.opts.output_types.should_codegen() {
rustc_symbol_mangling::test::report_symbol_names(tcx);
}
info!("Post-codegen\n{:?}", tcx.debug_stats()); info!("Post-codegen\n{:?}", tcx.debug_stats());
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
tcx.dcx().emit_fatal(errors::CantEmitMIR { error });
}
}
// This must run after monomorphization so that all generic types // This must run after monomorphization so that all generic types
// have been instantiated. // have been instantiated.
if tcx.sess.opts.unstable_opts.print_type_sizes { if tcx.sess.opts.unstable_opts.print_type_sizes {

View file

@ -811,8 +811,8 @@ passes_unused_duplicate =
passes_unused_empty_lints_note = passes_unused_empty_lints_note =
attribute `{$name}` with an empty list has no effect attribute `{$name}` with an empty list has no effect
passes_unused_linker_warnings_note = passes_unused_linker_messages_note =
the `linker_warnings` lint can only be controlled at the root of a crate that needs to be linked the `linker_messages` lint can only be controlled at the root of a crate that needs to be linked
passes_unused_multiple = passes_unused_multiple =
multiple `{$name}` attributes multiple `{$name}` attributes

View file

@ -2402,7 +2402,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
.iter() .iter()
.all(|kind| matches!(kind, CrateType::Rlib | CrateType::Staticlib)); .all(|kind| matches!(kind, CrateType::Rlib | CrateType::Staticlib));
if never_needs_link { if never_needs_link {
errors::UnusedNote::LinkerWarningsBinaryCrateOnly errors::UnusedNote::LinkerMessagesBinaryCrateOnly
} else { } else {
return; return;
} }

View file

@ -770,8 +770,8 @@ pub(crate) enum UnusedNote {
NoLints { name: Symbol }, NoLints { name: Symbol },
#[note(passes_unused_default_method_body_const_note)] #[note(passes_unused_default_method_body_const_note)]
DefaultMethodBodyConst, DefaultMethodBodyConst,
#[note(passes_unused_linker_warnings_note)] #[note(passes_unused_linker_messages_note)]
LinkerWarningsBinaryCrateOnly, LinkerMessagesBinaryCrateOnly,
} }
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]

View file

@ -3342,7 +3342,10 @@ impl Target {
); );
} }
"arm" => { "arm" => {
check!(self.llvm_floatabi.is_some(), "ARM targets must specify their float ABI",) check!(
self.llvm_floatabi.is_some(),
"ARM targets must set `llvm-floatabi` to `hard` or `soft`",
)
} }
_ => {} _ => {}
} }

View file

@ -665,6 +665,7 @@ impl File {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File; /// use std::fs::File;
/// ///
/// fn main() -> std::io::Result<()> { /// fn main() -> std::io::Result<()> {
@ -673,7 +674,7 @@ impl File {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[stable(feature = "file_lock", since = "CURRENT_RUSTC_VERSION")] #[unstable(feature = "file_lock", issue = "130994")]
pub fn lock(&self) -> io::Result<()> { pub fn lock(&self) -> io::Result<()> {
self.inner.lock() self.inner.lock()
} }
@ -717,6 +718,7 @@ impl File {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File; /// use std::fs::File;
/// ///
/// fn main() -> std::io::Result<()> { /// fn main() -> std::io::Result<()> {
@ -725,7 +727,7 @@ impl File {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[stable(feature = "file_lock", since = "CURRENT_RUSTC_VERSION")] #[unstable(feature = "file_lock", issue = "130994")]
pub fn lock_shared(&self) -> io::Result<()> { pub fn lock_shared(&self) -> io::Result<()> {
self.inner.lock_shared() self.inner.lock_shared()
} }
@ -774,6 +776,7 @@ impl File {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File; /// use std::fs::File;
/// ///
/// fn main() -> std::io::Result<()> { /// fn main() -> std::io::Result<()> {
@ -782,7 +785,7 @@ impl File {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[stable(feature = "file_lock", since = "CURRENT_RUSTC_VERSION")] #[unstable(feature = "file_lock", issue = "130994")]
pub fn try_lock(&self) -> io::Result<bool> { pub fn try_lock(&self) -> io::Result<bool> {
self.inner.try_lock() self.inner.try_lock()
} }
@ -830,6 +833,7 @@ impl File {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File; /// use std::fs::File;
/// ///
/// fn main() -> std::io::Result<()> { /// fn main() -> std::io::Result<()> {
@ -838,7 +842,7 @@ impl File {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[stable(feature = "file_lock", since = "CURRENT_RUSTC_VERSION")] #[unstable(feature = "file_lock", issue = "130994")]
pub fn try_lock_shared(&self) -> io::Result<bool> { pub fn try_lock_shared(&self) -> io::Result<bool> {
self.inner.try_lock_shared() self.inner.try_lock_shared()
} }
@ -866,6 +870,7 @@ impl File {
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File; /// use std::fs::File;
/// ///
/// fn main() -> std::io::Result<()> { /// fn main() -> std::io::Result<()> {
@ -875,7 +880,7 @@ impl File {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[stable(feature = "file_lock", since = "CURRENT_RUSTC_VERSION")] #[unstable(feature = "file_lock", issue = "130994")]
pub fn unlock(&self) -> io::Result<()> { pub fn unlock(&self) -> io::Result<()> {
self.inner.unlock() self.inner.unlock()
} }

View file

@ -143,8 +143,8 @@ impl Thread {
pub fn set_name(name: &CStr) { pub fn set_name(name: &CStr) {
unsafe { unsafe {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] { if #[cfg(any(target_os = "linux", target_os = "cygwin"))] {
// Linux limits the allowed length of the name. // Linux and Cygwin limits the allowed length of the name.
const TASK_COMM_LEN: usize = 16; const TASK_COMM_LEN: usize = 16;
let name = truncate_cstr::<{ TASK_COMM_LEN }>(name); let name = truncate_cstr::<{ TASK_COMM_LEN }>(name);
} else { } else {
@ -346,6 +346,7 @@ impl Drop for Thread {
target_os = "solaris", target_os = "solaris",
target_os = "illumos", target_os = "illumos",
target_os = "vxworks", target_os = "vxworks",
target_os = "cygwin",
target_vendor = "apple", target_vendor = "apple",
))] ))]
fn truncate_cstr<const MAX_WITH_NUL: usize>(cstr: &CStr) -> [libc::c_char; MAX_WITH_NUL] { fn truncate_cstr<const MAX_WITH_NUL: usize>(cstr: &CStr) -> [libc::c_char; MAX_WITH_NUL] {

View file

@ -108,6 +108,7 @@ fn test_is_finished() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_join_panic() { fn test_join_panic() {
match thread::spawn(move || panic!()).join() { match thread::spawn(move || panic!()).join() {
result::Result::Err(_) => (), result::Result::Err(_) => (),
@ -210,6 +211,7 @@ fn test_simple_newsched_spawn() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_try_panic_message_string_literal() { fn test_try_panic_message_string_literal() {
match thread::spawn(move || { match thread::spawn(move || {
panic!("static string"); panic!("static string");
@ -226,6 +228,7 @@ fn test_try_panic_message_string_literal() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_try_panic_any_message_owned_str() { fn test_try_panic_any_message_owned_str() {
match thread::spawn(move || { match thread::spawn(move || {
panic_any("owned string".to_string()); panic_any("owned string".to_string());
@ -242,6 +245,7 @@ fn test_try_panic_any_message_owned_str() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_try_panic_any_message_any() { fn test_try_panic_any_message_any() {
match thread::spawn(move || { match thread::spawn(move || {
panic_any(Box::new(413u16) as Box<dyn Any + Send>); panic_any(Box::new(413u16) as Box<dyn Any + Send>);
@ -260,6 +264,7 @@ fn test_try_panic_any_message_any() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_try_panic_any_message_unit_struct() { fn test_try_panic_any_message_unit_struct() {
struct Juju; struct Juju;

View file

@ -118,6 +118,7 @@ fn test_into_inner_drop() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_into_inner_poison() { fn test_into_inner_poison() {
let m = new_poisoned_mutex(NonCopy(10)); let m = new_poisoned_mutex(NonCopy(10));
@ -135,6 +136,7 @@ fn test_get_cloned() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_get_cloned_poison() { fn test_get_cloned_poison() {
let m = new_poisoned_mutex(Cloneable(10)); let m = new_poisoned_mutex(Cloneable(10));
@ -152,6 +154,7 @@ fn test_get_mut() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_get_mut_poison() { fn test_get_mut_poison() {
let mut m = new_poisoned_mutex(NonCopy(10)); let mut m = new_poisoned_mutex(NonCopy(10));
@ -179,6 +182,7 @@ fn test_set() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_set_poison() { fn test_set_poison() {
fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T) fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T)
where where
@ -217,6 +221,7 @@ fn test_replace() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_replace_poison() { fn test_replace_poison() {
fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T) fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T)
where where
@ -261,6 +266,7 @@ fn test_mutex_arc_condvar() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_arc_condvar_poison() { fn test_arc_condvar_poison() {
let packet = Packet(Arc::new((Mutex::new(1), Condvar::new()))); let packet = Packet(Arc::new((Mutex::new(1), Condvar::new())));
let packet2 = Packet(packet.0.clone()); let packet2 = Packet(packet.0.clone());
@ -290,6 +296,7 @@ fn test_arc_condvar_poison() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_mutex_arc_poison() { fn test_mutex_arc_poison() {
let arc = Arc::new(Mutex::new(1)); let arc = Arc::new(Mutex::new(1));
assert!(!arc.is_poisoned()); assert!(!arc.is_poisoned());
@ -304,6 +311,7 @@ fn test_mutex_arc_poison() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_mutex_arc_poison_mapped() { fn test_mutex_arc_poison_mapped() {
let arc = Arc::new(Mutex::new(1)); let arc = Arc::new(Mutex::new(1));
assert!(!arc.is_poisoned()); assert!(!arc.is_poisoned());
@ -335,6 +343,7 @@ fn test_mutex_arc_nested() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_mutex_arc_access_in_unwind() { fn test_mutex_arc_access_in_unwind() {
let arc = Arc::new(Mutex::new(1)); let arc = Arc::new(Mutex::new(1));
let arc2 = arc.clone(); let arc2 = arc.clone();
@ -381,6 +390,7 @@ fn test_mapping_mapped_guard() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn panic_while_mapping_unlocked_poison() { fn panic_while_mapping_unlocked_poison() {
let lock = Mutex::new(()); let lock = Mutex::new(());

View file

@ -52,6 +52,7 @@ fn stampede_once() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn poison_bad() { fn poison_bad() {
static O: Once = Once::new(); static O: Once = Once::new();
@ -80,6 +81,7 @@ fn poison_bad() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn wait_for_force_to_finish() { fn wait_for_force_to_finish() {
static O: Once = Once::new(); static O: Once = Once::new();
@ -137,6 +139,7 @@ fn wait() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn wait_on_poisoned() { fn wait_on_poisoned() {
let once = Once::new(); let once = Once::new();
@ -145,6 +148,7 @@ fn wait_on_poisoned() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn wait_force_on_poisoned() { fn wait_force_on_poisoned() {
let once = Once::new(); let once = Once::new();

View file

@ -77,8 +77,10 @@ fn get_or_try_init() {
let cell: OnceLock<String> = OnceLock::new(); let cell: OnceLock<String> = OnceLock::new();
assert!(cell.get().is_none()); assert!(cell.get().is_none());
let res = panic::catch_unwind(|| cell.get_or_try_init(|| -> Result<_, ()> { panic!() })); if cfg!(panic = "unwind") {
assert!(res.is_err()); let res = panic::catch_unwind(|| cell.get_or_try_init(|| -> Result<_, ()> { panic!() }));
assert!(res.is_err());
}
assert!(cell.get().is_none()); assert!(cell.get().is_none());
assert_eq!(cell.get_or_try_init(|| Err(())), Err(())); assert_eq!(cell.get_or_try_init(|| Err(())), Err(()));

View file

@ -73,6 +73,7 @@ fn frob() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_rw_arc_poison_wr() { fn test_rw_arc_poison_wr() {
let arc = Arc::new(RwLock::new(1)); let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone(); let arc2 = arc.clone();
@ -85,6 +86,7 @@ fn test_rw_arc_poison_wr() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_rw_arc_poison_mapped_w_r() { fn test_rw_arc_poison_mapped_w_r() {
let arc = Arc::new(RwLock::new(1)); let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone(); let arc2 = arc.clone();
@ -98,6 +100,7 @@ fn test_rw_arc_poison_mapped_w_r() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_rw_arc_poison_ww() { fn test_rw_arc_poison_ww() {
let arc = Arc::new(RwLock::new(1)); let arc = Arc::new(RwLock::new(1));
assert!(!arc.is_poisoned()); assert!(!arc.is_poisoned());
@ -112,6 +115,7 @@ fn test_rw_arc_poison_ww() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_rw_arc_poison_mapped_w_w() { fn test_rw_arc_poison_mapped_w_w() {
let arc = Arc::new(RwLock::new(1)); let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone(); let arc2 = arc.clone();
@ -126,6 +130,7 @@ fn test_rw_arc_poison_mapped_w_w() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_rw_arc_no_poison_rr() { fn test_rw_arc_no_poison_rr() {
let arc = Arc::new(RwLock::new(1)); let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone(); let arc2 = arc.clone();
@ -139,6 +144,7 @@ fn test_rw_arc_no_poison_rr() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_rw_arc_no_poison_mapped_r_r() { fn test_rw_arc_no_poison_mapped_r_r() {
let arc = Arc::new(RwLock::new(1)); let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone(); let arc2 = arc.clone();
@ -153,6 +159,7 @@ fn test_rw_arc_no_poison_mapped_r_r() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_rw_arc_no_poison_rw() { fn test_rw_arc_no_poison_rw() {
let arc = Arc::new(RwLock::new(1)); let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone(); let arc2 = arc.clone();
@ -166,6 +173,7 @@ fn test_rw_arc_no_poison_rw() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_rw_arc_no_poison_mapped_r_w() { fn test_rw_arc_no_poison_mapped_r_w() {
let arc = Arc::new(RwLock::new(1)); let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone(); let arc2 = arc.clone();
@ -218,6 +226,7 @@ fn test_rw_arc() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_rw_arc_access_in_unwind() { fn test_rw_arc_access_in_unwind() {
let arc = Arc::new(RwLock::new(1)); let arc = Arc::new(RwLock::new(1));
let arc2 = arc.clone(); let arc2 = arc.clone();
@ -316,6 +325,7 @@ fn test_into_inner_drop() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_into_inner_poison() { fn test_into_inner_poison() {
let m = new_poisoned_rwlock(NonCopy(10)); let m = new_poisoned_rwlock(NonCopy(10));
@ -333,6 +343,7 @@ fn test_get_cloned() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_get_cloned_poison() { fn test_get_cloned_poison() {
let m = new_poisoned_rwlock(Cloneable(10)); let m = new_poisoned_rwlock(Cloneable(10));
@ -350,6 +361,7 @@ fn test_get_mut() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_get_mut_poison() { fn test_get_mut_poison() {
let mut m = new_poisoned_rwlock(NonCopy(10)); let mut m = new_poisoned_rwlock(NonCopy(10));
@ -377,6 +389,7 @@ fn test_set() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_set_poison() { fn test_set_poison() {
fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T) fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T)
where where
@ -415,6 +428,7 @@ fn test_replace() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn test_replace_poison() { fn test_replace_poison() {
fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T) fn inner<T>(mut init: impl FnMut() -> T, mut value: impl FnMut() -> T)
where where
@ -482,6 +496,7 @@ fn test_mapping_mapped_guard() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn panic_while_mapping_read_unlocked_no_poison() { fn panic_while_mapping_read_unlocked_no_poison() {
let lock = RwLock::new(()); let lock = RwLock::new(());
@ -551,6 +566,7 @@ fn panic_while_mapping_read_unlocked_no_poison() {
} }
#[test] #[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
fn panic_while_mapping_write_unlocked_poison() { fn panic_while_mapping_write_unlocked_poison() {
let lock = RwLock::new(()); let lock = RwLock::new(());

View file

@ -768,12 +768,22 @@ impl Item {
.iter() .iter()
.filter_map(|attr| { .filter_map(|attr| {
if is_json { if is_json {
if matches!(attr, hir::Attribute::Parsed(AttributeKind::Deprecation { .. })) { match attr {
// rustdoc-json stores this in `Item::deprecation`, so we hir::Attribute::Parsed(AttributeKind::Deprecation { .. }) => {
// don't want it it `Item::attrs`. // rustdoc-json stores this in `Item::deprecation`, so we
None // don't want it it `Item::attrs`.
} else { None
Some(rustc_hir_pretty::attribute_to_string(&tcx, attr)) }
rustc_hir::Attribute::Parsed(rustc_attr_parsing::AttributeKind::Repr(
..,
)) => {
// We have separate pretty-printing logic for `#[repr(..)]` attributes.
// For example, there are circumstances where `#[repr(transparent)]`
// is applied but should not be publicly shown in rustdoc
// because it isn't public API.
None
}
_ => Some(rustc_hir_pretty::attribute_to_string(&tcx, attr)),
} }
} else if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) { } else if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
Some( Some(
@ -789,8 +799,7 @@ impl Item {
.collect(); .collect();
// Add #[repr(...)] // Add #[repr(...)]
if !is_json if let Some(def_id) = self.def_id()
&& let Some(def_id) = self.def_id()
&& let ItemType::Struct | ItemType::Enum | ItemType::Union = self.type_() && let ItemType::Struct | ItemType::Enum | ItemType::Union = self.type_()
{ {
let adt = tcx.adt_def(def_id); let adt = tcx.adt_def(def_id);

View file

@ -4,6 +4,10 @@
/* eslint-disable */ /* eslint-disable */
declare global { declare global {
/** Map from crate name to directory structure, for source view */
declare var srcIndex: Map<string, rustdoc.Dir>;
/** Defined and documented in `main.js` */
declare function nonnull(x: T|null, msg: string|undefined);
interface Window { interface Window {
/** Make the current theme easy to find */ /** Make the current theme easy to find */
currentTheme: HTMLLinkElement|null; currentTheme: HTMLLinkElement|null;
@ -40,6 +44,23 @@ declare global {
* or if this is a docs page, this function does nothing. * or if this is a docs page, this function does nothing.
*/ */
rustdocShowSourceSidebar: function(), rustdocShowSourceSidebar: function(),
/**
* Close the sidebar in source code view
*/
rustdocCloseSourceSidebar?: function(),
/**
* Shows the sidebar in source code view
*/
rustdocShowSourceSidebar?: function(),
/**
* Toggles the sidebar in source code view
*/
rustdocToggleSrcSidebar?: function(),
/**
* create's the sidebar in source code view.
* called in generated `src-files.js`.
*/
createSrcSidebar?: function(),
/** /**
* Set up event listeners for a scraped source example. * Set up event listeners for a scraped source example.
*/ */
@ -438,4 +459,12 @@ declare namespace rustdoc {
type TypeImpls = { type TypeImpls = {
[cratename: string]: Array<Array<string|0>> [cratename: string]: Array<Array<string|0>>
} }
/**
* Directory structure for source code view,
* defined in generated `src-files.js`.
*
* is a tuple of (filename, subdirs, filenames).
*/
type Dir = [string, rustdoc.Dir[], string[]]
} }

View file

@ -3,10 +3,8 @@
// Local js definitions: // Local js definitions:
/* global addClass, onEachLazy, removeClass, browserSupportsHistoryApi */ /* global addClass, onEachLazy, removeClass, browserSupportsHistoryApi */
/* global updateLocalStorage, getVar */ /* global updateLocalStorage, getVar, nonnull */
// Eventually fix this.
// @ts-nocheck
"use strict"; "use strict";
@ -29,6 +27,14 @@ function closeSidebarIfMobile() {
} }
} }
/**
* @param {rustdoc.Dir} elem
* @param {HTMLElement} parent
* @param {string} fullPath
* @param {boolean} hasFoundFile
*
* @returns {boolean} - new value for hasFoundFile
*/
function createDirEntry(elem, parent, fullPath, hasFoundFile) { function createDirEntry(elem, parent, fullPath, hasFoundFile) {
const dirEntry = document.createElement("details"); const dirEntry = document.createElement("details");
const summary = document.createElement("summary"); const summary = document.createElement("summary");
@ -95,7 +101,7 @@ window.rustdocToggleSrcSidebar = () => {
// This function is called from "src-files.js", generated in `html/render/write_shared.rs`. // This function is called from "src-files.js", generated in `html/render/write_shared.rs`.
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function createSrcSidebar() { function createSrcSidebar() {
const container = document.querySelector("nav.sidebar"); const container = nonnull(document.querySelector("nav.sidebar"));
const sidebar = document.createElement("div"); const sidebar = document.createElement("div");
sidebar.id = "src-sidebar"; sidebar.id = "src-sidebar";
@ -111,6 +117,7 @@ function createSrcSidebar() {
// Focus on the current file in the source files sidebar. // Focus on the current file in the source files sidebar.
const selected_elem = sidebar.getElementsByClassName("selected")[0]; const selected_elem = sidebar.getElementsByClassName("selected")[0];
if (typeof selected_elem !== "undefined") { if (typeof selected_elem !== "undefined") {
// @ts-expect-error
selected_elem.focus(); selected_elem.focus();
} }
} }
@ -130,11 +137,12 @@ function highlightSrcLines() {
to = from; to = from;
from = tmp; from = tmp;
} }
let elem = document.getElementById(from); const from_s = "" + from;
let elem = document.getElementById(from_s);
if (!elem) { if (!elem) {
return; return;
} }
const x = document.getElementById(from); const x = document.getElementById(from_s);
if (x) { if (x) {
x.scrollIntoView(); x.scrollIntoView();
} }
@ -142,7 +150,7 @@ function highlightSrcLines() {
removeClass(e, "line-highlighted"); removeClass(e, "line-highlighted");
}); });
for (let i = from; i <= to; ++i) { for (let i = from; i <= to; ++i) {
elem = document.getElementById(i); elem = document.getElementById("" + i);
if (!elem) { if (!elem) {
break; break;
} }
@ -153,11 +161,12 @@ function highlightSrcLines() {
const handleSrcHighlight = (function() { const handleSrcHighlight = (function() {
let prev_line_id = 0; let prev_line_id = 0;
/** @type {function(string): void} */
const set_fragment = name => { const set_fragment = name => {
const x = window.scrollX, const x = window.scrollX,
y = window.scrollY; y = window.scrollY;
if (browserSupportsHistoryApi()) { if (browserSupportsHistoryApi()) {
history.replaceState(null, null, "#" + name); history.replaceState(null, "", "#" + name);
highlightSrcLines(); highlightSrcLines();
} else { } else {
location.replace("#" + name); location.replace("#" + name);
@ -166,6 +175,7 @@ const handleSrcHighlight = (function() {
window.scrollTo(x, y); window.scrollTo(x, y);
}; };
// @ts-expect-error
return ev => { return ev => {
let cur_line_id = parseInt(ev.target.id, 10); let cur_line_id = parseInt(ev.target.id, 10);
// This event handler is attached to the entire line number column, but it should only // This event handler is attached to the entire line number column, but it should only
@ -191,7 +201,7 @@ const handleSrcHighlight = (function() {
} else { } else {
prev_line_id = cur_line_id; prev_line_id = cur_line_id;
set_fragment(cur_line_id); set_fragment("" + cur_line_id);
} }
}; };
}()); }());

View file

@ -21,6 +21,28 @@ const settingsDataset = (function() {
return settingsElement && settingsElement.dataset ? settingsElement.dataset : null; return settingsElement && settingsElement.dataset ? settingsElement.dataset : null;
})(); })();
/**
* Assert that the passed value is nonnull, then return it.
*
* Takes an optional error message argument.
*
* Must be defined in this file, as it is loaded before all others.
*
* @template T
* @param {T|null} x
* @param {string=} msg
* @returns T
*/
// used in other files, not yet used in this one.
// eslint-disable-next-line no-unused-vars
function nonnull(x, msg) {
if (x === null) {
throw (msg || "unexpected null value!");
} else {
return x;
}
}
/** /**
* Get a configuration value. If it's not set, get the default. * Get a configuration value. If it's not set, get the default.
* *

View file

@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
/// This integer is incremented with every breaking change to the API, /// This integer is incremented with every breaking change to the API,
/// and is returned along with the JSON blob as [`Crate::format_version`]. /// and is returned along with the JSON blob as [`Crate::format_version`].
/// Consuming code should assert that this value matches the format version(s) that it supports. /// Consuming code should assert that this value matches the format version(s) that it supports.
pub const FORMAT_VERSION: u32 = 42; pub const FORMAT_VERSION: u32 = 43;
/// The root of the emitted JSON blob. /// The root of the emitted JSON blob.
/// ///
@ -120,9 +120,23 @@ pub struct Item {
pub docs: Option<String>, pub docs: Option<String>,
/// This mapping resolves [intra-doc links](https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md) from the docstring to their IDs /// This mapping resolves [intra-doc links](https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md) from the docstring to their IDs
pub links: HashMap<String, Id>, pub links: HashMap<String, Id>,
/// Stringified versions of parsed attributes on this item. /// Attributes on this item.
/// Essentially debug printed (e.g. `#[inline]` becomes something similar to `#[attr="Inline(Hint)"]`). ///
/// Equivalent to the hir pretty-printing of attributes. /// Does not include `#[deprecated]` attributes: see the [`Self::deprecation`] field instead.
///
/// Some attributes appear in pretty-printed Rust form, regardless of their formatting
/// in the original source code. For example:
/// - `#[non_exhaustive]` and `#[must_use]` are represented as themselves.
/// - `#[no_mangle]` and `#[export_name]` are also represented as themselves.
/// - `#[repr(C)]` and other reprs also appear as themselves,
/// though potentially with a different order: e.g. `repr(i8, C)` may become `repr(C, i8)`.
/// Multiple repr attributes on the same item may be combined into an equivalent single attr.
///
/// Other attributes may appear debug-printed. For example:
/// - `#[inline]` becomes something similar to `#[attr="Inline(Hint)"]`.
///
/// As an internal implementation detail subject to change, this debug-printing format
/// is currently equivalent to the HIR pretty-printing of parsed attributes.
pub attrs: Vec<String>, pub attrs: Vec<String>,
/// Information about the items deprecation, if present. /// Information about the items deprecation, if present.
pub deprecation: Option<Deprecation>, pub deprecation: Option<Deprecation>,

View file

@ -1,6 +1,6 @@
#![no_std] #![no_std]
//@ is "$.index[?(@.name=='Aligned')].attrs" '["#[attr = Repr([ReprAlign(Align(4 bytes))])]\n"]' //@ is "$.index[?(@.name=='Aligned')].attrs" '["#[repr(align(4))]"]'
#[repr(align(4))] #[repr(align(4))]
pub struct Aligned { pub struct Aligned {
a: i8, a: i8,

View file

@ -1,16 +1,16 @@
#![no_std] #![no_std]
//@ is "$.index[?(@.name=='ReprCStruct')].attrs" '["#[attr = Repr([ReprC])]\n"]' //@ is "$.index[?(@.name=='ReprCStruct')].attrs" '["#[repr(C)]"]'
#[repr(C)] #[repr(C)]
pub struct ReprCStruct(pub i64); pub struct ReprCStruct(pub i64);
//@ is "$.index[?(@.name=='ReprCEnum')].attrs" '["#[attr = Repr([ReprC])]\n"]' //@ is "$.index[?(@.name=='ReprCEnum')].attrs" '["#[repr(C)]"]'
#[repr(C)] #[repr(C)]
pub enum ReprCEnum { pub enum ReprCEnum {
First, First,
} }
//@ is "$.index[?(@.name=='ReprCUnion')].attrs" '["#[attr = Repr([ReprC])]\n"]' //@ is "$.index[?(@.name=='ReprCUnion')].attrs" '["#[repr(C)]"]'
#[repr(C)] #[repr(C)]
pub union ReprCUnion { pub union ReprCUnion {
pub left: i64, pub left: i64,

View file

@ -1,34 +1,35 @@
#![no_std] #![no_std]
// Combinations of `#[repr(..)]` attributes. // Combinations of `#[repr(..)]` attributes.
// Rustdoc JSON emits normalized output, regardless of the original source.
//@ is "$.index[?(@.name=='ReprCI8')].attrs" '["#[attr = Repr([ReprC, ReprInt(SignedInt(I8))])]\n"]' //@ is "$.index[?(@.name=='ReprCI8')].attrs" '["#[repr(C, i8)]"]'
#[repr(C, i8)] #[repr(C, i8)]
pub enum ReprCI8 { pub enum ReprCI8 {
First, First,
} }
//@ is "$.index[?(@.name=='SeparateReprCI16')].attrs" '["#[attr = Repr([ReprC, ReprInt(SignedInt(I16))])]\n"]' //@ is "$.index[?(@.name=='SeparateReprCI16')].attrs" '["#[repr(C, i16)]"]'
#[repr(C)] #[repr(C)]
#[repr(i16)] #[repr(i16)]
pub enum SeparateReprCI16 { pub enum SeparateReprCI16 {
First, First,
} }
//@ is "$.index[?(@.name=='ReversedReprCUsize')].attrs" '["#[attr = Repr([ReprInt(UnsignedInt(Usize)), ReprC])]\n"]' //@ is "$.index[?(@.name=='ReversedReprCUsize')].attrs" '["#[repr(C, usize)]"]'
#[repr(usize, C)] #[repr(usize, C)]
pub enum ReversedReprCUsize { pub enum ReversedReprCUsize {
First, First,
} }
//@ is "$.index[?(@.name=='ReprCPacked')].attrs" '["#[attr = Repr([ReprC, ReprPacked(Align(1 bytes))])]\n"]' //@ is "$.index[?(@.name=='ReprCPacked')].attrs" '["#[repr(C, packed(1))]"]'
#[repr(C, packed)] #[repr(C, packed)]
pub struct ReprCPacked { pub struct ReprCPacked {
a: i8, a: i8,
b: i64, b: i64,
} }
//@ is "$.index[?(@.name=='SeparateReprCPacked')].attrs" '["#[attr = Repr([ReprC, ReprPacked(Align(2 bytes))])]\n"]' //@ is "$.index[?(@.name=='SeparateReprCPacked')].attrs" '["#[repr(C, packed(2))]"]'
#[repr(C)] #[repr(C)]
#[repr(packed(2))] #[repr(packed(2))]
pub struct SeparateReprCPacked { pub struct SeparateReprCPacked {
@ -36,21 +37,21 @@ pub struct SeparateReprCPacked {
b: i64, b: i64,
} }
//@ is "$.index[?(@.name=='ReversedReprCPacked')].attrs" '["#[attr = Repr([ReprPacked(Align(2 bytes)), ReprC])]\n"]' //@ is "$.index[?(@.name=='ReversedReprCPacked')].attrs" '["#[repr(C, packed(2))]"]'
#[repr(packed(2), C)] #[repr(packed(2), C)]
pub struct ReversedReprCPacked { pub struct ReversedReprCPacked {
a: i8, a: i8,
b: i64, b: i64,
} }
//@ is "$.index[?(@.name=='ReprCAlign')].attrs" '["#[attr = Repr([ReprC, ReprAlign(Align(16 bytes))])]\n"]' //@ is "$.index[?(@.name=='ReprCAlign')].attrs" '["#[repr(C, align(16))]"]'
#[repr(C, align(16))] #[repr(C, align(16))]
pub struct ReprCAlign { pub struct ReprCAlign {
a: i8, a: i8,
b: i64, b: i64,
} }
//@ is "$.index[?(@.name=='SeparateReprCAlign')].attrs" '["#[attr = Repr([ReprC, ReprAlign(Align(2 bytes))])]\n"]' //@ is "$.index[?(@.name=='SeparateReprCAlign')].attrs" '["#[repr(C, align(2))]"]'
#[repr(C)] #[repr(C)]
#[repr(align(2))] #[repr(align(2))]
pub struct SeparateReprCAlign { pub struct SeparateReprCAlign {
@ -58,20 +59,20 @@ pub struct SeparateReprCAlign {
b: i64, b: i64,
} }
//@ is "$.index[?(@.name=='ReversedReprCAlign')].attrs" '["#[attr = Repr([ReprAlign(Align(2 bytes)), ReprC])]\n"]' //@ is "$.index[?(@.name=='ReversedReprCAlign')].attrs" '["#[repr(C, align(2))]"]'
#[repr(align(2), C)] #[repr(align(2), C)]
pub struct ReversedReprCAlign { pub struct ReversedReprCAlign {
a: i8, a: i8,
b: i64, b: i64,
} }
//@ is "$.index[?(@.name=='AlignedExplicitRepr')].attrs" '["#[attr = Repr([ReprC, ReprAlign(Align(16 bytes)), ReprInt(SignedInt(Isize))])]\n"]' //@ is "$.index[?(@.name=='AlignedExplicitRepr')].attrs" '["#[repr(C, align(16), isize)]"]'
#[repr(C, align(16), isize)] #[repr(C, align(16), isize)]
pub enum AlignedExplicitRepr { pub enum AlignedExplicitRepr {
First, First,
} }
//@ is "$.index[?(@.name=='ReorderedAlignedExplicitRepr')].attrs" '["#[attr = Repr([ReprInt(SignedInt(Isize)), ReprC, ReprAlign(Align(16 bytes))])]\n"]' //@ is "$.index[?(@.name=='ReorderedAlignedExplicitRepr')].attrs" '["#[repr(C, align(16), isize)]"]'
#[repr(isize, C, align(16))] #[repr(isize, C, align(16))]
pub enum ReorderedAlignedExplicitRepr { pub enum ReorderedAlignedExplicitRepr {
First, First,

View file

@ -1,18 +1,18 @@
#![no_std] #![no_std]
//@ is "$.index[?(@.name=='I8')].attrs" '["#[attr = Repr([ReprInt(SignedInt(I8))])]\n"]' //@ is "$.index[?(@.name=='I8')].attrs" '["#[repr(i8)]"]'
#[repr(i8)] #[repr(i8)]
pub enum I8 { pub enum I8 {
First, First,
} }
//@ is "$.index[?(@.name=='I32')].attrs" '["#[attr = Repr([ReprInt(SignedInt(I32))])]\n"]' //@ is "$.index[?(@.name=='I32')].attrs" '["#[repr(i32)]"]'
#[repr(i32)] #[repr(i32)]
pub enum I32 { pub enum I32 {
First, First,
} }
//@ is "$.index[?(@.name=='Usize')].attrs" '["#[attr = Repr([ReprInt(UnsignedInt(Usize))])]\n"]' //@ is "$.index[?(@.name=='Usize')].attrs" '["#[repr(usize)]"]'
#[repr(usize)] #[repr(usize)]
pub enum Usize { pub enum Usize {
First, First,

View file

@ -1,16 +1,16 @@
#![no_std] #![no_std]
// Note the normalization: // Note the normalization:
// `#[repr(packed)]` in has the implict "1" in rustdoc JSON. // `#[repr(packed)]` in source becomes `#[repr(packed(1))]` in rustdoc JSON.
//
//@ is "$.index[?(@.name=='Packed')].attrs" '["#[attr = Repr([ReprPacked(Align(1 bytes))])]\n"]' //@ is "$.index[?(@.name=='Packed')].attrs" '["#[repr(packed(1))]"]'
#[repr(packed)] #[repr(packed)]
pub struct Packed { pub struct Packed {
a: i8, a: i8,
b: i64, b: i64,
} }
//@ is "$.index[?(@.name=='PackedAligned')].attrs" '["#[attr = Repr([ReprPacked(Align(4 bytes))])]\n"]' //@ is "$.index[?(@.name=='PackedAligned')].attrs" '["#[repr(packed(4))]"]'
#[repr(packed(4))] #[repr(packed(4))]
pub struct PackedAligned { pub struct PackedAligned {
a: i8, a: i8,

View file

@ -1,22 +1,37 @@
#![no_std] #![no_std]
// Rustdoc JSON currently includes `#[repr(transparent)]` // Rustdoc JSON *only* includes `#[repr(transparent)]`
// even if the transparency is not part of the public API // if the transparency is public API:
// - if a non-1-ZST field exists, it has to be public
// - otherwise, all fields are 1-ZST and at least one of them is public
// //
// https://doc.rust-lang.org/nomicon/other-reprs.html#reprtransparent // More info: https://doc.rust-lang.org/nomicon/other-reprs.html#reprtransparent
//@ is "$.index[?(@.name=='Transparent')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]' // Here, the non-1-ZST field is public.
// We expect `#[repr(transparent)]` in the attributes.
//
//@ is "$.index[?(@.name=='Transparent')].attrs" '["#[repr(transparent)]"]'
#[repr(transparent)] #[repr(transparent)]
pub struct Transparent(pub i64); pub struct Transparent(pub i64);
//@ is "$.index[?(@.name=='TransparentNonPub')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]' // Here the non-1-ZST field isn't public, so the attribute isn't included.
//
//@ has "$.index[?(@.name=='TransparentNonPub')]"
//@ is "$.index[?(@.name=='TransparentNonPub')].attrs" '[]'
#[repr(transparent)] #[repr(transparent)]
pub struct TransparentNonPub(i64); pub struct TransparentNonPub(i64);
//@ is "$.index[?(@.name=='AllZst')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]' // Only 1-ZST fields here, and one of them is public.
// We expect `#[repr(transparent)]` in the attributes.
//
//@ is "$.index[?(@.name=='AllZst')].attrs" '["#[repr(transparent)]"]'
#[repr(transparent)] #[repr(transparent)]
pub struct AllZst<'a>(pub core::marker::PhantomData<&'a ()>, ()); pub struct AllZst<'a>(pub core::marker::PhantomData<&'a ()>, ());
//@ is "$.index[?(@.name=='AllZstNotPublic')].attrs" '["#[attr = Repr([ReprTransparent])]\n"]' // Only 1-ZST fields here but none of them are public.
// The attribute isn't included.
//
//@ has "$.index[?(@.name=='AllZstNotPublic')]"
//@ is "$.index[?(@.name=='AllZstNotPublic')].attrs" '[]'
#[repr(transparent)] #[repr(transparent)]
pub struct AllZstNotPublic<'a>(core::marker::PhantomData<&'a ()>, ()); pub struct AllZstNotPublic<'a>(core::marker::PhantomData<&'a ()>, ());

View file

@ -1,5 +1,5 @@
#[repr(i32)] #[repr(i32)]
//@ is "$.index[?(@.name=='Foo')].attrs" '["#[attr = Repr([ReprInt(SignedInt(I32))])]\n"]' //@ is "$.index[?(@.name=='Foo')].attrs" '["#[repr(i32)]"]'
pub enum Foo { pub enum Foo {
//@ is "$.index[?(@.name=='Struct')].inner.variant.discriminant" null //@ is "$.index[?(@.name=='Struct')].inner.variant.discriminant" null
//@ count "$.index[?(@.name=='Struct')].inner.variant.kind.struct.fields[*]" 0 //@ count "$.index[?(@.name=='Struct')].inner.variant.kind.struct.fields[*]" 0

View file

@ -1,5 +1,5 @@
#[repr(u32)] #[repr(u32)]
//@ is "$.index[?(@.name=='Foo')].attrs" '["#[attr = Repr([ReprInt(UnsignedInt(U32))])]\n"]' //@ is "$.index[?(@.name=='Foo')].attrs" '["#[repr(u32)]"]'
pub enum Foo { pub enum Foo {
//@ is "$.index[?(@.name=='Tuple')].inner.variant.discriminant" null //@ is "$.index[?(@.name=='Tuple')].inner.variant.discriminant" null
//@ count "$.index[?(@.name=='Tuple')].inner.variant.kind.tuple[*]" 0 //@ count "$.index[?(@.name=='Tuple')].inner.variant.kind.tuple[*]" 0

View file

@ -16,7 +16,7 @@ warning: unused attribute
LL | #![allow(linker_messages)] LL | #![allow(linker_messages)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
| |
= note: the `linker_warnings` lint can only be controlled at the root of a crate that needs to be linked = note: the `linker_messages` lint can only be controlled at the root of a crate that needs to be linked
warning: 2 warnings emitted warning: 2 warnings emitted