Skip to content

Commit 570a043

Browse files
author
Nick Hamann
committed
Convert 15 diagnostics to have error codes (E0380-E0394).
Also adds explanations for E0380 and E0381.
1 parent fbef978 commit 570a043

File tree

9 files changed

+94
-66
lines changed

9 files changed

+94
-66
lines changed

src/librustc/diagnostics.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -891,5 +891,7 @@ register_diagnostics! {
891891
E0315, // cannot invoke closure outside of its lifetime
892892
E0316, // nested quantification of lifetimes
893893
E0370, // discriminant overflow
894-
E0378 // method calls limited to constant inherent methods
894+
E0378, // method calls limited to constant inherent methods
895+
E0394 // cannot refer to other statics by value, use the address-of
896+
// operator or a constant instead
895897
}

src/librustc/middle/check_const.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -762,9 +762,9 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'tcx> {
762762
// statics cannot be consumed by value at any time, that would imply
763763
// that they're an initializer (what a const is for) or kept in sync
764764
// over time (not feasible), so deny it outright.
765-
self.tcx.sess.span_err(consume_span,
766-
"cannot refer to other statics by value, use the \
767-
address-of operator or a constant instead");
765+
span_err!(self.tcx.sess, consume_span, E0394,
766+
"cannot refer to other statics by value, use the \
767+
address-of operator or a constant instead");
768768
}
769769
break;
770770
}

src/librustc_borrowck/borrowck/mod.rs

+33-38
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
603603

604604
let (ol, moved_lp_msg) = match the_move.kind {
605605
move_data::Declared => {
606-
self.tcx.sess.span_err(
607-
use_span,
608-
&format!("{} of possibly uninitialized variable: `{}`",
609-
verb,
610-
self.loan_path_to_string(lp)));
606+
span_err!(
607+
self.tcx.sess, use_span, E0381,
608+
"{} of possibly uninitialized variable: `{}`",
609+
verb,
610+
self.loan_path_to_string(lp));
611+
611612
(self.loan_path_to_string(moved_lp),
612613
String::new())
613614
}
@@ -644,12 +645,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
644645
let msg = if !has_fork && partial { "partially " }
645646
else if has_fork && !has_common { "collaterally "}
646647
else { "" };
647-
self.tcx.sess.span_err(
648-
use_span,
649-
&format!("{} of {}moved value: `{}`",
650-
verb,
651-
msg,
652-
nl));
648+
span_err!(
649+
self.tcx.sess, use_span, E0382,
650+
"{} of {}moved value: `{}`",
651+
verb, msg, nl);
653652
(ol, moved_lp_msg)
654653
}
655654
};
@@ -762,23 +761,21 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
762761
&self,
763762
span: Span,
764763
lp: &LoanPath<'tcx>) {
765-
self.tcx
766-
.sess
767-
.span_err(span,
768-
&format!("partial reinitialization of uninitialized \
769-
structure `{}`",
770-
self.loan_path_to_string(lp)));
764+
span_err!(
765+
self.tcx.sess, span, E0383,
766+
"partial reinitialization of uninitialized structure `{}`",
767+
self.loan_path_to_string(lp));
771768
}
772769

773770
pub fn report_reassigned_immutable_variable(&self,
774771
span: Span,
775772
lp: &LoanPath<'tcx>,
776773
assign:
777774
&move_data::Assignment) {
778-
self.tcx.sess.span_err(
779-
span,
780-
&format!("re-assignment of immutable variable `{}`",
781-
self.loan_path_to_string(lp)));
775+
span_err!(
776+
self.tcx.sess, span, E0384,
777+
"re-assignment of immutable variable `{}`",
778+
self.loan_path_to_string(lp));
782779
self.tcx.sess.span_note(assign.span, "prior assignment occurs here");
783780
}
784781

@@ -896,21 +893,19 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
896893

