From e6f6da119e7c5a3b8c24893d111b7e2422ec57fd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 14 Sep 2015 21:25:04 +0200 Subject: [PATCH] End of adding error codes in librustc --- src/librustc/diagnostics.rs | 69 ++++++++++++++++++++ src/librustc/middle/check_const.rs | 18 ++--- src/librustc/middle/infer/error_reporting.rs | 9 ++- src/librustc/middle/resolve_lifetime.rs | 8 +-- src/librustc/plugin/load.rs | 8 ++- 5 files changed, 92 insertions(+), 20 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 702df073092..cf858e74c8d 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1933,6 +1933,71 @@ fn foo<'a>(arg: &Box) { ... } ``` "##, +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. +"##, + } @@ -1996,4 +2061,8 @@ fn foo<'a>(arg: &Box) { ... } 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 } diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index ad9cbfcf4c0..e1c29531b7d 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -499,9 +499,9 @@ fn visit_expr(&mut self, ex: &hir::Expr) { if self.qualif.intersects(ConstQualif::MUTABLE_MEM) && tc.interior_unsafe() { outer = outer | ConstQualif::NOT_CONST; if self.mode != Mode::Var { - self.tcx.sess.span_err(ex.span, - "cannot borrow a constant which contains \ - interior mutability, create a static instead"); + span_err!(self.tcx.sess, ex.span, E0492, + "cannot borrow a constant which contains \ + interior mutability, create a static instead"); } } // 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>, ty::TyEnum(def, _) if def.has_dtor() => { v.add_qualif(ConstQualif::NEEDS_DROP); if v.mode != Mode::Var { - v.tcx.sess.span_err(e.span, - &format!("{}s are not allowed to have destructors", - v.msg())); + span_err!(v.tcx.sess, e.span, E0493, + "{}s are not allowed to have destructors", + v.msg()); } } _ => {} @@ -904,9 +904,9 @@ fn borrow(&mut self, // Borrowed statics can specifically *only* have their address taken, // not any number of other borrows such as borrowing fields, reading // elements of an array, etc. - self.tcx.sess.span_err(borrow_span, - "cannot refer to the interior of another \ - static, use a constant instead"); + span_err!(self.tcx.sess, borrow_span, E0494, + "cannot refer to the interior of another \ + static, use a constant instead"); } break; } diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index 3d5c568ad31..293abde7b78 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -1626,11 +1626,10 @@ fn report_inference_failure(&self, } }; - self.tcx.sess.span_err( - var_origin.span(), - &format!("cannot infer an appropriate lifetime{} \ - due to conflicting requirements", - var_description)); + span_err!(self.tcx.sess, var_origin.span(), E0495, + "cannot infer an appropriate lifetime{} \ + due to conflicting requirements", + var_description); } fn note_region_origin(&self, origin: &SubregionOrigin<'tcx>) { diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 73b3b32f648..c21999c2dbc 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -357,10 +357,10 @@ fn signal_shadowing_problem( sess: &Session, name: ast::Name, orig: Original, shadower: Shadower) { if let (ShadowKind::Lifetime, ShadowKind::Lifetime) = (orig.kind, shadower.kind) { // lifetime/lifetime shadowing is an error - sess.span_err(shadower.span, - &format!("{} name `{}` shadows a \ - {} name that is already in scope", - shadower.kind.desc(), name, orig.kind.desc())); + span_err!(sess, shadower.span, E0496, + "{} name `{}` shadows a \ + {} name that is already in scope", + shadower.kind.desc(), name, orig.kind.desc()); } else { // shadowing involving a label is only a warning, due to issues with // labels and lifetimes not being macro-hygienic. diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs index e0cb47d6c95..288426830ef 100644 --- a/src/librustc/plugin/load.rs +++ b/src/librustc/plugin/load.rs @@ -39,6 +39,10 @@ struct PluginLoader<'a> { plugins: Vec, } +fn call_malformed_plugin_attribute(a: &Session, b: Span) { + span_err!(a, b, E0498, "malformed plugin attribute"); +} + /// Read plugin metadata and dynamically load registrar functions. pub fn load_plugins(sess: &Session, krate: &ast::Crate, addl_plugins: Option>) -> Vec { @@ -52,14 +56,14 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate, let plugins = match attr.meta_item_list() { Some(xs) => xs, None => { - sess.span_err(attr.span, "malformed plugin attribute"); + call_malformed_plugin_attribute(sess, attr.span); continue; } }; for plugin in plugins { if plugin.value_str().is_some() { - sess.span_err(attr.span, "malformed plugin attribute"); + call_malformed_plugin_attribute(sess, attr.span); continue; } -- GitLab