Add long error explanations
This commit is contained in:
parent
0a45dd7e71
commit
b6818be41d
2 changed files with 85 additions and 20 deletions
|
@ -201,6 +201,74 @@ where appropriate is ongoing. Try using an unquoted name instead:
|
||||||
pub fn something() {}
|
pub fn something() {}
|
||||||
```
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
|
E0583: r##"
|
||||||
|
A file wasn't found for an out-of-line module.
|
||||||
|
|
||||||
|
Erroneous code example:
|
||||||
|
|
||||||
|
```compile_fail,E0583
|
||||||
|
mod file_that_doesnt_exist; // error: file not found for module
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
```
|
||||||
|
|
||||||
|
Please be sure that a file corresponding to the module exists. If you
|
||||||
|
want to use a module named `file_that_doesnt_exist`, you need to have a file
|
||||||
|
named `file_that_doesnt_exist.rs` or `file_that_doesnt_exist/mod.rs` in the
|
||||||
|
same directory.
|
||||||
|
"##,
|
||||||
|
|
||||||
|
E0585: r##"
|
||||||
|
A documentation comment that doesn't document anything was found.
|
||||||
|
|
||||||
|
Erroneous code example:
|
||||||
|
|
||||||
|
```compile_fail,E0585
|
||||||
|
fn main() {
|
||||||
|
// The following doc comment will fail:
|
||||||
|
/// This is a useless doc comment!
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Documentation comments need to be followed by items, including functions,
|
||||||
|
types, modules, etc. Examples:
|
||||||
|
|
||||||
|
```
|
||||||
|
/// I'm documenting the following struct:
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
/// I'm documenting the following function:
|
||||||
|
fn foo() {}
|
||||||
|
```
|
||||||
|
"##,
|
||||||
|
|
||||||
|
E0586: r##"
|
||||||
|
An inclusive range was used with no end.
|
||||||
|
|
||||||
|
Erroneous code example:
|
||||||
|
|
||||||
|
```compile_fail,E0586
|
||||||
|
let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
|
||||||
|
let x = &tmp[1...]; // error: inclusive range was used with no end
|
||||||
|
```
|
||||||
|
|
||||||
|
An inclusive range needs an end in order to *include* it. If you just need a
|
||||||
|
start and no end, use a non-inclusive range (with `..`):
|
||||||
|
|
||||||
|
```
|
||||||
|
let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
|
||||||
|
let x = &tmp[1..]; // ok!
|
||||||
|
```
|
||||||
|
|
||||||
|
Or put an end to your inclusive range:
|
||||||
|
|
||||||
|
```
|
||||||
|
let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
|
||||||
|
let x = &tmp[1...3]; // ok!
|
||||||
|
```
|
||||||
|
"##,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
register_diagnostics! {
|
register_diagnostics! {
|
||||||
|
@ -224,8 +292,5 @@ register_diagnostics! {
|
||||||
E0555, // malformed feature attribute, expected #![feature(...)]
|
E0555, // malformed feature attribute, expected #![feature(...)]
|
||||||
E0556, // malformed feature, expected just one word
|
E0556, // malformed feature, expected just one word
|
||||||
E0557, // feature has been removed
|
E0557, // feature has been removed
|
||||||
E0583, // file not found for module
|
|
||||||
E0584, // file for module `..` found at both .. and ..
|
E0584, // file for module `..` found at both .. and ..
|
||||||
E0585, // documentation comment that doesn't document anything
|
|
||||||
E0586, // inclusive range with no end
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,7 +219,7 @@ fn is_ident_or_underscore(t: &token::Token) -> bool {
|
||||||
pub struct ModulePath {
|
pub struct ModulePath {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub path_exists: bool,
|
pub path_exists: bool,
|
||||||
pub result: Result<ModulePathSuccess, Errors>,
|
pub result: Result<ModulePathSuccess, Error>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ModulePathSuccess {
|
pub struct ModulePathSuccess {
|
||||||
|
@ -233,7 +233,7 @@ pub struct ModulePathError {
|
||||||
pub help_msg: String,
|
pub help_msg: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Errors {
|
pub enum Error {
|
||||||
FileNotFoundForModule {
|
FileNotFoundForModule {
|
||||||
mod_name: String,
|
mod_name: String,
|
||||||
default_path: String,
|
default_path: String,
|
||||||
|
@ -249,10 +249,10 @@ pub enum Errors {
|
||||||
InclusiveRangeWithNoEnd,
|
InclusiveRangeWithNoEnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Errors {
|
impl Error {
|
||||||
pub fn span_err<'a>(self, sp: Span, handler: &'a errors::Handler) -> DiagnosticBuilder<'a> {
|
pub fn span_err<'a>(self, sp: Span, handler: &'a errors::Handler) -> DiagnosticBuilder<'a> {
|
||||||
match self {
|
match self {
|
||||||
Errors::FileNotFoundForModule { ref mod_name,
|
Error::FileNotFoundForModule { ref mod_name,
|
||||||
ref default_path,
|
ref default_path,
|
||||||
ref secondary_path,
|
ref secondary_path,
|
||||||
ref dir_path } => {
|
ref dir_path } => {
|
||||||
|
@ -264,7 +264,7 @@ impl Errors {
|
||||||
dir_path));
|
dir_path));
|
||||||
err
|
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,
|
let mut err = struct_span_err!(handler, sp, E0584,
|
||||||
"file for module `{}` found at both {} and {}",
|
"file for module `{}` found at both {} and {}",
|
||||||
mod_name,
|
mod_name,
|
||||||
|
@ -273,14 +273,14 @@ impl Errors {
|
||||||
err.help("delete or rename one of them to remove the ambiguity");
|
err.help("delete or rename one of them to remove the ambiguity");
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
Errors::UselessDocComment => {
|
Error::UselessDocComment => {
|
||||||
let mut err = struct_span_err!(handler, sp, E0585,
|
let mut err = struct_span_err!(handler, sp, E0585,
|
||||||
"found a documentation comment that doesn't document anything");
|
"found a documentation comment that doesn't document anything");
|
||||||
err.help("doc comments must come before what they document, maybe a comment was \
|
err.help("doc comments must come before what they document, maybe a comment was \
|
||||||
intended with `//`?");
|
intended with `//`?");
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
Errors::InclusiveRangeWithNoEnd => {
|
Error::InclusiveRangeWithNoEnd => {
|
||||||
let mut err = struct_span_err!(handler, sp, E0586,
|
let mut err = struct_span_err!(handler, sp, E0586,
|
||||||
"inclusive range with no end");
|
"inclusive range with no end");
|
||||||
err.help("inclusive ranges must be bounded at the end (`...b` or `a...b`)");
|
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 {
|
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 {
|
} else {
|
||||||
let mut err = self.fatal(&format!("expected identifier, found `{}`",
|
let mut err = self.fatal(&format!("expected identifier, found `{}`",
|
||||||
self.this_token_to_string()));
|
self.this_token_to_string()));
|
||||||
|
@ -1009,7 +1009,7 @@ impl<'a> Parser<'a> {
|
||||||
pub fn span_fatal(&self, sp: Span, m: &str) -> DiagnosticBuilder<'a> {
|
pub fn span_fatal(&self, sp: Span, m: &str) -> DiagnosticBuilder<'a> {
|
||||||
self.sess.span_diagnostic.struct_span_fatal(sp, m)
|
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())
|
err.span_err(sp, self.diagnostic())
|
||||||
}
|
}
|
||||||
pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str) -> DiagnosticBuilder<'a> {
|
pub fn span_fatal_help(&self, sp: Span, m: &str, help: &str) -> DiagnosticBuilder<'a> {
|
||||||
|
@ -2001,7 +2001,7 @@ impl<'a> Parser<'a> {
|
||||||
limits: RangeLimits)
|
limits: RangeLimits)
|
||||||
-> PResult<'a, ast::ExprKind> {
|
-> PResult<'a, ast::ExprKind> {
|
||||||
if end.is_none() && limits == RangeLimits::Closed {
|
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 {
|
} else {
|
||||||
Ok(ExprKind::Range(start, end, limits))
|
Ok(ExprKind::Range(start, end, limits))
|
||||||
}
|
}
|
||||||
|
@ -3916,7 +3916,7 @@ impl<'a> Parser<'a> {
|
||||||
let unused_attrs = |attrs: &[_], s: &mut Self| {
|
let unused_attrs = |attrs: &[_], s: &mut Self| {
|
||||||
if attrs.len() > 0 {
|
if attrs.len() > 0 {
|
||||||
if s.prev_token_kind == PrevTokenKind::DocComment {
|
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 {
|
} else {
|
||||||
s.span_err(s.span, "expected statement after outer attribute");
|
s.span_err(s.span, "expected statement after outer attribute");
|
||||||
}
|
}
|
||||||
|
@ -5050,7 +5050,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
token::CloseDelim(token::Brace) => {}
|
token::CloseDelim(token::Brace) => {}
|
||||||
token::DocComment(_) => return Err(self.span_fatal_err(self.span,
|
token::DocComment(_) => return Err(self.span_fatal_err(self.span,
|
||||||
Errors::UselessDocComment)),
|
Error::UselessDocComment)),
|
||||||
_ => return Err(self.span_fatal_help(self.span,
|
_ => return Err(self.span_fatal_help(self.span,
|
||||||
&format!("expected `,`, or `}}`, found `{}`", self.this_token_to_string()),
|
&format!("expected `,`, or `}}`, found `{}`", self.this_token_to_string()),
|
||||||
"struct fields should be separated by commas")),
|
"struct fields should be separated by commas")),
|
||||||
|
@ -5231,13 +5231,13 @@ impl<'a> Parser<'a> {
|
||||||
directory_ownership: DirectoryOwnership::Owned,
|
directory_ownership: DirectoryOwnership::Owned,
|
||||||
warn: false,
|
warn: false,
|
||||||
}),
|
}),
|
||||||
(false, false) => Err(Errors::FileNotFoundForModule {
|
(false, false) => Err(Error::FileNotFoundForModule {
|
||||||
mod_name: mod_name.clone(),
|
mod_name: mod_name.clone(),
|
||||||
default_path: default_path_str,
|
default_path: default_path_str,
|
||||||
secondary_path: secondary_path_str,
|
secondary_path: secondary_path_str,
|
||||||
dir_path: format!("{}", dir_path.display()),
|
dir_path: format!("{}", dir_path.display()),
|
||||||
}),
|
}),
|
||||||
(true, true) => Err(Errors::DuplicatePaths {
|
(true, true) => Err(Error::DuplicatePaths {
|
||||||
mod_name: mod_name.clone(),
|
mod_name: mod_name.clone(),
|
||||||
default_path: default_path_str,
|
default_path: default_path_str,
|
||||||
secondary_path: secondary_path_str,
|
secondary_path: secondary_path_str,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue