Skip to content

Add new error codes in librustc #28353

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

Merged
merged 2 commits into from
Sep 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
155 changes: 153 additions & 2 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,117 @@ This explicitly states that you expect the trait object `SomeTrait` to
contain references (with a maximum lifetime of `'a`).

[1]: https://github.com/rust-lang/rfcs/pull/1156
"##
"##,

E0454: r##"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can’t this be generalised to the E0452? There seems really little use to differentiate between an empty name and a malformed attribute.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite hard to say... It can be generalised, but like this, we have a very precise error code for each.

A link name was given with an empty name. Erroneous code example:

```
#[link(name = "")] extern {} // error: #[link(name = "")] given with empty name
```

The rust compiler cannot link to an external library if you don't give it its
name. Example:

```
#[link(name = "some_lib")] extern {} // ok!
```
"##,

E0458: r##"
An unknown "kind" was specified for a link attribute. Erroneous code example:

```
#[link(kind = "wonderful_unicorn")] extern {}
// error: unknown kind: `wonderful_unicorn`
```

Please specify a valid "kind" value, from one of the following:
* static
* dylib
* framework
"##,

E0459: r##"
A link was used without a name parameter. Erroneous code example:

```
#[link(kind = "dylib")] extern {}
// error: #[link(...)] specified without `name = "foo"`
```

Please add the name parameter to allow the rust compiler to find the library
you want. Example:

```
#[link(kind = "dylib", name = "some_lib")] extern {} // ok!
```
"##,

E0493: r##"
A type with a destructor was assigned to an invalid type of variable. Erroneous
code example:

```
struct Foo {
a: u32
}

impl Drop for Foo {
fn drop(&mut self) {}
}

const F : Foo = Foo { a : 0 };
// error: constants are not allowed to have destructors
static S : Foo = Foo { a : 0 };
// error: statics are not allowed to have destructors
```

To solve this issue, please use a type which does allow the usage of type with
destructors.
"##,

E0494: r##"
A reference of an interior static was assigned to another const/static.
Erroneous code example:

```
struct Foo {
a: u32
}

static S : Foo = Foo { a : 0 };
static A : &'static u32 = &S.a;
// error: cannot refer to the interior of another static, use a
// constant instead
```

The "base" variable has to be a const if you want another static/const variable
to refer to one of its fields. Example:

```
struct Foo {
a: u32
}

const S : Foo = Foo { a : 0 };
static A : &'static u32 = &S.a; // ok!
```
"##,

E0497: r##"
A stability attribute was used outside of the standard library. Erroneous code
example:

```
#[stable] // error: stability attributes may not be used outside of the
// standard library
fn foo() {}
```

It is not possible to use stability attributes outside of the standard library.
Also, for now, it is not possible to write deprecation messages either.
"##,

}

