Skip to content

Commit 8dfb890

Browse files
committed
Auto merge of #28353 - GuillaumeGomez:error_codes, r=Manishearth
r? @Manishearth This is a work in progress.
2 parents 1fe126a + e6f6da1 commit 8dfb890

File tree

11 files changed

+295
-148
lines changed

11 files changed

+295
-148
lines changed

src/librustc/diagnostics.rs

+153-2
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,117 @@ This explicitly states that you expect the trait object `SomeTrait` to
18861886
contain references (with a maximum lifetime of `'a`).
18871887
18881888
[1]: https://github.com/rust-lang/rfcs/pull/1156
1889-
"##
1889+
"##,
1890+
1891+
E0454: r##"
1892+
A link name was given with an empty name. Erroneous code example:
1893+
1894+
```
1895+
#[link(name = "")] extern {} // error: #[link(name = "")] given with empty name
1896+
```
1897+
1898+
The rust compiler cannot link to an external library if you don't give it its
1899+
name. Example:
1900+
1901+
```
1902+
#[link(name = "some_lib")] extern {} // ok!
1903+
```
1904+
"##,
1905+
1906+
E0458: r##"
1907+
An unknown "kind" was specified for a link attribute. Erroneous code example:
1908+
1909+
```
1910+
#[link(kind = "wonderful_unicorn")] extern {}
1911+
// error: unknown kind: `wonderful_unicorn`
1912+
```
1913+
1914+
Please specify a valid "kind" value, from one of the following:
1915+
* static
1916+
* dylib
1917+
* framework
1918+
"##,
1919+
1920+
E0459: r##"
1921+
A link was used without a name parameter. Erroneous code example:
1922+
1923+
```
1924+
#[link(kind = "dylib")] extern {}
1925+
// error: #[link(...)] specified without `name = "foo"`
1926+
```
1927+
1928+
Please add the name parameter to allow the rust compiler to find the library
1929+
you want. Example:
1930+
1931+
```
1932+
#[link(kind = "dylib", name = "some_lib")] extern {} // ok!
1933+
```
1934+
"##,
1935+
1936+
E0493: r##"
1937+
A type with a destructor was assigned to an invalid type of variable. Erroneous
1938+
code example:
1939+
1940+
```
1941+
struct Foo {
1942+
a: u32
1943+
}
1944+
1945+
impl Drop for Foo {
1946+
fn drop(&mut self) {}
1947+
}
1948+
1949+
const F : Foo = Foo { a : 0 };
1950+
// error: constants are not allowed to have destructors
1951+
static S : Foo = Foo { a : 0 };
1952+
// error: statics are not allowed to have destructors
1953+
```
1954+
1955+
To solve this issue, please use a type which does allow the usage of type with
1956+
destructors.
1957+
"##,
1958+
1959+
E0494: r##"
1960+
A reference of an interior static was assigned to another const/static.
1961+
Erroneous code example:
1962+
1963+
```
1964+
struct Foo {
1965+
a: u32
1966+
}
1967+
1968+
static S : Foo = Foo { a : 0 };
1969+
static A : &'static u32 = &S.a;
1970+
// error: cannot refer to the interior of another static, use a
1971+
// constant instead
1972+
```
1973+
1974+
The "base" variable has to be a const if you want another static/const variable
1975+
to refer to one of its fields. Example:
1976+
1977+
```
1978+
struct Foo {
1979+
a: u32
1980+
}
1981+
1982+
const S : Foo = Foo { a : 0 };
1983+
static A : &'static u32 = &S.a; // ok!
1984+
```
1985+
"##,
1986+
1987+
E0497: r##"
1988+
A stability attribute was used outside of the standard library. Erroneous code
1989+
example:
1990+
1991+
```
1992+
#[stable] // error: stability attributes may not be used outside of the
1993+
// standard library
1994+
fn foo() {}
1995+
```
1996+
1997+
It is not possible to use stability attributes outside of the standard library.
1998+
Also, for now, it is not possible to write deprecation messages either.
1999+
"##,
18902000

18912001
}
18922002

