8000 Rollup of 8 pull requests by Centril · Pull Request #70066 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 8 pull requests #70066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d6a17b5
Move tidy check to mingw-check
JohnTitor Mar 4, 2020
726d518
bootstrap: Use hash to determine if sanitizers needs to be rebuilt
tmiasko Mar 5, 2020
d49306d
implement zeroed and uninitialized with MaybeUninit
RalfJung Mar 11, 2020
c7eb0f2
fix expand-to-unstable test
RalfJung Mar 11, 2020
30bf3e1
Remove `free_region_map` from `TypeckTables`
matthewjasper Nov 30, 2019
f206c3e
Don't use `TypeckTables` in NiceRegionError
matthewjasper Feb 15, 2020
1fd3246
Erase regions in writeback
matthewjasper Feb 15, 2020
9772562
Update tests for erasing regions in typeck
matthewjasper Feb 15, 2020
996a51b
init-large-type test needs optimizations
RalfJung Mar 16, 2020
a2160e6
make mem::{zeroed,uninitialized} inline(always)
RalfJung Mar 16, 2020
ec86270
Make macro metavars respect (non-)hygiene
matthewjasper Mar 11, 2020
a4125a6
submod_path_from_attr: simplify & document
Centril Mar 7, 2020
48b9526
extract error_cannot_declare_mod_here
Centril Mar 7, 2020
bbd2129
extract error_decl_mod_in_block
Centril Mar 7, 2020
7042554
simplify submo 8000 d_path
Centril Mar 7, 2020
586c9b5
submod_path: use id.span
Centril Mar 7, 2020
d06031c
extract parse_mod
Centril Mar 7, 2020
a2a32c7
extract error_on_circular_module
Centril Mar 7, 2020
4d05f90
detach submod_path from Parser
Centril Mar 8, 2020
c824f5d
decouple push_directory from Parser
Centril Mar 8, 2020
4a70313
decouple eval_src_mod from Parser
Centril Mar 8, 2020
033f8a2
expand: use push_directory
Centril Mar 8, 2020
60a00b0
de-fatalize outline module parsing
Centril Mar 8, 2020
16d444a
extract parse_external_module
Centril Mar 8, 2020
a1f9953
extract error_on_circular_module
Centril Mar 8, 2020
97fa2bd
outline modules: parse -> expand.
Centril Mar 8, 2020
fb540a9
parse: module parsing -> item.rs
Centril Mar 8, 2020
e2cd4d0
move Directory -> parser::module
Centril Mar 8, 2020
e830157
{rustc_parse::parser -> rustc_expand}::module
Centril Mar 8, 2020
c16f0d3
{rustc_parse -> rustc_expand}::config
Centril Mar 8, 2020
2454395
add test for stripped nested outline module
Centril Mar 8, 2020
ed9d81e
parser/expand: minor cleanup
Centril Mar 9, 2020
9741bb6
tweak outline module parsing spans
Centril Mar 9, 2020
48b8ecc
use pretty-compare-only in a test
Centril Mar 10, 2020
998b33e
fix pre-expansion linting infra
Centril Mar 15, 2020
5cc4e94
fix rebase fallout
Centril Mar 15, 2020
442e5ff
Small fixes in documentation
JOE1994 Mar 17, 2020
194de27
Update books
ehuss Mar 17, 2020
8b0698b
--bless windows test
Centril Mar 17, 2020
9d56bb0
Rollup merge of #68746 - matthewjasper:metahygiene, r=petrochenkov
Centril Mar 17, 2020
fe69360
Rollup merge of #69189 - matthewjasper:erase-the-world, r=nikomatsakis
Centril Mar 17, 2020
2b7c6a3
Rollup merge of #69688 - JohnTitor:move-tidy, r=Mark-Simulacrum
Centril Mar 17, 2020
94603b3
Rollup merge of #69735 - tmiasko:bootstrap-sanitizers-hash, r=Mark-Si…
Centril Mar 17, 2020
90ebf47
Rollup merge of #69838 - Centril:expand-module, r=petrochenkov
Centril Mar 17, 2020
8582b04
Rollup merge of #69922 - RalfJung:less-intrinsic, r=oli-obk
Centril Mar 17, 2020
dd29171
Rollup merge of #70061 - JOE1994:patch-2, r=Dylan-DPC
Centril Mar 17, 2020
2e0141f
Rollup merge of #70064 - ehuss:update-books, r=ehuss
Centril Mar 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tweak outline module parsing spans
  • Loading branch information
