Skip to content

Commit 5a7da25

Browse files
author
Nick Hamann
committed
Convert 15 diagnostics to have error codes (E0380-E0394).
1 parent 98849d6 commit 5a7da25

File tree

9 files changed

+78
-66
lines changed

9 files changed

+78
-66
lines changed

src/librustc/diagnostics.rs

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 33 additions & 38 deletions
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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,14 @@
1111
#![allow(non_snake_case)]
1212

1313
register_diagnostics! {
14-
E0373 // closure may outlive current fn, but it borrows {}, which is owned by current fn
14+
E0373, // closure may outlive current fn, but it borrows {}, which is owned by current fn
15+
E0381, // use/capture of possibly uninitialized variable
16+
E0382, // use of partially/collaterally moved value
17+
E0383, // partial reinitialization of uninitialized structure
18+
E0384, // reassignment of immutable variable
19+
E0385, // {} in an aliasable location
20+
E0386, // {} in an immutable container
21+
E0387, // {} in a captured outer variable in an `Fn` closure
22+
E0388, // {} in a static location
23+
E0389 // {} in a `&` reference
1524
}

src/librustc_typeck/astconv.rs

Lines changed: 6 additions & 7 deletions
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

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

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

src/librustc_typeck/coherence/orphan.rs

Lines changed: 3 additions & 4 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,12 @@ Trait2 { ... }`) does not work if the trait is not object-safe. Please see the
10401040
[RFC 255] for more details on object safety rules.
10411041
10421042
[RFC 255]: https://github.com/rust-lang/rfcs/pull/255
1043+
"##,
1044+
1045+
E0380: r##"
1046+
Default impls are only allowed for traits with no methods or associated items.
1047+
For more information see the [opt-in builtin traits RFC](https://github.com/rust
1048+
-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
10431049
"##
10441050

10451051
}
@@ -1176,5 +1182,11 @@ register_diagnostics! {
11761182
// between structures
11771183
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
11781184
// between structures with the same definition
1179-
E0379 // trait fns cannot be const
1185+
E0379, // trait fns cannot be const
1186+
E0390, // only a single inherent implementation marked with
1187+
// `#[lang = \"{}\"]` is allowed for the `{}` primitive
1188+
E0391, // unsupported cyclic reference between types/traits detected
1189+
E0392, // parameter `{}` is never used
1190+
E0393 // the type parameter `{}` must be explicitly specified in an object
1191+
// type because its default value `{}` references the type `Self`"
11801192
}

0 commit comments

Comments
 (0)