From 3f97b2a65c31a1c53c29d233d6b37b0258e4a6b2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 24 Apr 2017 16:26:04 +0200 Subject: [PATCH] Add ui tests --- src/libsyntax/parse/parser.rs | 11 ++++------- .../auxiliary/foo/bar.rs | 0 .../auxiliary/foo/mod.rs | 0 .../invalid-module-declaration.rs | 0 .../invalid-module-declaration.stderr | 14 ++++++++++++++ 5 files changed, 18 insertions(+), 7 deletions(-) rename src/test/{compile-fail => ui/invalid-module-declaration}/auxiliary/foo/bar.rs (100%) rename src/test/{compile-fail => ui/invalid-module-declaration}/auxiliary/foo/mod.rs (100%) rename src/test/{compile-fail => ui/invalid-module-declaration}/invalid-module-declaration.rs (100%) create mode 100644 src/test/ui/invalid-module-declaration/invalid-module-declaration.stderr diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9df791c1c124e..afdb0cc4fdb79 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -57,10 +57,10 @@ use tokenstream::{self, Delimited, ThinTokenStream, TokenTree, TokenStream}; use symbol::{Symbol, keywords}; use util::ThinVec; +use std::cmp; use std::collections::HashSet; use std::mem; -use std::path::{Path, PathBuf}; -use std::rc::Rc; +use std::path::{self, Path, PathBuf}; use std::slice; bitflags! { @@ -5367,7 +5367,7 @@ impl<'a> Parser<'a> { "cannot declare a new module at this location"); if id_sp != syntax_pos::DUMMY_SP { let src_path = PathBuf::from(self.sess.codemap().span_to_filename(id_sp)); - if let Some(stem) = src_path.clone().file_stem() { + if let Some(stem) = src_path.file_stem() { let mut dest_path = src_path.clone(); dest_path.set_file_name(stem); dest_path.push("mod.rs"); @@ -5385,10 +5385,7 @@ impl<'a> Parser<'a> { } Err(err) } else { - match paths.result { - Ok(succ) => Ok(succ), - Err(err) => Err(self.span_fatal_err(id_sp, err)), - } + paths.result.map_err(|err| self.span_fatal_err(id_sp, err)) } } diff --git a/src/test/compile-fail/auxiliary/foo/bar.rs b/src/test/ui/invalid-module-declaration/auxiliary/foo/bar.rs similarity index 100% rename from src/test/compile-fail/auxiliary/foo/bar.rs rename to src/test/ui/invalid-module-declaration/auxiliary/foo/bar.rs diff --git a/src/test/compile-fail/auxiliary/foo/mod.rs b/src/test/ui/invalid-module-declaration/auxiliary/foo/mod.rs similarity index 100% rename from src/test/compile-fail/auxiliary/foo/mod.rs rename to src/test/ui/invalid-module-declaration/auxiliary/foo/mod.rs diff --git a/src/test/compile-fail/invalid-module-declaration.rs b/src/test/ui/invalid-module-declaration/invalid-module-declaration.rs similarity index 100% rename from src/test/compile-fail/invalid-module-declaration.rs rename to src/test/ui/invalid-module-declaration/invalid-module-declaration.rs diff --git a/src/test/ui/invalid-module-declaration/invalid-module-declaration.stderr b/src/test/ui/invalid-module-declaration/invalid-module-declaration.stderr new file mode 100644 index 0000000000000..3e9b21cdb740f --- /dev/null +++ b/src/test/ui/invalid-module-declaration/invalid-module-declaration.stderr @@ -0,0 +1,14 @@ +error: cannot declare a new module at this location + --> $DIR/auxiliary/foo/bar.rs:11:9 + | +11 | pub mod baz; + | ^^^ + | +note: maybe move this module `$DIR/auxiliary/foo/bar.rs` to its own directory via `$DIR/auxiliary/foo/bar/mod.rs` + --> $DIR/auxiliary/foo/bar.rs:11:9 + | +11 | pub mod baz; + | ^^^ + +error: aborting due to previous error +