897894
match cause {
898895
mc::AliasableOther => {
899-
self.tcx.sess.span_err(
900-
span,
901-
&format!("{} in an aliasable location",
902-
prefix));
896+
span_err!(
897+
self.tcx.sess, span, E0385,
898+
"{} in an aliasable location", prefix);
903899
}
904900
mc::AliasableReason::UnaliasableImmutable => {
905-
self.tcx.sess.span_err(
906-
span,
907-
&format!("{} in an immutable container",
908-
prefix));
901+
span_err!(
902+
self.tcx.sess, span, E0386,
903+
"{} in an immutable container", prefix);
909904
}
910905
mc::AliasableClosure(id) => {
911-
self.tcx.sess.span_err(span,
912-
&format!("{} in a captured outer \
913-
variable in an `Fn` closure", prefix));
906+
span_err!(
907+
self.tcx.sess, span, E0387,
908+
"{} in a captured outer variable in an `Fn` closure", prefix);
914909
if let BorrowViolation(euv::ClosureCapture(_)) = kind {
915910
// The aliasability violation with closure captures can
916911
// happen for nested closures, so we know the enclosing
@@ -925,14 +920,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
925920
}
926921
mc::AliasableStatic(..) |
927922
mc::AliasableStaticMut(..) => {
928-
self.tcx.sess.span_err(
929-
span,
930-
&format!("{} in a static location", prefix));
923+
span_err!(
924+
self.tcx.sess, span, E0388,
925+
"{} in a static location", prefix);
931926
}
932927
mc::AliasableBorrowed => {
933-
self.tcx.sess.span_err(
934-
span,
935-
&format!("{} in a `&` reference", prefix));
928+
span_err!(
929+
self.tcx.sess, span, E0389,
930+
"{} in a `&` reference", prefix);
936931
}
937932
}
938933

src/librustc_borrowck/diagnostics.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@
1010

1111
#![allow(non_snake_case)]
1212

13+
register_long_diagnostics! {
14+
15+
E0381: r##"
16+
It is not allowed to use or capture an uninitialized variable. For example:
17+
18+
```
19+
fn main() {
20+
let x: i32;
21+
let y = x; // error, use of possibly uninitialized variable
22+
```
23+
24+
To fix this, ensure that any declared variables are initialized before being
25+
used.
26+
"##
27+
28+
}
29+
1330
register_diagnostics! {
14-
E0373 // closure may outlive current fn, but it borrows {}, which is owned by current fn
31+
E0373, // closure may outlive current fn, but it borrows {}, which is owned by current fn
32+
E0382, // use of partially/collaterally moved value
33+
E0383, // partial reinitialization of uninitialized structure
34+
E0384, // reassignment of immutable variable
35+
E0385, // {} in an aliasable location
36+
E0386, // {} in an immutable container
37+
E0387, // {} in a captured outer variable in an `Fn` closure
38+
E0388, // {} in a static location
39+
E0389 // {} in a `&` reference
1540
}

src/librustc_typeck/astconv.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,12 @@ fn create_substs_for_ast_path<'tcx>(
437437
// defaults. This will lead to an ICE if we are not
438438
// careful!
439439
if self_ty.is_none() && ty::type_has_self(default) {
440-
tcx.sess.span_err(
441-
span,
442-
&format!("the type parameter `{}` must be explicitly specified \
443-
in an object type because its default value `{}` references \
444-
the type `Self`",
445-
param.name.user_string(tcx),
446-
default.user_string(tcx)));
440+
span_err!(tcx.sess, span, E0393,
441+
"the type parameter `{}` must be explicitly specified \
442+
in an object type because its default value `{}` references \
443+
the type `Self`",
444+
param.name.user_string(tcx),
445+
default.user_string(tcx));
447446
substs.types.push(TypeSpace, tcx.types.err);
448447
} else {
449448
// This is a default type parameter.

src/librustc_typeck/check/wf.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
124124
reject_non_type_param_bounds(ccx.tcx, item.span, &trait_predicates);
125125
if ty::trait_has_default_impl(ccx.tcx, local_def(item.id)) {
126126
if !items.is_empty() {
127-
ccx.tcx.sess.span_err(
128-
item.span,
129-
"traits with default impls (`e.g. unsafe impl Trait for ..`) must \
130-
have no methods or associated items")
127+
span_err!(ccx.tcx.sess, item.span, E0380,
128+
"traits with default impls (`e.g. unsafe impl \
129+
Trait for ..`) must have no methods or associated items")
131130
}
132131
}
133132
}
@@ -353,10 +352,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
353352
span: Span,
354353
param_name: ast::Name)
355354
{
356-
self.tcx().sess.span_err(
357-
span,
358-
&format!("parameter `{}` is never used",
359-
param_name.user_string(self.tcx())));
355+
span_err!(self.tcx().sess, span, E0392,
356+
"parameter `{}` is never used", param_name.user_string(self.tcx()));
360357

361358
let suggested_marker_id = self.tcx().lang_items.phantom_data();
362359
match suggested_marker_id {

src/librustc_typeck/coherence/orphan.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
4848
match lang_def_id {
4949
Some(lang_def_id) if lang_def_id == impl_def_id => { /* OK */ },
5050
_ => {
51-
self.tcx.sess.span_err(
52-
span,
53-
&format!("only a single inherent implementation marked with `#[lang = \"{}\"]` \
54-
is allowed for the `{}` primitive", lang, ty));
51+
span_err!(self.tcx.sess, span, E0390,
52+
"only a single inherent implementation marked with `#[lang = \"{}\"]` \
53+
is allowed for the `{}` primitive", lang, ty);
5554
}
5655
}
5756
}

src/librustc_typeck/collect.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,8 @@ impl<'a,'tcx> CrateCtxt<'a,'tcx> {
236236
assert!(!cycle.is_empty());
237237
let tcx = self.tcx;
238238

239-
tcx.sess.span_err(
240-
span,
241-
&format!("unsupported cyclic reference between types/traits detected"));
239+
span_err!(tcx.sess, span, E0391,
240+
"unsupported cyclic reference between types/traits detected");
242241

243242
match cycle[0] {
244243
AstConvRequest::GetItemTypeScheme(def_id) |

src/librustc_typeck/diagnostics.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,12 @@ Trait2 { ... }`) does not work if the trait is not object-safe. Please see the
10961096
[RFC 255] for more details on object safety rules.
10971097
10981098
[RFC 255]: https://github.com/rust-lang/rfcs/pull/255
1099+
"##,
1100+
1101+
E0380: r##"
1102+
Default impls are only allowed for traits with no methods or associated items.
1103+
For more information see the [opt-in builtin traits RFC](https://github.com/rust
1104+
-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
10991105
"##
11001106

11011107
}
@@ -1229,5 +1235,11 @@ register_diagnostics! {
12291235
// between structures
12301236
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
12311237
// between structures with the same definition
1232-
E0379 // trait fns cannot be const
1238+
E0379, // trait fns cannot be const
1239+
E0390, // only a single inherent implementation marked with
1240+
// `#[lang = \"{}\"]` is allowed for the `{}` primitive
1241+
E0391, // unsupported cyclic reference between types/traits detected
1242+
E0392, // parameter `{}` is never used
1243+
E0393 // the type parameter `{}` must be explicitly specified in an object
1244+
// type because its default value `{}` references the type `Self`"
12331245
}

0 commit comments

Comments
 (0)