Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
cbf5f7d
Use TypeRelating for instantiating query responses
matthewjasper Feb 29, 2020
7819335
resolve: Simplify `fn report_privacy_error`
petrochenkov Mar 7, 2020
059e825
resolve: Print import chains on privacy errors
petrochenkov Mar 7, 2020
f2cbe30
submod_path_from_attr: simplify & document
Centril Mar 7, 2020
9b3364f
extract error_cannot_declare_mod_here
Centril Mar 7, 2020
6cb04d9
extract error_decl_mod_in_block
Centril Mar 7, 2020
024af0b
simplify submod_path
Centril Mar 7, 2020
9855b34
submod_path: use id.span
Centril Mar 7, 2020
3eb86cf
extract parse_mod
Centril Mar 7, 2020
cbcb550
extract error_on_circular_module
Centril Mar 7, 2020
996449b
detach submod_path from Parser
Centril Mar 8, 2020
81b3500
decouple push_directory from Parser
Centril Mar 8, 2020
f284eb3
decouple eval_src_mod from Parser
Centril Mar 8, 2020
aff35c4
expand: use push_directory
Centril Mar 8, 2020
75ad1b8
de-fatalize outline module parsing
Centril Mar 8, 2020
e0d001e
extract parse_external_module
Centril Mar 8, 2020
df3792c
extract error_on_circular_module
Centril Mar 8, 2020
a9fd977
outline modules: parse -> expand.
Centril Mar 8, 2020
e994922
parse: module parsing -> item.rs
Centril Mar 8, 2020
65d072d
move Directory -> parser::module
Centril Mar 8, 2020
1b527ae
{rustc_parse::parser -> rustc_expand}::module
Centril Mar 8, 2020
adc3451
{rustc_parse -> rustc_expand}::config
Centril Mar 8, 2020
d171e59
add test for stripped nested outline module
Centril Mar 8, 2020
ad0b078
parser/expand: minor cleanup
Centril Mar 9, 2020
8fba7fb
Use smaller discriminants for generators
jonas-schievink Mar 9, 2020
b16d659
Add a test for generator discriminants
jonas-schievink Mar 9, 2020
906bb8d
fix #62456
contrun Mar 9, 2020
0a0c850
fix test failure due to earlier emitted error
contrun Mar 10, 2020
7df5868
tweak outline module parsing spans
Centril Mar 9, 2020
42ab820
use pretty-compare-only in a test
Centril Mar 10, 2020
9596dc2
parse_labeled_expr: simplify
Centril Mar 5, 2020
c303c44
use error_block_no_opening_brace more
Centril Mar 5, 2020
883e90d
simplify parse_inner_attributes
Centril Mar 5, 2020
8ee220c
more reuse in block parsing & improve diagnostics.
Centril Mar 5, 2020
055733f
parse: recover on `&'lt $expr` / `'lt $expr`.
Centril Mar 5, 2020
379f318
parse: simplify parse_fn_body
Centril Mar 5, 2020
be86b2d
parse: recover on `fn foo() = expr;`
Centril Mar 5, 2020
addbc5b
unify/improve/simplify attribute parsing
Centril Mar 5, 2020
fe848b4
parse_block_tail: reduce visibility
Centril Mar 5, 2020
e72df7e
parse_labeled_expr: add a suggestion on missing colon.
Centril Mar 6, 2020
83be689
parser/attr: adjust indentation.
Centril Mar 7, 2020
65b7ba5
parser: add note for `'label expr`.
Centril Mar 7, 2020
c01b3e6
block-no-opening-brace: add another statement
Centril Mar 7, 2020
09997e7
error_block_no_opening_brace: handle closures better
Centril Mar 7, 2020
25cd01b
issue 68890: add more minimal repro
Centril Mar 7, 2020
c0b073b
simplify & improve parse_ty_tuple_or_parens
Centril Mar 7, 2020
d1822b3
use check_path more
Centril Mar 7, 2020
ba3ae46
trait-object-lifetime-parens: improve recovery.
Centril Mar 7, 2020
458383d
parse_if_expr: recover on attributes
Centril Mar 7, 2020
d562523
Rollup merge of #69591 - matthewjasper:query-response-relate, r=nikom…
Centril Mar 10, 2020
8f39930
Rollup merge of #69760 - Centril:parse-expr-improve, r=estebank
Centril Mar 10, 2020
6a77a75
Rollup merge of #69811 - petrochenkov:privdiag2, r=estebank
Centril Mar 10, 2020
d4a9400
Rollup merge of #69837 - jonas-schievink:gen-discr-opt, r=tmandry
Centril Mar 10, 2020
3b8b04b
Rollup merge of #69838 - Centril:expand-module, r=petrochenkov,eddyb
Centril Mar 10, 2020
9d93aa1
Rollup merge of #69859 - contrun:fix-62456, r=matthewjasper
Centril Mar 10, 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
de-fatalize outline module parsing
  • Loading branch information
