Skip to content

Commit 6cb04d9

Browse files
committed
extract error_decl_mod_in_block
1 parent 9b3364f commit 6cb04d9

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/librustc_parse/parser/module.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,22 @@ impl<'a> Parser<'a> {
129129
DirectoryOwnership::Owned { .. } => {
130130
paths.result.map_err(|err| self.span_fatal_err(id_sp, err))
131131
}
132-
DirectoryOwnership::UnownedViaBlock => {
133-
let msg = "Cannot declare a non-inline module inside a block \
134-
unless it has a path attribute";
135-
let mut err = self.struct_span_err(id_sp, msg);
136-
if paths.path_exists {
137-
let msg = format!(
138-
"Maybe `use` the module `{}` instead of redeclaring it",
139-
paths.name
140-
);
141-
err.span_note(id_sp, &msg);
142-
}
143-
Err(err)
144-
}
132+
DirectoryOwnership::UnownedViaBlock => self.error_decl_mod_in_block(id_sp, paths),
145133
DirectoryOwnership::UnownedViaMod => self.error_cannot_declare_mod_here(id_sp, paths),
146134
}
147135
}
148136

137+
fn error_decl_mod_in_block<T>(&self, id_sp: Span, paths: ModulePath) -> PResult<'a, T> {
138+
let msg =
139+
"Cannot declare a non-inline module inside a block unless it has a path attribute";
140+
let mut err = self.struct_span_err(id_sp, msg);
141+
if paths.path_exists {
142+
let msg = format!("Maybe `use` the module `{}` instead of redeclaring it", paths.name);
143+
err.span_note(id_sp, &msg);
144+
}
145+
Err(err)
146+
}
147+
149148
fn error_cannot_declare_mod_here<T>(&self, id_sp: Span, paths: ModulePath) -> PResult<'a, T> {
150149
let mut err = self.struct_span_err(id_sp, "cannot declare a new module at this location");
151150
if !id_sp.is_dummy() {

0 commit comments

Comments
 (0)