From 0842f2c65c766301be488256a18d89e90c3b6304 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Wed, 5 Feb 2025 19:37:27 -0800 Subject: [PATCH 01/19] Add fast path for displaying pre-validated Wtf8Buf --- library/std/src/sys/os_str/wtf8.rs | 4 ++-- library/std/src/sys_common/wtf8.rs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/os_str/wtf8.rs b/library/std/src/sys/os_str/wtf8.rs index 19728d33990..8acec6f949f 100644 --- a/library/std/src/sys/os_str/wtf8.rs +++ b/library/std/src/sys/os_str/wtf8.rs @@ -41,13 +41,13 @@ impl AsInner for Buf { impl fmt::Debug for Buf { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(self.as_slice(), f) + fmt::Debug::fmt(&self.inner, f) } } impl fmt::Display for Buf { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self.as_slice(), f) + fmt::Display::fmt(&self.inner, f) } } diff --git a/library/std/src/sys_common/wtf8.rs b/library/std/src/sys_common/wtf8.rs index 952c39132b0..01cbb3e24ff 100644 --- a/library/std/src/sys_common/wtf8.rs +++ b/library/std/src/sys_common/wtf8.rs @@ -169,6 +169,18 @@ impl fmt::Debug for Wtf8Buf { } } +/// Formats the string with unpaired surrogates substituted with the replacement +/// character, U+FFFD. +impl fmt::Display for Wtf8Buf { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + if let Some(s) = self.as_known_utf8() { + fmt::Display::fmt(s, formatter) + } else { + fmt::Display::fmt(&**self, formatter) + } + } +} + impl Wtf8Buf { /// Creates a new, empty WTF-8 string. #[inline] @@ -262,6 +274,18 @@ impl Wtf8Buf { unsafe { Wtf8::from_mut_bytes_unchecked(&mut self.bytes) } } + /// Converts the string to UTF-8 without validation, if it was created from + /// valid UTF-8. + #[inline] + fn as_known_utf8(&self) -> Option<&str> { + if self.is_known_utf8 { + // SAFETY: The buffer is known to be valid UTF-8. + Some(unsafe { str::from_utf8_unchecked(self.as_bytes()) }) + } else { + None + } + } + /// Reserves capacity for at least `additional` more bytes to be inserted /// in the given `Wtf8Buf`. /// The collection may reserve more space to avoid frequent reallocations. From eb14652770451022d424a1c301a4416514464932 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Fri, 7 Feb 2025 11:54:02 -0800 Subject: [PATCH 02/19] Skip scanning for surrogates when not known valid --- library/std/src/sys_common/wtf8.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys_common/wtf8.rs b/library/std/src/sys_common/wtf8.rs index 01cbb3e24ff..f9ec112b197 100644 --- a/library/std/src/sys_common/wtf8.rs +++ b/library/std/src/sys_common/wtf8.rs @@ -388,7 +388,7 @@ impl Wtf8Buf { _ => { // If we'll be pushing a string containing a surrogate, we may // no longer have UTF-8. - if other.next_surrogate(0).is_some() { + if self.is_known_utf8 && other.next_surrogate(0).is_some() { self.is_known_utf8 = false; } From cf1242c461e035fd2cfb99f620e810015744cac4 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Wed, 19 Feb 2025 07:16:25 +0100 Subject: [PATCH 03/19] Enable `f16` for MIPS It seems as if `f16` works on MIPS now according to my testing on Rust master with LLVM 20, and I was asked to create PRs with my changes. I only tested on the flavour of `mipsel-unknown-linux-gnu` hardware that happens to be available to me, so I can't say anything about other MIPS hardware, but from a casual skimming of the LLVM code ([1], [2]) it seems like `f16` should work on all MIPS hardware. So enable it for all MIPS hardware. [1]: https://github.com/rust-lang/llvm-project/blob/rustc/20.1-2025-02-13/llvm/lib/Target/Mips/MipsISelLowering.h#L370 [2]: https://github.com/rust-lang/llvm-project/blob/rustc/20.1-2025-02-13/llvm/lib/CodeGen/TargetLoweringBase.cpp#L1367-L1388 --- library/std/build.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/std/build.rs b/library/std/build.rs index 8dc326a3dde..723d1eb02e0 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -107,7 +107,6 @@ fn main() { ("csky", _) => false, ("hexagon", _) => false, ("loongarch64", _) => false, - ("mips" | "mips64" | "mips32r6" | "mips64r6", _) => false, ("powerpc" | "powerpc64", _) => false, ("sparc" | "sparc64", _) => false, ("wasm32" | "wasm64", _) => false, From 123062bfd9ab2f017bbd18c93a325c8f707d3859 Mon Sep 17 00:00:00 2001 From: usamoi Date: Wed, 5 Feb 2025 20:09:50 +0800 Subject: [PATCH 04/19] pass optimization level to llvm-bitcode-linker --- compiler/rustc_codegen_ssa/src/back/linker.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 8900405c1b8..818edaf6603 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -1939,14 +1939,14 @@ impl<'a> Linker for LlbcLinker<'a> { } fn optimize(&mut self) { - match self.sess.opts.optimize { + self.link_arg(match self.sess.opts.optimize { OptLevel::No => "-O0", OptLevel::Less => "-O1", OptLevel::More => "-O2", OptLevel::Aggressive => "-O3", OptLevel::Size => "-Os", OptLevel::SizeMin => "-Oz", - }; + }); } fn full_relro(&mut self) {} From 6fc19785f7d4d0b91304a8c90348a2dbfd24d664 Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Sun, 23 Feb 2025 22:17:18 +0530 Subject: [PATCH 05/19] fixed by differentiating glob export --- src/librustdoc/passes/propagate_stability.rs | 12 +++++++++ tests/rustdoc/inline_local/staged-inline.rs | 28 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/librustdoc/passes/propagate_stability.rs b/src/librustdoc/passes/propagate_stability.rs index 9c958710c42..8cf39afd55c 100644 --- a/src/librustdoc/passes/propagate_stability.rs +++ b/src/librustdoc/passes/propagate_stability.rs @@ -39,6 +39,16 @@ impl DocFolder for StabilityPropagator<'_, '_> { let item_stability = self.cx.tcx.lookup_stability(def_id); let inline_stability = item.inline_stmt_id.and_then(|did| self.cx.tcx.lookup_stability(did)); + let is_glob_export = item.inline_stmt_id.and_then(|id| { + let hir_id = self.cx.tcx.local_def_id_to_hir_id(id); + Some(matches!( + self.cx.tcx.hir_node(hir_id), + rustc_hir::Node::Item(rustc_hir::Item { + kind: rustc_hir::ItemKind::Use(_, rustc_hir::UseKind::Glob), + .. + }) + )) + }); let own_stability = if let Some(item_stab) = item_stability && let StabilityLevel::Stable { since: _, allowed_through_unstable_modules } = item_stab.level @@ -47,6 +57,8 @@ impl DocFolder for StabilityPropagator<'_, '_> { since: inline_since, allowed_through_unstable_modules: _, } = inline_stab.level + && let Some(is_global_export) = is_glob_export + && !is_global_export { inline_stab.level = StabilityLevel::Stable { since: inline_since, diff --git a/tests/rustdoc/inline_local/staged-inline.rs b/tests/rustdoc/inline_local/staged-inline.rs index f2131ad5f94..ffe9a5d7c3c 100644 --- a/tests/rustdoc/inline_local/staged-inline.rs +++ b/tests/rustdoc/inline_local/staged-inline.rs @@ -16,3 +16,31 @@ pub mod ffi { //@ has "foo/struct.CStr.html" "//span[@class='sub-heading']/span[@class='since']" "1.0.0" //@ !has - "//span[@class='sub-heading']/span[@class='since']" "1.99.0" pub use ffi::CStr; + +// https://github.com/rust-lang/rust/issues/137141 +#[stable(feature = "futures_api", since = "1.36.0")] +//@ has "foo/task/index.html" "//span[@class='sub-heading']/span[@class='since']" "1.36.0" +//@ !has - "//span[@class='sub-heading']/span[@class='since']" "1.0.0" +pub mod task { + + #[doc(inline)] + #[stable(feature = "futures_api", since = "1.36.0")] + //@ has "foo/task/index.html" "//span[@class='sub-heading']/span[@class='since']" "1.36.0" + //@ has "foo/task/ready/index.html" "//span[@class='sub-heading']/span[@class='since']" "1.64.0" + pub use core::task::*; +} + +#[stable(feature = "futures_api", since = "1.36.0")] +//@ has "foo/core/index.html" "//span[@class='sub-heading']/span[@class='since']" "1.36.0" +//@ !has - "//span[@class='sub-heading']/span[@class='since']" "1.0.0" +pub mod core { + #[stable(feature = "futures_api", since = "1.36.0")] + //@ has "foo/core/task/index.html" "//span[@class='sub-heading']/span[@class='since']" "1.36.0" + pub mod task { + + #[stable(feature = "ready_macro", since = "1.64.0")] + //@ has "foo/core/task/ready/index.html" "//span[@class='sub-heading']/span[@class='since']" "1.64.0" + pub mod ready { + } + } +} \ No newline at end of file From afc89a1e021c99bdcd89a71c4c93ff6f3a2072c8 Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Sun, 23 Feb 2025 22:24:00 +0530 Subject: [PATCH 06/19] Fixed tidy error --- tests/rustdoc/inline_local/staged-inline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rustdoc/inline_local/staged-inline.rs b/tests/rustdoc/inline_local/staged-inline.rs index ffe9a5d7c3c..d0dc3f9eea7 100644 --- a/tests/rustdoc/inline_local/staged-inline.rs +++ b/tests/rustdoc/inline_local/staged-inline.rs @@ -43,4 +43,4 @@ pub mod core { pub mod ready { } } -} \ No newline at end of file +} From 5afa6a111bcf8552b8de15d1aec060580add640f Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 4 Dec 2024 12:51:59 +0000 Subject: [PATCH 07/19] ssa/mono: deduplicate `type_has_metadata` The implementation of the `type_has_metadata` function is duplicated in `rustc_codegen_ssa` and `rustc_monomorphize`, so move this to `rustc_middle`. --- compiler/rustc_codegen_ssa/src/mir/place.rs | 8 ++++++-- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 4 ++-- compiler/rustc_codegen_ssa/src/traits/type_.rs | 15 +-------------- compiler/rustc_middle/src/ty/util.rs | 14 ++++++++++++++ compiler/rustc_monomorphize/src/collector.rs | 13 +------------ 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index edd09b9c3c5..00e01e47fee 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -2,7 +2,7 @@ use rustc_abi::Primitive::{Int, Pointer}; use rustc_abi::{Align, BackendRepr, FieldsShape, Size, TagEncoding, VariantIdx, Variants}; use rustc_middle::mir::PlaceTy; use rustc_middle::mir::interpret::Scalar; -use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout}; use rustc_middle::ty::{self, Ty}; use rustc_middle::{bug, mir}; use tracing::{debug, instrument}; @@ -168,7 +168,11 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { }; let val = PlaceValue { llval, - llextra: if bx.cx().type_has_metadata(field.ty) { self.val.llextra } else { None }, + llextra: if bx.cx().tcx().type_has_metadata(field.ty, bx.cx().typing_env()) { + self.val.llextra + } else { + None + }, align: effective_field_align, }; val.with_type(field) diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 1eebe04225b..d24e48b37a4 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -3,7 +3,7 @@ use std::assert_matches::assert_matches; use arrayvec::ArrayVec; use rustc_abi::{self as abi, FIRST_VARIANT, FieldIdx}; use rustc_middle::ty::adjustment::PointerCoercion; -use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout}; +use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_middle::{bug, mir, span_bug}; use rustc_session::config::OptLevel; @@ -878,7 +878,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let ty = cg_place.layout.ty; assert!( - if bx.cx().type_has_metadata(ty) { + if bx.cx().tcx().type_has_metadata(ty, bx.cx().typing_env()) { matches!(val, OperandValue::Pair(..)) } else { matches!(val, OperandValue::Immediate(..)) diff --git a/compiler/rustc_codegen_ssa/src/traits/type_.rs b/compiler/rustc_codegen_ssa/src/traits/type_.rs index c178ebc596e..fbd927d0d66 100644 --- a/compiler/rustc_codegen_ssa/src/traits/type_.rs +++ b/compiler/rustc_codegen_ssa/src/traits/type_.rs @@ -1,7 +1,7 @@ use rustc_abi::{AddressSpace, Float, Integer, Reg}; use rustc_middle::bug; +use rustc_middle::ty::Ty; use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, TyAndLayout}; -use rustc_middle::ty::{self, Ty}; use rustc_target::callconv::{ArgAbi, CastTarget, FnAbi}; use super::BackendTypes; @@ -84,19 +84,6 @@ pub trait DerivedTypeCodegenMethods<'tcx>: fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool { ty.is_freeze(self.tcx(), self.typing_env()) } - - fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool { - if ty.is_sized(self.tcx(), self.typing_env()) { - return false; - } - - let tail = self.tcx().struct_tail_for_codegen(ty, self.typing_env()); - match tail.kind() { - ty::Foreign(..) => false, - ty::Str | ty::Slice(..) | ty::Dynamic(..) => true, - _ => bug!("unexpected unsized tail: {:?}", tail), - } - } } impl<'tcx, T> DerivedTypeCodegenMethods<'tcx> for T where diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index c153f6bb7d7..4d917963cd6 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -208,6 +208,20 @@ impl<'tcx> TyCtxt<'tcx> { tcx.struct_tail_raw(ty, |ty| tcx.normalize_erasing_regions(typing_env, ty), || {}) } + /// Returns true if a type has metadata. + pub fn type_has_metadata(self, ty: Ty<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> bool { + if ty.is_sized(self, typing_env) { + return false; + } + + let tail = self.struct_tail_for_codegen(ty, typing_env); + match tail.kind() { + ty::Foreign(..) => false, + ty::Str | ty::Slice(..) | ty::Dynamic(..) => true, + _ => bug!("unexpected unsized tail: {:?}", tail), + } + } + /// Returns the deeply last field of nested structures, or the same type if /// not a structure at all. Corresponds to the only possible unsized field, /// and its type can be used to determine unsizing strategy. diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index d7cb8f18f82..f8af6837fc2 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1043,18 +1043,7 @@ fn find_vtable_types_for_unsizing<'tcx>( ) -> (Ty<'tcx>, Ty<'tcx>) { let ptr_vtable = |inner_source: Ty<'tcx>, inner_target: Ty<'tcx>| { let typing_env = ty::TypingEnv::fully_monomorphized(); - let type_has_metadata = |ty: Ty<'tcx>| -> bool { - if ty.is_sized(tcx.tcx, typing_env) { - return false; - } - let tail = tcx.struct_tail_for_codegen(ty, typing_env); - match tail.kind() { - ty::Foreign(..) => false, - ty::Str | ty::Slice(..) | ty::Dynamic(..) => true, - _ => bug!("unexpected unsized tail: {:?}", tail), - } - }; - if type_has_metadata(inner_source) { + if tcx.type_has_metadata(inner_source, typing_env) { (inner_source, inner_target) } else { tcx.struct_lockstep_tails_for_codegen(inner_source, inner_target, typing_env) From a5615d3c626549df8da9ccf1a284e1262967ddfa Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 4 Feb 2025 12:20:09 +0000 Subject: [PATCH 08/19] codegen_llvm: avoid `Deref` impls w/ extern type `rustc_codegen_llvm` relied on `Deref` impls where `Deref::Target` was or contained an extern type - in my experimental implementation of rust-lang/rfcs#3729, this isn't possible as the `Target` associated type's `?Sized` bound cannot be relaxed backwards compatibly (unless we come up with some way of doing this). In later pull requests with the rust-lang/rfcs#3729 implementation, breakage like this could only occur for nightly users relying on the `extern_types` feature. Upstreaming this to avoid needing to keep carrying this patch locally, and I think it'll necessarily need to change eventually. --- compiler/rustc_codegen_llvm/src/back/lto.rs | 6 ++++-- .../src/back/owned_target_machine.rs | 11 +++++----- compiler/rustc_codegen_llvm/src/back/write.rs | 6 +++--- compiler/rustc_codegen_llvm/src/builder.rs | 6 +++--- compiler/rustc_codegen_llvm/src/common.rs | 2 +- compiler/rustc_codegen_llvm/src/context.rs | 2 +- compiler/rustc_codegen_llvm/src/llvm/mod.rs | 21 +++++++++---------- compiler/rustc_codegen_llvm/src/llvm_util.rs | 7 ++++--- 8 files changed, 31 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 99906ea7bce..05a2cd1c5a3 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -793,7 +793,9 @@ pub(crate) unsafe fn optimize_thin_module( { let _timer = cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_rename", thin_module.name()); - unsafe { llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target) }; + unsafe { + llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target.raw()) + }; save_temp_bitcode(cgcx, &module, "thin-lto-after-rename"); } @@ -823,7 +825,7 @@ pub(crate) unsafe fn optimize_thin_module( let _timer = cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_import", thin_module.name()); if unsafe { - !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target) + !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target.raw()) } { return Err(write::llvm_err(dcx, LlvmError::PrepareThinLtoModule)); } diff --git a/compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs b/compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs index f075f332462..dfde4595590 100644 --- a/compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs +++ b/compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs @@ -1,6 +1,5 @@ use std::ffi::{CStr, c_char}; use std::marker::PhantomData; -use std::ops::Deref; use std::ptr::NonNull; use rustc_data_structures::small_c_str::SmallCStr; @@ -80,12 +79,12 @@ impl OwnedTargetMachine { .map(|tm_unique| Self { tm_unique, phantom: PhantomData }) .ok_or_else(|| LlvmError::CreateTargetMachine { triple: SmallCStr::from(triple) }) } -} -impl Deref for OwnedTargetMachine { - type Target = llvm::TargetMachine; - - fn deref(&self) -> &Self::Target { + /// Returns inner `llvm::TargetMachine` type. + /// + /// This could be a `Deref` implementation, but `llvm::TargetMachine` is an extern type and + /// `Deref::Target: ?Sized`. + pub fn raw(&self) -> &llvm::TargetMachine { // SAFETY: constructing ensures we have a valid pointer created by // llvm::LLVMRustCreateTargetMachine. unsafe { self.tm_unique.as_ref() } diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index b67890c0465..29d6121844f 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -637,7 +637,7 @@ pub(crate) unsafe fn llvm_optimize( let result = unsafe { llvm::LLVMRustOptimize( module.module_llvm.llmod(), - &*module.module_llvm.tm, + &*module.module_llvm.tm.raw(), to_pass_builder_opt_level(opt_level), opt_stage, cgcx.opts.cg.linker_plugin_lto.enabled(), @@ -875,7 +875,7 @@ pub(crate) unsafe fn codegen( }; write_output_file( dcx, - tm, + tm.raw(), config.no_builtins, llmod, &path, @@ -909,7 +909,7 @@ pub(crate) unsafe fn codegen( write_output_file( dcx, - tm, + tm.raw(), config.no_builtins, llmod, &obj_out, diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 677a9cd3e90..3f20350d0ef 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -405,7 +405,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { // Emit KCFI operand bundle let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn); - if let Some(kcfi_bundle) = kcfi_bundle.as_deref() { + if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) { bundles.push(kcfi_bundle); } @@ -1433,7 +1433,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { // Emit KCFI operand bundle let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn); - if let Some(kcfi_bundle) = kcfi_bundle.as_deref() { + if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) { bundles.push(kcfi_bundle); } @@ -1782,7 +1782,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { // Emit KCFI operand bundle let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn); - if let Some(kcfi_bundle) = kcfi_bundle.as_deref() { + if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) { bundles.push(kcfi_bundle); } diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index f17d98fa242..0621b893e75 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -77,7 +77,7 @@ impl<'ll> Funclet<'ll> { } pub(crate) fn bundle(&self) -> &llvm::OperandBundle<'ll> { - &self.operand + self.operand.raw() } } diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index e7952bc95e7..ed8426ae197 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -205,7 +205,7 @@ pub(crate) unsafe fn create_module<'ll>( { let tm = crate::back::write::create_informational_target_machine(tcx.sess, false); unsafe { - llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, &tm); + llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm.raw()); } let llvm_data_layout = unsafe { llvm::LLVMGetDataLayoutStr(llmod) }; diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs index 5ec93424131..a36226b25a2 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs @@ -1,7 +1,6 @@ #![allow(non_snake_case)] use std::ffi::{CStr, CString}; -use std::ops::Deref; use std::ptr; use std::str::FromStr; use std::string::FromUtf8Error; @@ -355,6 +354,16 @@ impl<'a> OperandBundleOwned<'a> { }; OperandBundleOwned { raw: ptr::NonNull::new(raw).unwrap() } } + + /// Returns inner `OperandBundle` type. + /// + /// This could be a `Deref` implementation, but `OperandBundle` contains an extern type and + /// `Deref::Target: ?Sized`. + pub(crate) fn raw(&self) -> &OperandBundle<'a> { + // SAFETY: The returned reference is opaque and can only used for FFI. + // It is valid for as long as `&self` is. + unsafe { self.raw.as_ref() } + } } impl Drop for OperandBundleOwned<'_> { @@ -365,16 +374,6 @@ impl Drop for OperandBundleOwned<'_> { } } -impl<'a> Deref for OperandBundleOwned<'a> { - type Target = OperandBundle<'a>; - - fn deref(&self) -> &Self::Target { - // SAFETY: The returned reference is opaque and can only used for FFI. - // It is valid for as long as `&self` is. - unsafe { self.raw.as_ref() } - } -} - pub(crate) fn add_module_flag_u32( module: &Module, merge_behavior: ModuleFlagMergeBehavior, diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 1fcb20e0d7b..5cc4f4ab9e6 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -331,7 +331,8 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec print_target_cpus(sess, &tm, out), - PrintKind::TargetFeatures => print_target_features(sess, &tm, out), + PrintKind::TargetCPUs => print_target_cpus(sess, tm.raw(), out), + PrintKind::TargetFeatures => print_target_features(sess, tm.raw(), out), _ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req), } } From 21d41b09dfb782d44da4c487d5c377bf36e9bddc Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 24 Feb 2025 08:11:02 +0000 Subject: [PATCH 09/19] trait_sel: resolve vars in host effects In the standard library, the `Extend` impl for `Iterator` (specialised with `TrustedLen`) has a parameter which is constrained by a projection predicate. This projection predicate provides a value for an inference variable but host effect evaluation wasn't resolving variables first. Adding the extra resolve can the number of errors in some tests when they gain host effect predicates, but this is not unexpected as calls to `resolve_vars_if_possible` can cause more error tainting to happen. Co-authored-by: Boxy --- .../src/traits/effects.rs | 2 ++ .../unconstrained-var-specialization.rs | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/ui/traits/const-traits/unconstrained-var-specialization.rs diff --git a/compiler/rustc_trait_selection/src/traits/effects.rs b/compiler/rustc_trait_selection/src/traits/effects.rs index b32909efe0b..3c127416cbf 100644 --- a/compiler/rustc_trait_selection/src/traits/effects.rs +++ b/compiler/rustc_trait_selection/src/traits/effects.rs @@ -31,6 +31,8 @@ pub fn evaluate_host_effect_obligation<'tcx>( ); } + let ref obligation = selcx.infcx.resolve_vars_if_possible(obligation.clone()); + // Force ambiguity for infer self ty. if obligation.predicate.self_ty().is_ty_var() { return Err(EvaluationFailure::Ambiguous); diff --git a/tests/ui/traits/const-traits/unconstrained-var-specialization.rs b/tests/ui/traits/const-traits/unconstrained-var-specialization.rs new file mode 100644 index 00000000000..43a33114450 --- /dev/null +++ b/tests/ui/traits/const-traits/unconstrained-var-specialization.rs @@ -0,0 +1,36 @@ +//@ check-pass +//@ compile-flags: --crate-type=lib +#![no_std] +#![allow(internal_features)] +#![feature(rustc_attrs, min_specialization, const_trait_impl)] + +// In the default impl below, `A` is constrained by the projection predicate, and if the host effect +// predicate for `const Foo` doesn't resolve vars, then specialization will fail. + +#[const_trait] +trait Foo {} + +pub trait Iterator { + type Item; +} + +#[rustc_unsafe_specialization_marker] +pub trait MoreSpecificThanIterator: Iterator {} + +pub trait Tr { + fn foo(); +} + +impl Tr for Iter + where + Iter: Iterator, +{ + default fn foo() {} +} + +impl Tr for Iter + where + Iter: MoreSpecificThanIterator, +{ + fn foo() {} +} From cede9029fd97bef27565269f7f251ca5d3ac2c4a Mon Sep 17 00:00:00 2001 From: klensy Date: Mon, 24 Feb 2025 12:19:52 +0300 Subject: [PATCH 10/19] cleanup few unused args --- compiler/rustc_borrowck/src/lib.rs | 4 ++-- compiler/rustc_monomorphize/src/collector.rs | 2 +- compiler/rustc_resolve/src/diagnostics.rs | 9 ++------- compiler/rustc_resolve/src/imports.rs | 8 +++----- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index a98984a4b4c..68e0ab0933e 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -648,7 +648,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt< | StatementKind::StorageLive(..) => {} // This does not affect borrowck StatementKind::BackwardIncompatibleDropHint { place, reason: BackwardIncompatibleDropReason::Edition2024 } => { - self.check_backward_incompatible_drop(location, (**place, span), state); + self.check_backward_incompatible_drop(location, **place, state); } StatementKind::StorageDead(local) => { self.access_place( @@ -1174,7 +1174,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { fn check_backward_incompatible_drop( &mut self, location: Location, - (place, place_span): (Place<'tcx>, Span), + place: Place<'tcx>, state: &BorrowckDomain, ) { let tcx = self.infcx.tcx; diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 1195c25e130..9d9032025a4 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -752,7 +752,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { /// This does not walk the MIR of the constant as that is not needed for codegen, all we need is /// to ensure that the constant evaluates successfully and walk the result. #[instrument(skip(self), level = "debug")] - fn visit_const_operand(&mut self, constant: &mir::ConstOperand<'tcx>, location: Location) { + fn visit_const_operand(&mut self, constant: &mir::ConstOperand<'tcx>, _location: Location) { // No `super_constant` as we don't care about `visit_ty`/`visit_ty_const`. let Some(val) = self.eval_constant(constant) else { return }; collect_const_value(self.tcx, val, self.used_items); diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 5db6f83f3ee..f0418e9c27b 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -2252,7 +2252,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { #[instrument(level = "debug", skip(self, parent_scope))] pub(crate) fn make_path_suggestion( &mut self, - span: Span, mut path: Vec, parent_scope: &ParentScope<'ra>, ) -> Option<(Vec, Option)> { @@ -2480,7 +2479,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // or `use a::{b, c, d}};` // ^^^^^^^^^^^ let (has_nested, after_crate_name) = - find_span_immediately_after_crate_name(self.tcx.sess, module_name, import.use_span); + find_span_immediately_after_crate_name(self.tcx.sess, import.use_span); debug!(has_nested, ?after_crate_name); let source_map = self.tcx.sess.source_map(); @@ -2687,11 +2686,7 @@ fn extend_span_to_previous_binding(sess: &Session, binding_span: Span) -> Option /// // ^^^^^^^^^^^^^^^ -- true /// ``` #[instrument(level = "debug", skip(sess))] -fn find_span_immediately_after_crate_name( - sess: &Session, - module_name: Symbol, - use_span: Span, -) -> (bool, Span) { +fn find_span_immediately_after_crate_name(sess: &Session, use_span: Span) -> (bool, Span) { let source_map = sess.source_map(); // Using `use issue_59764::foo::{baz, makro};` as an example throughout.. diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 46e52e1f131..59081134a6d 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -955,11 +955,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } else { None }; - let err = match self.make_path_suggestion( - span, - import.module_path.clone(), - &import.parent_scope, - ) { + let err = match self + .make_path_suggestion(import.module_path.clone(), &import.parent_scope) + { Some((suggestion, note)) => UnresolvedImportError { span, label: None, From 7bf6fc16f24902d5efc5fc2c5ba6b72840a239b9 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 24 Feb 2025 09:49:06 +0000 Subject: [PATCH 11/19] tests: add variance test for const traits Added to demonstrate change in output in following commit. Many more interesting tests change with different output, missing errors, new errors, etc related to this but they all depend on feature flags and are much more complex than this. --- tests/ui/traits/const-traits/variance.rs | 14 ++++++++++++++ tests/ui/traits/const-traits/variance.stderr | 8 ++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/ui/traits/const-traits/variance.rs create mode 100644 tests/ui/traits/const-traits/variance.stderr diff --git a/tests/ui/traits/const-traits/variance.rs b/tests/ui/traits/const-traits/variance.rs new file mode 100644 index 00000000000..9eaf7910cb8 --- /dev/null +++ b/tests/ui/traits/const-traits/variance.rs @@ -0,0 +1,14 @@ +#![feature(rustc_attrs, const_trait_impl)] +#![allow(internal_features)] +#![rustc_variance_of_opaques] + +#[const_trait] +trait Foo {} + +impl const Foo for () {} + +fn foo<'a: 'a>() -> impl const Foo {} +//~^ ERROR ['a: o] + +fn main() {} + diff --git a/tests/ui/traits/const-traits/variance.stderr b/tests/ui/traits/const-traits/variance.stderr new file mode 100644 index 00000000000..f6efc24b747 --- /dev/null +++ b/tests/ui/traits/const-traits/variance.stderr @@ -0,0 +1,8 @@ +error: ['a: o] + --> $DIR/variance.rs:10:21 + | +LL | fn foo<'a: 'a>() -> impl const Foo {} + | ^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + From 0bed12e02d75f9d786a3496cb243355e603809ad Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 24 Feb 2025 09:50:22 +0000 Subject: [PATCH 12/19] hir_analysis: skip self type of host effect preds Like trait predicates, the self type ought to be skipped here. --- compiler/rustc_hir_analysis/src/variance/mod.rs | 4 ++++ tests/ui/traits/const-traits/variance.rs | 3 +-- tests/ui/traits/const-traits/variance.stderr | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index a7760326bb4..0800d99e945 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -198,6 +198,10 @@ fn variance_of_opaque( ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref: ty::TraitRef { def_id: _, args, .. }, polarity: _, + }) + | ty::ClauseKind::HostEffect(ty::HostEffectPredicate { + trait_ref: ty::TraitRef { def_id: _, args, .. }, + constness: _, }) => { for arg in &args[1..] { arg.visit_with(&mut collector); diff --git a/tests/ui/traits/const-traits/variance.rs b/tests/ui/traits/const-traits/variance.rs index 9eaf7910cb8..90b5c50161d 100644 --- a/tests/ui/traits/const-traits/variance.rs +++ b/tests/ui/traits/const-traits/variance.rs @@ -8,7 +8,6 @@ trait Foo {} impl const Foo for () {} fn foo<'a: 'a>() -> impl const Foo {} -//~^ ERROR ['a: o] +//~^ ERROR ['a: *] fn main() {} - diff --git a/tests/ui/traits/const-traits/variance.stderr b/tests/ui/traits/const-traits/variance.stderr index f6efc24b747..f5506931184 100644 --- a/tests/ui/traits/const-traits/variance.stderr +++ b/tests/ui/traits/const-traits/variance.stderr @@ -1,4 +1,4 @@ -error: ['a: o] +error: ['a: *] --> $DIR/variance.rs:10:21 | LL | fn foo<'a: 'a>() -> impl const Foo {} From db6da1268e874dad5d727a916edfd7ebb615129c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 24 Feb 2025 17:49:20 +0300 Subject: [PATCH 13/19] tests: Add regression test for derive token invalidation (#81099) --- .../ui/proc-macro/derive-cfg-nested-tokens.rs | 23 +++ .../derive-cfg-nested-tokens.stdout | 149 ++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 tests/ui/proc-macro/derive-cfg-nested-tokens.rs create mode 100644 tests/ui/proc-macro/derive-cfg-nested-tokens.stdout diff --git a/tests/ui/proc-macro/derive-cfg-nested-tokens.rs b/tests/ui/proc-macro/derive-cfg-nested-tokens.rs new file mode 100644 index 00000000000..7d4e8d8373d --- /dev/null +++ b/tests/ui/proc-macro/derive-cfg-nested-tokens.rs @@ -0,0 +1,23 @@ +// A regression test for issue #81099. + +//@ check-pass +//@ proc-macro:test-macros.rs + +#![feature(stmt_expr_attributes)] +#![feature(proc_macro_hygiene)] + +#[macro_use] +extern crate test_macros; + +#[derive(Clone, Copy)] +struct S { + // `print_args` runs twice + // - on eagerly configured `S` (from `impl Copy`), only 11 should be printed + // - on non-configured `S` (from `struct S`), both 10 and 11 should be printed + field: [u8; #[print_attr] { + #[cfg(FALSE)] { 10 } + #[cfg(not(FALSE))] { 11 } + }], +} + +fn main() {} diff --git a/tests/ui/proc-macro/derive-cfg-nested-tokens.stdout b/tests/ui/proc-macro/derive-cfg-nested-tokens.stdout new file mode 100644 index 00000000000..05bf21ee8f9 --- /dev/null +++ b/tests/ui/proc-macro/derive-cfg-nested-tokens.stdout @@ -0,0 +1,149 @@ +PRINT-ATTR INPUT (DISPLAY): { #[cfg(not(FALSE))] { 11 } } +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Group { + delimiter: Brace, + stream: TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: #0 bytes(491..492), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "cfg", + span: #0 bytes(493..496), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "not", + span: #0 bytes(497..500), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "FALSE", + span: #0 bytes(501..506), + }, + ], + span: #0 bytes(500..507), + }, + ], + span: #0 bytes(496..508), + }, + ], + span: #0 bytes(492..509), + }, + Group { + delimiter: Brace, + stream: TokenStream [ + Literal { + kind: Integer, + symbol: "11", + suffix: None, + span: #0 bytes(513..515), + }, + ], + span: #0 bytes(511..517), + }, + ], + span: #0 bytes(452..523), + }, +] +PRINT-ATTR INPUT (DISPLAY): { #[cfg(FALSE)] { 10 } #[cfg(not(FALSE))] { 11 } } +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Group { + delimiter: Brace, + stream: TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: #0 bytes(462..463), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "cfg", + span: #0 bytes(464..467), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "FALSE", + span: #0 bytes(468..473), + }, + ], + span: #0 bytes(467..474), + }, + ], + span: #0 bytes(463..475), + }, + Group { + delimiter: Brace, + stream: TokenStream [ + Literal { + kind: Integer, + symbol: "10", + suffix: None, + span: #0 bytes(478..480), + }, + ], + span: #0 bytes(476..482), + }, + Punct { + ch: '#', + spacing: Alone, + span: #0 bytes(491..492), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "cfg", + span: #0 bytes(493..496), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "not", + span: #0 bytes(497..500), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "FALSE", + span: #0 bytes(501..506), + }, + ], + span: #0 bytes(500..507), + }, + ], + span: #0 bytes(496..508), + }, + ], + span: #0 bytes(492..509), + }, + Group { + delimiter: Brace, + stream: TokenStream [ + Literal { + kind: Integer, + symbol: "11", + suffix: None, + span: #0 bytes(513..515), + }, + ], + span: #0 bytes(511..517), + }, + ], + span: #0 bytes(452..523), + }, +] From 60fc2beebbc0509e89af89cb021bdd67ea6239df Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Mon, 24 Feb 2025 19:48:24 +0100 Subject: [PATCH 14/19] run some tests on emscripten again these were ignored because of #45351, but that issue has long been fixed. Let's see if these pass, or if there is some issue lurking still --- .../simd/intrinsic/generic-arithmetic-pass.rs | 2 -- tests/ui/simd/intrinsic/generic-cast-pass.rs | 2 -- .../simd/intrinsic/generic-comparison-pass.rs | 18 ++++++++---------- .../ui/simd/intrinsic/generic-elements-pass.rs | 2 -- tests/ui/simd/issue-32947.rs | 5 +---- tests/ui/simd/issue-39720.rs | 1 - 6 files changed, 9 insertions(+), 21 deletions(-) diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs index 4a18c0164e4..29d82255d4e 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs +++ b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs @@ -1,6 +1,5 @@ //@ run-pass #![allow(non_camel_case_types)] -//@ ignore-emscripten FIXME(#45351) hits an LLVM assert #![feature(repr_simd, intrinsics)] #[repr(simd)] @@ -53,7 +52,6 @@ unsafe fn simd_or(x: T, y: T) -> T; #[rustc_intrinsic] unsafe fn simd_xor(x: T, y: T) -> T; - #[rustc_intrinsic] unsafe fn simd_neg(x: T) -> T; diff --git a/tests/ui/simd/intrinsic/generic-cast-pass.rs b/tests/ui/simd/intrinsic/generic-cast-pass.rs index 2155d845864..aab7347d1de 100644 --- a/tests/ui/simd/intrinsic/generic-cast-pass.rs +++ b/tests/ui/simd/intrinsic/generic-cast-pass.rs @@ -1,9 +1,7 @@ //@ run-pass -//@ ignore-emscripten FIXME(#45351) hits an LLVM assert #![feature(repr_simd, intrinsics)] - #[rustc_intrinsic] unsafe fn simd_cast(x: T) -> U; diff --git a/tests/ui/simd/intrinsic/generic-comparison-pass.rs b/tests/ui/simd/intrinsic/generic-comparison-pass.rs index 68f98372e1d..d0ec2503602 100644 --- a/tests/ui/simd/intrinsic/generic-comparison-pass.rs +++ b/tests/ui/simd/intrinsic/generic-comparison-pass.rs @@ -1,5 +1,4 @@ //@ run-pass -//@ ignore-emscripten FIXME(#45351) hits an LLVM assert #![feature(repr_simd, intrinsics, concat_idents)] #![allow(non_camel_case_types)] @@ -14,7 +13,6 @@ struct u32x4(pub [u32; 4]); #[derive(Copy, Clone)] struct f32x4(pub [f32; 4]); - #[rustc_intrinsic] unsafe fn simd_eq(x: T, y: T) -> U; @@ -39,11 +37,11 @@ macro_rules! cmp { let rhs = $rhs; let e: u32x4 = concat_idents!(simd_, $method)($lhs, $rhs); // assume the scalar version is correct/the behaviour we want. - assert!((e.0[0] != 0) == lhs.0[0] .$method(&rhs.0[0])); - assert!((e.0[1] != 0) == lhs.0[1] .$method(&rhs.0[1])); - assert!((e.0[2] != 0) == lhs.0[2] .$method(&rhs.0[2])); - assert!((e.0[3] != 0) == lhs.0[3] .$method(&rhs.0[3])); - }} + assert!((e.0[0] != 0) == lhs.0[0].$method(&rhs.0[0])); + assert!((e.0[1] != 0) == lhs.0[1].$method(&rhs.0[1])); + assert!((e.0[2] != 0) == lhs.0[2].$method(&rhs.0[2])); + assert!((e.0[3] != 0) == lhs.0[3].$method(&rhs.0[3])); + }}; } macro_rules! tests { ($($lhs: ident, $rhs: ident;)*) => {{ @@ -75,9 +73,9 @@ fn main() { let i2 = i32x4([5, -5, 20, -100]); let i3 = i32x4([10, -11, 20, -100]); - let u1 = u32x4([10, !11+1, 12, 13]); - let u2 = u32x4([5, !5+1, 20, !100+1]); - let u3 = u32x4([10, !11+1, 20, !100+1]); + let u1 = u32x4([10, !11 + 1, 12, 13]); + let u2 = u32x4([5, !5 + 1, 20, !100 + 1]); + let u3 = u32x4([10, !11 + 1, 20, !100 + 1]); let f1 = f32x4([10.0, -11.0, 12.0, 13.0]); let f2 = f32x4([5.0, -5.0, 20.0, -100.0]); diff --git a/tests/ui/simd/intrinsic/generic-elements-pass.rs b/tests/ui/simd/intrinsic/generic-elements-pass.rs index 8cb600bc9e4..b8d872c5cb7 100644 --- a/tests/ui/simd/intrinsic/generic-elements-pass.rs +++ b/tests/ui/simd/intrinsic/generic-elements-pass.rs @@ -1,5 +1,4 @@ //@ run-pass -//@ ignore-emscripten FIXME(#45351) hits an LLVM assert #![feature(repr_simd, intrinsics)] @@ -22,7 +21,6 @@ unsafe fn simd_insert(x: T, idx: u32, y: E) -> T; #[rustc_intrinsic] unsafe fn simd_extract(x: T, idx: u32) -> E; - #[rustc_intrinsic] unsafe fn simd_shuffle(x: T, y: T, idx: I) -> U; diff --git a/tests/ui/simd/issue-32947.rs b/tests/ui/simd/issue-32947.rs index dc5e7a4ec91..b34484b2d3b 100644 --- a/tests/ui/simd/issue-32947.rs +++ b/tests/ui/simd/issue-32947.rs @@ -1,5 +1,4 @@ //@ run-pass -//@ ignore-emscripten FIXME(#45351) #![feature(repr_simd, test)] @@ -15,9 +14,7 @@ fn main() { // non-optimized builds unsafe { let memory = &mut [0u64; 8] as *mut _ as *mut u8; - let misaligned_ptr: &mut [u8; 32] = { - std::mem::transmute(memory.offset(1)) - }; + let misaligned_ptr: &mut [u8; 32] = { std::mem::transmute(memory.offset(1)) }; *misaligned_ptr = std::mem::transmute(Mu64([1, 1, 1, 1])); test::black_box(memory); } diff --git a/tests/ui/simd/issue-39720.rs b/tests/ui/simd/issue-39720.rs index 8d7666faaf9..c3c4750d6de 100644 --- a/tests/ui/simd/issue-39720.rs +++ b/tests/ui/simd/issue-39720.rs @@ -1,5 +1,4 @@ //@ run-pass -//@ ignore-emscripten FIXME(#45351) #![feature(repr_simd, intrinsics)] From 8467a7658133fdc274e18f36357768000a3a7519 Mon Sep 17 00:00:00 2001 From: klensy Date: Mon, 24 Feb 2025 12:25:17 +0300 Subject: [PATCH 15/19] remove unused field from VariantDef::new and convert debug to instrument --- compiler/rustc_hir_analysis/src/collect.rs | 1 - compiler/rustc_metadata/src/rmeta/decoder.rs | 1 - compiler/rustc_middle/src/ty/mod.rs | 8 +------- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 5bb77c096dc..1a0d1cc7b9f 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1075,7 +1075,6 @@ fn lower_variant<'tcx>( def.ctor().map(|(kind, _, def_id)| (kind, def_id.to_def_id())), discr, fields, - adt_kind, parent_did.to_def_id(), recovered, adt_kind == AdtKind::Struct && tcx.has_attr(parent_did, sym::non_exhaustive) diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index e8dcda875e6..93594ff0f9a 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1118,7 +1118,6 @@ impl<'a> CrateMetadataRef<'a> { value: self.get_default_field(did.index), }) .collect(), - adt_kind, parent_did, None, data.is_non_exhaustive, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index bd1fb0ca41c..c44dca91fd9 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1183,23 +1183,17 @@ impl VariantDef { /// /// If someone speeds up attribute loading to not be a performance concern, they can /// remove this hack and use the constructor `DefId` everywhere. + #[instrument(level = "debug")] pub fn new( name: Symbol, variant_did: Option, ctor: Option<(CtorKind, DefId)>, discr: VariantDiscr, fields: IndexVec, - adt_kind: AdtKind, parent_did: DefId, recover_tainted: Option, is_field_list_non_exhaustive: bool, ) -> Self { - debug!( - "VariantDef::new(name = {:?}, variant_did = {:?}, ctor = {:?}, discr = {:?}, - fields = {:?}, adt_kind = {:?}, parent_did = {:?})", - name, variant_did, ctor, discr, fields, adt_kind, parent_did, - ); - let mut flags = VariantFlags::NO_VARIANT_FLAGS; if is_field_list_non_exhaustive { flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE; From 00e80e7b8b436430b4f4d065f0fde1646eff6a76 Mon Sep 17 00:00:00 2001 From: Colin Pitrat Date: Tue, 25 Feb 2025 11:47:11 +0000 Subject: [PATCH 16/19] Complete the list of resources used in rustdoc output --- src/librustdoc/html/static/COPYRIGHT.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/librustdoc/html/static/COPYRIGHT.txt b/src/librustdoc/html/static/COPYRIGHT.txt index 111340298c5..84826e5d077 100644 --- a/src/librustdoc/html/static/COPYRIGHT.txt +++ b/src/librustdoc/html/static/COPYRIGHT.txt @@ -45,6 +45,17 @@ included, and carry their own copyright notices and license terms: Licensed under the SIL Open Font License, Version 1.1. See SourceSerif4-LICENSE.md. +* Nanum Barun Gothic Font (NanumBarunGothic.woff2) + + Copyright 2017 NAVER, free for personal and commercial use. + https://hangeul.naver.com/2017/nanum + +* Rust logos (rust-logo.svg, favicon.svg, favicon-32x32.png) + + Copyright 2025 Rust Foundation. + Licensed under the Creative Commons Attribution license (CC-BY). + https://rustfoundation.org/policy/rust-trademark-policy/ + This copyright file is intended to be distributed with rustdoc output. # REUSE-IgnoreEnd From eaf8fc56d7695b5d6681518a74c4bf8050a4ff5e Mon Sep 17 00:00:00 2001 From: Colin Pitrat Date: Tue, 25 Feb 2025 12:24:30 +0000 Subject: [PATCH 17/19] Update information about NanumBarunGothic --- src/librustdoc/html/static/COPYRIGHT.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/COPYRIGHT.txt b/src/librustdoc/html/static/COPYRIGHT.txt index 84826e5d077..752dab0a347 100644 --- a/src/librustdoc/html/static/COPYRIGHT.txt +++ b/src/librustdoc/html/static/COPYRIGHT.txt @@ -47,8 +47,18 @@ included, and carry their own copyright notices and license terms: * Nanum Barun Gothic Font (NanumBarunGothic.woff2) - Copyright 2017 NAVER, free for personal and commercial use. + Copyright 2010, NAVER Corporation (http://www.nhncorp.com) + with Reserved Font Name Nanum, Naver Nanum, NanumGothic, Naver NanumGothic, + NanumMyeongjo, Naver NanumMyeongjo, NanumBrush, Naver NanumBrush, NanumPen, + Naver NanumPen, Naver NanumGothicEco, NanumGothicEco, + Naver NanumMyeongjoEco, NanumMyeongjoEco, Naver NanumGothicLight, + NanumGothicLight, NanumBarunGothic, Naver NanumBarunGothic. + https://hangeul.naver.com/2017/nanum + https://github.com/hiun/NanumBarunGothic + + Licensed under the SIL Open Font License, Version 1.1. + See NanumBarunGothic-LICENSE.txt. * Rust logos (rust-logo.svg, favicon.svg, favicon-32x32.png) From 48483adcb42ea07858800cf9c0be6531e204c6b7 Mon Sep 17 00:00:00 2001 From: xizheyin Date: Tue, 25 Feb 2025 21:21:00 +0800 Subject: [PATCH 18/19] fix doc in library/core/src/pin.rs Signed-off-by: xizheyin --- library/core/src/pin.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 2a0bf89fcf7..7fcd19f67ee 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -1240,8 +1240,8 @@ impl Pin { /// points to is pinned, that is a violation of the API contract and may lead to undefined /// behavior in later (even safe) operations. /// - /// By using this method, you are also making a promise about the [`Deref`] and - /// [`DerefMut`] implementations of `Ptr`, if they exist. Most importantly, they + /// By using this method, you are also making a promise about the [`Deref`], + /// [`DerefMut`], and [`Drop`] implementations of `Ptr`, if they exist. Most importantly, they /// must not move out of their `self` arguments: `Pin::as_mut` and `Pin::as_ref` /// will call `DerefMut::deref_mut` and `Deref::deref` *on the pointer type `Ptr`* /// and expect these methods to uphold the pinning invariants. From 4bf66c57fad749b0efe331c4c9e40f0a65e56e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jana=20D=C3=B6nszelmann?= Date: Tue, 25 Feb 2025 16:53:10 +0100 Subject: [PATCH 19/19] fix #137589 --- compiler/rustc_attr_parsing/src/context.rs | 5 ++++- compiler/rustc_attr_parsing/src/parser.rs | 13 +++++++----- tests/ui/attributes/crate-type-macro-empty.rs | 7 +++++++ .../attributes/crate-type-macro-empty.stderr | 20 +++++++++++++++++++ .../attributes/crate-type-macro-not-crate.rs | 9 +++++++++ .../crate-type-macro-not-crate.stderr | 17 ++++++++++++++++ .../attributes/crate-type-macro-not-found.rs | 8 ++++++++ .../crate-type-macro-not-found.stderr | 14 +++++++++++++ 8 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 tests/ui/attributes/crate-type-macro-empty.rs create mode 100644 tests/ui/attributes/crate-type-macro-empty.stderr create mode 100644 tests/ui/attributes/crate-type-macro-not-crate.rs create mode 100644 tests/ui/attributes/crate-type-macro-not-crate.stderr create mode 100644 tests/ui/attributes/crate-type-macro-not-found.rs create mode 100644 tests/ui/attributes/crate-type-macro-not-found.stderr diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 99eee0d3c4a..0e6b0bab082 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -333,7 +333,10 @@ impl<'sess> AttributeParser<'sess> { { lit } else { - let guar = self.dcx().has_errors().unwrap(); + let guar = self.dcx().span_delayed_bug( + args.span().unwrap_or(DUMMY_SP), + "expr in place where literal is expected (builtin attr parsing)", + ); ast::MetaItemLit { symbol: kw::Empty, suffix: None, diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs index 0ee0ea4ea59..b6d66af4466 100644 --- a/compiler/rustc_attr_parsing/src/parser.rs +++ b/compiler/rustc_attr_parsing/src/parser.rs @@ -13,7 +13,7 @@ use rustc_ast_pretty::pprust; use rustc_errors::DiagCtxtHandle; use rustc_hir::{self as hir, AttrPath}; use rustc_span::symbol::{Ident, kw}; -use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol}; +use rustc_span::{ErrorGuaranteed, Span, Symbol}; pub struct SegmentIterator<'a> { offset: usize, @@ -127,7 +127,7 @@ impl<'a> ArgParser<'a> { } AttrArgs::Eq { eq_span, expr } => Self::NameValue(NameValueParser { eq_span: *eq_span, - value: expr_to_lit(dcx, &expr), + value: expr_to_lit(dcx, &expr, *eq_span), value_span: expr.span, }), } @@ -348,7 +348,7 @@ impl NameValueParser { } } -fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr) -> MetaItemLit { +fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr, span: Span) -> MetaItemLit { // In valid code the value always ends up as a single literal. Otherwise, a dummy // literal suffices because the error is handled elsewhere. if let ExprKind::Lit(token_lit) = expr.kind @@ -356,8 +356,11 @@ fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr) -> MetaItemLit { { lit } else { - let guar = dcx.has_errors().unwrap(); - MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span: DUMMY_SP } + let guar = dcx.span_delayed_bug( + span, + "expr in place where literal is expected (builtin attr parsing)", + ); + MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span } } } diff --git a/tests/ui/attributes/crate-type-macro-empty.rs b/tests/ui/attributes/crate-type-macro-empty.rs new file mode 100644 index 00000000000..5ff7fc002fd --- /dev/null +++ b/tests/ui/attributes/crate-type-macro-empty.rs @@ -0,0 +1,7 @@ +// Tests for the issue in #137589 +#[crate_type = foo!()] +//~^ ERROR cannot find macro `foo` in this scope + +macro_rules! foo {} //~ ERROR unexpected end of macro invocation + +fn main() {} diff --git a/tests/ui/attributes/crate-type-macro-empty.stderr b/tests/ui/attributes/crate-type-macro-empty.stderr new file mode 100644 index 00000000000..e48d3d95470 --- /dev/null +++ b/tests/ui/attributes/crate-type-macro-empty.stderr @@ -0,0 +1,20 @@ +error: unexpected end of macro invocation + --> $DIR/crate-type-macro-empty.rs:5:1 + | +LL | macro_rules! foo {} + | ^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments + +error: cannot find macro `foo` in this scope + --> $DIR/crate-type-macro-empty.rs:2:16 + | +LL | #[crate_type = foo!()] + | ^^^ consider moving the definition of `foo` before this call + | +note: a macro with the same name exists, but it appears later + --> $DIR/crate-type-macro-empty.rs:5:14 + | +LL | macro_rules! foo {} + | ^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/attributes/crate-type-macro-not-crate.rs b/tests/ui/attributes/crate-type-macro-not-crate.rs new file mode 100644 index 00000000000..e5eb22d6f6e --- /dev/null +++ b/tests/ui/attributes/crate-type-macro-not-crate.rs @@ -0,0 +1,9 @@ +// Tests for the issue in #137589 + + +macro_rules! foo { + ($x:expr) => {"rlib"} +} + +#[crate_type = foo!()] //~ ERROR unexpected end of macro invocation +fn main() {} diff --git a/tests/ui/attributes/crate-type-macro-not-crate.stderr b/tests/ui/attributes/crate-type-macro-not-crate.stderr new file mode 100644 index 00000000000..ce188b3eef5 --- /dev/null +++ b/tests/ui/attributes/crate-type-macro-not-crate.stderr @@ -0,0 +1,17 @@ +error: unexpected end of macro invocation + --> $DIR/crate-type-macro-not-crate.rs:8:16 + | +LL | macro_rules! foo { + | ---------------- when calling this macro +... +LL | #[crate_type = foo!()] + | ^^^^^^ missing tokens in macro arguments + | +note: while trying to match meta-variable `$x:expr` + --> $DIR/crate-type-macro-not-crate.rs:5:6 + | +LL | ($x:expr) => {"rlib"} + | ^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/attributes/crate-type-macro-not-found.rs b/tests/ui/attributes/crate-type-macro-not-found.rs new file mode 100644 index 00000000000..824468c0e85 --- /dev/null +++ b/tests/ui/attributes/crate-type-macro-not-found.rs @@ -0,0 +1,8 @@ +// Tests for the issue in #137589 +#[crate_type = foo!()] //~ ERROR cannot find macro `foo` in this scope + +macro_rules! foo { + ($x:expr) => {"rlib"} +} + +fn main() {} diff --git a/tests/ui/attributes/crate-type-macro-not-found.stderr b/tests/ui/attributes/crate-type-macro-not-found.stderr new file mode 100644 index 00000000000..a4967e4f12e --- /dev/null +++ b/tests/ui/attributes/crate-type-macro-not-found.stderr @@ -0,0 +1,14 @@ +error: cannot find macro `foo` in this scope + --> $DIR/crate-type-macro-not-found.rs:2:16 + | +LL | #[crate_type = foo!()] + | ^^^ consider moving the definition of `foo` before this call + | +note: a macro with the same name exists, but it appears later + --> $DIR/crate-type-macro-not-found.rs:4:14 + | +LL | macro_rules! foo { + | ^^^ + +error: aborting due to 1 previous error +