Add long error explanations
This commit is contained in:
parent
0a45dd7e71
commit
b6818be41d
2 changed files with 85 additions and 20 deletions
|
@ -219,7 +219,7 @@ fn is_ident_or_underscore(t: &token::Token) -> bool {
|
|||
pub struct ModulePath {
|
||||
pub name: String,
|
||||
pub path_exists: bool,
|
||||
pub result: Result<ModulePathSuccess, Errors>,
|
||||
pub result: Result<ModulePathSuccess, Error>,
|
||||
}
|
||||
|
||||
pub struct ModulePathSuccess {
|
||||
|
@ -233,7 +233,7 @@ pub struct ModulePathError {
|
|||
pub help_msg: String,
|
||||
}
|
||||
|
||||
pub enum Errors {
|
||||
pub enum Error {
|
||||
FileNotFoundForModule {
|
||||
mod_name: String,
|
||||
default_path: String,
|
||||
|
@ -249,13 +249,13 @@ pub enum Errors {
|
|||
InclusiveRangeWithNoEnd,
|
||||
}
|
||||
|
||||
impl Errors {
|
||||
impl Error {
|
||||
pub fn span_err<'a>(self, sp: Span, handler: &'a errors::Handler) -> DiagnosticBuilder<'a> {
|
||||
match self {
|
||||
Errors::FileNotFoundForModule { ref mod_name,
|
||||
ref default_path,
|
||||
ref secondary_path,
|
||||
ref dir_path } => {
|
||||
Error::FileNotFoundForModule { ref mod_name,
|
||||
ref default_path,
|
||||
ref secondary_path,
|
||||
ref dir_path } => {
|
||||
let mut err = struct_span_err!(handler, sp, E0583,
|
||||
"file not found for module `{}`", mod_name);
|
||||
err.help(&format!("name the file either {} or {} inside the directory {:?}",
|
||||
|
@ -264,7 +264,7 @@ impl Errors {
|
|||
dir_path));
|
||||
err
|
||||
}
|
||||
Errors::DuplicatePaths { ref mod_name, ref default_path, ref secondary_path } => {
|
||||
Error::DuplicatePaths { ref mod_name, ref default_path, ref secondary_path } => {
|
||||
let mut err = struct_span_err!(handler, sp, E0584,
|
||||
"file for module `{}` found at both {} and {}",
|
||||
mod_name,
|
||||
|
@ -273,14 +273,14 @@ impl Errors {
|
|||
err.help("delete or rename one of them to remove the ambiguity");
|
||||
err
|
||||
}
|
||||
Errors::UselessDocComment => {
|
||||
Error::UselessDocComment => {
|
||||
let mut err = struct_span_err!(handler, sp, E0585,
|
||||
"found a documentation comment that doesn't document anything");
|
||||
err.help("doc comments must come before what they document, maybe a comment was \
|
||||
intended with `//`?");
|
||||
err
|
||||
}
|
||||
Errors::InclusiveRangeWithNoEnd => {
|
||||
Error::InclusiveRangeWithNoEnd => {
|
||||
let mut err = struct_span_err!(handler, sp, E0586,
|
||||
"inclusive range with no end");
|
||||
err.help("inclusive ranges must be bounded at the end (`...b` or `a...b`)");
|
||||
|
@ -518,7 +518,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
_ => {
|
||||
Err(if self.prev_token_kind == PrevTokenKind::DocComment {
|
||||
self.span_fatal_err(self.prev_span, Errors::UselessDocComment)
|
||||
self.span_fatal_err(self.prev_span, Error::UselessDocComment)
|
||||
} else {
|
||||
let mut err = self.fatal(&format!("expected identifier, found `{}`",
|
||||
self.this_token_to_string()));
|
||||
|
@ -1009,7 +1009,7 @@ impl<'a> Parser<'a> {
|
|||
pub fn span_fatal(&self, sp: Span, m: &str) -> DiagnosticBuilder<'a> {
|
||||
self.sess.span_diagnostic.struct_span_fatal(sp, m)
|
||||
}
|
||||
pub fn span_fatal_err(&self, sp: Span, err: Errors) -> DiagnosticBuilder<'a> {
|
||||
pub fn span_fatal_err(&self, sp: Span, err: Error) -> DiagnosticBuilder<'a> {
|
||||
err.span_err(sp, self.diagnostic())
|
||||
}
|
||||
pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str) -> DiagnosticBuilder<'a> {
|
||||
|
@ -2001,7 +2001,7 @@ impl<'a> Parser<'a> {
|
|||
limits: RangeLimits)
|
||||
-> PResult<'a, ast::ExprKind> {
|
||||
if end.is_none() && limits == RangeLimits::Closed {
|
||||
Err(self.span_fatal_err(self.span, Errors::InclusiveRangeWithNoEnd))
|
||||
Err(self.span_fatal_err(self.span, Error::InclusiveRangeWithNoEnd))
|
||||
} else {
|
||||
Ok(ExprKind::Range(start, end, limits))
|
||||
}
|
||||
|
@ -3916,7 +3916,7 @@ impl<'a> Parser<'a> {
|
|||
let unused_attrs = |attrs: &[_], s: &mut Self| {
|
||||
if attrs.len() > 0 {
|
||||
if s.prev_token_kind == PrevTokenKind::DocComment {
|
||||
self.span_fatal_err(s.prev_span, Errors::UselessDocComment).emit();
|
||||
s.span_fatal_err(s.prev_span, Error::UselessDocComment).emit();
|
||||
} else {
|
||||
s.span_err(s.span, "expected statement after outer attribute");
|
||||
}
|
||||
|
@ -5050,7 +5050,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
token::CloseDelim(token::Brace) => {}
|
||||
token::DocComment(_) => return Err(self.span_fatal_err(self.span,
|
||||
Errors::UselessDocComment)),
|
||||
Error::UselessDocComment)),
|
||||
_ => return Err(self.span_fatal_help(self.span,
|
||||
&format!("expected `,`, or `}}`, found `{}`", self.this_token_to_string()),
|
||||
"struct fields should be separated by commas")),
|
||||
|
@ -5231,13 +5231,13 @@ impl<'a> Parser<'a> {
|
|||
directory_ownership: DirectoryOwnership::Owned,
|
||||
warn: false,
|
||||
}),
|
||||
(false, false) => Err(Errors::FileNotFoundForModule {
|
||||
(false, false) => Err(Error::FileNotFoundForModule {
|
||||
mod_name: mod_name.clone(),
|
||||
default_path: default_path_str,
|
||||
secondary_path: secondary_path_str,
|
||||
dir_path: format!("{}", dir_path.display()),
|
||||
}),
|
||||
(true, true) => Err(Errors::DuplicatePaths {
|
||||
(true, true) => Err(Error::DuplicatePaths {
|
||||
mod_name: mod_name.clone(),
|
||||
default_path: default_path_str,
|
||||
secondary_path: secondary_path_str,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue