Skip to content

Commit 7358a5e

Browse files
Add part of new error codes in librustc
1 parent 1a1e6b8 commit 7358a5e

File tree

8 files changed

+203
-128
lines changed

8 files changed

+203
-128
lines changed

src/librustc/diagnostics.rs

+84-2
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,52 @@ 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+
"##,
18901935

18911936
}
18921937

@@ -1913,5 +1958,42 @@ register_diagnostics! {
19131958
E0314, // closure outlives stack frame
19141959
E0315, // cannot invoke closure outside of its lifetime
19151960
E0316, // nested quantification of lifetimes
1916-
E0400 // overloaded derefs are not allowed in constants
1961+
E0400, // overloaded derefs are not allowed in constants
1962+
E0452, // malformed lint attribute
1963+
E0453, // overruled by outer forbid
1964+
E0455, // native frameworks are only available on OSX targets
1965+
E0456, // plugin `..` is not available for triple `..`
1966+
E0457, // plugin `..` only found in rlib format, but must be available...
1967+
E0460, // found possibly newer version of crate `..`
1968+
E0461, // couldn't find crate `..` with expected target triple ..
1969+
E0462, // found staticlib `..` instead of rlib or dylib
1970+
E0463, // can't find crate for `..`
1971+
E0464, // multiple matching crates for `..`
1972+
E0465, // multiple .. candidates for `..` found
1973+
E0466, // bad macro import
1974+
E0467, // bad macro reexport
1975+
E0468, // an `extern crate` loading macros must be at the crate root
1976+
E0469, // imported macro not found
1977+
E0470, // reexported macro not found
1978+
E0471, // constant evaluation error: ..
1979+
E0472, // asm! is unsupported on this target
1980+
E0473, // dereference of reference outside its lifetime
1981+
E0474, // captured variable `..` does not outlive the enclosing closure
1982+
E0475, // index of slice outside its lifetime
1983+
E0476, // lifetime of the source pointer does not outlive lifetime bound...
1984+
E0477, // the type `..` does not fulfill the required lifetime...
1985+
E0478, // lifetime bound not satisfied
1986+
E0479, // the type `..` (provided as the value of a type parameter) is...
1987+
E0480, // lifetime of method receiver does not outlive the method call
1988+
E0481, // lifetime of function argument does not outlive the function call
1989+
E0482, // lifetime of return value does not outlive the function call
1990+
E0483, // lifetime of operand does not outlive the operation
1991+
E0484, // reference is not valid at the time of borrow
1992+
E0485, // automatically reference is not valid at the time of borrow
1993+
E0486, // type of expression contains references that are not valid during...
1994+
E0487, // unsafe use of destructor: destructor might be called while...
1995+
E0488, // lifetime of variable does not enclose its declaration
1996+
E0489, // type/lifetime parameter not in scope here
1997+
E0490, // a value of type `..` is borrowed for too long
1998+
E0491, // in type `..`, reference has a longer lifetime than the data it...
19171999
}