@@ -1914,5 +2024,46 @@ register_diagnostics! {
19142024
E0314, // closure outlives stack frame
19152025
E0315, // cannot invoke closure outside of its lifetime
19162026
E0316, // nested quantification of lifetimes
1917-
E0400 // overloaded derefs are not allowed in constants
2027+
E0400, // overloaded derefs are not allowed in constants
2028+
E0452, // malformed lint attribute
2029+
E0453, // overruled by outer forbid
2030+
E0455, // native frameworks are only available on OSX targets
2031+
E0456, // plugin `..` is not available for triple `..`
2032+
E0457, // plugin `..` only found in rlib format, but must be available...
2033+
E0460, // found possibly newer version of crate `..`
2034+
E0461, // couldn't find crate `..` with expected target triple ..
2035+
E0462, // found staticlib `..` instead of rlib or dylib
2036+
E0463, // can't find crate for `..`
2037+
E0464, // multiple matching crates for `..`
2038+
E0465, // multiple .. candidates for `..` found
2039+
E0466, // bad macro import
2040+
E0467, // bad macro reexport
2041+
E0468, // an `extern crate` loading macros must be at the crate root
2042+
E0469, // imported macro not found
2043+
E0470, // reexported macro not found
2044+
E0471, // constant evaluation error: ..
2045+
E0472, // asm! is unsupported on this target
2046+
E0473, // dereference of reference outside its lifetime
2047+
E0474, // captured variable `..` does not outlive the enclosing closure
2048+
E0475, // index of slice outside its lifetime
2049+
E0476, // lifetime of the source pointer does not outlive lifetime bound...
2050+
E0477, // the type `..` does not fulfill the required lifetime...
2051+
E0478, // lifetime bound not satisfied
2052+
E0479, // the type `..` (provided as the value of a type parameter) is...
2053+
E0480, // lifetime of method receiver does not outlive the method call
2054+
E0481, // lifetime of function argument does not outlive the function call
2055+
E0482, // lifetime of return value does not outlive the function call
2056+
E0483, // lifetime of operand does not outlive the operation
2057+
E0484, // reference is not valid at the time of borrow
2058+
E0485, // automatically reference is not valid at the time of borrow
2059+
E0486, // type of expression contains references that are not valid during...
2060+
E0487, // unsafe use of destructor: destructor might be called while...
2061+
E0488, // lifetime of variable does not enclose its declaration
2062+
E0489, // type/lifetime parameter not in scope here
2063+
E0490, // a value of type `..` is borrowed for too long
2064+
E0491, // in type `..`, reference has a longer lifetime than the data it...
2065+
E0492, // cannot borrow a constant which contains interior mutability
2066+
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
2067+
E0496, // .. name `..` shadows a .. name that is already in scope
2068+
E0498, // malformed plugin attribute
19182069
}

