Also adds explanations for E0380 and E0381.
E0315, // cannot invoke closure outside of its lifetime
E0316, // nested quantification of lifetimes
E0370, // discriminant overflow
- E0378 // method calls limited to constant inherent methods
+ E0378, // method calls limited to constant inherent methods
+ E0394 // cannot refer to other statics by value, use the address-of
+ // operator or a constant instead
}
// statics cannot be consumed by value at any time, that would imply
// that they're an initializer (what a const is for) or kept in sync
// over time (not feasible), so deny it outright.
- self.tcx.sess.span_err(consume_span,
- "cannot refer to other statics by value, use the \
- address-of operator or a constant instead");
+ span_err!(self.tcx.sess, consume_span, E0394,
+ "cannot refer to other statics by value, use the \
+ address-of operator or a constant instead");
}
break;
}
let (ol, moved_lp_msg) = match the_move.kind {
move_data::Declared => {
- self.tcx.sess.span_err(
- use_span,
- &format!("{} of possibly uninitialized variable: `{}`",
- verb,
- self.loan_path_to_string(lp)));
+ span_err!(
+ self.tcx.sess, use_span, E0381,
+ "{} of possibly uninitialized variable: `{}`",
+ verb,
+ self.loan_path_to_string(lp));
+
(self.loan_path_to_string(moved_lp),
String::new())
}
let msg = if !has_fork && partial { "partially " }
else if has_fork && !has_common { "collaterally "}
else { "" };
- self.tcx.sess.span_err(
- use_span,
- &format!("{} of {}moved value: `{}`",
- verb,
- msg,
- nl));
+ span_err!(
+ self.tcx.sess, use_span, E0382,
+ "{} of {}moved value: `{}`",
+ verb, msg, nl);
(ol, moved_lp_msg)
}
};
&self,
span: Span,
lp: &LoanPath<'tcx>) {
- self.tcx
- .sess
- .span_err(span,
- &format!("partial reinitialization of uninitialized \
- structure `{}`",
- self.loan_path_to_string(lp)));
+ span_err!(
+ self.tcx.sess, span, E0383,
+ "partial reinitialization of uninitialized structure `{}`",
+ self.loan_path_to_string(lp));
}
pub fn report_reassigned_immutable_variable(&self,
lp: &LoanPath<'tcx>,
assign:
&move_data::Assignment) {
- self.tcx.sess.span_err(
- span,
- &format!("re-assignment of immutable variable `{}`",
- self.loan_path_to_string(lp)));
+ span_err!(
+ self.tcx.sess, span, E0384,
+ "re-assignment of immutable variable `{}`",
+ self.loan_path_to_string(lp));
self.tcx.sess.span_note(assign.span, "prior assignment occurs here");
}
match cause {
mc::AliasableOther => {
- self.tcx.sess.span_err(
- span,
- &format!("{} in an aliasable location",
- prefix));
+ span_err!(
+ self.tcx.sess, span, E0385,
+ "{} in an aliasable location", prefix);
}
mc::AliasableReason::UnaliasableImmutable => {
- self.tcx.sess.span_err(
- span,
- &format!("{} in an immutable container",
- prefix));
+ span_err!(
+ self.tcx.sess, span, E0386,
+ "{} in an immutable container", prefix);
}
mc::AliasableClosure(id) => {
- self.tcx.sess.span_err(span,
- &format!("{} in a captured outer \
- variable in an `Fn` closure", prefix));
+ span_err!(
+ self.tcx.sess, span, E0387,
+ "{} in a captured outer variable in an `Fn` closure", prefix);
if let BorrowViolation(euv::ClosureCapture(_)) = kind {
// The aliasability violation with closure captures can
// happen for nested closures, so we know the enclosing
}
mc::AliasableStatic(..) |
mc::AliasableStaticMut(..) => {
- self.tcx.sess.span_err(
- span,
- &format!("{} in a static location", prefix));
+ span_err!(
+ self.tcx.sess, span, E0388,
+ "{} in a static location", prefix);
}
mc::AliasableBorrowed => {
- self.tcx.sess.span_err(
- span,
- &format!("{} in a `&` reference", prefix));
+ span_err!(
+ self.tcx.sess, span, E0389,
+ "{} in a `&` reference", prefix);
}
}
#![allow(non_snake_case)]
+register_long_diagnostics! {
+
+E0381: r##"
+It is not allowed to use or capture an uninitialized variable. For example:
+
+```
+fn main() {
+ let x: i32;
+ let y = x; // error, use of possibly uninitialized variable
+```
+
+To fix this, ensure that any declared variables are initialized before being
+used.
+"##
+
+}
+
register_diagnostics! {
- E0373 // closure may outlive current fn, but it borrows {}, which is owned by current fn
+ E0373, // closure may outlive current fn, but it borrows {}, which is owned by current fn
+ E0382, // use of partially/collaterally moved value
+ E0383, // partial reinitialization of uninitialized structure
+ E0384, // reassignment of immutable variable
+ E0385, // {} in an aliasable location
+ E0386, // {} in an immutable container
+ E0387, // {} in a captured outer variable in an `Fn` closure
+ E0388, // {} in a static location
+ E0389 // {} in a `&` reference
}
// defaults. This will lead to an ICE if we are not
// careful!
if self_ty.is_none() && ty::type_has_self(default) {
- tcx.sess.span_err(
- span,
- &format!("the type parameter `{}` must be explicitly specified \
- in an object type because its default value `{}` references \
- the type `Self`",
- param.name.user_string(tcx),
- default.user_string(tcx)));
+ span_err!(tcx.sess, span, E0393,
+ "the type parameter `{}` must be explicitly specified \
+ in an object type because its default value `{}` references \
+ the type `Self`",
+ param.name.user_string(tcx),
+ default.user_string(tcx));
substs.types.push(TypeSpace, tcx.types.err);
} else {
// This is a default type parameter.
reject_non_type_param_bounds(ccx.tcx, item.span, &trait_predicates);
if ty::trait_has_default_impl(ccx.tcx, local_def(item.id)) {
if !items.is_empty() {
- ccx.tcx.sess.span_err(
- item.span,
- "traits with default impls (`e.g. unsafe impl Trait for ..`) must \
- have no methods or associated items")
+ span_err!(ccx.tcx.sess, item.span, E0380,
+ "traits with default impls (`e.g. unsafe impl \
+ Trait for ..`) must have no methods or associated items")
}
}
}
span: Span,
param_name: ast::Name)
{
- self.tcx().sess.span_err(
- span,
- &format!("parameter `{}` is never used",
- param_name.user_string(self.tcx())));
+ span_err!(self.tcx().sess, span, E0392,
+ "parameter `{}` is never used", param_name.user_string(self.tcx()));
let suggested_marker_id = self.tcx().lang_items.phantom_data();
match suggested_marker_id {
match lang_def_id {
Some(lang_def_id) if lang_def_id == impl_def_id => { /* OK */ },
_ => {
- self.tcx.sess.span_err(
- span,
- &format!("only a single inherent implementation marked with `#[lang = \"{}\"]` \
- is allowed for the `{}` primitive", lang, ty));
+ span_err!(self.tcx.sess, span, E0390,
+ "only a single inherent implementation marked with `#[lang = \"{}\"]` \
+ is allowed for the `{}` primitive", lang, ty);
}
}
}
assert!(!cycle.is_empty());
let tcx = self.tcx;
- tcx.sess.span_err(
- span,
- &format!("unsupported cyclic reference between types/traits detected"));
+ span_err!(tcx.sess, span, E0391,
+ "unsupported cyclic reference between types/traits detected");
match cycle[0] {
AstConvRequest::GetItemTypeScheme(def_id) |
[RFC 255] for more details on object safety rules.
[RFC 255]: https://github.com/rust-lang/rfcs/pull/255
+"##,
+
+E0380: r##"
+Default impls are only allowed for traits with no methods or associated items.
+For more information see the [opt-in builtin traits RFC](https://github.com/rust
+-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
"##
}
// between structures
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
// between structures with the same definition
- E0379 // trait fns cannot be const
+ E0379, // trait fns cannot be const
+ E0390, // only a single inherent implementation marked with
+ // `#[lang = \"{}\"]` is allowed for the `{}` primitive
+ E0391, // unsupported cyclic reference between types/traits detected
+ E0392, // parameter `{}` is never used
+ E0393 // the type parameter `{}` must be explicitly specified in an object
+ // type because its default value `{}` references the type `Self`"
}