Centril committed Mar 8, 2020
commit 75ad1b8a32b15c8c8b1f8f7c794b4417276e3de8
2 changes: 1 addition & 1 deletion src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,7 @@ impl FnRetTy {
/// Module declaration.
///
/// E.g., `mod foo;` or `mod foo { .. }`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default)]
pub struct Mod {
/// A span from the first token past `{` to the last token until `}`.
/// For `mod foo;`, the inner span ranges from the first token
Expand Down
37 changes: 17 additions & 20 deletions src/librustc_parse/parser/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_ast::attr;
use rustc_ast::token::{self, TokenKind};
use rustc_errors::{struct_span_err, PResult};
use rustc_session::parse::ParseSess;
use rustc_span::source_map::{FileName, Span, DUMMY_SP};
use rustc_span::source_map::{FileName, Span};
use rustc_span::symbol::sym;

use std::path::{self, Path, PathBuf};
Expand All @@ -24,7 +24,7 @@ pub struct ModulePath<'a> {
// Public for rustfmt usage.
pub struct ModulePathSuccess {
pub path: PathBuf,
pub directory_ownership: DirectoryOwnership,
pub ownership: DirectoryOwnership,
}

impl<'a> Parser<'a> {
Expand All @@ -45,16 +45,13 @@ impl<'a> Parser<'a> {
let (module, mut inner_attrs) = if self.eat(&token::Semi) {
if in_cfg && self.recurse_into_file_modules {
// This mod is in an external file. Let's go get it!
let ModulePathSuccess { path, directory_ownership } = submod_path(
self.sess,
id,
&attrs,
self.directory.ownership,
&self.directory.path,
)?;
eval_src_mod(self.sess, self.cfg_mods, path, directory_ownership, id)?
let dir = &self.directory;
submod_path(self.sess, id, &attrs, dir.ownership, &dir.path)
.and_then(|r| eval_src_mod(self.sess, self.cfg_mods, r.path, r.ownership, id))
.map_err(|mut err| err.emit())
.unwrap_or_default()
} else {
(ast::Mod { inner: DUMMY_SP, items: Vec::new(), inline: false }, Vec::new())
Default::default()
}
} else {
let old_directory = self.directory.clone();
Expand Down Expand Up @@ -162,12 +159,12 @@ pub fn push_directory(
fn submod_path<'a>(
sess: &'a ParseSess,
id: ast::Ident,
outer_attrs: &[Attribute],
directory_ownership: DirectoryOwnership,
attrs: &[Attribute],
ownership: DirectoryOwnership,
dir_path: &Path,
) -> PResult<'a, ModulePathSuccess> {
if let Some(path) = submod_path_from_attr(outer_attrs, dir_path) {
let directory_ownership = match path.file_name().and_then(|s| s.to_str()) {
if let Some(path) = submod_path_from_attr(attrs, dir_path) {
let ownership = match path.file_name().and_then(|s| s.to_str()) {
// All `#[path]` files are treated as though they are a `mod.rs` file.
// This means that `mod foo;` declarations inside `#[path]`-included
// files are siblings,
Expand All @@ -178,16 +175,16 @@ fn submod_path<'a>(
Some(_) => DirectoryOwnership::Owned { relative: None },
_ => DirectoryOwnership::UnownedViaMod,
};
return Ok(ModulePathSuccess { directory_ownership, path });
return Ok(ModulePathSuccess { ownership, path });
}

let relative = match directory_ownership {
let relative = match ownership {
DirectoryOwnership::Owned { relative } => relative,
DirectoryOwnership::UnownedViaBlock | DirectoryOwnership::UnownedViaMod => None,
};
let ModulePath { path_exists, name, result } =
default_submod_path(sess, id, relative, dir_path);
match directory_ownership {
match ownership {
DirectoryOwnership::Owned { .. } => Ok(result?),
DirectoryOwnership::UnownedViaBlock => {
let _ = result.map_err(|mut err| err.cancel());
Expand Down Expand Up @@ -300,11 +297,11 @@ pub fn default_submod_path<'a>(
let result = match (default_exists, secondary_exists) {
(true, false) => Ok(ModulePathSuccess {
path: default_path,
directory_ownership: DirectoryOwnership::Owned { relative: Some(id) },
ownership: DirectoryOwnership::Owned { relative: Some(id) },
}),
(false, true) => Ok(ModulePathSuccess {
path: secondary_path,
directory_ownership: DirectoryOwnership::Owned { relative: None },
ownership: DirectoryOwnership::Owned { relative: None },
}),
(false, false) => {
let mut err = struct_span_err!(
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/mod/mod_file_disambig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ mod mod_file_disambig_aux; //~ ERROR file for module `mod_file_disambig_aux` fou

fn main() {
assert_eq!(mod_file_aux::bar(), 10);
//~^ ERROR failed to resolve: use of undeclared type or module `mod_file_aux`
}
11 changes: 9 additions & 2 deletions src/test/ui/mod/mod_file_disambig.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ LL | mod mod_file_disambig_aux;
|
= help: delete or rename one of them to remove the ambiguity

error: aborting due to previous error
error[E0433]: failed to resolve: use of undeclared type or module `mod_file_aux`
--> $DIR/mod_file_disambig.rs:4:16
|
LL | assert_eq!(mod_file_aux::bar(), 10);
| ^^^^^^^^^^^^ use of undeclared type or module `mod_file_aux`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0584`.
Some errors have detailed explanations: E0433, E0584.
For more information about an error, try `rustc --explain E0433`.
2 changes: 1 addition & 1 deletion src/test/ui/parser/circular_modules_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ pub fn hi_str() -> String {
}

fn main() {
circular_modules_hello::say_hello();
circular_modules_hello::say_hello(); //~ ERROR cannot find function `say_hello` in module
}
14 changes: 13 additions & 1 deletion src/test/ui/parser/circular_modules_main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,17 @@ error: circular modules: $DIR/circular_modules_hello.rs -> $DIR/circular_modules
LL | mod circular_modules_hello;
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error
error[E0425]: cannot find function `say_hello` in module `circular_modules_hello`
--> $DIR/circular_modules_main.rs:9:29
|
LL | circular_modules_hello::say_hello();
| ^^^^^^^^^ not found in `circular_modules_hello`
|
help: possible candidate is found in another module, you can import it into scope
|
LL | use circular_modules_hello::say_hello;
|

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.
1 change: 1 addition & 0 deletions src/test/ui/parser/mod_file_not_exist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ mod not_a_real_file; //~ ERROR file not found for module `not_a_real_file`

fn main() {
assert_eq!(mod_file_aux::bar(), 10);
//~^ ERROR failed to resolve: use of undeclared type or module `mod_file_aux`
}
11 changes: 9 additions & 2 deletions src/test/ui/parser/mod_file_not_exist.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ LL | mod not_a_real_file;
|
= help: name the file either not_a_real_file.rs or not_a_real_file/mod.rs inside the directory "$DIR"

error: aborting due to previous error
error[E0433]: failed to resolve: use of undeclared type or module `mod_file_aux`
--> $DIR/mod_file_not_exist.rs:7:16
|
LL | assert_eq!(mod_file_aux::bar(), 10);
| ^^^^^^^^^^^^ use of undeclared type or module `mod_file_aux`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0583`.
Some errors have detailed explanations: E0433, E0583.
For more information about an error, try `rustc --explain E0433`.