src/librustc/lint/context.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
433433
for result in gather_attrs(attrs) {
434434
let v = match result {
435435
Err(span) => {
436-
self.tcx.sess.span_err(span, "malformed lint attribute");
436+
span_err!(self.tcx.sess, span, E0452,
437+
"malformed lint attribute");
437438
continue;
438439
}
439440
Ok((lint_name, level, span)) => {
@@ -462,10 +463,10 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
462463
let now = self.lints.get_level_source(lint_id).0;
463464
if now == Forbid && level != Forbid {
464465
let lint_name = lint_id.as_str();
465-
self.tcx.sess.span_err(span,
466-
&format!("{}({}) overruled by outer forbid({})",
467-
level.as_str(), lint_name,
468-
lint_name));
466+
span_err!(self.tcx.sess, span, E0453,
467+
"{}({}) overruled by outer forbid({})",
468+
level.as_str(), lint_name,
469+
lint_name);
469470
} else if now != level {
470471
let src = self.lints.get_level_source(lint_id).1;
471472
self.level_stack.push((lint_id, (now, src)));

src/librustc/metadata/creader.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ fn register_native_lib(sess: &Session,
119119
if name.is_empty() {
120120
match span {
121121
Some(span) => {
122-
sess.span_err(span, "#[link(name = \"\")] given with \
123-
empty name");
122+
span_err!(sess, span, E0454,
123+
"#[link(name = \"\")] given with empty name");
124124
}
125125
None => {
126126
sess.err("empty library name given via `-l`");
@@ -132,7 +132,10 @@ fn register_native_lib(sess: &Session,
132132
if kind == cstore::NativeFramework && !is_osx {
133133
let msg = "native frameworks are only available on OSX targets";
134134
match span {
135-
Some(span) => sess.span_err(span, msg),
135+
Some(span) => {
136+
span_err!(sess, span, E0455,
137+
"{}", msg)
138+
}
136139
None => sess.err(msg),
137140
}
138141
}
@@ -514,7 +517,7 @@ impl<'a> CrateReader<'a> {
514517
name,
515518
config::host_triple(),
516519
self.sess.opts.target_triple);
517-
self.sess.span_err(span, &message[..]);
520+
span_err!(self.sess, span, E0456, "{}", &message[..]);
518521
self.sess.abort_if_errors();
519522
}
520523

@@ -524,10 +527,10 @@ impl<'a> CrateReader<'a> {
524527
match (ekrate.dylib.as_ref(), registrar) {
525528
(Some(dylib), Some(reg)) => Some((dylib.to_path_buf(), reg)),
526529
(None, Some(_)) => {
527-
let message = format!("plugin `{}` only found in rlib format, \
528-
but must be available in dylib format",
529-
name);
530-
self.sess.span_err(span, &message[..]);
530+
span_err!(self.sess, span, E0457,
531+
"plugin `{}` only found in rlib format, but must be available \
532+
in dylib format",
533+
name);
531534
// No need to abort because the loading code will just ignore this
532535
// empty dylib.
533536
None
@@ -760,7 +763,8 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
760763
Some("dylib") => cstore::NativeUnknown,
761764
Some("framework") => cstore::NativeFramework,
762765
Some(k) => {
763-
self.sess.span_err(m.span, &format!("unknown kind: `{}`", k));
766+
span_err!(self.sess, m.span, E0458,
767+
"unknown kind: `{}`", k);
764768
cstore::NativeUnknown
765769
}
766770
None => cstore::NativeUnknown
@@ -771,8 +775,8 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
771775
let n = match n {
772776
Some(n) => n,
773777
None => {
774-
self.sess.span_err(m.span, "#[link(...)] specified without \
775-
`name = \"foo\"`");
778+
span_err!(self.sess, m.span, E0459,
779+
"#[link(...)] specified without `name = \"foo\"`");
776780
InternedString::new("foo")
777781
}
778782
};

src/librustc/metadata/loader.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,28 @@ impl<'a> Context<'a> {
308308
}
309309

310310
pub fn report_load_errs(&mut self) {
311-
let message = if !self.rejected_via_hash.is_empty() {
312-
format!("found possibly newer version of crate `{}`",
313-
self.ident)
311+
let add = match self.root {
312+
&None => String::new(),
313+
&Some(ref r) => format!(" which `{}` depends on",
314+
r.ident)
315+
};
316+
if !self.rejected_via_hash.is_empty() {
317+
span_err!(self.sess, self.span, E0460,
318+
"found possibly newer version of crate `{}`{}",
319+
self.ident, add);
314320
} else if !self.rejected_via_triple.is_empty() {
315-
format!("couldn't find crate `{}` with expected target triple {}",
316-
self.ident, self.triple)
321+
span_err!(self.sess, self.span, E0461,
322+
"couldn't find crate `{}` with expected target triple {}{}",
323+
self.ident, self.triple, add);
317324
} else if !self.rejected_via_kind.is_empty() {
318-
format!("found staticlib `{}` instead of rlib or dylib", self.ident)
325+
span_err!(self.sess, self.span, E0462,
326+
"found staticlib `{}` instead of rlib or dylib{}",
327+
self.ident, add);
319328
} else {
320-
format!("can't find crate for `{}`", self.ident)
321-
};
322-
let message = match self.root {
323-
&None => message,
324-
&Some(ref r) => format!("{} which `{}` depends on",
325-
message, r.ident)
326-
};
327-
self.sess.span_err(self.span, &message[..]);
329+
span_err!(self.sess, self.span, E0463,
330+
"can't find crate for `{}`{}",
331+
self.ident, add);
332+
}
328333

329334
if !self.rejected_via_triple.is_empty() {
330335
let mismatches = self.rejected_via_triple.iter();
@@ -473,9 +478,9 @@ impl<'a> Context<'a> {
473478
0 => None,
474479
1 => Some(libraries.into_iter().next().unwrap()),
475480
_ => {
476-
self.sess.span_err(self.span,
477-
&format!("multiple matching crates for `{}`",
478-
self.crate_name));
481+
span_err!(self.sess, self.span, E0464,
482+
"multiple matching crates for `{}`",
483+
self.crate_name);
479484
self.sess.note("candidates:");
480485
for lib in &libraries {
481486
match lib.dylib {
@@ -543,11 +548,9 @@ impl<'a> Context<'a> {
543548
}
544549
};
545550
if ret.is_some() {
546-
self.sess.span_err(self.span,
547-
&format!("multiple {} candidates for `{}` \
548-
found",
549-
flavor,
550-
self.crate_name));
551+
span_err!(self.sess, self.span, E0465,
552+
"multiple {} candidates for `{}` found",
553+
flavor, self.crate_name);
551554
self.sess.span_note(self.span,
552555
&format!(r"candidate #1: {}",
553556
ret.as_ref().unwrap().0

src/librustc/metadata/macro_import.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ impl<'a> MacroLoader<'a> {
4040
}
4141
}
4242

43+
pub fn call_bad_macro_reexport(a: &Session, b: Span) {
44+
span_err!(a, b, E0467, "bad macro reexport");
45+
}
46+
4347
/// Read exported macros.
4448
pub fn read_macro_defs(sess: &Session, krate: &ast::Crate) -> Vec<ast::MacroDef> {
4549
let mut loader = MacroLoader::new(sess);
@@ -90,7 +94,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
9094
if let ast::MetaWord(ref name) = attr.node {
9195
sel.insert(name.clone(), attr.span);
9296
} else {
93-
self.sess.span_err(attr.span, "bad macro import");
97+
span_err!(self.sess, attr.span, E0466, "bad macro import");
9498
}
9599
}
96100
}
@@ -99,7 +103,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
99103
let names = match attr.meta_item_list() {
100104
Some(names) => names,
101105
None => {
102-
self.sess.span_err(attr.span, "bad macro reexport");
106+
call_bad_macro_reexport(self.sess, attr.span);
103107
continue;
104108
}
105109
};
@@ -108,7 +112,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
108112
if let ast::MetaWord(ref name) = attr.node {
109113
reexport.insert(name.clone(), attr.span);
110114
} else {
111-
self.sess.span_err(attr.span, "bad macro reexport");
115+
call_bad_macro_reexport(self.sess, attr.span);
112116
}
113117
}
114118
}
@@ -140,8 +144,8 @@ impl<'a> MacroLoader<'a> {
140144
}
141145

142146
if !self.span_whitelist.contains(&vi.span) {
143-
self.sess.span_err(vi.span, "an `extern crate` loading macros must be at \
144-
the crate root");
147+
span_err!(self.sess, vi.span, E0468,
148+
"an `extern crate` loading macros must be at the crate root");
145149
return;
146150
}
147151

@@ -166,14 +170,16 @@ impl<'a> MacroLoader<'a> {
166170
if let Some(sel) = import.as_ref() {
167171
for (name, span) in sel {
168172
if !seen.contains(&name) {
169-
self.sess.span_err(*span, "imported macro not found");
173+
span_err!(self.sess, *span, E0469,
174+
"imported macro not found");
170175
}
171176
}
172177
}
173178

174179
for (name, span) in &reexport {
175180
if !seen.contains(&name) {
176-
self.sess.span_err(*span, "reexported macro not found");
181+
span_err!(self.sess, *span, E0470,
182+
"reexported macro not found");
177183
}
178184
}
179185
}

0 commit comments

Comments
 (0)