From 9febbf827088cc8e94b2799e6c5976997bb88c65 Mon Sep 17 00:00:00 2001 From: Christopher Berner Date: Tue, 6 May 2025 20:18:06 -0700 Subject: [PATCH 01/10] Remove unnecessary handling of ERROR_IO_PENDING try_lock() and try_lock_shared() do not need to handle these per the discussion in https://github.com/rust-lang/rust/pull/140718#discussion_r2076678485 --- library/std/src/fs/tests.rs | 22 ++++++++++++++++++++++ library/std/src/sys/fs/windows.rs | 10 ++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 46b0d832fec45..49f99351c8aaf 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -366,6 +366,28 @@ fn file_lock_blocking_async() { t.join().unwrap(); } +#[test] +#[cfg(windows)] +fn file_try_lock_async() { + const FILE_FLAG_OVERLAPPED: u32 = 0x40000000; + + let tmpdir = tmpdir(); + let filename = &tmpdir.join("file_try_lock_async.txt"); + let f1 = check!(File::create(filename)); + let f2 = + check!(OpenOptions::new().custom_flags(FILE_FLAG_OVERLAPPED).write(true).open(filename)); + + // Check that shared locks block exclusive locks + check!(f1.lock_shared()); + assert_matches!(f2.try_lock(), Err(TryLockError::WouldBlock)); + check!(f1.unlock()); + + // Check that exclusive locks block all locks + check!(f1.lock()); + assert_matches!(f2.try_lock(), Err(TryLockError::WouldBlock)); + assert_matches!(f2.try_lock_shared(), Err(TryLockError::WouldBlock)); +} + #[test] fn file_test_io_seek_shakedown() { // 01234567890123 diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index 9039fd00f5d62..d01a572ac7332 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -415,10 +415,7 @@ impl File { match result { Ok(_) => Ok(()), - Err(err) - if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32) - || err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32) => - { + Err(err) if err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32) => { Err(TryLockError::WouldBlock) } Err(err) => Err(TryLockError::Error(err)), @@ -440,10 +437,7 @@ impl File { match result { Ok(_) => Ok(()), - Err(err) - if err.raw_os_error() == Some(c::ERROR_IO_PENDING as i32) - || err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32) => - { + Err(err) if err.raw_os_error() == Some(c::ERROR_LOCK_VIOLATION as i32) => { Err(TryLockError::WouldBlock) } Err(err) => Err(TryLockError::Error(err)), From fd260d530b880c44874340eaf2e31666a138a874 Mon Sep 17 00:00:00 2001 From: Christopher Berner Date: Tue, 20 May 2025 14:04:38 -0700 Subject: [PATCH 02/10] Add From for io::Error This makes error propagation from try_lock() and try_lock_shared() more convenient --- library/std/src/fs.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 11f439b9996de..4be52ac1eb386 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -392,6 +392,16 @@ impl fmt::Display for TryLockError { } } +#[unstable(feature = "file_lock", issue = "130994")] +impl From for io::Error { + fn from(err: TryLockError) -> io::Error { + match err { + TryLockError::Error(err) => err, + TryLockError::WouldBlock => io::ErrorKind::WouldBlock.into(), + } + } +} + impl File { /// Attempts to open a file in read-only mode. /// @@ -821,11 +831,14 @@ impl File { /// /// fn main() -> std::io::Result<()> { /// let f = File::create("foo.txt")?; + /// // Explicit handling of the WouldBlock error /// match f.try_lock() { /// Ok(_) => (), /// Err(TryLockError::WouldBlock) => (), // Lock not acquired /// Err(TryLockError::Error(err)) => return Err(err), /// } + /// // Alternately, propagate the error as an io::Error + /// f.try_lock()?; /// Ok(()) /// } /// ``` @@ -882,11 +895,14 @@ impl File { /// /// fn main() -> std::io::Result<()> { /// let f = File::open("foo.txt")?; + /// // Explicit handling of the WouldBlock error /// match f.try_lock_shared() { /// Ok(_) => (), /// Err(TryLockError::WouldBlock) => (), // Lock not acquired /// Err(TryLockError::Error(err)) => return Err(err), /// } + /// // Alternately, propagate the error as an io::Error + /// f.try_lock_shared()?; /// /// Ok(()) /// } From 7fdf35ed1cf7e374f6822ba980c48c77ba7fa9de Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Tue, 27 May 2025 14:24:18 +0800 Subject: [PATCH 03/10] remove `visit_mt` from `ast::mut_visit` doesn't look like anyone is using it. --- compiler/rustc_ast/src/mut_visit.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 6770fd5a4aaeb..0006886fddfc7 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -306,10 +306,6 @@ pub trait MutVisitor: Sized { walk_precise_capturing_arg(self, arg); } - fn visit_mt(&mut self, mt: &mut MutTy) { - walk_mt(self, mt); - } - fn visit_expr_field(&mut self, f: &mut ExprField) { walk_expr_field(self, f); } @@ -535,10 +531,10 @@ pub fn walk_ty(vis: &mut T, ty: &mut P) { TyKind::Infer | TyKind::ImplicitSelf | TyKind::Dummy | TyKind::Never | TyKind::CVarArgs => { } TyKind::Slice(ty) => vis.visit_ty(ty), - TyKind::Ptr(mt) => vis.visit_mt(mt), - TyKind::Ref(lt, mt) | TyKind::PinnedRef(lt, mt) => { + TyKind::Ptr(MutTy { ty, mutbl: _ }) => vis.visit_ty(ty), + TyKind::Ref(lt, MutTy { ty, mutbl: _ }) | TyKind::PinnedRef(lt, MutTy { ty, mutbl: _ }) => { visit_opt(lt, |lt| vis.visit_lifetime(lt)); - vis.visit_mt(mt); + vis.visit_ty(ty); } TyKind::BareFn(bft) => { let BareFnTy { safety, ext: _, generic_params, decl, decl_span } = bft.deref_mut(); @@ -1019,10 +1015,6 @@ pub fn walk_flat_map_expr_field( smallvec![f] } -fn walk_mt(vis: &mut T, MutTy { ty, mutbl: _ }: &mut MutTy) { - vis.visit_ty(ty); -} - pub fn walk_block(vis: &mut T, block: &mut P) { let Block { id, stmts, rules: _, span, tokens: _ } = block.deref_mut(); vis.visit_id(id); From dd148a06961e4e19a8d1788ed8c759e0394d48c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 27 May 2025 10:39:32 +0200 Subject: [PATCH 04/10] test: convert version_check ui test to run-make MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit else it breaks with `rpath=false`. Signed-off-by: Fabian Grünbichler --- tests/run-make/version-check/rmake.rs | 13 +++++++++++++ tests/ui/feature-gates/version_check.rs | 17 ----------------- 2 files changed, 13 insertions(+), 17 deletions(-) create mode 100644 tests/run-make/version-check/rmake.rs delete mode 100644 tests/ui/feature-gates/version_check.rs diff --git a/tests/run-make/version-check/rmake.rs b/tests/run-make/version-check/rmake.rs new file mode 100644 index 0000000000000..e6a14d2e95c3a --- /dev/null +++ b/tests/run-make/version-check/rmake.rs @@ -0,0 +1,13 @@ +use run_make_support::bare_rustc; + +fn main() { + let signalled_version = "Ceci n'est pas une rustc"; + let rustc_out = bare_rustc() + .env("RUSTC_OVERRIDE_VERSION_STRING", signalled_version) + .arg("--version") + .run() + .stdout_utf8(); + + let version = rustc_out.strip_prefix("rustc ").unwrap().trim_end(); + assert_eq!(version, signalled_version); +} diff --git a/tests/ui/feature-gates/version_check.rs b/tests/ui/feature-gates/version_check.rs deleted file mode 100644 index e212dc74fd123..0000000000000 --- a/tests/ui/feature-gates/version_check.rs +++ /dev/null @@ -1,17 +0,0 @@ -//@ run-pass -//@ only-linux -//@ only-x86 -// FIXME: this should be more like //@ needs-subprocesses -use std::process::Command; - -fn main() { - let signalled_version = "Ceci n'est pas une rustc"; - let version = Command::new(std::env::var_os("RUSTC").unwrap()) - .env("RUSTC_OVERRIDE_VERSION_STRING", signalled_version) - .arg("--version") - .output() - .unwrap() - .stdout; - let version = std::str::from_utf8(&version).unwrap().strip_prefix("rustc ").unwrap().trim_end(); - assert_eq!(version, signalled_version); -} From e6312c923220d187458473437d1710ed9e5ae9c7 Mon Sep 17 00:00:00 2001 From: klensy Date: Tue, 27 May 2025 14:11:14 +0300 Subject: [PATCH 05/10] bump fluent-* crates --- Cargo.lock | 28 +++++++++--------------- compiler/rustc_error_messages/Cargo.toml | 4 ++-- compiler/rustc_fluent_macro/Cargo.toml | 4 ++-- src/tools/tidy/Cargo.toml | 2 +- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 177ff6594e244..c309f10997ca4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1259,16 +1259,16 @@ dependencies = [ [[package]] name = "fluent-bundle" -version = "0.15.3" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe0a21ee80050c678013f82edf4b705fe2f26f1f9877593d13198612503f493" +checksum = "01203cb8918f5711e73891b347816d932046f95f54207710bda99beaeb423bf4" dependencies = [ "fluent-langneg", "fluent-syntax", "intl-memoizer", "intl_pluralrules", - "rustc-hash 1.1.0", - "self_cell 0.10.3", + "rustc-hash 2.1.1", + "self_cell", "smallvec", "unic-langid", ] @@ -1284,11 +1284,12 @@ dependencies = [ [[package]] name = "fluent-syntax" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a530c4694a6a8d528794ee9bbd8ba0122e779629ac908d15ad5a7ae7763a33d" +checksum = "54f0d287c53ffd184d04d8677f590f4ac5379785529e5e08b1c8083acdd5c198" dependencies = [ - "thiserror 1.0.69", + "memchr", + "thiserror 2.0.12", ] [[package]] @@ -1934,9 +1935,9 @@ dependencies = [ [[package]] name = "intl-memoizer" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe22e020fce238ae18a6d5d8c502ee76a52a6e880d99477657e6acc30ec57bda" +checksum = "310da2e345f5eb861e7a07ee182262e94975051db9e4223e909ba90f392f163f" dependencies = [ "type-map", "unic-langid", @@ -4832,15 +4833,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "self_cell" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14e4d63b804dc0c7ec4a1e52bcb63f02c7ac94476755aa579edac21e01f915d" -dependencies = [ - "self_cell 1.2.0", -] - [[package]] name = "self_cell" version = "1.2.0" diff --git a/compiler/rustc_error_messages/Cargo.toml b/compiler/rustc_error_messages/Cargo.toml index 578af7fc51d40..0951859fa531f 100644 --- a/compiler/rustc_error_messages/Cargo.toml +++ b/compiler/rustc_error_messages/Cargo.toml @@ -5,8 +5,8 @@ edition = "2024" [dependencies] # tidy-alphabetical-start -fluent-bundle = "0.15.2" -fluent-syntax = "0.11" +fluent-bundle = "0.16" +fluent-syntax = "0.12" icu_list = "1.2" icu_locid = "1.2" icu_provider_adapters = "1.2" diff --git a/compiler/rustc_fluent_macro/Cargo.toml b/compiler/rustc_fluent_macro/Cargo.toml index ce76b2745eaad..d7ef4280aef05 100644 --- a/compiler/rustc_fluent_macro/Cargo.toml +++ b/compiler/rustc_fluent_macro/Cargo.toml @@ -9,8 +9,8 @@ proc-macro = true [dependencies] # tidy-alphabetical-start annotate-snippets = "0.11" -fluent-bundle = "0.15.2" -fluent-syntax = "0.11" +fluent-bundle = "0.16" +fluent-syntax = "0.12" proc-macro2 = "1" quote = "1" syn = { version = "2", features = ["full"] } diff --git a/src/tools/tidy/Cargo.toml b/src/tools/tidy/Cargo.toml index dfdbc0878f263..4835c22021042 100644 --- a/src/tools/tidy/Cargo.toml +++ b/src/tools/tidy/Cargo.toml @@ -15,7 +15,7 @@ semver = "1.0" serde = { version = "1.0.125", features = ["derive"], optional = true } termcolor = "1.1.3" rustc-hash = "2.0.0" -fluent-syntax = "0.11.1" +fluent-syntax = "0.12" similar = "2.5.0" toml = "0.7.8" From 29c3babd7c03a48b022663beb7ad39bb24bbef36 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 24 May 2025 12:07:32 +0000 Subject: [PATCH 06/10] Rename unpack to kind --- .../src/diagnostics/region_name.rs | 4 +-- .../src/type_check/constraint_conversion.rs | 2 +- .../src/type_check/opaque_types.rs | 2 +- compiler/rustc_codegen_ssa/src/meth.rs | 2 +- .../rustc_const_eval/src/check_consts/ops.rs | 2 +- .../rustc_const_eval/src/util/type_name.rs | 2 +- .../rustc_hir_analysis/src/check/check.rs | 4 +-- .../src/check/compare_impl_item.rs | 4 +-- .../src/check/compare_impl_item/refine.rs | 2 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 4 +-- .../src/collect/item_bounds.rs | 2 +- .../src/hir_ty_lowering/dyn_compatibility.rs | 2 +- .../src/hir_ty_lowering/mod.rs | 2 +- .../src/outlives/implicit_infer.rs | 4 +-- .../rustc_hir_analysis/src/outlives/mod.rs | 2 +- .../rustc_hir_analysis/src/outlives/utils.rs | 2 +- .../src/variance/constraints.rs | 6 ++-- .../src/fn_ctxt/adjust_fulfillment_errors.rs | 16 +++++----- .../rustc_hir_typeck/src/method/suggest.rs | 4 +-- compiler/rustc_infer/src/infer/at.rs | 2 +- .../src/infer/canonical/instantiate.rs | 6 ++-- .../src/infer/canonical/query_response.rs | 6 ++-- compiler/rustc_infer/src/infer/context.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 4 +-- .../src/infer/outlives/obligations.rs | 4 +-- .../src/infer/relate/generalize.rs | 2 +- .../rustc_lint/src/impl_trait_overcaptures.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 4 +-- compiler/rustc_middle/src/ty/generic_args.rs | 30 +++++++++---------- compiler/rustc_middle/src/ty/impls_ty.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 26 ++++++++-------- compiler/rustc_middle/src/ty/opaque_types.rs | 6 ++-- compiler/rustc_middle/src/ty/print/pretty.rs | 6 ++-- compiler/rustc_middle/src/ty/relate.rs | 4 +-- .../rustc_middle/src/ty/structural_impls.rs | 4 +-- .../rustc_middle/src/ty/typeck_results.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 4 +-- .../src/thir/pattern/const_to_pat.rs | 2 +- .../src/cfi/typeid/itanium_cxx_abi/encode.rs | 4 +-- .../rustc_smir/src/rustc_smir/convert/ty.rs | 12 ++++---- compiler/rustc_symbol_mangling/src/export.rs | 2 +- compiler/rustc_symbol_mangling/src/legacy.rs | 2 +- compiler/rustc_symbol_mangling/src/v0.rs | 8 ++--- .../src/error_reporting/infer/mod.rs | 8 ++--- .../error_reporting/infer/need_type_info.rs | 12 ++++---- .../src/error_reporting/infer/suggest.rs | 4 +-- .../traits/fulfillment_errors.rs | 2 +- .../rustc_trait_selection/src/opaque_types.rs | 2 +- .../src/solve/delegate.rs | 2 +- .../src/solve/inspect/analyse.rs | 2 +- .../src/traits/select/mod.rs | 2 +- .../src/traits/structural_normalize.rs | 2 +- .../rustc_trait_selection/src/traits/wf.rs | 2 +- .../rustc_ty_utils/src/representability.rs | 4 +-- compiler/rustc_ty_utils/src/ty.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/utils.rs | 4 +-- .../src/arc_with_non_send_sync.rs | 2 +- src/tools/clippy/clippy_lints/src/derive.rs | 2 +- .../clippy/clippy_lints/src/eta_reduction.rs | 4 +-- .../clippy_lints/src/functions/ref_option.rs | 2 +- .../clippy/clippy_lints/src/let_underscore.rs | 2 +- .../src/matches/manual_unwrap_or.rs | 2 +- .../src/matches/redundant_pattern_match.rs | 2 +- .../matches/significant_drop_in_scrutinee.rs | 4 +-- .../src/methods/needless_collect.rs | 2 +- .../src/methods/unnecessary_sort_by.rs | 2 +- .../src/methods/unnecessary_to_owned.rs | 4 +-- .../src/needless_borrows_for_generic_args.rs | 2 +- .../src/non_send_fields_in_send_ty.rs | 6 ++-- .../src/only_used_in_recursion.rs | 2 +- src/tools/clippy/clippy_lints/src/returns.rs | 2 +- .../src/significant_drop_tightening.rs | 2 +- src/tools/clippy/clippy_lints/src/use_self.rs | 4 +-- .../src/msrv_attr_impl.rs | 2 +- src/tools/clippy/clippy_utils/src/lib.rs | 2 +- .../clippy_utils/src/qualify_min_const_fn.rs | 2 +- src/tools/clippy/clippy_utils/src/ty/mod.rs | 10 +++---- .../clippy_utils/src/ty/type_certainty/mod.rs | 2 +- src/tools/miri/src/machine.rs | 2 +- 80 files changed, 165 insertions(+), 165 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index b08c10983bbc0..4aa9e90ab885a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -607,7 +607,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>, ) -> Option<&'hir hir::Lifetime> { for (kind, hir_arg) in iter::zip(args, hir_args.args) { - match (kind.unpack(), hir_arg) { + match (kind.kind(), hir_arg) { (GenericArgKind::Lifetime(r), hir::GenericArg::Lifetime(lt)) => { if r.as_var() == needle_fr { return Some(lt); @@ -997,7 +997,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { ) -> bool { let tcx = self.infcx.tcx; ty.walk().any(|arg| { - if let ty::GenericArgKind::Type(ty) = arg.unpack() + if let ty::GenericArgKind::Type(ty) = arg.kind() && let ty::Param(_) = ty.kind() { clauses.iter().any(|pred| { diff --git a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs index 57516565147eb..a1c74672157bc 100644 --- a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs +++ b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs @@ -148,7 +148,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> { let mut next_outlives_predicates = vec![]; for (ty::OutlivesPredicate(k1, r2), constraint_category) in outlives_predicates { - match k1.unpack() { + match k1.kind() { GenericArgKind::Lifetime(r1) => { let r1_vid = self.to_region_vid(r1); let r2_vid = self.to_region_vid(r2); diff --git a/compiler/rustc_borrowck/src/type_check/opaque_types.rs b/compiler/rustc_borrowck/src/type_check/opaque_types.rs index 341c50c37f6db..5a422483eef41 100644 --- a/compiler/rustc_borrowck/src/type_check/opaque_types.rs +++ b/compiler/rustc_borrowck/src/type_check/opaque_types.rs @@ -221,7 +221,7 @@ fn register_member_constraints<'tcx>( .iter() .enumerate() .filter(|(i, _)| variances[*i] == ty::Invariant) - .filter_map(|(_, arg)| match arg.unpack() { + .filter_map(|(_, arg)| match arg.kind() { GenericArgKind::Lifetime(r) => Some(typeck.to_region_vid(r)), GenericArgKind::Type(_) | GenericArgKind::Const(_) => None, }) diff --git a/compiler/rustc_codegen_ssa/src/meth.rs b/compiler/rustc_codegen_ssa/src/meth.rs index 399c592432aca..3a11ce6befb36 100644 --- a/compiler/rustc_codegen_ssa/src/meth.rs +++ b/compiler/rustc_codegen_ssa/src/meth.rs @@ -77,7 +77,7 @@ fn dyn_trait_in_self<'tcx>( ty: Ty<'tcx>, ) -> Option> { for arg in ty.peel_refs().walk() { - if let GenericArgKind::Type(ty) = arg.unpack() + if let GenericArgKind::Type(ty) = arg.kind() && let ty::Dynamic(data, _, _) = ty.kind() { // FIXME(arbitrary_self_types): This is likely broken for receivers which diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index 1e5b98675c4f0..177ba56b165e4 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -281,7 +281,7 @@ fn build_error_for_const_call<'tcx>( let mut sugg = None; if ccx.tcx.is_lang_item(trait_id, LangItem::PartialEq) { - match (args[0].unpack(), args[1].unpack()) { + match (args[0].kind(), args[1].kind()) { (GenericArgKind::Type(self_ty), GenericArgKind::Type(rhs_ty)) if self_ty == rhs_ty && self_ty.is_ref() diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index 30e96ae414359..e8f2728a7728f 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -125,7 +125,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { ) -> Result<(), PrintError> { print_prefix(self)?; let args = - args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_))); + args.iter().cloned().filter(|arg| !matches!(arg.kind(), GenericArgKind::Lifetime(_))); if args.clone().next().is_some() { self.generic_delimiters(|cx| cx.comma_sep(args)) } else { diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 06814eaefe84f..db7a5fe789767 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -1575,7 +1575,7 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD let mut params_used = DenseBitSet::new_empty(generics.own_params.len()); for leaf in ty.walk() { - if let GenericArgKind::Type(leaf_ty) = leaf.unpack() + if let GenericArgKind::Type(leaf_ty) = leaf.kind() && let ty::Param(param) = leaf_ty.kind() { debug!("found use of ty param {:?}", param); @@ -1700,7 +1700,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG let mut label_match = |ty: Ty<'_>, span| { for arg in ty.walk() { - if let ty::GenericArgKind::Type(ty) = arg.unpack() + if let ty::GenericArgKind::Type(ty) = arg.kind() && let ty::Alias( ty::Opaque, ty::AliasTy { def_id: captured_def_id, .. }, diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 2ee41e2efbd33..47681a78ecca8 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -1231,7 +1231,7 @@ fn check_region_late_boundedness<'tcx>( for (id_arg, arg) in std::iter::zip(ty::GenericArgs::identity_for_item(tcx, impl_m.def_id), impl_m_args) { - if let ty::GenericArgKind::Lifetime(r) = arg.unpack() + if let ty::GenericArgKind::Lifetime(r) = arg.kind() && let ty::ReVar(vid) = r.kind() && let r = infcx .inner @@ -1256,7 +1256,7 @@ fn check_region_late_boundedness<'tcx>( for (id_arg, arg) in std::iter::zip(ty::GenericArgs::identity_for_item(tcx, trait_m.def_id), trait_m_args) { - if let ty::GenericArgKind::Lifetime(r) = arg.unpack() + if let ty::GenericArgKind::Lifetime(r) = arg.kind() && let ty::ReVar(vid) = r.kind() && let r = infcx .inner diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index 4973d84895978..3db1c40228f6f 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -427,7 +427,7 @@ fn report_mismatched_rpitit_captures<'tcx>( }; trait_captured_args - .sort_by_cached_key(|arg| !matches!(arg.unpack(), ty::GenericArgKind::Lifetime(_))); + .sort_by_cached_key(|arg| !matches!(arg.kind(), ty::GenericArgKind::Lifetime(_))); let suggestion = format!("use<{}>", trait_captured_args.iter().join(", ")); tcx.emit_node_span_lint( diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 06c5e518fc646..476ce0e869111 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -819,7 +819,7 @@ impl<'tcx> TypeVisitor> for GATArgsCollector<'tcx> { match t.kind() { ty::Alias(ty::Projection, p) if p.def_id == self.gat => { for (idx, arg) in p.args.iter().enumerate() { - match arg.unpack() { + match arg.kind() { GenericArgKind::Lifetime(lt) if !lt.is_bound() => { self.regions.insert((lt, idx)); } @@ -1517,7 +1517,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id } else { // If we've got a generic const parameter we still want to check its // type is correct in case both it and the param type are fully concrete. - let GenericArgKind::Const(ct) = default.unpack() else { + let GenericArgKind::Const(ct) = default.kind() else { continue; }; diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index 279b1e82a716f..5f1cdeddc193c 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -151,7 +151,7 @@ fn remap_gat_vars_and_recurse_into_nested_projections<'tcx>( let mut mapping = FxIndexMap::default(); let generics = tcx.generics_of(assoc_item_def_id); for (param, var) in std::iter::zip(&generics.own_params, gat_vars) { - let existing = match var.unpack() { + let existing = match var.kind() { ty::GenericArgKind::Lifetime(re) => { if let ty::RegionKind::ReBound(ty::INNERMOST, bv) = re.kind() { mapping.insert(bv.var, tcx.mk_param_from_def(param)) diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs index 9e44b645aca7b..e75c307984e78 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs @@ -216,7 +216,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { let pred = bound_predicate.rebind(pred); // A `Self` within the original bound will be instantiated with a // `trait_object_dummy_self`, so check for that. - let references_self = match pred.skip_binder().term.unpack() { + let references_self = match pred.skip_binder().term.kind() { ty::TermKind::Ty(ty) => ty.walk().any(|arg| arg == dummy_self.into()), // FIXME(associated_const_equality): We should walk the const instead of not doing anything ty::TermKind::Const(_) => false, diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 6b21bbbfcd809..9eaa8360fee8c 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -607,7 +607,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { if !infer_args && has_default { // No type parameter provided, but a default exists. if let Some(prev) = - preceding_args.iter().find_map(|arg| match arg.unpack() { + preceding_args.iter().find_map(|arg| match arg.kind() { GenericArgKind::Type(ty) => ty.error_reported().err(), _ => None, }) diff --git a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs index c99eb12efcca2..4f35b87be3016 100644 --- a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs +++ b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs @@ -119,7 +119,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( explicit_map: &mut ExplicitPredicatesMap<'tcx>, ) { for arg in ty.walk() { - let leaf_ty = match arg.unpack() { + let leaf_ty = match arg.kind() { GenericArgKind::Type(ty) => ty, // No predicates from lifetimes or constants, except potentially @@ -299,7 +299,7 @@ fn check_explicit_predicates<'tcx>( // binding) and thus infer an outlives requirement that `X: // 'b`. if let Some(self_ty) = ignored_self_ty - && let GenericArgKind::Type(ty) = outlives_predicate.0.unpack() + && let GenericArgKind::Type(ty) = outlives_predicate.0.kind() && ty.walk().any(|arg| arg == self_ty.into()) { debug!("skipping self ty = {ty:?}"); diff --git a/compiler/rustc_hir_analysis/src/outlives/mod.rs b/compiler/rustc_hir_analysis/src/outlives/mod.rs index daa908c8c78e4..fbf973a49dc7b 100644 --- a/compiler/rustc_hir_analysis/src/outlives/mod.rs +++ b/compiler/rustc_hir_analysis/src/outlives/mod.rs @@ -70,7 +70,7 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> { let predicates = &*tcx.arena.alloc_from_iter(set.as_ref().skip_binder().iter().filter_map( |(ty::OutlivesPredicate(kind1, region2), &span)| { - match kind1.unpack() { + match kind1.kind() { GenericArgKind::Type(ty1) => Some(( ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)) .upcast(tcx), diff --git a/compiler/rustc_hir_analysis/src/outlives/utils.rs b/compiler/rustc_hir_analysis/src/outlives/utils.rs index 044fb64ca8216..3fd1dbb3a8a08 100644 --- a/compiler/rustc_hir_analysis/src/outlives/utils.rs +++ b/compiler/rustc_hir_analysis/src/outlives/utils.rs @@ -25,7 +25,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>( return; } - match kind.unpack() { + match kind.kind() { GenericArgKind::Type(ty) => { // `T: 'outlived_region` for some type `T` // But T could be a lot of things: diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 92cfece77c473..68ceec384b958 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -201,7 +201,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { let variance_i = self.invariant(variance); for k in args { - match k.unpack() { + match k.kind() { GenericArgKind::Lifetime(lt) => { self.add_constraints_from_region(current, lt, variance_i) } @@ -294,7 +294,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { } for projection in data.projection_bounds() { - match projection.skip_binder().term.unpack() { + match projection.skip_binder().term.kind() { ty::TermKind::Ty(ty) => { self.add_constraints_from_ty(current, ty, self.invariant); } @@ -389,7 +389,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { "add_constraints_from_args: variance_decl={:?} variance_i={:?}", variance_decl, variance_i ); - match k.unpack() { + match k.kind() { GenericArgKind::Lifetime(lt) => { self.add_constraints_from_region(current, lt, variance_i) } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index ee0436f73e1de..db6482fe4faf5 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -80,12 +80,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let find_param_matching = |matches: &dyn Fn(ty::ParamTerm) -> bool| { predicate_args.iter().find_map(|arg| { arg.walk().find_map(|arg| { - if let ty::GenericArgKind::Type(ty) = arg.unpack() + if let ty::GenericArgKind::Type(ty) = arg.kind() && let ty::Param(param_ty) = *ty.kind() && matches(ty::ParamTerm::Ty(param_ty)) { Some(arg) - } else if let ty::GenericArgKind::Const(ct) = arg.unpack() + } else if let ty::GenericArgKind::Const(ct) = arg.kind() && let ty::ConstKind::Param(param_ct) = ct.kind() && matches(ty::ParamTerm::Const(param_ct)) { @@ -373,7 +373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Handle `Self` param specifically, since it's separated in // the path representation if let Some(self_ty) = self_ty - && let ty::GenericArgKind::Type(ty) = param.unpack() + && let ty::GenericArgKind::Type(ty) = param.kind() && ty == self.tcx.types.self_param { error.obligation.cause.span = self_ty @@ -389,7 +389,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } // Handle `Self` param specifically, since it's separated in // the path representation - if let ty::GenericArgKind::Type(ty) = param.unpack() + if let ty::GenericArgKind::Type(ty) = param.kind() && ty == self.tcx.types.self_param { error.obligation.cause.span = self_ty @@ -424,10 +424,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // the args list does not, then we should chop off all of the lifetimes, // since they're all elided. let segment_args = segment.args().args; - if matches!(own_args[0].unpack(), ty::GenericArgKind::Lifetime(_)) + if matches!(own_args[0].kind(), ty::GenericArgKind::Lifetime(_)) && segment_args.first().is_some_and(|arg| arg.is_ty_or_const()) && let Some(offset) = own_args.iter().position(|arg| { - matches!(arg.unpack(), ty::GenericArgKind::Type(_) | ty::GenericArgKind::Const(_)) + matches!(arg.kind(), ty::GenericArgKind::Type(_) | ty::GenericArgKind::Const(_)) }) && let Some(new_index) = index.checked_sub(offset) { @@ -750,7 +750,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return Ok(expr); } - let ty::GenericArgKind::Type(in_ty) = in_ty.unpack() else { + let ty::GenericArgKind::Type(in_ty) = in_ty.kind() else { return Err(expr); }; @@ -1045,7 +1045,7 @@ fn find_param_in_ty<'tcx>( if arg == param_to_point_at { return true; } - if let ty::GenericArgKind::Type(ty) = arg.unpack() + if let ty::GenericArgKind::Type(ty) = arg.kind() && let ty::Alias(ty::Projection | ty::Inherent, ..) = ty.kind() { // This logic may seem a bit strange, but typically when diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 7b71f5de7569f..3eae95d5b738d 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -2226,7 +2226,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let infer_args = self.tcx.mk_args_from_iter(args.into_iter().map(|arg| { if !arg.is_suggestable(self.tcx, true) { has_unsuggestable_args = true; - match arg.unpack() { + match arg.kind() { GenericArgKind::Lifetime(_) => self .next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP)) .into(), @@ -2843,7 +2843,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let [first] = ***args else { return; }; - let ty::GenericArgKind::Type(ty) = first.unpack() else { + let ty::GenericArgKind::Type(ty) = first.kind() else { return; }; let Ok(pick) = self.lookup_probe_for_diagnostic( diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 2cd67cc4da213..5fe795bd23a15 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -347,7 +347,7 @@ impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> { fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> { TypeTrace { cause: cause.clone(), - values: match (a.unpack(), b.unpack()) { + values: match (a.kind(), b.kind()) { (GenericArgKind::Lifetime(a), GenericArgKind::Lifetime(b)) => { ValuePairs::Regions(ExpectedFound::new(a, b)) } diff --git a/compiler/rustc_infer/src/infer/canonical/instantiate.rs b/compiler/rustc_infer/src/infer/canonical/instantiate.rs index f5ee5702d09cc..67f13192b5220 100644 --- a/compiler/rustc_infer/src/infer/canonical/instantiate.rs +++ b/compiler/rustc_infer/src/infer/canonical/instantiate.rs @@ -61,15 +61,15 @@ where value } else { let delegate = FnMutDelegate { - regions: &mut |br: ty::BoundRegion| match var_values[br.var].unpack() { + regions: &mut |br: ty::BoundRegion| match var_values[br.var].kind() { GenericArgKind::Lifetime(l) => l, r => bug!("{:?} is a region but value is {:?}", br, r), }, - types: &mut |bound_ty: ty::BoundTy| match var_values[bound_ty.var].unpack() { + types: &mut |bound_ty: ty::BoundTy| match var_values[bound_ty.var].kind() { GenericArgKind::Type(ty) => ty, r => bug!("{:?} is a type but value is {:?}", bound_ty, r), }, - consts: &mut |bound_ct: ty::BoundVar| match var_values[bound_ct].unpack() { + consts: &mut |bound_ct: ty::BoundVar| match var_values[bound_ct].kind() { GenericArgKind::Const(ct) => ct, c => bug!("{:?} is a const but value is {:?}", bound_ct, c), }, diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index bda33f3f455b0..008ef6900089f 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -245,7 +245,7 @@ impl<'tcx> InferCtxt<'tcx> { let result_value = query_response.instantiate_projected(self.tcx, &result_args, |v| { v.var_values[BoundVar::new(index)] }); - match (original_value.unpack(), result_value.unpack()) { + match (original_value.kind(), result_value.kind()) { (GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2)) if re1.is_erased() && re2.is_erased() => { @@ -402,7 +402,7 @@ impl<'tcx> InferCtxt<'tcx> { // [(?A, Vec), ('static, '?1), (?B, ?0)] for (original_value, result_value) in iter::zip(&original_values.var_values, result_values) { - match result_value.unpack() { + match result_value.kind() { GenericArgKind::Type(result_value) => { // e.g., here `result_value` might be `?0` in the example above... if let ty::Bound(debruijn, b) = *result_value.kind() { @@ -533,7 +533,7 @@ impl<'tcx> InferCtxt<'tcx> { for (index, value1) in variables1.var_values.iter().enumerate() { let value2 = variables2(BoundVar::new(index)); - match (value1.unpack(), value2.unpack()) { + match (value1.kind(), value2.kind()) { (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => { obligations.extend( self.at(cause, param_env) diff --git a/compiler/rustc_infer/src/infer/context.rs b/compiler/rustc_infer/src/infer/context.rs index 6b75d676f4d71..f7c702d321b21 100644 --- a/compiler/rustc_infer/src/infer/context.rs +++ b/compiler/rustc_infer/src/infer/context.rs @@ -90,7 +90,7 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> { } fn is_changed_arg(&self, arg: ty::GenericArg<'tcx>) -> bool { - match arg.unpack() { + match arg.kind() { ty::GenericArgKind::Lifetime(_) => { // Lifetimes should not change affect trait selection. false diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 8fb25cb9b32fa..96e03e3bea564 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1372,7 +1372,7 @@ impl<'tcx> TyOrConstInferVar { /// for types other than `ty::Infer(_)` (or `InferTy::Fresh*`) and /// for constants other than `ty::ConstKind::Infer(_)` (or `InferConst::Fresh`). pub fn maybe_from_generic_arg(arg: GenericArg<'tcx>) -> Option { - match arg.unpack() { + match arg.kind() { GenericArgKind::Type(ty) => Self::maybe_from_ty(ty), GenericArgKind::Const(ct) => Self::maybe_from_const(ct), GenericArgKind::Lifetime(_) => None, @@ -1383,7 +1383,7 @@ impl<'tcx> TyOrConstInferVar { /// for types other than `ty::Infer(_)` (or `InferTy::Fresh*`) and /// for constants other than `ty::ConstKind::Infer(_)` (or `InferConst::Fresh`). pub fn maybe_from_term(term: Term<'tcx>) -> Option { - match term.unpack() { + match term.kind() { TermKind::Ty(ty) => Self::maybe_from_ty(ty), TermKind::Const(ct) => Self::maybe_from_const(ct), } diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 890902af02bc6..0d2732a3b6d38 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -87,7 +87,7 @@ impl<'tcx> InferCtxt<'tcx> { ty::OutlivesPredicate(arg, r2): ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>, cause: &ObligationCause<'tcx>, ) { - match arg.unpack() { + match arg.kind() { ty::GenericArgKind::Lifetime(r1) => { self.register_region_outlives_constraint(ty::OutlivesPredicate(r1, r2), cause); } @@ -504,7 +504,7 @@ where ) { let constraint = origin.to_constraint_category(); for (index, k) in args.iter().enumerate() { - match k.unpack() { + match k.kind() { GenericArgKind::Lifetime(lt) => { let variance = if let Some(variances) = opt_variances { variances[index] diff --git a/compiler/rustc_infer/src/infer/relate/generalize.rs b/compiler/rustc_infer/src/infer/relate/generalize.rs index 210b8f37d883d..0e17b100276a2 100644 --- a/compiler/rustc_infer/src/infer/relate/generalize.rs +++ b/compiler/rustc_infer/src/infer/relate/generalize.rs @@ -329,7 +329,7 @@ struct Generalizer<'me, 'tcx> { impl<'tcx> Generalizer<'_, 'tcx> { /// Create an error that corresponds to the term kind in `root_term` fn cyclic_term_error(&self) -> TypeError<'tcx> { - match self.root_term.unpack() { + match self.root_term.kind() { ty::TermKind::Ty(ty) => TypeError::CyclicTy(ty), ty::TermKind::Const(ct) => TypeError::CyclicConst(ct), } diff --git a/compiler/rustc_lint/src/impl_trait_overcaptures.rs b/compiler/rustc_lint/src/impl_trait_overcaptures.rs index a8f45d043be97..8124d7f7c86a1 100644 --- a/compiler/rustc_lint/src/impl_trait_overcaptures.rs +++ b/compiler/rustc_lint/src/impl_trait_overcaptures.rs @@ -461,7 +461,7 @@ fn extract_def_id_from_arg<'tcx>( generics: &'tcx ty::Generics, arg: ty::GenericArg<'tcx>, ) -> DefId { - match arg.unpack() { + match arg.kind() { ty::GenericArgKind::Lifetime(re) => match re.kind() { ty::ReEarlyParam(ebr) => generics.region_param(ebr, tcx).def_id, ty::ReBound( diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 70172e55e541c..57b20a1bba606 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2781,7 +2781,7 @@ impl<'tcx> TyCtxt<'tcx> { return false; } - if !matches!(args[0].unpack(), ty::GenericArgKind::Type(_)) { + if !matches!(args[0].kind(), ty::GenericArgKind::Type(_)) { return false; } @@ -2803,7 +2803,7 @@ impl<'tcx> TyCtxt<'tcx> { }; for (param, arg) in std::iter::zip(&generics.own_params, own_args) { - match (¶m.kind, arg.unpack()) { + match (¶m.kind, arg.kind()) { (ty::GenericParamDefKind::Type { .. }, ty::GenericArgKind::Type(_)) | (ty::GenericParamDefKind::Lifetime, ty::GenericArgKind::Lifetime(_)) | (ty::GenericParamDefKind::Const { .. }, ty::GenericArgKind::Const(_)) => {} diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index 542c0b3e6ebb4..b7d3fd81b1117 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -137,7 +137,7 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for GenericArg<'tcx> { type Kind = GenericArgKind<'tcx>; fn kind(self) -> Self::Kind { - self.unpack() + self.kind() } } @@ -218,7 +218,7 @@ impl<'tcx> From> for GenericArg<'tcx> { impl<'tcx> From> for GenericArg<'tcx> { fn from(value: ty::Term<'tcx>) -> Self { - match value.unpack() { + match value.kind() { ty::TermKind::Ty(t) => t.into(), ty::TermKind::Const(c) => c.into(), } @@ -227,7 +227,7 @@ impl<'tcx> From> for GenericArg<'tcx> { impl<'tcx> GenericArg<'tcx> { #[inline] - pub fn unpack(self) -> GenericArgKind<'tcx> { + pub fn kind(self) -> GenericArgKind<'tcx> { let ptr = unsafe { self.ptr.map_addr(|addr| NonZero::new_unchecked(addr.get() & !TAG_MASK)) }; // SAFETY: use of `Interned::new_unchecked` here is ok because these @@ -251,7 +251,7 @@ impl<'tcx> GenericArg<'tcx> { #[inline] pub fn as_region(self) -> Option> { - match self.unpack() { + match self.kind() { GenericArgKind::Lifetime(re) => Some(re), _ => None, } @@ -259,7 +259,7 @@ impl<'tcx> GenericArg<'tcx> { #[inline] pub fn as_type(self) -> Option> { - match self.unpack() { + match self.kind() { GenericArgKind::Type(ty) => Some(ty), _ => None, } @@ -267,7 +267,7 @@ impl<'tcx> GenericArg<'tcx> { #[inline] pub fn as_const(self) -> Option> { - match self.unpack() { + match self.kind() { GenericArgKind::Const(ct) => Some(ct), _ => None, } @@ -275,7 +275,7 @@ impl<'tcx> GenericArg<'tcx> { #[inline] pub fn as_term(self) -> Option> { - match self.unpack() { + match self.kind() { GenericArgKind::Lifetime(_) => None, GenericArgKind::Type(ty) => Some(ty.into()), GenericArgKind::Const(ct) => Some(ct.into()), @@ -300,7 +300,7 @@ impl<'tcx> GenericArg<'tcx> { } pub fn is_non_region_infer(self) -> bool { - match self.unpack() { + match self.kind() { GenericArgKind::Lifetime(_) => false, // FIXME: This shouldn't return numerical/float. GenericArgKind::Type(ty) => ty.is_ty_or_numeric_infer(), @@ -327,7 +327,7 @@ impl<'a, 'tcx> Lift> for GenericArg<'a> { type Lifted = GenericArg<'tcx>; fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option { - match self.unpack() { + match self.kind() { GenericArgKind::Lifetime(lt) => tcx.lift(lt).map(|lt| lt.into()), GenericArgKind::Type(ty) => tcx.lift(ty).map(|ty| ty.into()), GenericArgKind::Const(ct) => tcx.lift(ct).map(|ct| ct.into()), @@ -340,7 +340,7 @@ impl<'tcx> TypeFoldable> for GenericArg<'tcx> { self, folder: &mut F, ) -> Result { - match self.unpack() { + match self.kind() { GenericArgKind::Lifetime(lt) => lt.try_fold_with(folder).map(Into::into), GenericArgKind::Type(ty) => ty.try_fold_with(folder).map(Into::into), GenericArgKind::Const(ct) => ct.try_fold_with(folder).map(Into::into), @@ -348,7 +348,7 @@ impl<'tcx> TypeFoldable> for GenericArg<'tcx> { } fn fold_with>>(self, folder: &mut F) -> Self { - match self.unpack() { + match self.kind() { GenericArgKind::Lifetime(lt) => lt.fold_with(folder).into(), GenericArgKind::Type(ty) => ty.fold_with(folder).into(), GenericArgKind::Const(ct) => ct.fold_with(folder).into(), @@ -358,7 +358,7 @@ impl<'tcx> TypeFoldable> for GenericArg<'tcx> { impl<'tcx> TypeVisitable> for GenericArg<'tcx> { fn visit_with>>(&self, visitor: &mut V) -> V::Result { - match self.unpack() { + match self.kind() { GenericArgKind::Lifetime(lt) => lt.visit_with(visitor), GenericArgKind::Type(ty) => ty.visit_with(visitor), GenericArgKind::Const(ct) => ct.visit_with(visitor), @@ -368,7 +368,7 @@ impl<'tcx> TypeVisitable> for GenericArg<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable for GenericArg<'tcx> { fn encode(&self, e: &mut E) { - self.unpack().encode(e) + self.kind().encode(e) } } @@ -390,7 +390,7 @@ impl<'tcx> GenericArgs<'tcx> { /// /// If any of the generic arguments are not types. pub fn into_type_list(&self, tcx: TyCtxt<'tcx>) -> &'tcx List> { - tcx.mk_type_list_from_iter(self.iter().map(|arg| match arg.unpack() { + tcx.mk_type_list_from_iter(self.iter().map(|arg| match arg.kind() { GenericArgKind::Type(ty) => ty, _ => bug!("`into_type_list` called on generic arg with non-types"), })) @@ -527,7 +527,7 @@ impl<'tcx> GenericArgs<'tcx> { /// Returns generic arguments that are not lifetimes. #[inline] pub fn non_erasable_generics(&self) -> impl DoubleEndedIterator> { - self.iter().filter_map(|k| match k.unpack() { + self.iter().filter_map(|k| match k.kind() { ty::GenericArgKind::Lifetime(_) => None, generic => Some(generic), }) diff --git a/compiler/rustc_middle/src/ty/impls_ty.rs b/compiler/rustc_middle/src/ty/impls_ty.rs index 5f6305bb48ad4..ac45ce887c9a7 100644 --- a/compiler/rustc_middle/src/ty/impls_ty.rs +++ b/compiler/rustc_middle/src/ty/impls_ty.rs @@ -60,7 +60,7 @@ where impl<'a, 'tcx> HashStable> for ty::GenericArg<'tcx> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - self.unpack().hash_stable(hcx, hasher); + self.kind().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index f57329608ef77..78c0812b08f80 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -504,7 +504,7 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Term<'tcx> { type Kind = TermKind<'tcx>; fn kind(self) -> Self::Kind { - self.unpack() + self.kind() } } @@ -521,7 +521,7 @@ unsafe impl<'tcx> Sync for Term<'tcx> where &'tcx (Ty<'tcx>, Const<'tcx>): Sync impl Debug for Term<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self.unpack() { + match self.kind() { TermKind::Ty(ty) => write!(f, "Term::Ty({ty:?})"), TermKind::Const(ct) => write!(f, "Term::Const({ct:?})"), } @@ -542,7 +542,7 @@ impl<'tcx> From> for Term<'tcx> { impl<'a, 'tcx> HashStable> for Term<'tcx> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - self.unpack().hash_stable(hcx, hasher); + self.kind().hash_stable(hcx, hasher); } } @@ -551,14 +551,14 @@ impl<'tcx> TypeFoldable> for Term<'tcx> { self, folder: &mut F, ) -> Result { - match self.unpack() { + match self.kind() { ty::TermKind::Ty(ty) => ty.try_fold_with(folder).map(Into::into), ty::TermKind::Const(ct) => ct.try_fold_with(folder).map(Into::into), } } fn fold_with>>(self, folder: &mut F) -> Self { - match self.unpack() { + match self.kind() { ty::TermKind::Ty(ty) => ty.fold_with(folder).into(), ty::TermKind::Const(ct) => ct.fold_with(folder).into(), } @@ -567,7 +567,7 @@ impl<'tcx> TypeFoldable> for Term<'tcx> { impl<'tcx> TypeVisitable> for Term<'tcx> { fn visit_with>>(&self, visitor: &mut V) -> V::Result { - match self.unpack() { + match self.kind() { ty::TermKind::Ty(ty) => ty.visit_with(visitor), ty::TermKind::Const(ct) => ct.visit_with(visitor), } @@ -576,7 +576,7 @@ impl<'tcx> TypeVisitable> for Term<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable for Term<'tcx> { fn encode(&self, e: &mut E) { - self.unpack().encode(e) + self.kind().encode(e) } } @@ -589,7 +589,7 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable for Term<'tcx> { impl<'tcx> Term<'tcx> { #[inline] - pub fn unpack(self) -> TermKind<'tcx> { + pub fn kind(self) -> TermKind<'tcx> { let ptr = unsafe { self.ptr.map_addr(|addr| NonZero::new_unchecked(addr.get() & !TAG_MASK)) }; // SAFETY: use of `Interned::new_unchecked` here is ok because these @@ -609,7 +609,7 @@ impl<'tcx> Term<'tcx> { } pub fn as_type(&self) -> Option> { - if let TermKind::Ty(ty) = self.unpack() { Some(ty) } else { None } + if let TermKind::Ty(ty) = self.kind() { Some(ty) } else { None } } pub fn expect_type(&self) -> Ty<'tcx> { @@ -617,7 +617,7 @@ impl<'tcx> Term<'tcx> { } pub fn as_const(&self) -> Option> { - if let TermKind::Const(c) = self.unpack() { Some(c) } else { None } + if let TermKind::Const(c) = self.kind() { Some(c) } else { None } } pub fn expect_const(&self) -> Const<'tcx> { @@ -625,14 +625,14 @@ impl<'tcx> Term<'tcx> { } pub fn into_arg(self) -> GenericArg<'tcx> { - match self.unpack() { + match self.kind() { TermKind::Ty(ty) => ty.into(), TermKind::Const(c) => c.into(), } } pub fn to_alias_term(self) -> Option> { - match self.unpack() { + match self.kind() { TermKind::Ty(ty) => match *ty.kind() { ty::Alias(_kind, alias_ty) => Some(alias_ty.into()), _ => None, @@ -645,7 +645,7 @@ impl<'tcx> Term<'tcx> { } pub fn is_infer(&self) -> bool { - match self.unpack() { + match self.kind() { TermKind::Ty(ty) => ty.is_ty_var(), TermKind::Const(ct) => ct.is_ct_infer(), } diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 9445a18ad76b1..5c05bdb08ebad 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -120,7 +120,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { } } - match self.map.get(&r.into()).map(|k| k.unpack()) { + match self.map.get(&r.into()).map(|k| k.kind()) { Some(GenericArgKind::Lifetime(r1)) => r1, Some(u) => panic!("region mapped to unexpected kind: {u:?}"), None if self.do_not_error => self.tcx.lifetimes.re_static, @@ -162,7 +162,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { ty::Param(param) => { // Look it up in the generic parameters list. - match self.map.get(&ty.into()).map(|k| k.unpack()) { + match self.map.get(&ty.into()).map(|k| k.kind()) { // Found it in the generic parameters list; replace with the parameter from the // opaque type. Some(GenericArgKind::Type(t1)) => t1, @@ -195,7 +195,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { match ct.kind() { ty::ConstKind::Param(..) => { // Look it up in the generic parameters list. - match self.map.get(&ct.into()).map(|k| k.unpack()) { + match self.map.get(&ct.into()).map(|k| k.kind()) { // Found it in the generic parameters list, replace with the parameter from the // opaque type. Some(GenericArgKind::Const(c1)) => c1, diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 6fd6aff0e2b23..877bea095f968 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1239,7 +1239,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { p!(write("{} = ", tcx.associated_item(assoc_item_def_id).name())); - match term.unpack() { + match term.kind() { TermKind::Ty(ty) => p!(print(ty)), TermKind::Const(c) => p!(print(c)), }; @@ -3386,7 +3386,7 @@ define_print_and_forward_display! { } ty::Term<'tcx> { - match self.unpack() { + match self.kind() { ty::TermKind::Ty(ty) => p!(print(ty)), ty::TermKind::Const(c) => p!(print(c)), } @@ -3401,7 +3401,7 @@ define_print_and_forward_display! { } GenericArg<'tcx> { - match self.unpack() { + match self.kind() { GenericArgKind::Lifetime(lt) => p!(print(lt)), GenericArgKind::Type(ty) => p!(print(ty)), GenericArgKind::Const(ct) => p!(print(ct)), diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 6ad4e5276b253..dc1d60f3d43c1 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -169,7 +169,7 @@ impl<'tcx> Relate> for ty::GenericArg<'tcx> { a: ty::GenericArg<'tcx>, b: ty::GenericArg<'tcx>, ) -> RelateResult<'tcx, ty::GenericArg<'tcx>> { - match (a.unpack(), b.unpack()) { + match (a.kind(), b.kind()) { (ty::GenericArgKind::Lifetime(a_lt), ty::GenericArgKind::Lifetime(b_lt)) => { Ok(relation.relate(a_lt, b_lt)?.into()) } @@ -190,7 +190,7 @@ impl<'tcx> Relate> for ty::Term<'tcx> { a: Self, b: Self, ) -> RelateResult<'tcx, Self> { - Ok(match (a.unpack(), b.unpack()) { + Ok(match (a.kind(), b.kind()) { (ty::TermKind::Ty(a), ty::TermKind::Ty(b)) => relation.relate(a, b)?.into(), (ty::TermKind::Const(a), ty::TermKind::Const(b)) => relation.relate(a, b)?.into(), _ => return Err(TypeError::Mismatch), diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 58f7bc75054bb..7a7c33fb34db5 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -202,7 +202,7 @@ impl fmt::Debug for ty::Placeholder { impl<'tcx> fmt::Debug for GenericArg<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self.unpack() { + match self.kind() { GenericArgKind::Lifetime(lt) => lt.fmt(f), GenericArgKind::Type(ty) => ty.fmt(f), GenericArgKind::Const(ct) => ct.fmt(f), @@ -326,7 +326,7 @@ impl<'tcx, T: Lift>> Lift> for Option { impl<'a, 'tcx> Lift> for Term<'a> { type Lifted = ty::Term<'tcx>; fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option { - match self.unpack() { + match self.kind() { TermKind::Ty(ty) => tcx.lift(ty).map(Into::into), TermKind::Const(c) => tcx.lift(c).map(Into::into), } diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index c6a45f8468690..9627188c334e9 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -778,7 +778,7 @@ impl<'tcx> IsIdentity for CanonicalUserType<'tcx> { } iter::zip(user_args.args, BoundVar::ZERO..).all(|(kind, cvar)| { - match kind.unpack() { + match kind.kind() { GenericArgKind::Type(ty) => match ty.kind() { ty::Bound(debruijn, b) => { // We only allow a `ty::INNERMOST` index in generic parameters. diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index ecf83926df7d2..06fd8a294d0eb 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -517,7 +517,7 @@ impl<'tcx> TyCtxt<'tcx> { let result = iter::zip(item_args, impl_args) .filter(|&(_, k)| { - match k.unpack() { + match k.kind() { GenericArgKind::Lifetime(region) => match region.kind() { ty::ReEarlyParam(ebr) => { !impl_generics.region_param(ebr, self).pure_wrt_drop @@ -554,7 +554,7 @@ impl<'tcx> TyCtxt<'tcx> { let mut seen = GrowableBitSet::default(); let mut seen_late = FxHashSet::default(); for arg in args { - match arg.unpack() { + match arg.kind() { GenericArgKind::Lifetime(lt) => match (ignore_regions, lt.kind()) { (CheckRegions::FromFunction, ty::ReBound(di, reg)) => { if !seen_late.insert((di, reg)) { diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index e233358f3866e..84a0190a7fa19 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -131,7 +131,7 @@ impl<'tcx> ConstToPat<'tcx> { .dcx() .create_err(ConstPatternDependsOnGenericParameter { span: self.span }); for arg in uv.args { - if let ty::GenericArgKind::Type(ty) = arg.unpack() + if let ty::GenericArgKind::Type(ty) = arg.kind() && let ty::Param(param_ty) = ty.kind() { let def_id = self.tcx.hir_enclosing_body_owner(self.id); diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs index 47831f2f4180d..9d1d3412f8d23 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs @@ -79,7 +79,7 @@ fn encode_args<'tcx>( s.push('I'); let def_generics = tcx.generics_of(for_def); for (n, arg) in args.iter().enumerate() { - match arg.unpack() { + match arg.kind() { GenericArgKind::Lifetime(region) => { s.push_str(&encode_region(region, dict)); } @@ -245,7 +245,7 @@ fn encode_predicate<'tcx>( let name = encode_ty_name(tcx, projection.def_id); let _ = write!(s, "u{}{}", name.len(), name); s.push_str(&encode_args(tcx, projection.args, projection.def_id, true, dict, options)); - match projection.term.unpack() { + match projection.term.kind() { TermKind::Ty(ty) => s.push_str(&encode_ty(tcx, ty, dict, options)), TermKind::Const(c) => s.push_str(&encode_const( tcx, diff --git a/compiler/rustc_smir/src/rustc_smir/convert/ty.rs b/compiler/rustc_smir/src/rustc_smir/convert/ty.rs index 8bcac4c4678e4..b0c9dba78a659 100644 --- a/compiler/rustc_smir/src/rustc_smir/convert/ty.rs +++ b/compiler/rustc_smir/src/rustc_smir/convert/ty.rs @@ -100,7 +100,7 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialProjection<'tcx> { stable_mir::ty::ExistentialProjection { def_id: tables.trait_def(*def_id), generic_args: args.stable(tables), - term: term.unpack().stable(tables), + term: term.kind().stable(tables), } } } @@ -158,7 +158,7 @@ impl<'tcx> Stable<'tcx> for ty::FieldDef { impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> { type T = stable_mir::ty::GenericArgs; fn stable(&self, tables: &mut Tables<'_>) -> Self::T { - GenericArgs(self.iter().map(|arg| arg.unpack().stable(tables)).collect()) + GenericArgs(self.iter().map(|arg| arg.kind().stable(tables)).collect()) } } @@ -604,8 +604,8 @@ impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> { PredicateKind::NormalizesTo(_pred) => unimplemented!(), PredicateKind::AliasRelate(a, b, alias_relation_direction) => { stable_mir::ty::PredicateKind::AliasRelate( - a.unpack().stable(tables), - b.unpack().stable(tables), + a.kind().stable(tables), + b.kind().stable(tables), alias_relation_direction.stable(tables), ) } @@ -640,7 +640,7 @@ impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> { ty.stable(tables), ), ClauseKind::WellFormed(term) => { - stable_mir::ty::ClauseKind::WellFormed(term.unpack().stable(tables)) + stable_mir::ty::ClauseKind::WellFormed(term.kind().stable(tables)) } ClauseKind::ConstEvaluatable(const_) => { stable_mir::ty::ClauseKind::ConstEvaluatable(const_.stable(tables)) @@ -726,7 +726,7 @@ impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> { let ty::ProjectionPredicate { projection_term, term } = self; stable_mir::ty::ProjectionPredicate { projection_term: projection_term.stable(tables), - term: term.unpack().stable(tables), + term: term.kind().stable(tables), } } } diff --git a/compiler/rustc_symbol_mangling/src/export.rs b/compiler/rustc_symbol_mangling/src/export.rs index 770401fc8cfea..956c996326bf9 100644 --- a/compiler/rustc_symbol_mangling/src/export.rs +++ b/compiler/rustc_symbol_mangling/src/export.rs @@ -147,7 +147,7 @@ impl<'tcx> AbiHashStable<'tcx> for ty::FnSig<'tcx> { impl<'tcx> AbiHashStable<'tcx> for ty::GenericArg<'tcx> { fn abi_hash(&self, tcx: TyCtxt<'tcx>, hasher: &mut StableHasher) { - self.unpack().abi_hash(tcx, hasher); + self.kind().abi_hash(tcx, hasher); } } diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index db102abda7fa3..12d1de463136a 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -386,7 +386,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> { print_prefix(self)?; let args = - args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_))); + args.iter().cloned().filter(|arg| !matches!(arg.kind(), GenericArgKind::Lifetime(_))); if args.clone().next().is_some() { self.generic_delimiters(|cx| cx.comma_sep(args)) diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 644031af8597a..49a5e20d7cf8b 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -646,7 +646,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { let name = cx.tcx.associated_item(projection.def_id).name(); cx.push("p"); cx.push_ident(name.as_str()); - match projection.term.unpack() { + match projection.term.kind() { ty::TermKind::Ty(ty) => ty.print(cx), ty::TermKind::Const(c) => c.print(cx), }?; @@ -912,11 +912,11 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { args: &[GenericArg<'tcx>], ) -> Result<(), PrintError> { // Don't print any regions if they're all erased. - let print_regions = args.iter().any(|arg| match arg.unpack() { + let print_regions = args.iter().any(|arg| match arg.kind() { GenericArgKind::Lifetime(r) => !r.is_erased(), _ => false, }); - let args = args.iter().cloned().filter(|arg| match arg.unpack() { + let args = args.iter().cloned().filter(|arg| match arg.kind() { GenericArgKind::Lifetime(_) => print_regions, _ => true, }); @@ -928,7 +928,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { self.push("I"); print_prefix(self)?; for arg in args { - match arg.unpack() { + match arg.kind() { GenericArgKind::Lifetime(lt) => { lt.print(self)?; } diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index fdd547448f004..aeadb32ac2b4e 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -738,7 +738,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { value.push_normal(", "); } - match arg.unpack() { + match arg.kind() { ty::GenericArgKind::Lifetime(lt) => { let s = lt.to_string(); value.push_normal(if s.is_empty() { "'_" } else { &s }); @@ -1166,7 +1166,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { for (i, (arg1, arg2)) in sub1.iter().zip(sub2).enumerate().take(len) { self.push_comma(&mut values.0, &mut values.1, i); - match arg1.unpack() { + match arg1.kind() { // At one point we'd like to elide all lifetimes here, they are // irrelevant for all diagnostics that use this output. // @@ -1509,7 +1509,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } let (is_simple_error, exp_found) = match values { ValuePairs::Terms(ExpectedFound { expected, found }) => { - match (expected.unpack(), found.unpack()) { + match (expected.kind(), found.kind()) { (ty::TermKind::Ty(expected), ty::TermKind::Ty(found)) => { let is_simple_err = expected.is_simple_text() && found.is_simple_text(); @@ -2156,7 +2156,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { return None; } - Some(match (exp_found.expected.unpack(), exp_found.found.unpack()) { + Some(match (exp_found.expected.kind(), exp_found.found.kind()) { (ty::TermKind::Ty(expected), ty::TermKind::Ty(found)) => { let (mut exp, mut fnd) = self.cmp(expected, found); // Use the terminal width as the basis to determine when to compress the printed 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 cb1c9c7536903..bfef3340b323f 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 @@ -215,7 +215,7 @@ impl<'a, 'tcx> TypeFolder> for ClosureEraser<'a, 'tcx> { // `_` because then we'd end up with `Vec<_, _>`, instead of // `Vec<_>`. arg - } else if let GenericArgKind::Type(_) = arg.unpack() { + } else if let GenericArgKind::Type(_) = arg.kind() { // We don't replace lifetime or const params, only type params. self.new_infer().into() } else { @@ -347,7 +347,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { highlight: ty::print::RegionHighlightMode<'tcx>, ) -> InferenceDiagnosticsData { let tcx = self.tcx; - match term.unpack() { + match term.kind() { TermKind::Ty(ty) => { if let ty::Infer(ty::TyVar(ty_vid)) = *ty.kind() { let var_origin = self.infcx.type_var_origin(ty_vid); @@ -568,7 +568,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { return arg; } - match arg.unpack() { + match arg.kind() { GenericArgKind::Lifetime(_) => bug!("unexpected lifetime"), GenericArgKind::Type(_) => self.next_ty_var(DUMMY_SP).into(), GenericArgKind::Const(_) => self.next_const_var(DUMMY_SP).into(), @@ -803,7 +803,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { } impl<'tcx> CostCtxt<'tcx> { fn arg_cost(self, arg: GenericArg<'tcx>) -> usize { - match arg.unpack() { + match arg.kind() { GenericArgKind::Lifetime(_) => 0, // erased GenericArgKind::Type(ty) => self.ty_cost(ty), GenericArgKind::Const(_) => 3, // some non-zero value @@ -898,7 +898,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { return true; } - match (arg.unpack(), self.target.unpack()) { + match (arg.kind(), self.target.kind()) { (GenericArgKind::Type(inner_ty), TermKind::Ty(target_ty)) => { use ty::{Infer, TyVar}; match (inner_ty.kind(), target_ty.kind()) { @@ -929,7 +929,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { if self.generic_arg_is_target(inner) { return true; } - match inner.unpack() { + match inner.kind() { GenericArgKind::Lifetime(_) => {} GenericArgKind::Type(ty) => { if matches!( diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs index cdbb92f4c7baa..3804c13acce8e 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs @@ -664,8 +664,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let Some(found) = exp_found.found.args.get(1) else { return; }; - let expected = expected.unpack(); - let found = found.unpack(); + let expected = expected.kind(); + let found = found.kind(); // 3. Extract the tuple type from Fn trait and suggest the change. if let GenericArgKind::Type(expected) = expected && let GenericArgKind::Type(found) = found diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index b88040a0f983d..9b5e421e0e481 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -2446,7 +2446,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } if let ty::Adt(def, args) = self_ty.kind() && let [arg] = &args[..] - && let ty::GenericArgKind::Type(ty) = arg.unpack() + && let ty::GenericArgKind::Type(ty) = arg.kind() && let ty::Adt(inner_def, _) = ty.kind() && inner_def == def { diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 332204a0c5f06..d5bde9192d5e2 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -81,7 +81,7 @@ pub fn check_opaque_type_parameter_valid<'tcx>( } for (i, arg) in opaque_type_key.iter_captured_args(tcx) { - let arg_is_param = match arg.unpack() { + let arg_is_param = match arg.kind() { GenericArgKind::Lifetime(lt) => match defining_scope_kind { DefiningScopeKind::HirTypeck => continue, DefiningScopeKind::MirBorrowck => { diff --git a/compiler/rustc_trait_selection/src/solve/delegate.rs b/compiler/rustc_trait_selection/src/solve/delegate.rs index eea311fe66ebb..038cdc1a56499 100644 --- a/compiler/rustc_trait_selection/src/solve/delegate.rs +++ b/compiler/rustc_trait_selection/src/solve/delegate.rs @@ -108,7 +108,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< arg: ty::GenericArg<'tcx>, span: Span, ) -> ty::GenericArg<'tcx> { - match arg.unpack() { + match arg.kind() { ty::GenericArgKind::Lifetime(_) => { self.next_region_var(RegionVariableOrigin::MiscVariable(span)).into() } diff --git a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs index 49a8b363b0aba..fda2c97ed56f4 100644 --- a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs +++ b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs @@ -207,7 +207,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> { let infcx = self.goal.infcx; match goal.predicate.kind().no_bound_vars() { Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => { - let unconstrained_term = match term.unpack() { + let unconstrained_term = match term.kind() { ty::TermKind::Ty(_) => infcx.next_ty_var(span).into(), ty::TermKind::Const(_) => infcx.next_const_var(span).into(), }; diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 2be799735a899..3a2f9e8ca179f 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1784,7 +1784,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { if !generics.is_own_empty() && obligation.predicate.args[generics.parent_count..].iter().any(|&p| { p.has_non_region_infer() - && match p.unpack() { + && match p.kind() { ty::GenericArgKind::Const(ct) => { self.infcx.shallow_resolve_const(ct) != ct } diff --git a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs index e6d5d336b8d55..3f7413454047d 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs @@ -39,7 +39,7 @@ impl<'tcx> At<'_, 'tcx> { return Ok(term); } - let new_infer = match term.unpack() { + let new_infer = match term.kind() { ty::TermKind::Ty(_) => self.infcx.next_ty_var(self.cause.span).into(), ty::TermKind::Const(_) => self.infcx.next_const_var(self.cause.span).into(), }; diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 08d3b92e9b5ef..3018dad8e0916 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -37,7 +37,7 @@ pub fn obligations<'tcx>( span: Span, ) -> Option> { // Handle the "cycle" case (see comment above) by bailing out if necessary. - let term = match term.unpack() { + let term = match term.kind() { TermKind::Ty(ty) => { match ty.kind() { ty::Infer(ty::TyVar(_)) => { diff --git a/compiler/rustc_ty_utils/src/representability.rs b/compiler/rustc_ty_utils/src/representability.rs index 98b1550e1a3d6..33d334092ba9c 100644 --- a/compiler/rustc_ty_utils/src/representability.rs +++ b/compiler/rustc_ty_utils/src/representability.rs @@ -74,7 +74,7 @@ fn representability_adt_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Representab // but the type parameters may cause a cycle with an upstream type let params_in_repr = tcx.params_in_repr(adt.did()); for (i, arg) in args.iter().enumerate() { - if let ty::GenericArgKind::Type(ty) = arg.unpack() { + if let ty::GenericArgKind::Type(ty) = arg.kind() { if params_in_repr.contains(i as u32) { rtry!(representability_ty(tcx, ty)); } @@ -104,7 +104,7 @@ fn params_in_repr_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, params_in_repr: &mut ty::Adt(adt, args) => { let inner_params_in_repr = tcx.params_in_repr(adt.did()); for (i, arg) in args.iter().enumerate() { - if let ty::GenericArgKind::Type(ty) = arg.unpack() { + if let ty::GenericArgKind::Type(ty) = arg.kind() { if inner_params_in_repr.contains(i as u32) { params_in_repr_ty(tcx, ty, params_in_repr); } diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 0c49ddff39bc2..330aaa25d1350 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -274,7 +274,7 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> DenseBitSe let def = tcx.adt_def(def_id); let num_params = tcx.generics_of(def_id).count(); - let maybe_unsizing_param_idx = |arg: ty::GenericArg<'tcx>| match arg.unpack() { + let maybe_unsizing_param_idx = |arg: ty::GenericArg<'tcx>| match arg.kind() { ty::GenericArgKind::Type(ty) => match ty.kind() { ty::Param(p) => Some(p.index), _ => None, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 28dfa01534ead..0fbffc7808de0 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -449,7 +449,7 @@ fn clean_middle_term<'tcx>( term: ty::Binder<'tcx, ty::Term<'tcx>>, cx: &mut DocContext<'tcx>, ) -> Term { - match term.skip_binder().unpack() { + match term.skip_binder().kind() { ty::TermKind::Ty(ty) => Term::Type(clean_middle_ty(term.rebind(ty), cx, None, None)), ty::TermKind::Const(c) => Term::Constant(clean_middle_const(term.rebind(c), cx)), } diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 2e38b6cdc650b..c58b07a5b6731 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -124,7 +124,7 @@ pub(crate) fn clean_middle_generic_args<'tcx>( elision_has_failed_once_before = true; } - match arg.skip_binder().unpack() { + match arg.skip_binder().kind() { GenericArgKind::Lifetime(lt) => { Some(GenericArg::Lifetime(clean_middle_region(lt).unwrap_or(Lifetime::elided()))) } @@ -161,7 +161,7 @@ fn can_elide_generic_arg<'tcx>( default: ty::Binder<'tcx, ty::GenericArg<'tcx>>, ) -> bool { debug_assert_matches!( - (actual.skip_binder().unpack(), default.skip_binder().unpack()), + (actual.skip_binder().kind(), default.skip_binder().kind()), (ty::GenericArgKind::Lifetime(_), ty::GenericArgKind::Lifetime(_)) | (ty::GenericArgKind::Type(_), ty::GenericArgKind::Type(_)) | (ty::GenericArgKind::Const(_), ty::GenericArgKind::Const(_)) diff --git a/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs b/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs index 2643f850879cc..9e09fb5bb4396 100644 --- a/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs +++ b/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for ArcWithNonSendSync { && let arg_ty = cx.typeck_results().expr_ty(arg) // make sure that the type is not and does not contain any type parameters && arg_ty.walk().all(|arg| { - !matches!(arg.unpack(), GenericArgKind::Type(ty) if matches!(ty.kind(), ty::Param(_))) + !matches!(arg.kind(), GenericArgKind::Type(ty) if matches!(ty.kind(), ty::Param(_))) }) && let Some(send) = cx.tcx.get_diagnostic_item(sym::Send) && let Some(sync) = cx.tcx.lang_items().sync_trait() diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index 3443b36eb4f39..062f7cef3a72a 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -345,7 +345,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h if ty_adt.repr().packed() && ty_subs .iter() - .any(|arg| matches!(arg.unpack(), GenericArgKind::Type(_) | GenericArgKind::Const(_))) + .any(|arg| matches!(arg.kind(), GenericArgKind::Type(_) | GenericArgKind::Const(_))) { return; } diff --git a/src/tools/clippy/clippy_lints/src/eta_reduction.rs b/src/tools/clippy/clippy_lints/src/eta_reduction.rs index 645f93068496b..6ed7c87915b27 100644 --- a/src/tools/clippy/clippy_lints/src/eta_reduction.rs +++ b/src/tools/clippy/clippy_lints/src/eta_reduction.rs @@ -306,7 +306,7 @@ fn has_late_bound_to_non_late_bound_regions(from_sig: FnSig<'_>, to_sig: FnSig<' return true; } for (from_arg, to_arg) in to_subs.iter().zip(from_subs) { - match (from_arg.unpack(), to_arg.unpack()) { + match (from_arg.kind(), to_arg.kind()) { (GenericArgKind::Lifetime(from_region), GenericArgKind::Lifetime(to_region)) => { if check_region(from_region, to_region) { return true; @@ -354,5 +354,5 @@ fn has_late_bound_to_non_late_bound_regions(from_sig: FnSig<'_>, to_sig: FnSig<' fn ty_has_static(ty: Ty<'_>) -> bool { ty.walk() - .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(re) if re.is_static())) + .any(|arg| matches!(arg.kind(), GenericArgKind::Lifetime(re) if re.is_static())) } diff --git a/src/tools/clippy/clippy_lints/src/functions/ref_option.rs b/src/tools/clippy/clippy_lints/src/functions/ref_option.rs index aba0fbcb9feb3..106202d00d403 100644 --- a/src/tools/clippy/clippy_lints/src/functions/ref_option.rs +++ b/src/tools/clippy/clippy_lints/src/functions/ref_option.rs @@ -17,7 +17,7 @@ fn check_ty<'a>(cx: &LateContext<'a>, param: &rustc_hir::Ty<'a>, param_ty: Ty<'a && is_type_diagnostic_item(cx, *opt_ty, sym::Option) && let ty::Adt(_, opt_gen_args) = opt_ty.kind() && let [gen_arg] = opt_gen_args.as_slice() - && let GenericArgKind::Type(gen_ty) = gen_arg.unpack() + && let GenericArgKind::Type(gen_ty) = gen_arg.kind() && !gen_ty.is_ref() // Need to gen the original spans, so first parsing mid, and hir parsing afterward && let hir::TyKind::Ref(lifetime, hir::MutTy { ty, .. }) = param.kind diff --git a/src/tools/clippy/clippy_lints/src/let_underscore.rs b/src/tools/clippy/clippy_lints/src/let_underscore.rs index 916191b2a7b0f..b72e14246db72 100644 --- a/src/tools/clippy/clippy_lints/src/let_underscore.rs +++ b/src/tools/clippy/clippy_lints/src/let_underscore.rs @@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore { && !local.span.in_external_macro(cx.tcx.sess.source_map()) { let init_ty = cx.typeck_results().expr_ty(init); - let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() { + let contains_sync_guard = init_ty.walk().any(|inner| match inner.kind() { GenericArgKind::Type(inner_ty) => inner_ty .ty_adt_def() .is_some_and(|adt| paths::PARKING_LOT_GUARDS.iter().any(|path| path.matches(cx, adt.did()))), diff --git a/src/tools/clippy/clippy_lints/src/matches/manual_unwrap_or.rs b/src/tools/clippy/clippy_lints/src/matches/manual_unwrap_or.rs index 3ac2c9fc2b361..8c3f52542d917 100644 --- a/src/tools/clippy/clippy_lints/src/matches/manual_unwrap_or.rs +++ b/src/tools/clippy/clippy_lints/src/matches/manual_unwrap_or.rs @@ -109,7 +109,7 @@ fn handle( && implements_trait(cx, expr_type, default_trait_id, &[]) // We check if the initial condition implements Default. && let Some(condition_ty) = cx.typeck_results().expr_ty(condition).walk().nth(1) - && let GenericArgKind::Type(condition_ty) = condition_ty.unpack() + && let GenericArgKind::Type(condition_ty) = condition_ty.kind() && implements_trait(cx, condition_ty, default_trait_id, &[]) && is_default_equivalent(cx, peel_blocks(body_none)) { diff --git a/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs b/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs index aa9be61bf4d43..c936c96f9719a 100644 --- a/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs @@ -108,7 +108,7 @@ fn find_match_true<'tcx>( fn try_get_generic_ty(ty: Ty<'_>, index: usize) -> Option> { if let ty::Adt(_, subs) = ty.kind() && let Some(sub) = subs.get(index) - && let GenericArgKind::Type(sub_ty) = sub.unpack() + && let GenericArgKind::Type(sub_ty) = sub.kind() { Some(sub_ty) } else { diff --git a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 0f3ad40784d36..88b4d9b7d544e 100644 --- a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -208,12 +208,12 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> { // (to avoid false positive on `Ref<'a, MutexGuard>`) || (args .iter() - .all(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_))) + .all(|arg| !matches!(arg.kind(), GenericArgKind::Lifetime(_))) // some generic parameter has significant drop // (to avoid false negative on `Box>`) && args .iter() - .filter_map(|arg| match arg.unpack() { + .filter_map(|arg| match arg.kind() { GenericArgKind::Type(ty) => Some(ty), _ => None, }) diff --git a/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs b/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs index 4c1ed6a1d833e..2b75d6a8248a0 100644 --- a/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs @@ -508,7 +508,7 @@ fn get_captured_ids(cx: &LateContext<'_>, ty: Ty<'_>) -> HirIdSet { match ty.kind() { ty::Adt(_, generics) => { for generic in *generics { - if let GenericArgKind::Type(ty) = generic.unpack() { + if let GenericArgKind::Type(ty) = generic.kind() { get_captured_ids_recursive(cx, ty, set); } } diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_sort_by.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_sort_by.rs index fb4984914eb03..dbff08bc51c90 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_sort_by.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_sort_by.rs @@ -188,7 +188,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Exp fn expr_borrows(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); - matches!(ty.kind(), ty::Ref(..)) || ty.walk().any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_))) + matches!(ty.kind(), ty::Ref(..)) || ty.walk().any(|arg| matches!(arg.kind(), GenericArgKind::Lifetime(_))) } pub(super) fn check<'tcx>( diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs index 29a0d2950bc6a..768bbebccd4af 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -608,7 +608,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< } fn has_lifetime(ty: Ty<'_>) -> bool { - ty.walk().any(|t| matches!(t.unpack(), GenericArgKind::Lifetime(_))) + ty.walk().any(|t| matches!(t.kind(), GenericArgKind::Lifetime(_))) } /// Returns true if the named method is `Iterator::cloned` or `Iterator::copied`. @@ -643,7 +643,7 @@ fn is_to_string_on_string_like<'a>( if let Some(args) = cx.typeck_results().node_args_opt(call_expr.hir_id) && let [generic_arg] = args.as_slice() - && let GenericArgKind::Type(ty) = generic_arg.unpack() + && let GenericArgKind::Type(ty) = generic_arg.kind() && let Some(deref_trait_id) = cx.tcx.get_diagnostic_item(sym::Deref) && let Some(as_ref_trait_id) = cx.tcx.get_diagnostic_item(sym::AsRef) && (cx.get_associated_type(ty, deref_trait_id, sym::Target) == Some(cx.tcx.types.str_) diff --git a/src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs b/src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs index e579dd5947d74..2efb55b9880c9 100644 --- a/src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -269,7 +269,7 @@ fn needless_borrow_count<'tcx>( .tcx .is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id) && let ty::Param(param_ty) = trait_predicate.self_ty().kind() - && let GenericArgKind::Type(ty) = args_with_referent_ty[param_ty.index as usize].unpack() + && let GenericArgKind::Type(ty) = args_with_referent_ty[param_ty.index as usize].kind() && ty.is_array() && !msrv.meets(cx, msrvs::ARRAY_INTO_ITERATOR) { diff --git a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs index 9542fed38759a..8ff78ec7c580d 100644 --- a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -172,7 +172,7 @@ impl NonSendField<'_> { /// Example: `MyStruct>` => `vec![P, Q, R]` fn collect_generic_params(ty: Ty<'_>) -> Vec> { ty.walk() - .filter_map(|inner| match inner.unpack() { + .filter_map(|inner| match inner.kind() { GenericArgKind::Type(inner_ty) => Some(inner_ty), _ => None, }) @@ -208,7 +208,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t ty::Adt(_, args) => { if contains_pointer_like(cx, ty) { // descends only if ADT contains any raw pointers - args.iter().all(|generic_arg| match generic_arg.unpack() { + args.iter().all(|generic_arg| match generic_arg.kind() { GenericArgKind::Type(ty) => ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait), // Lifetimes and const generics are not solid part of ADT and ignored GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => true, @@ -226,7 +226,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t /// Checks if the type contains any pointer-like types in args (including nested ones) fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> bool { for ty_node in target_ty.walk() { - if let GenericArgKind::Type(inner_ty) = ty_node.unpack() { + if let GenericArgKind::Type(inner_ty) = ty_node.kind() { match inner_ty.kind() { ty::RawPtr(_, _) => { return true; diff --git a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs index 6de203e068b79..ba8f6354d976a 100644 --- a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs @@ -385,7 +385,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion { fn has_matching_args(kind: FnKind, args: GenericArgsRef<'_>) -> bool { match kind { FnKind::Fn => true, - FnKind::TraitFn => args.iter().enumerate().all(|(idx, subst)| match subst.unpack() { + FnKind::TraitFn => args.iter().enumerate().all(|(idx, subst)| match subst.kind() { GenericArgKind::Lifetime(_) => true, GenericArgKind::Type(ty) => matches!(*ty.kind(), ty::Param(ty) if ty.index as usize == idx), GenericArgKind::Const(c) => matches!(c.kind(), ConstKind::Param(c) if c.index as usize == idx), diff --git a/src/tools/clippy/clippy_lints/src/returns.rs b/src/tools/clippy/clippy_lints/src/returns.rs index ab9b0f88f936c..6bc5af268ff8a 100644 --- a/src/tools/clippy/clippy_lints/src/returns.rs +++ b/src/tools/clippy/clippy_lints/src/returns.rs @@ -487,7 +487,7 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) .skip_binder() .output() .walk() - .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(re) if !re.is_static())) + .any(|arg| matches!(arg.kind(), GenericArgKind::Lifetime(re) if !re.is_static())) { ControlFlow::Break(()) } else { diff --git a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs index f3fea3add592d..521754f7bab72 100644 --- a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs +++ b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs @@ -184,7 +184,7 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> { } } for generic_arg in *b { - if let GenericArgKind::Type(ty) = generic_arg.unpack() + if let GenericArgKind::Type(ty) = generic_arg.kind() && self.has_sig_drop_attr(ty, depth) { return true; diff --git a/src/tools/clippy/clippy_lints/src/use_self.rs b/src/tools/clippy/clippy_lints/src/use_self.rs index 743f54ca993a9..aeda864b7eb5e 100644 --- a/src/tools/clippy/clippy_lints/src/use_self.rs +++ b/src/tools/clippy/clippy_lints/src/use_self.rs @@ -319,7 +319,7 @@ fn same_lifetimes<'tcx>(a: MiddleTy<'tcx>, b: MiddleTy<'tcx>) -> bool { args_a .iter() .zip(args_b.iter()) - .all(|(arg_a, arg_b)| match (arg_a.unpack(), arg_b.unpack()) { + .all(|(arg_a, arg_b)| match (arg_a.kind(), arg_b.kind()) { // TODO: Handle inferred lifetimes (GenericArgKind::Lifetime(inner_a), GenericArgKind::Lifetime(inner_b)) => inner_a == inner_b, (GenericArgKind::Type(type_a), GenericArgKind::Type(type_b)) => same_lifetimes(type_a, type_b), @@ -337,7 +337,7 @@ fn has_no_lifetime(ty: MiddleTy<'_>) -> bool { &Adt(_, args) => !args .iter() // TODO: Handle inferred lifetimes - .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(..))), + .any(|arg| matches!(arg.kind(), GenericArgKind::Lifetime(..))), _ => true, } } diff --git a/src/tools/clippy/clippy_lints_internal/src/msrv_attr_impl.rs b/src/tools/clippy/clippy_lints_internal/src/msrv_attr_impl.rs index 441c688485236..70b3c03d2bbd3 100644 --- a/src/tools/clippy/clippy_lints_internal/src/msrv_attr_impl.rs +++ b/src/tools/clippy/clippy_lints_internal/src/msrv_attr_impl.rs @@ -37,7 +37,7 @@ impl LateLintPass<'_> for MsrvAttrImpl { .type_of(f.did) .instantiate_identity() .walk() - .filter(|t| matches!(t.unpack(), GenericArgKind::Type(_))) + .filter(|t| matches!(t.kind(), GenericArgKind::Type(_))) .any(|t| internal_paths::MSRV_STACK.matches_ty(cx, t.expect_ty())) }) && !items.iter().any(|item| item.ident.name.as_str() == "check_attributes") diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 3a31917657103..8716ee48c88fd 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -3316,7 +3316,7 @@ pub fn leaks_droppable_temporary_with_limited_lifetime<'tcx>(cx: &LateContext<'t if temporary_ty.has_significant_drop(cx.tcx, cx.typing_env()) && temporary_ty .walk() - .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(re) if !re.is_static())) + .any(|arg| matches!(arg.kind(), GenericArgKind::Lifetime(re) if !re.is_static())) { ControlFlow::Break(()) } else { diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 45da266fd8a9a..bb04520c6b7d8 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -55,7 +55,7 @@ pub fn is_min_const_fn<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, msrv: Ms fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, msrv: Msrv) -> McfResult { for arg in ty.walk() { - let ty = match arg.unpack() { + let ty = match arg.kind() { GenericArgKind::Type(ty) => ty, // No constraints on lifetimes or constants, except potentially diff --git a/src/tools/clippy/clippy_utils/src/ty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/mod.rs index c50ad17bfad1e..61e70b3fa0bce 100644 --- a/src/tools/clippy/clippy_utils/src/ty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/mod.rs @@ -78,7 +78,7 @@ pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool /// Walks into `ty` and returns `true` if any inner type is an instance of the given adt /// constructor. pub fn contains_adt_constructor<'tcx>(ty: Ty<'tcx>, adt: AdtDef<'tcx>) -> bool { - ty.walk().any(|inner| match inner.unpack() { + ty.walk().any(|inner| match inner.kind() { GenericArgKind::Type(inner_ty) => inner_ty.ty_adt_def() == Some(adt), GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false, }) @@ -96,7 +96,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' needle: Ty<'tcx>, seen: &mut FxHashSet, ) -> bool { - ty.walk().any(|inner| match inner.unpack() { + ty.walk().any(|inner| match inner.kind() { GenericArgKind::Type(inner_ty) => { if inner_ty == needle { return true; @@ -129,7 +129,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' // For `impl Trait`, it will register a predicate of `::Assoc = U`, // so we check the term for `U`. ty::ClauseKind::Projection(projection_predicate) => { - if let ty::TermKind::Ty(ty) = projection_predicate.term.unpack() + if let ty::TermKind::Ty(ty) = projection_predicate.term.kind() && contains_ty_adt_constructor_opaque_inner(cx, ty, needle, seen) { return true; @@ -526,7 +526,7 @@ pub fn same_type_and_consts<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { args_a .iter() .zip(args_b.iter()) - .all(|(arg_a, arg_b)| match (arg_a.unpack(), arg_b.unpack()) { + .all(|(arg_a, arg_b)| match (arg_a.kind(), arg_b.kind()) { (GenericArgKind::Const(inner_a), GenericArgKind::Const(inner_b)) => inner_a == inner_b, (GenericArgKind::Type(type_a), GenericArgKind::Type(type_b)) => { same_type_and_consts(type_a, type_b) @@ -996,7 +996,7 @@ fn assert_generic_args_match<'tcx>(tcx: TyCtxt<'tcx>, did: DefId, args: &[Generi if let Some((idx, (param, arg))) = params .clone() - .zip(args.iter().map(|&x| x.unpack())) + .zip(args.iter().map(|&x| x.kind())) .enumerate() .find(|(_, (param, arg))| match (param, arg) { (GenericParamDefKind::Lifetime, GenericArgKind::Lifetime(_)) diff --git a/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs index 6e3586623277f..84df36c75bf89 100644 --- a/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs @@ -326,5 +326,5 @@ fn adt_def_id(ty: Ty<'_>) -> Option { fn contains_param(ty: Ty<'_>, index: u32) -> bool { ty.walk() - .any(|arg| matches!(arg.unpack(), GenericArgKind::Type(ty) if ty.is_param(index))) + .any(|arg| matches!(arg.kind(), GenericArgKind::Type(ty) if ty.is_param(index))) } diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 5d5c19a24fa3d..e7a2cb25159ac 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -1775,7 +1775,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { let is_generic = instance .args .into_iter() - .any(|kind| !matches!(kind.unpack(), ty::GenericArgKind::Lifetime(_))); + .any(|arg| !matches!(arg.kind(), ty::GenericArgKind::Lifetime(_))); let can_be_inlined = matches!( ecx.tcx.sess.opts.unstable_opts.cross_crate_inline_threshold, InliningThreshold::Always From 5f3ae06db07adcd6885558aa1f33ec2711fe0651 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 24 May 2025 17:41:09 +0000 Subject: [PATCH 07/10] Fix some var names --- compiler/rustc_borrowck/src/diagnostics/region_name.rs | 6 +++--- compiler/rustc_hir_analysis/src/outlives/mod.rs | 4 ++-- compiler/rustc_hir_analysis/src/outlives/utils.rs | 6 +++--- .../rustc_hir_analysis/src/variance/constraints.rs | 8 ++++---- .../src/fn_ctxt/adjust_fulfillment_errors.rs | 10 +++++----- compiler/rustc_infer/src/infer/outlives/obligations.rs | 4 ++-- compiler/rustc_middle/src/ty/generic_args.rs | 2 +- compiler/rustc_middle/src/ty/opaque_types.rs | 6 +++--- compiler/rustc_middle/src/ty/typeck_results.rs | 4 ++-- compiler/rustc_middle/src/ty/util.rs | 4 ++-- .../rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs | 4 ++-- compiler/rustc_type_ir/src/binder.rs | 6 +++--- compiler/rustc_type_ir/src/flags.rs | 4 ++-- 13 files changed, 34 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 4aa9e90ab885a..487f78058a8ca 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -606,8 +606,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { hir_args: &'hir hir::GenericArgs<'hir>, search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>, ) -> Option<&'hir hir::Lifetime> { - for (kind, hir_arg) in iter::zip(args, hir_args.args) { - match (kind.kind(), hir_arg) { + for (arg, hir_arg) in iter::zip(args, hir_args.args) { + match (arg.kind(), hir_arg) { (GenericArgKind::Lifetime(r), hir::GenericArg::Lifetime(lt)) => { if r.as_var() == needle_fr { return Some(lt); @@ -631,7 +631,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { ) => { self.dcx().span_delayed_bug( hir_arg.span(), - format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"), + format!("unmatched arg and hir arg: found {arg:?} vs {hir_arg:?}"), ); } } diff --git a/compiler/rustc_hir_analysis/src/outlives/mod.rs b/compiler/rustc_hir_analysis/src/outlives/mod.rs index fbf973a49dc7b..499f5572f470a 100644 --- a/compiler/rustc_hir_analysis/src/outlives/mod.rs +++ b/compiler/rustc_hir_analysis/src/outlives/mod.rs @@ -69,8 +69,8 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> { .map(|(&def_id, set)| { let predicates = &*tcx.arena.alloc_from_iter(set.as_ref().skip_binder().iter().filter_map( - |(ty::OutlivesPredicate(kind1, region2), &span)| { - match kind1.kind() { + |(ty::OutlivesPredicate(arg1, region2), &span)| { + match arg1.kind() { GenericArgKind::Type(ty1) => Some(( ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)) .upcast(tcx), diff --git a/compiler/rustc_hir_analysis/src/outlives/utils.rs b/compiler/rustc_hir_analysis/src/outlives/utils.rs index 3fd1dbb3a8a08..301f5de9424e5 100644 --- a/compiler/rustc_hir_analysis/src/outlives/utils.rs +++ b/compiler/rustc_hir_analysis/src/outlives/utils.rs @@ -14,7 +14,7 @@ pub(crate) type RequiredPredicates<'tcx> = /// outlives_component and add it to `required_predicates` pub(crate) fn insert_outlives_predicate<'tcx>( tcx: TyCtxt<'tcx>, - kind: GenericArg<'tcx>, + arg: GenericArg<'tcx>, outlived_region: Region<'tcx>, span: Span, required_predicates: &mut RequiredPredicates<'tcx>, @@ -25,7 +25,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>( return; } - match kind.kind() { + match arg.kind() { GenericArgKind::Type(ty) => { // `T: 'outlived_region` for some type `T` // But T could be a lot of things: @@ -135,7 +135,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>( if !is_free_region(r) { return; } - required_predicates.entry(ty::OutlivesPredicate(kind, outlived_region)).or_insert(span); + required_predicates.entry(ty::OutlivesPredicate(arg, outlived_region)).or_insert(span); } GenericArgKind::Const(_) => { diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 68ceec384b958..960ec7f66ab15 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -200,8 +200,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { // Trait are always invariant so we can take advantage of that. let variance_i = self.invariant(variance); - for k in args { - match k.kind() { + for arg in args { + match arg.kind() { GenericArgKind::Lifetime(lt) => { self.add_constraints_from_region(current, lt, variance_i) } @@ -373,7 +373,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { (None, Some(self.tcx().variances_of(def_id))) }; - for (i, k) in args.iter().enumerate() { + for (i, arg) in args.iter().enumerate() { let variance_decl = if let Some(InferredIndex(start)) = local { // Parameter on an item defined within current crate: // variance not yet inferred, so return a symbolic @@ -389,7 +389,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { "add_constraints_from_args: variance_decl={:?} variance_i={:?}", variance_decl, variance_i ); - match k.kind() { + match arg.kind() { GenericArgKind::Lifetime(lt) => { self.add_constraints_from_region(current, lt, variance_i) } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index db6482fe4faf5..2bc007b3ad4b5 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -357,7 +357,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, error: &mut traits::FulfillmentError<'tcx>, def_id: DefId, - param: ty::GenericArg<'tcx>, + arg: ty::GenericArg<'tcx>, qpath: &hir::QPath<'tcx>, ) -> bool { match qpath { @@ -365,7 +365,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for segment in path.segments.iter().rev() { if let Res::Def(kind, def_id) = segment.res && !matches!(kind, DefKind::Mod | DefKind::ForeignMod) - && self.point_at_generic_if_possible(error, def_id, param, segment) + && self.point_at_generic_if_possible(error, def_id, arg, segment) { return true; } @@ -373,7 +373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Handle `Self` param specifically, since it's separated in // the path representation if let Some(self_ty) = self_ty - && let ty::GenericArgKind::Type(ty) = param.kind() + && let ty::GenericArgKind::Type(ty) = arg.kind() && ty == self.tcx.types.self_param { error.obligation.cause.span = self_ty @@ -384,12 +384,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } hir::QPath::TypeRelative(self_ty, segment) => { - if self.point_at_generic_if_possible(error, def_id, param, segment) { + if self.point_at_generic_if_possible(error, def_id, arg, segment) { return true; } // Handle `Self` param specifically, since it's separated in // the path representation - if let ty::GenericArgKind::Type(ty) = param.kind() + if let ty::GenericArgKind::Type(ty) = arg.kind() && ty == self.tcx.types.self_param { error.obligation.cause.span = self_ty diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 0d2732a3b6d38..10827c9fd037b 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -503,8 +503,8 @@ where opt_variances: Option<&[ty::Variance]>, ) { let constraint = origin.to_constraint_category(); - for (index, k) in args.iter().enumerate() { - match k.kind() { + for (index, arg) in args.iter().enumerate() { + match arg.kind() { GenericArgKind::Lifetime(lt) => { let variance = if let Some(variances) = opt_variances { variances[index] diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index b7d3fd81b1117..5e038f9167507 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -527,7 +527,7 @@ impl<'tcx> GenericArgs<'tcx> { /// Returns generic arguments that are not lifetimes. #[inline] pub fn non_erasable_generics(&self) -> impl DoubleEndedIterator> { - self.iter().filter_map(|k| match k.kind() { + self.iter().filter_map(|arg| match arg.kind() { ty::GenericArgKind::Lifetime(_) => None, generic => Some(generic), }) diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 5c05bdb08ebad..2b024b7b6cbb3 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -120,7 +120,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { } } - match self.map.get(&r.into()).map(|k| k.kind()) { + match self.map.get(&r.into()).map(|arg| arg.kind()) { Some(GenericArgKind::Lifetime(r1)) => r1, Some(u) => panic!("region mapped to unexpected kind: {u:?}"), None if self.do_not_error => self.tcx.lifetimes.re_static, @@ -162,7 +162,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { ty::Param(param) => { // Look it up in the generic parameters list. - match self.map.get(&ty.into()).map(|k| k.kind()) { + match self.map.get(&ty.into()).map(|arg| arg.kind()) { // Found it in the generic parameters list; replace with the parameter from the // opaque type. Some(GenericArgKind::Type(t1)) => t1, @@ -195,7 +195,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { match ct.kind() { ty::ConstKind::Param(..) => { // Look it up in the generic parameters list. - match self.map.get(&ct.into()).map(|k| k.kind()) { + match self.map.get(&ct.into()).map(|arg| arg.kind()) { // Found it in the generic parameters list, replace with the parameter from the // opaque type. Some(GenericArgKind::Const(c1)) => c1, diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index 9627188c334e9..cc3887079d818 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -777,8 +777,8 @@ impl<'tcx> IsIdentity for CanonicalUserType<'tcx> { return false; } - iter::zip(user_args.args, BoundVar::ZERO..).all(|(kind, cvar)| { - match kind.kind() { + iter::zip(user_args.args, BoundVar::ZERO..).all(|(arg, cvar)| { + match arg.kind() { GenericArgKind::Type(ty) => match ty.kind() { ty::Bound(debruijn, b) => { // We only allow a `ty::INNERMOST` index in generic parameters. diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 06fd8a294d0eb..461d92f800639 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -516,8 +516,8 @@ impl<'tcx> TyCtxt<'tcx> { let item_args = ty::GenericArgs::identity_for_item(self, def.did()); let result = iter::zip(item_args, impl_args) - .filter(|&(_, k)| { - match k.kind() { + .filter(|&(_, arg)| { + match arg.kind() { GenericArgKind::Lifetime(region) => match region.kind() { ty::ReEarlyParam(ebr) => { !impl_generics.region_param(ebr, self).pure_wrt_drop diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index e696da9c2b72c..2924208173d2b 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -817,8 +817,8 @@ where /// Returns a ty infer or a const infer depending on whether `kind` is a `Ty` or `Const`. /// If `kind` is an integer inference variable this will still return a ty infer var. - pub(super) fn next_term_infer_of_kind(&mut self, kind: I::Term) -> I::Term { - match kind.kind() { + pub(super) fn next_term_infer_of_kind(&mut self, term: I::Term) -> I::Term { + match term.kind() { ty::TermKind::Ty(_) => self.next_ty_infer().into(), ty::TermKind::Const(_) => self.next_const_infer().into(), } diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index 000cf1e1fd8b1..1e6ca0dcf5d3e 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -676,7 +676,7 @@ impl<'a, I: Interner> TypeFolder for ArgFolder<'a, I> { // the specialized routine `ty::replace_late_regions()`. match r.kind() { ty::ReEarlyParam(data) => { - let rk = self.args.get(data.index() as usize).map(|k| k.kind()); + let rk = self.args.get(data.index() as usize).map(|arg| arg.kind()); match rk { Some(ty::GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt), Some(other) => self.region_param_expected(data, r, other), @@ -716,7 +716,7 @@ impl<'a, I: Interner> TypeFolder for ArgFolder<'a, I> { impl<'a, I: Interner> ArgFolder<'a, I> { fn ty_for_param(&self, p: I::ParamTy, source_ty: I::Ty) -> I::Ty { // Look up the type in the args. It really should be in there. - let opt_ty = self.args.get(p.index() as usize).map(|k| k.kind()); + let opt_ty = self.args.get(p.index() as usize).map(|arg| arg.kind()); let ty = match opt_ty { Some(ty::GenericArgKind::Type(ty)) => ty, Some(kind) => self.type_param_expected(p, source_ty, kind), @@ -753,7 +753,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> { fn const_for_param(&self, p: I::ParamConst, source_ct: I::Const) -> I::Const { // Look up the const in the args. It really should be in there. - let opt_ct = self.args.get(p.index() as usize).map(|k| k.kind()); + let opt_ct = self.args.get(p.index() as usize).map(|arg| arg.kind()); let ct = match opt_ct { Some(ty::GenericArgKind::Const(ct)) => ct, Some(kind) => self.const_param_expected(p, source_ct, kind), diff --git a/compiler/rustc_type_ir/src/flags.rs b/compiler/rustc_type_ir/src/flags.rs index 7ed0f92b6398a..37cc2baa402a0 100644 --- a/compiler/rustc_type_ir/src/flags.rs +++ b/compiler/rustc_type_ir/src/flags.rs @@ -479,8 +479,8 @@ impl FlagComputation { } fn add_args(&mut self, args: &[I::GenericArg]) { - for kind in args { - match kind.kind() { + for arg in args { + match arg.kind() { ty::GenericArgKind::Type(ty) => self.add_ty(ty), ty::GenericArgKind::Lifetime(lt) => self.add_region(lt), ty::GenericArgKind::Const(ct) => self.add_const(ct), From e25cf45daa8069ca984b2e4132774681461e4231 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Tue, 27 May 2025 00:52:38 +0800 Subject: [PATCH 08/10] triagebot: label `src/llvm-project` and `rustc_{llvm, codegen_llvm}` changes with `A-LLVM` --- triagebot.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index 9d7a0ef5aec0c..572568d5d52bf 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -593,6 +593,13 @@ trigger_files = [ "src/doc/rustc-dev-guide", ] +[autolabel."A-LLVM"] +trigger_files = [ + "src/llvm-project", + "compiler/rustc_llvm", + "compiler/rustc_codegen_llvm", +] + [notify-zulip."I-prioritize"] zulip_stream = 245100 # #t-compiler/prioritization/alerts topic = "#{number} {title}" From 3f526eeec4efe8a31154b7b20b64d99c1badce9e Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 27 May 2025 23:25:57 +1000 Subject: [PATCH 09/10] coverage: Revert "unused local file IDs" due to empty function names This reverts commit 3b22c21dd8c30f499051fe7a758ca0e5d81eb638, reversing changes made to 5f292eea6d63abbd26f1e6e00a0b8cf21d828d7d. --- .../src/coverageinfo/ffi.rs | 26 +++-------- .../src/coverageinfo/mapgen/covfun.rs | 44 +++++-------------- .../src/coverageinfo/mapgen/spans.rs | 28 ++++++++++-- compiler/rustc_interface/src/tests.rs | 3 +- .../rustc_mir_transform/src/coverage/spans.rs | 38 +--------------- compiler/rustc_session/src/config.rs | 5 --- compiler/rustc_session/src/options.rs | 1 - compiler/rustc_session/src/session.rs | 5 --- tests/coverage/async_closure.cov-map | 21 +++++---- tests/coverage/unused-local-file.coverage | 7 --- tests/coverage/unused-local-file.rs | 22 ---------- ...ch_match_arms.main.InstrumentCoverage.diff | 2 +- ...ument_coverage.bar.InstrumentCoverage.diff | 2 +- ...ment_coverage.main.InstrumentCoverage.diff | 4 +- ...rage_cleanup.main.CleanupPostBorrowck.diff | 4 +- ...erage_cleanup.main.InstrumentCoverage.diff | 4 +- 16 files changed, 62 insertions(+), 154 deletions(-) delete mode 100644 tests/coverage/unused-local-file.coverage delete mode 100644 tests/coverage/unused-local-file.rs diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs index c207df2fb0b45..f6000e7284002 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs @@ -155,20 +155,6 @@ pub(crate) struct Regions { impl Regions { /// Returns true if none of this structure's tables contain any regions. pub(crate) fn has_no_regions(&self) -> bool { - // Every region has a span, so if there are no spans then there are no regions. - self.all_cov_spans().next().is_none() - } - - pub(crate) fn all_cov_spans(&self) -> impl Iterator { - macro_rules! iter_cov_spans { - ( $( $regions:expr ),* $(,)? ) => { - std::iter::empty() - $( - .chain( $regions.iter().map(|region| ®ion.cov_span) ) - )* - } - } - let Self { code_regions, expansion_regions, @@ -177,13 +163,11 @@ impl Regions { mcdc_decision_regions, } = self; - iter_cov_spans!( - code_regions, - expansion_regions, - branch_regions, - mcdc_branch_regions, - mcdc_decision_regions, - ) + code_regions.is_empty() + && expansion_regions.is_empty() + && branch_regions.is_empty() + && mcdc_branch_regions.is_empty() + && mcdc_decision_regions.is_empty() } } diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs index d3a815fabe7a9..7bdbc68595290 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs @@ -11,7 +11,6 @@ use rustc_abi::Align; use rustc_codegen_ssa::traits::{ BaseTypeCodegenMethods as _, ConstCodegenMethods, StaticCodegenMethods, }; -use rustc_index::IndexVec; use rustc_middle::mir::coverage::{ BasicCoverageBlock, CovTerm, CoverageIdsInfo, Expression, FunctionCoverageInfo, Mapping, MappingKind, Op, @@ -105,16 +104,6 @@ fn fill_region_tables<'tcx>( ids_info: &'tcx CoverageIdsInfo, covfun: &mut CovfunRecord<'tcx>, ) { - // If this function is unused, replace all counters with zero. - let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter { - let term = if covfun.is_used { - ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term") - } else { - CovTerm::Zero - }; - ffi::Counter::from_term(term) - }; - // Currently a function's mappings must all be in the same file, so use the // first mapping's span to determine the file. let source_map = tcx.sess.source_map(); @@ -126,12 +115,6 @@ fn fill_region_tables<'tcx>( let local_file_id = covfun.virtual_file_mapping.push_file(&source_file); - // If this testing flag is set, add an extra unused entry to the local - // file table, to help test the code for detecting unused file IDs. - if tcx.sess.coverage_inject_unused_local_file() { - covfun.virtual_file_mapping.push_file(&source_file); - } - // In rare cases, _all_ of a function's spans are discarded, and coverage // codegen needs to handle that gracefully to avoid #133606. // It's hard for tests to trigger this organically, so instead we set @@ -152,6 +135,16 @@ fn fill_region_tables<'tcx>( // For each counter/region pair in this function+file, convert it to a // form suitable for FFI. for &Mapping { ref kind, span } in &fn_cov_info.mappings { + // If this function is unused, replace all counters with zero. + let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter { + let term = if covfun.is_used { + ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term") + } else { + CovTerm::Zero + }; + ffi::Counter::from_term(term) + }; + let Some(coords) = make_coords(span) else { continue }; let cov_span = coords.make_coverage_span(local_file_id); @@ -184,19 +177,6 @@ fn fill_region_tables<'tcx>( } } -/// LLVM requires all local file IDs to have at least one mapping region. -/// If that's not the case, skip this function, to avoid an assertion failure -/// (or worse) in LLVM. -fn check_local_file_table(covfun: &CovfunRecord<'_>) -> bool { - let mut local_file_id_seen = - IndexVec::::from_elem_n(false, covfun.virtual_file_mapping.local_file_table.len()); - for cov_span in covfun.regions.all_cov_spans() { - local_file_id_seen[cov_span.file_id] = true; - } - - local_file_id_seen.into_iter().all(|seen| seen) -} - /// Generates the contents of the covfun record for this function, which /// contains the function's coverage mapping data. The record is then stored /// as a global variable in the `__llvm_covfun` section. @@ -205,10 +185,6 @@ pub(crate) fn generate_covfun_record<'tcx>( global_file_table: &GlobalFileTable, covfun: &CovfunRecord<'tcx>, ) { - if !check_local_file_table(covfun) { - return; - } - let &CovfunRecord { mangled_function_name, source_hash, diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs index 574463be7ffe0..39a59560c9d3e 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs @@ -39,10 +39,7 @@ impl Coords { /// or other expansions), and if it does happen then skipping a span or function is /// better than an ICE or `llvm-cov` failure that the user might have no way to avoid. pub(crate) fn make_coords(source_map: &SourceMap, file: &SourceFile, span: Span) -> Option { - if span.is_empty() { - debug_assert!(false, "can't make coords from empty span: {span:?}"); - return None; - } + let span = ensure_non_empty_span(source_map, span)?; let lo = span.lo(); let hi = span.hi(); @@ -73,6 +70,29 @@ pub(crate) fn make_coords(source_map: &SourceMap, file: &SourceFile, span: Span) }) } +fn ensure_non_empty_span(source_map: &SourceMap, span: Span) -> Option { + if !span.is_empty() { + return Some(span); + } + + // The span is empty, so try to enlarge it to cover an adjacent '{' or '}'. + source_map + .span_to_source(span, |src, start, end| try { + // Adjusting span endpoints by `BytePos(1)` is normally a bug, + // but in this case we have specifically checked that the character + // we're skipping over is one of two specific ASCII characters, so + // adjusting by exactly 1 byte is correct. + if src.as_bytes().get(end).copied() == Some(b'{') { + Some(span.with_hi(span.hi() + BytePos(1))) + } else if start > 0 && src.as_bytes()[start - 1] == b'}' { + Some(span.with_lo(span.lo() - BytePos(1))) + } else { + None + } + }) + .ok()? +} + /// If `llvm-cov` sees a source region that is improperly ordered (end < start), /// it will immediately exit with a fatal error. To prevent that from happening, /// discard regions that are improperly ordered, or might be interpreted in a diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 20e081d33600e..068d96c860f57 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -776,8 +776,7 @@ fn test_unstable_options_tracking_hash() { CoverageOptions { level: CoverageLevel::Mcdc, no_mir_spans: true, - discard_all_spans_in_codegen: true, - inject_unused_local_file: true, + discard_all_spans_in_codegen: true } ); tracked!(crate_attr, vec!["abc".to_string()]); diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index ddeae093df5b7..ec76076020eb7 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -1,8 +1,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_middle::mir; use rustc_middle::ty::TyCtxt; -use rustc_span::source_map::SourceMap; -use rustc_span::{BytePos, DesugaringKind, ExpnKind, MacroKind, Span}; +use rustc_span::{DesugaringKind, ExpnKind, MacroKind, Span}; use tracing::instrument; use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph}; @@ -84,18 +83,8 @@ pub(super) fn extract_refined_covspans<'tcx>( // Discard any span that overlaps with a hole. discard_spans_overlapping_holes(&mut covspans, &holes); - // Discard spans that overlap in unwanted ways. + // Perform more refinement steps after holes have been dealt with. let mut covspans = remove_unwanted_overlapping_spans(covspans); - - // For all empty spans, either enlarge them to be non-empty, or discard them. - let source_map = tcx.sess.source_map(); - covspans.retain_mut(|covspan| { - let Some(span) = ensure_non_empty_span(source_map, covspan.span) else { return false }; - covspan.span = span; - true - }); - - // Merge covspans that can be merged. covspans.dedup_by(|b, a| a.merge_if_eligible(b)); code_mappings.extend(covspans.into_iter().map(|Covspan { span, bcb }| { @@ -241,26 +230,3 @@ fn compare_spans(a: Span, b: Span) -> std::cmp::Ordering { // - Both have the same start and span A extends further right .then_with(|| Ord::cmp(&a.hi(), &b.hi()).reverse()) } - -fn ensure_non_empty_span(source_map: &SourceMap, span: Span) -> Option { - if !span.is_empty() { - return Some(span); - } - - // The span is empty, so try to enlarge it to cover an adjacent '{' or '}'. - source_map - .span_to_source(span, |src, start, end| try { - // Adjusting span endpoints by `BytePos(1)` is normally a bug, - // but in this case we have specifically checked that the character - // we're skipping over is one of two specific ASCII characters, so - // adjusting by exactly 1 byte is correct. - if src.as_bytes().get(end).copied() == Some(b'{') { - Some(span.with_hi(span.hi() + BytePos(1))) - } else if start > 0 && src.as_bytes()[start - 1] == b'}' { - Some(span.with_lo(span.lo() - BytePos(1))) - } else { - None - } - }) - .ok()? -} diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 144aeb5c369cc..60e1b465ba96d 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -195,11 +195,6 @@ pub struct CoverageOptions { /// regression tests for #133606, because we don't have an easy way to /// reproduce it from actual source code. pub discard_all_spans_in_codegen: bool, - - /// `-Zcoverage-options=inject-unused-local-file`: During codegen, add an - /// extra dummy entry to each function's local file table, to exercise the - /// code that checks for local file IDs with no mapping regions. - pub inject_unused_local_file: bool, } /// Controls whether branch coverage or MC/DC coverage is enabled. diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 3d9fdcbc7b14c..5b4068740a159 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1413,7 +1413,6 @@ pub mod parse { "mcdc" => slot.level = CoverageLevel::Mcdc, "no-mir-spans" => slot.no_mir_spans = true, "discard-all-spans-in-codegen" => slot.discard_all_spans_in_codegen = true, - "inject-unused-local-file" => slot.inject_unused_local_file = true, _ => return false, } } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 34ac37d63787d..010ae42c2802d 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -371,11 +371,6 @@ impl Session { self.opts.unstable_opts.coverage_options.discard_all_spans_in_codegen } - /// True if testing flag `-Zcoverage-options=inject-unused-local-file` was passed. - pub fn coverage_inject_unused_local_file(&self) -> bool { - self.opts.unstable_opts.coverage_options.inject_unused_local_file - } - pub fn is_sanitizer_cfi_enabled(&self) -> bool { self.opts.unstable_opts.sanitizer.contains(SanitizerSet::CFI) } diff --git a/tests/coverage/async_closure.cov-map b/tests/coverage/async_closure.cov-map index 53128dd7a48b0..9f8dc8d6cbbae 100644 --- a/tests/coverage/async_closure.cov-map +++ b/tests/coverage/async_closure.cov-map @@ -37,29 +37,32 @@ Number of file 0 mappings: 8 Highest counter ID seen: c0 Function name: async_closure::main::{closure#0} -Raw bytes (9): 0x[01, 01, 00, 01, 01, 0b, 22, 00, 24] +Raw bytes (14): 0x[01, 01, 00, 02, 01, 0b, 22, 00, 23, 01, 00, 23, 00, 24] Number of files: 1 - file 0 => $DIR/async_closure.rs Number of expressions: 0 -Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 11, 34) to (start + 0, 36) +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 11, 34) to (start + 0, 35) +- Code(Counter(0)) at (prev + 0, 35) to (start + 0, 36) Highest counter ID seen: c0 Function name: async_closure::main::{closure#0} -Raw bytes (9): 0x[01, 01, 00, 01, 01, 0b, 22, 00, 24] +Raw bytes (14): 0x[01, 01, 00, 02, 01, 0b, 22, 00, 23, 01, 00, 23, 00, 24] Number of files: 1 - file 0 => $DIR/async_closure.rs Number of expressions: 0 -Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 11, 34) to (start + 0, 36) +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 11, 34) to (start + 0, 35) +- Code(Counter(0)) at (prev + 0, 35) to (start + 0, 36) Highest counter ID seen: c0 Function name: async_closure::main::{closure#0}::{closure#0}:: -Raw bytes (9): 0x[01, 01, 00, 01, 01, 0b, 22, 00, 24] +Raw bytes (14): 0x[01, 01, 00, 02, 01, 0b, 22, 00, 23, 01, 00, 23, 00, 24] Number of files: 1 - file 0 => $DIR/async_closure.rs Number of expressions: 0 -Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 11, 34) to (start + 0, 36) +Number of file 0 mappings: 2 +- Code(Counter(0)) at (prev + 11, 34) to (start + 0, 35) +- Code(Counter(0)) at (prev + 0, 35) to (start + 0, 36) Highest counter ID seen: c0 diff --git a/tests/coverage/unused-local-file.coverage b/tests/coverage/unused-local-file.coverage deleted file mode 100644 index 8f5a32f6d7080..0000000000000 --- a/tests/coverage/unused-local-file.coverage +++ /dev/null @@ -1,7 +0,0 @@ - LL| |//@ edition: 2021 - LL| | - LL| |// Force this function to be generated in its home crate, so that it ends up - LL| |// with normal coverage metadata. - LL| |#[inline(never)] - LL| 1|pub fn external_function() {} - diff --git a/tests/coverage/unused-local-file.rs b/tests/coverage/unused-local-file.rs deleted file mode 100644 index cf43c62d70305..0000000000000 --- a/tests/coverage/unused-local-file.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! If we give LLVM a local file table for a function, but some of the entries -//! in that table have no associated mapping regions, then an assertion failure -//! will occur in LLVM. We therefore need to detect and skip any function that -//! would trigger that assertion. -//! -//! To test that this case is handled, even before adding code that could allow -//! it to happen organically (for expansion region support), we use a special -//! testing-only flag to force it to occur. - -//@ edition: 2024 -//@ compile-flags: -Zcoverage-options=inject-unused-local-file - -// The `llvm-cov` tool will complain if the test binary ends up having no -// coverage metadata at all. To prevent that, we also link to instrumented -// code in an auxiliary crate that doesn't have the special flag set. - -//@ aux-build: discard_all_helper.rs -extern crate discard_all_helper; - -fn main() { - discard_all_helper::external_function(); -} diff --git a/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff b/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff index fa88211383a04..d465b8bded22f 100644 --- a/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff +++ b/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff @@ -40,7 +40,7 @@ + coverage Code { bcb: bcb5 } => $DIR/branch_match_arms.rs:19:17: 19:18 (#0); + coverage Code { bcb: bcb5 } => $DIR/branch_match_arms.rs:19:23: 19:30 (#0); + coverage Code { bcb: bcb5 } => $DIR/branch_match_arms.rs:19:31: 19:32 (#0); -+ coverage Code { bcb: bcb2 } => $DIR/branch_match_arms.rs:21:1: 21:2 (#0); ++ coverage Code { bcb: bcb2 } => $DIR/branch_match_arms.rs:21:2: 21:2 (#0); + bb0: { + Coverage::VirtualCounter(bcb0); diff --git a/tests/mir-opt/coverage/instrument_coverage.bar.InstrumentCoverage.diff b/tests/mir-opt/coverage/instrument_coverage.bar.InstrumentCoverage.diff index 9b6d2b22087b6..cf6d85abd80ef 100644 --- a/tests/mir-opt/coverage/instrument_coverage.bar.InstrumentCoverage.diff +++ b/tests/mir-opt/coverage/instrument_coverage.bar.InstrumentCoverage.diff @@ -6,7 +6,7 @@ + coverage Code { bcb: bcb0 } => $DIR/instrument_coverage.rs:27:1: 27:17 (#0); + coverage Code { bcb: bcb0 } => $DIR/instrument_coverage.rs:28:5: 28:9 (#0); -+ coverage Code { bcb: bcb0 } => $DIR/instrument_coverage.rs:29:1: 29:2 (#0); ++ coverage Code { bcb: bcb0 } => $DIR/instrument_coverage.rs:29:2: 29:2 (#0); + bb0: { + Coverage::VirtualCounter(bcb0); diff --git a/tests/mir-opt/coverage/instrument_coverage.main.InstrumentCoverage.diff b/tests/mir-opt/coverage/instrument_coverage.main.InstrumentCoverage.diff index b2bb2375aee60..980c5e202ffd8 100644 --- a/tests/mir-opt/coverage/instrument_coverage.main.InstrumentCoverage.diff +++ b/tests/mir-opt/coverage/instrument_coverage.main.InstrumentCoverage.diff @@ -10,8 +10,8 @@ + coverage Code { bcb: bcb0 } => $DIR/instrument_coverage.rs:13:1: 13:10 (#0); + coverage Code { bcb: bcb1 } => $DIR/instrument_coverage.rs:15:12: 15:15 (#0); + coverage Code { bcb: bcb2 } => $DIR/instrument_coverage.rs:16:13: 16:18 (#0); -+ coverage Code { bcb: bcb3 } => $DIR/instrument_coverage.rs:17:9: 17:10 (#0); -+ coverage Code { bcb: bcb2 } => $DIR/instrument_coverage.rs:19:1: 19:2 (#0); ++ coverage Code { bcb: bcb3 } => $DIR/instrument_coverage.rs:17:10: 17:10 (#0); ++ coverage Code { bcb: bcb2 } => $DIR/instrument_coverage.rs:19:2: 19:2 (#0); + bb0: { + Coverage::VirtualCounter(bcb0); diff --git a/tests/mir-opt/coverage/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff b/tests/mir-opt/coverage/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff index 2eb78c08ee800..b707cd41788ac 100644 --- a/tests/mir-opt/coverage/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff +++ b/tests/mir-opt/coverage/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff @@ -10,8 +10,8 @@ coverage Code { bcb: bcb0 } => $DIR/instrument_coverage_cleanup.rs:13:1: 13:10 (#0); coverage Code { bcb: bcb0 } => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0); coverage Code { bcb: bcb3 } => $DIR/instrument_coverage_cleanup.rs:14:37: 14:39 (#0); - coverage Code { bcb: bcb1 } => $DIR/instrument_coverage_cleanup.rs:14:38: 14:39 (#0); - coverage Code { bcb: bcb2 } => $DIR/instrument_coverage_cleanup.rs:15:1: 15:2 (#0); + coverage Code { bcb: bcb1 } => $DIR/instrument_coverage_cleanup.rs:14:39: 14:39 (#0); + coverage Code { bcb: bcb2 } => $DIR/instrument_coverage_cleanup.rs:15:2: 15:2 (#0); coverage Branch { true_bcb: bcb3, false_bcb: bcb1 } => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0); bb0: { diff --git a/tests/mir-opt/coverage/instrument_coverage_cleanup.main.InstrumentCoverage.diff b/tests/mir-opt/coverage/instrument_coverage_cleanup.main.InstrumentCoverage.diff index 0c1bc24b6dc19..239b845c2311e 100644 --- a/tests/mir-opt/coverage/instrument_coverage_cleanup.main.InstrumentCoverage.diff +++ b/tests/mir-opt/coverage/instrument_coverage_cleanup.main.InstrumentCoverage.diff @@ -10,8 +10,8 @@ + coverage Code { bcb: bcb0 } => $DIR/instrument_coverage_cleanup.rs:13:1: 13:10 (#0); + coverage Code { bcb: bcb0 } => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0); + coverage Code { bcb: bcb3 } => $DIR/instrument_coverage_cleanup.rs:14:37: 14:39 (#0); -+ coverage Code { bcb: bcb1 } => $DIR/instrument_coverage_cleanup.rs:14:38: 14:39 (#0); -+ coverage Code { bcb: bcb2 } => $DIR/instrument_coverage_cleanup.rs:15:1: 15:2 (#0); ++ coverage Code { bcb: bcb1 } => $DIR/instrument_coverage_cleanup.rs:14:39: 14:39 (#0); ++ coverage Code { bcb: bcb2 } => $DIR/instrument_coverage_cleanup.rs:15:2: 15:2 (#0); + coverage Branch { true_bcb: bcb3, false_bcb: bcb1 } => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0); + bb0: { From a963e6fc386cb91d33ff4ca020ceaf7bf590ee27 Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Tue, 27 May 2025 10:52:09 -0400 Subject: [PATCH 10/10] tests: mark option-niche-eq as fixed on LLVM 21 Some combination of recent Rust changes (between 3d86494a0d01 and aa57e46e24a4 from what I can tell) and changes in LLVM 21 (not recently, as best I can tell) have caused this test to start showing the behavior we want, so it's time to move this test to a proper place and mark it as fixed on LLVM 21. --- tests/codegen/option-niche-eq.rs | 11 +++++++++++ .../option-niche-unfixed/option-bool-eq.rs | 15 --------------- 2 files changed, 11 insertions(+), 15 deletions(-) delete mode 100644 tests/codegen/option-niche-unfixed/option-bool-eq.rs diff --git a/tests/codegen/option-niche-eq.rs b/tests/codegen/option-niche-eq.rs index a39e2870a0f4f..3900cb79aa2ab 100644 --- a/tests/codegen/option-niche-eq.rs +++ b/tests/codegen/option-niche-eq.rs @@ -1,5 +1,7 @@ +//@ revisions: REGULAR LLVM21 //@ min-llvm-version: 20 //@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled +//@ [LLVM21] min-llvm-version: 21 #![crate_type = "lib"] extern crate core; @@ -74,3 +76,12 @@ pub fn niche_eq(l: Option, r: Option) -> bool { // CHECK-NEXT: ret i1 l == r } + +// LLVM21-LABEL: @bool_eq +#[no_mangle] +pub fn bool_eq(l: Option, r: Option) -> bool { + // LLVM21: start: + // LLVM21-NEXT: icmp eq i8 + // LLVM21-NEXT: ret i1 + l == r +} diff --git a/tests/codegen/option-niche-unfixed/option-bool-eq.rs b/tests/codegen/option-niche-unfixed/option-bool-eq.rs deleted file mode 100644 index fa0e7836afb9e..0000000000000 --- a/tests/codegen/option-niche-unfixed/option-bool-eq.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ should-fail -//@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled -//! FIXME(#49892) -//! Tests that LLVM does not fully optimize comparisons of `Option`. -//! If this starts passing, it can be moved to `tests/codegen/option-niche-eq.rs` -#![crate_type = "lib"] - -// CHECK-LABEL: @bool_eq -#[no_mangle] -pub fn bool_eq(l: Option, r: Option) -> bool { - // CHECK: start: - // CHECK-NEXT: icmp eq i8 - // CHECK-NEXT: ret i1 - l == r -}