diff --git a/Cargo.lock b/Cargo.lock index 5a7ba9e7379..042eefb7aa3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,7 +24,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.8", + "winapi", ] [[package]] @@ -52,7 +52,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" dependencies = [ "libc", - "winapi 0.3.8", + "winapi", ] [[package]] @@ -275,7 +275,7 @@ dependencies = [ "cfg-if", "libc", "redox_users", - "winapi 0.3.8", + "winapi", ] [[package]] @@ -444,16 +444,6 @@ dependencies = [ "log", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -490,12 +480,34 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" +[[package]] +name = "measureme" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fef709d3257013bba7cff14fc504e07e80631d3fe0f6d38ce63b8f6510ccb932" +dependencies = [ + "byteorder", + "memmap", + "parking_lot", + "rustc-hash", +] + [[package]] name = "memchr" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "memoffset" version = "0.5.3" @@ -546,8 +558,8 @@ dependencies = [ "libc", "redox_syscall", "rustc_version", - "smallvec", - "winapi 0.3.8", + "smallvec 0.6.13", + "winapi", ] [[package]] @@ -626,7 +638,7 @@ dependencies = [ "libc", "rand_core 0.4.2", "rdrand", - "winapi 0.3.8", + "winapi", ] [[package]] @@ -687,26 +699,57 @@ dependencies = [ [[package]] name = "rustc-ap-arena" -version = "610.0.0" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7475f4c707269b56eb7144c53591e3cd6369a5aa1d66434829ea11df96d5e7e3" +checksum = "ea82fa3d9a8add7422228ca1a2cbba0784fa8861f56148ff64da08b3c7921b03" dependencies = [ "rustc-ap-rustc_data_structures", - "smallvec", + "smallvec 1.1.0", ] [[package]] name = "rustc-ap-graphviz" -version = "610.0.0" +version = "642.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "638d0b2b3bcf99824e0cb5a25dbc547b61dc20942e11daf6a97e981918aa18e5" + +[[package]] +name = "rustc-ap-rustc_ast_pretty" +version = "642.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38bab04dd676dee6d2f9670506a18c31bfce38bf7f8420aa83eb1140ecde049" +dependencies = [ + "log", + "rustc-ap-rustc_data_structures", + "rustc-ap-rustc_span", + "rustc-ap-syntax", +] + +[[package]] +name = "rustc-ap-rustc_attr" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e59a55520f140a70a3e0fad80a36e807caa85e9d7016167b91a5b521ea929be" +checksum = "10b843ba8b1ed43739133047673b9f6a54d3b3b4d328d69c6ea89ff971395f35" +dependencies = [ + "rustc-ap-rustc_ast_pretty", + "rustc-ap-rustc_data_structures", + "rustc-ap-rustc_errors", + "rustc-ap-rustc_feature", + "rustc-ap-rustc_macros", + "rustc-ap-rustc_session", + "rustc-ap-rustc_span", + "rustc-ap-serialize", + "rustc-ap-syntax", + "smallvec 1.1.0", +] [[package]] name = "rustc-ap-rustc_data_structures" -version = "610.0.0" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6420857d5a088f680ec1ba736ffba4ee9c1964b0d397e6318f38d461f4f7d5cb" +checksum = "dc3d1c6d0a80ab0c1df76405377cec0f3d5423fb5b0953a8eac70a2ad6c44df2" dependencies = [ + "bitflags", "cfg-if", "crossbeam-utils 0.6.6", "ena", @@ -714,6 +757,7 @@ dependencies = [ "jobserver", "lazy_static", "log", + "measureme", "parking_lot", "rustc-ap-graphviz", "rustc-ap-rustc_index", @@ -721,51 +765,70 @@ dependencies = [ "rustc-hash", "rustc-rayon", "rustc-rayon-core", - "smallvec", + "smallvec 1.1.0", "stable_deref_trait", + "winapi", ] [[package]] name = "rustc-ap-rustc_errors" -version = "610.0.0" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8abfca0960131262254a91d02ff4903526a261ede730d7a2c75b4234c867cdc0" +checksum = "4909a1eca29331332257230f29120a8ff68c9e37d868c564fcd599e430cf8914" dependencies = [ "annotate-snippets", "atty", "log", "rustc-ap-rustc_data_structures", + "rustc-ap-rustc_span", "rustc-ap-serialize", - "rustc-ap-syntax_pos", - "term_size", "termcolor", + "termize", "unicode-width", + "winapi", ] +[[package]] +name = "rustc-ap-rustc_feature" +version = "642.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63ab887a181d795cf5fd3edadf367760deafb90aefb844f168ab5255266e3478" +dependencies = [ + "lazy_static", + "rustc-ap-rustc_data_structures", + "rustc-ap-rustc_span", +] + +[[package]] +name = "rustc-ap-rustc_fs_util" +version = "642.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70814116df3c5fbec8f06f6a1d013ca481f620fd22a9475754e9bf3ee9ba70d8" + [[package]] name = "rustc-ap-rustc_index" -version = "610.0.0" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a395509dcb90a92c1479c085639594624e06b4ab3fc7c1b795b46a61f2d4f65" +checksum = "ac1bf1d3cf3d119d41353d6fd229ef7272d5097bc0924de021c0294bf86d48bf" dependencies = [ "rustc-ap-serialize", - "smallvec", + "smallvec 1.1.0", ] [[package]] name = "rustc-ap-rustc_lexer" -version = "610.0.0" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64eac8a0e6efb8f55292aa24be0208c7c0538236c613e79952fd1fa3d54bcf8e" +checksum = "4cda21a32cebdc11ec4f5393aa2fcde5ed1b2f673a8571e5a4dcdf07e4ae9cac" dependencies = [ "unicode-xid", ] [[package]] name = "rustc-ap-rustc_macros" -version = "610.0.0" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f99795e8be4877e9e05d59f201e1740c1cf673364655def5848606d9e25b75af" +checksum = "75c47b48ea51910ecfd853c9248a9bf4c767bc823449ab6a1d864dff65fbae16" dependencies = [ "itertools", "proc-macro2", @@ -775,63 +838,102 @@ dependencies = [ ] [[package]] -name = "rustc-ap-rustc_target" -version = "610.0.0" +name = "rustc-ap-rustc_parse" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f22e21fdd8e1c0030f507158fa79b9f1e080e6241aba994d0f97c14a0a07a826" +checksum = "abd88e89cd5b5d28dcd3a347a3d534c08627d9455570dc1a2d402cb8437b9d30" dependencies = [ "bitflags", "log", + "rustc-ap-rustc_ast_pretty", + "rustc-ap-rustc_attr", + "rustc-ap-rustc_data_structures", + "rustc-ap-rustc_errors", + "rustc-ap-rustc_feature", + "rustc-ap-rustc_lexer", + "rustc-ap-rustc_session", + "rustc-ap-rustc_span", + "rustc-ap-syntax", + "smallvec 1.1.0", + "unicode-normalization", +] + +[[package]] +name = "rustc-ap-rustc_session" +version = "642.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8487b4575fbb2d1fc6f1cd61225efd108a4d36817e6fb9b643d57fcae9cb12" +dependencies = [ + "log", + "num_cpus", "rustc-ap-rustc_data_structures", + "rustc-ap-rustc_errors", + "rustc-ap-rustc_feature", + "rustc-ap-rustc_fs_util", "rustc-ap-rustc_index", + "rustc-ap-rustc_span", + "rustc-ap-rustc_target", "rustc-ap-serialize", - "rustc-ap-syntax_pos", + "rustc-ap-syntax", ] [[package]] -name = "rustc-ap-serialize" -version = "610.0.0" +name = "rustc-ap-rustc_span" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1cd6ef5135408d62559866e79986ca261f4c1333253d500e5e66fe66d1432e" +checksum = "f69746c0d4c21bf20a5bb2bd247261a1aa8631f04202d7303352942dde70d987" dependencies = [ - "indexmap", - "smallvec", + "cfg-if", + "log", + "rustc-ap-arena", + "rustc-ap-rustc_data_structures", + "rustc-ap-rustc_index", + "rustc-ap-rustc_macros", + "rustc-ap-serialize", + "scoped-tls", + "unicode-width", ] [[package]] -name = "rustc-ap-syntax" -version = "610.0.0" +name = "rustc-ap-rustc_target" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61fc1c901d2cbd24cae95d7bc5a58aa7661ec3dc5320c78c32830a52a685c33c" +checksum = "8bbc6ae09b5d42ec66edd520e8412e0615c53a7c93607fe33dc4abab60ba7c8b" dependencies = [ "bitflags", - "lazy_static", "log", "rustc-ap-rustc_data_structures", - "rustc-ap-rustc_errors", "rustc-ap-rustc_index", - "rustc-ap-rustc_lexer", - "rustc-ap-rustc_target", + "rustc-ap-rustc_macros", + "rustc-ap-rustc_span", "rustc-ap-serialize", - "rustc-ap-syntax_pos", - "scoped-tls", - "smallvec", ] [[package]] -name = "rustc-ap-syntax_pos" -version = "610.0.0" +name = "rustc-ap-serialize" +version = "642.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "230534f638255853bb9f13987537e00a818435a0cc54b68d97221b6822c8f1bc" +checksum = "e13a1ead0252fc3d96da4c336a95950be6795f2b00c84a67ccadf26142f8cb41" dependencies = [ - "cfg-if", - "rustc-ap-arena", + "indexmap", + "smallvec 1.1.0", +] + +[[package]] +name = "rustc-ap-syntax" +version = "642.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1f59f48ca3a2ec16a7e82e718ed5aadf9c9e08cf63015d28b4e774767524a6a" +dependencies = [ + "log", "rustc-ap-rustc_data_structures", "rustc-ap-rustc_index", + "rustc-ap-rustc_lexer", "rustc-ap-rustc_macros", + "rustc-ap-rustc_span", "rustc-ap-serialize", "scoped-tls", - "unicode-width", + "smallvec 1.1.0", ] [[package]] @@ -923,7 +1025,7 @@ dependencies = [ "dirs", "itertools", "regex", - "rustc-ap-syntax_pos", + "rustc-ap-rustc_span", "rustfmt-config_proc_macro", "serde", "serde_json", @@ -954,10 +1056,14 @@ dependencies = [ "lazy_static", "log", "regex", + "rustc-ap-rustc_ast_pretty", "rustc-ap-rustc_data_structures", + "rustc-ap-rustc_errors", + "rustc-ap-rustc_parse", + "rustc-ap-rustc_session", + "rustc-ap-rustc_span", "rustc-ap-rustc_target", "rustc-ap-syntax", - "rustc-ap-syntax_pos", "rustfmt_configuration", "rustfmt_emitter", "term", @@ -1061,6 +1167,12 @@ dependencies = [ "maybe-uninit", ] +[[package]] +name = "smallvec" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44e59e0c9fa00817912ae6e4e6e3c4fe04455e75699d06eedc7d85917ed8e8f4" + [[package]] name = "stable_deref_trait" version = "1.1.1" @@ -1137,27 +1249,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5" dependencies = [ "dirs", - "winapi 0.3.8", + "winapi", ] [[package]] -name = "term_size" -version = "0.3.1" +name = "termcolor" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327" +checksum = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" dependencies = [ - "kernel32-sys", - "libc", - "winapi 0.2.8", + "wincolor", ] [[package]] -name = "termcolor" -version = "1.0.5" +name = "termize" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" +checksum = "1706be6b564323ce7092f5f7e6b118a14c8ef7ed0e69c8c5329c914a9f101295" dependencies = [ - "wincolor", + "libc", + "winapi", ] [[package]] @@ -1216,6 +1327,15 @@ dependencies = [ "serde", ] +[[package]] +name = "unicode-normalization" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf" +dependencies = [ + "smallvec 1.1.0", +] + [[package]] name = "unicode-segmentation" version = "1.6.0" @@ -1253,7 +1373,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e" dependencies = [ "same-file", - "winapi 0.3.8", + "winapi", "winapi-util", ] @@ -1263,12 +1383,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.8" @@ -1279,12 +1393,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1297,7 +1405,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" dependencies = [ - "winapi 0.3.8", + "winapi", ] [[package]] @@ -1312,6 +1420,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" dependencies = [ - "winapi 0.3.8", + "winapi", "winapi-util", ] diff --git a/rustfmt-core/rustfmt-config/Cargo.toml b/rustfmt-core/rustfmt-config/Cargo.toml index c65222dfd51..b4a8dc81deb 100644 --- a/rustfmt-core/rustfmt-config/Cargo.toml +++ b/rustfmt-core/rustfmt-config/Cargo.toml @@ -17,7 +17,7 @@ serde_json = "1.0" thiserror = "1.0" toml = "0.5" -[dependencies.syntax_pos] -package = "rustc-ap-syntax_pos" -version = "610.0.0" +[dependencies.rustc_span] +package = "rustc-ap-rustc_span" +version = "642.0.0" diff --git a/rustfmt-core/rustfmt-config/src/file_lines.rs b/rustfmt-core/rustfmt-config/src/file_lines.rs index 88c4443db17..2e040f06e4a 100644 --- a/rustfmt-core/rustfmt-config/src/file_lines.rs +++ b/rustfmt-core/rustfmt-config/src/file_lines.rs @@ -10,7 +10,7 @@ use serde::{ser, Deserialize, Deserializer, Serialize, Serializer}; use serde_json as json; use thiserror::Error; -use syntax_pos::{self, SourceFile}; +use rustc_span::{self, SourceFile}; /// A range of lines in a file, inclusive of both ends. pub struct LineRange { @@ -26,21 +26,21 @@ pub enum FileName { Stdin, } -impl From for FileName { - fn from(name: syntax_pos::FileName) -> FileName { +impl From for FileName { + fn from(name: rustc_span::FileName) -> FileName { match name { - syntax_pos::FileName::Real(p) => FileName::Real(p), - syntax_pos::FileName::Custom(ref f) if f == "stdin" => FileName::Stdin, + rustc_span::FileName::Real(p) => FileName::Real(p), + rustc_span::FileName::Custom(ref f) if f == "stdin" => FileName::Stdin, _ => unreachable!(), } } } -impl From<&FileName> for syntax_pos::FileName { - fn from(filename: &FileName) -> syntax_pos::FileName { +impl From<&FileName> for rustc_span::FileName { + fn from(filename: &FileName) -> rustc_span::FileName { match filename { - FileName::Real(path) => syntax_pos::FileName::Real(path.to_owned()), - FileName::Stdin => syntax_pos::FileName::Custom("stdin".to_owned()), + FileName::Real(path) => rustc_span::FileName::Real(path.to_owned()), + FileName::Stdin => rustc_span::FileName::Custom("stdin".to_owned()), } } } diff --git a/rustfmt-core/rustfmt-config/src/options.rs b/rustfmt-core/rustfmt-config/src/options.rs index c970868f482..5d8319ef5cf 100644 --- a/rustfmt-core/rustfmt-config/src/options.rs +++ b/rustfmt-core/rustfmt-config/src/options.rs @@ -374,7 +374,7 @@ impl Default for Edition { } } -impl From for syntax_pos::edition::Edition { +impl From for rustc_span::edition::Edition { fn from(edition: Edition) -> Self { match edition { Edition::Edition2015 => Self::Edition2015, diff --git a/rustfmt-core/rustfmt-lib/Cargo.toml b/rustfmt-core/rustfmt-lib/Cargo.toml index 82859bba4a3..2e292424af9 100644 --- a/rustfmt-core/rustfmt-lib/Cargo.toml +++ b/rustfmt-core/rustfmt-lib/Cargo.toml @@ -30,19 +30,35 @@ unicode-width = "0.1.5" [dev-dependencies] env_logger = "0.7" +[dependencies.rustc_ast_pretty] +package = "rustc-ap-rustc_ast_pretty" +version = "642.0.0" + +[dependencies.rustc_data_structures] +package = "rustc-ap-rustc_data_structures" +version = "642.0.0" + +[dependencies.rustc_errors] +package = "rustc-ap-rustc_errors" +version = "642.0.0" + +[dependencies.rustc_parse] +package = "rustc-ap-rustc_parse" +version = "642.0.0" + +[dependencies.rustc_session] +package = "rustc-ap-rustc_session" +version = "642.0.0" + +[dependencies.rustc_span] +package = "rustc-ap-rustc_span" +version = "642.0.0" + [dependencies.rustc_target] package = "rustc-ap-rustc_target" -version = "610.0.0" +version = "642.0.0" [dependencies.syntax] package = "rustc-ap-syntax" -version = "610.0.0" - -[dependencies.syntax_pos] -package = "rustc-ap-syntax_pos" -version = "610.0.0" - -[dependencies.rustc_data_structures] -package = "rustc-ap-rustc_data_structures" -version = "610.0.0" +version = "642.0.0" diff --git a/rustfmt-core/rustfmt-lib/src/attr.rs b/rustfmt-core/rustfmt-lib/src/attr.rs index 63a01e56603..30a6cb250ee 100644 --- a/rustfmt-core/rustfmt-lib/src/attr.rs +++ b/rustfmt-core/rustfmt-lib/src/attr.rs @@ -1,8 +1,7 @@ //! Format attributes and meta items. +use rustc_span::{BytePos, DUMMY_SP, Span, symbol::sym}; use syntax::ast; -use syntax::source_map::{BytePos, Span, DUMMY_SP}; -use syntax::symbol::sym; use self::doc_comment::DocCommentFormatter; use crate::comment::{contains_comment, rewrite_doc_comment, CommentStyle}; @@ -35,7 +34,7 @@ pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span { ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => expr.span, ast::StmtKind::Mac(ref mac) => { let (ref mac, _, _) = **mac; - mac.span + mac.span() } } } @@ -168,7 +167,7 @@ fn rewrite_initial_doc_comments( return Some((0, None)); } // Rewrite doc comments - let sugared_docs = take_while_with_pred(context, attrs, |a| a.is_sugared_doc); + let sugared_docs = take_while_with_pred(context, attrs, |a| a.is_doc_comment()); if !sugared_docs.is_empty() { let snippet = sugared_docs .iter() @@ -316,7 +315,7 @@ where impl Rewrite for ast::Attribute { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let snippet = context.snippet(self.span); - if self.is_sugared_doc { + if self.is_doc_comment() { rewrite_doc_comment(snippet, shape.comment(context.config), context.config) } else { let should_skip = self @@ -438,7 +437,7 @@ impl<'a> Rewrite for [ast::Attribute] { )?; result.push_str(&comment); if let Some(next) = attrs.get(derives.len()) { - if next.is_sugared_doc { + if next.is_doc_comment() { let snippet = context.snippet(missing_span); let (_, mlb) = has_newlines_before_after_comment(snippet); result.push_str(&mlb); @@ -471,7 +470,7 @@ impl<'a> Rewrite for [ast::Attribute] { )?; result.push_str(&comment); if let Some(next) = attrs.get(1) { - if next.is_sugared_doc { + if next.is_doc_comment() { let snippet = context.snippet(missing_span); let (_, mlb) = has_newlines_before_after_comment(snippet); result.push_str(&mlb); diff --git a/rustfmt-core/rustfmt-lib/src/chains.rs b/rustfmt-core/rustfmt-lib/src/chains.rs index ec4a4792e29..e4d65709ed6 100644 --- a/rustfmt-core/rustfmt-lib/src/chains.rs +++ b/rustfmt-core/rustfmt-lib/src/chains.rs @@ -58,7 +58,7 @@ use std::borrow::Cow; use std::cmp::min; -use syntax::source_map::{BytePos, Span}; +use rustc_span::{BytePos, Span}; use syntax::{ast, ptr}; use crate::comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar}; diff --git a/rustfmt-core/rustfmt-lib/src/closures.rs b/rustfmt-core/rustfmt-lib/src/closures.rs index 5edaaad1d35..bf54fc415d6 100644 --- a/rustfmt-core/rustfmt-lib/src/closures.rs +++ b/rustfmt-core/rustfmt-lib/src/closures.rs @@ -1,4 +1,4 @@ -use syntax::source_map::Span; +use rustc_span::Span; use syntax::{ast, ptr}; use crate::attr::get_attrs_from_stmt; @@ -184,7 +184,7 @@ fn rewrite_closure_expr( | ast::ExprKind::Loop(..) | ast::ExprKind::Struct(..) => true, - ast::ExprKind::AddrOf(_, ref expr) + ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Box(ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) @@ -431,7 +431,7 @@ fn is_block_closure_forced_inner(expr: &ast::Expr) -> bool { | ast::ExprKind::While(..) | ast::ExprKind::ForLoop(..) | ast::ExprKind::Loop(..) => true, - ast::ExprKind::AddrOf(_, ref expr) + ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Box(ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) diff --git a/rustfmt-core/rustfmt-lib/src/comment.rs b/rustfmt-core/rustfmt-lib/src/comment.rs index 59fd34a625d..148bdf9670e 100644 --- a/rustfmt-core/rustfmt-lib/src/comment.rs +++ b/rustfmt-core/rustfmt-lib/src/comment.rs @@ -3,7 +3,7 @@ use std::{self, borrow::Cow, iter}; use itertools::{multipeek, MultiPeek}; -use syntax::source_map::Span; +use rustc_span::Span; use crate::config::Config; use crate::rewrite::RewriteContext; diff --git a/rustfmt-core/rustfmt-lib/src/expr.rs b/rustfmt-core/rustfmt-lib/src/expr.rs index afc9fec925c..2ef3cf69834 100644 --- a/rustfmt-core/rustfmt-lib/src/expr.rs +++ b/rustfmt-core/rustfmt-lib/src/expr.rs @@ -2,8 +2,8 @@ use std::borrow::Cow; use std::cmp::min; use itertools::Itertools; -use syntax::parse::token::{DelimToken, LitKind}; -use syntax::source_map::{BytePos, Span}; +use rustc_span::{BytePos, Span}; +use syntax::token::{DelimToken, LitKind}; use syntax::{ast, ptr}; use crate::chains::rewrite_chain; @@ -159,7 +159,7 @@ pub(crate) fn format_expr( ast::ExprKind::Path(ref qself, ref path) => { rewrite_path(context, PathContext::Expr, qself.as_ref(), path, shape) } - ast::ExprKind::Assign(ref lhs, ref rhs) => { + ast::ExprKind::Assign(ref lhs, ref rhs, _) => { rewrite_assignment(context, lhs, rhs, None, shape) } ast::ExprKind::AssignOp(ref op, ref lhs, ref rhs) => { @@ -213,8 +213,8 @@ pub(crate) fn format_expr( rewrite_unary_prefix(context, "return ", &**expr, shape) } ast::ExprKind::Box(ref expr) => rewrite_unary_prefix(context, "box ", &**expr, shape), - ast::ExprKind::AddrOf(mutability, ref expr) => { - rewrite_expr_addrof(context, mutability, expr, shape) + ast::ExprKind::AddrOf(borrow_kind, mutability, ref expr) => { + rewrite_expr_addrof(context, borrow_kind, mutability, expr, shape) } ast::ExprKind::Cast(ref expr, ref ty) => rewrite_pair( &**expr, @@ -252,7 +252,7 @@ pub(crate) fn format_expr( fn needs_space_before_range(context: &RewriteContext<'_>, lhs: &ast::Expr) -> bool { match lhs.kind { ast::ExprKind::Lit(ref lit) => match lit.kind { - ast::LitKind::FloatUnsuffixed(..) => { + ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => { context.snippet(lit.span).ends_with('.') } _ => false, @@ -1289,7 +1289,7 @@ pub(crate) fn is_simple_expr(expr: &ast::Expr) -> bool { match expr.kind { ast::ExprKind::Lit(..) => true, ast::ExprKind::Path(ref qself, ref path) => qself.is_none() && path.segments.len() <= 1, - ast::ExprKind::AddrOf(_, ref expr) + ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Box(ref expr) | ast::ExprKind::Cast(ref expr, _) | ast::ExprKind::Field(ref expr, _) @@ -1335,8 +1335,12 @@ pub(crate) fn can_be_overflowed_expr( || (context.use_block_indent() && args_len == 1) } ast::ExprKind::Mac(ref mac) => { - match (mac.delim, context.config.overflow_delimited_expr()) { - (ast::MacDelimiter::Bracket, true) | (ast::MacDelimiter::Brace, true) => true, + match ( + syntax::ast::MacDelimiter::from_token(mac.args.delim()), + context.config.overflow_delimited_expr(), + ) { + (Some(ast::MacDelimiter::Bracket), true) + | (Some(ast::MacDelimiter::Brace), true) => true, _ => context.use_block_indent() && args_len == 1, } } @@ -1347,7 +1351,7 @@ pub(crate) fn can_be_overflowed_expr( } // Handle unary-like expressions - ast::ExprKind::AddrOf(_, ref expr) + ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Box(ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) @@ -1359,7 +1363,7 @@ pub(crate) fn can_be_overflowed_expr( pub(crate) fn is_nested_call(expr: &ast::Expr) -> bool { match expr.kind { ast::ExprKind::Call(..) | ast::ExprKind::Mac(..) => true, - ast::ExprKind::AddrOf(_, ref expr) + ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Box(ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) @@ -2035,13 +2039,14 @@ pub(crate) fn prefer_next_line( fn rewrite_expr_addrof( context: &RewriteContext<'_>, + _borrow_kind: ast::BorrowKind, mutability: ast::Mutability, expr: &ast::Expr, shape: Shape, ) -> Option { let operator_str = match mutability { - ast::Mutability::Immutable => "&", - ast::Mutability::Mutable => "&mut ", + ast::Mutability::Not => "&", + ast::Mutability::Mut => "&mut ", }; rewrite_unary_prefix(context, operator_str, expr, shape) } @@ -2049,7 +2054,7 @@ fn rewrite_expr_addrof( pub(crate) fn is_method_call(expr: &ast::Expr) -> bool { match expr.kind { ast::ExprKind::MethodCall(..) => true, - ast::ExprKind::AddrOf(_, ref expr) + ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Box(ref expr) | ast::ExprKind::Cast(ref expr, _) | ast::ExprKind::Try(ref expr) diff --git a/rustfmt-core/rustfmt-lib/src/formatting.rs b/rustfmt-core/rustfmt-lib/src/formatting.rs index 09a2e89a6e4..14040a2c429 100644 --- a/rustfmt-core/rustfmt-lib/src/formatting.rs +++ b/rustfmt-core/rustfmt-lib/src/formatting.rs @@ -4,8 +4,8 @@ use std::collections::HashMap; use std::io::{self, Write}; use std::time::{Duration, Instant}; +use rustc_span::Span; use syntax::ast; -use syntax::source_map::Span; use self::newline_style::apply_newline_style; use crate::comment::{CharClasses, FullCodeCharKind}; @@ -93,7 +93,7 @@ fn format_project( let mut context = FormatContext::new(&krate, report, parse_session, config, handler); let files = modules::ModResolver::new( &context.parse_session, - directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaMod(true)), + directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaMod), !input_is_stdin && config.recursive(), ) .visit_crate(&krate) diff --git a/rustfmt-core/rustfmt-lib/src/imports.rs b/rustfmt-core/rustfmt-lib/src/imports.rs index 988b268fa67..9a193113799 100644 --- a/rustfmt-core/rustfmt-lib/src/imports.rs +++ b/rustfmt-core/rustfmt-lib/src/imports.rs @@ -2,9 +2,8 @@ use std::borrow::Cow; use std::cmp::Ordering; use std::fmt; +use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol::sym}; use syntax::ast::{self, UseTreeKind}; -use syntax::source_map::{self, BytePos, Span, DUMMY_SP}; -use syntax::symbol::sym; use crate::comment::combine_strs_with_missing_comments; use crate::config::lists::*; @@ -249,7 +248,7 @@ impl UseTree { let allow_extend = if attrs.len() == 1 { let line_len = attr_str.len() + 1 + use_str.len(); - !attrs.first().unwrap().is_sugared_doc + !attrs.first().unwrap().is_doc_comment() && context.config.inline_attribute_width() >= line_len } else { false @@ -854,7 +853,7 @@ impl Rewrite for UseTree { #[cfg(test)] mod test { use super::*; - use syntax::source_map::DUMMY_SP; + use rustc_span::DUMMY_SP; // Parse the path part of an import. This parser is not robust and is only // suitable for use in a test harness. diff --git a/rustfmt-core/rustfmt-lib/src/items.rs b/rustfmt-core/rustfmt-lib/src/items.rs index 161997f969c..49d4b707caa 100644 --- a/rustfmt-core/rustfmt-lib/src/items.rs +++ b/rustfmt-core/rustfmt-lib/src/items.rs @@ -4,10 +4,9 @@ use std::borrow::Cow; use std::cmp::{max, min, Ordering}; use regex::Regex; -use rustc_target::spec::abi; -use syntax::source_map::{self, BytePos, Span}; +use rustc_span::{BytePos, DUMMY_SP, source_map, Span, symbol}; use syntax::visit; -use syntax::{ast, ptr, symbol}; +use syntax::{ast, ptr}; use crate::attr::filter_inline_attrs; use crate::comment::{ @@ -35,7 +34,7 @@ use crate::visitor::FmtVisitor; const DEFAULT_VISIBILITY: ast::Visibility = source_map::Spanned { node: ast::VisibilityKind::Inherited, - span: source_map::DUMMY_SP, + span: DUMMY_SP, }; fn type_annotation_separator(config: &Config) -> &str { @@ -195,7 +194,11 @@ impl<'a> Item<'a> { fn from_foreign_mod(fm: &'a ast::ForeignMod, span: Span, config: &Config) -> Item<'a> { Item { keyword: "", - abi: format_abi(fm.abi, config.force_explicit_abi(), true), + abi: format_extern( + ast::Extern::from_abi(fm.abi), + config.force_explicit_abi(), + true, + ), vis: None, body: fm .items @@ -219,7 +222,7 @@ enum BodyElement<'a> { pub(crate) struct FnSig<'a> { decl: &'a ast::FnDecl, generics: &'a ast::Generics, - abi: abi::Abi, + ext: ast::Extern, is_async: Cow<'a, ast::IsAsync>, constness: ast::Constness, defaultness: ast::Defaultness, @@ -236,7 +239,7 @@ impl<'a> FnSig<'a> { FnSig { decl, generics, - abi: abi::Abi::Rust, + ext: ast::Extern::None, is_async: Cow::Owned(ast::IsAsync::NotAsync), constness: ast::Constness::NotConst, defaultness: ast::Defaultness::Final, @@ -246,7 +249,7 @@ impl<'a> FnSig<'a> { } pub(crate) fn from_method_sig( - method_sig: &'a ast::MethodSig, + method_sig: &'a ast::FnSig, generics: &'a ast::Generics, ) -> FnSig<'a> { FnSig { @@ -254,7 +257,7 @@ impl<'a> FnSig<'a> { is_async: Cow::Borrowed(&method_sig.header.asyncness.node), constness: method_sig.header.constness.node, defaultness: ast::Defaultness::Final, - abi: method_sig.header.abi, + ext: method_sig.header.ext, decl: &*method_sig.decl, generics, visibility: DEFAULT_VISIBILITY, @@ -268,23 +271,23 @@ impl<'a> FnSig<'a> { defaultness: ast::Defaultness, ) -> FnSig<'a> { match *fn_kind { - visit::FnKind::ItemFn(_, fn_header, visibility, _) => FnSig { - decl, - generics, - abi: fn_header.abi, - constness: fn_header.constness.node, - is_async: Cow::Borrowed(&fn_header.asyncness.node), - defaultness, - unsafety: fn_header.unsafety, - visibility: visibility.clone(), - }, - visit::FnKind::Method(_, method_sig, vis, _) => { - let mut fn_sig = FnSig::from_method_sig(method_sig, generics); - fn_sig.defaultness = defaultness; - if let Some(vis) = vis { + visit::FnKind::Fn(fn_ctxt, _, fn_sig, vis, _) => match fn_ctxt { + visit::FnCtxt::Assoc(..) => { + let mut fn_sig = FnSig::from_method_sig(fn_sig, generics); + fn_sig.defaultness = defaultness; fn_sig.visibility = vis.clone(); + fn_sig + } + _ => FnSig { + decl, + generics, + ext: fn_sig.header.ext, + constness: fn_sig.header.constness.node, + is_async: Cow::Borrowed(&fn_sig.header.asyncness.node), + defaultness, + unsafety: fn_sig.header.unsafety, + visibility: vis.clone(), } - fn_sig } _ => unreachable!(), } @@ -298,8 +301,8 @@ impl<'a> FnSig<'a> { result.push_str(format_constness(self.constness)); result.push_str(format_async(&self.is_async)); result.push_str(format_unsafety(self.unsafety)); - result.push_str(&format_abi( - self.abi, + result.push_str(&format_extern( + self.ext, context.config.force_explicit_abi(), false, )); @@ -385,7 +388,7 @@ impl<'a> FmtVisitor<'a> { &mut self, indent: Indent, ident: ast::Ident, - sig: &ast::MethodSig, + sig: &ast::FnSig, generics: &ast::Generics, span: Span, ) -> Option { @@ -633,7 +636,7 @@ impl<'a> FmtVisitor<'a> { combine_strs_with_missing_comments(&context, &attrs_str, &variant_body, span, shape, false) } - fn visit_impl_items(&mut self, items: &[ast::ImplItem]) { + fn visit_impl_items(&mut self, items: &[ptr::P]) { if self.get_context().config.reorder_impl_items() { // Create visitor for each items, then reorder them. let mut buffer = vec![]; @@ -642,27 +645,72 @@ impl<'a> FmtVisitor<'a> { buffer.push((self.buffer.clone(), item.clone())); self.buffer.clear(); } + + fn is_type(ty: &Option>) -> bool { + match ty { + None => true, + Some(lty) => match lty.kind.opaque_top_hack() { + None => true, + Some(_) => false, + }, + } + } + + fn is_opaque(ty: &Option>) -> bool { + match ty { + None => false, + Some(lty) => match lty.kind.opaque_top_hack() { + None => false, + Some(_) => true, + }, + } + } + + fn both_type( + a: &Option>, + b: &Option>, + ) -> bool { + is_type(a) && is_type(b) + } + + fn both_opaque( + a: &Option>, + b: &Option>, + ) -> bool { + is_opaque(a) && is_opaque(b) + } + + // In rustc-ap-v638 the `OpaqueTy` AssocItemKind was removed but + // we still need to differentiate to maintain sorting order. + // type -> opaque -> const -> macro -> method - use crate::ast::ImplItemKind::*; - fn need_empty_line(a: &ast::ImplItemKind, b: &ast::ImplItemKind) -> bool { + use crate::ast::AssocItemKind::*; + fn need_empty_line(a: &ast::AssocItemKind, b: &ast::AssocItemKind) -> bool { match (a, b) { - (TyAlias(..), TyAlias(..)) - | (Const(..), Const(..)) - | (OpaqueTy(..), OpaqueTy(..)) => false, + (TyAlias(_, ref lty), TyAlias(_, ref rty)) + if both_type(lty, rty) || both_opaque(lty, rty) => + { + false + } + (Const(..), Const(..)) => false, _ => true, } } buffer.sort_by(|(_, a), (_, b)| match (&a.kind, &b.kind) { - (TyAlias(..), TyAlias(..)) - | (Const(..), Const(..)) - | (Macro(..), Macro(..)) - | (OpaqueTy(..), OpaqueTy(..)) => a.ident.as_str().cmp(&b.ident.as_str()), - (Method(..), Method(..)) => a.span.lo().cmp(&b.span.lo()), + (TyAlias(_, ref lty), TyAlias(_, ref rty)) + if both_type(lty, rty) || both_opaque(lty, rty) => + { + a.ident.as_str().cmp(&b.ident.as_str()) + } + (Const(..), Const(..)) | (Macro(..), Macro(..)) => { + a.ident.as_str().cmp(&b.ident.as_str()) + } + (Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()), + (TyAlias(_, ref ty), _) if is_type(ty) => Ordering::Less, + (_, TyAlias(_, ref ty)) if is_type(ty) => Ordering::Greater, (TyAlias(..), _) => Ordering::Less, (_, TyAlias(..)) => Ordering::Greater, - (OpaqueTy(..), _) => Ordering::Less, - (_, OpaqueTy(..)) => Ordering::Greater, (Const(..), _) => Ordering::Less, (_, Const(..)) => Ordering::Greater, (Macro(..), _) => Ordering::Less, @@ -696,7 +744,7 @@ pub(crate) fn format_impl( item: &ast::Item, offset: Indent, ) -> Option { - if let ast::ItemKind::Impl(_, _, _, ref generics, _, ref self_ty, ref items) = item.kind { + if let ast::ItemKind::Impl { ref generics, ref self_ty, ref items, ..} = item.kind { let mut result = String::with_capacity(128); let ref_and_type = format_impl_ref_and_type(context, item, offset)?; let sep = offset.to_string_with_newline(context.config); @@ -753,7 +801,7 @@ pub(crate) fn format_impl( } } - if is_impl_single_line(context, items, &result, &where_clause_str, item)? { + if is_impl_single_line(context, items.as_slice(), &result, &where_clause_str, item)? { result.push_str(&where_clause_str); if where_clause_str.contains('\n') || last_line_contains_single_line_comment(&result) { // if the where_clause contains extra comments AND @@ -822,7 +870,7 @@ pub(crate) fn format_impl( fn is_impl_single_line( context: &RewriteContext<'_>, - items: &[ast::ImplItem], + items: &[ptr::P], result: &str, where_clause_str: &str, item: &ast::Item, @@ -844,15 +892,15 @@ fn format_impl_ref_and_type( item: &ast::Item, offset: Indent, ) -> Option { - if let ast::ItemKind::Impl( + if let ast::ItemKind::Impl { unsafety, polarity, defaultness, ref generics, - ref trait_ref, + of_trait: ref trait_ref, ref self_ty, - _, - ) = item.kind + .. + } = item.kind { let mut result = String::with_capacity(128); @@ -1713,7 +1761,7 @@ impl<'a> StaticParts<'a> { let (prefix, ty, mutability, expr) = match item.kind { ast::ItemKind::Static(ref ty, mutability, ref expr) => ("static", ty, mutability, expr), ast::ItemKind::Const(ref ty, ref expr) => { - ("const", ty, ast::Mutability::Immutable, expr) + ("const", ty, ast::Mutability::Not, expr) } _ => unreachable!(), }; @@ -1729,9 +1777,9 @@ impl<'a> StaticParts<'a> { } } - pub(crate) fn from_trait_item(ti: &'a ast::TraitItem) -> Self { + pub(crate) fn from_trait_item(ti: &'a ast::AssocItem) -> Self { let (ty, expr_opt) = match ti.kind { - ast::TraitItemKind::Const(ref ty, ref expr_opt) => (ty, expr_opt), + ast::AssocItemKind::Const(ref ty, ref expr_opt) => (ty, expr_opt), _ => unreachable!(), }; StaticParts { @@ -1739,16 +1787,16 @@ impl<'a> StaticParts<'a> { vis: &DEFAULT_VISIBILITY, ident: ti.ident, ty, - mutability: ast::Mutability::Immutable, + mutability: ast::Mutability::Not, expr_opt: expr_opt.as_ref(), defaultness: None, span: ti.span, } } - pub(crate) fn from_impl_item(ii: &'a ast::ImplItem) -> Self { + pub(crate) fn from_impl_item(ii: &'a ast::AssocItem) -> Self { let (ty, expr) = match ii.kind { - ast::ImplItemKind::Const(ref ty, ref expr) => (ty, expr), + ast::AssocItemKind::Const(ref ty, ref expr) => (ty, expr), _ => unreachable!(), }; StaticParts { @@ -1756,8 +1804,8 @@ impl<'a> StaticParts<'a> { vis: &ii.vis, ident: ii.ident, ty, - mutability: ast::Mutability::Immutable, - expr_opt: Some(expr), + mutability: ast::Mutability::Not, + expr_opt: expr.as_ref(), defaultness: Some(ii.defaultness), span: ii.span, } @@ -3073,11 +3121,11 @@ impl Rewrite for ast::ForeignItem { let span = mk_sp(self.span.lo(), self.span.hi() - BytePos(1)); let item_str = match self.kind { - ast::ForeignItemKind::Fn(ref fn_decl, ref generics) => rewrite_fn_base( + ast::ForeignItemKind::Fn(ref fn_sig, ref generics, _) => rewrite_fn_base( context, shape.indent, self.ident, - &FnSig::new(fn_decl, generics, self.vis.clone()), + &FnSig::new(&fn_sig.decl, generics, self.vis.clone()), span, FnBraceStyle::None, ) @@ -3143,7 +3191,7 @@ fn rewrite_attrs( let allow_extend = if attrs.len() == 1 { let line_len = attrs_str.len() + 1 + item_str.len(); - !attrs.first().unwrap().is_sugared_doc + !attrs.first().unwrap().is_doc_comment() && context.config.inline_attribute_width() >= line_len } else { false diff --git a/rustfmt-core/rustfmt-lib/src/lists.rs b/rustfmt-core/rustfmt-lib/src/lists.rs index 8f98ab0747f..fbaf9e17695 100644 --- a/rustfmt-core/rustfmt-lib/src/lists.rs +++ b/rustfmt-core/rustfmt-lib/src/lists.rs @@ -3,7 +3,7 @@ use std::cmp; use std::iter::Peekable; -use syntax::source_map::BytePos; +use rustc_span::BytePos; use crate::comment::{find_comment_end, rewrite_comment, FindUncommented}; use crate::config::lists::*; diff --git a/rustfmt-core/rustfmt-lib/src/macros.rs b/rustfmt-core/rustfmt-lib/src/macros.rs index 4fa62982e9f..9cac5077520 100644 --- a/rustfmt-core/rustfmt-lib/src/macros.rs +++ b/rustfmt-core/rustfmt-lib/src/macros.rs @@ -12,16 +12,12 @@ use std::collections::HashMap; use std::panic::{catch_unwind, AssertUnwindSafe}; -use syntax::parse::new_parser_from_tts; -use syntax::parse::parser::Parser; -use syntax::parse::token::{BinOpToken, DelimToken, Token, TokenKind}; -use syntax::print::pprust; -use syntax::source_map::{BytePos, Span}; -use syntax::symbol::kw; +use rustc_ast_pretty::pprust; +use rustc_parse::{new_parser_from_tts, parser::Parser}; +use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, symbol::kw}; +use syntax::token::{BinOpToken, DelimToken, Token, TokenKind}; use syntax::tokenstream::{Cursor, TokenStream, TokenTree}; -use syntax::ThinVec; -use syntax::{ast, parse, ptr}; -use syntax_pos::{Symbol, DUMMY_SP}; +use syntax::{ast, ptr}; use crate::comment::{ contains_comment, CharClasses, FindUncommented, FullCodeCharKind, LineClasses, @@ -85,7 +81,7 @@ impl Rewrite for MacroArg { MacroArg::Ty(ref ty) => ty.rewrite(context, shape), MacroArg::Pat(ref pat) => pat.rewrite(context, shape), MacroArg::Item(ref item) => item.rewrite(context, shape), - MacroArg::Keyword(ident, _) => Some(ident.to_string()), + MacroArg::Keyword(ident, _) => Some(ident.name.to_string()), } } } @@ -114,23 +110,23 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { parse_macro_arg!( Expr, - |parser: &mut parse::parser::Parser<'b>| parser.parse_expr(), + |parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_expr(), |x: ptr::P| Some(x) ); parse_macro_arg!( Ty, - |parser: &mut parse::parser::Parser<'b>| parser.parse_ty(), + |parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_ty(), |x: ptr::P| Some(x) ); parse_macro_arg!( Pat, - |parser: &mut parse::parser::Parser<'b>| parser.parse_pat(None), + |parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_pat(None), |x: ptr::P| Some(x) ); // `parse_item` returns `Option>`. parse_macro_arg!( Item, - |parser: &mut parse::parser::Parser<'b>| parser.parse_item(), + |parser: &mut rustc_parse::parser::Parser<'b>| parser.parse_item(), |x: Option>| x ); @@ -147,7 +143,7 @@ fn rewrite_macro_name( // Avoid using pretty-printer in the common case. format!("{}!", rewrite_ident(context, path.segments[0].ident)) } else { - format!("{}!", path) + format!("{}!", pprust::path_to_string(path)) }; match extra_ident { Some(ident) if ident.name != kw::Invalid => format!("{} {}", name, ident), @@ -265,9 +261,9 @@ fn rewrite_macro_inner( } else { original_style }; + let ts = mac.args.inner_tokens(); - let ts: TokenStream = mac.stream(); - let has_comment = contains_comment(context.snippet(mac.span)); + let has_comment = contains_comment(context.snippet(mac.span())); if ts.is_empty() && !has_comment { return match style { DelimToken::Paren if position == MacroPosition::Item => { @@ -301,7 +297,7 @@ fn rewrite_macro_inner( } else if let Some(arg) = parse_macro_arg(&mut parser) { arg_vec.push(arg); } else { - return return_macro_parse_failure_fallback(context, shape.indent, mac.span); + return return_macro_parse_failure_fallback(context, shape.indent, mac.span()); } match parser.token.kind { @@ -325,16 +321,16 @@ fn rewrite_macro_inner( return return_macro_parse_failure_fallback( context, shape.indent, - mac.span, + mac.span(), ); } } } } - return return_macro_parse_failure_fallback(context, shape.indent, mac.span); + return return_macro_parse_failure_fallback(context, shape.indent, mac.span()); } _ if arg_vec.last().map_or(false, MacroArg::is_item) => continue, - _ => return return_macro_parse_failure_fallback(context, shape.indent, mac.span), + _ => return return_macro_parse_failure_fallback(context, shape.indent, mac.span()), } parser.bump(); @@ -354,7 +350,7 @@ fn rewrite_macro_inner( shape, style, position, - mac.span, + mac.span(), ); } @@ -371,7 +367,7 @@ fn rewrite_macro_inner( ¯o_name, arg_vec.iter(), shape, - mac.span, + mac.span(), context.config.width_heuristics().fn_call_width, if trailing_comma { Some(SeparatorTactic::Always) @@ -408,7 +404,7 @@ fn rewrite_macro_inner( let rewrite = rewrite_array( macro_name, arg_vec.iter(), - mac.span, + mac.span(), context, shape, force_trailing_comma, @@ -426,7 +422,7 @@ fn rewrite_macro_inner( // For macro invocations with braces, always put a space between // the `macro_name!` and `{ /* macro_body */ }` but skip modifying // anything in between the braces (for now). - let snippet = context.snippet(mac.span).trim_start_matches(|c| c != '{'); + let snippet = context.snippet(mac.span()).trim_start_matches(|c| c != '{'); match trim_left_preserve_layout(snippet, shape.indent, &context.config) { Some(macro_body) => Some(format!("{} {}", macro_name, macro_body)), None => Some(format!("{} {}", macro_name, snippet)), @@ -490,8 +486,8 @@ pub(crate) fn rewrite_macro_def( if snippet.as_ref().map_or(true, |s| s.ends_with(';')) { return snippet; } - - let mut parser = MacroParser::new(def.stream().into_trees()); + let ts = def.body.inner_tokens(); + let mut parser = MacroParser::new(ts.into_trees()); let parsed_def = match parser.parse() { Some(def) => def, None => return snippet, @@ -1194,27 +1190,28 @@ pub(crate) fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> O // `r#try!` must be used in the 2018 Edition. // https://doc.rust-lang.org/std/macro.try.html // https://github.com/rust-lang/rust/pull/62672 - if &mac.path.to_string() == "try" || &mac.path.to_string() == "r#try" { - let ts: TokenStream = mac.tts.clone(); + let path = &pprust::path_to_string(&mac.path); + if path == "try" || path == "r#try" { + let ts = mac.args.inner_tokens(); let mut parser = new_parser_from_tts(context.parse_sess.inner(), ts.trees().collect()); let mut kind = parser.parse_expr().ok()?; // take the end pos of mac so that the Try expression includes the closing parenthesis of // the try! macro - kind.span = mk_sp(kind.span.lo(), mac.span.hi()); + kind.span = mk_sp(kind.span.lo(), mac.span().hi()); Some(ast::Expr { id: ast::NodeId::root(), // dummy value kind: ast::ExprKind::Try(kind), - span: mac.span, // incorrect span, but shouldn't matter too much - attrs: ThinVec::new(), + span: mac.span(), // incorrect span, but shouldn't matter too much + attrs: ast::AttrVec::new(), }) } else { None } } -fn macro_style(mac: &ast::Mac, context: &RewriteContext<'_>) -> DelimToken { - let snippet = context.snippet(mac.span); +pub(crate) fn macro_style(mac: &ast::Mac, context: &RewriteContext<'_>) -> DelimToken { + let snippet = context.snippet(mac.span()); let paren_pos = snippet.find_uncommented("(").unwrap_or(usize::max_value()); let bracket_pos = snippet.find_uncommented("[").unwrap_or(usize::max_value()); let brace_pos = snippet.find_uncommented("{").unwrap_or(usize::max_value()); @@ -1466,7 +1463,10 @@ fn format_lazy_static( while parser.token.kind != TokenKind::Eof { // Parse a `lazy_static!` item. - let vis = crate::utils::format_visibility(context, &parse_or!(parse_visibility, false)); + let vis = crate::utils::format_visibility( + context, + &parse_or!(parse_visibility, rustc_parse::parser::FollowedByType::No), + ); parser.eat_keyword(kw::Static); parser.eat_keyword(kw::Ref); let id = parse_or!(parse_ident); diff --git a/rustfmt-core/rustfmt-lib/src/matches.rs b/rustfmt-core/rustfmt-lib/src/matches.rs index 60d93ac8c3e..d6072655d15 100644 --- a/rustfmt-core/rustfmt-lib/src/matches.rs +++ b/rustfmt-core/rustfmt-lib/src/matches.rs @@ -2,7 +2,7 @@ use std::iter::repeat; -use syntax::source_map::{BytePos, Span}; +use rustc_span::{BytePos, Span}; use syntax::{ast, ptr}; use crate::comment::{combine_strs_with_missing_comments, rewrite_comment}; @@ -575,7 +575,7 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool { | ast::ExprKind::Mac(..) | ast::ExprKind::Struct(..) | ast::ExprKind::Tup(..) => true, - ast::ExprKind::AddrOf(_, ref expr) + ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Box(ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) diff --git a/rustfmt-core/rustfmt-lib/src/missed_spans.rs b/rustfmt-core/rustfmt-lib/src/missed_spans.rs index 92fcb000ff9..60d916288fa 100644 --- a/rustfmt-core/rustfmt-lib/src/missed_spans.rs +++ b/rustfmt-core/rustfmt-lib/src/missed_spans.rs @@ -1,4 +1,4 @@ -use syntax::source_map::{BytePos, Pos, Span}; +use rustc_span::{BytePos, Pos, Span}; use crate::comment::{is_last_comment_block, rewrite_comment, CodeCharKind, CommentCodeSlices}; use crate::config::file_lines::FileLines; diff --git a/rustfmt-core/rustfmt-lib/src/modules.rs b/rustfmt-core/rustfmt-lib/src/modules.rs index 23928d8f17e..c3ed27a35f1 100644 --- a/rustfmt-core/rustfmt-lib/src/modules.rs +++ b/rustfmt-core/rustfmt-lib/src/modules.rs @@ -2,10 +2,9 @@ use std::borrow::Cow; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; +use rustc_span::symbol::{sym, Symbol}; use syntax::ast; -use syntax::symbol::sym; use syntax::visit::Visitor; -use syntax_pos::symbol::Symbol; use crate::attr::MetaVisitor; use crate::config::FileName; @@ -155,7 +154,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { } else { // An internal module (`mod foo { /* ... */ }`); if let Some(path) = find_path_value(&item.attrs) { - let path = Path::new(&path.as_str()).to_path_buf(); + let path = Path::new(&*path.as_str()).to_path_buf(); Ok(Some(SubModKind::InternalWithPath(path))) } else { Ok(Some(SubModKind::Internal(item))) @@ -253,7 +252,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { let relative = match self.directory.ownership { DirectoryOwnership::Owned { relative } => relative, - DirectoryOwnership::UnownedViaBlock | DirectoryOwnership::UnownedViaMod(_) => None, + DirectoryOwnership::UnownedViaBlock | DirectoryOwnership::UnownedViaMod => None, }; match self .parse_sess @@ -289,7 +288,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { fn push_inline_mod_directory(&mut self, id: ast::Ident, attrs: &[ast::Attribute]) { if let Some(path) = find_path_value(attrs) { - self.directory.path.push(&path.as_str()); + self.directory.path.push(&*path.as_str()); self.directory.ownership = DirectoryOwnership::Owned { relative: None }; } else { // We have to push on the current module name in the case of relative @@ -301,10 +300,10 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { if let DirectoryOwnership::Owned { relative } = &mut self.directory.ownership { if let Some(ident) = relative.take() { // remove the relative offset - self.directory.path.push(ident.as_str()); + self.directory.path.push(&*ident.as_str()); } } - self.directory.path.push(&id.as_str()); + self.directory.path.push(&*id.as_str()); } } diff --git a/rustfmt-core/rustfmt-lib/src/modules/visitor.rs b/rustfmt-core/rustfmt-lib/src/modules/visitor.rs index 80338b89b13..ad9111f7a9f 100644 --- a/rustfmt-core/rustfmt-lib/src/modules/visitor.rs +++ b/rustfmt-core/rustfmt-lib/src/modules/visitor.rs @@ -1,6 +1,6 @@ +use rustc_span::Symbol; use syntax::ast; use syntax::visit::Visitor; -use syntax_pos::Symbol; use crate::attr::MetaVisitor; use crate::syntux::parser::{Directory, Parser}; diff --git a/rustfmt-core/rustfmt-lib/src/overflow.rs b/rustfmt-core/rustfmt-lib/src/overflow.rs index 7b13bd4936f..6d90b065ea7 100644 --- a/rustfmt-core/rustfmt-lib/src/overflow.rs +++ b/rustfmt-core/rustfmt-lib/src/overflow.rs @@ -3,8 +3,8 @@ use std::cmp::min; use itertools::Itertools; -use syntax::parse::token::DelimToken; -use syntax::source_map::Span; +use rustc_span::Span; +use syntax::token::DelimToken; use syntax::{ast, ptr}; use crate::closures; diff --git a/rustfmt-core/rustfmt-lib/src/patterns.rs b/rustfmt-core/rustfmt-lib/src/patterns.rs index baa39dbbce6..fda85f296c8 100644 --- a/rustfmt-core/rustfmt-lib/src/patterns.rs +++ b/rustfmt-core/rustfmt-lib/src/patterns.rs @@ -1,6 +1,6 @@ +use rustc_span::{BytePos, Span}; use syntax::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSyntax}; use syntax::ptr; -use syntax::source_map::{BytePos, Span}; use crate::comment::{combine_strs_with_missing_comments, FindUncommented}; use crate::config::lists::*; @@ -179,25 +179,28 @@ impl Rewrite for Pat { None } } - PatKind::Range(ref lhs, ref rhs, ref end_kind) => { - let infix = match end_kind.node { - RangeEnd::Included(RangeSyntax::DotDotDot) => "...", - RangeEnd::Included(RangeSyntax::DotDotEq) => "..=", - RangeEnd::Excluded => "..", - }; - let infix = if context.config.spaces_around_ranges() { - format!(" {} ", infix) - } else { - infix.to_owned() - }; - rewrite_pair( - &**lhs, - &**rhs, - PairParts::infix(&infix), - context, - shape, - SeparatorPlace::Front, - ) + PatKind::Range(ref lhs, ref rhs, ref end_kind) => match (lhs, rhs) { + (Some(lhs), Some(rhs)) => { + let infix = match end_kind.node { + RangeEnd::Included(RangeSyntax::DotDotDot) => "...", + RangeEnd::Included(RangeSyntax::DotDotEq) => "..=", + RangeEnd::Excluded => "..", + }; + let infix = if context.config.spaces_around_ranges() { + format!(" {} ", infix) + } else { + infix.to_owned() + }; + rewrite_pair( + &**lhs, + &**rhs, + PairParts::infix(&infix), + context, + shape, + SeparatorPlace::Front, + ) + }, + (_, _) => unimplemented!(), } PatKind::Ref(ref pat, mutability) => { let prefix = format!("&{}", format_mutability(mutability)); diff --git a/rustfmt-core/rustfmt-lib/src/reorder.rs b/rustfmt-core/rustfmt-lib/src/reorder.rs index 653e69b5ef8..6a0a1cc62af 100644 --- a/rustfmt-core/rustfmt-lib/src/reorder.rs +++ b/rustfmt-core/rustfmt-lib/src/reorder.rs @@ -8,7 +8,8 @@ use std::cmp::{Ord, Ordering}; -use syntax::{ast, attr, source_map::Span, symbol::sym}; +use rustc_span::{Span, symbol::sym}; +use syntax::{ast, attr}; use crate::config::Config; use crate::imports::{merge_use_trees, UseTree}; @@ -31,9 +32,9 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering { // `extern crate foo as bar;` // ^^^ Comparing this. let a_orig_name = - a_name.map_or_else(|| a.ident.as_str(), syntax_pos::symbol::Symbol::as_str); + a_name.map_or_else(|| a.ident.as_str(), rustc_span::Symbol::as_str); let b_orig_name = - b_name.map_or_else(|| b.ident.as_str(), syntax_pos::symbol::Symbol::as_str); + b_name.map_or_else(|| b.ident.as_str(), rustc_span::Symbol::as_str); let result = a_orig_name.cmp(&b_orig_name); if result != Ordering::Equal { return result; diff --git a/rustfmt-core/rustfmt-lib/src/rewrite.rs b/rustfmt-core/rustfmt-lib/src/rewrite.rs index cd868bdf8f6..f73602f09a2 100644 --- a/rustfmt-core/rustfmt-lib/src/rewrite.rs +++ b/rustfmt-core/rustfmt-lib/src/rewrite.rs @@ -3,8 +3,8 @@ use std::cell::{Cell, RefCell}; use std::rc::Rc; +use rustc_span::Span; use syntax::ptr; -use syntax::source_map::Span; use crate::config::{Config, IndentStyle}; use crate::shape::Shape; diff --git a/rustfmt-core/rustfmt-lib/src/skip.rs b/rustfmt-core/rustfmt-lib/src/skip.rs index e21d407720d..29863dde719 100644 --- a/rustfmt-core/rustfmt-lib/src/skip.rs +++ b/rustfmt-core/rustfmt-lib/src/skip.rs @@ -1,7 +1,7 @@ //! Module that contains skip related stuffs. +use rustc_span::symbol::{sym, Symbol}; use syntax::ast::{Attribute, PathSegment}; -use syntax::symbol::{sym, Symbol}; macro_rules! sym { ($tt:tt) => { @@ -29,10 +29,15 @@ impl SkipContext { } } for attr in attrs { - if is_skip_attr_with(&attr.item.path.segments, |s| s == sym!(macros)) { - get_skip_names(&mut self.macros, attr) - } else if is_skip_attr_with(&attr.item.path.segments, |s| s == sym::attributes) { - get_skip_names(&mut self.attributes, attr) + match &attr.kind { + syntax::ast::AttrKind::Normal(ref attr_item) => { + if is_skip_attr_with(&attr_item.path.segments, |s| s == sym!(macros)) { + get_skip_names(&mut self.macros, attr) + } else if is_skip_attr_with(&attr_item.path.segments, |s| s == sym::attributes) { + get_skip_names(&mut self.attributes, attr) + } + } + _ => (), } } } diff --git a/rustfmt-core/rustfmt-lib/src/source_map.rs b/rustfmt-core/rustfmt-lib/src/source_map.rs index c1562f36a5a..76e0d24cf1e 100644 --- a/rustfmt-core/rustfmt-lib/src/source_map.rs +++ b/rustfmt-core/rustfmt-lib/src/source_map.rs @@ -1,7 +1,7 @@ //! This module contains utilities that work with the `SourceMap` from `libsyntax`/`syntex_syntax`. //! This includes extension traits and methods for looking up spans and line ranges for AST nodes. -use syntax::source_map::{BytePos, Span}; +use rustc_span::{BytePos, Span}; use crate::comment::FindUncommented; use crate::config::file_lines::LineRange; diff --git a/rustfmt-core/rustfmt-lib/src/spanned.rs b/rustfmt-core/rustfmt-lib/src/spanned.rs index 7624654a8eb..b2a70dd5cec 100644 --- a/rustfmt-core/rustfmt-lib/src/spanned.rs +++ b/rustfmt-core/rustfmt-lib/src/spanned.rs @@ -1,9 +1,7 @@ use std::cmp::max; -use syntax::{ - ast, ptr, - source_map::{self, Span}, -}; +use rustc_span::{source_map, Span}; +use syntax::{ast, ptr}; use crate::macros::MacroArg; use crate::utils::{mk_sp, outer_attributes}; @@ -31,12 +29,7 @@ macro_rules! span_with_attrs_lo_hi { if attrs.is_empty() { mk_sp($lo, $hi) } else { - // this path is already gone at latest rust-ap-* 627.0.0 - if attrs[0].item.path.to_string() == "warn_directory_ownership" { - mk_sp($lo, $hi) - } else { - mk_sp(attrs[0].span.lo(), $hi) - } + mk_sp(attrs[0].span.lo(), $hi) } }}; } @@ -58,13 +51,12 @@ macro_rules! implement_spanned { } // Implement `Spanned` for structs with `attrs` field. +implement_spanned!(ast::AssocItem); implement_spanned!(ast::Expr); implement_spanned!(ast::Field); implement_spanned!(ast::ForeignItem); implement_spanned!(ast::Item); implement_spanned!(ast::Local); -implement_spanned!(ast::TraitItem); -implement_spanned!(ast::ImplItem); impl Spanned for ast::Stmt { fn span(&self) -> Span { diff --git a/rustfmt-core/rustfmt-lib/src/stmt.rs b/rustfmt-core/rustfmt-lib/src/stmt.rs index 09888e916c6..b3cb160d847 100644 --- a/rustfmt-core/rustfmt-lib/src/stmt.rs +++ b/rustfmt-core/rustfmt-lib/src/stmt.rs @@ -1,5 +1,5 @@ +use rustc_span::Span; use syntax::ast; -use syntax_pos::Span; use crate::comment::recover_comment_removed; use crate::expr::{format_expr, ExprType}; diff --git a/rustfmt-core/rustfmt-lib/src/syntux/parser.rs b/rustfmt-core/rustfmt-lib/src/syntux/parser.rs index ad38537d8d1..9325cdbea52 100644 --- a/rustfmt-core/rustfmt-lib/src/syntux/parser.rs +++ b/rustfmt-core/rustfmt-lib/src/syntux/parser.rs @@ -2,19 +2,17 @@ use std::borrow::Cow; use std::panic::{catch_unwind, AssertUnwindSafe}; use std::path::{Path, PathBuf}; +use rustc_errors::{Diagnostic, PResult}; +use rustc_parse::{new_sub_parser_from_file, parser::Parser as RawParser}; +use rustc_span::{DUMMY_SP, Span, symbol::kw}; use syntax::ast; -use syntax::errors::Diagnostic; -use syntax::parse::parser::Parser as RawParser; -use syntax::parse::token::{DelimToken, TokenKind}; -use syntax::parse::{new_sub_parser_from_file, PResult}; -use syntax::source_map::{Span, DUMMY_SP}; -use syntax::symbol::kw; +use syntax::token::{DelimToken, TokenKind}; use crate::syntux::session::ParseSess; use crate::{Config, Input}; -pub(crate) type DirectoryOwnership = syntax::parse::DirectoryOwnership; -pub(crate) type ModulePathSuccess = syntax::parse::parser::ModulePathSuccess; +pub(crate) type DirectoryOwnership = rustc_parse::DirectoryOwnership; +pub(crate) type ModulePathSuccess = rustc_parse::parser::ModulePathSuccess; #[derive(Clone)] pub(crate) struct Directory { @@ -23,8 +21,8 @@ pub(crate) struct Directory { } impl<'a> Directory { - fn to_syntax_directory(&'a self) -> syntax::parse::Directory<'a> { - syntax::parse::Directory { + fn to_syntax_directory(&'a self) -> rustc_parse::Directory<'a> { + rustc_parse::Directory { path: Cow::Borrowed(&self.path), ownership: self.ownership, } @@ -90,13 +88,13 @@ impl<'a> ParserBuilder<'a> { } fn parser( - sess: &'a syntax::parse::ParseSess, + sess: &'a rustc_session::parse::ParseSess, input: Input, directory_ownership: Option, - ) -> Result, Vec> { + ) -> Result, Vec> { match input { Input::File(ref file) => Ok(if let Some(directory_ownership) = directory_ownership { - syntax::parse::new_sub_parser_from_file( + rustc_parse::new_sub_parser_from_file( sess, file, directory_ownership, @@ -104,11 +102,11 @@ impl<'a> ParserBuilder<'a> { DUMMY_SP, ) } else { - syntax::parse::new_parser_from_file(sess, file) + rustc_parse::new_parser_from_file(sess, file) }), - Input::Text(text) => syntax::parse::maybe_new_parser_from_source_str( + Input::Text(text) => rustc_parse::maybe_new_parser_from_source_str( sess, - syntax::source_map::FileName::Custom("stdin".to_owned()), + rustc_span::FileName::Custom("stdin".to_owned()), text, ) .map(|mut parser| { @@ -131,7 +129,7 @@ pub(crate) enum ParserError { impl<'a> Parser<'a> { pub(crate) fn submod_path_from_attr(attrs: &[ast::Attribute], path: &Path) -> Option { - syntax::parse::parser::Parser::submod_path_from_attr(attrs, path) + rustc_parse::parser::Parser::submod_path_from_attr(attrs, path) } // FIXME(topecongiro) Use the method from libsyntax[1] once it become public. @@ -153,7 +151,11 @@ impl<'a> Parser<'a> { } TokenKind::DocComment(s) => { // we need to get the position of this token before we bump. - let attr = syntax::attr::mk_sugared_doc_attr(s, parser.token.span); + let attr = syntax::attr::mk_doc_comment( + syntax::util::comments::doc_comment_style(&s.as_str()), + s, + parser.token.span, + ); if attr.style == ast::AttrStyle::Inner { attrs.push(attr); parser.bump(); @@ -281,9 +283,10 @@ impl<'a> Parser<'a> { mac: &'a ast::Mac, base_dir: &Directory, ) -> Result, &'static str> { - let mut parser = syntax::parse::stream_to_parser_with_base_dir( + let token_stream = mac.args.inner_tokens(); + let mut parser = rustc_parse::stream_to_parser_with_base_dir( sess.inner(), - mac.tts.clone(), + token_stream.clone(), base_dir.to_syntax_directory(), ); diff --git a/rustfmt-core/rustfmt-lib/src/syntux/session.rs b/rustfmt-core/rustfmt-lib/src/syntux/session.rs index 5d96d516783..b9cd90ca4df 100644 --- a/rustfmt-core/rustfmt-lib/src/syntux/session.rs +++ b/rustfmt-core/rustfmt-lib/src/syntux/session.rs @@ -2,13 +2,12 @@ use std::cell::RefCell; use std::path::Path; use std::rc::Rc; -use rustc_data_structures::sync::Send; +use rustc_data_structures::sync::{Lrc, Send}; +use rustc_errors::emitter::{Emitter, EmitterWriter}; +use rustc_errors::{ColorConfig, Diagnostic, Handler, Level as DiagnosticLevel}; +use rustc_session::parse::ParseSess as RawParseSess; +use rustc_span::{BytePos, source_map::{FilePathMapping, SourceMap}, Span}; use syntax::ast; -use syntax::errors::emitter::{ColorConfig, Emitter, EmitterWriter}; -use syntax::errors::{Diagnostic, Handler, Level as DiagnosticLevel}; -use syntax::parse::ParseSess as RawParseSess; -use syntax::source_map::{FilePathMapping, SourceMap}; -use syntax_pos::{BytePos, Span}; use crate::config::file_lines::LineRange; use crate::ignore_path::IgnorePathSet; @@ -28,6 +27,9 @@ pub(crate) struct ParseSess { struct SilentEmitter; impl Emitter for SilentEmitter { + fn source_map(&self) -> Option<&Lrc> { + None + } fn emit_diagnostic(&mut self, _db: &Diagnostic) {} } @@ -53,13 +55,16 @@ impl SilentOnIgnoredFilesEmitter { } impl Emitter for SilentOnIgnoredFilesEmitter { + fn source_map(&self) -> Option<&Lrc> { + None + } fn emit_diagnostic(&mut self, db: &Diagnostic) { if db.level == DiagnosticLevel::Fatal { return self.handle_non_ignoreable_error(db); } if let Some(primary_span) = &db.span.primary_span() { let file_name = self.source_map.span_to_filename(*primary_span); - if let syntax_pos::FileName::Real(ref path) = file_name { + if let rustc_span::FileName::Real(ref path) = file_name { if self .ignore_path_set .is_match(&FileName::Real(path.to_path_buf())) @@ -142,8 +147,8 @@ impl ParseSess { id: ast::Ident, relative: Option, dir_path: &Path, - ) -> syntax::parse::parser::ModulePath { - syntax::parse::parser::Parser::default_submod_path( + ) -> rustc_parse::parser::ModulePath { + rustc_parse::parser::Parser::default_submod_path( id, relative, dir_path, @@ -154,7 +159,7 @@ impl ParseSess { pub(crate) fn is_file_parsed(&self, path: &Path) -> bool { self.parse_sess .source_map() - .get_source_file(&syntax_pos::FileName::Real(path.to_path_buf())) + .get_source_file(&rustc_span::FileName::Real(path.to_path_buf())) .is_some() } @@ -270,14 +275,16 @@ mod tests { use crate::is_nightly_channel; use crate::utils::mk_sp; use std::path::PathBuf; - use syntax::source_map::FileName as SourceMapFileName; - use syntax_pos::MultiSpan; + use rustc_span::{DUMMY_SP, MultiSpan, FileName as SourceMapFileName}; struct TestEmitter { num_emitted_errors: Rc>, } impl Emitter for TestEmitter { + fn source_map(&self) -> Option<&Lrc> { + None + } fn emit_diagnostic(&mut self, _db: &Diagnostic) { *self.num_emitted_errors.borrow_mut() += 1; } @@ -291,6 +298,7 @@ mod tests { children: vec![], suggestions: vec![], span: span.unwrap_or_else(MultiSpan::new), + sort_span: DUMMY_SP, } } diff --git a/rustfmt-core/rustfmt-lib/src/types.rs b/rustfmt-core/rustfmt-lib/src/types.rs index 017e4ca9f51..c05a76bd2b3 100644 --- a/rustfmt-core/rustfmt-lib/src/types.rs +++ b/rustfmt-core/rustfmt-lib/src/types.rs @@ -1,9 +1,8 @@ use std::iter::ExactSizeIterator; use std::ops::Deref; +use rustc_span::{BytePos, Span, symbol::kw}; use syntax::ast::{self, FunctionRetTy, Mutability}; -use syntax::source_map::{BytePos, Span, DUMMY_SP}; -use syntax::symbol::kw; use crate::config::lists::*; use crate::config::{IndentStyle, TypeDensity}; @@ -19,7 +18,7 @@ use crate::shape::Shape; use crate::source_map::SpanUtils; use crate::spanned::Spanned; use crate::utils::{ - colon_spaces, extra_offset, first_line_width, format_abi, format_mutability, + colon_spaces, extra_offset, first_line_width, format_extern, format_mutability, last_line_extendable, last_line_width, mk_sp, rewrite_ident, }; @@ -275,13 +274,9 @@ fn rewrite_segment( result.push_str(&generics_str) } ast::GenericArgs::Parenthesized(ref data) => { - let output = match data.output { - Some(ref ty) => FunctionRetTy::Ty(ty.clone()), - None => FunctionRetTy::Default(DUMMY_SP), - }; result.push_str(&format_function_type( data.inputs.iter().map(|x| &**x), - &output, + &data.output, false, data.span, context, @@ -528,6 +523,7 @@ impl Rewrite for ast::GenericBound { ast::TraitBoundModifier::Maybe => poly_trait_ref .rewrite(context, shape.offset_left(1)?) .map(|s| format!("?{}", s)), + _ => unimplemented!(), }; rewrite.map(|s| if has_paren { format!("({})", s) } else { s }) } @@ -634,8 +630,8 @@ impl Rewrite for ast::Ty { } ast::TyKind::Ptr(ref mt) => { let prefix = match mt.mutbl { - Mutability::Mutable => "*mut ", - Mutability::Immutable => "*const ", + Mutability::Mut => "*mut ", + Mutability::Not => "*const ", }; rewrite_unary_prefix(context, prefix, &*mt.ty, shape) @@ -777,8 +773,8 @@ fn rewrite_bare_fn( result.push_str(crate::utils::format_unsafety(bare_fn.unsafety)); - result.push_str(&format_abi( - bare_fn.abi, + result.push_str(&format_extern( + bare_fn.ext, context.config.force_explicit_abi(), false, )); diff --git a/rustfmt-core/rustfmt-lib/src/utils.rs b/rustfmt-core/rustfmt-lib/src/utils.rs index 05de4b53ca2..6160ce77ae6 100644 --- a/rustfmt-core/rustfmt-lib/src/utils.rs +++ b/rustfmt-core/rustfmt-lib/src/utils.rs @@ -1,14 +1,13 @@ use std::borrow::Cow; +use rustc_ast_pretty::pprust; +use rustc_span::{BytePos, ExpnId, Span, sym, Symbol, SyntaxContext}; use rustc_target::spec::abi; use syntax::ast::{ self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility, VisibilityKind, }; use syntax::ptr; -use syntax::source_map::{BytePos, Span, SyntaxContext}; -use syntax::symbol::{sym, Symbol}; -use syntax_pos::ExpnId; use unicode_width::UnicodeWidthStr; use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses}; @@ -44,7 +43,7 @@ pub(crate) fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool { ( VisibilityKind::Restricted { path: p, .. }, VisibilityKind::Restricted { path: q, .. }, - ) => p.to_string() == q.to_string(), + ) => pprust::path_to_string(p) == pprust::path_to_string(q), (VisibilityKind::Public, VisibilityKind::Public) | (VisibilityKind::Inherited, VisibilityKind::Inherited) | ( @@ -129,13 +128,25 @@ pub(crate) fn format_auto(is_auto: ast::IsAuto) -> &'static str { #[inline] pub(crate) fn format_mutability(mutability: ast::Mutability) -> &'static str { match mutability { - ast::Mutability::Mutable => "mut ", - ast::Mutability::Immutable => "", + ast::Mutability::Mut => "mut ", + ast::Mutability::Not => "", } } #[inline] -pub(crate) fn format_abi(abi: abi::Abi, explicit_abi: bool, is_mod: bool) -> Cow<'static, str> { +pub(crate) fn format_extern( + ext: ast::Extern, + explicit_abi: bool, + is_mod: bool, +) -> Cow<'static, str> { + let abi = match ext { + ast::Extern::None => abi::Abi::Rust, + ast::Extern::Implicit => abi::Abi::C, + ast::Extern::Explicit(abi) => { + abi::lookup(&abi.symbol_unescaped.as_str()).unwrap_or(abi::Abi::Rust) + } + }; + if abi == abi::Abi::Rust && !is_mod { Cow::from("") } else if abi == abi::Abi::C && !explicit_abi { @@ -243,8 +254,8 @@ pub(crate) fn last_line_extendable(s: &str) -> bool { fn is_skip(meta_item: &MetaItem) -> bool { match meta_item.kind { MetaItemKind::Word => { - let path_str = meta_item.path.to_string(); - path_str == skip_annotation().as_str() || path_str == depr_skip_annotation().as_str() + let path_str = pprust::path_to_string(&meta_item.path); + path_str == &*skip_annotation().as_str() || path_str == &*depr_skip_annotation().as_str() } MetaItemKind::List(ref l) => { meta_item.check_name(sym::cfg_attr) && l.len() == 2 && is_skip_nested(&l[1]) @@ -420,7 +431,7 @@ pub(crate) fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr { | ast::ExprKind::Binary(_, ref e, _) | ast::ExprKind::Cast(ref e, _) | ast::ExprKind::Type(ref e, _) - | ast::ExprKind::Assign(ref e, _) + | ast::ExprKind::Assign(ref e, _, _) | ast::ExprKind::AssignOp(_, ref e, _) | ast::ExprKind::Field(ref e, _) | ast::ExprKind::Index(ref e, _) diff --git a/rustfmt-core/rustfmt-lib/src/vertical.rs b/rustfmt-core/rustfmt-lib/src/vertical.rs index 59b03789fb5..b932b0afa17 100644 --- a/rustfmt-core/rustfmt-lib/src/vertical.rs +++ b/rustfmt-core/rustfmt-lib/src/vertical.rs @@ -3,8 +3,8 @@ use std::cmp; use itertools::Itertools; +use rustc_span::{BytePos, Span}; use syntax::ast; -use syntax::source_map::{BytePos, Span}; use crate::comment::combine_strs_with_missing_comments; use crate::config::lists::*; diff --git a/rustfmt-core/rustfmt-lib/src/visitor.rs b/rustfmt-core/rustfmt-lib/src/visitor.rs index ad1ec309371..ee1e7f68415 100644 --- a/rustfmt-core/rustfmt-lib/src/visitor.rs +++ b/rustfmt-core/rustfmt-lib/src/visitor.rs @@ -1,8 +1,8 @@ use std::cell::{Cell, RefCell}; use std::rc::Rc; -use syntax::source_map::{BytePos, Pos, Span}; -use syntax::{ast, visit}; +use rustc_span::{BytePos, Pos, Span}; +use syntax::{ast, visit, token::DelimToken}; use crate::attr::*; use crate::comment::{rewrite_comment, CodeCharKind, CommentCodeSlices}; @@ -14,7 +14,7 @@ use crate::items::{ rewrite_opaque_impl_type, rewrite_opaque_type, rewrite_type_alias, FnBraceStyle, FnSig, StaticParts, StructParts, }; -use crate::macros::{rewrite_macro, rewrite_macro_def, MacroPosition}; +use crate::macros::{rewrite_macro, rewrite_macro_def, MacroPosition, macro_style}; use crate::rewrite::{Rewrite, RewriteContext}; use crate::shape::{Indent, Shape}; use crate::skip::{is_skip_attr, SkipContext}; @@ -355,7 +355,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { let indent = self.block_indent; let block; let rewrite = match fk { - visit::FnKind::ItemFn(ident, _, _, b) | visit::FnKind::Method(ident, _, _, b) => { + visit::FnKind::Fn(_, ident, _, _, Some(ref b)) => { block = b; self.rewrite_fn_before_block( indent, @@ -364,7 +364,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { mk_sp(s.lo(), b.span.lo()), ) } - visit::FnKind::Closure(_) => unreachable!(), + _ => unreachable!(), }; if let Some((fn_str, fn_brace_style)) = rewrite { @@ -448,7 +448,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { if should_visit_node_again { match item.kind { ast::ItemKind::Use(ref tree) => self.format_import(item, tree), - ast::ItemKind::Impl(..) => { + ast::ItemKind::Impl {..} => { let block_indent = self.block_indent; let rw = self.with_context(|ctx| format_impl(&ctx, item, block_indent)); self.push_rewrite(item.span, rw); @@ -502,39 +502,51 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => { self.visit_static(&StaticParts::from_item(item)); } - ast::ItemKind::Fn(ref decl, ref fn_header, ref generics, ref body) => { + ast::ItemKind::Fn(ref fn_signature, ref generics, ref body) => { let inner_attrs = inner_attributes(&item.attrs); + let fn_ctxt = match fn_signature.header.ext { + ast::Extern::None => visit::FnCtxt::Free, + _ => visit::FnCtxt::Foreign, + }; self.visit_fn( - visit::FnKind::ItemFn(item.ident, fn_header, &item.vis, body), + visit::FnKind::Fn( + fn_ctxt, + item.ident, + &fn_signature, + &item.vis, + body.as_deref(), + ), generics, - decl, + &fn_signature.decl, item.span, ast::Defaultness::Final, Some(&inner_attrs), ) } - ast::ItemKind::TyAlias(ref ty, ref generics) => { - let rewrite = rewrite_type_alias( - &self.get_context(), - self.block_indent, - item.ident, - ty, - generics, - &item.vis, - ); - self.push_rewrite(item.span, rewrite); - } - ast::ItemKind::OpaqueTy(ref generic_bounds, ref generics) => { - let rewrite = rewrite_opaque_type( - &self.get_context(), - self.block_indent, - item.ident, - generic_bounds, - generics, - &item.vis, - ); - self.push_rewrite(item.span, rewrite); - } + ast::ItemKind::TyAlias(ref ty, ref generics) => match ty.kind.opaque_top_hack() { + None => { + let rewrite = rewrite_type_alias( + &self.get_context(), + self.block_indent, + item.ident, + ty, + generics, + &item.vis, + ); + self.push_rewrite(item.span, rewrite); + } + Some(generic_bounds) => { + let rewrite = rewrite_opaque_type( + &self.get_context(), + self.block_indent, + item.ident, + generic_bounds, + generics, + &item.vis, + ); + self.push_rewrite(item.span, rewrite); + } + }, ast::ItemKind::GlobalAsm(..) => { let snippet = Some(self.snippet(item.span).to_owned()); self.push_rewrite(item.span, snippet); @@ -556,26 +568,28 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { self.skip_context = skip_context_saved; } - pub(crate) fn visit_trait_item(&mut self, ti: &ast::TraitItem) { + pub(crate) fn visit_trait_item(&mut self, ti: &ast::AssocItem) { skip_out_of_file_lines_range_visitor!(self, ti.span); if self.visit_attrs(&ti.attrs, ast::AttrStyle::Outer) { - self.push_skipped_with_span(ti.attrs.as_slice(), ti.span(), ti.span()); + self.push_skipped_with_span(ti.attrs.as_slice(), ti.span, ti.span); return; } match ti.kind { - ast::TraitItemKind::Const(..) => self.visit_static(&StaticParts::from_trait_item(ti)), - ast::TraitItemKind::Method(ref sig, None) => { + ast::AssocItemKind::Const(..) => self.visit_static(&StaticParts::from_trait_item(ti)), + ast::AssocItemKind::Fn(ref sig, None) => { let indent = self.block_indent; let rewrite = self.rewrite_required_fn(indent, ti.ident, sig, &ti.generics, ti.span); self.push_rewrite(ti.span, rewrite); } - ast::TraitItemKind::Method(ref sig, Some(ref body)) => { + ast::AssocItemKind::Fn(ref sig, Some(ref body)) => { let inner_attrs = inner_attributes(&ti.attrs); + let vis = rustc_span::source_map::dummy_spanned(ast::VisibilityKind::Inherited); + let fn_ctxt = visit::FnCtxt::Assoc(visit::AssocCtxt::Trait); self.visit_fn( - visit::FnKind::Method(ti.ident, sig, None, body), + visit::FnKind::Fn(fn_ctxt, ti.ident, sig, &vis, Some(body)), &ti.generics, &sig.decl, ti.span, @@ -583,7 +597,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { Some(&inner_attrs), ); } - ast::TraitItemKind::Type(ref generic_bounds, ref type_default) => { + ast::AssocItemKind::TyAlias(ref generic_bounds, ref type_default) => { let rewrite = rewrite_associated_type( ti.ident, type_default.as_ref(), @@ -594,25 +608,26 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { ); self.push_rewrite(ti.span, rewrite); } - ast::TraitItemKind::Macro(ref mac) => { + ast::AssocItemKind::Macro(ref mac) => { self.visit_mac(mac, Some(ti.ident), MacroPosition::Item); } } } - pub(crate) fn visit_impl_item(&mut self, ii: &ast::ImplItem) { + pub(crate) fn visit_impl_item(&mut self, ii: &ast::AssocItem) { skip_out_of_file_lines_range_visitor!(self, ii.span); if self.visit_attrs(&ii.attrs, ast::AttrStyle::Outer) { - self.push_skipped_with_span(ii.attrs.as_slice(), ii.span(), ii.span()); + self.push_skipped_with_span(ii.attrs.as_slice(), ii.span, ii.span); return; } match ii.kind { - ast::ImplItemKind::Method(ref sig, ref body) => { + ast::AssocItemKind::Fn(ref sig, Some(ref body)) => { let inner_attrs = inner_attributes(&ii.attrs); + let fn_ctxt = visit::FnCtxt::Assoc(visit::AssocCtxt::Impl); self.visit_fn( - visit::FnKind::Method(ii.ident, sig, Some(&ii.vis), body), + visit::FnKind::Fn(fn_ctxt, ii.ident, sig, &ii.vis, Some(body)), &ii.generics, &sig.decl, ii.span, @@ -620,41 +635,73 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { Some(&inner_attrs), ); } - ast::ImplItemKind::Const(..) => self.visit_static(&StaticParts::from_impl_item(ii)), - ast::ImplItemKind::TyAlias(ref ty) => { - let rewrite = rewrite_associated_impl_type( - ii.ident, - ii.defaultness, - Some(ty), - &ii.generics, - &self.get_context(), - self.block_indent, - ); + ast::AssocItemKind::Fn(ref sig, None) => { + let indent = self.block_indent; + let rewrite = + self.rewrite_required_fn(indent, ii.ident, sig, &ii.generics, ii.span); self.push_rewrite(ii.span, rewrite); } - ast::ImplItemKind::OpaqueTy(ref generic_bounds) => { - let rewrite = rewrite_opaque_impl_type( - &self.get_context(), - ii.ident, - &ii.generics, - generic_bounds, - self.block_indent, - ); + ast::AssocItemKind::Const(..) => self.visit_static(&StaticParts::from_impl_item(ii)), + ast::AssocItemKind::TyAlias(_, ref ty) => { + let rewrite_associated = || { + rewrite_associated_impl_type( + ii.ident, + ii.defaultness, + ty.as_ref(), + &ii.generics, + &self.get_context(), + self.block_indent, + ) + }; + let rewrite = match ty { + None => rewrite_associated(), + Some(ty) => match ty.kind.opaque_top_hack() { + Some(generic_bounds) => rewrite_opaque_impl_type( + &self.get_context(), + ii.ident, + &ii.generics, + generic_bounds, + self.block_indent, + ), + None => rewrite_associated(), + } + }; self.push_rewrite(ii.span, rewrite); } - ast::ImplItemKind::Macro(ref mac) => { + ast::AssocItemKind::Macro(ref mac) => { self.visit_mac(mac, Some(ii.ident), MacroPosition::Item); } } } fn visit_mac(&mut self, mac: &ast::Mac, ident: Option, pos: MacroPosition) { - skip_out_of_file_lines_range_visitor!(self, mac.span); + skip_out_of_file_lines_range_visitor!(self, mac.span()); // 1 = ; let shape = self.shape().saturating_sub_width(1); let rewrite = self.with_context(|ctx| rewrite_macro(mac, ident, ctx, shape, pos)); - self.push_rewrite(mac.span, rewrite); + // As of v638 of the rustc-ap-* crates, the associated span no longer includes + // the trailing semicolon. This determines the correct span to ensure scenarios + // with whitespace between the delimiters and trailing semi (i.e. `foo!(abc) ;`) + // are formatted correctly. + let (span, rewrite) = match macro_style(mac, &self.get_context()) { + DelimToken::Bracket | DelimToken::Paren if MacroPosition::Item == pos => { + let search_span = mk_sp(mac.span().hi(), self.snippet_provider.end_pos()); + let hi = self.snippet_provider.span_before(search_span, ";"); + let target_span = mk_sp(mac.span().lo(), hi + BytePos(1)); + let rewrite = rewrite.map(|rw| { + if !rw.ends_with(";") { + format!("{};", rw) + } else { + rw + } + }); + (target_span, rewrite) + } + _ => (mac.span(), rewrite), + }; + + self.push_rewrite(span, rewrite); } pub(crate) fn push_str(&mut self, s: &str) { @@ -761,16 +808,23 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { ErrorKind::DeprecatedAttr, )], ); - } else if self.is_unknown_rustfmt_attr(&attr.path.segments) { - let file_name = self.parse_sess.span_to_filename(attr.span); - self.report.append( - file_name, - vec![FormattingError::from_span( - attr.span, - self.parse_sess, - ErrorKind::BadAttr, - )], - ); + } else { + match &attr.kind { + ast::AttrKind::Normal(ref attribute_item) + if self.is_unknown_rustfmt_attr(&attribute_item.path.segments) => + { + let file_name = self.parse_sess.span_to_filename(attr.span); + self.report.append( + file_name, + vec![FormattingError::from_span( + attr.span, + self.parse_sess, + ErrorKind::BadAttr, + )], + ); + } + _ => (), + } } } if contains_skip(attrs) { diff --git a/rustfmt-core/rustfmt-lib/tests/source/issue-2916.rs b/rustfmt-core/rustfmt-lib/tests/source/issue-2916.rs new file mode 100644 index 00000000000..a1bd58b0722 --- /dev/null +++ b/rustfmt-core/rustfmt-lib/tests/source/issue-2916.rs @@ -0,0 +1,2 @@ +a_macro!(name, +) ; diff --git a/rustfmt-core/rustfmt-lib/tests/source/macros.rs b/rustfmt-core/rustfmt-lib/tests/source/macros.rs index 3b286579ca8..3b699dc204c 100644 --- a/rustfmt-core/rustfmt-lib/tests/source/macros.rs +++ b/rustfmt-core/rustfmt-lib/tests/source/macros.rs @@ -199,7 +199,7 @@ fn issue_3174() { gfx_pipeline!(pipe { vbuf: gfx::VertexBuffer = (), out: gfx::RenderTarget = "Target0", -}); +}) ; // #1919 #[test] diff --git a/rustfmt-core/rustfmt-lib/tests/target/issue-2916.rs b/rustfmt-core/rustfmt-lib/tests/target/issue-2916.rs index 5a6471ca863..fb07cc8065c 100644 --- a/rustfmt-core/rustfmt-lib/tests/target/issue-2916.rs +++ b/rustfmt-core/rustfmt-lib/tests/target/issue-2916.rs @@ -1,2 +1,2 @@ -a_macro!(name, +a_macro!(name, );