src/librustc/lint/context.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
467467
for result in gather_attrs(attrs) {
468468
let v = match result {
469469
Err(span) => {
470-
self.tcx.sess.span_err(span, "malformed lint attribute");
470+
span_err!(self.tcx.sess, span, E0452,
471+
"malformed lint attribute");
471472
continue;
472473
}
473474
Ok((lint_name, level, span)) => {
@@ -496,10 +497,10 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
496497
let now = self.lints.get_level_source(lint_id).0;
497498
if now == Forbid && level != Forbid {
498499
let lint_name = lint_id.as_str();
499-
self.tcx.sess.span_err(span,
500-
&format!("{}({}) overruled by outer forbid({})",
501-
level.as_str(), lint_name,
502-
lint_name));
500+
span_err!(self.tcx.sess, span, E0453,
501+
"{}({}) overruled by outer forbid({})",
502+
level.as_str(), lint_name,
503+
lint_name);
503504
} else if now != level {
504505
let src = self.lints.get_level_source(lint_id).1;
505506
self.level_stack.push((lint_id, (now, src)));

src/librustc/metadata/creader.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ fn register_native_lib(sess: &Session,
122122
if name.is_empty() {
123123
match span {
124124
Some(span) => {
125-
sess.span_err(span, "#[link(name = \"\")] given with \
126-
empty name");
125+
span_err!(sess, span, E0454,
126+
"#[link(name = \"\")] given with empty name");
127127
}
128128
None => {
129129
sess.err("empty library name given via `-l`");
@@ -135,7 +135,10 @@ fn register_native_lib(sess: &Session,
135135
if kind == cstore::NativeFramework && !is_osx {
136136
let msg = "native frameworks are only available on OSX targets";
137137
match span {
138-
Some(span) => sess.span_err(span, msg),
138+
Some(span) => {
139+
span_err!(sess, span, E0455,
140+
"{}", msg)
141+
}
139142
None => sess.err(msg),
140143
}
141144
}
@@ -517,7 +520,7 @@ impl<'a> CrateReader<'a> {
517520
name,
518521
config::host_triple(),
519522
self.sess.opts.target_triple);
520-
self.sess.span_err(span, &message[..]);
523+
span_err!(self.sess, span, E0456, "{}", &message[..]);
521524
self.sess.abort_if_errors();
522525
}
523526

@@ -527,10 +530,10 @@ impl<'a> CrateReader<'a> {
527530
match (ekrate.dylib.as_ref(), registrar) {
528531
(Some(dylib), Some(reg)) => Some((dylib.to_path_buf(), reg)),
529532
(None, Some(_)) => {
530-
let message = format!("plugin `{}` only found in rlib format, \
531-
but must be available in dylib format",
532-
name);
533-
self.sess.span_err(span, &message[..]);
533+
span_err!(self.sess, span, E0457,
534+
"plugin `{}` only found in rlib format, but must be available \
535+
in dylib format",
536+
name);
534537
// No need to abort because the loading code will just ignore this
535538
// empty dylib.
536539
None
@@ -763,7 +766,8 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
763766
Some("dylib") => cstore::NativeUnknown,
764767
Some("framework") => cstore::NativeFramework,
765768
Some(k) => {
766-
self.sess.span_err(m.span, &format!("unknown kind: `{}`", k));
769+
span_err!(self.sess, m.span, E0458,
770+
"unknown kind: `{}`", k);
767771
cstore::NativeUnknown
768772
}
769773
None => cstore::NativeUnknown
@@ -774,8 +778,8 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> {
774778
let n = match n {
775779
Some(n) => n,
776780
None => {
777-
self.sess.span_err(m.span, "#[link(...)] specified without \
778-
`name = \"foo\"`");
781+
span_err!(self.sess, m.span, E0459,
782+
"#[link(...)] specified without `name = \"foo\"`");
779783
InternedString::new("foo")
780784
}
781785
};

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
@@ -41,6 +41,10 @@ impl<'a> MacroLoader<'a> {
4141
}
4242
}
4343

44+
pub fn call_bad_macro_reexport(a: &Session, b: Span) {
45+
span_err!(a, b, E0467, "bad macro reexport");
46+
}
47+
4448
/// Read exported macros.
4549
pub fn read_macro_defs(sess: &Session, krate: &ast::Crate) -> Vec<ast::MacroDef> {
4650
let mut loader = MacroLoader::new(sess);
@@ -91,7 +95,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
9195
if let ast::MetaWord(ref name) = attr.node {
9296
sel.insert(name.clone(), attr.span);
9397
} else {
94-
self.sess.span_err(attr.span, "bad macro import");
98+
span_err!(self.sess, attr.span, E0466, "bad macro import");
9599
}
96100
}
97101
}
@@ -100,7 +104,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
100104
let names = match attr.meta_item_list() {
101105
Some(names) => names,
102106
None => {
103-
self.sess.span_err(attr.span, "bad macro reexport");
107+
call_bad_macro_reexport(self.sess, attr.span);
104108
continue;
105109
}
106110
};
@@ -109,7 +113,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
109113
if let ast::MetaWord(ref name) = attr.node {
110114
reexport.insert(name.clone(), attr.span);
111115
} else {
112-
self.sess.span_err(attr.span, "bad macro reexport");
116+
call_bad_macro_reexport(self.sess, attr.span);
113117
}
114118
}
115119
}
@@ -141,8 +145,8 @@ impl<'a> MacroLoader<'a> {
141145
}
142146

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

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

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

src/librustc/middle/check_match.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pat: &Pat) {
282282

283283
Err(err) => {
284284
let subspan = p.span.lo <= err.span.lo && err.span.hi <= p.span.hi;
285-
cx.tcx.sess.span_err(err.span,
286-
&format!("constant evaluation error: {}",
287-
err.description()));
285+
span_err!(cx.tcx.sess, err.span, E0471,
286+
"constant evaluation error: {}",
287+
err.description());
288288
if !subspan {
289289
cx.tcx.sess.span_note(p.span,
290290
"in pattern here")

src/librustc/middle/check_no_asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ struct CheckNoAsm<'a> {
3232
impl<'a, 'v> Visitor<'v> for CheckNoAsm<'a> {
3333
fn visit_expr(&mut self, e: &ast::Expr) {
3434
match e.node {
35-
ast::ExprInlineAsm(_) => self.sess.span_err(e.span,
36-
"asm! is unsupported on this target"),
35+
ast::ExprInlineAsm(_) => span_err!(self.sess, e.span, E0472,
36+
"asm! is unsupported on this target"),
3737
_ => {},
3838
}
3939
visit::walk_expr(self, e)

0 commit comments

Comments
 (0)