From c3afb16e1608929a816d6c0e2a0118185199aef1 Mon Sep 17 00:00:00 2001 From: Tinco Andringa Date: Wed, 11 Jul 2018 15:19:32 +0200 Subject: [PATCH 1/9] Track whether module declarations are inline (fixes #12590) --- src/libsyntax/ast.rs | 2 ++ src/libsyntax/ext/build.rs | 1 + src/libsyntax/ext/expand.rs | 1 + src/libsyntax/fold.rs | 4 ++- src/libsyntax/parse/parser.rs | 17 +++++++--- src/libsyntax/print/pprust.rs | 14 ++++++--- src/libsyntax/test.rs | 54 ++++++++++++++++++++++++++++++++ src/test/pretty/issue_12590_a.rs | 17 ++++++++++ src/test/pretty/issue_12590_b.rs | 14 +++++++++ 9 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 src/test/pretty/issue_12590_a.rs create mode 100644 src/test/pretty/issue_12590_b.rs diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 9851749be3765..0fd59d8d9f4d9 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1841,6 +1841,8 @@ pub struct Mod { /// to the last token in the external file. pub inner: Span, pub items: Vec>, + /// For `mod foo;` inline is false, for `mod foo { .. }` it is true. + pub inline: bool, } /// Foreign module declaration. diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index b1bed9602f362..6210003a40da4 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -1101,6 +1101,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ast::ItemKind::Mod(ast::Mod { inner: inner_span, items, + inline: true }) ) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 3bb19121ee308..389224e013edb 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -290,6 +290,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { krate.module = ast::Mod { inner: orig_mod_span, items: vec![], + inline: true, }; }, _ => unreachable!(), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 032393b4f1253..b95ef5f4b7abf 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1036,10 +1036,11 @@ pub fn noop_fold_fn_header(mut header: FnHeader, folder: &mut T) -> F header } -pub fn noop_fold_mod(Mod {inner, items}: Mod, folder: &mut T) -> Mod { +pub fn noop_fold_mod(Mod {inner, items, inline}: Mod, folder: &mut T) -> Mod { Mod { inner: folder.new_span(inner), items: items.move_flat_map(|x| folder.fold_item(x)), + inline: inline, } } @@ -1069,6 +1070,7 @@ pub fn noop_fold_crate(Crate {module, attrs, span}: Crate, None => (ast::Mod { inner: span, items: vec![], + inline: true, }, vec![], span) }; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f57fca2cfcf60..121565222429c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6252,6 +6252,7 @@ impl<'a> Parser<'a> { Ok(ast::Mod { inner: inner_lo.to(hi), items, + inline: true }) } @@ -6287,8 +6288,10 @@ impl<'a> Parser<'a> { // This mod is in an external file. Let's go get it! let ModulePathSuccess { path, directory_ownership, warn } = self.submod_path(id, &outer_attrs, id_span)?; - let (module, mut attrs) = + let (mut module, mut attrs) = self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?; + // Record that we fetched the mod from an external file + module.inline = false; if warn { let attr = Attribute { id: attr::mk_attr_id(), @@ -6301,9 +6304,13 @@ impl<'a> Parser<'a> { attr::mark_known(&attr); attrs.push(attr); } - Ok((id, module, Some(attrs))) + Ok((id, ItemKind::Mod(module), Some(attrs))) } else { - let placeholder = ast::Mod { inner: syntax_pos::DUMMY_SP, items: Vec::new() }; + let placeholder = ast::Mod { + inner: syntax_pos::DUMMY_SP, + items: Vec::new(), + inline: false + }; Ok((id, ItemKind::Mod(placeholder), None)) } } else { @@ -6503,7 +6510,7 @@ impl<'a> Parser<'a> { directory_ownership: DirectoryOwnership, name: String, id_sp: Span) - -> PResult<'a, (ast::ItemKind, Vec )> { + -> PResult<'a, (ast::Mod, Vec )> { let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut(); if let Some(i) = included_mod_stack.iter().position(|p| *p == path) { let mut err = String::from("circular modules: "); @@ -6525,7 +6532,7 @@ impl<'a> Parser<'a> { let mod_attrs = p0.parse_inner_attributes()?; let m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?; self.sess.included_mod_stack.borrow_mut().pop(); - Ok((ast::ItemKind::Mod(m0), mod_attrs)) + Ok((m0, mod_attrs)) } /// Parse a function declaration from a foreign module diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 85d29a5be89db..fb4000294ea60 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1260,10 +1260,16 @@ impl<'a> State<'a> { ast::ItemKind::Mod(ref _mod) => { self.head(&visibility_qualified(&item.vis, "mod"))?; self.print_ident(item.ident)?; - self.nbsp()?; - self.bopen()?; - self.print_mod(_mod, &item.attrs)?; - self.bclose(item.span)?; + + if _mod.inline { + self.nbsp()?; + self.bopen()?; + self.print_mod(_mod, &item.attrs)?; + self.bclose(item.span)?; + } else { + self.s.word(";")?; + } + } ast::ItemKind::ForeignMod(ref nmod) => { self.head("extern")?; diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index ab67736c389c0..408f250fd4505 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -240,6 +240,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt, let reexport_mod = ast::Mod { inner: DUMMY_SP, items, + inline: true, }; let sym = Ident::with_empty_ctxt(Symbol::gensym("__test_reexports")); @@ -392,6 +393,59 @@ fn mk_main(cx: &mut TestCtxt) -> P { tokens: None, }) + let testmod = ast::Mod { + inner: DUMMY_SP, + items: vec![import, mainfn, tests], + inline: true, + }; + let item_ = ast::ItemKind::Mod(testmod); + let mod_ident = Ident::with_empty_ctxt(Symbol::gensym("__test")); + + let mut expander = cx.ext_cx.monotonic_expander(); + let item = expander.fold_item(P(ast::Item { + id: ast::DUMMY_NODE_ID, + ident: mod_ident, + attrs: vec![], + node: item_, + vis: dummy_spanned(ast::VisibilityKind::Public), + span: DUMMY_SP, + tokens: None, + })).pop().unwrap(); + let reexport = cx.reexport_test_harness_main.map(|s| { + // building `use __test::main as ;` + let rename = Ident::with_empty_ctxt(s); + + let use_path = ast::UseTree { + span: DUMMY_SP, + prefix: path_node(vec![mod_ident, Ident::from_str("main")]), + kind: ast::UseTreeKind::Simple(Some(rename), ast::DUMMY_NODE_ID, ast::DUMMY_NODE_ID), + }; + + expander.fold_item(P(ast::Item { + id: ast::DUMMY_NODE_ID, + ident: keywords::Invalid.ident(), + attrs: vec![], + node: ast::ItemKind::Use(P(use_path)), + vis: dummy_spanned(ast::VisibilityKind::Inherited), + span: DUMMY_SP, + tokens: None, + })).pop().unwrap() + }); + + debug!("Synthetic test module:\n{}\n", pprust::item_to_string(&item)); + + (item, reexport) +} + +fn nospan(t: T) -> codemap::Spanned { + codemap::Spanned { node: t, span: DUMMY_SP } +} + +fn path_node(ids: Vec) -> ast::Path { + ast::Path { + span: DUMMY_SP, + segments: ids.into_iter().map(|id| ast::PathSegment::from_ident(id)).collect(), + } } fn path_name_i(idents: &[Ident]) -> String { diff --git a/src/test/pretty/issue_12590_a.rs b/src/test/pretty/issue_12590_a.rs new file mode 100644 index 0000000000000..0087c3c455897 --- /dev/null +++ b/src/test/pretty/issue_12590_a.rs @@ -0,0 +1,17 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// pp-exact + +// The next line should not be expanded + +mod issue_12590_b; + +fn main() { } diff --git a/src/test/pretty/issue_12590_b.rs b/src/test/pretty/issue_12590_b.rs new file mode 100644 index 0000000000000..ebb6310b04764 --- /dev/null +++ b/src/test/pretty/issue_12590_b.rs @@ -0,0 +1,14 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Second part of two file test +fn b() { } + +fn main() { } From 81a8ee8fc4822a651aaea722d7920c0f780e9041 Mon Sep 17 00:00:00 2001 From: Tinco Andringa Date: Thu, 12 Jul 2018 23:35:40 +0200 Subject: [PATCH 2/9] pretty=expanded should expand mod declarations --- src/libsyntax/parse/parser.rs | 6 +++--- src/libsyntax/print/pprust.rs | 13 ++++++++++--- src/test/pretty/issue_12590_c.pp | 24 ++++++++++++++++++++++++ src/test/pretty/issue_12590_c.rs | 18 ++++++++++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 src/test/pretty/issue_12590_c.pp create mode 100644 src/test/pretty/issue_12590_c.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 121565222429c..16f1a1ad846d8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6288,10 +6288,9 @@ impl<'a> Parser<'a> { // This mod is in an external file. Let's go get it! let ModulePathSuccess { path, directory_ownership, warn } = self.submod_path(id, &outer_attrs, id_span)?; - let (mut module, mut attrs) = + let (module, mut attrs) = self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?; // Record that we fetched the mod from an external file - module.inline = false; if warn { let attr = Attribute { id: attr::mk_attr_id(), @@ -6530,7 +6529,8 @@ impl<'a> Parser<'a> { p0.cfg_mods = self.cfg_mods; let mod_inner_lo = p0.span; let mod_attrs = p0.parse_inner_attributes()?; - let m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?; + let mut m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?; + m0.inline = false; self.sess.included_mod_stack.borrow_mut().pop(); Ok((m0, mod_attrs)) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index fb4000294ea60..74ac57a634b52 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -61,6 +61,7 @@ pub struct State<'a> { cur_cmnt: usize, boxes: Vec, ann: &'a (dyn PpAnn+'a), + is_expanded: bool } fn rust_printer<'a>(writer: Box, ann: &'a dyn PpAnn) -> State<'a> { @@ -72,6 +73,7 @@ fn rust_printer<'a>(writer: Box, ann: &'a dyn PpAnn) -> State<'a> cur_cmnt: 0, boxes: Vec::new(), ann, + is_expanded: false } } @@ -133,14 +135,17 @@ impl<'a> State<'a> { // If the code is post expansion, don't use the table of // literals, since it doesn't correspond with the literals // in the AST anymore. - if is_expanded { None } else { Some(lits) }) + if is_expanded { None } else { Some(lits) }, + is_expanded + ) } pub fn new(cm: &'a SourceMap, out: Box, ann: &'a dyn PpAnn, comments: Option>, - literals: Option>) -> State<'a> { + literals: Option>, + is_expanded: bool) -> State<'a> { State { s: pp::mk_printer(out, DEFAULT_COLUMNS), cm: Some(cm), @@ -149,6 +154,7 @@ impl<'a> State<'a> { cur_cmnt: 0, boxes: Vec::new(), ann, + is_expanded: is_expanded } } } @@ -1261,7 +1267,8 @@ impl<'a> State<'a> { self.head(&visibility_qualified(&item.vis, "mod"))?; self.print_ident(item.ident)?; - if _mod.inline { + if _mod.inline || self.is_expanded { + println!("Going to print inline anyway"); self.nbsp()?; self.bopen()?; self.print_mod(_mod, &item.attrs)?; diff --git a/src/test/pretty/issue_12590_c.pp b/src/test/pretty/issue_12590_c.pp new file mode 100644 index 0000000000000..359b55a735abb --- /dev/null +++ b/src/test/pretty/issue_12590_c.pp @@ -0,0 +1,24 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// pp-exact:issue_12590_c.pp +// pretty-mode:expanded + +// The next line should be expanded + +mod issue_12590_b { + + + fn b() { } + + fn main() { } +} + +fn main() { } diff --git a/src/test/pretty/issue_12590_c.rs b/src/test/pretty/issue_12590_c.rs new file mode 100644 index 0000000000000..a6b81fdefe6b8 --- /dev/null +++ b/src/test/pretty/issue_12590_c.rs @@ -0,0 +1,18 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// pp-exact:issue_12590_c.pp +// pretty-mode:expanded + +// The next line should be expanded + +mod issue_12590_b; + +fn main() { } From 23ee94e92b2111a65de9b6269df858a565656ff8 Mon Sep 17 00:00:00 2001 From: Tinco Andringa Date: Fri, 13 Jul 2018 23:36:50 +0200 Subject: [PATCH 3/9] Correctly close indentation blocks when pretty printing non-inline module --- src/libsyntax/print/pprust.rs | 3 ++- src/test/pretty/issue_12590_c.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 74ac57a634b52..f2acdb3f469d1 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1268,13 +1268,14 @@ impl<'a> State<'a> { self.print_ident(item.ident)?; if _mod.inline || self.is_expanded { - println!("Going to print inline anyway"); self.nbsp()?; self.bopen()?; self.print_mod(_mod, &item.attrs)?; self.bclose(item.span)?; } else { self.s.word(";")?; + self.end()?; // end inner head-block + self.end()?; // end outer head-block } } diff --git a/src/test/pretty/issue_12590_c.rs b/src/test/pretty/issue_12590_c.rs index a6b81fdefe6b8..e3db870ae4f48 100644 --- a/src/test/pretty/issue_12590_c.rs +++ b/src/test/pretty/issue_12590_c.rs @@ -8,8 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// pp-exact:issue_12590_c.pp +// pretty-compare-only // pretty-mode:expanded +// pp-exact:issue_12590_c.pp // The next line should be expanded From e4f47f43a6b2c26a5eef7d4a71379c47a6ea4eaf Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 17 Jul 2018 17:00:34 +0200 Subject: [PATCH 4/9] Update `compiletest` so that the pretty tests only read from stdin when they *have* to. This allows us to test expansion of files that use `mod foo;` syntax. --- src/tools/compiletest/src/runtest.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 24b575aae12f9..261986af52f21 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -240,6 +240,11 @@ struct DebuggerCommands { breakpoint_lines: Vec, } +enum ReadFrom { + Path, + Stdin, +} + impl<'test> TestCx<'test> { /// Code executed for each revision in turn (or, if there are no /// revisions, exactly once, with revision == None). @@ -421,7 +426,10 @@ impl<'test> TestCx<'test> { round, self.revision ), ); - let proc_res = self.print_source(srcs[round].to_owned(), &self.props.pretty_mode); + let read_from = if round == 0 { ReadFrom::Path } else { ReadFrom::Stdin }; + let proc_res = self.print_source(srcs[round].to_owned(), + &self.props.pretty_mode, + read_from); if !proc_res.status.success() { self.fatal_proc_rec( @@ -477,7 +485,7 @@ impl<'test> TestCx<'test> { } // additionally, run `--pretty expanded` and try to build it. - let proc_res = self.print_source(srcs[round].clone(), "expanded"); + let proc_res = self.print_source(srcs[round].clone(), "expanded", ReadFrom::Path); if !proc_res.status.success() { self.fatal_proc_rec("pretty-printing (expanded) failed", &proc_res); } @@ -495,12 +503,16 @@ impl<'test> TestCx<'test> { } } - fn print_source(&self, src: String, pretty_type: &str) -> ProcRes { + fn print_source(&self, src: String, pretty_type: &str, read_from: ReadFrom) -> ProcRes { let aux_dir = self.aux_output_dir_name(); + let input: &str = match read_from { + ReadFrom::Stdin => "-", + ReadFrom::Path => self.testpaths.file.to_str().unwrap(), + }; let mut rustc = Command::new(&self.config.rustc_path); rustc - .arg("-") + .arg(input) .args(&["-Z", &format!("unpretty={}", pretty_type)]) .args(&["--target", &self.config.target]) .arg("-L") From 9478190afc5bbe4bbfe5367673c2f209dddb37e4 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 17 Jul 2018 17:00:51 +0200 Subject: [PATCH 5/9] Fixed the test to match the compiler's output. --- src/test/pretty/issue_12590_c.pp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/test/pretty/issue_12590_c.pp b/src/test/pretty/issue_12590_c.pp index 359b55a735abb..b4751eb66f626 100644 --- a/src/test/pretty/issue_12590_c.pp +++ b/src/test/pretty/issue_12590_c.pp @@ -1,3 +1,9 @@ +#![feature(prelude_import)] +#![no_std] +#[prelude_import] +use std::prelude::v1::*; +#[macro_use] +extern crate std; // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. @@ -8,17 +14,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// pp-exact:issue_12590_c.pp +// pretty-compare-only // pretty-mode:expanded +// pp-exact:issue_12590_c.pp // The next line should be expanded mod issue_12590_b { - - fn b() { } - - fn main() { } + fn b() { } + fn main() { } } - fn main() { } From ca901a187c9104b91de0d2370025024397c90832 Mon Sep 17 00:00:00 2001 From: Tinco Andringa Date: Mon, 10 Sep 2018 12:10:41 +0200 Subject: [PATCH 6/9] dont pass in src if we are not reading from stdin in compiletest --- src/tools/compiletest/src/runtest.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 261986af52f21..4cc63640d148b 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -521,11 +521,16 @@ impl<'test> TestCx<'test> { .args(&self.props.compile_flags) .envs(self.props.exec_env.clone()); + let src_to_read = match read_from { + ReadFrom::Stdin => Some(src), + ReadFrom::Path => None + }; + self.compose_and_run( rustc, self.config.compile_lib_path.to_str().unwrap(), Some(aux_dir.to_str().unwrap()), - Some(src), + src_to_read, ) } From 518bcffa317db45e437a5e425fb3d7f29e6cab0c Mon Sep 17 00:00:00 2001 From: Tinco Andringa Date: Mon, 10 Sep 2018 12:28:30 +0200 Subject: [PATCH 7/9] refactor so that it's no longer possible to call print_source incorrectly --- src/tools/compiletest/src/runtest.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 4cc63640d148b..c9ddd5f00f23c 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -242,7 +242,7 @@ struct DebuggerCommands { enum ReadFrom { Path, - Stdin, + Stdin(String), } impl<'test> TestCx<'test> { @@ -426,11 +426,14 @@ impl<'test> TestCx<'test> { round, self.revision ), ); - let read_from = if round == 0 { ReadFrom::Path } else { ReadFrom::Stdin }; - let proc_res = self.print_source(srcs[round].to_owned(), - &self.props.pretty_mode, - read_from); + let read_from = if round == 0 { + ReadFrom::Path + } else { + ReadFrom::Stdin(srcs[round].to_owned()) + }; + let proc_res = self.print_source(read_from, + &self.props.pretty_mode); if !proc_res.status.success() { self.fatal_proc_rec( &format!( @@ -485,7 +488,7 @@ impl<'test> TestCx<'test> { } // additionally, run `--pretty expanded` and try to build it. - let proc_res = self.print_source(srcs[round].clone(), "expanded", ReadFrom::Path); + let proc_res = self.print_source(ReadFrom::Path, "expanded"); if !proc_res.status.success() { self.fatal_proc_rec("pretty-printing (expanded) failed", &proc_res); } @@ -503,10 +506,10 @@ impl<'test> TestCx<'test> { } } - fn print_source(&self, src: String, pretty_type: &str, read_from: ReadFrom) -> ProcRes { + fn print_source(&self, read_from: ReadFrom, pretty_type: &str) -> ProcRes { let aux_dir = self.aux_output_dir_name(); let input: &str = match read_from { - ReadFrom::Stdin => "-", + ReadFrom::Stdin(_) => "-", ReadFrom::Path => self.testpaths.file.to_str().unwrap(), }; @@ -521,8 +524,8 @@ impl<'test> TestCx<'test> { .args(&self.props.compile_flags) .envs(self.props.exec_env.clone()); - let src_to_read = match read_from { - ReadFrom::Stdin => Some(src), + let src = match read_from { + ReadFrom::Stdin(src) => Some(src), ReadFrom::Path => None }; @@ -530,7 +533,7 @@ impl<'test> TestCx<'test> { rustc, self.config.compile_lib_path.to_str().unwrap(), Some(aux_dir.to_str().unwrap()), - src_to_read, + src, ) } From ad5c0d49ffb271608e1e3ddbf0898d7005601cd6 Mon Sep 17 00:00:00 2001 From: Tinco Andringa Date: Mon, 10 Sep 2018 15:19:27 +0200 Subject: [PATCH 8/9] reintroduce inline to libsyntax test --- src/libsyntax/test.rs | 55 +------------------------------------------ 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 408f250fd4505..c0c03b46ec704 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -238,9 +238,9 @@ fn mk_reexport_mod(cx: &mut TestCtxt, })).collect(); let reexport_mod = ast::Mod { + inline: true, inner: DUMMY_SP, items, - inline: true, }; let sym = Ident::with_empty_ctxt(Symbol::gensym("__test_reexports")); @@ -393,59 +393,6 @@ fn mk_main(cx: &mut TestCtxt) -> P { tokens: None, }) - let testmod = ast::Mod { - inner: DUMMY_SP, - items: vec![import, mainfn, tests], - inline: true, - }; - let item_ = ast::ItemKind::Mod(testmod); - let mod_ident = Ident::with_empty_ctxt(Symbol::gensym("__test")); - - let mut expander = cx.ext_cx.monotonic_expander(); - let item = expander.fold_item(P(ast::Item { - id: ast::DUMMY_NODE_ID, - ident: mod_ident, - attrs: vec![], - node: item_, - vis: dummy_spanned(ast::VisibilityKind::Public), - span: DUMMY_SP, - tokens: None, - })).pop().unwrap(); - let reexport = cx.reexport_test_harness_main.map(|s| { - // building `use __test::main as ;` - let rename = Ident::with_empty_ctxt(s); - - let use_path = ast::UseTree { - span: DUMMY_SP, - prefix: path_node(vec![mod_ident, Ident::from_str("main")]), - kind: ast::UseTreeKind::Simple(Some(rename), ast::DUMMY_NODE_ID, ast::DUMMY_NODE_ID), - }; - - expander.fold_item(P(ast::Item { - id: ast::DUMMY_NODE_ID, - ident: keywords::Invalid.ident(), - attrs: vec![], - node: ast::ItemKind::Use(P(use_path)), - vis: dummy_spanned(ast::VisibilityKind::Inherited), - span: DUMMY_SP, - tokens: None, - })).pop().unwrap() - }); - - debug!("Synthetic test module:\n{}\n", pprust::item_to_string(&item)); - - (item, reexport) -} - -fn nospan(t: T) -> codemap::Spanned { - codemap::Spanned { node: t, span: DUMMY_SP } -} - -fn path_node(ids: Vec) -> ast::Path { - ast::Path { - span: DUMMY_SP, - segments: ids.into_iter().map(|id| ast::PathSegment::from_ident(id)).collect(), - } } fn path_name_i(idents: &[Ident]) -> String { From b985e91e434a26302f06333414224422f85a1d8b Mon Sep 17 00:00:00 2001 From: Tinco Andringa Date: Mon, 10 Sep 2018 15:44:42 +0200 Subject: [PATCH 9/9] update result of issue 12590 test --- src/test/pretty/issue_12590_c.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/pretty/issue_12590_c.pp b/src/test/pretty/issue_12590_c.pp index b4751eb66f626..7e057406d830f 100644 --- a/src/test/pretty/issue_12590_c.pp +++ b/src/test/pretty/issue_12590_c.pp @@ -1,7 +1,7 @@ #![feature(prelude_import)] #![no_std] #[prelude_import] -use std::prelude::v1::*; +use ::std::prelude::v1::*; #[macro_use] extern crate std; // Copyright 2012 The Rust Project Developers. See the COPYRIGHT