From 4ded686917c8fca90b0c1f66f8f49cbd801e60b5 Mon Sep 17 00:00:00 2001 From: fereidani Date: Mon, 10 Aug 2026 08:33:47 +0330 Subject: [PATCH 01/34] Optimize linked list iterator performance --- library/alloc/src/collections/linked_list.rs | 80 +++++++++++--------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index ca3b2eab30402..379569f0ffeea 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -1200,16 +1200,18 @@ impl<'a, T> Iterator for Iter<'a, T> { #[inline] fn next(&mut self) -> Option<&'a T> { if self.len == 0 { - None - } else { - self.head.map(|node| unsafe { - // Need an unbound lifetime to get 'a - let node = &*node.as_ptr(); - self.len -= 1; - self.head = node.next; - &node.element - }) + return None; } + // SAFETY: When `len > 0`, `head` and `tail` are guaranteed to be `Some`. + // The lifetime of the returned reference is bound to the lifetime of the iterator, + // which is valid because the iterator holds a reference to the list. + Some(unsafe { + // Need an unbound lifetime to get 'a + let node = &*self.head.unwrap_unchecked().as_ptr(); + self.len -= 1; + self.head = node.next; + &node.element + }) } #[inline] @@ -1228,16 +1230,18 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { if self.len == 0 { - None - } else { - self.tail.map(|node| unsafe { - // Need an unbound lifetime to get 'a - let node = &*node.as_ptr(); - self.len -= 1; - self.tail = node.prev; - &node.element - }) + return None; } + // SAFETY: When `len > 0`, `head` and `tail` are guaranteed to be `Some`. + // The lifetime of the returned reference is bound to the lifetime of the iterator, + // which is valid because the iterator holds a reference to the list. + Some(unsafe { + // Need an unbound lifetime to get 'a + let node = &*self.tail.unwrap_unchecked().as_ptr(); + self.len -= 1; + self.tail = node.prev; + &node.element + }) } } @@ -1268,16 +1272,18 @@ impl<'a, T> Iterator for IterMut<'a, T> { #[inline] fn next(&mut self) -> Option<&'a mut T> { if self.len == 0 { - None - } else { - self.head.map(|node| unsafe { - // Need an unbound lifetime to get 'a - let node = &mut *node.as_ptr(); - self.len -= 1; - self.head = node.next; - &mut node.element - }) + return None; } + // SAFETY: When `len > 0`, `head` and `tail` are guaranteed to be `Some`. + // The lifetime of the returned reference is bound to the lifetime of the iterator, + // which is valid because the iterator holds a reference to the list. + Some(unsafe { + // Need an unbound lifetime to get 'a + let node = &mut *self.head.unwrap_unchecked().as_ptr(); + self.len -= 1; + self.head = node.next; + &mut node.element + }) } #[inline] @@ -1296,16 +1302,18 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut T> { if self.len == 0 { - None - } else { - self.tail.map(|node| unsafe { - // Need an unbound lifetime to get 'a - let node = &mut *node.as_ptr(); - self.len -= 1; - self.tail = node.prev; - &mut node.element - }) + return None; } + // SAFETY: When `len > 0`, `head` and `tail` are guaranteed to be `Some`. + // The lifetime of the returned reference is bound to the lifetime of the iterator, + // which is valid because the iterator holds a reference to the list. + Some(unsafe { + // Need an unbound lifetime to get 'a + let node = &mut *self.tail.unwrap_unchecked().as_ptr(); + self.len -= 1; + self.tail = node.prev; + &mut node.element + }) } } From acb3ed67c1226c641d80dfaf897de96c8788c892 Mon Sep 17 00:00:00 2001 From: fereidani Date: Mon, 10 Aug 2026 08:34:23 +0330 Subject: [PATCH 02/34] Implement TrustedLen for LinkedList iterators --- library/alloc/src/collections/linked_list.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 379569f0ffeea..45e3ce09f454a 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -14,7 +14,7 @@ use core::cmp::Ordering; use core::hash::{Hash, Hasher}; -use core::iter::FusedIterator; +use core::iter::{FusedIterator, TrustedLen}; use core::marker::PhantomData; use core::ptr::NonNull; use core::{fmt, mem}; @@ -1251,6 +1251,9 @@ impl ExactSizeIterator for Iter<'_, T> {} #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Iter<'_, T> {} +#[unstable(feature = "trusted_len", issue = "37572")] +unsafe impl TrustedLen for Iter<'_, T> {} + #[stable(feature = "default_iters", since = "1.70.0")] impl Default for Iter<'_, T> { /// Creates an empty `linked_list::Iter`. @@ -1323,6 +1326,9 @@ impl ExactSizeIterator for IterMut<'_, T> {} #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IterMut<'_, T> {} +#[unstable(feature = "trusted_len", issue = "37572")] +unsafe impl TrustedLen for IterMut<'_, T> {} + #[stable(feature = "default_iters", since = "1.70.0")] impl Default for IterMut<'_, T> { fn default() -> Self { @@ -2039,6 +2045,9 @@ impl ExactSizeIterator for IntoIter {} #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter {} +#[unstable(feature = "trusted_len", issue = "37572")] +unsafe impl TrustedLen for IntoIter {} + #[stable(feature = "default_iters", since = "1.70.0")] impl Default for IntoIter { /// Creates an empty `linked_list::IntoIter`. From 3f0756325ef648839356baef9f040b5ec6e6331b Mon Sep 17 00:00:00 2001 From: fereidani Date: Mon, 10 Aug 2026 08:35:29 +0330 Subject: [PATCH 03/34] Improve linked list benchmarks to use black_box and better logic for benchmarking --- library/alloctests/benches/linked_list.rs | 31 +++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/library/alloctests/benches/linked_list.rs b/library/alloctests/benches/linked_list.rs index b9322b6d4c3ea..2c1a42bdf7122 100644 --- a/library/alloctests/benches/linked_list.rs +++ b/library/alloctests/benches/linked_list.rs @@ -1,6 +1,6 @@ use std::collections::LinkedList; -use test::Bencher; +use test::{Bencher, black_box}; #[bench] fn bench_collect_into(b: &mut Bencher) { @@ -44,35 +44,40 @@ fn bench_push_front_pop_front(b: &mut Bencher) { }) } +#[bench] +fn bench_iter_count(b: &mut Bencher) { + let m: LinkedList<_> = (0..128).collect(); + b.iter(|| { + assert!(black_box(&m).iter().count() == 128); + }) +} + #[bench] fn bench_iter(b: &mut Bencher) { - let v = &[0; 128]; - let m: LinkedList<_> = v.iter().cloned().collect(); + let m: LinkedList = (0..128).collect(); b.iter(|| { - assert!(m.iter().count() == 128); + assert!((0..128).sum::() == black_box(&m).iter().sum()); }) } + #[bench] fn bench_iter_mut(b: &mut Bencher) { - let v = &[0; 128]; - let mut m: LinkedList<_> = v.iter().cloned().collect(); + let mut m: LinkedList = (0..128).collect(); b.iter(|| { - assert!(m.iter_mut().count() == 128); + black_box(&mut m).iter_mut().for_each(|x| *x += 1); }) } #[bench] fn bench_iter_rev(b: &mut Bencher) { - let v = &[0; 128]; - let m: LinkedList<_> = v.iter().cloned().collect(); + let m: LinkedList = (0..128).collect(); b.iter(|| { - assert!(m.iter().rev().count() == 128); + assert!((0..128).sum::() == black_box(&m).iter().rev().sum()); }) } #[bench] fn bench_iter_mut_rev(b: &mut Bencher) { - let v = &[0; 128]; - let mut m: LinkedList<_> = v.iter().cloned().collect(); + let mut m: LinkedList = (0..128).collect(); b.iter(|| { - assert!(m.iter_mut().rev().count() == 128); + black_box(&mut m).iter_mut().rev().for_each(|x| *x += 1); }) } From c215bedc4223e5b056a2a232f3c4be3077146c37 Mon Sep 17 00:00:00 2001 From: yilin <21307130191@m.fudan.edu.cn> Date: Tue, 18 Aug 2026 09:56:23 +0800 Subject: [PATCH 04/34] doc: document safety requirements for core WTF-8 --- library/core/src/wtf8.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/library/core/src/wtf8.rs b/library/core/src/wtf8.rs index 56679ea3aa9d9..16554f108c0fa 100644 --- a/library/core/src/wtf8.rs +++ b/library/core/src/wtf8.rs @@ -49,7 +49,9 @@ impl fmt::Debug for CodePoint { impl CodePoint { /// Unsafely creates a new `CodePoint` without checking the value. /// - /// Only use when `value` is known to be less than or equal to 0x10FFFF. + /// # Safety + /// + /// `value` must be less than or equal to 0x10FFFF. #[inline] pub unsafe fn from_u32_unchecked(value: u32) -> CodePoint { // SAFETY: Guaranteed by caller. @@ -210,8 +212,9 @@ impl Wtf8 { /// Creates a WTF-8 slice from a WTF-8 byte slice. /// - /// Since the byte slice is not checked for valid WTF-8, this functions is - /// marked unsafe. + /// # Safety + /// + /// `value` must contain well-formed WTF-8. #[inline] pub unsafe fn from_bytes_unchecked(value: &[u8]) -> &Wtf8 { // SAFETY: start with &[u8], end with fancy &[u8] @@ -220,8 +223,9 @@ impl Wtf8 { /// Creates a mutable WTF-8 slice from a mutable WTF-8 byte slice. /// - /// Since the byte slice is not checked for valid WTF-8, this functions is - /// marked unsafe. + /// # Safety + /// + /// `value` must contain well-formed WTF-8. #[inline] pub unsafe fn from_mut_bytes_unchecked(value: &mut [u8]) -> &mut Wtf8 { // SAFETY: start with &mut [u8], end with fancy &mut [u8] From 558dbb6a540d86124caead3f325f2f34e97b9f43 Mon Sep 17 00:00:00 2001 From: LorrensP-2158466 Date: Fri, 24 Jul 2026 17:05:01 +0200 Subject: [PATCH 05/34] - implement `GenericArgs::terms` and use where needed. - be explicit when only needing types of `GenericArgs` --- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- .../rustc_codegen_llvm/src/debuginfo/metadata.rs | 1 + compiler/rustc_codegen_llvm/src/debuginfo/mod.rs | 3 ++- compiler/rustc_middle/src/ty/generic_args.rs | 5 +++++ compiler/rustc_middle/src/ty/print/pretty.rs | 4 +--- .../src/function_item_references.rs | 4 +--- .../src/error_reporting/infer/need_type_info.rs | 2 +- .../src/error_reporting/traits/ambiguity.rs | 12 ++++-------- .../src/traits/auto_trait.rs | 4 ++-- .../src/traits/select/mod.rs | 2 ++ src/tools/clippy/clippy_lints/src/manual_bits.rs | 2 +- src/tools/clippy/clippy_lints/src/methods/lib.rs | 2 +- .../src/methods/manual_str_repeat.rs | 2 +- .../src/methods/map_collect_result_unit.rs | 2 +- .../clippy/clippy_lints/src/methods/ok_expect.rs | 4 +++- .../clippy_lints/src/size_of_in_element_count.rs | 8 ++++++-- .../src/transmute/transmute_undefined_repr.rs | 16 ++++++++++------ .../clippy_lints/src/useless_conversion.rs | 4 ++-- tests/ui/lint/function-item-references.rs | 4 ++-- tests/ui/lint/function-item-references.stderr | 4 ++-- 20 files changed, 49 insertions(+), 38 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 14b1c9b31ef9f..c858eb200d791 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1850,7 +1850,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { assert_eq!(tcx.trait_impl_of_assoc(def_id), None); self.prove_clauses( - args.types().map(|ty| ty::ClauseKind::WellFormed(ty.into())), + args.terms().map(|t| ty::ClauseKind::WellFormed(t.into())), locations, ConstraintCategory::Boring, ); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 33f6eca6be9cc..54bdfb5f442d9 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1432,6 +1432,7 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>( ty: Ty<'tcx>, ) -> SmallVec> { if let ty::Adt(def, args) = *ty.kind() { + // FIXME: also do consts? if args.types().next().is_some() { let generics = cx.tcx.generics_of(def.did()); let names = get_parameter_names(cx, generics); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index d6d9946450899..4267d61ad4445 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -289,7 +289,7 @@ impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { generics: &ty::Generics, args: GenericArgsRef<'tcx>, ) -> &'ll DIArray { - if args.types().next().is_none() { + if args.terms().next().is_none() { return create_DIArray(DIB(cx), &[]); } @@ -298,6 +298,7 @@ impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { let names = get_parameter_names(cx, generics); iter::zip(args, names) .filter_map(|(kind, name)| { + // FIXME: debug info for consts (using `createTemplateValueParameter`?) kind.as_type().map(|ty| { let actual_type = cx.tcx.normalize_erasing_regions( cx.typing_env(), diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index a9ca6bfef5534..fceb737dc8365 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -518,6 +518,11 @@ impl<'tcx> GenericArgs<'tcx> { self.iter().filter_map(|k| k.as_const()) } + #[inline] + pub fn terms(&self) -> impl DoubleEndedIterator> { + self.iter().filter_map(|k| k.as_term()) + } + /// Returns generic arguments that are not lifetimes. #[inline] pub fn non_erasable_generics(&self) -> impl DoubleEndedIterator> { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 4ab474fd89fe6..f52d096d53e35 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2305,9 +2305,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> { // `Foo<...>`. if let Some(arg) = args.types().next() { if let ty::Adt(_, arg_args) = arg.kind() { - if arg_args.consts().next().is_none() - && arg_args.types().next().is_none() - { + if arg_args.terms().next().is_none() { // Single param type with no type or const parameters: // `Foo>`. true diff --git a/compiler/rustc_mir_transform/src/function_item_references.rs b/compiler/rustc_mir_transform/src/function_item_references.rs index 41d16c00ff64b..a7b27f824e9e2 100644 --- a/compiler/rustc_mir_transform/src/function_item_references.rs +++ b/compiler/rustc_mir_transform/src/function_item_references.rs @@ -164,9 +164,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> { other_abi => format!("extern {other_abi} "), }; let ident = self.tcx.item_ident(fn_id); - let ty_params = fn_args.types().map(|ty| format!("{ty}")); - let const_params = fn_args.consts().map(|c| format!("{c}")); - let params = ty_params.chain(const_params).join(", "); + let params = fn_args.terms().map(|term| format!("{term}")).join(", "); let num_args = fn_sig.inputs().map_bound(|inputs| inputs.len()).skip_binder(); let variadic = if fn_sig.c_variadic() { ", ..." } else { "" }; let ret = if fn_sig.output().skip_binder().is_unit() { "" } else { " -> _" }; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs index 1a66ddb8e2238..903c3998fd4b6 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs @@ -678,7 +678,7 @@ impl<'tcx> InferSourceKind<'tcx> { || matches!( ty.kind(), ty::Adt(_, args) - if args.types().count() == 0 && args.consts().count() == 0 + if args.terms().next().is_none() ) { // `ty` is either `_`, a primitive type like `u32` or a type with no type or diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs index 06d882a309489..c450d02d58cd6 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs @@ -182,17 +182,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { /// share an inference variable into a single diagnostic. pub(super) fn ambiguity_term(&self, predicate: ty::Predicate<'tcx>) -> Option> { match predicate.kind().skip_binder() { - ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => data - .trait_ref - .args - .iter() - .filter_map(ty::GenericArg::as_term) - .find(|term| term.has_non_region_infer()), + ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => { + data.trait_ref.args.terms().find(|term| term.has_non_region_infer()) + } ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => data .projection_term .args - .iter() - .filter_map(ty::GenericArg::as_term) + .terms() .chain([data.term]) .find(|term| term.has_non_region_infer()), ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => Some(term), diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index c885406f6dcfb..8cfc86880a5e3 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -454,7 +454,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { let new_args = new_trait.trait_ref.args; let old_args = old_trait.trait_ref.args; - if !new_args.types().eq(old_args.types()) { + if !new_args.terms().eq(old_args.terms()) { // We can't compare lifetimes if the types are different, // so skip checking `old_clause`. return true; @@ -624,7 +624,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { } fn is_param_no_infer(&self, args: GenericArgsRef<'tcx>) -> bool { - self.is_of_param(args.type_at(0)) && !args.types().any(|t| t.has_infer_types()) + self.is_of_param(args.type_at(0)) && !args.terms().any(|t| t.has_infer_types()) } pub fn is_of_param(&self, ty: Ty<'tcx>) -> bool { diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 9b4ee13bf1b63..4eae79cd41c16 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1216,6 +1216,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // This suffices to allow chains like `FnMut` implemented in // terms of `Fn` etc, but we could probably make this more // precise still. + // + // FIXME(min_generic_const_args): Consider consts as well? let unbound_input_types = stack.fresh_trait_pred.skip_binder().trait_ref.args.types().any(|ty| ty.is_fresh()); diff --git a/src/tools/clippy/clippy_lints/src/manual_bits.rs b/src/tools/clippy/clippy_lints/src/manual_bits.rs index da0d9be1cb7fa..18b21ab264a46 100644 --- a/src/tools/clippy/clippy_lints/src/manual_bits.rs +++ b/src/tools/clippy/clippy_lints/src/manual_bits.rs @@ -102,7 +102,7 @@ fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option< cx.typeck_results() .node_args(count_func.hir_id) .types() - .next() + .nth(0) // the `T` in `size_of::` .map(|resolved_ty| (real_ty_span, resolved_ty)) } else { None diff --git a/src/tools/clippy/clippy_lints/src/methods/lib.rs b/src/tools/clippy/clippy_lints/src/methods/lib.rs index 84038283bcf8f..ceab607d8d96b 100644 --- a/src/tools/clippy/clippy_lints/src/methods/lib.rs +++ b/src/tools/clippy/clippy_lints/src/methods/lib.rs @@ -22,7 +22,7 @@ impl SelfKind { } else if let ty::Adt(adt_def, args) = ty.kind() && matches!(cx.tcx.get_diagnostic_name(adt_def.did()), Some(sym::Rc | sym::Arc)) { - args.types().next() == Some(parent_ty) + args.iter().filter_map(ty::GenericArg::as_type).nth(0) == Some(parent_ty) } else { false } diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs b/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs index 80ee741fab35e..0267d8fafe570 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs @@ -20,7 +20,7 @@ enum RepeatKind { fn get_ty_param(ty: Ty<'_>) -> Option> { if let ty::Adt(_, subs) = ty.kind() { - subs.types().next() + subs.iter().filter_map(ty::GenericArg::as_type).nth(0) } else { None } diff --git a/src/tools/clippy/clippy_lints/src/methods/map_collect_result_unit.rs b/src/tools/clippy/clippy_lints/src/methods/map_collect_result_unit.rs index 6f556fe592af8..404e061c3049e 100644 --- a/src/tools/clippy/clippy_lints/src/methods/map_collect_result_unit.rs +++ b/src/tools/clippy/clippy_lints/src/methods/map_collect_result_unit.rs @@ -14,7 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, iter: &hir::Expr let collect_ret_ty = cx.typeck_results().expr_ty(expr); if collect_ret_ty.is_diag_item(cx, sym::Result) && let ty::Adt(_, args) = collect_ret_ty.kind() - && let Some(result_t) = args.types().next() + && let Some(result_t) = args.iter().filter_map(ty::GenericArg::as_type).nth(0) && result_t.is_unit() // get parts for snippet { diff --git a/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs b/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs index 4982506036ef6..aa323b7891ff2 100644 --- a/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs @@ -37,7 +37,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr /// Given a `Result` type, return its error type (`E`). fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { match ty.kind() { - ty::Adt(adt, args) if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) => args.types().nth(1), + ty::Adt(adt, args) if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) => { + args.iter().filter_map(ty::GenericArg::as_type).nth(1) + }, _ => None, } } diff --git a/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs b/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs index 3623039aece15..c135283a702d0 100644 --- a/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs +++ b/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs @@ -43,7 +43,11 @@ fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, inverted: Some(sym::mem_size_of | sym::mem_size_of_val) ) { - cx.typeck_results().node_args(count_func.hir_id).types().next() + cx.typeck_results() + .node_args(count_func.hir_id) + .iter() + .filter_map(ty::GenericArg::as_type) + .nth(0) } else { None } @@ -92,7 +96,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( )) // Get the pointee type - && let Some(pointee_ty) = cx.typeck_results().node_args(func.hir_id).types().next() + && let Some(pointee_ty) = cx.typeck_results().node_args(func.hir_id).iter().filter_map(ty::GenericArg::as_type).nth(0) { return Some((pointee_ty, count)); } diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs index 05f4071406477..e7957fe10257b 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -323,12 +323,16 @@ fn is_size_pair(ty: Ty<'_>) -> bool { } fn same_except_params<'tcx>(subs1: GenericArgsRef<'tcx>, subs2: GenericArgsRef<'tcx>) -> bool { - // TODO: check const parameters as well. Currently this will consider `Array<5>` the same as - // `Array<6>` - for (ty1, ty2) in subs1.types().zip(subs2.types()).filter(|(ty1, ty2)| ty1 != ty2) { - match (ty1.kind(), ty2.kind()) { - (ty::Param(_), _) | (_, ty::Param(_)) => (), - (ty::Adt(adt1, subs1), ty::Adt(adt2, subs2)) if adt1 == adt2 && same_except_params(subs1, subs2) => (), + for (t1, t2) in subs1.terms().zip(subs2.terms()).filter(|(t1, t2)| t1 != t2) { + match (t1.kind(), t2.kind()) { + (ty::TermKind::Ty(ty1), ty::TermKind::Ty(ty2)) => match (ty1.kind(), ty2.kind()) { + (ty::Param(_), _) | (_, ty::Param(_)) => (), + (ty::Adt(adt1, subs1), ty::Adt(adt2, subs2)) if adt1 == adt2 && same_except_params(subs1, subs2) => (), + _ => return false, + }, + // FIXME: check const parameters better as well. Currently this will consider `Array<5>` the same as + // `Array<6>` + (ty::TermKind::Const(c1), ty::TermKind::Const(c2)) if c1 == c2 => todo!(), _ => return false, } } diff --git a/src/tools/clippy/clippy_lints/src/useless_conversion.rs b/src/tools/clippy/clippy_lints/src/useless_conversion.rs index ed9bf1e86e691..8071b0e50f9b0 100644 --- a/src/tools/clippy/clippy_lints/src/useless_conversion.rs +++ b/src/tools/clippy/clippy_lints/src/useless_conversion.rs @@ -400,7 +400,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { && let b = cx.typeck_results().expr_ty(recv) && a.is_diag_item(cx, sym::Result) && let ty::Adt(_, args) = a.kind() - && let Some(a_type) = args.types().next() + && let Some(a_type) = args.iter().filter_map(GenericArg::as_type).nth(0) && same_type_modulo_regions(a_type, b) { span_lint_and_help( @@ -425,7 +425,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { if name == sym::try_from_fn && a.is_diag_item(cx, sym::Result) && let ty::Adt(_, args) = a.kind() - && let Some(a_type) = args.types().next() + && let Some(a_type) = args.iter().filter_map(GenericArg::as_type).nth(0) && same_type_modulo_regions(a_type, b) { let hint = format!("consider removing `{}()`", snippet(cx, path.span, "TryFrom::try_from")); diff --git a/tests/ui/lint/function-item-references.rs b/tests/ui/lint/function-item-references.rs index 5afd8341473f3..739e5fab8a35e 100644 --- a/tests/ui/lint/function-item-references.rs +++ b/tests/ui/lint/function-item-references.rs @@ -16,7 +16,7 @@ unsafe extern "C" fn variadic(_x: u32, _args: ...) { } fn take_generic_ref<'a, T>(_x: &'a T) { } fn take_generic_array(_x: [T; N]) { } fn multiple_generic(_x: T, _y: U) { } -fn multiple_generic_arrays(_x: [T; N], _y: [U; M]) { } +fn multiple_generic_arrays(_x: [T; N], _y: [U; M]) { } //function references passed to these functions should never lint fn call_fn(f: &dyn Fn(u32) -> u32, x: u32) { f(x); } @@ -120,7 +120,7 @@ fn main() { //~^ WARNING taking a reference to a function item does not give a function pointer println!("{:p}", &multiple_generic::); //~^ WARNING taking a reference to a function item does not give a function pointer - println!("{:p}", &multiple_generic_arrays::); + println!("{:p}", &multiple_generic_arrays::); //~^ WARNING taking a reference to a function item does not give a function pointer println!("{:p}", &std::env::var::); //~^ WARNING taking a reference to a function item does not give a function pointer diff --git a/tests/ui/lint/function-item-references.stderr b/tests/ui/lint/function-item-references.stderr index 837a4b2087fdf..f2c7a03fc8f70 100644 --- a/tests/ui/lint/function-item-references.stderr +++ b/tests/ui/lint/function-item-references.stderr @@ -127,8 +127,8 @@ LL | println!("{:p}", &multiple_generic::); warning: taking a reference to a function item does not give a function pointer --> $DIR/function-item-references.rs:123:22 | -LL | println!("{:p}", &multiple_generic_arrays::); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: cast `multiple_generic_arrays` to obtain a function pointer: `multiple_generic_arrays:: as fn(_, _)` +LL | println!("{:p}", &multiple_generic_arrays::); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: cast `multiple_generic_arrays` to obtain a function pointer: `multiple_generic_arrays:: as fn(_, _)` warning: taking a reference to a function item does not give a function pointer --> $DIR/function-item-references.rs:125:22 From 715bd312a897aa1d2dbf76641109521d48196cd2 Mon Sep 17 00:00:00 2001 From: LorrensP-2158466 Date: Sat, 8 Aug 2026 10:53:43 +0200 Subject: [PATCH 06/34] use `next().and_then(as_type)` instead of `filter_map(as_type).nth(0)` --- src/tools/clippy/clippy_lints/src/manual_bits.rs | 5 +++-- src/tools/clippy/clippy_lints/src/methods/lib.rs | 2 +- .../clippy/clippy_lints/src/methods/manual_str_repeat.rs | 2 +- .../clippy_lints/src/methods/map_collect_result_unit.rs | 2 +- src/tools/clippy/clippy_lints/src/methods/ok_expect.rs | 4 +--- .../clippy/clippy_lints/src/size_of_in_element_count.rs | 6 +++--- .../clippy_lints/src/transmute/transmute_undefined_repr.rs | 2 +- src/tools/clippy/clippy_lints/src/useless_conversion.rs | 4 ++-- 8 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/manual_bits.rs b/src/tools/clippy/clippy_lints/src/manual_bits.rs index 18b21ab264a46..92313eab318d2 100644 --- a/src/tools/clippy/clippy_lints/src/manual_bits.rs +++ b/src/tools/clippy/clippy_lints/src/manual_bits.rs @@ -101,8 +101,9 @@ fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option< { cx.typeck_results() .node_args(count_func.hir_id) - .types() - .nth(0) // the `T` in `size_of::` + .iter() + .next() // the `T` in `size_of::` + .and_then(ty::GenericArg::as_type) .map(|resolved_ty| (real_ty_span, resolved_ty)) } else { None diff --git a/src/tools/clippy/clippy_lints/src/methods/lib.rs b/src/tools/clippy/clippy_lints/src/methods/lib.rs index ceab607d8d96b..9246ed331ee94 100644 --- a/src/tools/clippy/clippy_lints/src/methods/lib.rs +++ b/src/tools/clippy/clippy_lints/src/methods/lib.rs @@ -22,7 +22,7 @@ impl SelfKind { } else if let ty::Adt(adt_def, args) = ty.kind() && matches!(cx.tcx.get_diagnostic_name(adt_def.did()), Some(sym::Rc | sym::Arc)) { - args.iter().filter_map(ty::GenericArg::as_type).nth(0) == Some(parent_ty) + args.iter().next().and_then(ty::GenericArg::as_type) == Some(parent_ty) } else { false } diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs b/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs index 0267d8fafe570..80ee741fab35e 100644 --- a/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs +++ b/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs @@ -20,7 +20,7 @@ enum RepeatKind { fn get_ty_param(ty: Ty<'_>) -> Option> { if let ty::Adt(_, subs) = ty.kind() { - subs.iter().filter_map(ty::GenericArg::as_type).nth(0) + subs.types().next() } else { None } diff --git a/src/tools/clippy/clippy_lints/src/methods/map_collect_result_unit.rs b/src/tools/clippy/clippy_lints/src/methods/map_collect_result_unit.rs index 404e061c3049e..155f31d6528cf 100644 --- a/src/tools/clippy/clippy_lints/src/methods/map_collect_result_unit.rs +++ b/src/tools/clippy/clippy_lints/src/methods/map_collect_result_unit.rs @@ -14,7 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, iter: &hir::Expr let collect_ret_ty = cx.typeck_results().expr_ty(expr); if collect_ret_ty.is_diag_item(cx, sym::Result) && let ty::Adt(_, args) = collect_ret_ty.kind() - && let Some(result_t) = args.iter().filter_map(ty::GenericArg::as_type).nth(0) + && let Some(result_t) = args.iter().next().and_then(ty::GenericArg::as_type) && result_t.is_unit() // get parts for snippet { diff --git a/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs b/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs index aa323b7891ff2..182757f347d8c 100644 --- a/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs @@ -37,9 +37,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr /// Given a `Result` type, return its error type (`E`). fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option> { match ty.kind() { - ty::Adt(adt, args) if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) => { - args.iter().filter_map(ty::GenericArg::as_type).nth(1) - }, + ty::Adt(adt, args) if cx.tcx.is_diagnostic_item(sym::Result, adt.did()) => args.iter().nth(1)?.as_type(), _ => None, } } diff --git a/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs b/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs index c135283a702d0..98e84f38bbaea 100644 --- a/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs +++ b/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs @@ -46,8 +46,8 @@ fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, inverted: cx.typeck_results() .node_args(count_func.hir_id) .iter() - .filter_map(ty::GenericArg::as_type) - .nth(0) + .next() + .and_then(ty::GenericArg::as_type) } else { None } @@ -96,7 +96,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( )) // Get the pointee type - && let Some(pointee_ty) = cx.typeck_results().node_args(func.hir_id).iter().filter_map(ty::GenericArg::as_type).nth(0) + && let Some(pointee_ty) = cx.typeck_results().node_args(func.hir_id).types().next() { return Some((pointee_ty, count)); } diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs index e7957fe10257b..83eca20266684 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -332,7 +332,7 @@ fn same_except_params<'tcx>(subs1: GenericArgsRef<'tcx>, subs2: GenericArgsRef<' }, // FIXME: check const parameters better as well. Currently this will consider `Array<5>` the same as // `Array<6>` - (ty::TermKind::Const(c1), ty::TermKind::Const(c2)) if c1 == c2 => todo!(), + (ty::TermKind::Const(_), ty::TermKind::Const(_)) => {}, _ => return false, } } diff --git a/src/tools/clippy/clippy_lints/src/useless_conversion.rs b/src/tools/clippy/clippy_lints/src/useless_conversion.rs index 8071b0e50f9b0..2df9269524ab2 100644 --- a/src/tools/clippy/clippy_lints/src/useless_conversion.rs +++ b/src/tools/clippy/clippy_lints/src/useless_conversion.rs @@ -400,7 +400,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { && let b = cx.typeck_results().expr_ty(recv) && a.is_diag_item(cx, sym::Result) && let ty::Adt(_, args) = a.kind() - && let Some(a_type) = args.iter().filter_map(GenericArg::as_type).nth(0) + && let Some(a_type) = args.iter().next().and_then(GenericArg::as_type) && same_type_modulo_regions(a_type, b) { span_lint_and_help( @@ -425,7 +425,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { if name == sym::try_from_fn && a.is_diag_item(cx, sym::Result) && let ty::Adt(_, args) = a.kind() - && let Some(a_type) = args.iter().filter_map(GenericArg::as_type).nth(0) + && let Some(a_type) = args.iter().next().and_then(GenericArg::as_type) && same_type_modulo_regions(a_type, b) { let hint = format!("consider removing `{}()`", snippet(cx, path.span, "TryFrom::try_from")); From 7b7dffb30148e601695800d355472a60b0a9a885 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 18 Aug 2026 19:29:29 +0000 Subject: [PATCH 07/34] Only suggest RUST_MIN_STACK if stack overflow --- compiler/rustc_driver_impl/src/signal_handler.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_driver_impl/src/signal_handler.rs b/compiler/rustc_driver_impl/src/signal_handler.rs index 3d5df19bf67ee..f1dbb45539c91 100644 --- a/compiler/rustc_driver_impl/src/signal_handler.rs +++ b/compiler/rustc_driver_impl/src/signal_handler.rs @@ -115,7 +115,8 @@ unsafe extern "C" fn print_stack_trace(signum: libc::c_int) { written += rem.len() + 1; let random_depth = || 8 * 16; // chosen by random diceroll (2d20) - if (cyclic || stack.len() > random_depth()) && signum == libc::SIGSEGV { + let maybe_stack_overflow = (cyclic || stack.len() > random_depth()) && signum == libc::SIGSEGV; + if maybe_stack_overflow { // technically speculation, but assert it with confidence anyway. // rustc only arrived in this signal handler because bad things happened // and this message is for explaining it's not the programmer's fault @@ -128,7 +129,7 @@ unsafe extern "C" fn print_stack_trace(signum: libc::c_int) { } raw_errln!("note: we would appreciate a report at https://github.com/rust-lang/rust"); written += 1; - if signum == libc::SIGSEGV { + if maybe_stack_overflow { // get the current stack size WITHOUT blocking and double it let new_size = STACK_SIZE.get().copied().unwrap_or(DEFAULT_STACK_SIZE) * 2; raw_errln!( From 494a1a6ae1672d4acf14779f87e7d52d9ec276cb Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sun, 16 Aug 2026 16:12:27 +0800 Subject: [PATCH 08/34] proc_macro: add support for 16-bit targets Add arena and fxhash entries for targets that have 16-bit pointers. Signed-off-by: Sean Cross --- library/proc_macro/src/bridge/arena.rs | 19 +++++++++++-------- library/proc_macro/src/bridge/fxhash.rs | 17 ++++++----------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/library/proc_macro/src/bridge/arena.rs b/library/proc_macro/src/bridge/arena.rs index d4879021f9d87..13fabf7e14f13 100644 --- a/library/proc_macro/src/bridge/arena.rs +++ b/library/proc_macro/src/bridge/arena.rs @@ -9,14 +9,6 @@ use std::mem::MaybeUninit; use std::ops::Range; use std::{cmp, ptr, slice}; -// The arenas start with PAGE-sized chunks, and then each new chunk is twice as -// big as its predecessor, up until we reach HUGE_PAGE-sized chunks, whereupon -// we stop growing. This scales well, from arenas that are barely used up to -// arenas that are used for 100s of MiBs. Note also that the chosen sizes match -// the usual sizes of pages and huge pages on Linux. -const PAGE: usize = 4096; -const HUGE_PAGE: usize = 2 * 1024 * 1024; - /// A minimal arena allocator inspired by `rustc_arena::DroplessArena`. /// /// This is unfortunately a complete re-implementation rather than a dependency @@ -44,6 +36,17 @@ impl Arena { #[inline(never)] #[cold] fn grow(&self, additional: usize) { + // The arenas start with PAGE-sized chunks, and then each new chunk is twice as + // big as its predecessor, up until we reach HUGE_PAGE-sized chunks, whereupon + // we stop growing. This scales well, from arenas that are barely used up to + // arenas that are used for 100s of MiBs. Note also that the chosen sizes match + // the usual sizes of pages and huge pages on Linux. + const PAGE: usize = 4096; + const HUGE_PAGE: usize = cfg_select! { + any(target_pointer_width = "64", target_pointer_width = "32") => 2 * 1024 * 1024, + _ => 8192, // just make it compile for -Zbuild-std + }; + let mut chunks = self.chunks.borrow_mut(); let mut new_cap; if let Some(last_chunk) = chunks.last_mut() { diff --git a/library/proc_macro/src/bridge/fxhash.rs b/library/proc_macro/src/bridge/fxhash.rs index 5f6b3d1b929e4..97e5f220ff4a5 100644 --- a/library/proc_macro/src/bridge/fxhash.rs +++ b/library/proc_macro/src/bridge/fxhash.rs @@ -27,14 +27,14 @@ pub(super) struct FxHasher { hash: usize, } -#[cfg(target_pointer_width = "32")] -const K: usize = 0x9e3779b9; -#[cfg(target_pointer_width = "64")] -const K: usize = 0x517cc1b727220a95; - impl FxHasher { #[inline] fn add_to_hash(&mut self, i: usize) { + const K: usize = cfg_select! { + target_pointer_width = "64" => 0x517cc1b727220a95, + target_pointer_width = "32" => 0x9e3779b9, + _ => 0, // just make it compile for -Zbuild-std + }; self.hash = self.hash.rotate_left(5).bitxor(i).wrapping_mul(K); } } @@ -42,15 +42,10 @@ impl FxHasher { impl Hasher for FxHasher { #[inline] fn write(&mut self, mut bytes: &[u8]) { - #[cfg(target_pointer_width = "32")] - let read_usize = |bytes: &[u8]| u32::from_ne_bytes(bytes[..4].try_into().unwrap()); - #[cfg(target_pointer_width = "64")] - let read_usize = |bytes: &[u8]| u64::from_ne_bytes(bytes[..8].try_into().unwrap()); - let mut hash = FxHasher { hash: self.hash }; assert!(size_of::() <= 8); while bytes.len() >= size_of::() { - hash.add_to_hash(read_usize(bytes) as usize); + hash.add_to_hash(usize::from_ne_bytes(bytes[..size_of::()].try_into().unwrap())); bytes = &bytes[size_of::()..]; } if (size_of::() > 4) && (bytes.len() >= 4) { From 4c28ae248ac0d9321e09add0dc3bebf2c8a2c692 Mon Sep 17 00:00:00 2001 From: Tim Neumann Date: Tue, 18 Aug 2026 19:51:01 +0200 Subject: [PATCH 09/34] LLVM 24: configure float-abi via module flag --- compiler/rustc_codegen_llvm/src/context.rs | 11 +++++++++ .../rustc_llvm/llvm-wrapper/PassWrapper.cpp | 8 ++++++- tests/codegen-llvm/float/abi-flag.rs | 23 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/codegen-llvm/float/abi-flag.rs diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 668072ff082ec..9a95372fb8b6a 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -563,6 +563,17 @@ pub(crate) unsafe fn create_module<'ll>( ); } + if llvm_version >= (24, 0, 0) + && let Some(floatabi) = sess.target.llvm_floatabi + { + llvm::add_module_flag_str( + llmod, + llvm::ModuleFlagMergeBehavior::Error, + "float-abi", + floatabi.desc(), + ); + } + // Add module flags specified via -Z llvm_module_flag for (key, value, merge_behavior) in &sess.opts.unstable_opts.llvm_module_flag { let merge_behavior = match merge_behavior.as_str() { diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 3ad59c53a5bf3..81a506c63a8ee 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -365,7 +365,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Trip); +#if LLVM_VERSION_LT(24, 0) Options.FloatABIType = FloatABIType; +#endif Options.DataSections = DataSections; Options.FunctionSections = FunctionSections; Options.UniqueSectionNames = UniqueSectionNames; @@ -439,7 +441,11 @@ extern "C" void LLVMRustAddLibraryInfo(LLVMTargetMachineRef T, if (DisableSimplifyLibCalls) TLII.disableAllFunctions(); unwrap(PMR)->add(new TargetLibraryInfoWrapperPass(TLII)); -#if LLVM_VERSION_GE(22, 0) +#if LLVM_VERSION_GE(24, 0) + unwrap(PMR)->add(new RuntimeLibraryInfoWrapper( + Options->ExceptionModel, Options->EABIVersion, Options->MCOptions.ABIName, + Options->VecLib)); +#elif LLVM_VERSION_GE(22, 0) unwrap(PMR)->add(new RuntimeLibraryInfoWrapper( TargetTriple, Options->ExceptionModel, Options->FloatABIType, Options->EABIVersion, Options->MCOptions.ABIName, Options->VecLib)); diff --git a/tests/codegen-llvm/float/abi-flag.rs b/tests/codegen-llvm/float/abi-flag.rs new file mode 100644 index 0000000000000..8b99988e4ba81 --- /dev/null +++ b/tests/codegen-llvm/float/abi-flag.rs @@ -0,0 +1,23 @@ +//@ add-minicore +//@ min-llvm-version: 24 +//@ revisions: armhf armsf aarch64sf + +//@ [armhf] needs-llvm-components: arm +//@ [armhf] compile-flags: --target=armv7-unknown-linux-gnueabihf + +//@ [armsf] needs-llvm-components: arm +//@ [armsf] compile-flags: --target=armv7-unknown-linux-gnueabi + +//@ [aarch64sf] needs-llvm-components: aarch64 +//@ [aarch64sf] compile-flags: --target=aarch64-unknown-none-softfloat + +#![crate_type = "lib"] +#![feature(no_core)] +#![no_core] + +// rustc sets the module flag only for targets with an explicit `llvm_floatabi`, +// which is (currently) only the case on ARM. + +// armhf: !{i32 1, !"float-abi", !"hard"} +// armsf: !{i32 1, !"float-abi", !"soft"} +// aarch64sf-NOT: !"float-abi" From d6e1d0e714abf431cfdd67f88a73350a08d55d9c Mon Sep 17 00:00:00 2001 From: KevinA-cpu Date: Thu, 20 Aug 2026 01:21:53 +0700 Subject: [PATCH 10/34] Add regression test for confusing lifetime error message issue --- .../confusing-lifetime-error-issue-79033.rs | 36 +++++++++++++ ...onfusing-lifetime-error-issue-79033.stderr | 51 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 tests/ui/impl-trait/confusing-lifetime-error-issue-79033.rs create mode 100644 tests/ui/impl-trait/confusing-lifetime-error-issue-79033.stderr diff --git a/tests/ui/impl-trait/confusing-lifetime-error-issue-79033.rs b/tests/ui/impl-trait/confusing-lifetime-error-issue-79033.rs new file mode 100644 index 0000000000000..323d42bdc979f --- /dev/null +++ b/tests/ui/impl-trait/confusing-lifetime-error-issue-79033.rs @@ -0,0 +1,36 @@ +// Regression test for https://github.com/rust-lang/rust/issues/79033/ +// rustc should be clear about the lifetime issue below where +// self is borrowed for the duration of the returned iterator +// but the lifetime of self will end when fn lines() returns. +//@ edition: 2024 + +#[derive(Debug, Clone, Copy)] +pub struct Location<'a> { + pub filename: &'a str, + pub start: LocationHalf, + pub end: LocationHalf, +} + +#[derive(Debug, Clone, Copy)] +pub struct LocationHalf { + pub line: u32, + pub column: u32, +} + +impl Location<'_> { + /// Returns an iterator over the line numbers and lines of this location. + pub fn lines<'a>(self, source: &'a str) -> impl Iterator { + let lines = source.split('\n'); + lines.enumerate().filter_map(|(i, line)| { + //~^ ERROR closure may outlive the current function, but it borrows `self.start.line`, which is owned by the current function + //~| ERROR closure may outlive the current function, but it borrows `self.end.line`, which is owned by the current function + if self.start.line as usize <= i && i <= self.end.line as usize { + Some((i as u32 + 1, line)) + } else { + None + } + }) + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/confusing-lifetime-error-issue-79033.stderr b/tests/ui/impl-trait/confusing-lifetime-error-issue-79033.stderr new file mode 100644 index 0000000000000..81cad8de969eb --- /dev/null +++ b/tests/ui/impl-trait/confusing-lifetime-error-issue-79033.stderr @@ -0,0 +1,51 @@ +error[E0373]: closure may outlive the current function, but it borrows `self.start.line`, which is owned by the current function + --> $DIR/confusing-lifetime-error-issue-79033.rs:24:38 + | +LL | lines.enumerate().filter_map(|(i, line)| { + | ^^^^^^^^^^^ may outlive borrowed value `self.start.line` +... +LL | if self.start.line as usize <= i && i <= self.end.line as usize { + | --------------- `self.start.line` is borrowed here + | +note: function requires argument type to outlive `'static` + --> $DIR/confusing-lifetime-error-issue-79033.rs:24:9 + | +LL | / lines.enumerate().filter_map(|(i, line)| { +LL | | +LL | | +LL | | if self.start.line as usize <= i && i <= self.end.line as usize { +... | +LL | | }) + | |__________^ +help: to force the closure to take ownership of `self.start.line` (and any other referenced variables), use the `move` keyword + | +LL | lines.enumerate().filter_map(move |(i, line)| { + | ++++ + +error[E0373]: closure may outlive the current function, but it borrows `self.end.line`, which is owned by the current function + --> $DIR/confusing-lifetime-error-issue-79033.rs:24:38 + | +LL | lines.enumerate().filter_map(|(i, line)| { + | ^^^^^^^^^^^ may outlive borrowed value `self.end.line` +... +LL | if self.start.line as usize <= i && i <= self.end.line as usize { + | ------------- `self.end.line` is borrowed here + | +note: function requires argument type to outlive `'static` + --> $DIR/confusing-lifetime-error-issue-79033.rs:24:9 + | +LL | / lines.enumerate().filter_map(|(i, line)| { +LL | | +LL | | +LL | | if self.start.line as usize <= i && i <= self.end.line as usize { +... | +LL | | }) + | |__________^ +help: to force the closure to take ownership of `self.end.line` (and any other referenced variables), use the `move` keyword + | +LL | lines.enumerate().filter_map(move |(i, line)| { + | ++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0373`. From 8ba038c9e056de993b1f523bcfdfc3dc1b38c822 Mon Sep 17 00:00:00 2001 From: zakrad <49591476+zakrad@users.noreply.github.com> Date: Thu, 20 Aug 2026 11:56:13 +0330 Subject: [PATCH 11/34] Add regression test for dead_code on type alias used in impl self type --- .../type-alias-used-in-impl-59333.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/ui/lint/dead-code/type-alias-used-in-impl-59333.rs diff --git a/tests/ui/lint/dead-code/type-alias-used-in-impl-59333.rs b/tests/ui/lint/dead-code/type-alias-used-in-impl-59333.rs new file mode 100644 index 0000000000000..5f2e4296b0eb7 --- /dev/null +++ b/tests/ui/lint/dead-code/type-alias-used-in-impl-59333.rs @@ -0,0 +1,34 @@ +//@ check-pass +//! Regression test for . +//! A type alias used only as (part of) the self type of an impl was +//! incorrectly flagged as dead code. + +#![deny(dead_code)] + +struct Runner; + +type RuntimeImpl = Runner; + +trait Runtime { + fn run(&mut self); +} + +impl Runtime for &mut RuntimeImpl { + fn run(&mut self) {} +} + +struct Walker; + +type WalkerImpl = Walker; + +trait Walk { + fn walk(&self) {} +} + +impl Walk for WalkerImpl {} + +fn main() { + let mut runner = Runner; + (&mut runner).run(); + Walker.walk(); +} From 0ff906ae755fd8a5a12215ecc105e2b97650e4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 20 Aug 2026 10:47:44 +0200 Subject: [PATCH 12/34] Configure LLM policy URL for triagebot --- triagebot.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/triagebot.toml b/triagebot.toml index a842b2a07c15f..4990c72ffce6c 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1581,6 +1581,7 @@ cc = ["@rust-lang/wg-const-eval"] [assign] warn_non_default_branch.enable = true contributing_url = "https://rustc-dev-guide.rust-lang.org/getting-started.html" +llm_policy_url = "https://forge.rust-lang.org/policies/llm-usage.html" [[assign.warn_non_default_branch.exceptions]] title = "[beta" From 9da8a55be97ef8158c80c97049a2d6dfb80ce0bf Mon Sep 17 00:00:00 2001 From: Tim Neumann Date: Thu, 20 Aug 2026 17:03:36 +0200 Subject: [PATCH 13/34] splat-fn-ptr-ptr-tuple.rs: add let to avoid UB --- tests/ui/splat/splat-fn-ptr-ptr-tuple.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/ui/splat/splat-fn-ptr-ptr-tuple.rs b/tests/ui/splat/splat-fn-ptr-ptr-tuple.rs index 6473abce4b750..6a108a1411a6b 100644 --- a/tests/ui/splat/splat-fn-ptr-ptr-tuple.rs +++ b/tests/ui/splat/splat-fn-ptr-ptr-tuple.rs @@ -66,25 +66,24 @@ fn main() { assert_eq!((*fn_pp)(1u32, 2i8), (2i8, 1u32)); // Now with *mut and non-terminal splat + let mut fn_p = splat_non_terminal_arg as fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32); let fn_pp: *mut fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32) - = ptr::from_mut( - &mut (splat_non_terminal_arg as fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32)) - ); + = ptr::from_mut(&mut fn_p); unsafe { assert_eq!((*fn_pp)(1, 2, 3.5), (2, 3.5, 1)); assert_eq!((*fn_pp)(1u32, 2i8, 3.5f64), (2i8, 3.5f64, 1u32)); } + let mut fn_p = splat_non_terminal_arg as _; let fn_pp: *mut fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32) - = ptr::from_mut(&mut (splat_non_terminal_arg as _)); + = ptr::from_mut(&mut fn_p); unsafe { assert_eq!((*fn_pp)(1, 2, 3.5), (2, 3.5, 1)); assert_eq!((*fn_pp)(1u32, 2i8, 3.5f64), (2i8, 3.5f64, 1u32)); } - let fn_pp = ptr::from_mut( - &mut (splat_non_terminal_arg as fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32)) - ); + let mut fn_p = splat_non_terminal_arg as fn(#[rustc_splat] (u32, i8), f64) -> (i8, f64, u32); + let fn_pp = ptr::from_mut(&mut fn_p); unsafe { assert_eq!((*fn_pp)(1, 2, 3.5), (2, 3.5, 1)); assert_eq!((*fn_pp)(1u32, 2i8, 3.5f64), (2i8, 3.5f64, 1u32)); From d15096be6e9a1702281699c28bbd328df5fcfcb6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 20 Aug 2026 18:10:01 +0200 Subject: [PATCH 14/34] Add back `tests/rustdoc-gui/notable-trait.goml` test --- tests/rustdoc-gui/notable-trait.goml | 256 +++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 tests/rustdoc-gui/notable-trait.goml diff --git a/tests/rustdoc-gui/notable-trait.goml b/tests/rustdoc-gui/notable-trait.goml new file mode 100644 index 0000000000000..d776021917e8c --- /dev/null +++ b/tests/rustdoc-gui/notable-trait.goml @@ -0,0 +1,256 @@ +// This test checks the position of the `i` for the notable traits. +include: "utils.goml" +go-to: "file://" + |DOC_PATH| + "/test_docs/struct.NotableStructWithLongName.html" +show-text: true + +define-function: ( + "check-notable-tooltip-position", + [x, i_x], + block { + // Checking they have the same y position. + compare-elements-position-near: ( + "//*[@id='method.create_an_iterator_from_read']//a[normalize-space()='NotableStructWithLongName']", + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", + {"y": 1}, + ) + // Checking they don't have the same x position. + compare-elements-position-false: ( + "//*[@id='method.create_an_iterator_from_read']//a[normalize-space()='NotableStructWithLongName']", + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", + ["x"], + ) + // The `i` should be *after* the type. + assert-position: ( + "//*[@id='method.create_an_iterator_from_read']//a[normalize-space()='NotableStructWithLongName']", + {"x": |x|}, + ) + assert-position: ( + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", + {"x": |i_x|}, + ) + }, +) + +define-function: ( + "check-notable-tooltip-position-complete", + [x, i_x, popover_x], + block { + call-function: ("check-notable-tooltip-position", {"x": |x|, "i_x": |i_x|}) + assert-count: ("//*[@class='tooltip popover']", 0) + click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" + assert-count: ("//*[@class='tooltip popover']", 1) + wait-for-position: ( + "//*[@class='tooltip popover']", + {"x": |popover_x|} + ) + compare-elements-position-near: ( + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", + "//*[@class='tooltip popover']", + {"y": 30} + ) + compare-elements-position-false: ( + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", + "//*[@class='tooltip popover']", + ["x"] + ) + click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" + move-cursor-to: "//h1" + assert-count: ("//*[@class='tooltip popover']", 0) + }, +) + +// We start with a wide screen. +set-window-size: (1100, 600) +call-function: ("check-notable-tooltip-position-complete", { + "x": 682, + "i_x": 960, + "popover_x": 468, +}) + +// Now only the `i` should be on the next line. +set-window-size: (1055, 600) +compare-elements-position-false: ( + "//*[@id='method.create_an_iterator_from_read']//a[normalize-space()='NotableStructWithLongName']", + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", + ["y", "x"], +) + +// Now both the `i` and the struct name should be on the next line. +set-window-size: (980, 600) +call-function: ("check-notable-tooltip-position", { + "x": 250, + "i_x": 528, +}) + +go-to: "file://" + |DOC_PATH| + "/test_docs/struct.NotableStructWithLongName.html" +// This is needed to ensure that the text color is computed. +show-text: true + +// Now check the colors. +define-function: ( + "check-colors", + [theme, header_color, content_color, type_color, trait_color, link_color], + block { + call-function: ("switch-theme", {"theme": |theme|}) + + assert-css: ( + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", + {"color": |content_color|}, + ALL, + ) + + move-cursor-to: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" + wait-for-count: (".tooltip.popover", 1) + + assert-css: ( + "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", + {"color": |link_color|}, + ALL, + ) + + assert-css: ( + ".tooltip.popover h3", + {"color": |header_color|}, + ALL, + ) + assert-css: ( + ".tooltip.popover pre", + {"color": |content_color|}, + ALL, + ) + assert-css: ( + ".tooltip.popover pre a.struct", + {"color": |type_color|}, + ALL, + ) + assert-css: ( + ".tooltip.popover pre a.trait", + {"color": |trait_color|}, + ALL, + ) + }, +) + +call-function: ( + "check-colors", + { + "theme": "ayu", + "link_color": "#39afd7", + "content_color": "#e6e1cf", + "header_color": "#fff", + "type_color": "#ffa0a5", + "trait_color": "#39afd7", + }, +) + +call-function: ( + "check-colors", + { + "theme": "dark", + "link_color": "#d2991d", + "content_color": "#ddd", + "header_color": "#ddd", + "type_color": "#2dbfb8", + "trait_color": "#b78cf2", + }, +) + +call-function: ( + "check-colors", + { + "theme": "light", + "link_color": "#3873ad", + "content_color": "black", + "header_color": "black", + "type_color": "#ad378a", + "trait_color": "#6e4fc9", + }, +) + +// Checking on mobile now. +set-window-size: (650, 600) +wait-for-size: ("body", {"width": 650}) +call-function: ("check-notable-tooltip-position-complete", { + "x": 26, + "i_x": 305, + "popover_x": 0, +}) + +reload: + +// Check that pressing escape works +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" +move-cursor-to: "//*[@class='tooltip popover']" +assert-count: ("//*[@class='tooltip popover']", 1) +press-key: "Escape" +assert-count: ("//*[@class='tooltip popover']", 0) +assert: "#method\.create_an_iterator_from_read .tooltip:focus" + +// Check that clicking outside works. +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" +assert-count: ("//*[@class='tooltip popover']", 1) +click: ".main-heading h1" +assert-count: ("//*[@class='tooltip popover']", 0) +assert-false: "#method\.create_an_iterator_from_read .tooltip:focus" + +// Check that pressing tab over and over works. +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" +move-cursor-to: "//*[@class='tooltip popover']" +assert-count: ("//*[@class='tooltip popover']", 1) +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +press-key: "Tab" +assert-count: ("//*[@class='tooltip popover']", 0) +assert: "#method\.create_an_iterator_from_read .tooltip:focus" + +define-function: ( + "setup-popup", + [], + block { + store-window-property: {"scrollY": scroll} + click: "#method\.create_an_iterator_from_read .fn" + // We ensure that the scroll position changed. + assert-window-property-false: {"scrollY": |scroll|} + // Store the new position. + store-window-property: {"scrollY": scroll} + click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" + wait-for: "//*[@class='tooltip popover']" + click: ".main-heading h1" + } +) + +// Now we check that the focus isn't given back to the wrong item when opening +// another popover. +call-function: ("setup-popup", {}) +click: ".main-heading h1" +// We ensure we didn't come back to the previous focused item. +assert-window-property-false: {"scrollY": |scroll|} + +// Same but with Escape handling. +call-function: ("setup-popup", {}) +press-key: "Escape" +// We ensure we didn't come back to the previous focused item. +assert-window-property-false: {"scrollY": |scroll|} + +// Opening the mobile sidebar should close the popover. +set-window-size: (650, 600) +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" +assert-count: ("//*[@class='tooltip popover']", 1) +click: ".sidebar-menu-toggle" +assert: "//*[@class='sidebar shown']" +assert-count: ("//*[@class='tooltip popover']", 0) +assert-false: "#method\.create_an_iterator_from_read .tooltip:focus" + +// Also check the focus handling for the settings button. +set-window-size: (1100, 600) +reload: +assert-count: ("//*[@class='tooltip popover']", 0) +click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']" +wait-for-count: ("//*[@class='tooltip popover']", 1) +call-function: ("open-settings-menu", {}) +wait-for-count: ("//*[@class='tooltip popover']", 0) +assert-false: "#method\.create_an_iterator_from_read .tooltip:focus" From 274e97c6be538d12f838d284781713a92494ff7e Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 20 Aug 2026 18:44:38 +0200 Subject: [PATCH 15/34] Fix rustdoc remapping `documentation` scope documentation --- src/doc/rustdoc/src/unstable-features.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md index 3b5bf4ae080dc..ab317ba1048a4 100644 --- a/src/doc/rustdoc/src/unstable-features.md +++ b/src/doc/rustdoc/src/unstable-features.md @@ -812,8 +812,7 @@ Defines which scopes of paths should be remapped by --remap-path-prefix. `rustdoc` (and by extension `rustc`) have a special `documentation` remapping scope, it permits remapping source paths that ends up in the generated documentation. -Currently the scope can only be specified from `rustc`, due to the lack of an equivalent -`--remap-path-scope` flag in `rustc`. +It can specified with `--remap-path-scope=documentation`. ## `#[doc(cfg)]` and `#[doc(auto_cfg)]` From 176a865eb385c9b1996e085f65757778a367c042 Mon Sep 17 00:00:00 2001 From: cdcp2 Date: Thu, 20 Aug 2026 12:30:48 -0500 Subject: [PATCH 16/34] Update expect messages in path docs to better follow guidelines --- library/std/src/path.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 8b41a3792ac9a..861d49073f56a 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -3329,7 +3329,7 @@ impl Path { /// use std::path::Path; /// /// let path = Path::new("/Minas/tirith"); - /// let metadata = path.metadata().expect("metadata call failed"); + /// let metadata = path.metadata().expect("the path should point to an existing file or directory"); /// println!("{:?}", metadata.file_type()); /// ``` #[stable(feature = "path_ext", since = "1.5.0")] @@ -3348,7 +3348,7 @@ impl Path { /// use std::path::Path; /// /// let path = Path::new("/Minas/tirith"); - /// let metadata = path.symlink_metadata().expect("symlink_metadata call failed"); + /// let metadata = path.symlink_metadata().expect("the path should exist"); /// println!("{:?}", metadata.file_type()); /// ``` #[stable(feature = "path_ext", since = "1.5.0")] @@ -3483,7 +3483,7 @@ impl Path { /// use std::path::Path; /// /// let path = Path::new("/laputa/sky_castle.rs"); - /// let path_link = path.read_link().expect("read_link call failed"); + /// let path_link = path.read_link().expect("the path should be an existing symbolic link"); /// ``` #[stable(feature = "path_ext", since = "1.5.0")] #[inline] @@ -3504,7 +3504,7 @@ impl Path { /// use std::path::Path; /// /// let path = Path::new("/laputa"); - /// for entry in path.read_dir().expect("read_dir call failed") { + /// for entry in path.read_dir().expect("the path should point to an existing directory") { /// if let Ok(entry) = entry { /// println!("{:?}", entry.path()); /// } @@ -3569,7 +3569,7 @@ impl Path { /// /// ```no_run /// use std::path::Path; - /// assert!(!Path::new("does_not_exist.txt").try_exists().expect("Can't check existence of file does_not_exist.txt")); + /// assert!(!Path::new("does_not_exist.txt").try_exists().expect("the path's existence should be verifiable")); /// assert!(Path::new("/root/secret_file.txt").try_exists().is_err()); /// ``` /// From ab350138857514e8300bc08e8b5ae83ee6dd038a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Fri, 21 Aug 2026 08:22:31 +0200 Subject: [PATCH 17/34] Change triagebot backport to ping T-libs-fcp --- triagebot.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/triagebot.toml b/triagebot.toml index 6e8fbbad2651a..d0694508eeffe 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -850,7 +850,7 @@ zulip_stream = 542373 # #t-libs/backports topic = "#{number}: beta-nominated" message_on_add = [ """\ -@*T-libs* PR #{number} "{title}" has been nominated for beta backport. +@*T-libs-fcp* PR #{number} "{title}" has been nominated for beta backport. """, """\ /poll Should #{number} be beta backported? @@ -874,7 +874,7 @@ zulip_stream = 542373 # #t-libs/backports topic = "#{number}: stable-nominated" message_on_add = [ """\ -@**channel** PR #{number} "{title}" has been nominated for stable backport. +@*T-libs-fcp* PR #{number} "{title}" has been nominated for stable backport. """, """\ /poll Approve stable backport of #{number}? From 589bb91122dbff7c51f4593afb36926e9c645e76 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 14:34:21 +0200 Subject: [PATCH 18/34] Move `Limit` --- Cargo.lock | 23 +++++++++++++++++++ compiler/rustc_attr_ir/Cargo.toml | 1 + compiler/rustc_attr_ir/src/data_structures.rs | 2 +- compiler/rustc_attr_ir/src/pretty_printing.rs | 2 +- compiler/rustc_attr_parsing/Cargo.toml | 1 + .../rustc_attr_parsing/src/attributes/util.rs | 2 +- compiler/rustc_const_eval/Cargo.toml | 1 + .../src/interpret/eval_context.rs | 2 +- compiler/rustc_data_structures/src/lib.rs | 2 -- compiler/rustc_error_messages/Cargo.toml | 1 + .../src/diagnostic_impls.rs | 2 +- compiler/rustc_expand/Cargo.toml | 1 + compiler/rustc_expand/src/base.rs | 3 ++- compiler/rustc_expand/src/diagnostics.rs | 2 +- compiler/rustc_expand/src/expand.rs | 2 +- compiler/rustc_hir_analysis/Cargo.toml | 1 + compiler/rustc_hir_analysis/src/autoderef.rs | 2 +- .../rustc_hir_analysis/src/diagnostics.rs | 2 +- compiler/rustc_interface/Cargo.toml | 1 + compiler/rustc_interface/src/limits.rs | 2 +- compiler/rustc_interface/src/passes.rs | 3 ++- compiler/rustc_middle/Cargo.toml | 1 + compiler/rustc_middle/src/diagnostics.rs | 4 ++-- compiler/rustc_middle/src/ty/context.rs | 3 ++- .../src/ty/context/impl_interner.rs | 2 +- compiler/rustc_middle/src/ty/error.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 2 +- compiler/rustc_mir_transform/Cargo.toml | 1 + .../rustc_mir_transform/src/inline/cycle.rs | 2 +- compiler/rustc_monomorphize/Cargo.toml | 1 + compiler/rustc_monomorphize/src/collector.rs | 2 +- .../src/mono_checks/move_check.rs | 2 +- compiler/rustc_query_impl/Cargo.toml | 1 + compiler/rustc_query_impl/src/diagnostics.rs | 2 +- compiler/rustc_query_impl/src/execution.rs | 3 ++- compiler/rustc_session/Cargo.toml | 1 + compiler/rustc_session/src/session.rs | 3 ++- compiler/rustc_structures/Cargo.toml | 11 +++++++++ compiler/rustc_structures/src/lib.rs | 3 +++ .../src/limit.rs | 0 compiler/rustc_trait_selection/Cargo.toml | 1 + .../nice_region_error/placeholder_error.rs | 2 +- .../src/error_reporting/traits/overflow.rs | 2 +- compiler/rustc_ty_utils/Cargo.toml | 1 + compiler/rustc_ty_utils/src/layout.rs | 2 +- compiler/rustc_ty_utils/src/needs_drop.rs | 2 +- 48 files changed, 86 insertions(+), 32 deletions(-) create mode 100644 compiler/rustc_structures/Cargo.toml create mode 100644 compiler/rustc_structures/src/lib.rs rename compiler/{rustc_data_structures => rustc_structures}/src/limit.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index d268ee58d83d6..17f1ae5d62070 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3664,6 +3664,7 @@ dependencies = [ "rustc_macros", "rustc_serialize", "rustc_span", + "rustc_structures", "rustc_target", "smallvec", "thin-vec", @@ -3688,6 +3689,7 @@ dependencies = [ "rustc_parse_format", "rustc_session", "rustc_span", + "rustc_structures", "rustc_target", "thin-vec", ] @@ -3855,6 +3857,7 @@ dependencies = [ "rustc_mir_dataflow", "rustc_session", "rustc_span", + "rustc_structures", "rustc_target", "rustc_trait_selection", "tracing", @@ -3973,6 +3976,7 @@ dependencies = [ "rustc_macros", "rustc_serialize", "rustc_span", + "rustc_structures", "unic-langid", ] @@ -4023,6 +4027,7 @@ dependencies = [ "rustc_serialize", "rustc_session", "rustc_span", + "rustc_structures", "scoped-tls", "smallvec", "thin-vec", @@ -4098,6 +4103,7 @@ dependencies = [ "rustc_middle", "rustc_session", "rustc_span", + "rustc_structures", "rustc_target", "rustc_trait_selection", "smallvec", @@ -4251,6 +4257,7 @@ dependencies = [ "rustc_resolve", "rustc_session", "rustc_span", + "rustc_structures", "rustc_symbol_mangling", "rustc_target", "rustc_thread_pool", @@ -4405,6 +4412,7 @@ dependencies = [ "rustc_serialize", "rustc_session", "rustc_span", + "rustc_structures", "rustc_target", "rustc_thread_pool", "rustc_type_ir", @@ -4476,6 +4484,7 @@ dependencies = [ "rustc_mir_dataflow", "rustc_session", "rustc_span", + "rustc_structures", "rustc_target", "rustc_trait_selection", "smallvec", @@ -4498,6 +4507,7 @@ dependencies = [ "rustc_serialize", "rustc_session", "rustc_span", + "rustc_structures", "rustc_symbol_mangling", "rustc_target", "serde", @@ -4663,6 +4673,7 @@ dependencies = [ "rustc_middle", "rustc_serialize", "rustc_span", + "rustc_structures", "rustc_thread_pool", "tracing", ] @@ -4741,6 +4752,7 @@ dependencies = [ "rustc_macros", "rustc_serialize", "rustc_span", + "rustc_structures", "rustc_target", "termize", "tracing", @@ -4770,6 +4782,15 @@ dependencies = [ "unicode-width 0.2.2", ] +[[package]] +name = "rustc_structures" +version = "0.0.0" +dependencies = [ + "rustc_data_structures", + "rustc_macros", + "rustc_serialize", +] + [[package]] name = "rustc_symbol_mangling" version = "0.0.0" @@ -4849,6 +4870,7 @@ dependencies = [ "rustc_next_trait_solver", "rustc_session", "rustc_span", + "rustc_structures", "rustc_transmute", "smallvec", "thin-vec", @@ -4897,6 +4919,7 @@ dependencies = [ "rustc_middle", "rustc_session", "rustc_span", + "rustc_structures", "rustc_target", "rustc_trait_selection", "rustc_ty_walk", diff --git a/compiler/rustc_attr_ir/Cargo.toml b/compiler/rustc_attr_ir/Cargo.toml index 28ca2c8839508..9520f762d7f8e 100644 --- a/compiler/rustc_attr_ir/Cargo.toml +++ b/compiler/rustc_attr_ir/Cargo.toml @@ -13,6 +13,7 @@ rustc_error_messages = { path = "../rustc_error_messages" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } thin-vec = "0.2.18" diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index eb15c2af14d88..5de91cc8b7b23 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -10,13 +10,13 @@ use rustc_ast::expand::autodiff_attrs::{DiffActivity, DiffMode}; use rustc_ast::expand::typetree::TypeTree; use rustc_ast::token::DocFragmentKind; use rustc_ast::{AttrStyle, Path, ast}; -use rustc_data_structures::Limit; use rustc_data_structures::fx::FxIndexMap; use rustc_error_messages::{DiagArgValue, IntoDiagArg}; use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash}; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; +use rustc_structures::Limit; pub use rustc_target::spec::SanitizerSet; use thin_vec::ThinVec; diff --git a/compiler/rustc_attr_ir/src/pretty_printing.rs b/compiler/rustc_attr_ir/src/pretty_printing.rs index 1cecd49aa1424..f130c2b0f4b0e 100644 --- a/compiler/rustc_attr_ir/src/pretty_printing.rs +++ b/compiler/rustc_attr_ir/src/pretty_printing.rs @@ -10,11 +10,11 @@ use rustc_ast::expand::autodiff_attrs::{DiffActivity, DiffMode}; use rustc_ast::token::{CommentKind, DocFragmentKind}; use rustc_ast::{AttrId, AttrStyle, IntTy, UintTy}; use rustc_ast_pretty::pp::Printer; -use rustc_data_structures::Limit; use rustc_data_structures::fx::FxIndexMap; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; +use rustc_structures::Limit; use rustc_target::spec::SanitizerSet; use thin_vec::ThinVec; diff --git a/compiler/rustc_attr_parsing/Cargo.toml b/compiler/rustc_attr_parsing/Cargo.toml index 70161a7961815..3c40253e34a4c 100644 --- a/compiler/rustc_attr_parsing/Cargo.toml +++ b/compiler/rustc_attr_parsing/Cargo.toml @@ -19,6 +19,7 @@ rustc_parse = { path = "../rustc_parse" } rustc_parse_format = { path = "../rustc_parse_format" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } thin-vec = "0.2.19" # tidy-alphabetical-end diff --git a/compiler/rustc_attr_parsing/src/attributes/util.rs b/compiler/rustc_attr_parsing/src/attributes/util.rs index ed6d27b4c58f7..8f8af2218506e 100644 --- a/compiler/rustc_attr_parsing/src/attributes/util.rs +++ b/compiler/rustc_attr_parsing/src/attributes/util.rs @@ -2,9 +2,9 @@ use std::num::IntErrorKind; use rustc_ast::{LitKind, ast}; use rustc_attr_ir::RustcVersion; -use rustc_data_structures::Limit; use rustc_feature::is_builtin_attr_name; use rustc_span::Symbol; +use rustc_structures::Limit; use crate::context::AcceptContext; use crate::diagnostics::LimitInvalid; diff --git a/compiler/rustc_const_eval/Cargo.toml b/compiler/rustc_const_eval/Cargo.toml index eac00eb7b876d..296368c42034b 100644 --- a/compiler/rustc_const_eval/Cargo.toml +++ b/compiler/rustc_const_eval/Cargo.toml @@ -20,6 +20,7 @@ rustc_middle = { path = "../rustc_middle" } rustc_mir_dataflow = { path = "../rustc_mir_dataflow" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } tracing = "0.1" diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 571e7e5975c79..8fa028df9455f 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -3,7 +3,6 @@ use std::collections::hash_map::Entry; use either::{Left, Right}; use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout}; -use rustc_data_structures::Limit; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; use rustc_middle::mir::interpret::{ErrorHandled, InvalidMetaKind, ReportedErrorInfo}; @@ -17,6 +16,7 @@ use rustc_middle::ty::{ }; use rustc_middle::{mir, span_bug}; use rustc_span::Span; +use rustc_structures::Limit; use rustc_target::callconv::FnAbi; use tracing::{debug, trace}; diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 9714fb2123b08..d8c1e2bd0ed30 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -48,7 +48,6 @@ pub use ena::{snapshot_vec, undo_log, unify}; // (via `ShardedHashMap`), and because it lets other compiler crates use the // lower-level `HashTable` API without a tricky `hashbrown` dependency. pub use hashbrown::hash_table; -pub use limit::Limit; pub use rustc_index::static_assert_size; // Re-export some data-structure crates which are part of our public API. pub use {either, indexmap, smallvec, thin_vec}; @@ -63,7 +62,6 @@ pub mod fx; pub mod graph; pub mod intern; pub mod jobserver; -mod limit; pub mod marker; pub mod memmap; pub mod obligation_forest; diff --git a/compiler/rustc_error_messages/Cargo.toml b/compiler/rustc_error_messages/Cargo.toml index 50f0b265527fe..f4f2862c2db9d 100644 --- a/compiler/rustc_error_messages/Cargo.toml +++ b/compiler/rustc_error_messages/Cargo.toml @@ -14,5 +14,6 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } unic-langid = { version = "0.9.0", features = ["macros"] } # tidy-alphabetical-end diff --git a/compiler/rustc_error_messages/src/diagnostic_impls.rs b/compiler/rustc_error_messages/src/diagnostic_impls.rs index d2bbdde362156..0c6443bf12fe8 100644 --- a/compiler/rustc_error_messages/src/diagnostic_impls.rs +++ b/compiler/rustc_error_messages/src/diagnostic_impls.rs @@ -5,8 +5,8 @@ use std::num::ParseIntError; use std::path::{Path, PathBuf}; use std::process::ExitStatus; -use rustc_data_structures::Limit; use rustc_span::edition::Edition; +use rustc_structures::Limit; use crate::{DiagArgValue, IntoDiagArg}; diff --git a/compiler/rustc_expand/Cargo.toml b/compiler/rustc_expand/Cargo.toml index 885de14fd6b2f..80353e4c8dba4 100644 --- a/compiler/rustc_expand/Cargo.toml +++ b/compiler/rustc_expand/Cargo.toml @@ -29,6 +29,7 @@ rustc_proc_macro = { path = "../rustc_proc_macro" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } scoped-tls = "1.0" smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } thin-vec = "0.2.19" diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 64b6e4b8ef498..d845c2b732629 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -13,7 +13,7 @@ use rustc_attr_ir::{ self as attrs, CfgEntry, CollapseMacroDebuginfo, Deprecation, Stability, find_attr, }; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; -use rustc_data_structures::{Limit, sync}; +use rustc_data_structures::sync; use rustc_errors::{BufferedEarlyLint, DiagCtxtHandle, ErrorGuaranteed}; use rustc_feature::Features; use rustc_hir::def::MacroKinds; @@ -27,6 +27,7 @@ use rustc_span::edition::Edition; use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind}; use rustc_span::source_map::SourceMap; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw}; +use rustc_structures::Limit; use smallvec::{SmallVec, smallvec}; use thin_vec::ThinVec; diff --git a/compiler/rustc_expand/src/diagnostics.rs b/compiler/rustc_expand/src/diagnostics.rs index 8c9e0dc9b85de..34fe7cab71b5b 100644 --- a/compiler/rustc_expand/src/diagnostics.rs +++ b/compiler/rustc_expand/src/diagnostics.rs @@ -1,9 +1,9 @@ use std::borrow::Cow; -use rustc_data_structures::Limit; use rustc_errors::codes::*; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol}; +use rustc_structures::Limit; #[derive(Diagnostic)] #[diag("`#[cfg_attr]` does not expand to any attributes")] diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 18e789314fa78..3a51b758a427b 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -19,7 +19,6 @@ use rustc_attr_parsing::{ AttributeParser, AttributeSafety, CFG_TEMPLATE, EvalConfigResult, ShouldEmit, eval_config_entry, parse_cfg, validate_attr, }; -use rustc_data_structures::Limit; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; use rustc_errors::PResult; use rustc_feature::Features; @@ -32,6 +31,7 @@ use rustc_parse::parser::{ use rustc_session::diagnostics::feature_err; use rustc_span::hygiene::SyntaxContext; use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, Symbol, sym}; +use rustc_structures::Limit; use smallvec::SmallVec; use crate::base::*; diff --git a/compiler/rustc_hir_analysis/Cargo.toml b/compiler/rustc_hir_analysis/Cargo.toml index 955629d40cee2..06092f53272ce 100644 --- a/compiler/rustc_hir_analysis/Cargo.toml +++ b/compiler/rustc_hir_analysis/Cargo.toml @@ -24,6 +24,7 @@ rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } diff --git a/compiler/rustc_hir_analysis/src/autoderef.rs b/compiler/rustc_hir_analysis/src/autoderef.rs index 20c3ac6036678..01d0c8483ac54 100644 --- a/compiler/rustc_hir_analysis/src/autoderef.rs +++ b/compiler/rustc_hir_analysis/src/autoderef.rs @@ -1,9 +1,9 @@ -use rustc_data_structures::Limit; use rustc_infer::infer::InferCtxt; use rustc_infer::traits::PredicateObligations; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, Unnormalized}; use rustc_span::def_id::{LOCAL_CRATE, LocalDefId}; use rustc_span::{ErrorGuaranteed, Span}; +use rustc_structures::Limit; use rustc_trait_selection::traits::ObligationCtxt; use tracing::{debug, instrument}; diff --git a/compiler/rustc_hir_analysis/src/diagnostics.rs b/compiler/rustc_hir_analysis/src/diagnostics.rs index 890d25f14b264..2547695132e7d 100644 --- a/compiler/rustc_hir_analysis/src/diagnostics.rs +++ b/compiler/rustc_hir_analysis/src/diagnostics.rs @@ -1,7 +1,6 @@ //! Errors emitted by `rustc_hir_analysis`. use rustc_abi::ExternAbi; -use rustc_data_structures::Limit; use rustc_errors::codes::*; use rustc_errors::{ Applicability, Diag, DiagCtxtHandle, DiagSymbolList, Diagnostic, EmissionGuarantee, Level, @@ -10,6 +9,7 @@ use rustc_errors::{ use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_middle::ty::{self, Ty}; use rustc_span::{Ident, Span, Symbol}; +use rustc_structures::Limit; pub(crate) mod wrong_number_of_generic_args; mod precise_captures; diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index bda6f48734b31..4e99ba176d57b 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -41,6 +41,7 @@ rustc_query_impl = { path = "../rustc_query_impl" } rustc_resolve = { path = "../rustc_resolve" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_symbol_mangling = { path = "../rustc_symbol_mangling" } rustc_target = { path = "../rustc_target" } rustc_thread_pool = { path = "../rustc_thread_pool" } diff --git a/compiler/rustc_interface/src/limits.rs b/compiler/rustc_interface/src/limits.rs index f1f2b1536f806..8f116cfdf6a86 100644 --- a/compiler/rustc_interface/src/limits.rs +++ b/compiler/rustc_interface/src/limits.rs @@ -8,10 +8,10 @@ //! Users can override these limits via an attribute on the crate like //! `#![recursion_limit="22"]`. This pass just looks for those attributes. -use rustc_data_structures::Limit; use rustc_hir::{Attribute, find_attr}; use rustc_middle::query::Providers; use rustc_session::{Limits, Session}; +use rustc_structures::Limit; pub(crate) fn provide(providers: &mut Providers) { providers.limits = |tcx, ()| { diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index fa9d2f8e852b5..35fb9102eb265 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -15,7 +15,7 @@ use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{ AppendOnlyIndexVec, DynSend, DynSync, FreezeLock, WorkerLocal, par_fns, }; -use rustc_data_structures::{Limit, thousands}; +use rustc_data_structures::thousands; use rustc_errors::timings::TimingSection; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level}; use rustc_expand::base::{ExtCtxt, LintStoreExpand}; @@ -44,6 +44,7 @@ use rustc_session::{IncrCompSession, Session}; use rustc_span::{ DUMMY_SP, ErrorGuaranteed, ExpnKind, SourceFileHash, SourceFileHashAlgorithm, Span, Symbol, sym, }; +use rustc_structures::Limit; use rustc_trait_selection::{solve, traits}; use tracing::{info, instrument}; diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index 96506291735ba..b26969a830f11 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -28,6 +28,7 @@ rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } rustc_thread_pool = { path = "../rustc_thread_pool" } rustc_type_ir = { path = "../rustc_type_ir" } diff --git a/compiler/rustc_middle/src/diagnostics.rs b/compiler/rustc_middle/src/diagnostics.rs index 9d90691e51446..b2e987602963f 100644 --- a/compiler/rustc_middle/src/diagnostics.rs +++ b/compiler/rustc_middle/src/diagnostics.rs @@ -59,7 +59,7 @@ pub(crate) struct RecursionLimitReached<'tcx> { #[primary_span] pub span: Span, pub ty: Ty<'tcx>, - pub suggested_limit: rustc_data_structures::Limit, + pub suggested_limit: rustc_structures::Limit, } #[derive(Diagnostic)] @@ -71,7 +71,7 @@ pub(crate) struct RecursionLimitReachedSizeSkeleton<'tcx> { #[primary_span] pub span: Span, pub ty: Ty<'tcx>, - pub suggested_limit: rustc_data_structures::Limit, + pub suggested_limit: rustc_structures::Limit, } #[derive(Diagnostic)] diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index f4ee5a693ecb3..af60db2166c46 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -18,6 +18,7 @@ use std::{fmt, iter, mem}; use rustc_abi::{ExternAbi, FieldIdx, Layout, LayoutData, TargetDataLayout, VariantIdx}; use rustc_ast as ast; use rustc_crate_store::{CrateStoreDyn, Untracked}; +use rustc_data_structures::defer; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::intern::Interned; use rustc_data_structures::profiling::SelfProfilerRef; @@ -27,7 +28,6 @@ use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{ self, DynSend, DynSync, FreezeReadGuard, Lock, RwLock, WorkerLocal, }; -use rustc_data_structures::{Limit, defer}; use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, MultiSpan}; use rustc_hir::attrs::lang_items::LangItem; use rustc_hir::def::DefKind; @@ -43,6 +43,7 @@ use rustc_session::config::CrateType; use rustc_session::{IncrCompSession, Session}; use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; +use rustc_structures::Limit; use rustc_type_ir::TyKind::*; pub use rustc_type_ir::lift::Lift; use rustc_type_ir::{CollectAndApply, WithCachedTypeInfo, elaborate, search_graph}; diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index 2444f8513b8e4..637fc1d34b9e1 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -2,7 +2,6 @@ use std::{debug_assert_matches, fmt}; -use rustc_data_structures::Limit; use rustc_data_structures::intern::Interned; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; @@ -12,6 +11,7 @@ use rustc_hir::def::{CtorKind, DefKind, Namespace}; use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId}; use rustc_lint_defs::builtin::RECURSION_DEPTH_EXCEEDING_LIMIT; use rustc_span::{DUMMY_SP, Span, Symbol}; +use rustc_structures::Limit; use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverProjectionLangItem, SolverTraitLangItem}; use rustc_type_ir::{ BoundVar, CollectAndApply, DebruijnIndex, Interner, TypeFoldable, Unnormalized, VisitorResult, diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index a16352e45564e..33541dee52fe6 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -4,11 +4,11 @@ use std::hash::{DefaultHasher, Hash, Hasher}; use std::io::{Read, Write}; use std::path::PathBuf; -use rustc_data_structures::Limit; use rustc_errors::pluralize; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind}; use rustc_macros::extension; +use rustc_structures::Limit; pub use rustc_type_ir::error::ExpectedFound; use crate::ty::print::{FmtPrinter, Print, with_forced_trimmed_paths}; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index c525a9e4ebe61..f6e0e03858157 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -6,7 +6,6 @@ use rustc_abi::{ PointerKind, Primitive, ReprFlags, ReprOptions, Scalar, Size, TagEncoding, TargetDataLayout, TyAbiInterface, VariantIdx, Variants, }; -use rustc_data_structures::Limit; use rustc_errors::{ Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level, }; @@ -16,6 +15,7 @@ use rustc_hir::def_id::DefId; use rustc_macros::{StableHash, TyDecodable, TyEncodable, extension}; use rustc_session::config::OptLevel; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym}; +use rustc_structures::Limit; use rustc_target::callconv::FnAbi; use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, X86Abi}; use tracing::debug; diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 84437a237c28a..67a2a23b15a07 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -7,7 +7,6 @@ use rustc_abi::{ExternAbi, Size}; use rustc_apfloat::Float; use rustc_apfloat::ieee::{Double, Half, Quad, Single}; use rustc_crate_store::{ExternCrate, ExternCrateSource}; -use rustc_data_structures::Limit; use rustc_data_structures::fx::{FxIndexMap, IndexEntry}; use rustc_data_structures::unord::UnordMap; use rustc_hir as hir; @@ -17,6 +16,7 @@ use rustc_hir::def_id::{DefIdMap, DefIdSet, LOCAL_CRATE, ModId}; use rustc_hir::definitions::{DefKey, DefPathDataName}; use rustc_macros::{Lift, extension}; use rustc_span::{Ident, RemapPathScopeComponents, Symbol, kw, sym}; +use rustc_structures::Limit; use rustc_type_ir::{FieldInfo, Unnormalized, Upcast as _, elaborate}; use smallvec::SmallVec; diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 2e31e666f8f48..d18882e4649ca 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -4,7 +4,6 @@ use std::{fmt, iter}; use rustc_abi::{Float, Integer, IntegerType, Size}; use rustc_apfloat::Float as _; -use rustc_data_structures::Limit; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::stable_hash::{StableHash, StableHasher}; use rustc_errors::ErrorGuaranteed; @@ -15,6 +14,7 @@ use rustc_hir::{self as hir, find_attr}; use rustc_index::bit_set::GrowableBitSet; use rustc_macros::{StableHash, TyDecodable, TyEncodable, extension}; use rustc_span::sym; +use rustc_structures::Limit; use rustc_type_ir::solve::SizedTraitKind; use smallvec::{SmallVec, smallvec}; use tracing::{debug, instrument}; diff --git a/compiler/rustc_mir_transform/Cargo.toml b/compiler/rustc_mir_transform/Cargo.toml index b5dc8100cbb26..4d157391ed4b0 100644 --- a/compiler/rustc_mir_transform/Cargo.toml +++ b/compiler/rustc_mir_transform/Cargo.toml @@ -22,6 +22,7 @@ rustc_middle = { path = "../rustc_middle" } rustc_mir_dataflow = { path = "../rustc_mir_dataflow" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } diff --git a/compiler/rustc_mir_transform/src/inline/cycle.rs b/compiler/rustc_mir_transform/src/inline/cycle.rs index b974cb656379d..5b6b5203fdafa 100644 --- a/compiler/rustc_mir_transform/src/inline/cycle.rs +++ b/compiler/rustc_mir_transform/src/inline/cycle.rs @@ -1,10 +1,10 @@ -use rustc_data_structures::Limit; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::unord::UnordSet; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::mir::TerminatorKind; use rustc_middle::ty::{self, GenericArgsRef, InstanceKind, ShimKind, TyCtxt, TypeVisitableExt}; use rustc_span::sym; +use rustc_structures::Limit; use tracing::{instrument, trace}; #[instrument(level = "debug", skip(tcx), ret)] diff --git a/compiler/rustc_monomorphize/Cargo.toml b/compiler/rustc_monomorphize/Cargo.toml index de020de0b1dc5..ce5b90e2593a8 100644 --- a/compiler/rustc_monomorphize/Cargo.toml +++ b/compiler/rustc_monomorphize/Cargo.toml @@ -17,6 +17,7 @@ rustc_middle = { path = "../rustc_middle" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_symbol_mangling = { path = "../rustc_symbol_mangling" } rustc_target = { path = "../rustc_target" } serde = "1" diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 62519ee4f13ee..b7813992db5bf 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -208,7 +208,6 @@ use std::cell::OnceCell; use std::ops::ControlFlow; -use rustc_data_structures::Limit; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::{Lock, par_for_each_in}; use rustc_data_structures::unord::{UnordMap, UnordSet}; @@ -233,6 +232,7 @@ use rustc_middle::util::Providers; use rustc_middle::{bug, span_bug}; use rustc_session::config::{DebugInfo, EntryFnType, Offload}; use rustc_span::{DUMMY_SP, Span, Spanned, Symbol, dummy_spanned, respan}; +use rustc_structures::Limit; use tracing::{debug, instrument, trace}; use crate::diagnostics::{ diff --git a/compiler/rustc_monomorphize/src/mono_checks/move_check.rs b/compiler/rustc_monomorphize/src/mono_checks/move_check.rs index b32ca204f3998..3d925baa0a32b 100644 --- a/compiler/rustc_monomorphize/src/mono_checks/move_check.rs +++ b/compiler/rustc_monomorphize/src/mono_checks/move_check.rs @@ -1,5 +1,4 @@ use rustc_abi::Size; -use rustc_data_structures::Limit; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; use rustc_lint_defs::builtin::LARGE_ASSIGNMENTS; @@ -7,6 +6,7 @@ use rustc_middle::mir::visit::Visitor as MirVisitor; use rustc_middle::mir::{self, Location, traversal}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable}; use rustc_span::{Span, Spanned, sym}; +use rustc_structures::Limit; use tracing::{debug, trace}; use crate::diagnostics::LargeAssignmentsLint; diff --git a/compiler/rustc_query_impl/Cargo.toml b/compiler/rustc_query_impl/Cargo.toml index ec1d8dab74519..1b526e416b38d 100644 --- a/compiler/rustc_query_impl/Cargo.toml +++ b/compiler/rustc_query_impl/Cargo.toml @@ -13,6 +13,7 @@ rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_thread_pool = { path = "../rustc_thread_pool" } tracing = "0.1" # tidy-alphabetical-end diff --git a/compiler/rustc_query_impl/src/diagnostics.rs b/compiler/rustc_query_impl/src/diagnostics.rs index eee6cea623909..dd33d4c7bbf57 100644 --- a/compiler/rustc_query_impl/src/diagnostics.rs +++ b/compiler/rustc_query_impl/src/diagnostics.rs @@ -1,7 +1,7 @@ -use rustc_data_structures::Limit; use rustc_errors::codes::*; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{Span, Symbol}; +use rustc_structures::Limit; #[derive(Diagnostic)] #[help( diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index 3e5ee960e2772..796ce8e666fc5 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -3,7 +3,7 @@ use std::mem::ManuallyDrop; use std::num::NonZero; use rustc_data_structures::hash_table::Entry; -use rustc_data_structures::{Limit, defer, outline, sharded, sync}; +use rustc_data_structures::{defer, outline, sharded, sync}; use rustc_errors::FatalError; use rustc_middle::dep_graph::{ DepGraphData, DepNode, DepNodeIndex, DepNodeKey, SerializedDepNodeIndex, @@ -17,6 +17,7 @@ use rustc_middle::ty::tls::{self, ImplicitCtxt}; use rustc_middle::verify_ich::incremental_verify_ich; use rustc_span::def_id::LOCAL_CRATE; use rustc_span::{DUMMY_SP, Span}; +use rustc_structures::Limit; use crate::diagnostics::{QueryOverflow, QueryOverflowNote}; use crate::handle_cycle_error; diff --git a/compiler/rustc_session/Cargo.toml b/compiler/rustc_session/Cargo.toml index c230c6793f0c2..9e3cac424ad6d 100644 --- a/compiler/rustc_session/Cargo.toml +++ b/compiler/rustc_session/Cargo.toml @@ -18,6 +18,7 @@ rustc_lint_defs = { path = "../rustc_lint_defs" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } termize = "0.2" tracing = "0.1" diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 99ff5d4b691ae..cd3cbc8e37ea0 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -6,10 +6,10 @@ use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::{env, io}; +use rustc_data_structures::flock; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef}; use rustc_data_structures::sync::{AppendOnlyVec, DynSend, DynSync, Lock}; -use rustc_data_structures::{Limit, flock}; use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter; use rustc_errors::codes::*; use rustc_errors::emitter::{DynEmitter, HumanReadableErrorType, OutputTheme, stderr_destination}; @@ -25,6 +25,7 @@ pub use rustc_span::def_id::StableCrateId; use rustc_span::edition::Edition; use rustc_span::source_map::{FilePathMapping, SourceMap}; use rustc_span::{RealFileName, Span, Symbol}; +use rustc_structures::Limit; use rustc_target::asm::InlineAsmArch; use rustc_target::spec::{ Arch, CfgAbi, CodeModel, DebuginfoKind, Os, PanicStrategy, RelocModel, RelroLevel, diff --git a/compiler/rustc_structures/Cargo.toml b/compiler/rustc_structures/Cargo.toml new file mode 100644 index 0000000000000..847efc4ceeb10 --- /dev/null +++ b/compiler/rustc_structures/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "rustc_structures" +version = "0.0.0" +edition = "2024" + +[dependencies] +# tidy-alphabetical-start +rustc_data_structures = { path = "../rustc_data_structures" } +rustc_macros = { path = "../rustc_macros" } +rustc_serialize = { path = "../rustc_serialize" } +# tidy-alphabetical-end diff --git a/compiler/rustc_structures/src/lib.rs b/compiler/rustc_structures/src/lib.rs new file mode 100644 index 0000000000000..6e97f35f39a04 --- /dev/null +++ b/compiler/rustc_structures/src/lib.rs @@ -0,0 +1,3 @@ +mod limit; + +pub use limit::Limit; diff --git a/compiler/rustc_data_structures/src/limit.rs b/compiler/rustc_structures/src/limit.rs similarity index 100% rename from compiler/rustc_data_structures/src/limit.rs rename to compiler/rustc_structures/src/limit.rs diff --git a/compiler/rustc_trait_selection/Cargo.toml b/compiler/rustc_trait_selection/Cargo.toml index 52d88db0fba66..039856eeb4857 100644 --- a/compiler/rustc_trait_selection/Cargo.toml +++ b/compiler/rustc_trait_selection/Cargo.toml @@ -19,6 +19,7 @@ rustc_middle = { path = "../rustc_middle" } rustc_next_trait_solver = { path = "../rustc_next_trait_solver" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_transmute = { path = "../rustc_transmute", features = ["rustc"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } thin-vec = "0.2.19" diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs index ee8a4099b21cf..ccbe23cf7a631 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs @@ -1,6 +1,5 @@ use std::fmt; -use rustc_data_structures::Limit; use rustc_data_structures::intern::Interned; use rustc_errors::{Applicability, Diag, IntoDiagArg}; use rustc_hir as hir; @@ -12,6 +11,7 @@ use rustc_middle::ty::print::{FmtPrinter, Print, PrintTraitRefExt as _, RegionHi use rustc_middle::ty::{ self, GenericArgsRef, IsSuggestable, RePlaceholder, Region, RegionExt, TyCtxt, }; +use rustc_structures::Limit; use tracing::{debug, instrument}; use crate::diagnostics::{ diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/overflow.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/overflow.rs index da73c3e0d687d..30a18a928e842 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/overflow.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/overflow.rs @@ -1,6 +1,5 @@ use std::fmt; -use rustc_data_structures::Limit; use rustc_errors::{Diag, E0275, EmissionGuarantee, ErrorGuaranteed, struct_span_code_err}; use rustc_hir::def::Namespace; use rustc_hir::def_id::LOCAL_CRATE; @@ -8,6 +7,7 @@ use rustc_infer::traits::{Obligation, PredicateObligation}; use rustc_middle::ty::print::{FmtPrinter, Print}; use rustc_middle::ty::{self, TyCtxt, Upcast}; use rustc_span::Span; +use rustc_structures::Limit; use tracing::debug; use crate::error_reporting::TypeErrCtxt; diff --git a/compiler/rustc_ty_utils/Cargo.toml b/compiler/rustc_ty_utils/Cargo.toml index f633ef9950c09..e6de7bd1fab24 100644 --- a/compiler/rustc_ty_utils/Cargo.toml +++ b/compiler/rustc_ty_utils/Cargo.toml @@ -17,6 +17,7 @@ rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_ty_walk = { path = "../rustc_ty_walk" } diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 9e9aed008bf31..a8042374ee42f 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -9,7 +9,6 @@ use rustc_abi::{ LayoutCalculatorError, LayoutData, Niche, ReprOptions, Scalar, Size, StructKind, TagEncoding, VariantIdx, Variants, WrappingRange, }; -use rustc_data_structures::Limit; use rustc_hashes::Hash64; use rustc_hir as hir; use rustc_hir::find_attr; @@ -27,6 +26,7 @@ use rustc_middle::ty::{ }; use rustc_session::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo}; use rustc_span::{Symbol, sym}; +use rustc_structures::Limit; use tracing::{debug, instrument}; use crate::diagnostics::NonPrimitiveSimdType; diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index ec51304104745..e4d389cffd800 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -1,6 +1,5 @@ //! Check whether a type has (potentially) non-trivial drop glue. -use rustc_data_structures::Limit; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def_id::DefId; use rustc_hir::find_attr; @@ -8,6 +7,7 @@ use rustc_middle::bug; use rustc_middle::query::Providers; use rustc_middle::ty::util::{AlwaysRequiresDrop, needs_drop_components}; use rustc_middle::ty::{self, EarlyBinder, GenericArgsRef, Ty, TyCtxt, Unnormalized}; +use rustc_structures::Limit; use tracing::{debug, instrument}; use crate::diagnostics::NeedsDropOverflow; From 2a20dfa922638f4489b8f90c226844c75c3b5642 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 14:56:33 +0200 Subject: [PATCH 19/34] move SanitizerSet --- Cargo.lock | 6 +- compiler/rustc_attr_ir/Cargo.toml | 1 - compiler/rustc_attr_ir/src/data_structures.rs | 3 +- compiler/rustc_attr_ir/src/pretty_printing.rs | 3 +- .../src/attributes/codegen_attrs.rs | 3 +- compiler/rustc_codegen_llvm/Cargo.toml | 1 + compiler/rustc_codegen_llvm/src/back/lto.rs | 2 +- compiler/rustc_structures/Cargo.toml | 3 + compiler/rustc_structures/src/lib.rs | 2 + .../rustc_structures/src/sanitizer_set.rs | 166 ++++++++++++++++++ compiler/rustc_target/Cargo.toml | 1 + compiler/rustc_target/src/spec/mod.rs | 145 +-------------- 12 files changed, 184 insertions(+), 152 deletions(-) create mode 100644 compiler/rustc_structures/src/sanitizer_set.rs diff --git a/Cargo.lock b/Cargo.lock index 17f1ae5d62070..fb38fff0c4ad9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3665,7 +3665,6 @@ dependencies = [ "rustc_serialize", "rustc_span", "rustc_structures", - "rustc_target", "smallvec", "thin-vec", "tracing", @@ -3787,6 +3786,7 @@ dependencies = [ "rustc_sanitizers", "rustc_session", "rustc_span", + "rustc_structures", "rustc_symbol_mangling", "rustc_target", "smallvec", @@ -4786,9 +4786,12 @@ dependencies = [ name = "rustc_structures" version = "0.0.0" dependencies = [ + "bitflags", "rustc_data_structures", "rustc_macros", "rustc_serialize", + "schemars", + "serde", ] [[package]] @@ -4821,6 +4824,7 @@ dependencies = [ "rustc_macros", "rustc_serialize", "rustc_span", + "rustc_structures", "schemars", "serde", "serde_derive", diff --git a/compiler/rustc_attr_ir/Cargo.toml b/compiler/rustc_attr_ir/Cargo.toml index 9520f762d7f8e..2ede16da2fa22 100644 --- a/compiler/rustc_attr_ir/Cargo.toml +++ b/compiler/rustc_attr_ir/Cargo.toml @@ -14,7 +14,6 @@ rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } rustc_structures = { path = "../rustc_structures" } -rustc_target = { path = "../rustc_target" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } thin-vec = "0.2.18" tracing = "0.1" diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index 5de91cc8b7b23..35b5643ee3b1c 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -16,8 +16,7 @@ use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash}; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; -use rustc_structures::Limit; -pub use rustc_target::spec::SanitizerSet; +use rustc_structures::{Limit, SanitizerSet}; use thin_vec::ThinVec; pub use crate::canonical_symbols::{CanonicalSymbol, CanonicalSymbols}; diff --git a/compiler/rustc_attr_ir/src/pretty_printing.rs b/compiler/rustc_attr_ir/src/pretty_printing.rs index f130c2b0f4b0e..128b5301fffa6 100644 --- a/compiler/rustc_attr_ir/src/pretty_printing.rs +++ b/compiler/rustc_attr_ir/src/pretty_printing.rs @@ -14,8 +14,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; -use rustc_structures::Limit; -use rustc_target::spec::SanitizerSet; +use rustc_structures::{Limit, SanitizerSet}; use thin_vec::ThinVec; /// This trait is used to print attributes in `rustc_hir_pretty`. diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index feed600d44df4..ba845acc9e23c 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -1,9 +1,10 @@ use rustc_attr_ir::{ - CoverageAttrKind, InstrumentFnAttr, OptimizeAttr, RtsanSetting, SanitizerSet, UsedBy, find_attr, + CoverageAttrKind, InstrumentFnAttr, OptimizeAttr, RtsanSetting, UsedBy, find_attr, }; use rustc_feature::AttributeStability; use rustc_session::diagnostics::feature_err; use rustc_span::edition::Edition::Edition2024; +use rustc_structures::SanitizerSet; use super::prelude::*; use crate::attributes::AttributeSafety; diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index b325742325ef2..27c4062ddd941 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -36,6 +36,7 @@ rustc_middle = { path = "../rustc_middle" } rustc_sanitizers = { path = "../rustc_sanitizers" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_symbol_mangling = { path = "../rustc_symbol_mangling" } rustc_target = { path = "../rustc_target" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 4883eb1087be3..db111926ca671 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -18,10 +18,10 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::memmap::Mmap; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_errors::{DiagCtxt, DiagCtxtHandle}; -use rustc_hir::attrs::SanitizerSet; use rustc_middle::bug; use rustc_middle::dep_graph::WorkProduct; use rustc_session::config; +use rustc_structures::SanitizerSet; use tracing::{debug, info}; use crate::back::write::{ diff --git a/compiler/rustc_structures/Cargo.toml b/compiler/rustc_structures/Cargo.toml index 847efc4ceeb10..153a1d0e1f540 100644 --- a/compiler/rustc_structures/Cargo.toml +++ b/compiler/rustc_structures/Cargo.toml @@ -5,7 +5,10 @@ edition = "2024" [dependencies] # tidy-alphabetical-start +bitflags = "2.4.1" rustc_data_structures = { path = "../rustc_data_structures" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } +schemars = "1.0.4" +serde = "1.0.219" # tidy-alphabetical-end diff --git a/compiler/rustc_structures/src/lib.rs b/compiler/rustc_structures/src/lib.rs index 6e97f35f39a04..377b00669e467 100644 --- a/compiler/rustc_structures/src/lib.rs +++ b/compiler/rustc_structures/src/lib.rs @@ -1,3 +1,5 @@ mod limit; +mod sanitizer_set; pub use limit::Limit; +pub use sanitizer_set::SanitizerSet; diff --git a/compiler/rustc_structures/src/sanitizer_set.rs b/compiler/rustc_structures/src/sanitizer_set.rs new file mode 100644 index 0000000000000..b0aa4586ac54f --- /dev/null +++ b/compiler/rustc_structures/src/sanitizer_set.rs @@ -0,0 +1,166 @@ +use core::fmt; +use std::str::FromStr; + +use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash}; + +#[derive( + Default, + Clone, + Copy, + PartialEq, + Eq, + Hash, + Encodable_NoContext, + Decodable_NoContext, + StableHash +)] +pub struct SanitizerSet(u16); +bitflags::bitflags! { + impl SanitizerSet: u16 { + const ADDRESS = 1 << 0; + const LEAK = 1 << 1; + const MEMORY = 1 << 2; + const THREAD = 1 << 3; + const HWADDRESS = 1 << 4; + const CFI = 1 << 5; + const MEMTAG = 1 << 6; + const SHADOWCALLSTACK = 1 << 7; + const KCFI = 1 << 8; + const KERNELADDRESS = 1 << 9; + const KERNELHWADDRESS = 1 << 10; + const SAFESTACK = 1 << 11; + const DATAFLOW = 1 << 12; + const REALTIME = 1 << 13; + } +} +rustc_data_structures::external_bitflags_debug! { SanitizerSet } + +impl SanitizerSet { + // Taken from LLVM's sanitizer compatibility logic: + // https://github.com/llvm/llvm-project/blob/release/18.x/clang/lib/Driver/SanitizerArgs.cpp#L512 + const MUTUALLY_EXCLUSIVE: &'static [(SanitizerSet, SanitizerSet)] = &[ + (SanitizerSet::ADDRESS, SanitizerSet::MEMORY), + (SanitizerSet::ADDRESS, SanitizerSet::THREAD), + (SanitizerSet::ADDRESS, SanitizerSet::HWADDRESS), + (SanitizerSet::ADDRESS, SanitizerSet::MEMTAG), + (SanitizerSet::ADDRESS, SanitizerSet::KERNELADDRESS), + (SanitizerSet::ADDRESS, SanitizerSet::KERNELHWADDRESS), + (SanitizerSet::ADDRESS, SanitizerSet::SAFESTACK), + (SanitizerSet::LEAK, SanitizerSet::MEMORY), + (SanitizerSet::LEAK, SanitizerSet::THREAD), + (SanitizerSet::LEAK, SanitizerSet::KERNELADDRESS), + (SanitizerSet::LEAK, SanitizerSet::KERNELHWADDRESS), + (SanitizerSet::LEAK, SanitizerSet::SAFESTACK), + (SanitizerSet::MEMORY, SanitizerSet::THREAD), + (SanitizerSet::MEMORY, SanitizerSet::HWADDRESS), + (SanitizerSet::MEMORY, SanitizerSet::KERNELADDRESS), + (SanitizerSet::MEMORY, SanitizerSet::KERNELHWADDRESS), + (SanitizerSet::MEMORY, SanitizerSet::SAFESTACK), + (SanitizerSet::THREAD, SanitizerSet::HWADDRESS), + (SanitizerSet::THREAD, SanitizerSet::KERNELADDRESS), + (SanitizerSet::THREAD, SanitizerSet::KERNELHWADDRESS), + (SanitizerSet::THREAD, SanitizerSet::SAFESTACK), + (SanitizerSet::HWADDRESS, SanitizerSet::MEMTAG), + (SanitizerSet::HWADDRESS, SanitizerSet::KERNELADDRESS), + (SanitizerSet::HWADDRESS, SanitizerSet::KERNELHWADDRESS), + (SanitizerSet::HWADDRESS, SanitizerSet::SAFESTACK), + (SanitizerSet::CFI, SanitizerSet::KCFI), + (SanitizerSet::MEMTAG, SanitizerSet::KERNELADDRESS), + (SanitizerSet::MEMTAG, SanitizerSet::KERNELHWADDRESS), + (SanitizerSet::KERNELADDRESS, SanitizerSet::KERNELHWADDRESS), + (SanitizerSet::KERNELADDRESS, SanitizerSet::SAFESTACK), + (SanitizerSet::KERNELHWADDRESS, SanitizerSet::SAFESTACK), + ]; + + /// Return sanitizer's name + /// + /// Returns none if the flags is a set of sanitizers numbering not exactly one. + pub fn as_str(self) -> Option<&'static str> { + Some(match self { + SanitizerSet::ADDRESS => "address", + SanitizerSet::CFI => "cfi", + SanitizerSet::DATAFLOW => "dataflow", + SanitizerSet::KCFI => "kcfi", + SanitizerSet::KERNELADDRESS => "kernel-address", + SanitizerSet::KERNELHWADDRESS => "kernel-hwaddress", + SanitizerSet::LEAK => "leak", + SanitizerSet::MEMORY => "memory", + SanitizerSet::MEMTAG => "memtag", + SanitizerSet::SAFESTACK => "safestack", + SanitizerSet::SHADOWCALLSTACK => "shadow-call-stack", + SanitizerSet::THREAD => "thread", + SanitizerSet::HWADDRESS => "hwaddress", + SanitizerSet::REALTIME => "realtime", + _ => return None, + }) + } + + pub fn mutually_exclusive(self) -> Option<(SanitizerSet, SanitizerSet)> { + Self::MUTUALLY_EXCLUSIVE + .into_iter() + .find(|&(a, b)| self.contains(*a) && self.contains(*b)) + .copied() + } +} + +/// Formats a sanitizer set as a comma separated list of sanitizers' names. +impl fmt::Display for SanitizerSet { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut first = true; + for s in *self { + let name = s.as_str().unwrap_or_else(|| panic!("unrecognized sanitizer {s:?}")); + if !first { + f.write_str(", ")?; + } + f.write_str(name)?; + first = false; + } + Ok(()) + } +} + +impl FromStr for SanitizerSet { + type Err = String; + fn from_str(s: &str) -> Result { + Ok(match s { + "address" => SanitizerSet::ADDRESS, + "cfi" => SanitizerSet::CFI, + "dataflow" => SanitizerSet::DATAFLOW, + "kcfi" => SanitizerSet::KCFI, + "kernel-address" => SanitizerSet::KERNELADDRESS, + "kernel-hwaddress" => SanitizerSet::KERNELHWADDRESS, + "leak" => SanitizerSet::LEAK, + "memory" => SanitizerSet::MEMORY, + "memtag" => SanitizerSet::MEMTAG, + "safestack" => SanitizerSet::SAFESTACK, + "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK, + "thread" => SanitizerSet::THREAD, + "hwaddress" => SanitizerSet::HWADDRESS, + "realtime" => SanitizerSet::REALTIME, + s => return Err(format!("unknown sanitizer {s}")), + }) + } +} + +impl schemars::JsonSchema for SanitizerSet { + fn schema_name() -> std::borrow::Cow<'static, str> { + "SanitizerSet".into() + } + fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema { + let all = Self::all().iter().map(|sanitizer| sanitizer.as_str()).collect::>(); + schemars::json_schema! ({ + "type": "string", + "enum": all, + }) + } +} + +impl<'de> serde::Deserialize<'de> for SanitizerSet { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let s = String::deserialize(deserializer)?; + FromStr::from_str(&s).map_err(serde::de::Error::custom) + } +} diff --git a/compiler/rustc_target/Cargo.toml b/compiler/rustc_target/Cargo.toml index 33d40625323c3..af19aff21c116 100644 --- a/compiler/rustc_target/Cargo.toml +++ b/compiler/rustc_target/Cargo.toml @@ -15,6 +15,7 @@ rustc_fs_util = { path = "../rustc_fs_util" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } schemars = "1.0.4" serde = "1.0.219" serde_derive = "1.0.219" diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index ff6cade232523..0b952a3bf1c1c 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -41,7 +41,6 @@ use core::result::Result; use std::borrow::Cow; use std::collections::BTreeMap; -use std::fmt; use std::hash::Hash; use std::ops::{Deref, DerefMut}; use std::path::{Path, PathBuf}; @@ -73,6 +72,7 @@ pub use abi_map::{AbiMap, AbiMapping}; pub use base::apple; pub use base::avr::ef_avr_arch; pub use json::json_schema; +pub use rustc_structures::SanitizerSet; pub use tuple::TargetTuple; /// Linker is called through a C/C++ compiler. @@ -1148,149 +1148,6 @@ impl ToJson for StackProbeType { } } -#[derive(Default, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, StableHash)] -pub struct SanitizerSet(u16); -bitflags::bitflags! { - impl SanitizerSet: u16 { - const ADDRESS = 1 << 0; - const LEAK = 1 << 1; - const MEMORY = 1 << 2; - const THREAD = 1 << 3; - const HWADDRESS = 1 << 4; - const CFI = 1 << 5; - const MEMTAG = 1 << 6; - const SHADOWCALLSTACK = 1 << 7; - const KCFI = 1 << 8; - const KERNELADDRESS = 1 << 9; - const KERNELHWADDRESS = 1 << 10; - const SAFESTACK = 1 << 11; - const DATAFLOW = 1 << 12; - const REALTIME = 1 << 13; - } -} -rustc_data_structures::external_bitflags_debug! { SanitizerSet } - -impl SanitizerSet { - // Taken from LLVM's sanitizer compatibility logic: - // https://github.com/llvm/llvm-project/blob/release/18.x/clang/lib/Driver/SanitizerArgs.cpp#L512 - const MUTUALLY_EXCLUSIVE: &'static [(SanitizerSet, SanitizerSet)] = &[ - (SanitizerSet::ADDRESS, SanitizerSet::MEMORY), - (SanitizerSet::ADDRESS, SanitizerSet::THREAD), - (SanitizerSet::ADDRESS, SanitizerSet::HWADDRESS), - (SanitizerSet::ADDRESS, SanitizerSet::MEMTAG), - (SanitizerSet::ADDRESS, SanitizerSet::KERNELADDRESS), - (SanitizerSet::ADDRESS, SanitizerSet::KERNELHWADDRESS), - (SanitizerSet::ADDRESS, SanitizerSet::SAFESTACK), - (SanitizerSet::LEAK, SanitizerSet::MEMORY), - (SanitizerSet::LEAK, SanitizerSet::THREAD), - (SanitizerSet::LEAK, SanitizerSet::KERNELADDRESS), - (SanitizerSet::LEAK, SanitizerSet::KERNELHWADDRESS), - (SanitizerSet::LEAK, SanitizerSet::SAFESTACK), - (SanitizerSet::MEMORY, SanitizerSet::THREAD), - (SanitizerSet::MEMORY, SanitizerSet::HWADDRESS), - (SanitizerSet::MEMORY, SanitizerSet::KERNELADDRESS), - (SanitizerSet::MEMORY, SanitizerSet::KERNELHWADDRESS), - (SanitizerSet::MEMORY, SanitizerSet::SAFESTACK), - (SanitizerSet::THREAD, SanitizerSet::HWADDRESS), - (SanitizerSet::THREAD, SanitizerSet::KERNELADDRESS), - (SanitizerSet::THREAD, SanitizerSet::KERNELHWADDRESS), - (SanitizerSet::THREAD, SanitizerSet::SAFESTACK), - (SanitizerSet::HWADDRESS, SanitizerSet::MEMTAG), - (SanitizerSet::HWADDRESS, SanitizerSet::KERNELADDRESS), - (SanitizerSet::HWADDRESS, SanitizerSet::KERNELHWADDRESS), - (SanitizerSet::HWADDRESS, SanitizerSet::SAFESTACK), - (SanitizerSet::CFI, SanitizerSet::KCFI), - (SanitizerSet::MEMTAG, SanitizerSet::KERNELADDRESS), - (SanitizerSet::MEMTAG, SanitizerSet::KERNELHWADDRESS), - (SanitizerSet::KERNELADDRESS, SanitizerSet::KERNELHWADDRESS), - (SanitizerSet::KERNELADDRESS, SanitizerSet::SAFESTACK), - (SanitizerSet::KERNELHWADDRESS, SanitizerSet::SAFESTACK), - ]; - - /// Return sanitizer's name - /// - /// Returns none if the flags is a set of sanitizers numbering not exactly one. - pub fn as_str(self) -> Option<&'static str> { - Some(match self { - SanitizerSet::ADDRESS => "address", - SanitizerSet::CFI => "cfi", - SanitizerSet::DATAFLOW => "dataflow", - SanitizerSet::KCFI => "kcfi", - SanitizerSet::KERNELADDRESS => "kernel-address", - SanitizerSet::KERNELHWADDRESS => "kernel-hwaddress", - SanitizerSet::LEAK => "leak", - SanitizerSet::MEMORY => "memory", - SanitizerSet::MEMTAG => "memtag", - SanitizerSet::SAFESTACK => "safestack", - SanitizerSet::SHADOWCALLSTACK => "shadow-call-stack", - SanitizerSet::THREAD => "thread", - SanitizerSet::HWADDRESS => "hwaddress", - SanitizerSet::REALTIME => "realtime", - _ => return None, - }) - } - - pub fn mutually_exclusive(self) -> Option<(SanitizerSet, SanitizerSet)> { - Self::MUTUALLY_EXCLUSIVE - .into_iter() - .find(|&(a, b)| self.contains(*a) && self.contains(*b)) - .copied() - } -} - -/// Formats a sanitizer set as a comma separated list of sanitizers' names. -impl fmt::Display for SanitizerSet { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut first = true; - for s in *self { - let name = s.as_str().unwrap_or_else(|| panic!("unrecognized sanitizer {s:?}")); - if !first { - f.write_str(", ")?; - } - f.write_str(name)?; - first = false; - } - Ok(()) - } -} - -impl FromStr for SanitizerSet { - type Err = String; - fn from_str(s: &str) -> Result { - Ok(match s { - "address" => SanitizerSet::ADDRESS, - "cfi" => SanitizerSet::CFI, - "dataflow" => SanitizerSet::DATAFLOW, - "kcfi" => SanitizerSet::KCFI, - "kernel-address" => SanitizerSet::KERNELADDRESS, - "kernel-hwaddress" => SanitizerSet::KERNELHWADDRESS, - "leak" => SanitizerSet::LEAK, - "memory" => SanitizerSet::MEMORY, - "memtag" => SanitizerSet::MEMTAG, - "safestack" => SanitizerSet::SAFESTACK, - "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK, - "thread" => SanitizerSet::THREAD, - "hwaddress" => SanitizerSet::HWADDRESS, - "realtime" => SanitizerSet::REALTIME, - s => return Err(format!("unknown sanitizer {s}")), - }) - } -} - -crate::json::serde_deserialize_from_str!(SanitizerSet); -impl schemars::JsonSchema for SanitizerSet { - fn schema_name() -> std::borrow::Cow<'static, str> { - "SanitizerSet".into() - } - fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema { - let all = Self::all().iter().map(|sanitizer| sanitizer.as_str()).collect::>(); - schemars::json_schema! ({ - "type": "string", - "enum": all, - }) - } -} - impl ToJson for SanitizerSet { fn to_json(&self) -> Json { self.into_iter() From 29dba3e3263becdbb850675d58cf1a10c1e8adc8 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 15:07:30 +0200 Subject: [PATCH 20/34] make nightly feature --- compiler/rustc_structures/Cargo.toml | 16 +++++++++++++--- compiler/rustc_structures/src/lib.rs | 2 ++ compiler/rustc_structures/src/limit.rs | 4 +++- compiler/rustc_structures/src/sanitizer_set.rs | 16 +++++----------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_structures/Cargo.toml b/compiler/rustc_structures/Cargo.toml index 153a1d0e1f540..565d7d4df8b54 100644 --- a/compiler/rustc_structures/Cargo.toml +++ b/compiler/rustc_structures/Cargo.toml @@ -6,9 +6,19 @@ edition = "2024" [dependencies] # tidy-alphabetical-start bitflags = "2.4.1" -rustc_data_structures = { path = "../rustc_data_structures" } -rustc_macros = { path = "../rustc_macros" } -rustc_serialize = { path = "../rustc_serialize" } +rustc_data_structures = { path = "../rustc_data_structures", optional = true } +rustc_macros = { path = "../rustc_macros", optional = true } +rustc_serialize = { path = "../rustc_serialize", optional = true } schemars = "1.0.4" serde = "1.0.219" # tidy-alphabetical-end + +[features] +# tidy-alphabetical-start +default = ["nightly"] +nightly = [ + "dep:rustc_data_structures", + "dep:rustc_macros", + "dep:rustc_serialize", +] +# tidy-alphabetical-end diff --git a/compiler/rustc_structures/src/lib.rs b/compiler/rustc_structures/src/lib.rs index 377b00669e467..4ac98fde5f7b9 100644 --- a/compiler/rustc_structures/src/lib.rs +++ b/compiler/rustc_structures/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(unstable_features)] + mod limit; mod sanitizer_set; diff --git a/compiler/rustc_structures/src/limit.rs b/compiler/rustc_structures/src/limit.rs index ee1588d5112ed..c7a9b25994767 100644 --- a/compiler/rustc_structures/src/limit.rs +++ b/compiler/rustc_structures/src/limit.rs @@ -1,11 +1,13 @@ use std::fmt; use std::ops::{Div, Mul}; +#[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash}; /// New-type wrapper around `usize` for representing limits. Ensures that comparisons against /// limits are consistent throughout the compiler. -#[derive(Clone, Copy, Debug, StableHash, Encodable_NoContext, Decodable_NoContext)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr(feature = "nightly", derive(StableHash, Encodable_NoContext, Decodable_NoContext))] pub struct Limit(pub usize); impl Limit { diff --git a/compiler/rustc_structures/src/sanitizer_set.rs b/compiler/rustc_structures/src/sanitizer_set.rs index b0aa4586ac54f..bce77f3abc05b 100644 --- a/compiler/rustc_structures/src/sanitizer_set.rs +++ b/compiler/rustc_structures/src/sanitizer_set.rs @@ -1,19 +1,11 @@ use core::fmt; use std::str::FromStr; +#[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash}; -#[derive( - Default, - Clone, - Copy, - PartialEq, - Eq, - Hash, - Encodable_NoContext, - Decodable_NoContext, - StableHash -)] +#[derive(Default, Clone, Copy, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, StableHash))] pub struct SanitizerSet(u16); bitflags::bitflags! { impl SanitizerSet: u16 { @@ -33,6 +25,8 @@ bitflags::bitflags! { const REALTIME = 1 << 13; } } + +#[cfg(feature = "nightly")] rustc_data_structures::external_bitflags_debug! { SanitizerSet } impl SanitizerSet { From f713bb2185d2ebc5d808a0d53dc08d612c312612 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 16:29:47 +0200 Subject: [PATCH 21/34] invert dependency on rustc_error_messages --- Cargo.lock | 2 +- compiler/rustc_error_messages/Cargo.toml | 1 - compiler/rustc_error_messages/src/diagnostic_impls.rs | 7 ------- compiler/rustc_structures/Cargo.toml | 2 ++ compiler/rustc_structures/src/limit.rs | 10 ++++++++++ 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fb38fff0c4ad9..e1b1af9ce4543 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3976,7 +3976,6 @@ dependencies = [ "rustc_macros", "rustc_serialize", "rustc_span", - "rustc_structures", "unic-langid", ] @@ -4788,6 +4787,7 @@ version = "0.0.0" dependencies = [ "bitflags", "rustc_data_structures", + "rustc_error_messages", "rustc_macros", "rustc_serialize", "schemars", diff --git a/compiler/rustc_error_messages/Cargo.toml b/compiler/rustc_error_messages/Cargo.toml index f4f2862c2db9d..50f0b265527fe 100644 --- a/compiler/rustc_error_messages/Cargo.toml +++ b/compiler/rustc_error_messages/Cargo.toml @@ -14,6 +14,5 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } -rustc_structures = { path = "../rustc_structures" } unic-langid = { version = "0.9.0", features = ["macros"] } # tidy-alphabetical-end diff --git a/compiler/rustc_error_messages/src/diagnostic_impls.rs b/compiler/rustc_error_messages/src/diagnostic_impls.rs index 0c6443bf12fe8..38b086eaa80d3 100644 --- a/compiler/rustc_error_messages/src/diagnostic_impls.rs +++ b/compiler/rustc_error_messages/src/diagnostic_impls.rs @@ -6,7 +6,6 @@ use std::path::{Path, PathBuf}; use std::process::ExitStatus; use rustc_span::edition::Edition; -use rustc_structures::Limit; use crate::{DiagArgValue, IntoDiagArg}; @@ -157,9 +156,3 @@ impl IntoDiagArg for Backtrace { DiagArgValue::Str(Cow::from(self.to_string())) } } - -impl IntoDiagArg for Limit { - fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { - self.0.into_diag_arg(&mut None) - } -} diff --git a/compiler/rustc_structures/Cargo.toml b/compiler/rustc_structures/Cargo.toml index 565d7d4df8b54..438277828eec4 100644 --- a/compiler/rustc_structures/Cargo.toml +++ b/compiler/rustc_structures/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" # tidy-alphabetical-start bitflags = "2.4.1" rustc_data_structures = { path = "../rustc_data_structures", optional = true } +rustc_error_messages = { path = "../rustc_error_messages", optional = true } rustc_macros = { path = "../rustc_macros", optional = true } rustc_serialize = { path = "../rustc_serialize", optional = true } schemars = "1.0.4" @@ -18,6 +19,7 @@ serde = "1.0.219" default = ["nightly"] nightly = [ "dep:rustc_data_structures", + "dep:rustc_error_messages", "dep:rustc_macros", "dep:rustc_serialize", ] diff --git a/compiler/rustc_structures/src/limit.rs b/compiler/rustc_structures/src/limit.rs index c7a9b25994767..ade348523bce7 100644 --- a/compiler/rustc_structures/src/limit.rs +++ b/compiler/rustc_structures/src/limit.rs @@ -56,3 +56,13 @@ impl Mul for Limit { Limit::new(self.0 * rhs) } } + +#[cfg(feature = "nightly")] +impl rustc_error_messages::IntoDiagArg for Limit { + fn into_diag_arg( + self, + _: &mut Option, + ) -> rustc_error_messages::DiagArgValue { + self.0.into_diag_arg(&mut None) + } +} From 38af4a23c2089675be2a060e9de1308a840f4460 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 17:59:33 +0200 Subject: [PATCH 22/34] move CrateType --- Cargo.lock | 7 ++ compiler/rustc_attr_ir/src/data_structures.rs | 104 +--------------- compiler/rustc_attr_ir/src/pretty_printing.rs | 3 +- .../src/attributes/crate_level.rs | 3 +- .../rustc_codegen_cranelift/src/driver/jit.rs | 4 +- compiler/rustc_codegen_llvm/src/context.rs | 3 +- .../rustc_codegen_llvm/src/debuginfo/gdb.rs | 3 +- compiler/rustc_codegen_llvm/src/intrinsic.rs | 2 +- compiler/rustc_codegen_llvm/src/mono_item.rs | 2 +- compiler/rustc_codegen_ssa/Cargo.toml | 1 + compiler/rustc_codegen_ssa/src/back/link.rs | 5 +- compiler/rustc_codegen_ssa/src/back/linker.rs | 3 +- compiler/rustc_codegen_ssa/src/back/lto.rs | 3 +- .../src/back/symbol_export.rs | 2 +- compiler/rustc_codegen_ssa/src/back/write.rs | 4 +- compiler/rustc_codegen_ssa/src/base.rs | 3 +- compiler/rustc_codegen_ssa/src/lib.rs | 3 +- .../rustc_codegen_ssa/src/traits/backend.rs | 3 +- compiler/rustc_driver_impl/Cargo.toml | 1 + compiler/rustc_driver_impl/src/lib.rs | 3 +- compiler/rustc_interface/src/diagnostics.rs | 2 +- compiler/rustc_interface/src/passes.rs | 6 +- compiler/rustc_interface/src/util.rs | 3 +- compiler/rustc_lint/Cargo.toml | 1 + compiler/rustc_lint/src/nonstandard_style.rs | 2 +- compiler/rustc_metadata/Cargo.toml | 1 + compiler/rustc_metadata/src/creader.rs | 4 +- .../rustc_metadata/src/dependency_format.rs | 2 +- compiler/rustc_metadata/src/fs.rs | 3 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 3 +- .../src/middle/dependency_format.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 3 +- compiler/rustc_passes/Cargo.toml | 1 + compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_passes/src/check_export.rs | 2 +- compiler/rustc_passes/src/dead.rs | 2 +- compiler/rustc_passes/src/eii.rs | 2 +- compiler/rustc_passes/src/entry.rs | 3 +- compiler/rustc_passes/src/lang_items.rs | 2 +- compiler/rustc_passes/src/reachable.rs | 2 +- compiler/rustc_passes/src/weak_lang_items.rs | 2 +- compiler/rustc_resolve/Cargo.toml | 1 + compiler/rustc_resolve/src/late.rs | 3 +- compiler/rustc_resolve/src/lib.rs | 2 +- compiler/rustc_session/src/config.rs | 3 +- compiler/rustc_session/src/options.rs | 1 + compiler/rustc_session/src/output.rs | 3 +- compiler/rustc_session/src/session.rs | 4 +- compiler/rustc_structures/Cargo.toml | 2 + compiler/rustc_structures/src/crate_type.rs | 114 ++++++++++++++++++ compiler/rustc_structures/src/lib.rs | 2 + 51 files changed, 196 insertions(+), 151 deletions(-) create mode 100644 compiler/rustc_structures/src/crate_type.rs diff --git a/Cargo.lock b/Cargo.lock index e1b1af9ce4543..5fcd934635486 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3826,6 +3826,7 @@ dependencies = [ "rustc_serialize", "rustc_session", "rustc_span", + "rustc_structures", "rustc_symbol_mangling", "rustc_target", "rustc_trait_selection", @@ -3952,6 +3953,7 @@ dependencies = [ "rustc_resolve", "rustc_session", "rustc_span", + "rustc_structures", "rustc_target", "serde_json", "shlex", @@ -4298,6 +4300,7 @@ dependencies = [ "rustc_parse_format", "rustc_session", "rustc_span", + "rustc_structures", "rustc_symbol_mangling", "rustc_target", "rustc_trait_selection", @@ -4379,6 +4382,7 @@ dependencies = [ "rustc_serialize", "rustc_session", "rustc_span", + "rustc_structures", "rustc_target", "tempfile", "tracing", @@ -4580,6 +4584,7 @@ dependencies = [ "rustc_privacy", "rustc_session", "rustc_span", + "rustc_structures", "rustc_target", "rustc_trait_selection", "tracing", @@ -4700,6 +4705,7 @@ dependencies = [ "rustc_middle", "rustc_session", "rustc_span", + "rustc_structures", "smallvec", "thin-vec", "tracing", @@ -4790,6 +4796,7 @@ dependencies = [ "rustc_error_messages", "rustc_macros", "rustc_serialize", + "rustc_span", "schemars", "serde", ] diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index 35b5643ee3b1c..cd95d5ce0c8af 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -16,7 +16,7 @@ use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash}; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; -use rustc_structures::{Limit, SanitizerSet}; +use rustc_structures::{CrateType, Limit, SanitizerSet}; use thin_vec::ThinVec; pub use crate::canonical_symbols::{CanonicalSymbol, CanonicalSymbols}; @@ -691,108 +691,6 @@ pub enum CollapseMacroDebuginfo { Yes = 3, } -/// Crate type, as specified by `#![crate_type]` -#[derive(Copy, Clone, Debug, Hash, PartialEq, Default, PartialOrd, Eq, Ord)] -#[derive(StableHash, Encodable, Decodable, PrintAttribute)] -pub enum CrateType { - /// `#![crate_type = "bin"]` - Executable, - /// `#![crate_type = "dylib"]` - Dylib, - /// `#![crate_type = "rlib"]` or `#![crate_type = "lib"]` - #[default] - Rlib, - /// `#![crate_type = "staticlib"]` - StaticLib, - /// `#![crate_type = "cdylib"]` - Cdylib, - /// `#![crate_type = "proc-macro"]` - ProcMacro, - /// `#![crate_type = "sdylib"]` - // Unstable; feature(export_stable) - Sdylib, -} - -impl CrateType { - /// Pairs of each `#[crate_type] = "..."` value and the crate type it resolves to - pub fn all() -> &'static [(Symbol, Self)] { - debug_assert_eq!(CrateType::default(), CrateType::Rlib); - &[ - (rustc_span::sym::lib, CrateType::Rlib), - (rustc_span::sym::rlib, CrateType::Rlib), - (rustc_span::sym::dylib, CrateType::Dylib), - (rustc_span::sym::cdylib, CrateType::Cdylib), - (rustc_span::sym::staticlib, CrateType::StaticLib), - (rustc_span::sym::proc_dash_macro, CrateType::ProcMacro), - (rustc_span::sym::bin, CrateType::Executable), - (rustc_span::sym::sdylib, CrateType::Sdylib), - ] - } - - /// Same as [`CrateType::all`], but does not include unstable options. - /// Used for diagnostics. - pub fn all_stable() -> &'static [(Symbol, Self)] { - debug_assert_eq!(CrateType::default(), CrateType::Rlib); - &[ - (rustc_span::sym::lib, CrateType::Rlib), - (rustc_span::sym::rlib, CrateType::Rlib), - (rustc_span::sym::dylib, CrateType::Dylib), - (rustc_span::sym::cdylib, CrateType::Cdylib), - (rustc_span::sym::staticlib, CrateType::StaticLib), - (rustc_span::sym::proc_dash_macro, CrateType::ProcMacro), - (rustc_span::sym::bin, CrateType::Executable), - ] - } - - pub fn has_metadata(self) -> bool { - match self { - CrateType::Rlib | CrateType::Dylib | CrateType::ProcMacro => true, - CrateType::Executable - | CrateType::Cdylib - | CrateType::StaticLib - | CrateType::Sdylib => false, - } - } -} - -impl TryFrom for CrateType { - type Error = (); - - fn try_from(value: Symbol) -> Result { - Ok(match value { - rustc_span::sym::bin => CrateType::Executable, - rustc_span::sym::dylib => CrateType::Dylib, - rustc_span::sym::staticlib => CrateType::StaticLib, - rustc_span::sym::cdylib => CrateType::Cdylib, - rustc_span::sym::rlib => CrateType::Rlib, - rustc_span::sym::lib => CrateType::default(), - rustc_span::sym::proc_dash_macro => CrateType::ProcMacro, - rustc_span::sym::sdylib => CrateType::Sdylib, - _ => return Err(()), - }) - } -} - -impl std::fmt::Display for CrateType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match *self { - CrateType::Executable => "bin".fmt(f), - CrateType::Dylib => "dylib".fmt(f), - CrateType::Rlib => "rlib".fmt(f), - CrateType::StaticLib => "staticlib".fmt(f), - CrateType::Cdylib => "cdylib".fmt(f), - CrateType::ProcMacro => "proc-macro".fmt(f), - CrateType::Sdylib => "sdylib".fmt(f), - } - } -} - -impl IntoDiagArg for CrateType { - fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { - self.to_string().into_diag_arg(&mut None) - } -} - #[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)] pub enum RustcDumpLayoutKind { Align, diff --git a/compiler/rustc_attr_ir/src/pretty_printing.rs b/compiler/rustc_attr_ir/src/pretty_printing.rs index 128b5301fffa6..7abcd4c23e397 100644 --- a/compiler/rustc_attr_ir/src/pretty_printing.rs +++ b/compiler/rustc_attr_ir/src/pretty_printing.rs @@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; -use rustc_structures::{Limit, SanitizerSet}; +use rustc_structures::{CrateType, Limit, SanitizerSet}; use thin_vec::ThinVec; /// This trait is used to print attributes in `rustc_hir_pretty`. @@ -207,4 +207,5 @@ print_debug!( CfgEntry, DiffActivity, DiffMode, + CrateType, ); diff --git a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs index 571750bf142a8..3a1c7858f030b 100644 --- a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs +++ b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs @@ -1,9 +1,10 @@ -use rustc_attr_ir::{CrateType, WindowsSubsystemKind}; +use rustc_attr_ir::WindowsSubsystemKind; use rustc_data_structures::fx::FxIndexSet; use rustc_feature::AttributeStability; use rustc_lint_defs::builtin::{DUPLICATE_TOOLS, UNKNOWN_CRATE_TYPES}; use rustc_span::Symbol; use rustc_span::edit_distance::find_best_match_for_name_with_substrings; +use rustc_structures::CrateType; use super::prelude::*; use crate::diagnostics::{ diff --git a/compiler/rustc_codegen_cranelift/src/driver/jit.rs b/compiler/rustc_codegen_cranelift/src/driver/jit.rs index 32f60615844bc..8bf1cd9bf85bc 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/jit.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/jit.rs @@ -37,7 +37,7 @@ fn create_jit_module( } pub(crate) fn run_jit(tcx: TyCtxt<'_>, target_cpu: String, jit_args: Vec) -> ! { - if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) { + if !tcx.crate_types().contains(&rustc_structures::CrateType::Executable) { tcx.dcx().fatal("can't jit non-executable crate"); } @@ -180,7 +180,7 @@ fn dep_symbol_lookup_fn( let mut dylib_paths = Vec::new(); - let data = &crate_info.dependency_formats[&rustc_session::config::CrateType::Executable]; + let data = &crate_info.dependency_formats[&rustc_structures::CrateType::Executable]; // `used_crates` is in reverse postorder in terms of dependencies. Reverse the order here to // get a postorder which ensures that all dependencies of a dylib are loaded before the dylib // itself. This helps the dynamic linker to find dylibs not in the regular dynamic library diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 668072ff082ec..a51ccd10aa366 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -21,10 +21,11 @@ use rustc_middle::ty::layout::{ use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_session::config::{ - BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, FunctionReturn, PAuthKey, PacRet, + BranchProtection, CFGuard, CFProtection, DebugInfo, FunctionReturn, PAuthKey, PacRet, }; use rustc_session::{PointerAuthSchema, Session}; use rustc_span::{DUMMY_SP, Span, Spanned, Symbol, sym}; +use rustc_structures::CrateType; use rustc_target::spec::{ Arch, CfgAbi, Env, FramePointer, HasTargetSpec, Os, RelocModel, SmallDataThresholdSupport, Target, TlsModel, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs index f5b843b4e3e74..dbf877077cb49 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs @@ -6,7 +6,8 @@ use rustc_codegen_ssa::traits::*; use rustc_hir::attrs::DebuggerVisualizerType; use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::bug; -use rustc_session::config::{CrateType, DebugInfo}; +use rustc_session::config::DebugInfo; +use rustc_structures::CrateType; use crate::builder::Builder; use crate::common::CodegenCx; diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 2bf31a4330ddf..0890b18a10cfa 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -23,9 +23,9 @@ use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf}; use rustc_middle::ty::offload_meta::OffloadMetadata; use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv}; use rustc_middle::{bug, span_bug}; -use rustc_session::config::CrateType; use rustc_session::diagnostics::feature_err; use rustc_span::{ErrorGuaranteed, Span, Symbol, sym}; +use rustc_structures::CrateType; use rustc_symbol_mangling::{ mangle_internal_symbol, mangle_offload_export, symbol_name_for_instance_in_crate, }; diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index 19d43797a875d..d67156c6cfa39 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -11,7 +11,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::mono::Visibility; use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv, LayoutOf}; use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt}; -use rustc_session::config::CrateType; +use rustc_structures::CrateType; use rustc_target::callconv::{FnAbi, PassMode}; use rustc_target::spec::{Arch, RelocModel}; use tracing::debug; diff --git a/compiler/rustc_codegen_ssa/Cargo.toml b/compiler/rustc_codegen_ssa/Cargo.toml index ab4ab9c80319b..a1306143a680a 100644 --- a/compiler/rustc_codegen_ssa/Cargo.toml +++ b/compiler/rustc_codegen_ssa/Cargo.toml @@ -32,6 +32,7 @@ rustc_mir_transform = { path = "../rustc_mir_transform" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_symbol_mangling = { path = "../rustc_symbol_mangling" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index f14d58c24f316..a5288d339cfc3 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -34,8 +34,8 @@ use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile; use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::exported_symbols::SymbolExportKind; use rustc_session::config::{ - self, CFGuard, CrateType, DebugInfo, InstrumentMcount, LinkerFeaturesCli, LinkerJobs, - OutFileName, OutputFilenames, OutputType, PrintKind, SplitDwarfKind, Strip, + self, CFGuard, DebugInfo, InstrumentMcount, LinkerFeaturesCli, LinkerJobs, OutFileName, + OutputFilenames, OutputType, PrintKind, SplitDwarfKind, Strip, }; use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename}; use rustc_session::search_paths::PathKind; @@ -43,6 +43,7 @@ use rustc_session::search_paths::PathKind; /// need out of the shared crate context before we get rid of it. use rustc_session::{Session, filesearch}; use rustc_span::Symbol; +use rustc_structures::CrateType; use rustc_target::spec::crt_objects::CrtObjects; use rustc_target::spec::{ Arch, BinaryFormat, Cc, CfgAbi, Env, LinkOutputKind, LinkSelfContainedComponents, diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 40e2f60ca6442..15f0c450f55f8 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -14,7 +14,8 @@ use rustc_middle::middle::exported_symbols::{ }; use rustc_middle::ty::{SymbolName, TyCtxt}; use rustc_session::Session; -use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip}; +use rustc_session::config::{self, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip}; +use rustc_structures::CrateType; use rustc_target::spec::{Arch, Cc, CfgAbi, LinkOutputKind, LinkerFlavor, Lld, Os}; use tracing::{debug, warn}; diff --git a/compiler/rustc_codegen_ssa/src/back/lto.rs b/compiler/rustc_codegen_ssa/src/back/lto.rs index 0b33c1db8e5dc..31fae5b4f96b0 100644 --- a/compiler/rustc_codegen_ssa/src/back/lto.rs +++ b/compiler/rustc_codegen_ssa/src/back/lto.rs @@ -8,7 +8,8 @@ use rustc_errors::DiagCtxtHandle; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportLevel}; use rustc_middle::ty::TyCtxt; -use rustc_session::config::{CrateType, Lto}; +use rustc_session::config::Lto; +use rustc_structures::CrateType; use tracing::info; use crate::back::symbol_export::{self, allocator_shim_symbols, symbol_name_for_instance_in_crate}; diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index cc102c636f4ae..f30ba43b0b0ba 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -18,8 +18,8 @@ use rustc_middle::ty::{ self, GenericArgKind, GenericArgsRef, Instance, ShimKind, SymbolName, Ty, TyCtxt, }; use rustc_middle::util::Providers; -use rustc_session::config::CrateType; use rustc_span::Span; +use rustc_structures::CrateType; use rustc_symbol_mangling::{is_offload_kernel, mangle_internal_symbol}; use rustc_target::spec::{Arch, Os, TlsModel}; use tracing::debug; diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 691ac892aa39a..78cdd3e38f68c 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -23,12 +23,12 @@ use rustc_middle::bug; use rustc_middle::dep_graph::{WorkProduct, WorkProductMap}; use rustc_middle::ty::TyCtxt; use rustc_session::config::{ - self, CrateType, Lto, OptLevel, OutFileName, OutputFilenames, OutputType, Passes, - SwitchWithOptPath, + self, Lto, OptLevel, OutFileName, OutputFilenames, OutputType, Passes, SwitchWithOptPath, }; use rustc_session::{IncrCompSession, Session}; use rustc_span::source_map::SourceMap; use rustc_span::{FileName, InnerSpan, Span, SpanData}; +use rustc_structures::CrateType; use rustc_target::spec::{MergeFunctions, SanitizerSet}; use tracing::debug; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 0468e3de18d8b..9eb4fd510fd7f 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -30,8 +30,9 @@ use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout}; use rustc_middle::ty::{self, Instance, PatternKind, Ty, TyCtxt, UintTy, Unnormalized}; use rustc_middle::{bug, span_bug}; use rustc_session::Session; -use rustc_session::config::{self, CrateType, EntryFnType}; +use rustc_session::config::{self, EntryFnType}; use rustc_span::{DUMMY_SP, Symbol}; +use rustc_structures::CrateType; use rustc_symbol_mangling::mangle_internal_symbol; use rustc_target::spec::{Arch, Os}; use rustc_trait_selection::infer::{BoundRegionConversionTime, TyCtxtInferExt}; diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index edf06c4023e2f..23cb46d5a6634 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -37,8 +37,9 @@ use rustc_middle::util::Providers; use rustc_serialize::opaque::{FileEncoder, MemDecoder}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_session::Session; -use rustc_session::config::{CrateType, OutputFilenames, OutputType}; +use rustc_session::config::{OutputFilenames, OutputType}; use rustc_span::{Span, Symbol}; +use rustc_structures::CrateType; pub mod assert_module_sources; pub mod back; diff --git a/compiler/rustc_codegen_ssa/src/traits/backend.rs b/compiler/rustc_codegen_ssa/src/traits/backend.rs index 36f4d858d0be5..11878c1f5165d 100644 --- a/compiler/rustc_codegen_ssa/src/traits/backend.rs +++ b/compiler/rustc_codegen_ssa/src/traits/backend.rs @@ -8,9 +8,10 @@ use rustc_metadata::creader::MetadataLoaderDyn; use rustc_middle::dep_graph::WorkProductMap; use rustc_middle::ty::TyCtxt; use rustc_middle::util::Providers; -use rustc_session::config::{CrateType, OutputFilenames, PrintRequest}; +use rustc_session::config::{OutputFilenames, PrintRequest}; use rustc_session::{IncrCompSession, Session}; use rustc_span::Symbol; +use rustc_structures::CrateType; use super::CodegenObject; use crate::back::archive::ArArchiveBuilderBuilder; diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index 04a30933a4276..6dba3dff47327 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -34,6 +34,7 @@ rustc_public = { path = "../rustc_public", features = ["rustc_internal"] } rustc_resolve = { path = "../rustc_resolve" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } serde_json = "1.0.59" shlex = "1.0" diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 3f975e1d16bf5..8155632583d26 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -52,7 +52,7 @@ use rustc_middle::ty::TyCtxt; use rustc_parse::lexer::StripTokens; use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal}; use rustc_session::config::{ - CG_OPTIONS, CrateType, ErrorOutputType, Input, OptionDesc, OutFileName, OutputType, Sysroot, + CG_OPTIONS, ErrorOutputType, Input, OptionDesc, OutFileName, OutputType, Sysroot, UnstableOptions, Z_OPTIONS, nightly_options, parse_target_triple, }; use rustc_session::getopts::{self, Matches}; @@ -60,6 +60,7 @@ use rustc_session::output::invalid_output_for_target; use rustc_session::{EarlyDiagCtxt, Session, config}; use rustc_span::def_id::LOCAL_CRATE; use rustc_span::{DUMMY_SP, FileName}; +use rustc_structures::CrateType; use rustc_target::json::ToJson; use rustc_target::spec::{Target, TargetTuple}; use tracing::trace; diff --git a/compiler/rustc_interface/src/diagnostics.rs b/compiler/rustc_interface/src/diagnostics.rs index 9e6d4317c98e5..2a2757f814715 100644 --- a/compiler/rustc_interface/src/diagnostics.rs +++ b/compiler/rustc_interface/src/diagnostics.rs @@ -1,9 +1,9 @@ use std::io; use std::path::Path; -use rustc_hir::attrs::CrateType; use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; +use rustc_structures::CrateType; use rustc_target::spec::TargetTuple; #[derive(Diagnostic)] diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 35fb9102eb265..c829864b02288 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -36,7 +36,7 @@ use rustc_parse::lexer::StripTokens; use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal}; use rustc_passes::{abi_test, input_stats, layout_test}; use rustc_resolve::{Resolver, ResolverOutputs}; -use rustc_session::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType}; +use rustc_session::config::{Input, OutFileName, OutputFilenames, OutputType}; use rustc_session::diagnostics::feature_err; use rustc_session::output::{filename_for_input, invalid_output_for_target}; use rustc_session::search_paths::PathKind; @@ -44,7 +44,7 @@ use rustc_session::{IncrCompSession, Session}; use rustc_span::{ DUMMY_SP, ErrorGuaranteed, ExpnKind, SourceFileHash, SourceFileHashAlgorithm, Span, Symbol, sym, }; -use rustc_structures::Limit; +use rustc_structures::{CrateType, Limit}; use rustc_trait_selection::{solve, traits}; use tracing::{info, instrument}; @@ -876,7 +876,7 @@ pub fn write_dep_info(tcx: TyCtxt<'_>) { } pub fn write_interface<'tcx>(tcx: TyCtxt<'tcx>) { - if !tcx.crate_types().contains(&rustc_session::config::CrateType::Sdylib) { + if !tcx.crate_types().contains(&rustc_structures::CrateType::Sdylib) { return; } let _timer = tcx.sess.timer("write_interface"); diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 23b152bd57240..89907447571ee 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -22,12 +22,13 @@ use rustc_middle::dep_graph::WorkProductMap; use rustc_middle::ty::{CurrentGcx, TyCtxt}; use rustc_query_impl::{CollectActiveJobsKind, collect_active_query_jobs}; use rustc_session::config::{ - Cfg, CrateType, Jobs, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple, + Cfg, Jobs, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple, }; use rustc_session::{EarlyDiagCtxt, IncrCompSession, Session, filesearch}; use rustc_span::edition::Edition; use rustc_span::source_map::SourceMapInputs; use rustc_span::{SessionGlobals, Symbol, sym}; +use rustc_structures::CrateType; use rustc_target::spec::Target; use tracing::info; diff --git a/compiler/rustc_lint/Cargo.toml b/compiler/rustc_lint/Cargo.toml index 5d575dc7c1641..a672f242449e4 100644 --- a/compiler/rustc_lint/Cargo.toml +++ b/compiler/rustc_lint/Cargo.toml @@ -23,6 +23,7 @@ rustc_middle = { path = "../rustc_middle" } rustc_parse_format = { path = "../rustc_parse_format" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_symbol_mangling = { path = "../rustc_symbol_mangling" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index 30c65a504d8d7..45f34e6a6e3c1 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -11,9 +11,9 @@ use rustc_hir::{Attribute, GenericParamKind, PatExprKind, PatKind, find_attr}; use rustc_lint_defs::{declare_lint, declare_lint_pass}; use rustc_middle::hir::nested_filter::All; use rustc_middle::ty::AssocContainer; -use rustc_session::config::CrateType; use rustc_span::def_id::LocalDefId; use rustc_span::{BytePos, Ident, Span, sym}; +use rustc_structures::CrateType; use crate::diagnostics::{ NonCamelCaseType, NonCamelCaseTypeSub, NonSnakeCaseDiag, NonSnakeCaseDiagSub, diff --git a/compiler/rustc_metadata/Cargo.toml b/compiler/rustc_metadata/Cargo.toml index 46a2f4b5114f9..a2ef8454ed6a6 100644 --- a/compiler/rustc_metadata/Cargo.toml +++ b/compiler/rustc_metadata/Cargo.toml @@ -29,6 +29,7 @@ rustc_proc_macro = { path = "../rustc_proc_macro" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } tempfile = "3.7.1" tracing = "0.1" diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 7667f0c714523..7c6397d0114fc 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -27,14 +27,14 @@ use rustc_proc_macro::bridge::client::Client as ProcMacroClient; use rustc_session::Session; use rustc_session::config::mitigation_coverage::DeniedPartialMitigationLevel; use rustc_session::config::{ - CrateType, ExtendedTargetModifierInfo, ExternLocation, Externs, OptionsTargetModifiers, - TargetModifier, + ExtendedTargetModifierInfo, ExternLocation, Externs, OptionsTargetModifiers, TargetModifier, }; use rustc_session::output::validate_crate_name; use rustc_session::search_paths::PathKind; use rustc_span::def_id::DefId; use rustc_span::edition::Edition; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym}; +use rustc_structures::CrateType; use rustc_target::spec::{PanicStrategy, Target}; use tracing::{debug, info}; diff --git a/compiler/rustc_metadata/src/dependency_format.rs b/compiler/rustc_metadata/src/dependency_format.rs index 6460e20ce211b..90844009f6bbe 100644 --- a/compiler/rustc_metadata/src/dependency_format.rs +++ b/compiler/rustc_metadata/src/dependency_format.rs @@ -59,8 +59,8 @@ use rustc_index::IndexVec; use rustc_middle::bug; use rustc_middle::middle::dependency_format::{Dependencies, DependencyList, Linkage}; use rustc_middle::ty::TyCtxt; -use rustc_session::config::CrateType; use rustc_span::sym; +use rustc_structures::CrateType; use rustc_target::spec::PanicStrategy; use tracing::info; diff --git a/compiler/rustc_metadata/src/fs.rs b/compiler/rustc_metadata/src/fs.rs index 044ec5345cdcd..535197b3dc51a 100644 --- a/compiler/rustc_metadata/src/fs.rs +++ b/compiler/rustc_metadata/src/fs.rs @@ -5,8 +5,9 @@ use rustc_data_structures::temp_dir::MaybeTempDir; use rustc_fs_util::TempDirBuilder; use rustc_middle::ty::TyCtxt; use rustc_session::Session; -use rustc_session::config::{CrateType, OutFileName, OutputType}; +use rustc_session::config::{OutFileName, OutputType}; use rustc_session::output::filename_for_metadata; +use rustc_structures::CrateType; use crate::diagnostics::{ BinaryOutputToTty, FailedCopyToStdout, FailedCreateEncodedMetadata, FailedCreateFile, diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 228600fa76794..cc7da00fcec5c 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -27,13 +27,14 @@ use rustc_middle::ty::fast_reject::{self, TreatParams}; use rustc_middle::{bug, span_bug}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder, opaque}; use rustc_session::config::mitigation_coverage::DeniedPartialMitigation; -use rustc_session::config::{CrateType, OptLevel, TargetModifier}; +use rustc_session::config::{OptLevel, TargetModifier}; use rustc_span::def_id::CRATE_MOD_ID; use rustc_span::hygiene::HygieneEncodeContext; use rustc_span::{ ByteSymbol, ExternalSource, FileName, SourceFile, SpanData, SpanEncoder, StableSourceFileId, Symbol, SyntaxContext, sym, }; +use rustc_structures::CrateType; use tracing::{debug, instrument, trace}; use crate::diagnostics::{FailCreateFileEncoder, FailWriteFile}; diff --git a/compiler/rustc_middle/src/middle/dependency_format.rs b/compiler/rustc_middle/src/middle/dependency_format.rs index ea04b519a7dea..f71a5d8e2718b 100644 --- a/compiler/rustc_middle/src/middle/dependency_format.rs +++ b/compiler/rustc_middle/src/middle/dependency_format.rs @@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_hir::def_id::CrateNum; use rustc_index::IndexVec; use rustc_macros::{Decodable, Encodable, StableHash}; -use rustc_session::config::CrateType; +use rustc_structures::CrateType; /// A list of dependencies for a certain crate type. pub type DependencyList = IndexVec; diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index af60db2166c46..35c61f66d639e 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -39,11 +39,10 @@ use rustc_index::IndexVec; use rustc_lint_defs::Lint; use rustc_lint_defs::builtin::UNUSED_FEATURES; use rustc_macros::Diagnostic; -use rustc_session::config::CrateType; use rustc_session::{IncrCompSession, Session}; use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; -use rustc_structures::Limit; +use rustc_structures::{CrateType, Limit}; use rustc_type_ir::TyKind::*; pub use rustc_type_ir::lift::Lift; use rustc_type_ir::{CollectAndApply, WithCachedTypeInfo, elaborate, search_graph}; diff --git a/compiler/rustc_passes/Cargo.toml b/compiler/rustc_passes/Cargo.toml index bcfe65f31b082..acdefb96bb9be 100644 --- a/compiler/rustc_passes/Cargo.toml +++ b/compiler/rustc_passes/Cargo.toml @@ -21,6 +21,7 @@ rustc_middle = { path = "../rustc_middle" } rustc_privacy = { path = "../rustc_privacy" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } tracing = "0.1" diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index c3c7fa591befd..405cf42a0a559 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -40,10 +40,10 @@ use rustc_middle::traits::ObligationCause; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::{self, TyCtxt, TypingMode, Unnormalized}; use rustc_middle::{bug, span_bug}; -use rustc_session::config::CrateType; use rustc_session::diagnostics::feature_err; use rustc_span::edition::Edition; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; +use rustc_structures::CrateType; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs}; use rustc_trait_selection::traits::{ObligationCtxt, TraitErrors}; diff --git a/compiler/rustc_passes/src/check_export.rs b/compiler/rustc_passes/src/check_export.rs index 411aad0717959..bd2cf272faa35 100644 --- a/compiler/rustc_passes/src/check_export.rs +++ b/compiler/rustc_passes/src/check_export.rs @@ -14,8 +14,8 @@ use rustc_middle::query::{LocalCrate, Providers}; use rustc_middle::ty::{ self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Unnormalized, Visibility, }; -use rustc_session::config::CrateType; use rustc_span::Span; +use rustc_structures::CrateType; use crate::diagnostics::UnexportableItem; diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 68ee14bc5474d..e67408a419611 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -23,8 +23,8 @@ use rustc_middle::middle::privacy::Level; use rustc_middle::query::Providers; use rustc_middle::ty::{self, AssocTag, TyCtxt}; use rustc_middle::{bug, span_bug}; -use rustc_session::config::CrateType; use rustc_span::{Symbol, kw}; +use rustc_structures::CrateType; use crate::diagnostics::{ ChangeFields, DeadCodePubInBinaryNote, IgnoredDerivedImpls, MultipleDeadCodes, ParentInfo, diff --git a/compiler/rustc_passes/src/eii.rs b/compiler/rustc_passes/src/eii.rs index 48621faeecc2f..05cb10e174d89 100644 --- a/compiler/rustc_passes/src/eii.rs +++ b/compiler/rustc_passes/src/eii.rs @@ -8,7 +8,7 @@ use rustc_hir::attrs::{EiiDecl, EiiImpl}; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_middle::diagnostics::DuplicateEiiImpls; use rustc_middle::ty::TyCtxt; -use rustc_session::config::CrateType; +use rustc_structures::CrateType; use crate::diagnostics::EiiWithoutImpl; diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 80cfe10ca7176..3b0ee311efc22 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -4,8 +4,9 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId}; use rustc_hir::{ItemId, Node, find_attr}; use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; -use rustc_session::config::{CrateType, EntryFnType, sigpipe}; +use rustc_session::config::{EntryFnType, sigpipe}; use rustc_span::{RemapPathScopeComponents, Span}; +use rustc_structures::CrateType; use crate::diagnostics::{ExternMain, MultipleRustcMain, NoMainErr}; diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 86a57a4d36121..ddf8bbf764e6e 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -230,7 +230,7 @@ impl<'ast, 'tcx> LanguageItemCollector<'ast, 'tcx> { } } - if self.tcx.crate_types().contains(&rustc_session::config::CrateType::Sdylib) { + if self.tcx.crate_types().contains(&rustc_structures::CrateType::Sdylib) { self.tcx.dcx().emit_err(IncorrectCrateType { span: attr_span }); } diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 05f12aaedcfce..576c65a58021c 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -35,7 +35,7 @@ use rustc_middle::mir::interpret::{ConstAllocation, ErrorHandled, GlobalAlloc}; use rustc_middle::query::Providers; use rustc_middle::ty::{self, ExistentialTraitRef, TyCtxt}; use rustc_privacy::DefIdVisitor; -use rustc_session::config::CrateType; +use rustc_structures::CrateType; use tracing::debug; /// Determines whether this item is recursive for reachability. See `is_recursively_reachable_local` diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs index 3d451fde8adb8..e7042767f8bae 100644 --- a/compiler/rustc_passes/src/weak_lang_items.rs +++ b/compiler/rustc_passes/src/weak_lang_items.rs @@ -5,7 +5,7 @@ use rustc_hir::attrs::lang_items::{self, LangItem}; use rustc_hir::attrs::weak_lang_items::WEAK_LANG_ITEMS; use rustc_middle::middle::lang_items::required; use rustc_middle::ty::TyCtxt; -use rustc_session::config::CrateType; +use rustc_structures::CrateType; use crate::diagnostics::{MissingLangItem, MissingPanicHandler, PanicUnwindWithoutStd}; diff --git a/compiler/rustc_resolve/Cargo.toml b/compiler/rustc_resolve/Cargo.toml index c8330631a979e..19a4ee5a55ff7 100644 --- a/compiler/rustc_resolve/Cargo.toml +++ b/compiler/rustc_resolve/Cargo.toml @@ -26,6 +26,7 @@ rustc_metadata = { path = "../rustc_metadata" } rustc_middle = { path = "../rustc_middle" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } thin-vec = "0.2.19" tracing = "0.1" diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index b9cc7b7fff74c..0e99db1b95cc1 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -32,9 +32,10 @@ use rustc_lint_defs::builtin::{ELIDED_LIFETIMES_IN_PATHS, UNUSED_LABELS}; use rustc_middle::middle::resolve_bound_vars::Set1; use rustc_middle::ty::{AssocTag, DelegationInfo, Visibility}; use rustc_middle::{bug, span_bug}; -use rustc_session::config::{CrateType, ResolveDocLinks}; +use rustc_session::config::ResolveDocLinks; use rustc_session::diagnostics::feature_err; use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Spanned, Symbol, kw, respan, sym}; +use rustc_structures::CrateType; use smallvec::{SmallVec, smallvec}; use thin_vec::ThinVec; use tracing::{debug, instrument, trace}; diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 5faf0cd642440..180157dbfb950 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -70,10 +70,10 @@ use rustc_middle::ty::{ ResolverAstLowering, ResolverGlobalCtxt, TyCtxt, TyCtxtFeed, Visibility, }; use rustc_middle::{bug, span_bug}; -use rustc_session::config::CrateType; use rustc_span::def_id::{LocalModId, ModId}; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; +use rustc_structures::CrateType; use smallvec::{SmallVec, smallvec}; use tracing::{debug, instrument}; diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 266a5adb2f29c..50e028e887470 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -26,6 +26,7 @@ use rustc_span::source_map::FilePathMapping; use rustc_span::{ FileName, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm, Symbol, sym, }; +use rustc_structures::CrateType; use rustc_target::spec::{ FramePointer, LinkSelfContainedComponents, LinkerFeatures, PanicStrategy, SplitDebuginfo, Target, TargetTuple, @@ -1579,8 +1580,6 @@ pub enum EntryFnType { }, } -pub use rustc_attr_ir::CrateType; - #[derive(Clone, Hash, Debug, PartialEq, Eq, Encodable, Decodable)] pub enum Passes { Some(Vec), diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 9ed3975043966..08e09c39a0804 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -16,6 +16,7 @@ use rustc_macros::{BlobDecodable, Encodable}; use rustc_span::edit_distance::edit_distance; use rustc_span::edition::Edition; use rustc_span::{RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm}; +use rustc_structures::CrateType; use rustc_target::spec::{ CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, diff --git a/compiler/rustc_session/src/output.rs b/compiler/rustc_session/src/output.rs index e2eb46c4ca878..2d1bdc521852a 100644 --- a/compiler/rustc_session/src/output.rs +++ b/compiler/rustc_session/src/output.rs @@ -3,9 +3,10 @@ use std::path::Path; use rustc_span::{Span, Symbol}; +use rustc_structures::CrateType; use crate::Session; -use crate::config::{CrateType, OutFileName, OutputFilenames, OutputType}; +use crate::config::{OutFileName, OutputFilenames, OutputType}; use crate::diagnostics::{ CrateNameEmpty, FileIsNotWriteable, InvalidCharacterInCrateName, InvalidCharacterInCrateNameSuggestion, diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index cd3cbc8e37ea0..cdbc4d1e36ab8 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -25,7 +25,7 @@ pub use rustc_span::def_id::StableCrateId; use rustc_span::edition::Edition; use rustc_span::source_map::{FilePathMapping, SourceMap}; use rustc_span::{RealFileName, Span, Symbol}; -use rustc_structures::Limit; +use rustc_structures::{CrateType, Limit}; use rustc_target::asm::InlineAsmArch; use rustc_target::spec::{ Arch, CfgAbi, CodeModel, DebuginfoKind, Os, PanicStrategy, RelocModel, RelroLevel, @@ -36,7 +36,7 @@ use rustc_target::spec::{ use crate::code_stats::CodeStats; pub use crate::code_stats::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo}; use crate::config::{ - self, BranchProtection, Cfg, CheckCfg, CoverageLevel, CoverageOptions, CrateType, DebugInfo, + self, BranchProtection, Cfg, CheckCfg, CoverageLevel, CoverageOptions, DebugInfo, ErrorOutputType, FunctionReturn, Input, InstrumentCoverage, InstrumentMcount, NATIVE_CPU, OptLevel, OutFileName, OutputType, PAuthKey, PointerAuthOption, SwitchWithOptPath, }; diff --git a/compiler/rustc_structures/Cargo.toml b/compiler/rustc_structures/Cargo.toml index 438277828eec4..8b91e2951876b 100644 --- a/compiler/rustc_structures/Cargo.toml +++ b/compiler/rustc_structures/Cargo.toml @@ -10,6 +10,7 @@ rustc_data_structures = { path = "../rustc_data_structures", optional = true } rustc_error_messages = { path = "../rustc_error_messages", optional = true } rustc_macros = { path = "../rustc_macros", optional = true } rustc_serialize = { path = "../rustc_serialize", optional = true } +rustc_span = { path = "../rustc_span", optional = true } schemars = "1.0.4" serde = "1.0.219" # tidy-alphabetical-end @@ -22,5 +23,6 @@ nightly = [ "dep:rustc_error_messages", "dep:rustc_macros", "dep:rustc_serialize", + "dep:rustc_span", ] # tidy-alphabetical-end diff --git a/compiler/rustc_structures/src/crate_type.rs b/compiler/rustc_structures/src/crate_type.rs new file mode 100644 index 0000000000000..505370a524281 --- /dev/null +++ b/compiler/rustc_structures/src/crate_type.rs @@ -0,0 +1,114 @@ +#[cfg(feature = "nightly")] +use { + rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash}, + rustc_span::{Symbol, sym}, +}; + +/// Crate type, as specified by `#![crate_type]` +#[derive(Copy, Clone, Debug, Hash, PartialEq, Default, PartialOrd, Eq, Ord)] +#[cfg_attr(feature = "nightly", derive(StableHash, Encodable_NoContext, Decodable_NoContext))] +pub enum CrateType { + /// `#![crate_type = "bin"]` + Executable, + /// `#![crate_type = "dylib"]` + Dylib, + /// `#![crate_type = "rlib"]` or `#![crate_type = "lib"]` + #[default] + Rlib, + /// `#![crate_type = "staticlib"]` + StaticLib, + /// `#![crate_type = "cdylib"]` + Cdylib, + /// `#![crate_type = "proc-macro"]` + ProcMacro, + /// `#![crate_type = "sdylib"]` + // Unstable; feature(export_stable) + Sdylib, +} +#[cfg(feature = "nightly")] +impl CrateType { + /// Pairs of each `#[crate_type] = "..."` value and the crate type it resolves to + pub fn all() -> &'static [(Symbol, Self)] { + debug_assert_eq!(CrateType::default(), CrateType::Rlib); + &[ + (sym::lib, CrateType::Rlib), + (sym::rlib, CrateType::Rlib), + (sym::dylib, CrateType::Dylib), + (sym::cdylib, CrateType::Cdylib), + (sym::staticlib, CrateType::StaticLib), + (sym::proc_dash_macro, CrateType::ProcMacro), + (sym::bin, CrateType::Executable), + (sym::sdylib, CrateType::Sdylib), + ] + } + + /// Same as [`CrateType::all`], but does not include unstable options. + /// Used for diagnostics. + pub fn all_stable() -> &'static [(Symbol, Self)] { + debug_assert_eq!(CrateType::default(), CrateType::Rlib); + &[ + (sym::lib, CrateType::Rlib), + (sym::rlib, CrateType::Rlib), + (sym::dylib, CrateType::Dylib), + (sym::cdylib, CrateType::Cdylib), + (sym::staticlib, CrateType::StaticLib), + (sym::proc_dash_macro, CrateType::ProcMacro), + (sym::bin, CrateType::Executable), + ] + } +} + +impl CrateType { + pub fn has_metadata(self) -> bool { + match self { + CrateType::Rlib | CrateType::Dylib | CrateType::ProcMacro => true, + CrateType::Executable + | CrateType::Cdylib + | CrateType::StaticLib + | CrateType::Sdylib => false, + } + } +} + +#[cfg(feature = "nightly")] +impl TryFrom for CrateType { + type Error = (); + + fn try_from(value: Symbol) -> Result { + Ok(match value { + sym::bin => CrateType::Executable, + sym::dylib => CrateType::Dylib, + sym::staticlib => CrateType::StaticLib, + sym::cdylib => CrateType::Cdylib, + sym::rlib => CrateType::Rlib, + sym::lib => CrateType::default(), + sym::proc_dash_macro => CrateType::ProcMacro, + sym::sdylib => CrateType::Sdylib, + _ => return Err(()), + }) + } +} + +impl std::fmt::Display for CrateType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match *self { + CrateType::Executable => "bin".fmt(f), + CrateType::Dylib => "dylib".fmt(f), + CrateType::Rlib => "rlib".fmt(f), + CrateType::StaticLib => "staticlib".fmt(f), + CrateType::Cdylib => "cdylib".fmt(f), + CrateType::ProcMacro => "proc-macro".fmt(f), + CrateType::Sdylib => "sdylib".fmt(f), + } + } +} + +#[cfg(feature = "nightly")] +impl rustc_error_messages::IntoDiagArg for CrateType { + fn into_diag_arg( + self, + _: &mut Option, + ) -> rustc_error_messages::DiagArgValue { + self.to_string().into_diag_arg(&mut None) + } +} diff --git a/compiler/rustc_structures/src/lib.rs b/compiler/rustc_structures/src/lib.rs index 4ac98fde5f7b9..a769a28edff6d 100644 --- a/compiler/rustc_structures/src/lib.rs +++ b/compiler/rustc_structures/src/lib.rs @@ -1,7 +1,9 @@ #![deny(unstable_features)] +mod crate_type; mod limit; mod sanitizer_set; +pub use crate_type::CrateType; pub use limit::Limit; pub use sanitizer_set::SanitizerSet; From 8d970ffe691eb7bc882124107999340519b3efcc Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 18:16:04 +0200 Subject: [PATCH 23/34] Move `NativeLibKind` --- Cargo.lock | 1 + compiler/rustc_attr_ir/src/data_structures.rs | 72 +------------------ compiler/rustc_attr_ir/src/pretty_printing.rs | 3 +- .../src/attributes/link_attrs.rs | 1 + compiler/rustc_codegen_ssa/src/back/link.rs | 3 +- .../src/back/link/raw_dylib.rs | 2 +- .../rustc_codegen_ssa/src/back/rmeta_link.rs | 2 +- compiler/rustc_codegen_ssa/src/lib.rs | 4 +- compiler/rustc_crate_store/Cargo.toml | 1 + compiler/rustc_crate_store/src/cstore.rs | 3 +- compiler/rustc_metadata/src/native_libs.rs | 3 +- .../rustc_session/src/config/native_libs.rs | 2 +- compiler/rustc_session/src/utils.rs | 2 +- compiler/rustc_structures/src/lib.rs | 2 + .../rustc_structures/src/native_lib_kind.rs | 71 ++++++++++++++++++ 15 files changed, 90 insertions(+), 82 deletions(-) create mode 100644 compiler/rustc_structures/src/native_lib_kind.rs diff --git a/Cargo.lock b/Cargo.lock index 5fcd934635486..bbce8baaacee6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3875,6 +3875,7 @@ dependencies = [ "rustc_macros", "rustc_serialize", "rustc_span", + "rustc_structures", ] [[package]] diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index cd95d5ce0c8af..d15f21d1cc424 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -16,7 +16,7 @@ use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash}; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; -use rustc_structures::{CrateType, Limit, SanitizerSet}; +use rustc_structures::{CrateType, Limit, NativeLibKind, SanitizerSet}; use thin_vec::ThinVec; pub use crate::canonical_symbols::{CanonicalSymbol, CanonicalSymbols}; @@ -371,76 +371,6 @@ pub enum PeImportNameType { Undecorated, } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[derive(Encodable, Decodable, PrintAttribute)] -#[derive(StableHash)] -pub enum NativeLibKind { - /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC) - Static { - /// Whether to bundle objects from static library into produced rlib - bundle: Option, - /// Whether to link static library without throwing any object files away - whole_archive: Option, - /// Whether to export c static library symbols - export_symbols: Option, - }, - /// Dynamic library (e.g. `libfoo.so` on Linux) - /// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC). - Dylib { - /// Whether the dynamic library will be linked only if it satisfies some undefined symbols - as_needed: Option, - }, - /// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library. - /// On Linux, it refers to a generated shared library stub. - RawDylib { - /// Whether the dynamic library will be linked only if it satisfies some undefined symbols - as_needed: Option, - }, - /// A macOS-specific kind of dynamic libraries. - Framework { - /// Whether the framework will be linked only if it satisfies some undefined symbols - as_needed: Option, - }, - /// Argument which is passed to linker, relative order with libraries and other arguments - /// is preserved - LinkArg, - - /// Module imported from WebAssembly - WasmImportModule, - - /// The library kind wasn't specified, `Dylib` is currently used as a default. - Unspecified, -} - -impl NativeLibKind { - pub fn has_modifiers(&self) -> bool { - match self { - NativeLibKind::Static { bundle, whole_archive, export_symbols } => { - bundle.is_some() || whole_archive.is_some() || export_symbols.is_some() - } - NativeLibKind::Dylib { as_needed } - | NativeLibKind::Framework { as_needed } - | NativeLibKind::RawDylib { as_needed } => as_needed.is_some(), - NativeLibKind::Unspecified - | NativeLibKind::LinkArg - | NativeLibKind::WasmImportModule => false, - } - } - - pub fn is_statically_included(&self) -> bool { - matches!(self, NativeLibKind::Static { .. }) - } - - pub fn is_dllimport(&self) -> bool { - matches!( - self, - NativeLibKind::Dylib { .. } - | NativeLibKind::RawDylib { .. } - | NativeLibKind::Unspecified - ) - } -} - #[derive(Debug, Encodable, Decodable, Clone, StableHash, PrintAttribute)] pub struct LinkEntry { pub span: Span, diff --git a/compiler/rustc_attr_ir/src/pretty_printing.rs b/compiler/rustc_attr_ir/src/pretty_printing.rs index 7abcd4c23e397..7a0e9180ec7e9 100644 --- a/compiler/rustc_attr_ir/src/pretty_printing.rs +++ b/compiler/rustc_attr_ir/src/pretty_printing.rs @@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; -use rustc_structures::{CrateType, Limit, SanitizerSet}; +use rustc_structures::{CrateType, Limit, NativeLibKind, SanitizerSet}; use thin_vec::ThinVec; /// This trait is used to print attributes in `rustc_hir_pretty`. @@ -208,4 +208,5 @@ print_debug!( DiffActivity, DiffMode, CrateType, + NativeLibKind, ); diff --git a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs index 6d25e7fb00183..d674149c225f6 100644 --- a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs @@ -7,6 +7,7 @@ use rustc_session::Session; use rustc_session::diagnostics::feature_err; use rustc_span::edition::Edition::Edition2024; use rustc_span::kw; +use rustc_structures::NativeLibKind; use rustc_target::spec::{Arch, BinaryFormat}; use super::prelude::*; diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index a5288d339cfc3..25003e071beb7 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -21,7 +21,6 @@ use rustc_data_structures::memmap::Mmap; use rustc_data_structures::temp_dir::MaybeTempDir; use rustc_errors::DiagCtxtHandle; use rustc_fs_util::{TempDirBuilder, fix_windows_verbatim_for_gcc, try_canonicalize}; -use rustc_hir::attrs::NativeLibKind; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_lint_defs::builtin::{LINKER_INFO, LINKER_MESSAGES}; use rustc_macros::Diagnostic; @@ -43,7 +42,7 @@ use rustc_session::search_paths::PathKind; /// need out of the shared crate context before we get rid of it. use rustc_session::{Session, filesearch}; use rustc_span::Symbol; -use rustc_structures::CrateType; +use rustc_structures::{CrateType, NativeLibKind}; use rustc_target::spec::crt_objects::CrtObjects; use rustc_target::spec::{ Arch, BinaryFormat, Cc, CfgAbi, Env, LinkOutputKind, LinkSelfContainedComponents, diff --git a/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs b/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs index 2857c4f28b222..13478f417238a 100644 --- a/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs +++ b/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs @@ -8,9 +8,9 @@ use rustc_data_structures::base_n::{CASE_INSENSITIVE, ToBaseN}; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::stable_hash::StableHasher; use rustc_hashes::Hash128; -use rustc_hir::attrs::NativeLibKind; use rustc_session::Session; use rustc_span::Symbol; +use rustc_structures::NativeLibKind; use rustc_target::spec::Arch; use crate::back::archive::ImportLibraryItem; diff --git a/compiler/rustc_codegen_ssa/src/back/rmeta_link.rs b/compiler/rustc_codegen_ssa/src/back/rmeta_link.rs index 69ec3788ac632..59139214146c4 100644 --- a/compiler/rustc_codegen_ssa/src/back/rmeta_link.rs +++ b/compiler/rustc_codegen_ssa/src/back/rmeta_link.rs @@ -8,11 +8,11 @@ use std::path::{Path, PathBuf}; use object::read::archive::ArchiveFile; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::memmap::Mmap; -use rustc_hir::attrs::NativeLibKind; use rustc_serialize::opaque::mem_encoder::MemEncoder; use rustc_serialize::opaque::{MAGIC_END_BYTES, MemDecoder}; use rustc_serialize::{Decodable, Encodable}; use rustc_span::Symbol; +use rustc_structures::NativeLibKind; use rustc_target::spec::Target; use tracing::debug; diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 23cb46d5a6634..bf2ce74e38d84 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -22,7 +22,7 @@ use rustc_crate_store::{self as cstore, CrateSource}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_hir::CRATE_HIR_ID; -use rustc_hir::attrs::{CfgEntry, NativeLibKind, WindowsSubsystemKind}; +use rustc_hir::attrs::{CfgEntry, WindowsSubsystemKind}; use rustc_hir::def_id::CrateNum; use rustc_lint_defs::builtin::{LINKER_INFO, LINKER_MESSAGES}; use rustc_macros::{Decodable, Encodable}; @@ -39,7 +39,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_session::Session; use rustc_session::config::{OutputFilenames, OutputType}; use rustc_span::{Span, Symbol}; -use rustc_structures::CrateType; +use rustc_structures::{CrateType, NativeLibKind}; pub mod assert_module_sources; pub mod back; diff --git a/compiler/rustc_crate_store/Cargo.toml b/compiler/rustc_crate_store/Cargo.toml index 7c84c26afe2dc..1857ae8130c10 100644 --- a/compiler/rustc_crate_store/Cargo.toml +++ b/compiler/rustc_crate_store/Cargo.toml @@ -12,4 +12,5 @@ rustc_hir_id = { path = "../rustc_hir_id" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } +rustc_structures = { path = "../rustc_structures" } # tidy-alphabetical-end diff --git a/compiler/rustc_crate_store/src/cstore.rs b/compiler/rustc_crate_store/src/cstore.rs index e3b339a5ce871..fba2fc288f5a9 100644 --- a/compiler/rustc_crate_store/src/cstore.rs +++ b/compiler/rustc_crate_store/src/cstore.rs @@ -6,7 +6,7 @@ use std::any::Any; use std::path::PathBuf; use rustc_abi::ExternAbi; -use rustc_attr_ir::{CfgEntry, NativeLibKind, PeImportNameType}; +use rustc_attr_ir::{CfgEntry, PeImportNameType}; use rustc_data_structures::sync::{self, AppendOnlyIndexVec, FreezeLock}; use rustc_hir_id::definitions::{DefKey, DefPath, Definitions}; use rustc_macros::{BlobDecodable, Decodable, Encodable, StableHash}; @@ -14,6 +14,7 @@ use rustc_span::def_id::{ CrateNum, DefId, DefPathHash, LOCAL_CRATE, LocalDefId, StableCrateId, StableCrateIdMap, }; use rustc_span::{Span, Symbol}; +use rustc_structures::NativeLibKind; /// Where a crate came from on the local filesystem. One of these three options /// must be non-None. diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index 138bb55847255..87e0902b1f7f8 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -4,7 +4,7 @@ use rustc_crate_store::{ DllCallingConvention, DllImport, DllImportSymbolType, ForeignModule, NativeLib, }; use rustc_data_structures::fx::FxHashSet; -use rustc_hir::attrs::{NativeLibKind, PeImportNameType}; +use rustc_hir::attrs::PeImportNameType; use rustc_hir::def::DefKind; use rustc_hir::find_attr; use rustc_middle::bug; @@ -14,6 +14,7 @@ use rustc_middle::ty::{self, List, Ty, TyCtxt}; use rustc_session::Session; use rustc_span::Symbol; use rustc_span::def_id::{DefId, LOCAL_CRATE}; +use rustc_structures::NativeLibKind; use rustc_target::spec::{Arch, BinaryFormat, CfgAbi}; use crate::diagnostics; diff --git a/compiler/rustc_session/src/config/native_libs.rs b/compiler/rustc_session/src/config/native_libs.rs index d8c41fbae4c96..0733bd3ca4b78 100644 --- a/compiler/rustc_session/src/config/native_libs.rs +++ b/compiler/rustc_session/src/config/native_libs.rs @@ -4,8 +4,8 @@ //! (There is also a similar but separate syntax for `#[link]` attributes, //! which have their own parser in `rustc_metadata`.) -use rustc_attr_ir::NativeLibKind; use rustc_feature::UnstableFeatures; +use rustc_structures::NativeLibKind; use crate::EarlyDiagCtxt; use crate::config::UnstableOptions; diff --git a/compiler/rustc_session/src/utils.rs b/compiler/rustc_session/src/utils.rs index d1d0f18b2c4cf..42300d540ed49 100644 --- a/compiler/rustc_session/src/utils.rs +++ b/compiler/rustc_session/src/utils.rs @@ -1,10 +1,10 @@ use std::path::PathBuf; use std::sync::OnceLock; -use rustc_attr_ir::NativeLibKind; use rustc_data_structures::profiling::VerboseTimingGuard; use rustc_fs_util::try_canonicalize; use rustc_macros::{Decodable, Encodable, StableHash}; +use rustc_structures::NativeLibKind; use crate::session::Session; diff --git a/compiler/rustc_structures/src/lib.rs b/compiler/rustc_structures/src/lib.rs index a769a28edff6d..f8adc211fa0cb 100644 --- a/compiler/rustc_structures/src/lib.rs +++ b/compiler/rustc_structures/src/lib.rs @@ -2,8 +2,10 @@ mod crate_type; mod limit; +mod native_lib_kind; mod sanitizer_set; pub use crate_type::CrateType; pub use limit::Limit; +pub use native_lib_kind::NativeLibKind; pub use sanitizer_set::SanitizerSet; diff --git a/compiler/rustc_structures/src/native_lib_kind.rs b/compiler/rustc_structures/src/native_lib_kind.rs new file mode 100644 index 0000000000000..a232d7a314573 --- /dev/null +++ b/compiler/rustc_structures/src/native_lib_kind.rs @@ -0,0 +1,71 @@ +#[cfg(feature = "nightly")] +use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash}; + +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "nightly", derive(StableHash, Encodable_NoContext, Decodable_NoContext))] +pub enum NativeLibKind { + /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC) + Static { + /// Whether to bundle objects from static library into produced rlib + bundle: Option, + /// Whether to link static library without throwing any object files away + whole_archive: Option, + /// Whether to export c static library symbols + export_symbols: Option, + }, + /// Dynamic library (e.g. `libfoo.so` on Linux) + /// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC). + Dylib { + /// Whether the dynamic library will be linked only if it satisfies some undefined symbols + as_needed: Option, + }, + /// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library. + /// On Linux, it refers to a generated shared library stub. + RawDylib { + /// Whether the dynamic library will be linked only if it satisfies some undefined symbols + as_needed: Option, + }, + /// A macOS-specific kind of dynamic libraries. + Framework { + /// Whether the framework will be linked only if it satisfies some undefined symbols + as_needed: Option, + }, + /// Argument which is passed to linker, relative order with libraries and other arguments + /// is preserved + LinkArg, + + /// Module imported from WebAssembly + WasmImportModule, + + /// The library kind wasn't specified, `Dylib` is currently used as a default. + Unspecified, +} + +impl NativeLibKind { + pub fn has_modifiers(&self) -> bool { + match self { + NativeLibKind::Static { bundle, whole_archive, export_symbols } => { + bundle.is_some() || whole_archive.is_some() || export_symbols.is_some() + } + NativeLibKind::Dylib { as_needed } + | NativeLibKind::Framework { as_needed } + | NativeLibKind::RawDylib { as_needed } => as_needed.is_some(), + NativeLibKind::Unspecified + | NativeLibKind::LinkArg + | NativeLibKind::WasmImportModule => false, + } + } + + pub fn is_statically_included(&self) -> bool { + matches!(self, NativeLibKind::Static { .. }) + } + + pub fn is_dllimport(&self) -> bool { + matches!( + self, + NativeLibKind::Dylib { .. } + | NativeLibKind::RawDylib { .. } + | NativeLibKind::Unspecified + ) + } +} From 7bec35198154b2c07e5658b74f1a3d232b0b8c69 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 18:27:33 +0200 Subject: [PATCH 24/34] move CollapseMacroDebuginfo --- Cargo.lock | 1 - compiler/rustc_attr_ir/src/data_structures.rs | 22 +------------------ compiler/rustc_attr_ir/src/pretty_printing.rs | 3 ++- .../src/attributes/macro_attrs.rs | 3 ++- compiler/rustc_expand/src/base.rs | 6 ++--- compiler/rustc_session/Cargo.toml | 1 - compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_session/src/options.rs | 3 +-- .../src/collapse_macro_debug_info.rs | 22 +++++++++++++++++++ compiler/rustc_structures/src/lib.rs | 2 ++ 10 files changed, 33 insertions(+), 32 deletions(-) create mode 100644 compiler/rustc_structures/src/collapse_macro_debug_info.rs diff --git a/Cargo.lock b/Cargo.lock index bbce8baaacee6..740bc02db788b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4748,7 +4748,6 @@ dependencies = [ "libc", "rustc_abi", "rustc_ast", - "rustc_attr_ir", "rustc_data_structures", "rustc_errors", "rustc_feature", diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index d15f21d1cc424..195712559782d 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -16,7 +16,7 @@ use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash}; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; -use rustc_structures::{CrateType, Limit, NativeLibKind, SanitizerSet}; +use rustc_structures::{CollapseMacroDebuginfo, CrateType, Limit, NativeLibKind, SanitizerSet}; use thin_vec::ThinVec; pub use crate::canonical_symbols::{CanonicalSymbol, CanonicalSymbols}; @@ -601,26 +601,6 @@ impl rustc_serialize::Encodable for DocAttribute } } -/// How to perform collapse macros debug info -/// if-ext - if macro from different crate (related to callsite code) -/// | cmd \ attr | no | (unspecified) | external | yes | -/// | no | no | no | no | no | -/// | (unspecified) | no | no | if-ext | yes | -/// | external | no | if-ext | if-ext | yes | -/// | yes | yes | yes | yes | yes | -#[derive(Copy, Clone, Debug, Hash, PartialEq)] -#[derive(StableHash, Encodable, Decodable, PrintAttribute)] -pub enum CollapseMacroDebuginfo { - /// Don't collapse debuginfo for the macro - No = 0, - /// Unspecified value - Unspecified = 1, - /// Collapse debuginfo if the macro comes from a different crate - External = 2, - /// Collapse debuginfo for the macro - Yes = 3, -} - #[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)] pub enum RustcDumpLayoutKind { Align, diff --git a/compiler/rustc_attr_ir/src/pretty_printing.rs b/compiler/rustc_attr_ir/src/pretty_printing.rs index 7a0e9180ec7e9..cd8a0c0e1e96f 100644 --- a/compiler/rustc_attr_ir/src/pretty_printing.rs +++ b/compiler/rustc_attr_ir/src/pretty_printing.rs @@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_span::def_id::DefId; use rustc_span::hygiene::Transparency; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; -use rustc_structures::{CrateType, Limit, NativeLibKind, SanitizerSet}; +use rustc_structures::{CollapseMacroDebuginfo, CrateType, Limit, NativeLibKind, SanitizerSet}; use thin_vec::ThinVec; /// This trait is used to print attributes in `rustc_hir_pretty`. @@ -209,4 +209,5 @@ print_debug!( DiffMode, CrateType, NativeLibKind, + CollapseMacroDebuginfo, ); diff --git a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs index fc1f0f2361b35..c9625521aec44 100644 --- a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs @@ -1,6 +1,7 @@ -use rustc_attr_ir::{CollapseMacroDebuginfo, MacroUseArgs, find_attr}; +use rustc_attr_ir::{MacroUseArgs, find_attr}; use rustc_feature::AttributeStability; use rustc_lint_defs::builtin::INVALID_MACRO_EXPORT_ARGUMENTS; +use rustc_structures::CollapseMacroDebuginfo; use super::prelude::*; use crate::diagnostics::MacroOnlyAttribute; diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index d845c2b732629..fda75319b087b 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -9,9 +9,7 @@ use rustc_ast::attr::MarkedAttrs; use rustc_ast::tokenstream::TokenStream; use rustc_ast::visit::{AssocCtxt, Visitor}; use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind, Safety}; -use rustc_attr_ir::{ - self as attrs, CfgEntry, CollapseMacroDebuginfo, Deprecation, Stability, find_attr, -}; +use rustc_attr_ir::{self as attrs, CfgEntry, Deprecation, Stability, find_attr}; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::sync; use rustc_errors::{BufferedEarlyLint, DiagCtxtHandle, ErrorGuaranteed}; @@ -27,7 +25,7 @@ use rustc_span::edition::Edition; use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind}; use rustc_span::source_map::SourceMap; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw}; -use rustc_structures::Limit; +use rustc_structures::{CollapseMacroDebuginfo, Limit}; use smallvec::{SmallVec, smallvec}; use thin_vec::ThinVec; diff --git a/compiler/rustc_session/Cargo.toml b/compiler/rustc_session/Cargo.toml index 9e3cac424ad6d..0bf35dac5513b 100644 --- a/compiler/rustc_session/Cargo.toml +++ b/compiler/rustc_session/Cargo.toml @@ -8,7 +8,6 @@ edition = "2024" getopts = "0.2" rustc_abi = { path = "../rustc_abi" } rustc_ast = { path = "../rustc_ast" } -rustc_attr_ir = { path = "../rustc_attr_ir" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 50e028e887470..f5d56698c7680 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -3317,7 +3317,6 @@ pub(crate) mod dep_tracking { use rustc_abi::Align; use rustc_ast::attr::version::RustcVersion; - use rustc_attr_ir::CollapseMacroDebuginfo; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::stable_hash::StableHasher; use rustc_errors::LanguageIdentifier; @@ -3325,6 +3324,7 @@ pub(crate) mod dep_tracking { use rustc_hashes::Hash64; use rustc_span::edition::Edition; use rustc_span::{RealFileName, RemapPathScopeComponents}; + use rustc_structures::CollapseMacroDebuginfo; use rustc_target::spec::{ CodeModel, FramePointer, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, TargetTuple, diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 08e09c39a0804..68e0fec59f06e 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -5,7 +5,6 @@ use std::str; use rustc_abi::Align; use rustc_ast::attr::version::RustcVersion; -use rustc_attr_ir::CollapseMacroDebuginfo; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::profiling::TimePassesFormat; use rustc_data_structures::stable_hash::StableHasher; @@ -16,7 +15,7 @@ use rustc_macros::{BlobDecodable, Encodable}; use rustc_span::edit_distance::edit_distance; use rustc_span::edition::Edition; use rustc_span::{RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm}; -use rustc_structures::CrateType; +use rustc_structures::{CollapseMacroDebuginfo, CrateType}; use rustc_target::spec::{ CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, diff --git a/compiler/rustc_structures/src/collapse_macro_debug_info.rs b/compiler/rustc_structures/src/collapse_macro_debug_info.rs new file mode 100644 index 0000000000000..8dd3f6cb5c337 --- /dev/null +++ b/compiler/rustc_structures/src/collapse_macro_debug_info.rs @@ -0,0 +1,22 @@ +#[cfg(feature = "nightly")] +use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash}; + +// How to perform collapse macros debug info +/// if-ext - if macro from different crate (related to callsite code) +/// | cmd \ attr | no | (unspecified) | external | yes | +/// | no | no | no | no | no | +/// | (unspecified) | no | no | if-ext | yes | +/// | external | no | if-ext | if-ext | yes | +/// | yes | yes | yes | yes | yes | +#[derive(Copy, Clone, Debug, Hash, PartialEq)] +#[cfg_attr(feature = "nightly", derive(StableHash, Encodable_NoContext, Decodable_NoContext))] +pub enum CollapseMacroDebuginfo { + /// Don't collapse debuginfo for the macro + No = 0, + /// Unspecified value + Unspecified = 1, + /// Collapse debuginfo if the macro comes from a different crate + External = 2, + /// Collapse debuginfo for the macro + Yes = 3, +} diff --git a/compiler/rustc_structures/src/lib.rs b/compiler/rustc_structures/src/lib.rs index f8adc211fa0cb..a0cbe516d626b 100644 --- a/compiler/rustc_structures/src/lib.rs +++ b/compiler/rustc_structures/src/lib.rs @@ -1,10 +1,12 @@ #![deny(unstable_features)] +mod collapse_macro_debug_info; mod crate_type; mod limit; mod native_lib_kind; mod sanitizer_set; +pub use collapse_macro_debug_info::CollapseMacroDebuginfo; pub use crate_type::CrateType; pub use limit::Limit; pub use native_lib_kind::NativeLibKind; From 587412a2642a1e1d3327b6fbdfe006847f20866c Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 21:05:13 +0200 Subject: [PATCH 25/34] Add crate docs --- compiler/rustc_structures/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_structures/src/lib.rs b/compiler/rustc_structures/src/lib.rs index a0cbe516d626b..a7ebea5ba9943 100644 --- a/compiler/rustc_structures/src/lib.rs +++ b/compiler/rustc_structures/src/lib.rs @@ -1,4 +1,6 @@ -#![deny(unstable_features)] +//! Basic structs that end up being used in attributes for one reason or another, +//! but are not used exclusively in or around attributes. +#![deny(unstable_features, reason = "ends up in dependencies of rust-analyzer")] mod collapse_macro_debug_info; mod crate_type; From 601e9d6a96a36c90c62697be49f015deff7a746d Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 21:07:07 +0200 Subject: [PATCH 26/34] bless bootstrap --- .../core/builder/cli_paths/snapshots/x_bench.snap | 1 + .../cli_paths/snapshots/x_build_compiler.snap | 1 + .../core/builder/cli_paths/snapshots/x_check.snap | 1 + .../cli_paths/snapshots/x_check_compiler.snap | 1 + .../x_check_compiletest_include_default_paths.snap | 1 + .../core/builder/cli_paths/snapshots/x_clippy.snap | 1 + .../src/core/builder/cli_paths/snapshots/x_fix.snap | 1 + .../src/core/builder/cli_paths/snapshots/x_test.snap | 1 + .../cli_paths/snapshots/x_test_skip_coverage.snap | 1 + .../snapshots/x_test_skip_coverage_map.snap | 1 + .../snapshots/x_test_skip_coverage_run.snap | 1 + .../cli_paths/snapshots/x_test_skip_tests.snap | 1 + .../snapshots/x_test_skip_tests_coverage.snap | 1 + .../cli_paths/snapshots/x_test_skip_tests_etc.snap | 1 + src/bootstrap/src/core/builder/tests.rs | 12 ++++++------ 15 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap index 755c0e19b8ae1..bb55f31c405d6 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap @@ -86,6 +86,7 @@ expression: bench - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_build_compiler.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_build_compiler.snap index 924972d28e607..9d3ff75cc1cce 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_build_compiler.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_build_compiler.snap @@ -68,6 +68,7 @@ expression: build compiler - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap index 46e00afd325d1..812bc18078999 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap @@ -70,6 +70,7 @@ expression: check - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiler.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiler.snap index eb48e337aeb0e..dc069febfcebe 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiler.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiler.snap @@ -70,6 +70,7 @@ expression: check compiler - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap index c84a6aed4eba8..921060318f5e5 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap @@ -70,6 +70,7 @@ expression: check compiletest --include-default-paths - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_clippy.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_clippy.snap index 99db9ae7b0268..dfb838638bf68 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_clippy.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_clippy.snap @@ -85,6 +85,7 @@ expression: clippy - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap index 529073c5b5a55..356be4863d1a6 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap @@ -70,6 +70,7 @@ expression: fix - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap index 7807566751a2f..49a1c04c6af63 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap @@ -134,6 +134,7 @@ expression: test - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap index 7bac4c859c450..397f8dbd794a3 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap @@ -131,6 +131,7 @@ expression: test --skip=coverage - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage_map.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage_map.snap index 732b84e90a880..d4723f9070859 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage_map.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage_map.snap @@ -134,6 +134,7 @@ expression: test --skip=coverage-map - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage_run.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage_run.snap index c36a9fd752aed..40d211627d7e0 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage_run.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage_run.snap @@ -134,6 +134,7 @@ expression: test --skip=coverage-run - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap index bf5de019af6f4..bdd627ae37cc3 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap @@ -95,6 +95,7 @@ expression: test --skip=tests - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_coverage.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_coverage.snap index 3236872a46469..7551afd31a79c 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_coverage.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_coverage.snap @@ -131,6 +131,7 @@ expression: test --skip=tests/coverage - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_etc.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_etc.snap index 93d3ee139e3fb..4457208ab56b9 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_etc.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_etc.snap @@ -79,6 +79,7 @@ expression: test --skip=tests --skip=library --skip=tidyselftest - Set({compiler/rustc_serialize}) - Set({compiler/rustc_session}) - Set({compiler/rustc_span}) + - Set({compiler/rustc_structures}) - Set({compiler/rustc_symbol_mangling}) - Set({compiler/rustc_target}) - Set({compiler/rustc_thread_pool}) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 465c7d8a82726..3b20f5198eb19 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1661,7 +1661,7 @@ mod snapshot { insta::assert_snapshot!( ctx.config("check") .path("compiler") - .render_steps(), @"[check] rustc 0 -> rustc 1 (76 crates)"); + .render_steps(), @"[check] rustc 0 -> rustc 1 (77 crates)"); } #[test] @@ -1687,7 +1687,7 @@ mod snapshot { ctx.config("check") .path("compiler") .stage(1) - .render_steps(), @"[check] rustc 0 -> rustc 1 (76 crates)"); + .render_steps(), @"[check] rustc 0 -> rustc 1 (77 crates)"); } #[test] @@ -1701,7 +1701,7 @@ mod snapshot { [build] llvm [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 - [check] rustc 1 -> rustc 2 (76 crates) + [check] rustc 1 -> rustc 2 (77 crates) "); } @@ -1717,7 +1717,7 @@ mod snapshot { [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 [check] rustc 1 -> std 1 - [check] rustc 1 -> rustc 2 (76 crates) + [check] rustc 1 -> rustc 2 (77 crates) [check] rustc 1 -> rustc 2 [check] rustc 1 -> Rustdoc 2 [check] rustc 1 -> rustc_codegen_cranelift 2 @@ -1814,7 +1814,7 @@ mod snapshot { ctx.config("check") .paths(&["library", "compiler"]) .args(&args) - .render_steps(), @"[check] rustc 0 -> rustc 1 (76 crates)"); + .render_steps(), @"[check] rustc 0 -> rustc 1 (77 crates)"); } #[test] @@ -3025,7 +3025,7 @@ mod snapshot { let ctx = TestCtx::new(); insta::assert_snapshot!(ctx.config("fix").path("compiler").render_steps(), @r" [build] llvm - [fix] rustc 0 -> rustc 1 (76 crates) + [fix] rustc 0 -> rustc 1 (77 crates) "); } } From 12278ac261e89e6719a650aa7ba75bd0ec858b97 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 21:13:23 +0200 Subject: [PATCH 27/34] Fix tools --- src/librustdoc/config.rs | 3 ++- src/librustdoc/core.rs | 3 ++- src/librustdoc/doctest.rs | 3 ++- src/librustdoc/lib.rs | 1 + src/librustdoc/passes/collect_intra_doc_links.rs | 2 +- src/tools/clippy/clippy_lints/src/lib.rs | 2 +- src/tools/clippy/clippy_lints/src/missing_inline.rs | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 7c3e91b90b754..3ad07dd35ccf0 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_errors::DiagCtxtHandle; use rustc_lint::Level; use rustc_session::config::{ - self, CodegenOptions, CrateType, ErrorOutputType, Externs, Input, JsonUnusedExterns, + self, CodegenOptions, ErrorOutputType, Externs, Input, JsonUnusedExterns, OptionsTargetModifiers, OutFileName, Sysroot, UnstableOptions, get_cmd_lint_options, nightly_options, parse_crate_types_from_list, parse_externs, parse_target_triple, }; @@ -17,6 +17,7 @@ use rustc_session::search_paths::SearchPath; use rustc_session::{EarlyDiagCtxt, getopts}; use rustc_span::edition::Edition; use rustc_span::{FileName, RemapPathScopeComponents}; +use rustc_structures::CrateType; use rustc_target::spec::TargetTuple; use smallvec::SmallVec; diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 0aec839025936..c30c68a1fa5c8 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -20,11 +20,12 @@ use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; use rustc_session::Session; use rustc_session::config::{ - self, CrateType, ErrorOutputType, Input, OutputType, OutputTypes, ResolveDocLinks, + self, ErrorOutputType, Input, OutputType, OutputTypes, ResolveDocLinks, }; pub(crate) use rustc_session::config::{Options, UnstableOptions}; use rustc_span::source_map; use rustc_span::symbol::sym; +use rustc_structures::CrateType; use tracing::{debug, info}; use crate::clean::inline::build_trait; diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 68d491618353a..f5ea54971b848 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -27,9 +27,10 @@ use rustc_hir::{Attribute, CRATE_HIR_ID}; use rustc_interface::interface; use rustc_lint as lint; use rustc_middle::ty::TyCtxt; -use rustc_session::config::{self, CrateType, ErrorOutputType, Input}; +use rustc_session::config::{self, ErrorOutputType, Input}; use rustc_span::edition::Edition; use rustc_span::{FileName, RemapPathScopeComponents, Span}; +use rustc_structures::CrateType; use rustc_target::spec::{Target, TargetTuple}; use tempfile::{Builder as TempFileBuilder, TempDir}; use tracing::{debug, info}; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index cf7d61c520f04..c4f7d2c361952 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -53,6 +53,7 @@ extern crate rustc_resolve; extern crate rustc_serialize; extern crate rustc_session; extern crate rustc_span; +extern crate rustc_structures; extern crate rustc_target; extern crate rustc_trait_selection; extern crate test; diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 815b82d5361c4..38d285f4fe86d 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -24,10 +24,10 @@ use rustc_resolve::rustdoc::{ MalformedGenerics, has_primitive_or_keyword_or_attribute_docs, prepare_to_doc_link_resolution, source_span_for_markdown_range, strip_generics_from_path, }; -use rustc_session::config::CrateType; use rustc_span::BytePos; use rustc_span::def_id::ModId; use rustc_span::symbol::{Ident, Symbol, sym}; +use rustc_structures::CrateType; use smallvec::{SmallVec, smallvec}; use tracing::{debug, info, instrument, trace}; diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index 8b0765fb6c012..c539edddf6a4d 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -38,8 +38,8 @@ extern crate rustc_lint; extern crate rustc_middle; extern crate rustc_parse_format; extern crate rustc_resolve; -extern crate rustc_session; extern crate rustc_span; +extern crate rustc_structures; extern crate rustc_target; extern crate rustc_trait_selection; diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index adad6a2b2cba2..f1baa6a697d78 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir::{ImplItem, ImplItemKind, Item, ItemKind, OwnerId, TraitFn, TraitItem, TraitItemKind, find_attr}; use rustc_lint::{LateContext, LateLintPass, declare_lint_pass}; -use rustc_session::config::CrateType; +use rustc_structures::CrateType; use rustc_span::Span; declare_clippy_lint! { From 9e9c3b1f1217b8c54df2c2d5bdb65b14b13ffa7c Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Mon, 17 Aug 2026 21:59:07 +0200 Subject: [PATCH 28/34] fix miri --- src/tools/miri/src/bin/miri.rs | 4 +++- src/tools/miri/src/helpers.rs | 2 +- src/tools/miri/src/lib.rs | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index ae9a64b0abcf4..f28bb524775ed 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -16,6 +16,7 @@ extern crate rustc_log; extern crate rustc_metadata; extern crate rustc_middle; extern crate rustc_session; +extern crate rustc_structures; // Override the C allocator in the same way that the `rustc` binary would do. rustc_driver::override_c_allocator_in_binary!(); @@ -44,7 +45,8 @@ use rustc_interface::util::DummyCodegenBackend; use rustc_log::tracing::debug; use rustc_middle::query::LocalCrate; use rustc_middle::ty::TyCtxt; -use rustc_session::config::{CrateType, ErrorOutputType, OptLevel}; +use rustc_structures::CrateType; +use rustc_session::config::{ ErrorOutputType, OptLevel}; use rustc_session::{EarlyDiagCtxt, Session}; use crate::log::setup::{deinit_loggers, init_early_loggers, init_late_loggers}; diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index 1e47ff4e56f1e..9bf202e8254e8 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -12,7 +12,7 @@ use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::exported_symbols::ExportedSymbol; use rustc_middle::ty::layout::{LayoutOf, MaybeResult, TyAndLayout}; use rustc_middle::ty::{self, FnSigKind, IntTy, Ty, TyCtxt, UintTy}; -use rustc_session::config::CrateType; +use rustc_structures::CrateType; use rustc_span::{Span, Symbol}; use rustc_symbol_mangling::mangle_internal_symbol; use rustc_target::spec::Os; diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index 7d878024b02e2..a2b6108882df3 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -73,6 +73,7 @@ extern crate rustc_log; extern crate rustc_middle; extern crate rustc_session; extern crate rustc_span; +extern crate rustc_structures; extern crate rustc_symbol_mangling; extern crate rustc_target; // Linking `rustc_driver` pulls in the required object code as the rest of the rustc crates are From c03400ec35ad58eaa5f9a0985127cfa8000c2f2c Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Tue, 18 Aug 2026 11:09:34 +0200 Subject: [PATCH 29/34] fix miri --- src/tools/miri/priroda/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tools/miri/priroda/src/main.rs b/src/tools/miri/priroda/src/main.rs index 74f5bd4f89c5d..44743c446091b 100644 --- a/src/tools/miri/priroda/src/main.rs +++ b/src/tools/miri/priroda/src/main.rs @@ -7,6 +7,7 @@ extern crate rustc_interface; extern crate rustc_middle; extern crate rustc_session; extern crate rustc_span; +extern crate rustc_structures; mod debugger; mod frontend; @@ -14,11 +15,11 @@ mod frontend; use debugger::PrirodaContext; use miri::*; use rustc_driver::Compilation; -use rustc_hir::attrs::CrateType; use rustc_interface::interface; use rustc_middle::ty::TyCtxt; use rustc_session::EarlyDiagCtxt; use rustc_session::config::ErrorOutputType; +use rustc_structures::CrateType; fn find_sysroot() -> String { std::env::var("MIRI_SYSROOT") From 20321fa9d0ace349abe233ade3d65841280da4b7 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Tue, 18 Aug 2026 12:29:53 +0200 Subject: [PATCH 30/34] fix tests --- compiler/rustc_interface/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 6f7688e021c39..1628c8466cdf6 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -8,7 +8,6 @@ use rustc_abi::Align; use rustc_data_structures::profiling::TimePassesFormat; use rustc_errors::ColorConfig; use rustc_errors::emitter::HumanReadableErrorType; -use rustc_hir::attrs::{CollapseMacroDebuginfo, NativeLibKind}; use rustc_lint_defs::Level; use rustc_session::config::{ AnnotateMoves, AutoDiff, BranchProtection, CFGuard, Cfg, CodegenRetagOptions, CoverageLevel, @@ -26,6 +25,7 @@ use rustc_session::{CompilerIO, EarlyDiagCtxt, Session, build_session, getopts}; use rustc_span::edition::{DEFAULT_EDITION, Edition}; use rustc_span::source_map::{RealFileLoader, SourceMapInputs}; use rustc_span::{FileName, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm, sym}; +use rustc_structures::{CollapseMacroDebuginfo, NativeLibKind}; use rustc_target::spec::{ CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel, From cf98f583f1b8dea30af2000d14ab8fe8997f170c Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Tue, 18 Aug 2026 14:36:57 +0200 Subject: [PATCH 31/34] fix fulldeps --- tests/ui-fulldeps/codegen-backend/auxiliary/the_backend.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ui-fulldeps/codegen-backend/auxiliary/the_backend.rs b/tests/ui-fulldeps/codegen-backend/auxiliary/the_backend.rs index 5ddaed75aa323..a147e3ddf6942 100644 --- a/tests/ui-fulldeps/codegen-backend/auxiliary/the_backend.rs +++ b/tests/ui-fulldeps/codegen-backend/auxiliary/the_backend.rs @@ -8,6 +8,7 @@ extern crate rustc_driver as _; extern crate rustc_metadata; extern crate rustc_middle; extern crate rustc_session; +extern crate rustc_structures; use std::any::Any; @@ -58,8 +59,9 @@ impl CodegenBackend for TheBackend { ) { use std::io::Write; - use rustc_session::config::{CrateType, OutFileName}; + use rustc_session::config::OutFileName; use rustc_session::output::out_filename; + use rustc_structures::CrateType; let crate_name = crate_info.local_crate_name; for &crate_type in sess.opts.crate_types.iter() { From d6e4a1d9685a294a60c77ba150f39b3c0d59b793 Mon Sep 17 00:00:00 2001 From: aerooneqq Date: Fri, 21 Aug 2026 11:03:21 +0000 Subject: [PATCH 32/34] delegation: simplify matches on `FnKind`, minor refactorings * More concise matches on `FnKind`, some renamings * Move most of utility functions to extensions * Address review comments * Revert "Move most of utility functions to extensions" * Address review comments --- compiler/rustc_hir_analysis/src/delegation.rs | 178 ++++++++---------- 1 file changed, 83 insertions(+), 95 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/delegation.rs b/compiler/rustc_hir_analysis/src/delegation.rs index ab34246d9716e..5324b4d3552c6 100644 --- a/compiler/rustc_hir_analysis/src/delegation.rs +++ b/compiler/rustc_hir_analysis/src/delegation.rs @@ -71,22 +71,23 @@ enum SelfPositionKind { None, } -fn create_self_position_kind( +fn create_self_param_position_kind( tcx: TyCtxt<'_>, - delegation_id: LocalDefId, + def_id: LocalDefId, sig_id: DefId, ) -> SelfPositionKind { - match (fn_kind(tcx, delegation_id), fn_kind(tcx, sig_id)) { - (FnKind::AssocInherentImpl, FnKind::AssocTrait) - | (FnKind::AssocTraitImpl, FnKind::AssocTrait) - | (FnKind::AssocTrait, FnKind::AssocTrait) - | (FnKind::AssocTrait, FnKind::Free) => SelfPositionKind::Zero, - + match fn_kinds(tcx, def_id, sig_id) { (FnKind::Free, FnKind::AssocTrait) => { - let kind = tcx.hir_delegation_info(delegation_id).self_ty_propagation_kind; + let kind = tcx.hir_delegation_info(def_id).self_ty_propagation_kind; SelfPositionKind::AfterLifetimes(kind) } + (_, FnKind::AssocTraitImpl) => unreachable!(), + + (_, FnKind::AssocTrait) | (FnKind::AssocTrait, _) => SelfPositionKind::Zero, + + (FnKind::AssocTraitImpl, _) => unreachable!(), + _ => SelfPositionKind::None, } } @@ -116,6 +117,17 @@ fn fn_kind<'tcx>(tcx: TyCtxt<'tcx>, def_id: impl Into) -> FnKind { } } +fn fn_kinds(tcx: TyCtxt<'_>, def_id: LocalDefId, sig_id: DefId) -> (FnKind, FnKind) { + let kinds = (fn_kind(tcx, def_id), fn_kind(tcx, sig_id)); + + // For trait impl's `sig_id` is always equal to the corresponding trait method. + assert!(!matches!(kinds, (_, FnKind::AssocTraitImpl))); + // Delegation to inherent impls is not yet supported. + assert!(!matches!(kinds, (_, FnKind::AssocInherentImpl))); + + kinds +} + /// Given the current context(caller and callee `FnKind`), it specifies /// the policy of predicates and generic parameters inheritance. #[derive(Clone, Copy, Debug, PartialEq)] @@ -152,7 +164,7 @@ fn create_mapping<'tcx>( ) -> FxHashMap { let mut mapping: FxHashMap = Default::default(); - let self_pos_kind = create_self_position_kind(tcx, def_id, sig_id); + let self_pos_kind = create_self_param_position_kind(tcx, def_id, sig_id); let is_self_at_zero = matches!(self_pos_kind, SelfPositionKind::Zero); // Is self at zero? If so insert mapping, self in sig parent is always at 0. @@ -215,30 +227,24 @@ fn create_mapping<'tcx>( fn get_delegation_parent_args_count_without_self<'tcx>( tcx: TyCtxt<'tcx>, - delegation_id: LocalDefId, + def_id: LocalDefId, sig_id: DefId, ) -> usize { - let delegation_parent_args_count = tcx.generics_of(delegation_id).parent_count; + let kinds @ (def_kind, _) = fn_kinds(tcx, def_id, sig_id); - match (fn_kind(tcx, delegation_id), fn_kind(tcx, sig_id)) { - (FnKind::Free, FnKind::Free) - | (FnKind::Free, FnKind::AssocTrait) - | (FnKind::AssocTraitImpl, FnKind::AssocTrait) => 0, + match kinds { + (FnKind::AssocTraitImpl, FnKind::AssocTrait) => 0, - (FnKind::AssocInherentImpl, FnKind::Free) - | (FnKind::AssocInherentImpl, FnKind::AssocTrait) => { - delegation_parent_args_count /* No Self in AssocInherentImpl */ - } + (FnKind::AssocTraitImpl, _) | (_, FnKind::AssocTraitImpl) => unreachable!(), - (FnKind::AssocTrait, FnKind::Free) | (FnKind::AssocTrait, FnKind::AssocTrait) => { - delegation_parent_args_count - 1 /* Without Self */ - } + (FnKind::Free, _) => 0, - // For trait impl's `sig_id` is always equal to the corresponding trait method. - // For inherent methods delegation is not yet supported. - (FnKind::AssocTraitImpl, _) - | (_, FnKind::AssocTraitImpl) - | (_, FnKind::AssocInherentImpl) => unreachable!(), + (_, _) => { + let delegation_parent_args_count = tcx.generics_of(def_id).parent_count; + let has_self = def_kind == FnKind::AssocTrait; + + delegation_parent_args_count - usize::from(has_self) + } } } @@ -247,75 +253,57 @@ fn get_parent_and_inheritance_kind<'tcx>( def_id: LocalDefId, sig_id: DefId, ) -> (Option, InheritanceKind) { - match (fn_kind(tcx, def_id), fn_kind(tcx, sig_id)) { - (FnKind::Free, FnKind::Free) | (FnKind::Free, FnKind::AssocTrait) => { - (None, InheritanceKind::WithParent(true)) - } + let kinds @ (_, sig_kind) = fn_kinds(tcx, def_id, sig_id); + match kinds { (FnKind::AssocTraitImpl, FnKind::AssocTrait) => { (Some(tcx.parent(def_id.to_def_id())), InheritanceKind::Own) } - (FnKind::AssocInherentImpl, FnKind::AssocTrait) - | (FnKind::AssocTrait, FnKind::AssocTrait) - | (FnKind::AssocInherentImpl, FnKind::Free) - | (FnKind::AssocTrait, FnKind::Free) => { - (Some(tcx.parent(def_id.to_def_id())), InheritanceKind::WithParent(false)) + (FnKind::AssocTraitImpl, _) | (_, FnKind::AssocTraitImpl) => unreachable!(), + + (FnKind::Free, _) => { + let copy_self_clauses = sig_kind == FnKind::AssocTrait; + (None, InheritanceKind::WithParent(copy_self_clauses)) } - // For trait impl's `sig_id` is always equal to the corresponding trait method. - // For inherent methods delegation is not yet supported. - (FnKind::AssocTraitImpl, _) - | (_, FnKind::AssocTraitImpl) - | (_, FnKind::AssocInherentImpl) => unreachable!(), + (_, _) => (Some(tcx.parent(def_id.to_def_id())), InheritanceKind::WithParent(false)), } } -fn get_delegation_self_ty<'tcx>(tcx: TyCtxt<'tcx>, delegation_id: LocalDefId) -> Option> { - let sig_id = tcx.hir_opt_delegation_sig_id(delegation_id).expect("Delegation must have sig_id"); - let (caller_kind, callee_kind) = (fn_kind(tcx, delegation_id), fn_kind(tcx, sig_id)); +fn get_delegation_self_ty<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Option> { + let sig_id = tcx.hir_opt_delegation_sig_id(def_id).expect("processing delegation"); + let (caller_kind, callee_kind) = fn_kinds(tcx, def_id, sig_id); match (caller_kind, callee_kind) { - (FnKind::Free, FnKind::AssocTrait) - | (FnKind::AssocInherentImpl, FnKind::Free) - | (FnKind::Free, FnKind::Free) - | (FnKind::AssocTrait, FnKind::Free) - | (FnKind::AssocTrait, FnKind::AssocTrait) => { - match create_self_position_kind(tcx, delegation_id, sig_id) { - SelfPositionKind::None => None, - SelfPositionKind::AfterLifetimes(propagation_kind) => { - Some(match propagation_kind { - Some(kind) => match kind { - DelegationSelfTyPropagationKind::SelfTy(self_ty_id) => { - let ctx = ItemCtxt::new(tcx, delegation_id); - ctx.lower_ty(tcx.hir_node(self_ty_id).expect_ty()) - } - DelegationSelfTyPropagationKind::SelfParam => { - let index = tcx.generics_of(delegation_id).own_counts().lifetimes; - Ty::new_param(tcx, index as u32, kw::SelfUpper) - } - }, - None => Ty::new_error_with_message( - tcx, - tcx.def_span(delegation_id), - "self propagation kind must be specified for `AfterLifetimes` variant", - ), - }) - } - SelfPositionKind::Zero => Some(Ty::new_param(tcx, 0, kw::SelfUpper)), - } + (FnKind::AssocTraitImpl, FnKind::AssocTrait) | (FnKind::AssocInherentImpl, _) => { + Some(tcx.type_of(tcx.local_parent(def_id)).instantiate_identity().skip_norm_wip()) } - (FnKind::AssocTraitImpl, FnKind::AssocTrait) - | (FnKind::AssocInherentImpl, FnKind::AssocTrait) => Some( - tcx.type_of(tcx.local_parent(delegation_id)).instantiate_identity().skip_norm_wip(), - ), - // For trait impl's `sig_id` is always equal to the corresponding trait method. - // For inherent methods delegation is not yet supported. - (FnKind::AssocTraitImpl, _) - | (_, FnKind::AssocTraitImpl) - | (_, FnKind::AssocInherentImpl) => unreachable!(), + (FnKind::AssocTraitImpl, _) | (_, FnKind::AssocTraitImpl) => unreachable!(), + + (_, _) => match create_self_param_position_kind(tcx, def_id, sig_id) { + SelfPositionKind::None => None, + SelfPositionKind::AfterLifetimes(propagation_kind) => Some(match propagation_kind { + Some(kind) => match kind { + DelegationSelfTyPropagationKind::SelfTy(self_ty_id) => { + let ctx = ItemCtxt::new(tcx, def_id); + ctx.lower_ty(tcx.hir_node(self_ty_id).expect_ty()) + } + DelegationSelfTyPropagationKind::SelfParam => { + let index = tcx.generics_of(def_id).own_counts().lifetimes; + Ty::new_param(tcx, index as u32, kw::SelfUpper) + } + }, + None => Ty::new_error_with_message( + tcx, + tcx.def_span(def_id), + "self propagation kind must be specified for `AfterLifetimes` variant", + ), + }), + SelfPositionKind::Zero => Some(Ty::new_param(tcx, 0, kw::SelfUpper)), + }, } } @@ -337,12 +325,12 @@ fn get_delegation_self_ty<'tcx>(tcx: TyCtxt<'tcx>, delegation_id: LocalDefId) -> fn create_generic_args<'tcx>( tcx: TyCtxt<'tcx>, sig_id: DefId, - delegation_id: LocalDefId, + def_id: LocalDefId, mut parent_args: &[ty::GenericArg<'tcx>], mut child_args: &[ty::GenericArg<'tcx>], ) -> (Vec>, &'tcx [ty::GenericArg<'tcx>]) { - let delegation_generics = tcx.generics_of(delegation_id); - let delegation_args = ty::GenericArgs::identity_for_item(tcx, delegation_id); + let delegation_generics = tcx.generics_of(def_id); + let delegation_args = ty::GenericArgs::identity_for_item(tcx, def_id); let real_args_count = delegation_args.len() - delegation_generics.own_synthetic_params_count(); let synth_args = &delegation_args[real_args_count..]; @@ -352,12 +340,12 @@ fn create_generic_args<'tcx>( let delegation_args = &delegation_args[delegation_generics.parent_count..]; - let kinds = (fn_kind(tcx, delegation_id), fn_kind(tcx, sig_id)); + let kinds = fn_kinds(tcx, def_id, sig_id); if matches!(kinds, (FnKind::AssocTraitImpl, FnKind::AssocTrait)) { // Special case, as user specifies Trait args in trait impl header, we want to treat // them as parent args. We always generate a function whose generics match // child generics in trait. - let parent = tcx.local_parent(delegation_id); + let parent = tcx.local_parent(def_id); parent_args = tcx.impl_trait_header(parent).trait_ref.instantiate_identity().skip_norm_wip().args; @@ -368,7 +356,7 @@ fn create_generic_args<'tcx>( delegation_parent_args = &[]; } - let self_type = get_delegation_self_ty(tcx, delegation_id).map(|t| t.into()); + let self_type = get_delegation_self_ty(tcx, def_id).map(ty::GenericArg::from); // Remove `Self` from parent args (it is always at the `0th` index) as it is // added manually. @@ -377,7 +365,7 @@ fn create_generic_args<'tcx>( } let (zero_self, after_lifetimes_self) = - match create_self_position_kind(tcx, delegation_id, sig_id) { + match create_self_param_position_kind(tcx, def_id, sig_id) { SelfPositionKind::AfterLifetimes(_) => { assert!(self_type.is_some()); (None, self_type) @@ -505,7 +493,7 @@ pub(crate) fn inherit_clauses_for_delegation_item<'tcx>( let (parent_args, child_args) = tcx.delegation_user_specified_args(def_id); let (folder, args) = create_folder_and_args(tcx, def_id, sig_id, parent_args, child_args); - let self_pos_kind = create_self_position_kind(tcx, def_id, sig_id); + let self_pos_kind = create_self_param_position_kind(tcx, def_id, sig_id); let filter_self_clauses = matches!( self_pos_kind, SelfPositionKind::AfterLifetimes(Some(DelegationSelfTyPropagationKind::SelfTy(..))) @@ -584,7 +572,6 @@ pub(crate) fn inherit_sig_for_delegation_item<'tcx>( ) -> &'tcx [Ty<'tcx>] { let sig_id = tcx.hir_opt_delegation_sig_id(def_id).expect("Delegation must have sig_id"); let caller_sig = tcx.fn_sig(sig_id); - if let Err(err) = check_constraints(tcx, def_id, sig_id) { let sig_len = caller_sig.instantiate_identity().skip_binder().inputs().len() + 1; let err_type = Ty::new_error(tcx, err); @@ -606,23 +593,24 @@ pub(crate) fn inherit_sig_for_delegation_item<'tcx>( // we want to extract [Self, 'static, i32, 1] for parent and [A, B] for child. pub(crate) fn delegation_user_specified_args<'tcx>( tcx: TyCtxt<'tcx>, - delegation_id: LocalDefId, + def_id: LocalDefId, ) -> (&'tcx [ty::GenericArg<'tcx>], &'tcx [ty::GenericArg<'tcx>]) { - let info = tcx.hir_delegation_info(delegation_id); + let info = tcx.hir_delegation_info(def_id); let get_segment = |hir_id| -> Option<(&'tcx PathSegment<'tcx>, DefId)> { let segment = tcx.hir_node(hir_id).expect_path_segment(); segment.res.opt_def_id().map(|def_id| (segment, def_id)) }; - let ctx = ItemCtxt::new_for_delegation(tcx, delegation_id); + let ctx = ItemCtxt::new_for_delegation(tcx, def_id); let lowerer = ctx.lowerer(); let parent_args = info .parent_seg_id_for_sig .and_then(get_segment) .filter(|(_, def_id)| matches!(tcx.def_kind(*def_id), DefKind::Trait)) .map(|(segment, def_id)| { - let self_ty = get_delegation_self_ty(tcx, delegation_id); + let self_ty = (tcx.def_kind(def_id) == DefKind::Trait) + .then(|| Ty::new_param(tcx, 0, kw::SelfUpper)); lowerer .lower_generic_args_of_path(segment.ident.span, def_id, &[], segment, self_ty) From ff619e2637dc788a980817d72acc0e40ebdee3eb Mon Sep 17 00:00:00 2001 From: Obei Sideg Date: Fri, 21 Aug 2026 13:54:02 +0300 Subject: [PATCH 33/34] Use attribute parser for `deprecated` attribute checking --- compiler/rustc_ast/src/visit.rs | 3 +- compiler/rustc_attr_ir/src/lang_items.rs | 44 ++++++++--------- compiler/rustc_attr_ir/src/target.rs | 20 ++++---- .../src/attributes/deprecation.rs | 31 ++++++++++-- .../rustc_attr_parsing/src/attributes/doc.rs | 8 +++- .../src/attributes/inline.rs | 4 +- .../src/attributes/link_attrs.rs | 4 +- .../src/attributes/prelude.rs | 2 +- .../src/attributes/rustc_dump.rs | 33 +++++++++---- .../src/attributes/rustc_internal.rs | 40 ++++++++++++---- .../src/attributes/stability.rs | 14 ++++-- .../rustc_attr_parsing/src/diagnostics.rs | 11 +++++ .../rustc_attr_parsing/src/target_checking.rs | 10 ++-- compiler/rustc_hir/src/lib.rs | 2 +- compiler/rustc_hir/src/target_impls.rs | 6 +-- compiler/rustc_passes/src/check_attr.rs | 47 +++++++++---------- compiler/rustc_passes/src/diagnostics.rs | 11 ----- 17 files changed, 183 insertions(+), 107 deletions(-) diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 166b3a9518a31..6b7ea072da61b 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -15,13 +15,14 @@ pub use rustc_ast_ir::visit::VisitorResult; pub use rustc_ast_ir::{try_visit, visit_opt, walk_list, walk_visitable_list}; +use rustc_macros::StableHash; use rustc_span::{Ident, Span, Spanned, Symbol}; use thin_vec::ThinVec; use crate::ast::*; use crate::tokenstream::DelimSpan; -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, StableHash)] pub enum AssocCtxt { Trait, Impl { of_trait: bool }, diff --git a/compiler/rustc_attr_ir/src/lang_items.rs b/compiler/rustc_attr_ir/src/lang_items.rs index fe631b5ea9859..7c91fbefa50e1 100644 --- a/compiler/rustc_attr_ir/src/lang_items.rs +++ b/compiler/rustc_attr_ir/src/lang_items.rs @@ -14,7 +14,7 @@ use rustc_span::def_id::DefId; use rustc_span::{Symbol, kw, sym}; use crate::PrintAttribute; -use crate::target::{MethodKind, Target}; +use crate::target::{AssocCtxt, MethodKind, Target}; /// All of the lang items, defined or not. /// Defined lang items can come from the current crate or its dependencies. @@ -161,8 +161,8 @@ language_item_table! { MetaSized, sym::meta_sized, meta_sized_trait, Target::Trait, GenericRequirement::Exact(0); PointeeSized, sym::pointee_sized, pointee_sized_trait, Target::Trait, GenericRequirement::Exact(0); Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1); - AlignOf, sym::mem_align_const, align_const, Target::AssocConst, GenericRequirement::Exact(0); - SizeOf, sym::mem_size_const, size_const, Target::AssocConst, GenericRequirement::Exact(0); + AlignOf, sym::mem_align_const, align_const, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0); + SizeOf, sym::mem_size_const, size_const, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0); OffsetOf, sym::offset_of, offset_of, Target::Fn, GenericRequirement::Exact(1); /// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ"). StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None; @@ -174,10 +174,10 @@ language_item_table! { Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0); DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None; /// The associated item of the `DiscriminantKind` trait. - Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy, GenericRequirement::None; + Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None; PointeeTrait, sym::pointee_trait, pointee_trait, Target::Trait, GenericRequirement::None; - Metadata, sym::metadata_type, metadata_type, Target::AssocTy, GenericRequirement::None; + Metadata, sym::metadata_type, metadata_type, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None; DynMetadata, sym::dyn_metadata, dyn_metadata, Target::Struct, GenericRequirement::None; NonNull, sym::non_null, non_null_trait, Target::Struct, GenericRequirement::Exact(1); @@ -241,9 +241,9 @@ language_item_table! { Deref, sym::deref, deref_trait, Target::Trait, GenericRequirement::Exact(0); DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait, GenericRequirement::Exact(0); DerefPure, sym::deref_pure, deref_pure_trait, Target::Trait, GenericRequirement::Exact(0); - DerefTarget, sym::deref_target, deref_target, Target::AssocTy, GenericRequirement::None; + DerefTarget, sym::deref_target, deref_target, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None; Receiver, sym::receiver, receiver_trait, Target::Trait, GenericRequirement::None; - ReceiverTarget, sym::receiver_target, receiver_target, Target::AssocTy, GenericRequirement::None; + ReceiverTarget, sym::receiver_target, receiver_target, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None; LegacyReceiver, sym::legacy_receiver, legacy_receiver_trait, Target::Trait, GenericRequirement::None; Fn, kw::Fn, fn_trait, Target::Trait, GenericRequirement::Exact(1); @@ -254,24 +254,24 @@ language_item_table! { AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1); AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1); AsyncFnOnce, sym::async_fn_once, async_fn_once_trait, Target::Trait, GenericRequirement::Exact(1); - AsyncFnOnceOutput, sym::async_fn_once_output, async_fn_once_output, Target::AssocTy, GenericRequirement::Exact(1); - CallOnceFuture, sym::call_once_future, call_once_future, Target::AssocTy, GenericRequirement::Exact(1); - CallRefFuture, sym::call_ref_future, call_ref_future, Target::AssocTy, GenericRequirement::Exact(2); + AsyncFnOnceOutput, sym::async_fn_once_output, async_fn_once_output, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(1); + CallOnceFuture, sym::call_once_future, call_once_future, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(1); + CallRefFuture, sym::call_ref_future, call_ref_future, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(2); AsyncFnKindHelper, sym::async_fn_kind_helper, async_fn_kind_helper, Target::Trait, GenericRequirement::Exact(1); - AsyncFnKindUpvars, sym::async_fn_kind_upvars, async_fn_kind_upvars, Target::AssocTy, GenericRequirement::Exact(5); + AsyncFnKindUpvars, sym::async_fn_kind_upvars, async_fn_kind_upvars, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(5); - FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None; + FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::None; Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0); FusedIterator, sym::fused_iterator, fused_iterator_trait, Target::Trait, GenericRequirement::Exact(0); Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0); - FutureOutput, sym::future_output, future_output, Target::AssocTy, GenericRequirement::Exact(0); + FutureOutput, sym::future_output, future_output, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(0); AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0); CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None; Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Exact(1); - CoroutineReturn, sym::coroutine_return, coroutine_return, Target::AssocTy, GenericRequirement::Exact(1); - CoroutineYield, sym::coroutine_yield, coroutine_yield, Target::AssocTy, GenericRequirement::Exact(1); + CoroutineReturn, sym::coroutine_return, coroutine_return, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(1); + CoroutineYield, sym::coroutine_yield, coroutine_yield, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(1); CoroutineResume, sym::coroutine_resume, coroutine_resume, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None; @@ -389,8 +389,8 @@ language_item_table! { PollPending, sym::Pending, poll_pending_variant, Target::Variant, GenericRequirement::None; AsyncGenReady, sym::AsyncGenReady, async_gen_ready, Target::Method(MethodKind::Inherent), GenericRequirement::Exact(1); - AsyncGenPending, sym::AsyncGenPending, async_gen_pending, Target::AssocConst, GenericRequirement::Exact(1); - AsyncGenFinished, sym::AsyncGenFinished, async_gen_finished, Target::AssocConst, GenericRequirement::Exact(1); + AsyncGenPending, sym::AsyncGenPending, async_gen_pending, Target::AssocConst(AssocCtxt::Impl { of_trait: false }), GenericRequirement::Exact(1); + AsyncGenFinished, sym::AsyncGenFinished, async_gen_finished, Target::AssocConst(AssocCtxt::Impl { of_trait: false }), GenericRequirement::Exact(1); // FIXME(swatinem): the following lang items are used for async lowering and // should become obsolete eventually. @@ -426,8 +426,8 @@ language_item_table! { Range, sym::Range, range_struct, Target::Struct, GenericRequirement::None; RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct, GenericRequirement::None; RangeTo, sym::RangeTo, range_to_struct, Target::Struct, GenericRequirement::None; - RangeMax, sym::RangeMax, range_max, Target::AssocConst, GenericRequirement::Exact(0); - RangeMin, sym::RangeMin, range_min, Target::AssocConst, GenericRequirement::Exact(0); + RangeMax, sym::RangeMax, range_max, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0); + RangeMin, sym::RangeMin, range_min, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0); RangeSub, sym::RangeSub, range_sub, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::Exact(0); // `new_range` types that are `Copy + IntoIterator` @@ -458,9 +458,9 @@ language_item_table! { // Field representing types. FieldRepresentingType, sym::field_representing_type, field_representing_type, Target::Struct, GenericRequirement::Exact(3); Field, sym::field, field, Target::Trait, GenericRequirement::Exact(0); - FieldBase, sym::field_base, field_base, Target::AssocTy, GenericRequirement::Exact(0); - FieldType, sym::field_type, field_type, Target::AssocTy, GenericRequirement::Exact(0); - FieldOffset, sym::field_offset, field_offset, Target::AssocConst, GenericRequirement::Exact(0); + FieldBase, sym::field_base, field_base, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(0); + FieldType, sym::field_type, field_type, Target::AssocTy(AssocCtxt::Trait), GenericRequirement::Exact(0); + FieldOffset, sym::field_offset, field_offset, Target::AssocConst(AssocCtxt::Trait), GenericRequirement::Exact(0); // Used to fallback `{float}` to `f32` when `f32: From<{float}>` From, sym::From, from_trait, Target::Trait, GenericRequirement::Exact(1); diff --git a/compiler/rustc_attr_ir/src/target.rs b/compiler/rustc_attr_ir/src/target.rs index 762ae3b6129e1..8b8cd9db634da 100644 --- a/compiler/rustc_attr_ir/src/target.rs +++ b/compiler/rustc_attr_ir/src/target.rs @@ -2,7 +2,7 @@ use std::fmt::{self, Display}; -use rustc_ast::visit::AssocCtxt; +pub use rustc_ast::visit::AssocCtxt; use rustc_ast::{AssocItemKind, ForeignItemKind, ast}; use rustc_macros::StableHash; @@ -49,9 +49,9 @@ pub enum Target { Expression, Statement, Arm, - AssocConst, + AssocConst(AssocCtxt), Method(MethodKind), - AssocTy, + AssocTy(AssocCtxt), ForeignFn, ForeignStatic, ForeignTy, @@ -81,7 +81,7 @@ rustc_error_messages::into_diag_arg_using_display!(Target); impl Target { pub fn is_associated_item(self) -> bool { match self { - Target::AssocConst | Target::AssocTy | Target::Method(_) => true, + Target::AssocConst(_) | Target::AssocTy(_) | Target::Method(_) => true, Target::ExternCrate | Target::Use | Target::Static @@ -157,7 +157,7 @@ impl Target { pub fn from_assoc_item_kind(kind: &ast::AssocItemKind, assoc_ctxt: AssocCtxt) -> Target { match kind { - AssocItemKind::Const(_) => Target::AssocConst, + AssocItemKind::Const(_) => Target::AssocConst(assoc_ctxt), AssocItemKind::Fn(f) => Target::Method(match assoc_ctxt { AssocCtxt::Trait => MethodKind::Trait { body: f.body.is_some() }, AssocCtxt::Impl { of_trait, .. } => { @@ -168,7 +168,7 @@ impl Target { } } }), - AssocItemKind::Type(_) => Target::AssocTy, + AssocItemKind::Type(_) => Target::AssocTy(assoc_ctxt), AssocItemKind::Delegation(_) => Target::Delegation { mac: false }, AssocItemKind::DelegationMac(_) => Target::Delegation { mac: true }, AssocItemKind::MacCall(_) => Target::MacroCall, @@ -210,14 +210,14 @@ impl Target { Target::Expression => "expression", Target::Statement => "statement", Target::Arm => "match arm", - Target::AssocConst => "associated const", + Target::AssocConst(_) => "associated const", Target::Method(kind) => match kind { MethodKind::Inherent => "inherent method", MethodKind::Trait { body: false } => "required trait method", MethodKind::Trait { body: true } => "provided trait method", MethodKind::TraitImpl => "trait method in an impl block", }, - Target::AssocTy => "associated type", + Target::AssocTy(_) => "associated type", Target::ForeignFn => "foreign function", Target::ForeignStatic => "foreign static item", Target::ForeignTy => "foreign type", @@ -265,14 +265,14 @@ impl Target { Target::Expression => "expressions", Target::Statement => "statements", Target::Arm => "match arms", - Target::AssocConst => "associated consts", + Target::AssocConst(_) => "associated consts", Target::Method(kind) => match kind { MethodKind::Inherent => "inherent methods", MethodKind::Trait { body: false } => "required trait methods", MethodKind::Trait { body: true } => "provided trait methods", MethodKind::TraitImpl => "trait methods in impl blocks", }, - Target::AssocTy => "associated types", + Target::AssocTy(_) => "associated types", Target::ForeignFn => "foreign functions", Target::ForeignStatic => "foreign statics", Target::ForeignTy => "foreign types", diff --git a/compiler/rustc_attr_parsing/src/attributes/deprecation.rs b/compiler/rustc_attr_parsing/src/attributes/deprecation.rs index fb35e5169caba..b68042c39670c 100644 --- a/compiler/rustc_attr_parsing/src/attributes/deprecation.rs +++ b/compiler/rustc_attr_parsing/src/attributes/deprecation.rs @@ -1,10 +1,15 @@ use rustc_ast::LitKind; use rustc_attr_ir::{DeprecatedSince, Deprecation, RustcVersion, VERSION_PLACEHOLDER}; use rustc_feature::AttributeStability; +use rustc_lint_defs::builtin::UNUSED_ATTRIBUTES; use super::prelude::*; use super::util::parse_version; -use crate::diagnostics::{DeprecatedItemSuggestion, InvalidSince, MissingNote, MissingSince}; +use crate::diagnostics::{ + DeprecatedAnnotationHasNoEffect, DeprecatedItemSuggestion, InvalidSince, MissingNote, + MissingSince, +}; +use crate::target_checking::Policy::AllowSilent; fn get( cx: &mut AcceptContext<'_, '_>, @@ -48,8 +53,12 @@ impl SingleAttributeParser for DeprecatedParser { Allow(Target::ForeignTy), Allow(Target::Field), Allow(Target::Trait), - Allow(Target::AssocTy), - Allow(Target::AssocConst), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + AllowSilent(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Trait)), + AllowSilent(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), Allow(Target::Variant), Allow(Target::Impl { of_trait: false }), Allow(Target::Crate), @@ -182,6 +191,22 @@ impl SingleAttributeParser for DeprecatedParser { return None; } + // `#[deprecated]` on trait-impl associated items has no effect (deprecation comes from the + // trait definition). Methods also get `useless_deprecated` from target checking. + if matches!( + cx.target, + Target::Method(MethodKind::TraitImpl) + | Target::AssocConst(AssocCtxt::Impl { of_trait: true }) + | Target::AssocTy(AssocCtxt::Impl { of_trait: true }) + ) { + let attr_span = cx.attr_span; + cx.emit_lint( + UNUSED_ATTRIBUTES, + DeprecatedAnnotationHasNoEffect { span: attr_span }, + attr_span, + ); + } + Some(AttributeKind::Deprecated { deprecation: Deprecation { since, note, suggestion }, span: cx.attr_span, diff --git a/compiler/rustc_attr_parsing/src/attributes/doc.rs b/compiler/rustc_attr_parsing/src/attributes/doc.rs index 1f1c82c051f44..7b0df693debf5 100644 --- a/compiler/rustc_attr_parsing/src/attributes/doc.rs +++ b/compiler/rustc_attr_parsing/src/attributes/doc.rs @@ -777,12 +777,16 @@ impl AttributeParser for DocParser { // Allow(Target::TraitAlias), // Allow(Target::Impl { of_trait: true }), // Allow(Target::Impl { of_trait: false }), - // Allow(Target::AssocConst), + // Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + // Allow(Target::AssocConst(AssocCtxt::Trait)), + // Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), // Allow(Target::Method(MethodKind::Inherent)), // Allow(Target::Method(MethodKind::Trait { body: true })), // Allow(Target::Method(MethodKind::Trait { body: false })), // Allow(Target::Method(MethodKind::TraitImpl)), - // Allow(Target::AssocTy), + // Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + // Allow(Target::AssocTy(AssocCtxt::Trait)), + // Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), // Allow(Target::ForeignFn), // Allow(Target::ForeignStatic), // Allow(Target::ForeignTy), diff --git a/compiler/rustc_attr_parsing/src/attributes/inline.rs b/compiler/rustc_attr_parsing/src/attributes/inline.rs index b63fb27ce6707..f3e305ea266a1 100644 --- a/compiler/rustc_attr_parsing/src/attributes/inline.rs +++ b/compiler/rustc_attr_parsing/src/attributes/inline.rs @@ -22,7 +22,9 @@ impl SingleAttributeParser for InlineParser { Warn(Target::Field), Warn(Target::MacroDef), Warn(Target::Arm), - Warn(Target::AssocConst), + Warn(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Warn(Target::AssocConst(AssocCtxt::Trait)), + Warn(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), Warn(Target::MacroCall), ]); const TEMPLATE: AttributeTemplate = template!( diff --git a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs index 6d25e7fb00183..9f7b27532ea06 100644 --- a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs @@ -547,7 +547,9 @@ impl NoArgsAttributeParser for ExportStableParser { Allow(Target::Enum), Allow(Target::Union), Allow(Target::TyAlias), - Allow(Target::AssocTy), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), Allow(Target::Use), Allow(Target::Mod), Allow(Target::Impl { of_trait: false }), diff --git a/compiler/rustc_attr_parsing/src/attributes/prelude.rs b/compiler/rustc_attr_parsing/src/attributes/prelude.rs index 0721d6f1926ae..76ce02833d797 100644 --- a/compiler/rustc_attr_parsing/src/attributes/prelude.rs +++ b/compiler/rustc_attr_parsing/src/attributes/prelude.rs @@ -2,7 +2,7 @@ #[doc(hidden)] pub(super) use rustc_attr_ir::AttributeKind; #[doc(hidden)] -pub(super) use rustc_attr_ir::target::{MethodKind, Target}; +pub(super) use rustc_attr_ir::target::{AssocCtxt, MethodKind, Target}; #[doc(hidden)] pub(super) use rustc_span::{Ident, Span, Symbol, sym}; #[doc(hidden)] diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs index a8cc501f2ed19..99c7e933b07b4 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs @@ -1,4 +1,4 @@ -use rustc_attr_ir::target::{MethodKind, Target}; +use rustc_attr_ir::target::{AssocCtxt, MethodKind, Target}; use rustc_attr_ir::{AttributeKind, RustcDumpLayoutKind}; use rustc_feature::AttributeStability; use rustc_span::{Span, Symbol, sym}; @@ -59,8 +59,12 @@ impl NoArgsAttributeParser for RustcDumpGenericsParser { Allow(Target::Closure), Allow(Target::TyAlias), Allow(Target::Const), - Allow(Target::AssocConst), - Allow(Target::AssocTy), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), Allow(Target::Impl { of_trait: false }), Allow(Target::Impl { of_trait: true }), Allow(Target::Method(MethodKind::Inherent)), @@ -101,8 +105,11 @@ pub(crate) struct RustcDumpItemBoundsParser; impl NoArgsAttributeParser for RustcDumpItemBoundsParser { const PATH: &[Symbol] = &[sym::rustc_dump_item_bounds]; - const ALLOWED_TARGETS: AllowedTargets<'_> = - AllowedTargets::AllowList(&[Allow(Target::AssocTy)]); + const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), + ]); const STABILITY: AttributeStability = unstable!(rustc_attrs); const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpItemBounds; } @@ -176,8 +183,12 @@ pub(crate) struct RustcDumpObjectLifetimeDefaultsParser; impl NoArgsAttributeParser for RustcDumpObjectLifetimeDefaultsParser { const PATH: &[Symbol] = &[sym::rustc_dump_object_lifetime_defaults]; const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ - Allow(Target::AssocConst), - Allow(Target::AssocTy), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), Allow(Target::Const), Allow(Target::Enum), Allow(Target::Fn), @@ -203,8 +214,12 @@ pub(crate) struct RustcDumpClausesParser; impl NoArgsAttributeParser for RustcDumpClausesParser { const PATH: &[Symbol] = &[sym::rustc_dump_clauses]; const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ - Allow(Target::AssocConst), - Allow(Target::AssocTy), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), Allow(Target::Const), Allow(Target::Delegation { mac: false }), Allow(Target::Delegation { mac: true }), diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs index dddd61e9f0ba0..f1860acc4c05a 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs @@ -777,8 +777,12 @@ impl CombineAttributeParser for RustcCleanParser { const CONVERT: ConvertFn = |items, _| AttributeKind::RustcClean(items); const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ // tidy-alphabetical-start - Allow(Target::AssocConst), - Allow(Target::AssocTy), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocTy(AssocCtxt::Trait)), Allow(Target::Const), Allow(Target::Enum), Allow(Target::Expression), @@ -870,8 +874,12 @@ impl SingleAttributeParser for RustcIfThisChangedParser { const PATH: &[Symbol] = &[sym::rustc_if_this_changed]; const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ // tidy-alphabetical-start - Allow(Target::AssocConst), - Allow(Target::AssocTy), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocTy(AssocCtxt::Trait)), Allow(Target::Const), Allow(Target::Enum), Allow(Target::Expression), @@ -928,8 +936,12 @@ impl CombineAttributeParser for RustcThenThisWouldNeedParser { |items, _span| AttributeKind::RustcThenThisWouldNeed(items); const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ // tidy-alphabetical-start - Allow(Target::AssocConst), - Allow(Target::AssocTy), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocTy(AssocCtxt::Trait)), Allow(Target::Const), Allow(Target::Enum), Allow(Target::Expression), @@ -1004,12 +1016,16 @@ impl NoArgsAttributeParser for RustcEffectiveVisibilityParser { Allow(Target::TraitAlias), Allow(Target::Impl { of_trait: false }), Allow(Target::Impl { of_trait: true }), - Allow(Target::AssocConst), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), Allow(Target::Method(MethodKind::Inherent)), Allow(Target::Method(MethodKind::Trait { body: false })), Allow(Target::Method(MethodKind::Trait { body: true })), Allow(Target::Method(MethodKind::TraitImpl)), - Allow(Target::AssocTy), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), Allow(Target::ForeignFn), Allow(Target::ForeignStatic), Allow(Target::ForeignTy), @@ -1031,8 +1047,12 @@ impl SingleAttributeParser for RustcDiagnosticItemParser { Allow(Target::Enum), Allow(Target::MacroDef), Allow(Target::TyAlias), - Allow(Target::AssocTy), - Allow(Target::AssocConst), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), Allow(Target::Fn), Allow(Target::Const), Allow(Target::Mod), diff --git a/compiler/rustc_attr_parsing/src/attributes/stability.rs b/compiler/rustc_attr_parsing/src/attributes/stability.rs index 6bdb14548cfee..6dbbe0bf4d0c8 100644 --- a/compiler/rustc_attr_parsing/src/attributes/stability.rs +++ b/compiler/rustc_attr_parsing/src/attributes/stability.rs @@ -1,6 +1,6 @@ use std::num::NonZero; -use rustc_attr_ir::target::{GenericParamKind, MethodKind, Target}; +use rustc_attr_ir::target::{AssocCtxt, GenericParamKind, MethodKind, Target}; use rustc_attr_ir::{ DefaultBodyStability, PartialConstStability, Stability, StabilityLevel, StableSince, UnstableReason, UnstableRemovedFeature, VERSION_PLACEHOLDER, @@ -28,8 +28,12 @@ const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ Allow(Target::Mod), Allow(Target::Use), // FIXME I don't think this does anything? Allow(Target::Const), - Allow(Target::AssocConst), - Allow(Target::AssocTy), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), Allow(Target::Trait), Allow(Target::TraitAlias), Allow(Target::TyAlias), @@ -240,7 +244,9 @@ impl AttributeParser for ConstStabilityParser { Allow(Target::Impl { of_trait: true }), Allow(Target::Use), // FIXME I don't think this does anything? Allow(Target::Const), - Allow(Target::AssocConst), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), Allow(Target::Trait), Allow(Target::Static), Allow(Target::Crate), diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index 9d72bdcb75ce3..a37d56419adac 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -1149,6 +1149,17 @@ pub(crate) struct DeprecatedItemSuggestion { pub details: (), } +#[derive(Diagnostic)] +#[diag("this `#[deprecated]` annotation has no effect")] +pub(crate) struct DeprecatedAnnotationHasNoEffect { + #[suggestion( + "remove the unnecessary deprecation attribute", + applicability = "machine-applicable", + code = "" + )] + pub span: Span, +} + #[derive(Diagnostic)] #[diag("expected single version literal")] pub(crate) struct ExpectedSingleVersionLiteral { diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 686a0b139e94d..1e272b9674dab 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use rustc_ast::{AttrStyle, Safety}; -use rustc_attr_ir::target::{MethodKind, Target}; +use rustc_attr_ir::target::{AssocCtxt, MethodKind, Target}; use rustc_attr_ir::{AttrItem, Attribute, AttributeKind}; use rustc_errors::{DiagArgValue, MultiSpan, StashKey}; use rustc_feature::Features; @@ -510,12 +510,16 @@ pub(crate) const ALL_TARGETS: &[Policy] = { Allow(Target::Expression), Allow(Target::Statement), Allow(Target::Arm), - Allow(Target::AssocConst), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocConst(AssocCtxt::Trait)), + Allow(Target::AssocConst(AssocCtxt::Impl { of_trait: true })), Allow(Target::Method(MethodKind::Inherent)), Allow(Target::Method(MethodKind::Trait { body: false })), Allow(Target::Method(MethodKind::Trait { body: true })), Allow(Target::Method(MethodKind::TraitImpl)), - Allow(Target::AssocTy), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: false })), + Allow(Target::AssocTy(AssocCtxt::Trait)), + Allow(Target::AssocTy(AssocCtxt::Impl { of_trait: true })), Allow(Target::ForeignFn), Allow(Target::ForeignStatic), Allow(Target::ForeignTy), diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index 8fa3b0e83aafe..0b279f334e9fb 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -31,7 +31,7 @@ pub use rustc_span::def_id; // FIXME: Remove this use tree, replace by `rustc_hir::attrs` or `rustc_attr_ir` imports #[doc(hidden)] pub use { - attrs::target::{self, MethodKind, Target}, + attrs::target::{self, AssocCtxt, MethodKind, Target}, attrs::{ AttrArgs, AttrItem, AttrPath, Attribute, ConstStability, DefaultBodyStability, HashIgnoredAttrId, PartialConstStability, Stability, StabilityLevel, StableSince, diff --git a/compiler/rustc_hir/src/target_impls.rs b/compiler/rustc_hir/src/target_impls.rs index 57564bd815595..ecc9a381c6b6c 100644 --- a/compiler/rustc_hir/src/target_impls.rs +++ b/compiler/rustc_hir/src/target_impls.rs @@ -1,6 +1,6 @@ //! Implements conversions from HIR types to Target. -use rustc_attr_ir::target::{GenericParamKind, MethodKind, Target}; +use rustc_attr_ir::target::{AssocCtxt, GenericParamKind, MethodKind, Target}; use crate::def::DefKind; use crate::{self as hir, ItemKind, TraitItemKind}; @@ -36,14 +36,14 @@ impl From<&hir::GenericParam<'_>> for Target { impl From<&hir::TraitItem<'_>> for Target { fn from(trait_item: &hir::TraitItem<'_>) -> Target { match trait_item.kind { - TraitItemKind::Const(..) => Target::AssocConst, + TraitItemKind::Const(..) => Target::AssocConst(AssocCtxt::Trait), TraitItemKind::Fn(_, hir::TraitFn::Required(_)) => { Target::Method(MethodKind::Trait { body: false }) } TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => { Target::Method(MethodKind::Trait { body: true }) } - TraitItemKind::Type(..) => Target::AssocTy, + TraitItemKind::Type(..) => Target::AssocTy(AssocCtxt::Trait), } } } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 3a3b0ed519708..dbe56185e5180 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -24,7 +24,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalModId; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{ - self as hir, Attribute, CRATE_HIR_ID, Constness, FnSig, ForeignItem, GenericParam, + self as hir, AssocCtxt, Attribute, CRATE_HIR_ID, Constness, FnSig, ForeignItem, GenericParam, GenericParamKind, HirId, Item, ItemKind, MethodKind, Mod, Node, ParamName, Target, TraitItem, find_attr, }; @@ -60,7 +60,15 @@ struct DiagnosticOnConstOnlyForNonConstTraitImpls { fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target { match impl_item.kind { - hir::ImplItemKind::Const(..) => Target::AssocConst, + hir::ImplItemKind::Const(..) => { + let parent_def_id = tcx.hir_get_parent_item(impl_item.hir_id()).def_id; + let containing_item = tcx.hir_expect_item(parent_def_id); + let of_trait = match &containing_item.kind { + hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(), + _ => bug!("parent of an ImplItem must be an Impl"), + }; + Target::AssocConst(AssocCtxt::Impl { of_trait }) + } hir::ImplItemKind::Fn(..) => { let parent_def_id = tcx.hir_get_parent_item(impl_item.hir_id()).def_id; let containing_item = tcx.hir_expect_item(parent_def_id); @@ -74,7 +82,15 @@ fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) Target::Method(MethodKind::Inherent) } } - hir::ImplItemKind::Type(..) => Target::AssocTy, + hir::ImplItemKind::Type(..) => { + let parent_def_id = tcx.hir_get_parent_item(impl_item.hir_id()).def_id; + let containing_item = tcx.hir_expect_item(parent_def_id); + let of_trait = match &containing_item.kind { + hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(), + _ => bug!("parent of an ImplItem must be an Impl"), + }; + Target::AssocTy(AssocCtxt::Impl { of_trait }) + } } } @@ -190,9 +206,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::RustcAllowConstFnUnstable(_, first_span) => { self.check_rustc_allow_const_fn_unstable(hir_id, *first_span, span, target) } - AttributeKind::Deprecated { span: attr_span, .. } => { - self.check_deprecated(hir_id, *attr_span, target) - } AttributeKind::Naked(..) => self.check_naked(hir_id, target), AttributeKind::NonExhaustive(attr_span) => { self.check_non_exhaustive(*attr_span, span, target, item) @@ -245,6 +258,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::CustomMir(..) => (), AttributeKind::DebuggerVisualizer(..) => (), AttributeKind::DefaultLibAllocator => (), + AttributeKind::Deprecated { .. } => (), AttributeKind::DoNotRecommend => (), // `#[doc]` is actually a lot more than just doc comments, so is checked below AttributeKind::DocComment { .. } => (), @@ -810,7 +824,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { fn check_doc_alias_value(&self, span: Span, hir_id: HirId, target: Target, alias: Symbol) { if let Some(location) = match target { - Target::AssocTy => { + Target::AssocTy(_) => { if let DefKind::Impl { .. } = self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id)) { @@ -819,7 +833,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { None } } - Target::AssocConst => { + Target::AssocConst(_) => { let parent_def_id = self.tcx.hir_get_parent_item(hir_id).def_id; let containing_item = self.tcx.hir_expect_item(parent_def_id); // We can't link to trait impl's consts. @@ -1280,23 +1294,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } - fn check_deprecated(&self, hir_id: HirId, attr_span: Span, target: Target) { - match target { - Target::AssocConst | Target::Method(..) | Target::AssocTy - if self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id)) - == DefKind::Impl { of_trait: true } => - { - self.tcx.emit_node_span_lint( - UNUSED_ATTRIBUTES, - hir_id, - attr_span, - diagnostics::DeprecatedAnnotationHasNoEffect { span: attr_span }, - ); - } - _ => {} - } - } - fn check_macro_export(&self, hir_id: HirId, attr_span: Span, target: Target) { if target != Target::MacroDef { return; diff --git a/compiler/rustc_passes/src/diagnostics.rs b/compiler/rustc_passes/src/diagnostics.rs index 16a2cc4007318..9864e9debf9d8 100644 --- a/compiler/rustc_passes/src/diagnostics.rs +++ b/compiler/rustc_passes/src/diagnostics.rs @@ -283,17 +283,6 @@ pub(crate) struct InvalidMayDangle { pub attr_span: Span, } -#[derive(Diagnostic)] -#[diag("this `#[deprecated]` annotation has no effect")] -pub(crate) struct DeprecatedAnnotationHasNoEffect { - #[suggestion( - "remove the unnecessary deprecation attribute", - applicability = "machine-applicable", - code = "" - )] - pub span: Span, -} - #[derive(Diagnostic)] #[diag("`#[panic_handler]` function required, but not found")] pub(crate) struct MissingPanicHandler; From da0ecbbb866c384fb6268877166f328f56c0d977 Mon Sep 17 00:00:00 2001 From: Obei Sideg Date: Fri, 21 Aug 2026 14:00:26 +0300 Subject: [PATCH 34/34] Use `MethodKind::TraitImpl` for methods in trait impls --- compiler/rustc_passes/src/check_attr.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index dbe56185e5180..1e60c5f9802e5 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -77,7 +77,7 @@ fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) _ => bug!("parent of an ImplItem must be an Impl"), }; if containing_impl_is_for_trait { - Target::Method(MethodKind::Trait { body: true }) + Target::Method(MethodKind::TraitImpl) } else { Target::Method(MethodKind::Inherent) } @@ -749,7 +749,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match target { Target::Fn | Target::Closure - | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => { + | Target::Method( + MethodKind::Trait { body: true } | MethodKind::TraitImpl | MethodKind::Inherent, + ) => { // `#[inline]` is ignored if the symbol must be codegened upstream because it's exported. if let Some(did) = hir_id.as_owner() && self.tcx.def_kind(did).has_codegen_attrs() @@ -775,7 +777,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { fn check_naked(&self, hir_id: HirId, target: Target) { match target { Target::Fn - | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => { + | Target::Method( + MethodKind::Trait { body: true } | MethodKind::TraitImpl | MethodKind::Inherent, + ) => { let fn_sig = self.tcx.hir_node(hir_id).fn_sig().unwrap(); let abi = fn_sig.header.abi; if abi.is_rustic_abi() && !self.tcx.features().naked_functions_rustic_abi() {