diff options
| author | llogiq <bogusandre@gmail.com> | 2025-05-16 15:05:36 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-16 15:05:36 +0000 |
| commit | 94cfebb397e509d283f092504c34fa26638b3e75 (patch) | |
| tree | da5f7880a0304580ac4b4c199f4132fa85379e8a /clippy_utils | |
| parent | 5cb7e4039eeb355771b73164d4bf8c5ff08f6c11 (diff) | |
| parent | 318ba60cfb59ba3165d1a03bd3ab3acb3406cb14 (diff) | |
| download | rust-94cfebb397e509d283f092504c34fa26638b3e75.tar.gz rust-94cfebb397e509d283f092504c34fa26638b3e75.zip | |
Rewrite `non_copy_const` (#13207)
fixes #12979 fixes #12951 fixes #13233 Tests still need to be finished and the docs still need to be updated, but this should otherwise ready. changelog: Lint `declare_interior_mutable_const` and `borrow_interior_mutable_const` more precisely
Diffstat (limited to 'clippy_utils')
| -rw-r--r-- | clippy_utils/src/ty/mod.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clippy_utils/src/ty/mod.rs b/clippy_utils/src/ty/mod.rs index 26d41cfb497..c50ad17bfad 100644 --- a/clippy_utils/src/ty/mod.rs +++ b/clippy_utils/src/ty/mod.rs @@ -1361,3 +1361,14 @@ pub fn is_slice_like<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { || ty.is_array() || matches!(ty.kind(), ty::Adt(adt_def, _) if cx.tcx.is_diagnostic_item(sym::Vec, adt_def.did())) } + +/// Gets the index of a field by name. +pub fn get_field_idx_by_name(ty: Ty<'_>, name: Symbol) -> Option<usize> { + match *ty.kind() { + ty::Adt(def, _) if def.is_union() || def.is_struct() => { + def.non_enum_variant().fields.iter().position(|f| f.name == name) + }, + ty::Tuple(_) => name.as_str().parse::<usize>().ok(), + _ => None, + } +} |