Expand All @@ -1913,5 +2023,46 @@ register_diagnostics! {
E0314, // closure outlives stack frame
E0315, // cannot invoke closure outside of its lifetime
E0316, // nested quantification of lifetimes
E0400 // overloaded derefs are not allowed in constants
E0400, // overloaded derefs are not allowed in constants
E0452, // malformed lint attribute
E0453, // overruled by outer forbid
E0455, // native frameworks are only available on OSX targets
E0456, // plugin `..` is not available for triple `..`
E0457, // plugin `..` only found in rlib format, but must be available...
E0460, // found possibly newer version of crate `..`
E0461, // couldn't find crate `..` with expected target triple ..
E0462, // found staticlib `..` instead of rlib or dylib
E0463, // can't find crate for `..`
E0464, // multiple matching crates for `..`
E0465, // multiple .. candidates for `..` found
E0466, // bad macro import
E0467, // bad macro reexport
E0468, // an `extern crate` loading macros must be at the crate root
E0469, // imported macro not found
E0470, // reexported macro not found
E0471, // constant evaluation error: ..
E0472, // asm! is unsupported on this target
E0473, // dereference of reference outside its lifetime
E0474, // captured variable `..` does not outlive the enclosing closure
E0475, // index of slice outside its lifetime
E0476, // lifetime of the source pointer does not outlive lifetime bound...
E0477, // the type `..` does not fulfill the required lifetime...
E0478, // lifetime bound not satisfied
E0479, // the type `..` (provided as the value of a type parameter) is...
E0480, // lifetime of method receiver does not outlive the method call
E0481, // lifetime of function argument does not outlive the function call
E0482, // lifetime of return value does not outlive the function call
E0483, // lifetime of operand does not outlive the operation
E0484, // reference is not valid at the time of borrow
E0485, // automatically reference is not valid at the time of borrow
E0486, // type of expression contains references that are not valid during...
E0487, // unsafe use of destructor: destructor might be called while...
E0488, // lifetime of variable does not enclose its declaration
E0489, // type/lifetime parameter not in scope here
E0490, // a value of type `..` is borrowed for too long
E0491, // in type `..`, reference has a longer lifetime than the data it...
E0492, // cannot borrow a constant which contains interior mutability
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
E0496, // .. name `..` shadows a .. name that is already in scope
E0498, // malformed plugin attribute
}
11 changes: 6 additions & 5 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
for result in gather_attrs(attrs) {
let v = match result {
Err(span) => {
self.tcx.sess.span_err(span, "malformed lint attribute");
span_err!(self.tcx.sess, span, E0452,
"malformed lint attribute");
continue;
}
Ok((lint_name, level, span)) => {
Expand Down Expand Up @@ -496,10 +497,10 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
let now = self.lints.get_level_source(lint_id).0;
if now == Forbid && level != Forbid {
let lint_name = lint_id.as_str();
self.tcx.sess.span_err(span,
&format!("{}({}) overruled by outer forbid({})",
level.as_str(), lint_name,
lint_name));
span_err!(self.tcx.sess, span, E0453,
"{}({}) overruled by outer forbid({})",
level.as_str(), lint_name,
lint_name);
} else if now != level {
let src = self.lints.get_level_source(lint_id).1;
self.level_stack.push((lint_id, (now, src)));
Expand Down
26 changes: 15 additions & 11 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ fn register_native_lib(sess: &Session,
if name.is_empty() {
match span {
Some(span) => {
sess.span_err(span, "#[link(name = \"\")] given with \
empty name");
span_err!(sess, span, E0454,
"#[link(name = \"\")] given with empty name");
}
None => {
sess.err("empty library name given via `-l`");
Expand All @@ -135,7 +135,10 @@ fn register_native_lib(sess: &Session,
if kind == cstore::NativeFramework && !is_osx {
let msg = "native frameworks are only available on OSX targets";
match span {
Some(span) => sess.span_err(span, msg),
Some(span) => {
span_err!(sess, span, E0455,
"{}", msg)
}
None => sess.err(msg),
}
}
Expand Down Expand Up @@ -517,7 +520,7 @@ impl<'a> CrateReader<'a> {
name,
config::host_triple(),
self.sess.opts.target_triple);
self.sess.span_err(span, &message[..]);
span_err!(self.sess, span, E0456, "{}", &message[..]);
self.sess.abort_if_errors();
}

Expand All @@ -527,10 +530,10 @@ impl<'a> CrateReader<'a> {
match (ekrate.dylib.as_ref(), registrar) {
(Some(dylib), Some(reg)) => Some((dylib.to_path_buf(), reg)),
(None, Some(_)) => {
let message = format!("plugin `{}` only found in rlib format, \
but must be available in dylib format",
name);
self.sess.span_err(span, &message[..]);
span_err!(self.sess, span, E0457,
"plugin `{}` only found in rlib format, but must be available \
in dylib format",
name);
// No need to abort because the loading code will just ignore this
// empty dylib.
None
Expand Down Expand Up @@ -763,7 +766,8 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
Some("dylib") => cstore::NativeUnknown,
Some("framework") => cstore::NativeFramework,
Some(k) => {
self.sess.span_err(m.span, &format!("unknown kind: `{}`", k));
span_err!(self.sess, m.span, E0458,
"unknown kind: `{}`", k);
cstore::NativeUnknown
}
None => cstore::NativeUnknown
Expand All @@ -774,8 +778,8 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
let n = match n {
Some(n) => n,
None => {
self.sess.span_err(m.span, "#[link(...)] specified without \
`name = \"foo\"`");
span_err!(self.sess, m.span, E0459,
"#[link(...)] specified without `name = \"foo\"`");
InternedString::new("foo")
}
};
Expand Down
47 changes: 25 additions & 22 deletions src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,23 +308,28 @@ impl<'a> Context<'a> {
}

pub fn report_load_errs(&mut self) {
let message = if !self.rejected_via_hash.is_empty() {
format!("found possibly newer version of crate `{}`",
self.ident)
let add = match self.root {
&None => String::new(),
&Some(ref r) => format!(" which `{}` depends on",
r.ident)
};
if !self.rejected_via_hash.is_empty() {
span_err!(self.sess, self.span, E0460,
"found possibly newer version of crate `{}`{}",
self.ident, add);
} else if !self.rejected_via_triple.is_empty() {
format!("couldn't find crate `{}` with expected target triple {}",
self.ident, self.triple)
span_err!(self.sess, self.span, E0461,
"couldn't find crate `{}` with expected target triple {}{}",
self.ident, self.triple, add);
} else if !self.rejected_via_kind.is_empty() {
format!("found staticlib `{}` instead of rlib or dylib", self.ident)
span_err!(self.sess, self.span, E0462,
"found staticlib `{}` instead of rlib or dylib{}",
self.ident, add);
} else {
format!("can't find crate for `{}`", self.ident)
};
let message = match self.root {
&None => message,
&Some(ref r) => format!("{} which `{}` depends on",
message, r.ident)
};
self.sess.span_err(self.span, &message[..]);
span_err!(self.sess, self.span, E0463,
"can't find crate for `{}`{}",
self.ident, add);
}

if !self.rejected_via_triple.is_empty() {
let mismatches = self.rejected_via_triple.iter();
Expand Down Expand Up @@ -473,9 +478,9 @@ impl<'a> Context<'a> {
0 => None,
1 => Some(libraries.into_iter().next().unwrap()),
_ => {
self.sess.span_err(self.span,
&format!("multiple matching crates for `{}`",
self.crate_name));
span_err!(self.sess, self.span, E0464,
"multiple matching crates for `{}`",
self.crate_name);
self.sess.note("candidates:");
for lib in &libraries {
match lib.dylib {
Expand Down Expand Up @@ -543,11 +548,9 @@ impl<'a> Context<'a> {
}
};
if ret.is_some() {
self.sess.span_err(self.span,
&format!("multiple {} candidates for `{}` \
found",
flavor,
self.crate_name));
span_err!(self.sess, self.span, E0465,
"multiple {} candidates for `{}` found",
flavor, self.crate_name);
self.sess.span_note(self.span,
&format!(r"candidate #1: {}",
ret.as_ref().unwrap().0
Expand Down
20 changes: 13 additions & 7 deletions src/librustc/metadata/macro_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ impl<'a> MacroLoader<'a> {
}
}

pub fn call_bad_macro_reexport(a: &Session, b: Span) {
span_err!(a, b, E0467, "bad macro reexport");
}

/// Read exported macros.
pub fn read_macro_defs(sess: &Session, krate: &ast::Crate) -> Vec<ast::MacroDef> {
let mut loader = MacroLoader::new(sess);
Expand Down Expand Up @@ -91,7 +95,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
if let ast::MetaWord(ref name) = attr.node {
sel.insert(name.clone(), attr.span);
} else {
self.sess.span_err(attr.span, "bad macro import");
span_err!(self.sess, attr.span, E0466, "bad macro import");
}
}
}
Expand All @@ -100,7 +104,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
let names = match attr.meta_item_list() {
Some(names) => names,
None => {
self.sess.span_err(attr.span, "bad macro reexport");
call_bad_macro_reexport(self.sess, attr.span);
continue;
}
};
Expand All @@ -109,7 +113,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
if let ast::MetaWord(ref name) = attr.node {
reexport.insert(name.clone(), attr.span);
} else {
self.sess.span_err(attr.span, "bad macro reexport");
call_bad_macro_reexport(self.sess, attr.span);
}
}
}
Expand Down Expand Up @@ -141,8 +145,8 @@ impl<'a> MacroLoader<'a> {
}

if !self.span_whitelist.contains(&vi.span) {
self.sess.span_err(vi.span, "an `extern crate` loading macros must be at \
the crate root");
span_err!(self.sess, vi.span, E0468,
"an `extern crate` loading macros must be at the crate root");
return;
}

Expand All @@ -167,14 +171,16 @@ impl<'a> MacroLoader<'a> {
if let Some(sel) = import.as_ref() {
for (name, span) in sel {
if !seen.contains(&name) {
self.sess.span_err(*span, "imported macro not found");
span_err!(self.sess, *span, E0469,
"imported macro not found");
}
}
}

for (name, span) in &reexport {
if !seen.contains(&name) {
self.sess.span_err(*span, "reexported macro not found");
span_err!(self.sess, *span, E0470,
"reexported macro not found");
}
}
}
Expand Down
Loading