diff --git a/CHANGELOG.md b/CHANGELOG.md index 483a34826a7..e004bba0dc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ ### Changed - Stabilize `style_edition=2024` and stabilize the `style_edition` command line option [#6431](https://github.com/rust-lang/rustfmt/pull/6431) [rust-lang/rust#134929](https://github.com/rust-lang/rust/pull/134929) -- Apply version sorting to module declarations when using `style_edition=2024` [#6368](https://github.com/rust-lang/rustfmt/pull/6368) +- Apply version sorting to module declarations when using `style_edition=2027` [#6368](https://github.com/rust-lang/rustfmt/pull/6368) and [#6594](https://github.com/rust-lang/rustfmt/pull/6594) - When users set the deprecated `version` config, rustfmt now gives a hint about which equivalent `style_edition` they should use [#6361](https://github.com/rust-lang/rustfmt/pull/6361) - Correct version chunk splitting in the internal version sort algorithm [#6407](https://github.com/rust-lang/rustfmt/pull/6407) - Extend support for single line let-chain formatting to include cases where the left hand side operand is a literal, in alignment with finalized style rules as part of let-chain stabilization [#6492](https://github.com/rust-lang/rustfmt/pull/6492) diff --git a/Cargo.lock b/Cargo.lock index acc898ef086..ee9c0f0cbcb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,9 +77,9 @@ checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "bstr" @@ -125,7 +125,7 @@ dependencies = [ "semver", "serde", "serde_json", - "thiserror", + "thiserror 1.0.40", ] [[package]] @@ -208,23 +208,23 @@ checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" [[package]] name = "dirs" -version = "5.0.1" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" dependencies = [ "dirs-sys", ] [[package]] name = "dirs-sys" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.48.0", + "windows-sys 0.60.2", ] [[package]] @@ -256,9 +256,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.6" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", @@ -341,9 +341,19 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.141" +version = "0.2.177" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" + +[[package]] +name = "libredox" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" +dependencies = [ + "bitflags", + "libc", +] [[package]] name = "log" @@ -405,9 +415,9 @@ checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] @@ -421,24 +431,15 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" -dependencies = [ - "bitflags", -] - [[package]] name = "redox_users" -version = "0.4.3" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" dependencies = [ "getrandom", - "redox_syscall", - "thiserror", + "libredox", + "thiserror 2.0.17", ] [[package]] @@ -497,7 +498,7 @@ dependencies = [ "serde", "serde_json", "term", - "thiserror", + "thiserror 1.0.40", "toml", "tracing", "tracing-subscriber", @@ -593,9 +594,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" dependencies = [ "proc-macro2", "quote", @@ -617,7 +618,16 @@ version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.40", +] + +[[package]] +name = "thiserror" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +dependencies = [ + "thiserror-impl 2.0.17", ] [[package]] @@ -631,6 +641,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.4" @@ -778,9 +799,9 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "winapi" @@ -825,7 +846,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets 0.48.0", + "windows-targets 0.48.5", ] [[package]] @@ -839,17 +860,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.0", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] @@ -871,9 +892,9 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" @@ -883,9 +904,9 @@ checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" @@ -895,9 +916,9 @@ checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" @@ -913,9 +934,9 @@ checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" @@ -925,9 +946,9 @@ checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" @@ -937,9 +958,9 @@ checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" @@ -949,9 +970,9 @@ checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" diff --git a/Cargo.toml b/Cargo.toml index 9aba9bfa64d..fa4869b0355 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ cargo_metadata = "0.18" clap = { version = "4.4.2", features = ["derive"] } clap-cargo = "0.12.0" diff = "0.1" -dirs = "5.0" +dirs = "6.0" getopts = "0.2" ignore = "0.4" itertools = "0.12" diff --git a/rust-toolchain b/rust-toolchain index 80851788276..f2ce790ea06 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2025-04-02" +channel = "nightly-2025-12-06" components = ["llvm-tools", "rustc-dev"] diff --git a/src/chains.rs b/src/chains.rs index 9ab20b355fb..90adb67ad43 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -58,7 +58,7 @@ use std::borrow::Cow; use std::cmp::min; -use rustc_ast::{ast, ptr}; +use rustc_ast::ast; use rustc_span::{BytePos, Span, symbol}; use tracing::debug; @@ -190,7 +190,7 @@ enum ChainItemKind { MethodCall( ast::PathSegment, Vec, - ThinVec>, + ThinVec>, ), StructField(symbol::Ident), TupleField(symbol::Ident, bool), @@ -351,7 +351,7 @@ impl ChainItem { fn rewrite_method_call( method_name: symbol::Ident, types: &[ast::GenericArg], - args: &[ptr::P], + args: &[Box], span: Span, context: &RewriteContext<'_>, shape: Shape, diff --git a/src/closures.rs b/src/closures.rs index 1ab1a80f863..19cd0d9792c 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -1,4 +1,4 @@ -use rustc_ast::{Label, ast, ptr}; +use rustc_ast::{Label, ast}; use rustc_span::Span; use thin_vec::thin_vec; use tracing::debug; @@ -169,7 +169,7 @@ fn rewrite_closure_with_block( let block = ast::Block { stmts: thin_vec![ast::Stmt { id: ast::NodeId::root(), - kind: ast::StmtKind::Expr(ptr::P(body.clone())), + kind: ast::StmtKind::Expr(Box::new(body.clone())), span: body.span, }], id: ast::NodeId::root(), diff --git a/src/config/mod.rs b/src/config/mod.rs index 04a4e89dee7..a21dd36f176 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -556,7 +556,6 @@ mod test { #[allow(dead_code)] mod mock { use super::super::*; - use crate::config_option_with_style_edition_default; use rustfmt_config_proc_macro::config_type; #[config_type] diff --git a/src/expr.rs b/src/expr.rs index 348cffc21ee..1c309800010 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -3,7 +3,7 @@ use std::cmp::min; use itertools::Itertools; use rustc_ast::token::{Delimiter, Lit, LitKind}; -use rustc_ast::{ForLoopKind, MatchKind, ast, ptr, token}; +use rustc_ast::{ForLoopKind, MatchKind, ast, token}; use rustc_span::{BytePos, Span}; use tracing::debug; @@ -1461,7 +1461,7 @@ fn choose_separator_tactic(context: &RewriteContext<'_>, span: Span) -> Option, callee: &str, - args: &[ptr::P], + args: &[Box], span: Span, shape: Shape, ) -> RewriteResult { @@ -1724,7 +1724,7 @@ fn struct_lit_can_be_aligned(fields: &[ast::ExprField], has_base: bool) -> bool fn rewrite_struct_lit<'a>( context: &RewriteContext<'_>, path: &ast::Path, - qself: &Option>, + qself: &Option>, fields: &'a [ast::ExprField], struct_rest: &ast::StructRest, attrs: &[ast::Attribute], @@ -2127,7 +2127,7 @@ fn rewrite_assignment( context: &RewriteContext<'_>, lhs: &ast::Expr, rhs: &ast::Expr, - op: Option<&ast::BinOp>, + op: Option<&ast::AssignOp>, shape: Shape, ) -> RewriteResult { let operator_str = match op { @@ -2357,8 +2357,10 @@ fn rewrite_expr_addrof( ) -> RewriteResult { let operator_str = match (mutability, borrow_kind) { (ast::Mutability::Not, ast::BorrowKind::Ref) => "&", + (ast::Mutability::Not, ast::BorrowKind::Pin) => "&pin const ", (ast::Mutability::Not, ast::BorrowKind::Raw) => "&raw const ", (ast::Mutability::Mut, ast::BorrowKind::Ref) => "&mut ", + (ast::Mutability::Mut, ast::BorrowKind::Pin) => "&pin mut ", (ast::Mutability::Mut, ast::BorrowKind::Raw) => "&raw mut ", }; rewrite_unary_prefix(context, operator_str, expr, shape) diff --git a/src/imports.rs b/src/imports.rs index f0797516b15..54023824d7f 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -184,7 +184,7 @@ impl UseSegment { modsep: bool, ) -> Option { let name = rewrite_ident(context, path_seg.ident); - if name.is_empty() || name == "{{root}}" { + if name.is_empty() { return None; } let kind = match name { diff --git a/src/items.rs b/src/items.rs index 0e814644304..6ec1f0ff1c9 100644 --- a/src/items.rs +++ b/src/items.rs @@ -4,8 +4,8 @@ use std::borrow::Cow; use std::cmp::{Ordering, max, min}; use regex::Regex; +use rustc_ast::ast; use rustc_ast::visit; -use rustc_ast::{ast, ptr}; use rustc_span::{BytePos, DUMMY_SP, Ident, Span, symbol}; use tracing::debug; @@ -65,6 +65,11 @@ impl Rewrite for ast::Local { return Err(RewriteError::SkipFormatting); } + // FIXME(super_let): Implement formatting + if self.super_.is_some() { + return Err(RewriteError::SkipFormatting); + } + let attrs_str = self.attrs.rewrite_result(context, shape)?; let mut result = if attrs_str.is_empty() { "let ".to_owned() @@ -675,7 +680,7 @@ impl<'a> FmtVisitor<'a> { // StyleEdition::Edition20{15|18|21} formatting that was off by 1. See issue #5801 field.attrs.rewrite(&context, shape.sub_width_opt(1)?)? }; - // sub_width(1) to take the trailing comma into account + // sub_width_opt(1) to take the trailing comma into account let shape = shape.sub_width_opt(1)?; let lo = field @@ -714,9 +719,9 @@ impl<'a> FmtVisitor<'a> { .ok() } - fn visit_impl_items(&mut self, items: &[ptr::P]) { + fn visit_impl_items(&mut self, items: &[Box]) { if self.get_context().config.reorder_impl_items() { - type TyOpt = Option>; + type TyOpt = Option>; use crate::ast::AssocItemKind::*; let is_type = |ty: &TyOpt| opaque_ty(ty).is_none(); let is_opaque = |ty: &TyOpt| opaque_ty(ty).is_some(); @@ -825,8 +830,7 @@ pub(crate) fn format_impl( let where_span_end = context.snippet_provider.opt_span_before(missing_span, "{"); let where_clause_str = rewrite_where_clause( context, - &generics.where_clause.predicates, - generics.where_clause.span, + &generics.where_clause, context.config.brace_style(), Shape::legacy(where_budget, offset.block_only()), false, @@ -922,7 +926,7 @@ pub(crate) fn format_impl( fn is_impl_single_line( context: &RewriteContext<'_>, - items: &[ptr::P], + items: &[Box], result: &str, where_clause_str: &str, item: &ast::Item, @@ -944,20 +948,22 @@ fn format_impl_ref_and_type( offset: Indent, ) -> RewriteResult { let ast::Impl { - safety, - polarity, - defaultness, + generics, + of_trait, + self_ty, + items: _, constness, - ref generics, - of_trait: ref trait_ref, - ref self_ty, - .. - } = *iimpl; + } = iimpl; let mut result = String::with_capacity(128); result.push_str(&format_visibility(context, &item.vis)); - result.push_str(format_defaultness(defaultness)); - result.push_str(format_safety(safety)); + + if let Some(of_trait) = of_trait.as_deref() { + result.push_str(format_defaultness(of_trait.defaultness)); + result.push_str(format_safety(of_trait.safety)); + } else { + result.push_str(format_constness_right(*constness)); + } let shape = if context.config.style_edition() >= StyleEdition::Edition2024 { Shape::indented(offset + last_line_width(&result), context.config) @@ -971,28 +977,24 @@ fn format_impl_ref_and_type( }; let generics_str = rewrite_generics(context, "impl", generics, shape)?; result.push_str(&generics_str); - result.push_str(format_constness_right(constness)); - - let polarity_str = match polarity { - ast::ImplPolarity::Negative(_) => "!", - ast::ImplPolarity::Positive => "", - }; - let polarity_overhead; let trait_ref_overhead; - if let Some(ref trait_ref) = *trait_ref { + if let Some(of_trait) = of_trait.as_deref() { + result.push_str(format_constness_right(*constness)); + let polarity_str = match of_trait.polarity { + ast::ImplPolarity::Negative(_) => "!", + ast::ImplPolarity::Positive => "", + }; let result_len = last_line_width(&result); result.push_str(&rewrite_trait_ref( context, - trait_ref, + &of_trait.trait_ref, offset, polarity_str, result_len, )?); - polarity_overhead = 0; // already written trait_ref_overhead = " for".len(); } else { - polarity_overhead = polarity_str.len(); trait_ref_overhead = 0; } @@ -1007,17 +1009,15 @@ fn format_impl_ref_and_type( } else { 0 }; - let used_space = - last_line_width(&result) + polarity_overhead + trait_ref_overhead + curly_brace_overhead; + let used_space = last_line_width(&result) + trait_ref_overhead + curly_brace_overhead; // 1 = space before the type. let budget = context.budget(used_space + 1); if let Some(self_ty_str) = self_ty.rewrite(context, Shape::legacy(budget, offset)) { if !self_ty_str.contains('\n') { - if trait_ref.is_some() { + if of_trait.is_some() { result.push_str(" for "); } else { result.push(' '); - result.push_str(polarity_str); } result.push_str(&self_ty_str); return Ok(result); @@ -1029,12 +1029,10 @@ fn format_impl_ref_and_type( // Add indentation of one additional tab. let new_line_offset = offset.block_indent(context.config); result.push_str(&new_line_offset.to_string(context.config)); - if trait_ref.is_some() { + if of_trait.is_some() { result.push_str("for "); - } else { - result.push_str(polarity_str); } - let budget = context.budget(last_line_width(&result) + polarity_overhead); + let budget = context.budget(last_line_width(&result)); let type_offset = match context.config.indent_style() { IndentStyle::Visual => new_line_offset + trait_ref_overhead, IndentStyle::Block => new_line_offset, @@ -1097,10 +1095,10 @@ impl<'a> StructParts<'a> { pub(crate) fn from_item(item: &'a ast::Item) -> Self { let (prefix, def, ident, generics) = match item.kind { - ast::ItemKind::Struct(ident, ref def, ref generics) => { + ast::ItemKind::Struct(ident, ref generics, ref def) => { ("struct ", def, ident, generics) } - ast::ItemKind::Union(ident, ref def, ref generics) => ("union ", def, ident, generics), + ast::ItemKind::Union(ident, ref generics, ref def) => ("union ", def, ident, generics), _ => unreachable!(), }; StructParts { @@ -1153,22 +1151,26 @@ fn format_struct( pub(crate) fn format_trait( context: &RewriteContext<'_>, item: &ast::Item, - trait_: &ast::Trait, offset: Indent, ) -> RewriteResult { + let ast::ItemKind::Trait(trait_kind) = &item.kind else { + unreachable!(); + }; let ast::Trait { + constness, is_auto, safety, ident, ref generics, ref bounds, ref items, - } = *trait_; + } = **trait_kind; let mut result = String::with_capacity(128); let header = format!( - "{}{}{}trait ", + "{}{}{}{}trait ", format_visibility(context, &item.vis), + format_constness(constness), format_safety(safety), format_auto(is_auto), ); @@ -1214,8 +1216,7 @@ pub(crate) fn format_trait( let option = WhereClauseOption::snuggled(&generics_str); let where_clause_str = rewrite_where_clause( context, - &generics.where_clause.predicates, - generics.where_clause.span, + &generics.where_clause, context.config.brace_style(), Shape::legacy(where_budget, offset.block_only()), where_on_new_line, @@ -1224,7 +1225,6 @@ pub(crate) fn format_trait( pos_before_where, option, )?; - // If the where-clause cannot fit on the same line, // put the where-clause on a new line if !where_clause_str.contains('\n') @@ -1340,8 +1340,7 @@ impl<'a> Rewrite for TraitAliasBounds<'a> { let where_str = rewrite_where_clause( context, - &self.generics.where_clause.predicates, - self.generics.where_clause.span, + &self.generics.where_clause, context.config.brace_style(), shape, false, @@ -1370,6 +1369,7 @@ pub(crate) fn format_trait_alias( context: &RewriteContext<'_>, ident: Ident, item: &ast::Item, + constness: ast::Const, generics: &ast::Generics, generic_bounds: &ast::GenericBounds, shape: Shape, @@ -1380,7 +1380,8 @@ pub(crate) fn format_trait_alias( let g_shape = shape.offset_left(6, span)?.sub_width(2, span)?; let generics_str = rewrite_generics(context, alias, generics, g_shape)?; let vis_str = format_visibility(context, vis); - let lhs = format!("{vis_str}trait {generics_str} ="); + let constness = format_constness(constness); + let lhs = format!("{vis_str}{constness}trait {generics_str} ="); // 1 = ";" let trait_alias_bounds = TraitAliasBounds { generic_bounds, @@ -1611,8 +1612,7 @@ fn format_tuple_struct( let option = WhereClauseOption::new(true, WhereClauseSpace::Newline); rewrite_where_clause( context, - &generics.where_clause.predicates, - generics.where_clause.span, + &generics.where_clause, context.config.brace_style(), Shape::legacy(where_budget, offset.block_only()), false, @@ -1633,12 +1633,12 @@ fn format_tuple_struct( let inner_span = mk_sp(body_lo, body_hi); format_empty_struct_or_tuple(context, inner_span, offset, &mut result, "(", ")"); } else { + let shape = Shape::indented(offset, context.config).sub_width_opt(1)?; let lo = if let Some(generics) = struct_parts.generics { generics.span.hi() } else { struct_parts.ident.span.hi() }; - let shape = Shape::indented(offset, context.config).sub_width_opt(1)?; result = overflow::rewrite_with_parens( context, &result, @@ -1681,7 +1681,7 @@ struct TyAliasRewriteInfo<'c, 'g>( &'c RewriteContext<'c>, Indent, &'g ast::Generics, - ast::TyAliasWhereClauses, + &'g ast::WhereClause, symbol::Ident, Span, ); @@ -1702,13 +1702,13 @@ pub(crate) fn rewrite_type_alias<'a>( ref generics, ref bounds, ref ty, - where_clauses, + ref after_where_clause, } = *ty_alias_kind; let ty_opt = ty.as_ref(); let rhs_hi = ty .as_ref() - .map_or(where_clauses.before.span.hi(), |ty| ty.span.hi()); - let rw_info = &TyAliasRewriteInfo(context, indent, generics, where_clauses, ident, span); + .map_or(generics.where_clause.span.hi(), |ty| ty.span.hi()); + let rw_info = &TyAliasRewriteInfo(context, indent, generics, after_where_clause, ident, span); let op_ty = opaque_ty(ty); // Type Aliases are formatted slightly differently depending on the context // in which they appear, whether they are opaque, and whether they are associated. @@ -1752,11 +1752,7 @@ fn rewrite_ty( vis: &ast::Visibility, ) -> RewriteResult { let mut result = String::with_capacity(128); - let TyAliasRewriteInfo(context, indent, generics, where_clauses, ident, span) = *rw_info; - let (before_where_predicates, after_where_predicates) = generics - .where_clause - .predicates - .split_at(where_clauses.split); + let TyAliasRewriteInfo(context, indent, generics, after_where_clause, ident, span) = *rw_info; result.push_str(&format!("{}type ", format_visibility(context, vis))); let ident_str = rewrite_ident(context, ident); @@ -1791,8 +1787,7 @@ fn rewrite_ty( } let before_where_clause_str = rewrite_where_clause( context, - before_where_predicates, - where_clauses.before.span, + &generics.where_clause, context.config.brace_style(), Shape::legacy(where_budget, indent), false, @@ -1807,9 +1802,9 @@ fn rewrite_ty( // If there are any where clauses, add a newline before the assignment. // If there is a before where clause, do not indent, but if there is // only an after where clause, additionally indent the type. - if !before_where_predicates.is_empty() { + if !generics.where_clause.predicates.is_empty() { result.push_str(&indent.to_string_with_newline(context.config)); - } else if !after_where_predicates.is_empty() { + } else if !after_where_clause.predicates.is_empty() { result.push_str( &indent .block_indent(context.config) @@ -1822,7 +1817,7 @@ fn rewrite_ty( let comment_span = context .snippet_provider .opt_span_before(span, "=") - .map(|op_lo| mk_sp(where_clauses.before.span.hi(), op_lo)); + .map(|op_lo| mk_sp(generics.where_clause.span.hi(), op_lo)); let lhs = match comment_span { Some(comment_span) @@ -1833,7 +1828,7 @@ fn rewrite_ty( .unknown_error()?, ) => { - let comment_shape = if !before_where_predicates.is_empty() { + let comment_shape = if !generics.where_clause.predicates.is_empty() { Shape::indented(indent, context.config) } else { let shape = Shape::indented(indent, context.config); @@ -1854,7 +1849,7 @@ fn rewrite_ty( // 1 = `;` unless there's a trailing where clause let shape = Shape::indented(indent, context.config); - let shape = if after_where_predicates.is_empty() { + let shape = if after_where_clause.predicates.is_empty() { Shape::indented(indent, context.config).sub_width(1, span)? } else { shape @@ -1864,12 +1859,11 @@ fn rewrite_ty( result }; - if !after_where_predicates.is_empty() { + if !after_where_clause.predicates.is_empty() { let option = WhereClauseOption::new(true, WhereClauseSpace::Newline); let after_where_clause_str = rewrite_where_clause( context, - after_where_predicates, - where_clauses.after.span, + &after_where_clause, context.config.brace_style(), Shape::indented(indent, context.config), false, @@ -1998,37 +1992,37 @@ pub(crate) struct StaticParts<'a> { generics: Option<&'a ast::Generics>, ty: &'a ast::Ty, mutability: ast::Mutability, - expr_opt: Option<&'a ptr::P>, + expr_opt: Option<&'a ast::Expr>, defaultness: Option, span: Span, } impl<'a> StaticParts<'a> { pub(crate) fn from_item(item: &'a ast::Item) -> Self { - let (defaultness, prefix, safety, ident, ty, mutability, expr, generics) = match &item.kind - { - ast::ItemKind::Static(s) => ( - None, - "static", - s.safety, - s.ident, - &s.ty, - s.mutability, - &s.expr, - None, - ), - ast::ItemKind::Const(c) => ( - Some(c.defaultness), - "const", - ast::Safety::Default, - c.ident, - &c.ty, - ast::Mutability::Not, - &c.expr, - Some(&c.generics), - ), - _ => unreachable!(), - }; + let (defaultness, prefix, safety, ident, ty, mutability, expr_opt, generics) = + match &item.kind { + ast::ItemKind::Static(s) => ( + None, + "static", + s.safety, + s.ident, + &s.ty, + s.mutability, + s.expr.as_deref(), + None, + ), + ast::ItemKind::Const(c) => ( + Some(c.defaultness), + "const", + ast::Safety::Default, + c.ident, + &c.ty, + ast::Mutability::Not, + c.rhs.as_ref().map(|rhs| rhs.expr()), + Some(&c.generics), + ), + _ => unreachable!(), + }; StaticParts { prefix, safety, @@ -2037,7 +2031,7 @@ impl<'a> StaticParts<'a> { generics, ty, mutability, - expr_opt: expr.as_ref(), + expr_opt, defaultness, span: item.span, } @@ -2045,7 +2039,12 @@ impl<'a> StaticParts<'a> { pub(crate) fn from_trait_item(ti: &'a ast::AssocItem, ident: Ident) -> Self { let (defaultness, ty, expr_opt, generics) = match &ti.kind { - ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics)), + ast::AssocItemKind::Const(c) => ( + c.defaultness, + &c.ty, + c.rhs.as_ref().map(|rhs| rhs.expr()), + Some(&c.generics), + ), _ => unreachable!(), }; StaticParts { @@ -2056,15 +2055,20 @@ impl<'a> StaticParts<'a> { generics, ty, mutability: ast::Mutability::Not, - expr_opt: expr_opt.as_ref(), + expr_opt, defaultness: Some(defaultness), span: ti.span, } } pub(crate) fn from_impl_item(ii: &'a ast::AssocItem, ident: Ident) -> Self { - let (defaultness, ty, expr, generics) = match &ii.kind { - ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr, Some(&c.generics)), + let (defaultness, ty, expr_opt, generics) = match &ii.kind { + ast::AssocItemKind::Const(c) => ( + c.defaultness, + &c.ty, + c.rhs.as_ref().map(|rhs| rhs.expr()), + Some(&c.generics), + ), _ => unreachable!(), }; StaticParts { @@ -2075,7 +2079,7 @@ impl<'a> StaticParts<'a> { generics, ty, mutability: ast::Mutability::Not, - expr_opt: expr.as_ref(), + expr_opt, defaultness: Some(defaultness), span: ii.span, } @@ -2138,7 +2142,7 @@ fn rewrite_static( rewrite_assign_rhs_with_comments( context, &lhs, - &**expr, + expr, Shape::legacy(remaining_width, offset.block_only()), &RhsAssignKind::Expr(&expr.kind, expr.span), RhsTactics::Default, @@ -2421,11 +2425,7 @@ pub(crate) fn span_hi_for_param(context: &RewriteContext<'_>, param: &ast::Param } pub(crate) fn is_named_param(param: &ast::Param) -> bool { - if let ast::PatKind::Ident(_, ident, _) = param.pat.kind { - ident.name != symbol::kw::Empty - } else { - true - } + !matches!(param.pat.kind, ast::PatKind::Missing) } #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -2569,7 +2569,7 @@ fn rewrite_fn_base( .last() .map_or(false, |last_line| last_line.contains("//")); - if context.config.style_edition() >= StyleEdition::Edition2027 { + if context.config.style_edition() >= StyleEdition::Edition2024 { if closing_paren_overflow_max_width { result.push(')'); result.push_str(&indent.to_string_with_newline(context.config)); @@ -2713,8 +2713,7 @@ fn rewrite_fn_base( } let where_clause_str = rewrite_where_clause( context, - &where_clause.predicates, - where_clause.span, + &where_clause, context.config.brace_style(), Shape::indented(indent, context.config), true, @@ -3017,8 +3016,8 @@ fn rewrite_where_clause_rfc_style( let clause_shape = shape .block() .with_max_width(context.config) - .block_left(context.config.tab_spaces(), where_span)? - .sub_width(1, where_span)?; + .block_left(context.config.tab_spaces(), where_span) + .and_then(|s| s.sub_width(1, where_span))?; let force_single_line = context.config.where_single_line() && predicates.len() == 1 && !where_clause_option.veto_single_line; @@ -3146,8 +3145,7 @@ fn rewrite_bounds_on_where_clause( fn rewrite_where_clause( context: &RewriteContext<'_>, - predicates: &[ast::WherePredicate], - where_span: Span, + where_clause: &ast::WhereClause, brace_style: BraceStyle, shape: Shape, on_new_line: bool, @@ -3156,6 +3154,12 @@ fn rewrite_where_clause( span_end_before_where: BytePos, where_clause_option: WhereClauseOption, ) -> RewriteResult { + let ast::WhereClause { + ref predicates, + span: where_span, + has_where_token: _, + } = *where_clause; + if predicates.is_empty() { return Ok(String::new()); } @@ -3342,8 +3346,7 @@ fn format_generics( } let where_clause_str = rewrite_where_clause( context, - &generics.where_clause.predicates, - generics.where_clause.span, + &generics.where_clause, brace_style, Shape::legacy(budget, offset.block_only()), true, @@ -3585,7 +3588,7 @@ pub(crate) fn rewrite_extern_crate( pub(crate) fn is_mod_decl(item: &ast::Item) -> bool { !matches!( item.kind, - ast::ItemKind::Mod(_, _, ast::ModKind::Loaded(_, ast::Inline::Yes, _, _)) + ast::ItemKind::Mod(_, _, ast::ModKind::Loaded(_, ast::Inline::Yes, _)) ) } diff --git a/src/macros.rs b/src/macros.rs index 3b58d28bfb0..1c5d804c6d4 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -12,9 +12,9 @@ use std::collections::HashMap; use std::panic::{AssertUnwindSafe, catch_unwind}; +use rustc_ast::ast; use rustc_ast::token::{Delimiter, Token, TokenKind}; use rustc_ast::tokenstream::{TokenStream, TokenStreamIter, TokenTree}; -use rustc_ast::{ast, ptr}; use rustc_ast_pretty::pprust; use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Symbol}; use tracing::debug; @@ -53,10 +53,10 @@ pub(crate) enum MacroPosition { #[derive(Debug)] pub(crate) enum MacroArg { - Expr(ptr::P), - Ty(ptr::P), - Pat(ptr::P), - Item(ptr::P), + Expr(Box), + Ty(Box), + Pat(Box), + Item(Box), Keyword(Ident, Span), } @@ -724,7 +724,7 @@ fn last_tok(tt: &TokenTree) -> Token { match *tt { TokenTree::Token(ref t, _) => t.clone(), TokenTree::Delimited(delim_span, _, delim, _) => Token { - kind: TokenKind::CloseDelim(delim), + kind: delim.as_open_token_kind(), span: delim_span.close, }, } @@ -860,18 +860,18 @@ impl MacroArgParser { }; self.result.push(ParsedMacroArg { - kind: MacroArgKind::Repeat(delim, inner, another, self.last_tok.clone()), + kind: MacroArgKind::Repeat(delim, inner, another, self.last_tok), }); Some(()) } - fn update_buffer(&mut self, t: &Token) { + fn update_buffer(&mut self, t: Token) { if self.buf.is_empty() { - self.start_tok = t.clone(); + self.start_tok = t; } else { let needs_space = match next_space(&self.last_tok.kind) { - SpaceState::Ident => ident_like(t), - SpaceState::Punctuation => !ident_like(t), + SpaceState::Ident => ident_like(&t), + SpaceState::Punctuation => !ident_like(&t), SpaceState::Always => true, SpaceState::Never => false, }; @@ -880,7 +880,7 @@ impl MacroArgParser { } } - self.buf.push_str(&pprust::token_to_string(t)); + self.buf.push_str(&pprust::token_to_string(&t)); } fn need_space_prefix(&self) -> bool { @@ -939,7 +939,7 @@ impl MacroArgParser { ) if self.is_meta_var => { self.add_meta_variable(&mut iter)?; } - TokenTree::Token(ref t, _) => self.update_buffer(t), + &TokenTree::Token(t, _) => self.update_buffer(t), &TokenTree::Delimited(_dspan, _spacing, delimited, ref tts) => { if !self.buf.is_empty() { if next_space(&self.last_tok.kind) == SpaceState::Always { @@ -1126,8 +1126,14 @@ fn next_space(tok: &TokenKind) -> SpaceState { TokenKind::PathSep | TokenKind::Pound | TokenKind::Dollar - | TokenKind::OpenDelim(_) - | TokenKind::CloseDelim(_) => SpaceState::Never, + | TokenKind::OpenParen + | TokenKind::CloseParen + | TokenKind::OpenBrace + | TokenKind::CloseBrace + | TokenKind::OpenBracket + | TokenKind::CloseBracket + | TokenKind::OpenInvisible(_) + | TokenKind::CloseInvisible(_) => SpaceState::Never, TokenKind::Literal(..) | TokenKind::Ident(..) | TokenKind::Lifetime(..) => { SpaceState::Ident diff --git a/src/matches.rs b/src/matches.rs index 1727a9de868..4741abbe465 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -2,7 +2,7 @@ use std::iter::repeat; -use rustc_ast::{MatchKind, ast, ptr}; +use rustc_ast::{MatchKind, ast}; use rustc_span::{BytePos, Span}; use tracing::debug; @@ -396,7 +396,7 @@ fn flatten_arm_body<'a>( fn rewrite_match_body( context: &RewriteContext<'_>, - body: &ptr::P, + body: &Box, pats_str: &str, shape: Shape, has_guard: bool, @@ -571,7 +571,7 @@ fn rewrite_match_body( // The `if ...` guard on a match arm. fn rewrite_guard( context: &RewriteContext<'_>, - guard: &Option>, + guard: &Option>, shape: Shape, // The amount of space used up on this line for the pattern in // the arm (excludes offset). diff --git a/src/modules.rs b/src/modules.rs index 4270f692910..b1d6394875b 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -26,7 +26,7 @@ type FileModMap<'ast> = BTreeMap>; #[derive(Debug, Clone)] pub(crate) struct Module<'a> { ast_mod_kind: Option>, - pub(crate) items: Cow<'a, ThinVec>>, + pub(crate) items: Cow<'a, ThinVec>>, inner_attr: ast::AttrVec, pub(crate) span: Span, } @@ -35,7 +35,7 @@ impl<'a> Module<'a> { pub(crate) fn new( mod_span: Span, ast_mod_kind: Option>, - mod_items: Cow<'a, ThinVec>>, + mod_items: Cow<'a, ThinVec>>, mod_attrs: Cow<'a, ast::AttrVec>, ) -> Self { let inner_attr = mod_attrs @@ -189,16 +189,16 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> { /// Visit modules defined inside macro calls. fn visit_mod_outside_ast( &mut self, - items: ThinVec>, + items: ThinVec>, ) -> Result<(), ModuleResolutionError> { for item in items { if is_cfg_if(&item) { - self.visit_cfg_if(Cow::Owned(item.into_inner()))?; + self.visit_cfg_if(Cow::Owned(*item))?; continue; } if is_cfg_match(&item) { - self.visit_cfg_match(Cow::Owned(item.into_inner()))?; + self.visit_cfg_match(Cow::Owned(*item))?; continue; } @@ -221,7 +221,7 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> { /// Visit modules from AST. fn visit_mod_from_ast( &mut self, - items: &'ast [rustc_ast::ptr::P], + items: &'ast [Box], ) -> Result<(), ModuleResolutionError> { for item in items { if is_cfg_if(item) { @@ -344,11 +344,12 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> { self.directory = directory; } match (sub_mod.ast_mod_kind, sub_mod.items) { - (Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _, _))), _) => { + (Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => { self.visit_mod_from_ast(items) } - (Some(Cow::Owned(ast::ModKind::Loaded(items, _, _, _))), _) - | (_, Cow::Owned(items)) => self.visit_mod_outside_ast(items), + (Some(Cow::Owned(ast::ModKind::Loaded(items, _, _))), _) | (_, Cow::Owned(items)) => { + self.visit_mod_outside_ast(items) + } (_, _) => Ok(()), } } diff --git a/src/overflow.rs b/src/overflow.rs index 19f7b06f8a3..4230c89b57b 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -3,8 +3,8 @@ use std::cmp::min; use itertools::Itertools; +use rustc_ast::ast; use rustc_ast::token::Delimiter; -use rustc_ast::{ast, ptr}; use rustc_span::Span; use tracing::debug; @@ -219,7 +219,7 @@ pub(crate) trait IntoOverflowableItem<'a>: Rewrite + Spanned { fn into_overflowable_item(&'a self) -> OverflowableItem<'a>; } -impl<'a, T: 'a + IntoOverflowableItem<'a>> IntoOverflowableItem<'a> for ptr::P { +impl<'a, T: 'a + IntoOverflowableItem<'a>> IntoOverflowableItem<'a> for Box { fn into_overflowable_item(&'a self) -> OverflowableItem<'a> { (**self).into_overflowable_item() } diff --git a/src/parse/macros/asm.rs b/src/parse/macros/asm.rs new file mode 100644 index 00000000000..bfa9c6300c4 --- /dev/null +++ b/src/parse/macros/asm.rs @@ -0,0 +1,11 @@ +use rustc_ast::ast; +use rustc_parse::parser::asm::{AsmArg, parse_asm_args}; + +use crate::rewrite::RewriteContext; + +#[allow(dead_code)] +pub(crate) fn parse_asm(context: &RewriteContext<'_>, mac: &ast::MacCall) -> Option> { + let ts = mac.args.tokens.clone(); + let mut parser = super::build_parser(context, ts); + parse_asm_args(&mut parser, mac.span(), ast::AsmMacro::Asm).ok() +} diff --git a/src/parse/macros/cfg_if.rs b/src/parse/macros/cfg_if.rs index 0b7b6c4d361..26bf6c5326f 100644 --- a/src/parse/macros/cfg_if.rs +++ b/src/parse/macros/cfg_if.rs @@ -1,7 +1,7 @@ use std::panic::{AssertUnwindSafe, catch_unwind}; use rustc_ast::ast; -use rustc_ast::token::{Delimiter, TokenKind}; +use rustc_ast::token::TokenKind; use rustc_parse::exp; use rustc_parse::parser::ForceCollect; use rustc_span::symbol::kw; @@ -60,11 +60,9 @@ fn parse_cfg_if_inner<'a>( return Err("Expected an opening brace"); } - while parser.token != TokenKind::CloseDelim(Delimiter::Brace) - && parser.token.kind != TokenKind::Eof - { + while parser.token != TokenKind::CloseBrace && parser.token.kind != TokenKind::Eof { let item = match parser.parse_item(ForceCollect::No) { - Ok(Some(item_ptr)) => item_ptr.into_inner(), + Ok(Some(item_ptr)) => *item_ptr, Ok(None) => continue, Err(err) => { err.cancel(); diff --git a/src/parse/macros/cfg_match.rs b/src/parse/macros/cfg_match.rs index 87071db2749..388217af004 100644 --- a/src/parse/macros/cfg_match.rs +++ b/src/parse/macros/cfg_match.rs @@ -1,7 +1,7 @@ use std::panic::{AssertUnwindSafe, catch_unwind}; use rustc_ast::ast; -use rustc_ast::token::{Delimiter, TokenKind}; +use rustc_ast::token::TokenKind; use rustc_parse::exp; use rustc_parse::parser::ForceCollect; @@ -26,7 +26,7 @@ fn parse_cfg_match_inner<'a>( let ts = mac.args.tokens.clone(); let mut parser = build_stream_parser(psess.inner(), ts); - if parser.token == TokenKind::OpenDelim(Delimiter::Brace) { + if parser.token == TokenKind::OpenBrace { return Err("Expression position cfg_match! not yet supported"); } @@ -48,11 +48,9 @@ fn parse_cfg_match_inner<'a>( return Err("Expected an opening brace"); } - while parser.token != TokenKind::CloseDelim(Delimiter::Brace) - && parser.token.kind != TokenKind::Eof - { + while parser.token != TokenKind::CloseBrace && parser.token.kind != TokenKind::Eof { let item = match parser.parse_item(ForceCollect::No) { - Ok(Some(item_ptr)) => item_ptr.into_inner(), + Ok(Some(item)) => *item, Ok(None) => continue, Err(err) => { err.cancel(); diff --git a/src/parse/macros/lazy_static.rs b/src/parse/macros/lazy_static.rs index cbe81004e22..8611615d123 100644 --- a/src/parse/macros/lazy_static.rs +++ b/src/parse/macros/lazy_static.rs @@ -1,5 +1,4 @@ use rustc_ast::ast; -use rustc_ast::ptr::P; use rustc_ast::token; use rustc_ast::tokenstream::TokenStream; use rustc_parse::exp; @@ -10,7 +9,7 @@ use crate::rewrite::RewriteContext; pub(crate) fn parse_lazy_static( context: &RewriteContext<'_>, ts: TokenStream, -) -> Option, P)>> { +) -> Option, Box)>> { let mut result = vec![]; let mut parser = super::build_parser(context, ts); macro_rules! parse_or { diff --git a/src/parse/macros/mod.rs b/src/parse/macros/mod.rs index 16313ce65f4..9ff7fe74df0 100644 --- a/src/parse/macros/mod.rs +++ b/src/parse/macros/mod.rs @@ -1,6 +1,6 @@ +use rustc_ast::ast; use rustc_ast::token::{Delimiter, NonterminalKind, NtExprKind::*, NtPatKind::*, TokenKind}; use rustc_ast::tokenstream::TokenStream; -use rustc_ast::{ast, ptr}; use rustc_parse::MACRO_ARGUMENTS; use rustc_parse::parser::{ForceCollect, Parser, Recovery}; use rustc_session::parse::ParseSess; @@ -49,26 +49,26 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { Expr, NonterminalKind::Expr(Expr), |parser: &mut Parser<'b>| parser.parse_expr(), - |x: ptr::P| Some(x) + |x: Box| Some(x) ); parse_macro_arg!( Ty, NonterminalKind::Ty, |parser: &mut Parser<'b>| parser.parse_ty(), - |x: ptr::P| Some(x) + |x: Box| Some(x) ); parse_macro_arg!( Pat, NonterminalKind::Pat(PatParam { inferred: false }), |parser: &mut Parser<'b>| parser.parse_pat_no_top_alt(None, None), - |x: ptr::P| Some(x) + |x: ast::Pat| Some(Box::new(x)) ); - // `parse_item` returns `Option>`. + // `parse_item` returns `Option>`. parse_macro_arg!( Item, NonterminalKind::Item, |parser: &mut Parser<'b>| parser.parse_item(ForceCollect::No), - |x: Option>| x + |x: Option>| x ); None @@ -164,7 +164,7 @@ pub(crate) fn parse_macro_args( pub(crate) fn parse_expr( context: &RewriteContext<'_>, tokens: TokenStream, -) -> Option> { +) -> Option> { let mut parser = build_parser(context, tokens); parser.parse_expr().ok() } diff --git a/src/parse/parser.rs b/src/parse/parser.rs index f357aed66c2..63c6c8c99d0 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -1,8 +1,9 @@ use std::panic::{AssertUnwindSafe, catch_unwind}; use std::path::{Path, PathBuf}; -use rustc_ast::{ast, attr, ptr}; +use rustc_ast::{ast, attr}; use rustc_errors::Diag; +use rustc_parse::lexer::StripTokens; use rustc_parse::parser::Parser as RawParser; use rustc_parse::{exp, new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal}; use rustc_span::{Span, sym}; @@ -64,11 +65,14 @@ impl<'a> ParserBuilder<'a> { input: Input, ) -> Result, Vec>> { match input { - Input::File(ref file) => new_parser_from_file(psess, file, None), + Input::File(ref file) => { + new_parser_from_file(psess, file, StripTokens::ShebangAndFrontmatter, None) + } Input::Text(text) => new_parser_from_source_str( psess, rustc_span::FileName::Custom("stdin".to_owned()), text, + StripTokens::ShebangAndFrontmatter, ), } } @@ -102,10 +106,14 @@ impl<'a> Parser<'a> { psess: &'a ParseSess, path: &Path, span: Span, - ) -> Result<(ast::AttrVec, ThinVec>, Span), ParserError> { + ) -> Result<(ast::AttrVec, ThinVec>, Span), ParserError> { let result = catch_unwind(AssertUnwindSafe(|| { - let mut parser = - unwrap_or_emit_fatal(new_parser_from_file(psess.inner(), path, Some(span))); + let mut parser = unwrap_or_emit_fatal(new_parser_from_file( + psess.inner(), + path, + StripTokens::ShebangAndFrontmatter, + Some(span), + )); match parser.parse_mod(exp!(Eof)) { Ok((a, i, spans)) => Some((a, i, spans.inner_span)), Err(e) => { diff --git a/src/parse/session.rs b/src/parse/session.rs index afd847f9515..10e2809e58b 100644 --- a/src/parse/session.rs +++ b/src/parse/session.rs @@ -5,7 +5,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use rustc_data_structures::sync::IntoDynSyncSend; use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter, SilentEmitter, stderr_destination}; use rustc_errors::registry::Registry; -use rustc_errors::translation::Translate; +use rustc_errors::translation::Translator; use rustc_errors::{ColorConfig, Diag, DiagCtxt, DiagInner, Level as DiagnosticLevel}; use rustc_session::parse::ParseSess as RawParseSess; use rustc_span::{ @@ -47,16 +47,6 @@ impl SilentOnIgnoredFilesEmitter { } } -impl Translate for SilentOnIgnoredFilesEmitter { - fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> { - self.emitter.fluent_bundle() - } - - fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle { - self.emitter.fallback_fluent_bundle() - } -} - impl Emitter for SilentOnIgnoredFilesEmitter { fn source_map(&self) -> Option<&SourceMap> { None @@ -84,6 +74,10 @@ impl Emitter for SilentOnIgnoredFilesEmitter { } self.handle_non_ignoreable_error(diag, registry); } + + fn translator(&self) -> &Translator { + self.emitter.translator() + } } impl From for ColorConfig { @@ -110,23 +104,15 @@ fn default_dcx( ColorConfig::Never }; - let fallback_bundle = rustc_errors::fallback_fluent_bundle( - rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), - false, - ); - let emitter = Box::new( - HumanEmitter::new(stderr_destination(emit_color), fallback_bundle) - .sm(Some(source_map.clone())), - ); - - let emitter: Box = if !show_parse_errors { - Box::new(SilentEmitter { - fatal_emitter: emitter, - fatal_note: None, - emit_fatal_diagnostic: false, - }) + let translator = rustc_driver::default_translator(); + + let emitter: Box = if show_parse_errors { + Box::new( + HumanEmitter::new(stderr_destination(emit_color), translator) + .sm(Some(source_map.clone())), + ) } else { - emitter + Box::new(SilentEmitter { translator }) }; DiagCtxt::new(Box::new(SilentOnIgnoredFilesEmitter { has_non_ignorable_parser_errors: false, @@ -205,7 +191,7 @@ impl ParseSess { } pub(crate) fn set_silent_emitter(&mut self) { - self.raw_psess.dcx().make_silent(None, false); + self.raw_psess.dcx().make_silent(); } pub(crate) fn span_to_filename(&self, span: Span) -> FileName { @@ -335,16 +321,6 @@ mod tests { num_emitted_errors: Arc, } - impl Translate for TestEmitter { - fn fluent_bundle(&self) -> Option<&rustc_errors::FluentBundle> { - None - } - - fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle { - panic!("test emitter attempted to translate a diagnostic"); - } - } - impl Emitter for TestEmitter { fn source_map(&self) -> Option<&SourceMap> { None @@ -353,6 +329,10 @@ mod tests { fn emit_diagnostic(&mut self, _diag: DiagInner, _registry: &Registry) { self.num_emitted_errors.fetch_add(1, Ordering::Release); } + + fn translator(&self) -> &Translator { + panic!("test emitter attempted to translate a diagnostic"); + } } fn build_diagnostic(level: DiagnosticLevel, span: Option) -> DiagInner { diff --git a/src/patterns.rs b/src/patterns.rs index 80daad75fec..df2a8dc5c6f 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -1,5 +1,4 @@ use rustc_ast::ast::{self, BindingMode, ByRef, Pat, PatField, PatKind, RangeEnd, RangeSyntax}; -use rustc_ast::ptr; use rustc_span::{BytePos, Span}; use crate::comment::{FindUncommented, combine_strs_with_missing_comments}; @@ -18,7 +17,9 @@ use crate::shape::Shape; use crate::source_map::SpanUtils; use crate::spanned::Spanned; use crate::types::{PathContext, rewrite_path}; -use crate::utils::{format_mutability, mk_sp, mk_sp_lo_plus_one, rewrite_ident}; +use crate::utils::{ + format_mutability, format_pinnedness_and_mutability, mk_sp, mk_sp_lo_plus_one, rewrite_ident, +}; /// Returns `true` if the given pattern is "short". /// A short pattern is defined by the following grammar: @@ -42,6 +43,7 @@ pub(crate) fn is_short_pattern( fn is_short_pattern_inner(context: &RewriteContext<'_>, pat: &ast::Pat) -> bool { match &pat.kind { + ast::PatKind::Missing => unreachable!(), ast::PatKind::Rest | ast::PatKind::Never | ast::PatKind::Wild | ast::PatKind::Err(_) => { true } @@ -69,14 +71,14 @@ fn is_short_pattern_inner(context: &RewriteContext<'_>, pat: &ast::Pat) -> bool } ast::PatKind::Box(ref p) | PatKind::Deref(ref p) - | ast::PatKind::Ref(ref p, _) + | ast::PatKind::Ref(ref p, _, _) | ast::PatKind::Paren(ref p) => is_short_pattern_inner(context, &*p), PatKind::Or(ref pats) => pats.iter().all(|p| is_short_pattern_inner(context, p)), } } pub(crate) struct RangeOperand<'a, T> { - pub operand: &'a Option>, + pub operand: &'a Option>, pub span: Span, } @@ -100,6 +102,7 @@ impl Rewrite for Pat { fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult { match self.kind { + PatKind::Missing => unreachable!(), PatKind::Or(ref pats) => { let pat_strs = pats .iter() @@ -132,9 +135,13 @@ impl Rewrite for Pat { PatKind::Ident(BindingMode(by_ref, mutability), ident, ref sub_pat) => { let mut_prefix = format_mutability(mutability).trim(); - let (ref_kw, mut_infix) = match by_ref { - ByRef::Yes(rmutbl) => ("ref", format_mutability(rmutbl).trim()), - ByRef::No => ("", ""), + let (ref_kw, pin_infix, mut_infix) = match by_ref { + ByRef::Yes(pinnedness, rmutbl) => { + let (pin_infix, mut_infix) = + format_pinnedness_and_mutability(pinnedness, rmutbl); + ("ref", pin_infix.trim(), mut_infix.trim()) + } + ByRef::No => ("", "", ""), }; let id_str = rewrite_ident(context, ident); let sub_pat = match *sub_pat { @@ -145,6 +152,7 @@ impl Rewrite for Pat { .checked_sub( mut_prefix.len() + ref_kw.len() + + pin_infix.len() + mut_infix.len() + id_str.len() + 2, @@ -191,18 +199,17 @@ impl Rewrite for Pat { (true, true) => (self.span.lo(), "".to_owned()), }; - // combine result of above and mut - let (second_lo, second) = match (first.is_empty(), mut_infix.is_empty()) { + // combine result of above and pin + let (second_lo, second) = match (first.is_empty(), pin_infix.is_empty()) { (false, false) => { let lo = context.snippet_provider.span_after(self.span, "ref"); - let end_span = mk_sp(first_lo, self.span.hi()); - let hi = context.snippet_provider.span_before(end_span, "mut"); + let hi = context.snippet_provider.span_before(self.span, "pin"); ( - context.snippet_provider.span_after(end_span, "mut"), + context.snippet_provider.span_after(self.span, "pin"), combine_strs_with_missing_comments( context, &first, - mut_infix, + pin_infix, mk_sp(lo, hi), shape, true, @@ -210,7 +217,33 @@ impl Rewrite for Pat { ) } (false, true) => (first_lo, first), - (true, false) => unreachable!("mut_infix necessarily follows a ref"), + (true, false) => unreachable!("pin_infix necessarily follows a ref"), + (true, true) => (self.span.lo(), "".to_owned()), + }; + + // combine result of above and const|mut + let (third_lo, third) = match (second.is_empty(), mut_infix.is_empty()) { + (false, false) => { + let lo = context.snippet_provider.span_after( + self.span, + if pin_infix.is_empty() { "ref" } else { "pin" }, + ); + let end_span = mk_sp(second_lo, self.span.hi()); + let hi = context.snippet_provider.span_before(end_span, mut_infix); + ( + context.snippet_provider.span_after(end_span, mut_infix), + combine_strs_with_missing_comments( + context, + &second, + mut_infix, + mk_sp(lo, hi), + shape, + true, + )?, + ) + } + (false, true) => (second_lo, second), + (true, false) => unreachable!("mut_infix necessarily follows a pin or ref"), (true, true) => (self.span.lo(), "".to_owned()), }; @@ -230,9 +263,9 @@ impl Rewrite for Pat { combine_strs_with_missing_comments( context, - &second, + &third, &next, - mk_sp(second_lo, ident.span.lo()), + mk_sp(third_lo, ident.span.lo()), shape, true, ) @@ -261,8 +294,10 @@ impl Rewrite for Pat { PatKind::Range(ref lhs, ref rhs, ref end_kind) => { rewrite_range_pat(context, shape, lhs, rhs, end_kind, self.span) } - PatKind::Ref(ref pat, mutability) => { - let prefix = format!("&{}", format_mutability(mutability)); + PatKind::Ref(ref pat, pinnedness, mutability) => { + let (pin_prefix, mut_prefix) = + format_pinnedness_and_mutability(pinnedness, mutability); + let prefix = format!("&{}{}", pin_prefix, mut_prefix); rewrite_unary_prefix(context, &prefix, &**pat, shape) } PatKind::Tuple(ref items) => rewrite_tuple_pat(items, None, self.span, context, shape), @@ -302,7 +337,7 @@ impl Rewrite for Pat { qself, path, fields, - rest == ast::PatFieldsRest::Rest, + matches!(rest, ast::PatFieldsRest::Rest(_)), self.span, context, shape, @@ -324,8 +359,8 @@ impl Rewrite for Pat { pub(crate) fn rewrite_range_pat( context: &RewriteContext<'_>, shape: Shape, - lhs: &Option>, - rhs: &Option>, + lhs: &Option>, + rhs: &Option>, end_kind: &rustc_span::source_map::Spanned, span: Span, ) -> RewriteResult { @@ -366,7 +401,7 @@ pub(crate) fn rewrite_range_pat( } fn rewrite_struct_pat( - qself: &Option>, + qself: &Option>, path: &ast::Path, fields: &[ast::PatField], ellipsis: bool, @@ -504,7 +539,7 @@ impl Rewrite for PatField { #[derive(Debug)] pub(crate) enum TuplePatField<'a> { - Pat(&'a ptr::P), + Pat(&'a ast::Pat), Dotdot(Span), } @@ -550,7 +585,7 @@ pub(crate) fn can_be_overflowed_pat( | ast::PatKind::Tuple(..) | ast::PatKind::Struct(..) | ast::PatKind::TupleStruct(..) => context.use_block_indent() && len == 1, - ast::PatKind::Ref(ref p, _) | ast::PatKind::Box(ref p) => { + ast::PatKind::Ref(ref p, _, _) | ast::PatKind::Box(ref p) => { can_be_overflowed_pat(context, &TuplePatField::Pat(p), len) } ast::PatKind::Expr(ref expr) => can_be_overflowed_expr(context, expr, len), @@ -561,7 +596,7 @@ pub(crate) fn can_be_overflowed_pat( } fn rewrite_tuple_pat( - pats: &[ptr::P], + pats: &[ast::Pat], path_str: Option, span: Span, context: &RewriteContext<'_>, diff --git a/src/reorder.rs b/src/reorder.rs index e9d0fc059f8..6ef6e0bc969 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -29,7 +29,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item, context: &RewriteContext<'_>) -> let style_edition = context.config.style_edition(); match (&a.kind, &b.kind) { (&ast::ItemKind::Mod(_, a_ident, _), &ast::ItemKind::Mod(_, b_ident, _)) => { - if style_edition <= StyleEdition::Edition2021 { + if style_edition <= StyleEdition::Edition2024 { a_ident.as_str().cmp(b_ident.as_str()) } else { version_sort(a_ident.as_str(), b_ident.as_str()) @@ -43,7 +43,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item, context: &RewriteContext<'_>) -> // ^^^ Comparing this. let a_orig_name = a_name.unwrap_or(a_ident.name); let b_orig_name = b_name.unwrap_or(b_ident.name); - let result = if style_edition <= StyleEdition::Edition2021 { + let result = if style_edition <= StyleEdition::Edition2024 { a_orig_name.as_str().cmp(b_orig_name.as_str()) } else { version_sort(a_orig_name.as_str(), b_orig_name.as_str()) @@ -58,7 +58,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item, context: &RewriteContext<'_>) -> (Some(..), None) => Ordering::Greater, (None, Some(..)) => Ordering::Less, (None, None) => Ordering::Equal, - (Some(..), Some(..)) if style_edition <= StyleEdition::Edition2021 => { + (Some(..), Some(..)) if style_edition <= StyleEdition::Edition2024 => { a_ident.as_str().cmp(b_ident.as_str()) } (Some(..), Some(..)) => version_sort(a_ident.as_str(), b_ident.as_str()), diff --git a/src/rewrite.rs b/src/rewrite.rs index 7ca1ca522ff..115ec630821 100644 --- a/src/rewrite.rs +++ b/src/rewrite.rs @@ -3,7 +3,6 @@ use std::cell::{Cell, RefCell}; use std::rc::Rc; -use rustc_ast::ptr; use rustc_span::Span; use thiserror::Error; @@ -24,7 +23,7 @@ pub(crate) trait Rewrite { } } -impl Rewrite for ptr::P { +impl Rewrite for Box { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { (**self).rewrite(context, shape) } diff --git a/src/spanned.rs b/src/spanned.rs index 507647566d4..020651e2daa 100644 --- a/src/spanned.rs +++ b/src/spanned.rs @@ -1,6 +1,6 @@ use std::cmp::max; -use rustc_ast::{ast, ptr}; +use rustc_ast::ast; use rustc_span::{Span, source_map}; use crate::macros::MacroArg; @@ -12,7 +12,7 @@ pub(crate) trait Spanned { fn span(&self) -> Span; } -impl Spanned for ptr::P { +impl Spanned for Box { fn span(&self) -> Span { (**self).span() } @@ -122,7 +122,7 @@ impl Spanned for ast::GenericParam { fn span(&self) -> Span { let lo = match self.kind { _ if !self.attrs.is_empty() => self.attrs[0].span.lo(), - ast::GenericParamKind::Const { kw_span, .. } => kw_span.lo(), + ast::GenericParamKind::Const { span, .. } => span.lo(), _ => self.ident.span.lo(), }; let hi = if self.bounds.is_empty() { diff --git a/src/types.rs b/src/types.rs index 76f176c97c4..d47fa8f6302 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,7 +1,6 @@ use std::ops::Deref; use rustc_ast::ast::{self, FnRetTy, Mutability, Term}; -use rustc_ast::ptr; use rustc_span::{BytePos, Pos, Span, symbol::kw}; use tracing::debug; @@ -9,8 +8,7 @@ use crate::comment::{combine_strs_with_missing_comments, contains_comment}; use crate::config::lists::*; use crate::config::{IndentStyle, StyleEdition, TypeDensity}; use crate::expr::{ - ExprType, RhsAssignKind, format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, - rewrite_unary_prefix, + ExprType, RhsAssignKind, format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, }; use crate::lists::{ ListFormatting, ListItem, Separator, definitive_tactic, itemize_list, write_list, @@ -39,7 +37,7 @@ pub(crate) enum PathContext { pub(crate) fn rewrite_path( context: &RewriteContext<'_>, path_context: PathContext, - qself: &Option>, + qself: &Option>, path: &ast::Path, shape: Shape, ) -> RewriteResult { @@ -685,7 +683,7 @@ impl Rewrite for ast::GenericParam { let param_start = if let ast::GenericParamKind::Const { ref ty, - kw_span, + span, default, } = &self.kind { @@ -707,7 +705,7 @@ impl Rewrite for ast::GenericParam { default.rewrite_result(context, Shape::legacy(budget, shape.indent))?; param.push_str(&rewrite); } - kw_span.lo() + span.lo() } else { param.push_str(rewrite_ident(context, self.ident)); self.ident.span.lo() @@ -825,10 +823,6 @@ impl Rewrite for ast::Ty { let shape = shape.offset_left(4, self.span())?; (shape, "dyn ") } - ast::TraitObjectSyntax::DynStar => { - let shape = shape.offset_left(5, self.span())?; - (shape, "dyn* ") - } ast::TraitObjectSyntax::None => (shape, ""), }; let mut res = bounds.rewrite_result(context, shape)?; @@ -1003,7 +997,7 @@ impl Rewrite for ast::Ty { }) } } - ast::TyKind::BareFn(ref bare_fn) => rewrite_bare_fn(bare_fn, self.span, context, shape), + ast::TyKind::FnPtr(ref fn_ptr) => rewrite_fn_ptr(fn_ptr, self.span, context, shape), ast::TyKind::Never => Ok(String::from("!")), ast::TyKind::MacCall(ref mac) => { rewrite_macro(mac, context, shape, MacroPosition::Expression) @@ -1026,13 +1020,6 @@ impl Rewrite for ast::Ty { } ast::TyKind::CVarArgs => Ok("...".to_owned()), ast::TyKind::Dummy | ast::TyKind::Err(_) => Ok(context.snippet(self.span).to_owned()), - ast::TyKind::Typeof(ref anon_const) => rewrite_call( - context, - "typeof", - &[anon_const.value.clone()], - self.span, - shape, - ), ast::TyKind::Pat(ref ty, ref pat) => { let ty = ty.rewrite_result(context, shape)?; let pat = pat.rewrite_result(context, shape)?; @@ -1078,13 +1065,26 @@ impl Rewrite for ast::TyPat { ast::TyPatKind::Range(ref lhs, ref rhs, ref end_kind) => { rewrite_range_pat(context, shape, lhs, rhs, end_kind, self.span) } - ast::TyPatKind::Err(_) => Err(RewriteError::Unknown), + ast::TyPatKind::Or(ref variants) => { + let mut first = true; + let mut s = String::new(); + for variant in variants { + if first { + first = false + } else { + s.push_str(" | "); + } + s.push_str(&variant.rewrite_result(context, shape)?); + } + Ok(s) + } + ast::TyPatKind::NotNull | ast::TyPatKind::Err(_) => Err(RewriteError::Unknown), } } } -fn rewrite_bare_fn( - bare_fn: &ast::BareFnTy, +fn rewrite_fn_ptr( + fn_ptr: &ast::FnPtrTy, span: Span, context: &RewriteContext<'_>, shape: Shape, @@ -1093,7 +1093,7 @@ fn rewrite_bare_fn( let mut result = String::with_capacity(128); - if let Some(ref lifetime_str) = rewrite_bound_params(context, shape, &bare_fn.generic_params) { + if let Some(ref lifetime_str) = rewrite_bound_params(context, shape, &fn_ptr.generic_params) { result.push_str("for<"); // 6 = "for<> ".len(), 4 = "for<". // This doesn't work out so nicely for multiline situation with lots of @@ -1102,10 +1102,10 @@ fn rewrite_bare_fn( result.push_str("> "); } - result.push_str(crate::utils::format_safety(bare_fn.safety)); + result.push_str(crate::utils::format_safety(fn_ptr.safety)); result.push_str(&format_extern( - bare_fn.ext, + fn_ptr.ext, context.config.force_explicit_abi(), )); @@ -1120,9 +1120,9 @@ fn rewrite_bare_fn( }; let rewrite = format_function_type( - bare_fn.decl.inputs.iter(), - &bare_fn.decl.output, - bare_fn.decl.c_variadic(), + fn_ptr.decl.inputs.iter(), + &fn_ptr.decl.output, + fn_ptr.decl.c_variadic(), span, context, func_ty_shape, @@ -1315,7 +1315,7 @@ fn join_bounds_inner( } } -pub(crate) fn opaque_ty(ty: &Option>) -> Option<&ast::GenericBounds> { +pub(crate) fn opaque_ty(ty: &Option>) -> Option<&ast::GenericBounds> { ty.as_ref().and_then(|t| match &t.kind { ast::TyKind::ImplTrait(_, bounds) => Some(bounds), _ => None, diff --git a/src/utils.rs b/src/utils.rs index fcd475b1784..3a2975024a3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,10 +1,10 @@ use std::borrow::Cow; +use rustc_ast::YieldKind; use rustc_ast::ast::{ self, Attribute, MetaItem, MetaItemInner, MetaItemKind, NodeId, Path, Visibility, VisibilityKind, }; -use rustc_ast::{YieldKind, ptr}; use rustc_ast_pretty::pprust; use rustc_span::{BytePos, LocalExpnId, Span, Symbol, SyntaxContext, sym, symbol}; use unicode_width::UnicodeWidthStr; @@ -132,6 +132,19 @@ pub(crate) fn format_mutability(mutability: ast::Mutability) -> &'static str { } } +#[inline] +pub(crate) fn format_pinnedness_and_mutability( + pinnedness: ast::Pinnedness, + mutability: ast::Mutability, +) -> (&'static str, &'static str) { + match (pinnedness, mutability) { + (ast::Pinnedness::Pinned, ast::Mutability::Mut) => ("pin ", "mut "), + (ast::Pinnedness::Pinned, ast::Mutability::Not) => ("pin ", "const "), + (ast::Pinnedness::Not, ast::Mutability::Mut) => ("", "mut "), + (ast::Pinnedness::Not, ast::Mutability::Not) => ("", ""), + } +} + #[inline] pub(crate) fn format_extern(ext: ast::Extern, explicit_abi: bool) -> Cow<'static, str> { match ext { @@ -149,8 +162,8 @@ pub(crate) fn format_extern(ext: ast::Extern, explicit_abi: bool) -> Cow<'static } #[inline] -// Transform `Vec>` into `Vec<&T>` -pub(crate) fn ptr_vec_to_ref_vec(vec: &[ptr::P]) -> Vec<&T> { +// Transform `Vec>` into `Vec<&T>` +pub(crate) fn ptr_vec_to_ref_vec(vec: &[Box]) -> Vec<&T> { vec.iter().map(|x| &**x).collect::>() } diff --git a/src/visitor.rs b/src/visitor.rs index d7b1178a4e0..e656a662e1c 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -492,20 +492,20 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { let rw = self.with_context(|ctx| format_impl(ctx, item, iimpl, block_indent)); self.push_rewrite(item.span, rw.ok()); } - ast::ItemKind::Trait(ref trait_kind) => { + ast::ItemKind::Trait(..) => { let block_indent = self.block_indent; - let rw = - self.with_context(|ctx| format_trait(ctx, item, trait_kind, block_indent)); + let rw = self.with_context(|ctx| format_trait(ctx, item, block_indent)); self.push_rewrite(item.span, rw.ok()); } - ast::ItemKind::TraitAlias(ident, ref generics, ref generic_bounds) => { + ast::ItemKind::TraitAlias(ref ta) => { let shape = Shape::indented(self.block_indent, self.config); let rw = format_trait_alias( &self.get_context(), - ident, + ta.ident, item, - generics, - generic_bounds, + ta.constness, + &ta.generics, + &ta.bounds, shape, ); self.push_rewrite(item.span, rw.ok()); @@ -522,7 +522,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { ast::ItemKind::Struct(..) | ast::ItemKind::Union(..) => { self.visit_struct(&StructParts::from_item(item)); } - ast::ItemKind::Enum(ident, ref def, ref generics) => { + ast::ItemKind::Enum(ident, ref generics, ref def) => { self.format_missing_with_indent(source!(self, item.span).lo()); self.visit_enum(ident, &item.vis, def, generics, item.span); self.last_pos = source!(self, item.span).hi(); @@ -875,7 +875,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { !is_skip_attr(segments) } - fn walk_mod_items(&mut self, items: &[rustc_ast::ptr::P]) { + fn walk_mod_items(&mut self, items: &[Box]) { self.visit_items_with_reordering(&ptr_vec_to_ref_vec(items)); } @@ -943,7 +943,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { let ident_str = rewrite_ident(&self.get_context(), ident).to_owned(); self.push_str(&ident_str); - if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans, _) = mod_kind { + if let ast::ModKind::Loaded(ref items, ast::Inline::Yes, ref spans) = mod_kind { let ast::ModSpans { inner_span, inject_use_span: _, diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs index 8f6c31ba51d..7070d56ec44 100644 --- a/tests/rustfmt/main.rs +++ b/tests/rustfmt/main.rs @@ -181,10 +181,11 @@ fn dont_emit_ICE() { "tests/target/issue-6105.rs", ]; + let panic_re = regex::Regex::new("thread.*panicked").unwrap(); for file in files { let args = [file]; let (_stdout, stderr) = rustfmt(&args); - assert!(!stderr.contains("thread 'main' panicked")); + assert!(!panic_re.is_match(&stderr)); } } diff --git a/tests/source/frontmatter_compact.rs b/tests/source/frontmatter_compact.rs new file mode 100644 index 00000000000..21d4c6f4b61 --- /dev/null +++ b/tests/source/frontmatter_compact.rs @@ -0,0 +1,8 @@ +#!/usr/bin/env cargo +---identifier +[dependencies] +regex = "1" +--- +#![feature(frontmatter)] + +fn main() {} diff --git a/tests/source/frontmatter_escaped.rs b/tests/source/frontmatter_escaped.rs new file mode 100644 index 00000000000..0d026377566 --- /dev/null +++ b/tests/source/frontmatter_escaped.rs @@ -0,0 +1,13 @@ +#!/usr/bin/env cargo +------------ +package.description = """ +Header +----- + +Body +""" +------------ + +#![feature(frontmatter)] + +fn main() {} diff --git a/tests/source/frontmatter_spaced.rs b/tests/source/frontmatter_spaced.rs new file mode 100644 index 00000000000..ee0bb81705c --- /dev/null +++ b/tests/source/frontmatter_spaced.rs @@ -0,0 +1,16 @@ +#!/usr/bin/env cargo + + +--- identifier +[dependencies] +regex = "1" + +--- + + + + + +#![feature(frontmatter)] + +fn main() {} diff --git a/tests/source/issue-3278/style_edition_2015.rs b/tests/source/issue-3278/version_one.rs similarity index 100% rename from tests/source/issue-3278/style_edition_2015.rs rename to tests/source/issue-3278/version_one.rs diff --git a/tests/source/issue-3278/style_edition_2024.rs b/tests/source/issue-3278/version_two.rs similarity index 100% rename from tests/source/issue-3278/style_edition_2024.rs rename to tests/source/issue-3278/version_two.rs diff --git a/tests/source/issue-6202/long_pat.rs b/tests/source/issue-6202/long_pat.rs index a7f47f32cb2..4444a4a78cb 100644 --- a/tests/source/issue-6202/long_pat.rs +++ b/tests/source/issue-6202/long_pat.rs @@ -1,6 +1,7 @@ -// max_width = 120 -// error_on_line_overflow = true -// style_edition = "2027" +// rustfmt-max_width: 120 +// rustfmt-error_on_line_overflow: true +// rustfmt-style_edition: 2027 +// rustfmt-edition: 2024 impl EarlyLintPass for NeedlessContinue { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { @@ -11,4 +12,4 @@ impl EarlyLintPass for NeedlessContinue { check_final_block_stmt(cx, body, label, expr.span.ctxt()); } } -} \ No newline at end of file +} diff --git a/tests/source/let_chains.rs b/tests/source/let_chains.rs index 0c4d8aa85ea..fc2a9310569 100644 --- a/tests/source/let_chains.rs +++ b/tests/source/let_chains.rs @@ -1,3 +1,5 @@ +// rustfmt-edition: 2024 + fn main() { if let x = x && x {} diff --git a/tests/source/long-fn-1/style_edition_2027.rs b/tests/source/long-fn-1/style_edition_2027.rs deleted file mode 100644 index ded5a38d179..00000000000 --- a/tests/source/long-fn-1/style_edition_2027.rs +++ /dev/null @@ -1,21 +0,0 @@ -// rustfmt-style_edition: 2027 -// Tests that a function which is almost short enough, but not quite, gets -// formatted correctly. - -impl Foo { - fn some_input(&mut self, input: Input, input_path: Option, ) -> (Input, Option) {} - - fn some_inpu(&mut self, input: Input, input_path: Option) -> (Input, Option) {} -} - -// #1843 -#[allow(non_snake_case)] -pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash() -> bool { - false -} - -// #3009 -impl Something { - fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine( -) -> Result< (), String > {} -} diff --git a/tests/source/long-fn-1/style_edition_2015.rs b/tests/source/long-fn-1/version_one.rs similarity index 100% rename from tests/source/long-fn-1/style_edition_2015.rs rename to tests/source/long-fn-1/version_one.rs diff --git a/tests/source/long-fn-1/style_edition_2024.rs b/tests/source/long-fn-1/version_two.rs similarity index 100% rename from tests/source/long-fn-1/style_edition_2024.rs rename to tests/source/long-fn-1/version_two.rs diff --git a/tests/source/negative-impl.rs b/tests/source/negative-impl.rs index da242d4f3dc..e8f9508e656 100644 --- a/tests/source/negative-impl.rs +++ b/tests/source/negative-impl.rs @@ -1,7 +1,3 @@ impl ! Display for JoinHandle { } -impl ! Box < JoinHandle > { } - impl ! std :: fmt :: Display for JoinHandle < T : std :: future :: Future + std :: marker :: Send + std :: marker :: Sync > { } - -impl ! JoinHandle < T : std :: future :: Future < Output > + std :: marker :: Send + std :: marker :: Sync + 'static > + 'static { } diff --git a/tests/source/pin_sugar.rs b/tests/source/pin_sugar.rs index 370dfbc196a..5f52e244926 100644 --- a/tests/source/pin_sugar.rs +++ b/tests/source/pin_sugar.rs @@ -18,3 +18,32 @@ impl Foo { mut self) {} fn i(&pin mut self) {} } + +fn borrows() { + let mut foo = 0_i32; + let x: Pin<&mut _> = & pin + mut foo; + + let x: Pin<&_> = & + pin const + foo; +} + +fn patterns<'a>( + &pin mut x: &pin + mut + i32, + & + pin + const + y: & + 'a pin + const + i32, + ref pin mut z: i32, + mut + ref + pin + const + w: i32, +) {} diff --git a/tests/source/reorder_modules/disabled_style_edition_2027.rs b/tests/source/reorder_modules/disabled_style_edition_2027.rs new file mode 100644 index 00000000000..f5f0cb6357f --- /dev/null +++ b/tests/source/reorder_modules/disabled_style_edition_2027.rs @@ -0,0 +1,47 @@ +// rustfmt-style_edition: 2027 +// rustfmt-reorder_modules: false + +mod x86; +mod v0s; +mod v001; +mod x87; +mod zyxw; +mod A2; +mod ZYXW; +mod w5s009t; +mod u8; +mod x86_128; +mod _ZYXW; +mod ZY_XW; +mod a1; +mod v01; +mod v0u; +mod x86_64; +mod ua; +mod x86_32; +mod v9; +mod v010; +mod u_zzz; +mod v0; +mod v00; +mod v009; +mod w005s09t; +mod u32; +mod v1; +mod v00t; +mod v09; +mod u256; +mod ZY_XW; +mod _abcd; +mod ABCD; +mod Z_YXW; +mod u64; +mod abcd; +mod ZYXW_; +mod u16; +mod uz; +mod v10; +mod x64; +mod u128; +mod usize; +mod v000; diff --git a/tests/source/reorder_modules/enabled_style_edition_2027.rs b/tests/source/reorder_modules/enabled_style_edition_2027.rs new file mode 100644 index 00000000000..46f6abe9312 --- /dev/null +++ b/tests/source/reorder_modules/enabled_style_edition_2027.rs @@ -0,0 +1,47 @@ +// rustfmt-style_edition: 2027 +// rustfmt-reorder_modules: true + +mod x86; +mod v0s; +mod v001; +mod x87; +mod zyxw; +mod A2; +mod ZYXW; +mod w5s009t; +mod u8; +mod x86_128; +mod _ZYXW; +mod ZY_XW; +mod a1; +mod v01; +mod v0u; +mod x86_64; +mod ua; +mod x86_32; +mod v9; +mod v010; +mod u_zzz; +mod v0; +mod v00; +mod v009; +mod w005s09t; +mod u32; +mod v1; +mod v00t; +mod v09; +mod u256; +mod ZY_XW; +mod _abcd; +mod ABCD; +mod Z_YXW; +mod u64; +mod abcd; +mod ZYXW_; +mod u16; +mod uz; +mod v10; +mod x64; +mod u128; +mod usize; +mod v000; diff --git a/tests/source/trait.rs b/tests/source/trait.rs index b6db9e1590d..1970646f777 100644 --- a/tests/source/trait.rs +++ b/tests/source/trait.rs @@ -181,3 +181,5 @@ trait Visible { pub fn f(); pub fn g() {} } + +const trait Foomp = Hash; \ No newline at end of file diff --git a/tests/source/type.rs b/tests/source/type.rs index 7a232f85198..09ec22cf8d1 100644 --- a/tests/source/type.rs +++ b/tests/source/type.rs @@ -142,25 +142,19 @@ type MyFn = fn(a: SomeLongComplexType, b: SomeOtherLongComplexType,) -> Box() -> i32 { ::CONST } +const fn not_quite_const() -> i32 { ::CONST } -impl ~ const T {} +impl const T for U {} -fn apit(_: impl ~ const T) {} +fn apit(_: impl [ const ] T) {} -fn rpit() -> impl ~ const T { S } +fn rpit() -> impl [ const] T { S } pub struct Foo(T); -impl Foo { +impl Foo { fn new(t: T) -> Self { Self(t) } } - -// #4357 -type T = typeof( -1); -impl T for .. { -} diff --git a/tests/target/const_trait.rs b/tests/target/const_trait.rs new file mode 100644 index 00000000000..c4c88b17fc5 --- /dev/null +++ b/tests/target/const_trait.rs @@ -0,0 +1,5 @@ +#![feature(trait_alias, const_trait_impl)] + +const trait Bar {} + +const trait Foo = Bar; diff --git a/tests/target/frontmatter_compact.rs b/tests/target/frontmatter_compact.rs new file mode 100644 index 00000000000..21d4c6f4b61 --- /dev/null +++ b/tests/target/frontmatter_compact.rs @@ -0,0 +1,8 @@ +#!/usr/bin/env cargo +---identifier +[dependencies] +regex = "1" +--- +#![feature(frontmatter)] + +fn main() {} diff --git a/tests/target/frontmatter_escaped.rs b/tests/target/frontmatter_escaped.rs new file mode 100644 index 00000000000..0d026377566 --- /dev/null +++ b/tests/target/frontmatter_escaped.rs @@ -0,0 +1,13 @@ +#!/usr/bin/env cargo +------------ +package.description = """ +Header +----- + +Body +""" +------------ + +#![feature(frontmatter)] + +fn main() {} diff --git a/tests/target/frontmatter_spaced.rs b/tests/target/frontmatter_spaced.rs new file mode 100644 index 00000000000..ee0bb81705c --- /dev/null +++ b/tests/target/frontmatter_spaced.rs @@ -0,0 +1,16 @@ +#!/usr/bin/env cargo + + +--- identifier +[dependencies] +regex = "1" + +--- + + + + + +#![feature(frontmatter)] + +fn main() {} diff --git a/tests/target/issue-3278/style_edition_2024.rs b/tests/target/issue-3278/style_edition_2024.rs deleted file mode 100644 index 676db3b20f8..00000000000 --- a/tests/target/issue-3278/style_edition_2024.rs +++ /dev/null @@ -1,8 +0,0 @@ -// rustfmt-style_edition: 2024 - -pub fn parse_conditional<'a, I: 'a>( -) -> impl Parser + 'a -where - I: Stream, -{ -} diff --git a/tests/target/issue-3278/style_edition_2027.rs b/tests/target/issue-3278/style_edition_2027.rs deleted file mode 100644 index f33dffeb7f5..00000000000 --- a/tests/target/issue-3278/style_edition_2027.rs +++ /dev/null @@ -1,8 +0,0 @@ -// rustfmt-style_edition: 2027 - -pub fn parse_conditional<'a, I: 'a>() --> impl Parser + 'a -where - I: Stream, -{ -} diff --git a/tests/target/issue-3278/style_edition_2015.rs b/tests/target/issue-3278/version_one.rs similarity index 100% rename from tests/target/issue-3278/style_edition_2015.rs rename to tests/target/issue-3278/version_one.rs diff --git a/tests/source/issue-3278/style_edition_2027.rs b/tests/target/issue-3278/version_two.rs similarity index 82% rename from tests/source/issue-3278/style_edition_2027.rs rename to tests/target/issue-3278/version_two.rs index f33dffeb7f5..eb605e509f9 100644 --- a/tests/source/issue-3278/style_edition_2027.rs +++ b/tests/target/issue-3278/version_two.rs @@ -1,4 +1,4 @@ -// rustfmt-style_edition: 2027 +// rustfmt-style_edition: 2024 pub fn parse_conditional<'a, I: 'a>() -> impl Parser + 'a diff --git a/tests/target/issue-6202/long_pat.rs b/tests/target/issue-6202/long_pat.rs index fef118a9da2..1d2282626a2 100644 --- a/tests/target/issue-6202/long_pat.rs +++ b/tests/target/issue-6202/long_pat.rs @@ -1,6 +1,7 @@ -// max_width = 120 -// error_on_line_overflow = true -// style_edition = "2027" +// rustfmt-max_width: 120 +// rustfmt-error_on_line_overflow: true +// rustfmt-style_edition: 2027 +// rustfmt-edition: 2024 impl EarlyLintPass for NeedlessContinue { fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) { diff --git a/tests/target/issue_5542.rs b/tests/target/issue_5542.rs deleted file mode 100644 index 730bb7b681a..00000000000 --- a/tests/target/issue_5542.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use core::fmt::Debug; - -fn main() { - let i = 42; - let dyn_i = i as dyn* Debug; - dbg!(dyn_i); -} diff --git a/tests/target/let_chains.rs b/tests/target/let_chains.rs index 204937b4cac..4fd6048d914 100644 --- a/tests/target/let_chains.rs +++ b/tests/target/let_chains.rs @@ -1,3 +1,5 @@ +// rustfmt-edition: 2024 + fn main() { if let x = x && x diff --git a/tests/target/long-fn-1/style_edition_2024.rs b/tests/target/long-fn-1/style_edition_2024.rs deleted file mode 100644 index f5edca5ee7d..00000000000 --- a/tests/target/long-fn-1/style_edition_2024.rs +++ /dev/null @@ -1,29 +0,0 @@ -// rustfmt-style_edition: 2024 -// Tests that a function which is almost short enough, but not quite, gets -// formatted correctly. - -impl Foo { - fn some_input( - &mut self, - input: Input, - input_path: Option, - ) -> (Input, Option) { - } - - fn some_inpu(&mut self, input: Input, input_path: Option) -> (Input, Option) { - } -} - -// #1843 -#[allow(non_snake_case)] -pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash( -) -> bool { - false -} - -// #3009 -impl Something { - fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine( - ) -> Result<(), String> { - } -} diff --git a/tests/target/long-fn-1/style_edition_2015.rs b/tests/target/long-fn-1/version_one.rs similarity index 100% rename from tests/target/long-fn-1/style_edition_2015.rs rename to tests/target/long-fn-1/version_one.rs diff --git a/tests/target/long-fn-1/style_edition_2027.rs b/tests/target/long-fn-1/version_two.rs similarity index 95% rename from tests/target/long-fn-1/style_edition_2027.rs rename to tests/target/long-fn-1/version_two.rs index 87361f0b96b..f6007398bcc 100644 --- a/tests/target/long-fn-1/style_edition_2027.rs +++ b/tests/target/long-fn-1/version_two.rs @@ -1,4 +1,4 @@ -// rustfmt-style_edition: 2027 +// rustfmt-style_edition: 2024 // Tests that a function which is almost short enough, but not quite, gets // formatted correctly. diff --git a/tests/target/negative-impl.rs b/tests/target/negative-impl.rs index 16ce7e26a99..bb53048dbc6 100644 --- a/tests/target/negative-impl.rs +++ b/tests/target/negative-impl.rs @@ -1,14 +1,6 @@ impl !Display for JoinHandle {} -impl !Box {} - impl !std::fmt::Display for JoinHandle { } - -impl - !JoinHandle + std::marker::Send + std::marker::Sync + 'static> - + 'static -{ -} diff --git a/tests/target/pin_sugar.rs b/tests/target/pin_sugar.rs index 7d04efb1b32..f366ab4da95 100644 --- a/tests/target/pin_sugar.rs +++ b/tests/target/pin_sugar.rs @@ -16,3 +16,18 @@ impl Foo { fn h<'a>(&'a pin mut self) {} fn i(&pin mut self) {} } + +fn borrows() { + let mut foo = 0_i32; + let x: Pin<&mut _> = &pin mut foo; + + let x: Pin<&_> = &pin const foo; +} + +fn patterns<'a>( + &pin mut x: &pin mut i32, + &pin const y: &'a pin const i32, + ref pin mut z: i32, + mut ref pin const w: i32, +) { +} diff --git a/tests/target/reorder_modules/disabled_style_edition_2027.rs b/tests/target/reorder_modules/disabled_style_edition_2027.rs new file mode 100644 index 00000000000..f5f0cb6357f --- /dev/null +++ b/tests/target/reorder_modules/disabled_style_edition_2027.rs @@ -0,0 +1,47 @@ +// rustfmt-style_edition: 2027 +// rustfmt-reorder_modules: false + +mod x86; +mod v0s; +mod v001; +mod x87; +mod zyxw; +mod A2; +mod ZYXW; +mod w5s009t; +mod u8; +mod x86_128; +mod _ZYXW; +mod ZY_XW; +mod a1; +mod v01; +mod v0u; +mod x86_64; +mod ua; +mod x86_32; +mod v9; +mod v010; +mod u_zzz; +mod v0; +mod v00; +mod v009; +mod w005s09t; +mod u32; +mod v1; +mod v00t; +mod v09; +mod u256; +mod ZY_XW; +mod _abcd; +mod ABCD; +mod Z_YXW; +mod u64; +mod abcd; +mod ZYXW_; +mod u16; +mod uz; +mod v10; +mod x64; +mod u128; +mod usize; +mod v000; diff --git a/tests/target/reorder_modules/enabled_style_edition_2024.rs b/tests/target/reorder_modules/enabled_style_edition_2024.rs index ad78762aa01..addc555aa0e 100644 --- a/tests/target/reorder_modules/enabled_style_edition_2024.rs +++ b/tests/target/reorder_modules/enabled_style_edition_2024.rs @@ -1,47 +1,47 @@ // rustfmt-style_edition: 2024 // rustfmt-reorder_modules: true -mod _ZYXW; -mod _abcd; mod A2; mod ABCD; -mod Z_YXW; -mod ZY_XW; -mod ZY_XW; mod ZYXW; mod ZYXW_; +mod ZY_XW; +mod ZY_XW; +mod Z_YXW; +mod _ZYXW; +mod _abcd; mod a1; mod abcd; -mod u_zzz; -mod u8; +mod u128; mod u16; +mod u256; mod u32; mod u64; -mod u128; -mod u256; +mod u8; +mod u_zzz; mod ua; mod usize; mod uz; -mod v000; -mod v00; mod v0; -mod v0s; -mod v00t; -mod v0u; +mod v00; +mod v000; mod v001; -mod v01; -mod v1; mod v009; -mod v09; -mod v9; +mod v00t; +mod v01; mod v010; +mod v09; +mod v0s; +mod v0u; +mod v1; mod v10; +mod v9; mod w005s09t; mod w5s009t; mod x64; mod x86; +mod x86_128; mod x86_32; mod x86_64; -mod x86_128; mod x87; mod zyxw; diff --git a/tests/target/reorder_modules/enabled_style_edition_2027.rs b/tests/target/reorder_modules/enabled_style_edition_2027.rs new file mode 100644 index 00000000000..44acabd75f5 --- /dev/null +++ b/tests/target/reorder_modules/enabled_style_edition_2027.rs @@ -0,0 +1,47 @@ +// rustfmt-style_edition: 2027 +// rustfmt-reorder_modules: true + +mod _ZYXW; +mod _abcd; +mod A2; +mod ABCD; +mod Z_YXW; +mod ZY_XW; +mod ZY_XW; +mod ZYXW; +mod ZYXW_; +mod a1; +mod abcd; +mod u_zzz; +mod u8; +mod u16; +mod u32; +mod u64; +mod u128; +mod u256; +mod ua; +mod usize; +mod uz; +mod v000; +mod v00; +mod v0; +mod v0s; +mod v00t; +mod v0u; +mod v001; +mod v01; +mod v1; +mod v009; +mod v09; +mod v9; +mod v010; +mod v10; +mod w005s09t; +mod w5s009t; +mod x64; +mod x86; +mod x86_32; +mod x86_64; +mod x86_128; +mod x87; +mod zyxw; diff --git a/tests/target/trait.rs b/tests/target/trait.rs index 7f067991b26..7a65b13d629 100644 --- a/tests/target/trait.rs +++ b/tests/target/trait.rs @@ -218,3 +218,5 @@ trait Visible { pub fn f(); pub fn g() {} } + +const trait Foomp = Hash; diff --git a/tests/target/type.rs b/tests/target/type.rs index 325adb52f3f..623192b72b8 100644 --- a/tests/target/type.rs +++ b/tests/target/type.rs @@ -147,27 +147,23 @@ type MyFn = fn( // Const bound -trait T: ~const Super {} +trait T: [const] Super {} -const fn not_quite_const() -> i32 { +const fn not_quite_const() -> i32 { ::CONST } -impl ~const T {} +impl const T for U {} -fn apit(_: impl ~const T) {} +fn apit(_: impl [const] T) {} -fn rpit() -> impl ~const T { +fn rpit() -> impl [const] T { S } pub struct Foo(T); -impl Foo { +impl Foo { fn new(t: T) -> Self { Self(t) } } - -// #4357 -type T = typeof(1); -impl T for .. {}