Convert 15 diagnostics to have error codes (E0380-E0394).
Also adds explanations for E0380 and E0381.
This commit is contained in:
parent
fbef978fd7
commit
570a043576
@ -891,5 +891,7 @@ register_diagnostics! {
|
||||
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
|
||||
}
|
||||
|
@ -762,9 +762,9 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'tcx> {
|
||||
// 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;
|
||||
}
|
||||
|
@ -603,11 +603,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
|
||||
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())
|
||||
}
|
||||
@ -644,12 +645,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
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)
|
||||
}
|
||||
};
|
||||
@ -762,12 +761,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
&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,
|
||||
@ -775,10 +772,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
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");
|
||||
}
|
||||
|
||||
@ -896,21 +893,19 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
|
||||
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
|
||||
@ -925,14 +920,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,31 @@
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
register_diagnostics! {
|
||||
E0373 // closure may outlive current fn, but it borrows {}, which is owned by current fn
|
||||
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
|
||||
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
|
||||
}
|
||||
|
@ -437,13 +437,12 @@ fn create_substs_for_ast_path<'tcx>(
|
||||
// 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.
|
||||
|
@ -124,10 +124,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -353,10 +352,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
|
||||
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 {
|
||||
|
@ -48,10 +48,9 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -236,9 +236,8 @@ impl<'a,'tcx> CrateCtxt<'a,'tcx> {
|
||||
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) |
|
||||
|
@ -1096,6 +1096,12 @@ Trait2 { ... }`) does not work if the trait is not object-safe. Please see the
|
||||
[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).
|
||||
"##
|
||||
|
||||
}
|
||||
@ -1229,5 +1235,11 @@ register_diagnostics! {
|
||||
// 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`"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user