diff options
| author | The Miri Cronjob Bot <miri@cron.bot> | 2025-01-05 05:05:33 +0000 |
|---|---|---|
| committer | The Miri Cronjob Bot <miri@cron.bot> | 2025-01-05 05:05:33 +0000 |
| commit | 74a13d185a583e9a77a7c418c151590e88157908 (patch) | |
| tree | 9c5b7a7602945da7ed9a3eb5d07d95869424c516 /src/tools | |
| parent | e6159b4afbb550b9cacdbc056baec2e5e23c8fda (diff) | |
| parent | 6243c0f818ee05b81a8e465bc3d44ae040ea14bd (diff) | |
| download | rust-74a13d185a583e9a77a7c418c151590e88157908.tar.gz rust-74a13d185a583e9a77a7c418c151590e88157908.zip | |
Merge from rustc
Diffstat (limited to 'src/tools')
33 files changed, 364 insertions, 147 deletions
diff --git a/src/tools/cargo b/src/tools/cargo -Subproject d73d2caf9e41a39daf2a8d6ce60ec80bf354d2a +Subproject fd784878cfa843e3e29a6654ecf564c62fae673 diff --git a/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs b/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs index cf33e1444e4..74153990266 100644 --- a/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs +++ b/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs @@ -464,7 +464,7 @@ fn convert_module_item_kind(value: &ItemKind<'_>) -> SourceItemOrderingModuleIte ItemKind::Use(..) => Use, ItemKind::Static(..) => Static, ItemKind::Const(..) => Const, - ItemKind::Fn(..) => Fn, + ItemKind::Fn{ .. } => Fn, ItemKind::Macro(..) => Macro, ItemKind::Mod(..) => Mod, ItemKind::ForeignMod { .. } => ForeignMod, diff --git a/src/tools/clippy/clippy_lints/src/attrs/utils.rs b/src/tools/clippy/clippy_lints/src/attrs/utils.rs index 96de0642904..152e6ec70a1 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/utils.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/utils.rs @@ -21,7 +21,7 @@ pub(super) fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool { } pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool { - if let ItemKind::Fn(_, _, eid) = item.kind { + if let ItemKind::Fn { body: eid, .. } = item.kind { is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value) } else { true diff --git a/src/tools/clippy/clippy_lints/src/doc/mod.rs b/src/tools/clippy/clippy_lints/src/doc/mod.rs index b2135fe18bd..c835b81679b 100644 --- a/src/tools/clippy/clippy_lints/src/doc/mod.rs +++ b/src/tools/clippy/clippy_lints/src/doc/mod.rs @@ -639,7 +639,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation { self.check_private_items, ); match item.kind { - ItemKind::Fn(sig, _, body_id) => { + ItemKind::Fn { sig, body: body_id, .. } => { if !(is_entrypoint_fn(cx, item.owner_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) { diff --git a/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs b/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs index 0f9ff550853..2327da0ccff 100644 --- a/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs +++ b/src/tools/clippy/clippy_lints/src/doc/too_long_first_doc_paragraph.rs @@ -25,7 +25,7 @@ pub(super) fn check( // page. So associated items or impl blocks are not part of this list. ItemKind::Static(..) | ItemKind::Const(..) - | ItemKind::Fn(..) + | ItemKind::Fn{ .. } | ItemKind::Macro(..) | ItemKind::Mod(..) | ItemKind::TyAlias(..) diff --git a/src/tools/clippy/clippy_lints/src/exit.rs b/src/tools/clippy/clippy_lints/src/exit.rs index 3c235fab009..e6ddcd107d9 100644 --- a/src/tools/clippy/clippy_lints/src/exit.rs +++ b/src/tools/clippy/clippy_lints/src/exit.rs @@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit { && let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id() && cx.tcx.is_diagnostic_item(sym::process_exit, def_id) && let parent = cx.tcx.hir().get_parent_item(e.hir_id) - && let OwnerNode::Item(Item{kind: ItemKind::Fn(..), ..}) = cx.tcx.hir_owner_node(parent) + && let OwnerNode::Item(Item{kind: ItemKind::Fn{ .. }, ..}) = cx.tcx.hir_owner_node(parent) // If the next item up is a function we check if it is an entry point // and only then emit a linter warning && !is_entrypoint_fn(cx, parent.to_def_id()) diff --git a/src/tools/clippy/clippy_lints/src/extra_unused_type_parameters.rs b/src/tools/clippy/clippy_lints/src/extra_unused_type_parameters.rs index ae4b6680065..d0159ab89e1 100644 --- a/src/tools/clippy/clippy_lints/src/extra_unused_type_parameters.rs +++ b/src/tools/clippy/clippy_lints/src/extra_unused_type_parameters.rs @@ -253,7 +253,11 @@ fn is_empty_body(cx: &LateContext<'_>, body: BodyId) -> bool { impl<'tcx> LateLintPass<'tcx> for ExtraUnusedTypeParameters { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { - if let ItemKind::Fn(_, generics, body_id) = item.kind + if let ItemKind::Fn { + generics, + body: body_id, + .. + } = item.kind && !generics.params.is_empty() && !is_empty_body(cx, body_id) && (!self.avoid_breaking_exported_api || !cx.effective_visibilities.is_exported(item.owner_id.def_id)) diff --git a/src/tools/clippy/clippy_lints/src/functions/must_use.rs b/src/tools/clippy/clippy_lints/src/functions/must_use.rs index afdb5d5306a..1a01f5f885c 100644 --- a/src/tools/clippy/clippy_lints/src/functions/must_use.rs +++ b/src/tools/clippy/clippy_lints/src/functions/must_use.rs @@ -24,7 +24,12 @@ use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT}; pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { let attrs = cx.tcx.hir().attrs(item.hir_id()); let attr = cx.tcx.get_attr(item.owner_id, sym::must_use); - if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind { + if let hir::ItemKind::Fn { + ref sig, + body: ref body_id, + .. + } = item.kind + { let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if let Some(attr) = attr { diff --git a/src/tools/clippy/clippy_lints/src/functions/result.rs b/src/tools/clippy/clippy_lints/src/functions/result.rs index 674d78eaae7..9c396986f62 100644 --- a/src/tools/clippy/clippy_lints/src/functions/result.rs +++ b/src/tools/clippy/clippy_lints/src/functions/result.rs @@ -36,7 +36,7 @@ fn result_err_ty<'tcx>( } pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64, msrv: &Msrv) { - if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind + if let hir::ItemKind::Fn { ref sig, .. } = item.kind && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.owner_id.def_id, item.span) { if cx.effective_visibilities.is_exported(item.owner_id.def_id) { diff --git a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs index c370f206c8f..ad2da3c7fcd 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs @@ -149,7 +149,12 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { ); } }, - ItemKind::Fn(ref sig, generics, body_id) => { + ItemKind::Fn { + ref sig, + generics, + body: body_id, + .. + } => { let body = cx.tcx.hir().body(body_id); for ty in sig.decl.inputs { diff --git a/src/tools/clippy/clippy_lints/src/lifetimes.rs b/src/tools/clippy/clippy_lints/src/lifetimes.rs index 8b2eee34a97..239822f4085 100644 --- a/src/tools/clippy/clippy_lints/src/lifetimes.rs +++ b/src/tools/clippy/clippy_lints/src/lifetimes.rs @@ -95,7 +95,13 @@ declare_lint_pass!(Lifetimes => [NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES]); impl<'tcx> LateLintPass<'tcx> for Lifetimes { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Fn(ref sig, generics, id) = item.kind { + if let ItemKind::Fn { + ref sig, + generics, + body: id, + .. + } = item.kind + { check_fn_inner(cx, sig, Some(id), None, generics, item.span, true); } else if let ItemKind::Impl(impl_) = item.kind { if !item.span.from_expansion() { diff --git a/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs b/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs index 9f543b79bac..f88605fbea0 100644 --- a/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/infinite_loop.rs @@ -75,7 +75,11 @@ fn get_parent_fn_ret_ty<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option .. }) => (), Node::Item(hir::Item { - kind: hir::ItemKind::Fn(FnSig { decl, .. }, _, _), + kind: + hir::ItemKind::Fn { + sig: FnSig { decl, .. }, + .. + }, .. }) | Node::TraitItem(hir::TraitItem { diff --git a/src/tools/clippy/clippy_lints/src/matches/needless_match.rs b/src/tools/clippy/clippy_lints/src/matches/needless_match.rs index 73822314b4b..63bea586caf 100644 --- a/src/tools/clippy/clippy_lints/src/matches/needless_match.rs +++ b/src/tools/clippy/clippy_lints/src/matches/needless_match.rs @@ -133,7 +133,7 @@ fn expr_ty_matches_p_ty(cx: &LateContext<'_>, expr: &Expr<'_>, p_expr: &Expr<'_> }, // compare match_expr ty with RetTy in `fn foo() -> RetTy` Node::Item(item) => { - if let ItemKind::Fn(..) = item.kind { + if let ItemKind::Fn{ .. } = item.kind { let output = cx .tcx .fn_sig(item.owner_id) 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 d19064fd57e..42107581ab4 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 @@ -496,7 +496,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< Node::Stmt(_) => return true, Node::Block(..) => continue, Node::Item(item) => { - if let ItemKind::Fn(_, _, body_id) = &item.kind + if let ItemKind::Fn { body: body_id, .. } = &item.kind && let output_ty = return_ty(cx, item.owner_id) && rustc_hir_typeck::can_coerce(cx.tcx, cx.param_env, item.owner_id.def_id, ty, output_ty) { diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs index b6f49dcc163..1141728640d 100644 --- a/src/tools/clippy/clippy_lints/src/missing_doc.rs +++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs @@ -192,7 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) { match it.kind { - hir::ItemKind::Fn(..) => { + hir::ItemKind::Fn{ .. } => { // ignore main() if it.ident.name == sym::main { let at_root = cx.tcx.local_parent(it.owner_id.def_id) == CRATE_DEF_ID; diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index 11ff779d531..b18f18d89e5 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { return; } match it.kind { - hir::ItemKind::Fn(..) => { + hir::ItemKind::Fn{ .. } => { let desc = "a function"; let attrs = cx.tcx.hir().attrs(it.hir_id()); check_missing_inline_attrs(cx, attrs, it.span, desc); diff --git a/src/tools/clippy/clippy_lints/src/mut_key.rs b/src/tools/clippy/clippy_lints/src/mut_key.rs index 745f81d1c51..7abc5870d00 100644 --- a/src/tools/clippy/clippy_lints/src/mut_key.rs +++ b/src/tools/clippy/clippy_lints/src/mut_key.rs @@ -76,7 +76,7 @@ impl_lint_pass!(MutableKeyType<'_> => [ MUTABLE_KEY_TYPE ]); impl<'tcx> LateLintPass<'tcx> for MutableKeyType<'tcx> { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) { - if let hir::ItemKind::Fn(ref sig, ..) = item.kind { + if let hir::ItemKind::Fn { ref sig, .. } = item.kind { self.check_sig(cx, item.owner_id.def_id, sig.decl); } } diff --git a/src/tools/clippy/clippy_lints/src/no_effect.rs b/src/tools/clippy/clippy_lints/src/no_effect.rs index 7feff7e4d3f..92644456f63 100644 --- a/src/tools/clippy/clippy_lints/src/no_effect.rs +++ b/src/tools/clippy/clippy_lints/src/no_effect.rs @@ -144,7 +144,7 @@ impl NoEffect { |diag| { for parent in cx.tcx.hir().parent_iter(stmt.hir_id) { if let Node::Item(item) = parent.1 - && let ItemKind::Fn(..) = item.kind + && let ItemKind::Fn{ .. } = item.kind && let Node::Block(block) = cx.tcx.parent_hir_node(stmt.hir_id) && let [.., final_stmt] = block.stmts && final_stmt.hir_id == stmt.hir_id diff --git a/src/tools/clippy/clippy_lints/src/no_mangle_with_rust_abi.rs b/src/tools/clippy/clippy_lints/src/no_mangle_with_rust_abi.rs index 64587e08ddc..9ee4e493277 100644 --- a/src/tools/clippy/clippy_lints/src/no_mangle_with_rust_abi.rs +++ b/src/tools/clippy/clippy_lints/src/no_mangle_with_rust_abi.rs @@ -37,7 +37,7 @@ declare_lint_pass!(NoMangleWithRustAbi => [NO_MANGLE_WITH_RUST_ABI]); impl<'tcx> LateLintPass<'tcx> for NoMangleWithRustAbi { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { - if let ItemKind::Fn(fn_sig, _, _) = &item.kind { + if let ItemKind::Fn { sig: fn_sig, .. } = &item.kind { let attrs = cx.tcx.hir().attrs(item.hir_id()); let mut app = Applicability::MaybeIncorrect; let fn_snippet = snippet_with_applicability(cx, fn_sig.span.with_hi(item.ident.span.lo()), "..", &mut app); diff --git a/src/tools/clippy/clippy_lints/src/ptr.rs b/src/tools/clippy/clippy_lints/src/ptr.rs index b674b01406d..a86926d8416 100644 --- a/src/tools/clippy/clippy_lints/src/ptr.rs +++ b/src/tools/clippy/clippy_lints/src/ptr.rs @@ -189,7 +189,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { let mut parents = hir.parent_iter(body.value.hir_id); let (item_id, sig, is_trait_item) = match parents.next() { Some((_, Node::Item(i))) => { - if let ItemKind::Fn(sig, ..) = &i.kind { + if let ItemKind::Fn { sig, .. } = &i.kind { (i.owner_id, sig, false) } else { return; diff --git a/src/tools/clippy/clippy_lints/src/returns.rs b/src/tools/clippy/clippy_lints/src/returns.rs index aeff31d02d2..dfaee8cc305 100644 --- a/src/tools/clippy/clippy_lints/src/returns.rs +++ b/src/tools/clippy/clippy_lints/src/returns.rs @@ -204,7 +204,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { // Ensure this is not the final stmt, otherwise removing it would cause a compile error && let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id)) - && let ItemKind::Fn(_, _, body) = item.kind + && let ItemKind::Fn { body, .. } = item.kind && let block = cx.tcx.hir().body(body).value && let ExprKind::Block(block, _) = block.kind && !is_inside_let_else(cx.tcx, expr) diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_box_returns.rs b/src/tools/clippy/clippy_lints/src/unnecessary_box_returns.rs index 34df1d5560a..4158050f969 100644 --- a/src/tools/clippy/clippy_lints/src/unnecessary_box_returns.rs +++ b/src/tools/clippy/clippy_lints/src/unnecessary_box_returns.rs @@ -130,9 +130,9 @@ impl LateLintPass<'_> for UnnecessaryBoxReturns { } fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - let ItemKind::Fn(signature, ..) = &item.kind else { + let ItemKind::Fn { sig, .. } = &item.kind else { return; }; - self.check_fn_item(cx, signature.decl, item.owner_id.def_id, item.ident.name); + self.check_fn_item(cx, sig.decl, item.owner_id.def_id, item.ident.name); } } diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index b71b53ea3bb..68e7f807bf5 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -245,7 +245,7 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) { ItemKind::ExternCrate(_) => (Pat::Str("extern"), Pat::Str(";")), ItemKind::Static(..) => (Pat::Str("static"), Pat::Str(";")), ItemKind::Const(..) => (Pat::Str("const"), Pat::Str(";")), - ItemKind::Fn(sig, ..) => (fn_header_search_pat(sig.header), Pat::Str("")), + ItemKind::Fn { sig, .. } => (fn_header_search_pat(sig.header), Pat::Str("")), ItemKind::ForeignMod { .. } => (Pat::Str("extern"), Pat::Str("}")), ItemKind::TyAlias(..) => (Pat::Str("type"), Pat::Str(";")), ItemKind::Enum(..) => (Pat::Str("enum"), Pat::Str("}")), diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 77c597f8534..30e7471dd92 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1397,7 +1397,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio enclosing_node.and_then(|node| match node { Node::Block(block) => Some(block), Node::Item(&Item { - kind: ItemKind::Fn(_, _, eid), + kind: ItemKind::Fn { body: eid, .. }, .. }) | Node::ImplItem(&ImplItem { @@ -2565,7 +2565,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: HirId) -> bool { // function scope .any(|(_id, node)| { if let Node::Item(item) = node { - if let ItemKind::Fn(_, _, _) = item.kind { + if let ItemKind::Fn { .. } = item.kind { // Note that we have sorted the item names in the visitor, // so the binary_search gets the same as `contains`, but faster. return names.binary_search(&item.ident.name).is_ok(); @@ -2722,7 +2722,7 @@ impl<'tcx> ExprUseCtxt<'tcx> { }) => ExprUseNode::ConstStatic(owner_id), Node::Item(&Item { - kind: ItemKind::Fn(..), + kind: ItemKind::Fn { .. }, owner_id, .. }) diff --git a/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr index 2e3386628b4..6a6c6168a1f 100644 --- a/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr +++ b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr @@ -1,12 +1,3 @@ -error: use of a disallowed macro `std::vec` - --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:16:5 - | -LL | vec![1, 2, 3]; - | ^^^^^^^^^^^^^ - | - = note: `-D clippy::disallowed-macros` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::disallowed_macros)]` - error: use of a disallowed macro `serde::Serialize` --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:18:14 | @@ -14,6 +5,8 @@ LL | #[derive(Serialize)] | ^^^^^^^^^ | = note: no serializing + = note: `-D clippy::disallowed-macros` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::disallowed_macros)]` error: use of a disallowed macro `macros::attr` --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:31:1 @@ -47,6 +40,12 @@ error: use of a disallowed macro `std::cfg` LL | cfg!(unix); | ^^^^^^^^^^ +error: use of a disallowed macro `std::vec` + --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:16:5 + | +LL | vec![1, 2, 3]; + | ^^^^^^^^^^^^^ + error: use of a disallowed macro `macros::expr` --> tests/ui-toml/disallowed_macros/disallowed_macros.rs:21:13 | diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 48149e3b897..8c96554738e 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -934,6 +934,9 @@ fn iter_header( impl Config { fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec<String>) { + const FORBIDDEN_REVISION_NAMES: [&str; 9] = + ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"]; + if let Some(raw) = self.parse_name_value_directive(line, "revisions") { if self.mode == Mode::RunMake { panic!("`run-make` tests do not support revisions: {}", testfile.display()); @@ -948,6 +951,15 @@ impl Config { raw, testfile.display() ); + } else if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt) + && FORBIDDEN_REVISION_NAMES.contains(&revision.as_str()) + { + panic!( + "revision name `{revision}` is not permitted in a test suite that uses `FileCheck` annotations\n\ + as it is confusing when used as custom `FileCheck` prefix: `{revision}` in line `{}`: {}", + raw, + testfile.display() + ); } existing.push(revision); } diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 618b66dfd4c..25bb1a5f428 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -554,6 +554,59 @@ fn test_duplicate_revisions() { } #[test] +#[should_panic( + expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations" +)] +fn test_assembly_mode_forbidden_revisions() { + let config = cfg().mode("assembly").build(); + parse_rs(&config, "//@ revisions: CHECK"); +} + +#[test] +#[should_panic( + expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations" +)] +fn test_codegen_mode_forbidden_revisions() { + let config = cfg().mode("codegen").build(); + parse_rs(&config, "//@ revisions: CHECK"); +} + +#[test] +#[should_panic( + expected = "revision name `CHECK` is not permitted in a test suite that uses `FileCheck` annotations" +)] +fn test_miropt_mode_forbidden_revisions() { + let config = cfg().mode("mir-opt").build(); + parse_rs(&config, "//@ revisions: CHECK"); +} + +#[test] +fn test_forbidden_revisions_allowed_in_non_filecheck_dir() { + let revisions = ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"]; + let modes = [ + "pretty", + "debuginfo", + "rustdoc", + "rustdoc-json", + "codegen-units", + "incremental", + "ui", + "js-doc-test", + "coverage-map", + "coverage-run", + "crashes", + ]; + + for rev in revisions { + let content = format!("//@ revisions: {rev}"); + for mode in modes { + let config = cfg().mode(mode).build(); + parse_rs(&config, &content); + } + } +} + +#[test] fn ignore_arch() { let archs = [ ("x86_64-unknown-linux-gnu", "x86_64"), diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 7084c407a64..9e8443cd13c 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -506,8 +506,9 @@ impl<'test> TestCx<'test> { // Generate `cfg(FALSE, REV1, ..., REVN)` (for all possible revisions) // // For compatibility reason we consider the `FALSE` cfg to be expected - // since it is extensively used in the testsuite. - check_cfg.push_str("cfg(FALSE"); + // since it is extensively used in the testsuite, as well as the `test` + // cfg since we have tests that uses it. + check_cfg.push_str("cfg(test,FALSE"); for revision in &self.props.revisions { check_cfg.push(','); check_cfg.push_str(&normalize_revision(revision)); diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index 8832016d0fa..9055aa30271 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -242,7 +242,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls { let is_reachable_non_generic = matches!( tcx.hir_node_by_def_id(local_def_id), Node::Item(&hir::Item { - kind: hir::ItemKind::Static(..) | hir::ItemKind::Fn(..), + kind: hir::ItemKind::Static(..) | hir::ItemKind::Fn{ .. }, .. }) | Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs deleted file mode 100644 index e84a3cf633f..00000000000 --- a/src/tools/run-make-support/src/assertion_helpers.rs +++ /dev/null @@ -1,107 +0,0 @@ -//! Collection of assertions and assertion-related helpers. - -use std::panic; -use std::path::Path; - -use crate::{fs, regex}; - -fn print<'a, 'e, A: AsRef<str>, E: AsRef<str>>( - assertion_kind: &str, - haystack: &'a A, - needle: &'e E, -) -> (&'a str, &'e str) { - let haystack = haystack.as_ref(); - let needle = needle.as_ref(); - eprintln!("{assertion_kind}:"); - eprintln!("=== HAYSTACK ==="); - eprintln!("{}", haystack); - eprintln!("=== NEEDLE ==="); - eprintln!("{}", needle); - (haystack, needle) -} - -/// Assert that `actual` is equal to `expected`. -#[track_caller] -pub fn assert_equals<A: AsRef<str>, E: AsRef<str>>(actual: A, expected: E) { - let actual = actual.as_ref(); - let expected = expected.as_ref(); - eprintln!("=== ACTUAL TEXT ==="); - eprintln!("{}", actual); - eprintln!("=== EXPECTED ==="); - eprintln!("{}", expected); - if actual != expected { - panic!("expected text was not found in actual text"); - } -} - -/// Assert that `haystack` contains `needle`. -#[track_caller] -pub fn assert_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) { - let (haystack, needle) = print("assert_contains", &haystack, &needle); - if !haystack.contains(needle) { - panic!("needle was not found in haystack"); - } -} - -/// Assert that `haystack` does not contain `needle`. -#[track_caller] -pub fn assert_not_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) { - let (haystack, needle) = print("assert_not_contains", &haystack, &needle); - if haystack.contains(needle) { - panic!("needle was unexpectedly found in haystack"); - } -} - -/// Assert that `haystack` contains the regex pattern `needle`. -#[track_caller] -pub fn assert_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) { - let (haystack, needle) = print("assert_contains_regex", &haystack, &needle); - let re = regex::Regex::new(needle).unwrap(); - if !re.is_match(haystack) { - panic!("needle was not found in haystack"); - } -} - -/// Assert that `haystack` does not contain the regex pattern `needle`. -#[track_caller] -pub fn assert_not_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) { - let (haystack, needle) = print("assert_not_contains_regex", &haystack, &needle); - let re = regex::Regex::new(needle).unwrap(); - if re.is_match(haystack) { - panic!("needle was unexpectedly found in haystack"); - } -} - -/// Assert that `haystack` contains `needle` a `count` number of times. -#[track_caller] -pub fn assert_count_is<H: AsRef<str>, N: AsRef<str>>(count: usize, haystack: H, needle: N) { - let (haystack, needle) = print("assert_count_is", &haystack, &needle); - if count != haystack.matches(needle).count() { - panic!("needle did not appear {count} times in haystack"); - } -} - -/// Assert that all files in `dir1` exist and have the same content in `dir2` -pub fn assert_dirs_are_equal(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) { - let dir2 = dir2.as_ref(); - fs::read_dir_entries(dir1, |entry_path| { - let entry_name = entry_path.file_name().unwrap(); - if entry_path.is_dir() { - assert_dirs_are_equal(&entry_path, &dir2.join(entry_name)); - } else { - let path2 = dir2.join(entry_name); - let file1 = fs::read(&entry_path); - let file2 = fs::read(&path2); - - // We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display. - // Why not using String? Because there might be minified files or even potentially - // binary ones, so that would display useless output. - assert!( - file1 == file2, - "`{}` and `{}` have different content", - entry_path.display(), - path2.display(), - ); - } - }); -} diff --git a/src/tools/run-make-support/src/assertion_helpers/mod.rs b/src/tools/run-make-support/src/assertion_helpers/mod.rs new file mode 100644 index 00000000000..9b666473b5b --- /dev/null +++ b/src/tools/run-make-support/src/assertion_helpers/mod.rs @@ -0,0 +1,135 @@ +//! Collection of assertions and assertion-related helpers. + +#[cfg(test)] +mod tests; + +use std::panic; +use std::path::Path; + +use crate::{fs, regex}; + +/// Assert that `actual` is equal to `expected`. +#[track_caller] +pub fn assert_equals<A: AsRef<str>, E: AsRef<str>>(actual: A, expected: E) { + let actual = actual.as_ref(); + let expected = expected.as_ref(); + + if actual != expected { + eprintln!("=== ACTUAL TEXT ==="); + eprintln!("{}", actual); + eprintln!("=== EXPECTED ==="); + eprintln!("{}", expected); + panic!("expected text does not match actual text"); + } +} + +struct SearchDetails<'assertion_name, 'haystack, 'needle> { + assertion_name: &'assertion_name str, + haystack: &'haystack str, + needle: &'needle str, +} + +impl<'assertion_name, 'haystack, 'needle> SearchDetails<'assertion_name, 'haystack, 'needle> { + fn dump(&self) { + eprintln!("{}:", self.assertion_name); + eprintln!("=== HAYSTACK ==="); + eprintln!("{}", self.haystack); + eprintln!("=== NEEDLE ==="); + eprintln!("{}", self.needle); + } +} + +/// Assert that `haystack` contains `needle`. +#[track_caller] +pub fn assert_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) { + let haystack = haystack.as_ref(); + let needle = needle.as_ref(); + if !haystack.contains(needle) { + SearchDetails { assertion_name: "assert_contains", haystack, needle }.dump(); + panic!("needle was not found in haystack"); + } +} + +/// Assert that `haystack` does not contain `needle`. +#[track_caller] +pub fn assert_not_contains<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) { + let haystack = haystack.as_ref(); + let needle = needle.as_ref(); + if haystack.contains(needle) { + SearchDetails { assertion_name: "assert_not_contains", haystack, needle }.dump(); + panic!("needle was unexpectedly found in haystack"); + } +} + +/// Assert that `haystack` contains the regex `needle`. +#[track_caller] +pub fn assert_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) { + let haystack = haystack.as_ref(); + let needle = needle.as_ref(); + let re = regex::Regex::new(needle).unwrap(); + if !re.is_match(haystack) { + SearchDetails { assertion_name: "assert_contains_regex", haystack, needle }.dump(); + panic!("regex was not found in haystack"); + } +} + +/// Assert that `haystack` does not contain the regex `needle`. +#[track_caller] +pub fn assert_not_contains_regex<H: AsRef<str>, N: AsRef<str>>(haystack: H, needle: N) { + let haystack = haystack.as_ref(); + let needle = needle.as_ref(); + let re = regex::Regex::new(needle).unwrap(); + if re.is_match(haystack) { + SearchDetails { assertion_name: "assert_not_contains_regex", haystack, needle }.dump(); + panic!("regex was unexpectedly found in haystack"); + } +} + +/// Assert that `haystack` contains regex `needle` an `expected_count` number of times. +#[track_caller] +pub fn assert_count_is<H: AsRef<str>, N: AsRef<str>>( + expected_count: usize, + haystack: H, + needle: N, +) { + let haystack = haystack.as_ref(); + let needle = needle.as_ref(); + + let actual_count = haystack.matches(needle).count(); + if expected_count != actual_count { + let count_fmt = format!( + "assert_count_is (expected_count = {expected_count}, actual_count = {actual_count})" + ); + SearchDetails { assertion_name: &count_fmt, haystack, needle }.dump(); + panic!( + "regex did not appear {expected_count} times in haystack (expected_count = \ + {expected_count}, actual_count = {actual_count})" + ); + } +} + +/// Assert that all files in `dir1` exist and have the same content in `dir2` +// FIXME(#135037): not robust against symlinks, lacks sanity test coverage. +pub fn assert_dirs_are_equal(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) { + let dir2 = dir2.as_ref(); + fs::read_dir_entries(dir1, |entry_path| { + let entry_name = entry_path.file_name().unwrap(); + if entry_path.is_dir() { + assert_dirs_are_equal(&entry_path, &dir2.join(entry_name)); + } else { + let path2 = dir2.join(entry_name); + let file1 = fs::read(&entry_path); + let file2 = fs::read(&path2); + + // We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display. + // Why not using String? Because there might be minified files or even potentially + // binary ones, so that would display useless output. + assert!( + file1 == file2, + "`{}` and `{}` have different content", + entry_path.display(), + path2.display(), + ); + } + }); +} diff --git a/src/tools/run-make-support/src/assertion_helpers/tests.rs b/src/tools/run-make-support/src/assertion_helpers/tests.rs new file mode 100644 index 00000000000..8bf7740d2e6 --- /dev/null +++ b/src/tools/run-make-support/src/assertion_helpers/tests.rs @@ -0,0 +1,100 @@ +//! Basic sanity checks for assertion helpers. +use super::*; + +mod test_assert_equals { + use super::*; + + #[test] + fn assert_equals_same() { + assert_equals("foo", "foo"); + assert_equals("", ""); + } + + #[test] + #[should_panic] + fn assert_equals_different() { + assert_equals("foo", "bar"); + } +} + +mod test_assert_contains { + use super::*; + + #[test] + fn assert_contains_yes() { + assert_contains("", ""); + assert_contains(" ", ""); + assert_contains("a", "a"); + assert_contains("ab", "a"); + } + + #[test] + #[should_panic] + fn assert_contains_no() { + assert_contains("a", "b"); + } +} + +mod test_assert_not_contains { + use super::*; + + #[test] + fn assert_not_contains_yes() { + assert_not_contains("a", "b"); + } + + #[test] + #[should_panic] + fn assert_not_contains_no() { + assert_not_contains(" ", ""); + } +} + +mod assert_contains_regex { + use super::*; + + #[test] + fn assert_contains_regex_yes() { + assert_contains_regex("", ""); + assert_contains_regex("", ".*"); + assert_contains_regex("abcde", ".*"); + assert_contains_regex("abcde", ".+"); + } + + #[test] + #[should_panic] + fn assert_contains_regex_no() { + assert_contains_regex("", ".+"); + } +} + +mod assert_not_contains_regex_regex { + use super::*; + + #[test] + fn assert_not_contains_regex_yes() { + assert_not_contains_regex("abc", "d"); + } + + #[test] + #[should_panic] + fn assert_not_contains_regex_no() { + assert_not_contains_regex("abc", ".*"); + } +} + +mod test_assert_count_is { + use super::*; + + #[test] + fn assert_count_is_yes() { + assert_count_is(0, "", "b"); + assert_count_is(3, "abcbdb", "b"); + } + + #[test] + #[should_panic] + fn assert_count_is_no() { + assert_count_is(2, "abcbdb", "b"); + } +} diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index d00d5a9b4da..912cbb668b0 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -18,7 +18,7 @@ const LICENSES: &[&str] = &[ // tidy-alphabetical-start "(MIT OR Apache-2.0) AND Unicode-3.0", // unicode_ident (1.0.14) "(MIT OR Apache-2.0) AND Unicode-DFS-2016", // unicode_ident (1.0.12) - "0BSD OR MIT OR Apache-2.0", // adler license + "0BSD OR MIT OR Apache-2.0", // adler2 license "0BSD", "Apache-2.0 / MIT", "Apache-2.0 OR ISC OR MIT", @@ -462,7 +462,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ const PERMITTED_STDLIB_DEPENDENCIES: &[&str] = &[ // tidy-alphabetical-start "addr2line", - "adler", + "adler2", "allocator-api2", "cc", "cfg-if", |