Centril committed Mar 16, 2020
commit 9741bb6c3c9e201cfd679040a8813167029d0262
9 changes: 4 additions & 5 deletions src/librustc_expand/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,17 +1368,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {

let mut attrs = mem::take(&mut item.attrs); // We do this to please borrowck.
let ident = item.ident;
let span = item.span;

match item.kind {
ast::ItemKind::MacCall(..) => {
item.attrs = attrs;
self.check_attributes(&item.attrs);
item.and_then(|item| match item.kind {
ItemKind::MacCall(mac) => self
.collect(
AstFragmentKind::Items,
InvocationKind::Bang { mac, span: item.span },
)
.collect(AstFragmentKind::Items, InvocationKind::Bang { mac, span })
.make_items(),
_ => unreachable!(),
})
Expand All @@ -1396,7 +1394,8 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
push_directory(ident, &item.attrs, dir)
} else {
// We have an outline `mod foo;` so we need to parse the file.
let (new_mod, dir) = parse_external_mod(sess, ident, dir, &mut attrs, pushed);
let (new_mod, dir) =
parse_external_mod(sess, ident, span, dir, &mut attrs, pushed);
*old_mod = new_mod;
item.attrs = attrs;
// File can have inline attributes, e.g., `#![cfg(...)]` & co. => Reconfigure.
Expand Down
40 changes: 21 additions & 19 deletions src/librustc_expand/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,26 @@ pub struct ModulePathSuccess {
crate fn parse_external_mod(
sess: &ParseSess,
id: ast::Ident,
span: Span, // The span to blame on errors.
Directory { mut ownership, path }: Directory,
attrs: &mut Vec<Attribute>,
pop_mod_stack: &mut bool,
) -> (Mod, Directory) {
// We bail on the first error, but that error does not cause a fatal error... (1)
let result: PResult<'_, _> = try {
// Extract the file path and the new ownership.
let mp = submod_path(sess, id, &attrs, ownership, &path)?;
let mp = submod_path(sess, id, span, &attrs, ownership, &path)?;
ownership = mp.ownership;

// Ensure file paths are acyclic.
let mut included_mod_stack = sess.included_mod_stack.borrow_mut();
error_on_circular_module(sess, id.span, &mp.path, &included_mod_stack)?;
error_on_circular_module(sess, span, &mp.path, &included_mod_stack)?;
included_mod_stack.push(mp.path.clone());
*pop_mod_stack = true; // We have pushed, so notify caller.
drop(included_mod_stack);

// Actually parse the external file as amodule.
let mut p0 = new_sub_parser_from_file(sess, &mp.path, Some(id.to_string()), id.span);
let mut p0 = new_sub_parser_from_file(sess, &mp.path, Some(id.to_string()), span);
let mut module = p0.parse_mod(&token::Eof)?;
module.0.inline = false;
module
Expand Down Expand Up @@ -126,6 +127,7 @@ crate fn push_directory(
fn submod_path<'a>(
sess: &'a ParseSess,
id: ast::Ident,
span: Span,
attrs: &[Attribute],
ownership: DirectoryOwnership,
dir_path: &Path,
Expand All @@ -150,54 +152,53 @@ fn submod_path<'a>(
DirectoryOwnership::UnownedViaBlock | DirectoryOwnership::UnownedViaMod => None,
};
let ModulePath { path_exists, name, result } =
default_submod_path(sess, id, relative, dir_path);
default_submod_path(sess, id, span, relative, dir_path);
match ownership {
DirectoryOwnership::Owned { .. } => Ok(result?),
DirectoryOwnership::UnownedViaBlock => {
let _ = result.map_err(|mut err| err.cancel());
error_decl_mod_in_block(sess, id.span, path_exists, &name)
error_decl_mod_in_block(sess, span, path_exists, &name)
}
DirectoryOwnership::UnownedViaMod => {
let _ = result.map_err(|mut err| err.cancel());
error_cannot_declare_mod_here(sess, id.span, path_exists, &name)
error_cannot_declare_mod_here(sess, span, path_exists, &name)
}
}
}

fn error_decl_mod_in_block<'a, T>(
sess: &'a ParseSess,
id_sp: Span,
span: Span,
path_exists: bool,
name: &str,
) -> PResult<'a, T> {
let msg = "Cannot declare a non-inline module inside a block unless it has a path attribute";
let mut err = sess.span_diagnostic.struct_span_err(id_sp, msg);
let mut err = sess.span_diagnostic.struct_span_err(span, msg);
if path_exists {
let msg = format!("Maybe `use` the module `{}` instead of redeclaring it", name);
err.span_note(id_sp, &msg);
err.span_note(span, &msg);
}
Err(err)
}

fn error_cannot_declare_mod_here<'a, T>(
sess: &'a ParseSess,
id_sp: Span,
span: Span,
path_exists: bool,
name: &str,
) -> PResult<'a, T> {
let mut err =
sess.span_diagnostic.struct_span_err(id_sp, "cannot declare a new module at this location");
if !id_sp.is_ 8000 dummy() {
if let FileName::Real(src_path) = sess.source_map().span_to_filename(id_sp) {
sess.span_diagnostic.struct_span_err(span, "cannot declare a new module at this location");
if !span.is_dummy() {
if let FileName::Real(src_path) = sess.source_map().span_to_filename(span) {
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");
err.span_note(
id_sp,
span,
&format!(
"maybe move this module `{}` to its own \
directory via `{}`",
"maybe move this module `{}` to its own directory via `{}`",
src_path.display(),
dest_path.display()
),
Expand All @@ -207,7 +208,7 @@ fn error_cannot_declare_mod_here<'a, T>(
}
if path_exists {
err.span_note(
id_sp,
span,
&format!("... or maybe `use` the module `{}` instead of possibly redeclaring it", name),
);
}
Expand Down Expand Up @@ -237,6 +238,7 @@ pub fn submod_path_from_attr(attrs: &[Attribute], dir_path: &Path) -> Option<Pat
pub fn default_submod_path<'a>(
sess: &'a ParseSess,
id: ast::Ident,
span: Span,
relative: Option<ast::Ident>,
dir_path: &Path,
) -> ModulePath<'a> {
Expand Down Expand Up @@ -273,7 +275,7 @@ pub fn default_submod_path<'a>(
(false, false) => {
let mut err = struct_span_err!(
sess.span_diagnostic,
id.span,
span,
E0583,
"file not found for module `{}`",
mod_name,
Expand All @@ -288,7 +290,7 @@ pub fn default_submod_path<'a>(
(true, true) => {
let mut err = struct_span_err!(
sess.span_diagnostic,
id.span,
span,
E0584,
"file for module `{}` found at both {} and {}",
mod_name,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a> Parser<'a> {
}

/// Parses a `mod <foo> { ... }` or `mod <foo>;` item.
pub(super) fn parse_item_mod(&mut self, attrs: &mut Vec<Attribute>) -> PResult<'a, ItemInfo> {
fn parse_item_mod(&mut self, attrs: &mut Vec<Attribute>) -> PResult<'a, ItemInfo> {
let id = self.parse_ident()?;
let (module, mut inner_attrs) = if self.eat(&token::Semi) {
Default::default()
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/directory_ownership/macro-expanded-mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

macro_rules! mod_decl {
($i:ident) => {
mod $i;
mod $i; //~ ERROR Cannot declare a non-inline module inside a block
};
}

Expand All @@ -11,5 +11,5 @@ mod macro_expanded_mod_helper {
}

fn main() {
mod_decl!(foo); //~ ERROR Cannot declare a non-inline module inside a block
mod_decl!(foo);
}
9 changes: 7 additions & 2 deletions src/test/ui/directory_ownership/macro-expanded-mod.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
error: Cannot declare a non-inline module inside a block unless it has a path attribute
--> $DIR/macro-expanded-mod.rs:14:15
--> $DIR/macro-expanded-mod.rs:5:9
|
LL | mod $i;
| ^^^^^^^
...
LL | mod_decl!(foo);
| ^^^
| --------------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Cannot declare a non-inline module inside a block unless it has a path attribute
--> $DIR/non-inline-mod-restriction.rs:4:9
--> $DIR/non-inline-mod-restriction.rs:4:5
|
LL | mod foo;
| ^^^
| ^^^^^^^^

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0583.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0583]: file not found for module `module_that_doesnt_exist`
--> $DIR/E0583.rs:1:5
--> $DIR/E0583.rs:1:1
|
LL | mod module_that_doesnt_exist;
| ^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: to create the module `module_that_doesnt_exist`, create file "$DIR/module_that_doesnt_exist.rs"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0583]: file not found for module `baz`
--> $DIR/auxiliary/foo/bar.rs:1:9
--> $DIR/auxiliary/foo/bar.rs:1:1
|
LL | pub mod baz;
| ^^^
| ^^^^^^^^^^^^
|
= help: to create the module `baz`, create file "$DIR/auxiliary/foo/bar/baz.rs"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0583]: file not found for module `missing`
--> $DIR/foo.rs:4:5
--> $DIR/foo.rs:4:1
|
LL | mod missing;
| ^^^^^^^
| ^^^^^^^^^^^^
|
= help: to create the module `missing`, create file "$DIR/foo/missing.rs"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0583]: file not found for module `missing`
--> $DIR/foo_inline.rs:4:9
--> $DIR/foo_inline.rs:4:5
|
LL | mod missing;
| ^^^^^^^
| ^^^^^^^^^^^^
|
= help: to create the module `missing`, create file "$DIR/foo_inline/inline/missing.rs"

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/mod/mod_file_disambig.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0584]: file for module `mod_file_disambig_aux` found at both mod_file_disambig_aux.rs and mod_file_disambig_aux/mod.rs
--> $DIR/mod_file_disambig.rs:1:5
--> $DIR/mod_file_disambig.rs:1:1
|
LL | mod mod_file_disambig_aux;
| ^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: delete or rename one of them to remove the ambiguity

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/circular_modules_main.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: circular modules: $DIR/circular_modules_hello.rs -> $DIR/circular_modules_main.rs -> $DIR/circular_modules_hello.rs
--> $DIR/circular_modules_main.rs:2:5
--> $DIR/circular_modules_main.rs:2:1
|
LL | mod circular_modules_hello;
| ^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0425]: cannot find function `say_hello` in module `circular_modules_hello`
--> $DIR/circular_modules_main.rs:9:29
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-5806.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: couldn't read $DIR/../parser: $ACCESS_DENIED_MSG (os error $ACCESS_DENIED_CODE)
--> $DIR/issue-5806.rs:5:5
--> $DIR/issue-5806.rs:5:1
|
LL | mod foo;
| ^^^
| ^^^^^^^^

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/mod_file_not_exist.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0583]: file not found for module `not_a_real_file`
--> $DIR/mod_file_not_exist.rs:3:5
--> $DIR/mod_file_not_exist.rs:3:1
|
LL | mod not_a_real_file;
| ^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^
|
= help: to create the module `not_a_real_file`, create file "$DIR/not_a_real_file.rs"

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/mod_file_with_path_attr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: couldn't read $DIR/not_a_real_file.rs: $FILE_NOT_FOUND_MSG (os error 2)
--> $DIR/mod_file_with_path_attr.rs:4:5
--> $DIR/mod_file_with_path_attr.rs:4:1
|
LL | mod m;
| ^
| ^^^^^^

error: aborting due to previous error

0