diff options
| author | bors <bors@rust-lang.org> | 2019-12-23 02:47:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-12-23 02:47:52 +0000 |
| commit | a916ac22b9f7f1f0f7aba0a41a789b3ecd765018 (patch) | |
| tree | 139cba4184f0f290fdbdff1aa0aa68352b16ccbb /src/libsyntax_ext/source_util.rs | |
| parent | 9b98af84c4aa66392236fff59c86da2130d46d46 (diff) | |
| parent | 0f24ccd21d9f734a21daaf3566900127167556d1 (diff) | |
Auto merge of #67540 - Mark-Simulacrum:fmt-the-world, r=Centril
Format the world This PR modifies the formatting infrastructure a bit in the first commit (to enable the forgotten 2018 edition), as well as removes most directories from the ignore list in rustfmt.toml. It then follows that up with the second commit which runs `x.py fmt` and formats the entire repository. We continue to not format the test directory (`src/test`) because of interactions with pretty printing and, in part, because re-blessing all of those files is somewhat harder to review, so is best suited for a follow up PR in my opinion.
Diffstat (limited to 'src/libsyntax_ext/source_util.rs')
| -rw-r--r-- | src/libsyntax_ext/source_util.rs | 89 |
1 files changed, 58 insertions, 31 deletions
diff --git a/src/libsyntax_ext/source_util.rs b/src/libsyntax_ext/source_util.rs index 4aab68d7c0e..4f46252f8be 100644 --- a/src/libsyntax_ext/source_util.rs +++ b/src/libsyntax_ext/source_util.rs @@ -1,13 +1,13 @@ -use rustc_parse::{self, DirectoryOwnership, new_sub_parser_from_file, parser::Parser}; +use rustc_parse::{self, new_sub_parser_from_file, parser::Parser, DirectoryOwnership}; use syntax::ast; +use syntax::early_buffered_lints::INCOMPLETE_INCLUDE; use syntax::print::pprust; use syntax::ptr::P; use syntax::symbol::Symbol; use syntax::token; use syntax::tokenstream::TokenStream; -use syntax::early_buffered_lints::INCOMPLETE_INCLUDE; -use syntax_expand::panictry; use syntax_expand::base::{self, *}; +use syntax_expand::panictry; use smallvec::SmallVec; use syntax_pos::{self, Pos, Span}; @@ -19,8 +19,11 @@ use rustc_data_structures::sync::Lrc; // a given file into the current one. /// line!(): expands to the current line number -pub fn expand_line(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) - -> Box<dyn base::MacResult+'static> { +pub fn expand_line( + cx: &mut ExtCtxt<'_>, + sp: Span, + tts: TokenStream, +) -> Box<dyn base::MacResult + 'static> { let sp = cx.with_def_site_ctxt(sp); base::check_zero_tts(cx, sp, tts, "line!"); @@ -31,8 +34,11 @@ pub fn expand_line(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) } /* column!(): expands to the current column number */ -pub fn expand_column(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) - -> Box<dyn base::MacResult+'static> { +pub fn expand_column( + cx: &mut ExtCtxt<'_>, + sp: Span, + tts: TokenStream, +) -> Box<dyn base::MacResult + 'static> { let sp = cx.with_def_site_ctxt(sp); base::check_zero_tts(cx, sp, tts, "column!"); @@ -45,8 +51,11 @@ pub fn expand_column(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) /// file!(): expands to the current filename */ /// The source_file (`loc.file`) contains a bunch more information we could spit /// out if we wanted. -pub fn expand_file(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) - -> Box<dyn base::MacResult+'static> { +pub fn expand_file( + cx: &mut ExtCtxt<'_>, + sp: Span, + tts: TokenStream, +) -> Box<dyn base::MacResult + 'static> { let sp = cx.with_def_site_ctxt(sp); base::check_zero_tts(cx, sp, tts, "file!"); @@ -55,15 +64,21 @@ pub fn expand_file(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) base::MacEager::expr(cx.expr_str(topmost, Symbol::intern(&loc.file.name.to_string()))) } -pub fn expand_stringify(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) - -> Box<dyn base::MacResult+'static> { +pub fn expand_stringify( + cx: &mut ExtCtxt<'_>, + sp: Span, + tts: TokenStream, +) -> Box<dyn base::MacResult + 'static> { let sp = cx.with_def_site_ctxt(sp); let s = pprust::tts_to_string(tts); base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&s))) } -pub fn expand_mod(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) - -> Box<dyn base::MacResult+'static> { +pub fn expand_mod( + cx: &mut ExtCtxt<'_>, + sp: Span, + tts: TokenStream, +) -> Box<dyn base::MacResult + 'static> { let sp = cx.with_def_site_ctxt(sp); base::check_zero_tts(cx, sp, tts, "module_path!"); let mod_path = &cx.current_expansion.module.mod_path; @@ -75,8 +90,11 @@ pub fn expand_mod(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) /// include! : parse the given file as an expr /// This is generally a bad idea because it's going to behave /// unhygienically. -pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) - -> Box<dyn base::MacResult+'cx> { +pub fn expand_include<'cx>( + cx: &'cx mut ExtCtxt<'_>, + sp: Span, + tts: TokenStream, +) -> Box<dyn base::MacResult + 'cx> { let sp = cx.with_def_site_ctxt(sp); let file = match get_single_str_from_tts(cx, sp, tts, "include!") { Some(f) => f, @@ -88,7 +106,7 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) Err(mut err) => { err.emit(); return DummyResult::any(sp); - }, + } }; let directory_ownership = DirectoryOwnership::Owned { relative: None }; let p = new_sub_parser_from_file(cx.parse_sess(), &file, directory_ownership, None, sp); @@ -115,10 +133,15 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) while self.p.token != token::Eof { match panictry!(self.p.parse_item()) { Some(item) => ret.push(item), - None => self.p.sess.span_diagnostic.span_fatal(self.p.token.span, - &format!("expected item, found `{}`", - self.p.this_token_to_string())) - .raise() + None => self + .p + .sess + .span_diagnostic + .span_fatal( + self.p.token.span, + &format!("expected item, found `{}`", self.p.this_token_to_string()), + ) + .raise(), } } Some(ret) @@ -129,19 +152,22 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) } // include_str! : read the given file, insert it as a literal string expr -pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) - -> Box<dyn base::MacResult+'static> { +pub fn expand_include_str( + cx: &mut ExtCtxt<'_>, + sp: Span, + tts: TokenStream, +) -> Box<dyn base::MacResult + 'static> { let sp = cx.with_def_site_ctxt(sp); let file = match get_single_str_from_tts(cx, sp, tts, "include_str!") { Some(f) => f, - None => return DummyResult::any(sp) + None => return DummyResult::any(sp), }; let file = match cx.resolve_path(file, sp) { Ok(f) => f, Err(mut err) => { err.emit(); return DummyResult::any(sp); - }, + } }; match cx.source_map().load_binary_file(&file) { Ok(bytes) => match std::str::from_utf8(&bytes) { @@ -161,24 +187,25 @@ pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) } } -pub fn expand_include_bytes(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) - -> Box<dyn base::MacResult+'static> { +pub fn expand_include_bytes( + cx: &mut ExtCtxt<'_>, + sp: Span, + tts: TokenStream, +) -> Box<dyn base::MacResult + 'static> { let sp = cx.with_def_site_ctxt(sp); let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") { Some(f) => f, - None => return DummyResult::any(sp) + None => return DummyResult::any(sp), }; let file = match cx.resolve_path(file, sp) { Ok(f) => f, Err(mut err) => { err.emit(); return DummyResult::any(sp); - }, + } }; match cx.source_map().load_binary_file(&file) { - Ok(bytes) => { - base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))) - }, + Ok(bytes) => base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))), Err(e) => { cx.span_err(sp, &format!("couldn't read {}: {}", file.display(), e)); DummyResult::any(sp) |
