Skip to content

Commit e6f6da1

Browse files
End of adding error codes in librustc
1 parent 7358a5e commit e6f6da1

File tree

5 files changed

+92
-20
lines changed

5 files changed

+92
-20
lines changed

src/librustc/diagnostics.rs

+69
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,71 @@ you want. Example:
19331933
```
19341934
"##,
19351935

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+
"##,
2000+
19362001
}
19372002

19382003

@@ -1996,4 +2061,8 @@ register_diagnostics! {
19962061
E0489, // type/lifetime parameter not in scope here
19972062
E0490, // a value of type `..` is borrowed for too long
19982063
E0491, // in type `..`, reference has a longer lifetime than the data it...
2064+
E0492, // cannot borrow a constant which contains interior mutability
2065+
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
2066+
E0496, // .. name `..` shadows a .. name that is already in scope
2067+
E0498, // malformed plugin attribute
19992068
}

src/librustc/middle/check_const.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
499499
if self.qualif.intersects(ConstQualif::MUTABLE_MEM) && tc.interior_unsafe() {
500500
outer = outer | ConstQualif::NOT_CONST;
501501
if self.mode != Mode::Var {
502-
self.tcx.sess.span_err(ex.span,
503-
"cannot borrow a constant which contains \
504-
interior mutability, create a static instead");
502+
span_err!(self.tcx.sess, ex.span, E0492,
503+
"cannot borrow a constant which contains \
504+
interior mutability, create a static instead");
505505
}
506506
}
507507
// If the reference has to be 'static, avoid in-place initialization
@@ -548,9 +548,9 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
548548
ty::TyEnum(def, _) if def.has_dtor() => {
549549
v.add_qualif(ConstQualif::NEEDS_DROP);
550550
if v.mode != Mode::Var {
551-
v.tcx.sess.span_err(e.span,
552-
&format!("{}s are not allowed to have destructors",
553-
v.msg()));
551+
span_err!(v.tcx.sess, e.span, E0493,
552+
"{}s are not allowed to have destructors",
553+
v.msg());
554554
}
555555
}
556556
_ => {}
@@ -904,9 +904,9 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'tcx> {
904904
// Borrowed statics can specifically *only* have their address taken,
905905
// not any number of other borrows such as borrowing fields, reading
906906
// elements of an array, etc.
907-
self.tcx.sess.span_err(borrow_span,
908-
"cannot refer to the interior of another \
909-
static, use a constant instead");
907+
span_err!(self.tcx.sess, borrow_span, E0494,
908+
"cannot refer to the interior of another \
909+
static, use a constant instead");
910910
}
911911
break;
912912
}

src/librustc/middle/infer/error_reporting.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1626,11 +1626,10 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
16261626
}
16271627
};
16281628

1629-
self.tcx.sess.span_err(
1630-
var_origin.span(),
1631-
&format!("cannot infer an appropriate lifetime{} \
1632-
due to conflicting requirements",
1633-
var_description));
1629+
span_err!(self.tcx.sess, var_origin.span(), E0495,
1630+
"cannot infer an appropriate lifetime{} \
1631+
due to conflicting requirements",
1632+
var_description);
16341633
}
16351634

16361635
fn note_region_origin(&self, origin: &SubregionOrigin<'tcx>) {

src/librustc/middle/resolve_lifetime.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ fn signal_shadowing_problem(
357357
sess: &Session, name: ast::Name, orig: Original, shadower: Shadower) {
358358
if let (ShadowKind::Lifetime, ShadowKind::Lifetime) = (orig.kind, shadower.kind) {
359359
// lifetime/lifetime shadowing is an error
360-
sess.span_err(shadower.span,
361-
&format!("{} name `{}` shadows a \
362-
{} name that is already in scope",
363-
shadower.kind.desc(), name, orig.kind.desc()));
360+
span_err!(sess, shadower.span, E0496,
361+
"{} name `{}` shadows a \
362+
{} name that is already in scope",
363+
shadower.kind.desc(), name, orig.kind.desc());
364364
} else {
365365
// shadowing involving a label is only a warning, due to issues with
366366
// labels and lifetimes not being macro-hygienic.

src/librustc/plugin/load.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ struct PluginLoader<'a> {
3939
plugins: Vec<PluginRegistrar>,
4040
}
4141

42+
fn call_malformed_plugin_attribute(a: &Session, b: Span) {
43+
span_err!(a, b, E0498, "malformed plugin attribute");
44+
}
45+
4246
/// Read plugin metadata and dynamically load registrar functions.
4347
pub fn load_plugins(sess: &Session, krate: &ast::Crate,
4448
addl_plugins: Option<Vec<String>>) -> Vec<PluginRegistrar> {
@@ -52,14 +56,14 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate,
5256
let plugins = match attr.meta_item_list() {
5357
Some(xs) => xs,
5458
None => {
55-
sess.span_err(attr.span, "malformed plugin attribute");
59+
call_malformed_plugin_attribute(sess, attr.span);
5660
continue;
5761
}
5862
};
5963

6064
for plugin in plugins {
6165
if plugin.value_str().is_some() {
62-
sess.span_err(attr.span, "malformed plugin attribute");
66+
call_malformed_plugin_attribute(sess, attr.span);
6367
continue;
6468
}
6569

0 commit comments

Comments
 (0)