Skip to content

Commit 268decb

Browse files
committed
make all uses of ty::Error or ConstKind::Error delay a span bug
1 parent f315c35 commit 268decb

File tree

71 files changed

+279
-225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+279
-225
lines changed

Diff for: src/librustc_codegen_ssa/debuginfo/type_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub fn push_debuginfo_type_name<'tcx>(
195195
tcx.def_key(def_id).disambiguated_data.disambiguator
196196
));
197197
}
198-
ty::Error
198+
ty::Error(_)
199199
| ty::Infer(_)
200200
| ty::Placeholder(..)
201201
| ty::Projection(..)

Diff for: src/librustc_infer/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
403403
| ty::Float(..)
404404
| ty::Adt(..)
405405
| ty::Str
406-
| ty::Error
406+
| ty::Error(_)
407407
| ty::Array(..)
408408
| ty::Slice(..)
409409
| ty::RawPtr(..)

Diff for: src/librustc_infer/infer/canonical/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
154154
self.tcx
155155
.mk_const(ty::Const {
156156
val: ty::ConstKind::Placeholder(placeholder_mapped),
157-
ty: self.tcx.types.err, // FIXME(const_generics)
157+
ty: self.tcx.ty_error(), // FIXME(const_generics)
158158
})
159159
.into()
160160
}

Diff for: src/librustc_infer/infer/freshen.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
192192
| ty::Float(..)
193193
| ty::Adt(..)
194194
| ty::Str
195-
| ty::Error
195+
| ty::Error(_)
196196
| ty::Array(..)
197197
| ty::Slice(..)
198198
| ty::RawPtr(..)
@@ -250,7 +250,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
250250
ty::ConstKind::Param(_)
251251
| ty::ConstKind::Value(_)
252252
| ty::ConstKind::Unevaluated(..)
253-
| ty::ConstKind::Error => {}
253+
| ty::ConstKind::Error(_) => {}
254254
}
255255

256256
ct.super_fold_with(self)

Diff for: src/librustc_infer/infer/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1751,9 +1751,10 @@ impl<'tcx> TypeTrace<'tcx> {
17511751
}
17521752

17531753
pub fn dummy(tcx: TyCtxt<'tcx>) -> TypeTrace<'tcx> {
1754+
let err = tcx.ty_error();
17541755
TypeTrace {
17551756
cause: ObligationCause::dummy(),
1756-
values: Types(ExpectedFound { expected: tcx.types.err, found: tcx.types.err }),
1757+
values: Types(ExpectedFound { expected: err, found: err }),
17571758
}
17581759
}
17591760
}

Diff for: src/librustc_infer/infer/resolve.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
189189
match t.kind {
190190
ty::Infer(ty::TyVar(vid)) => {
191191
self.err = Some(FixupError::UnresolvedTy(vid));
192-
self.tcx().types.err
192+
self.tcx().ty_error()
193193
}
194194
ty::Infer(ty::IntVar(vid)) => {
195195
self.err = Some(FixupError::UnresolvedIntTy(vid));
196-
self.tcx().types.err
196+
self.tcx().ty_error()
197197
}
198198
ty::Infer(ty::FloatVar(vid)) => {
199199
self.err = Some(FixupError::UnresolvedFloatTy(vid));
200-
self.tcx().types.err
200+
self.tcx().ty_error()
201201
}
202202
ty::Infer(_) => {
203203
bug!("Unexpected type in full type resolver: {:?}", t);
@@ -228,7 +228,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
228228
match c.val {
229229
ty::ConstKind::Infer(InferConst::Var(vid)) => {
230230
self.err = Some(FixupError::UnresolvedConst(vid));
231-
return self.tcx().mk_const(ty::Const { val: ty::ConstKind::Error, ty: c.ty });
231+
return self.tcx().const_error(c.ty);
232232
}
233233
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
234234
bug!("Unexpected const in full const resolver: {:?}", c);

Diff for: src/librustc_infer/infer/sub.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
119119
Ok(a)
120120
}
121121

122-
(&ty::Error, _) | (_, &ty::Error) => {
122+
(&ty::Error(_), _) | (_, &ty::Error(_)) => {
123123
infcx.set_tainted_by_errors();
124-
Ok(self.tcx().types.err)
124+
Ok(self.tcx().ty_error())
125125
}
126126

127127
_ => {

Diff for: src/librustc_lint/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
889889
ty::Param(..)
890890
| ty::Infer(..)
891891
| ty::Bound(..)
892-
| ty::Error
892+
| ty::Error(_)
893893
| ty::Closure(..)
894894
| ty::Generator(..)
895895
| ty::GeneratorWitness(..)

Diff for: src/librustc_middle/traits/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
221221
| ty::Ref(..)
222222
| ty::Str
223223
| ty::Foreign(..)
224-
| ty::Error => true,
224+
| ty::Error(_) => true,
225225

226226
// [T; N] and [T] have same properties as T.
227227
ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, ty),

Diff for: src/librustc_middle/ty/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl TypeRelation<'tcx> for Match<'tcx> {
7979
Err(TypeError::Sorts(relate::expected_found(self, &a, &b)))
8080
}
8181

82-
(&ty::Error, _) | (_, &ty::Error) => Ok(self.tcx().types.err),
82+
(&ty::Error(_), _) | (_, &ty::Error(_)) => Ok(self.tcx().ty_error()),
8383

8484
_ => relate::super_relate_tys(self, a, b),
8585
}

Diff for: src/librustc_middle/ty/context.rs

+45-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use rustc_session::lint::{Level, Lint};
4646
use rustc_session::Session;
4747
use rustc_span::source_map::MultiSpan;
4848
use rustc_span::symbol::{kw, sym, Symbol};
49-
use rustc_span::Span;
49+
use rustc_span::{Span, DUMMY_SP};
5050
use rustc_target::abi::{Layout, TargetDataLayout, VariantIdx};
5151
use rustc_target::spec::abi;
5252

@@ -145,7 +145,6 @@ pub struct CommonTypes<'tcx> {
145145
pub f64: Ty<'tcx>,
146146
pub never: Ty<'tcx>,
147147
pub self_param: Ty<'tcx>,
148-
pub err: Ty<'tcx>,
149148

150149
/// Dummy type used for the `Self` of a `TraitRef` created for converting
151150
/// a trait object, and which gets removed in `ExistentialTraitRef`.
@@ -804,7 +803,6 @@ impl<'tcx> CommonTypes<'tcx> {
804803
bool: mk(Bool),
805804
char: mk(Char),
806805
never: mk(Never),
807-
err: mk(Error),
808806
isize: mk(Int(ast::IntTy::Isize)),
809807
i8: mk(Int(ast::IntTy::I8)),
810808
i16: mk(Int(ast::IntTy::I16)),
@@ -1143,6 +1141,49 @@ impl<'tcx> TyCtxt<'tcx> {
11431141
}
11441142
}
11451143

1144+
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
1145+
#[track_caller]
1146+
pub fn ty_error(self) -> Ty<'tcx> {
1147+
self.err_with_message_and_location(
1148+
DUMMY_SP,
1149+
"TyKind::Error constructed but no error reported",
1150+
std::panic::Location::caller(),
1151+
)
1152+
}
1153+
1154+
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` with the given `msg to
1155+
/// ensure it gets used.
1156+
#[track_caller]
1157+
pub fn ty_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Ty<'tcx> {
1158+
self.err_with_message_and_location(span, msg, std::panic::Location::caller())
1159+
}
1160+
1161+
pub fn err_with_message_and_location<S: Into<MultiSpan>>(
1162+
self,
1163+
span: S,
1164+
msg: &str,
1165+
loc: &'static std::panic::Location<'static>,
1166+
) -> Ty<'tcx> {
1167+
self.sess.delay_span_bug(span, &format!("{}: {}", loc, msg));
1168+
self.mk_ty(Error(super::sty::DelaySpanBugEmitted(())))
1169+
}
1170+
1171+
/// Like `err` but for constants.
1172+
#[track_caller]
1173+
pub fn const_error(self, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
1174+
self.sess.delay_span_bug(
1175+
DUMMY_SP,
1176+
&format!(
1177+
"ty::ConstKind::Error constructed but no error reported. {}",
1178+
std::panic::Location::caller()
1179+
),
1180+
);
1181+
self.mk_const(ty::Const {
1182+
val: ty::ConstKind::Error(super::sty::DelaySpanBugEmitted(())),
1183+
ty,
1184+
})
1185+
}
1186+
11461187
pub fn consider_optimizing<T: Fn() -> String>(&self, msg: T) -> bool {
11471188
let cname = self.crate_name(LOCAL_CRATE).as_str();
11481189
self.sess.consider_optimizing(&cname, msg)
@@ -1846,7 +1887,7 @@ macro_rules! sty_debug_print {
18461887
let variant = match t.kind {
18471888
ty::Bool | ty::Char | ty::Int(..) | ty::Uint(..) |
18481889
ty::Float(..) | ty::Str | ty::Never => continue,
1849-
ty::Error => /* unimportant */ continue,
1890+
ty::Error(_) => /* unimportant */ continue,
18501891
$(ty::$variant(..) => &mut $variant,)*
18511892
};
18521893
let lt = t.flags.intersects(ty::TypeFlags::HAS_RE_INFER);

Diff for: src/librustc_middle/ty/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,14 @@ impl<'tcx> ty::TyS<'tcx> {
286286
ty::Projection(_) => "associated type".into(),
287287
ty::Param(p) => format!("type parameter `{}`", p).into(),
288288
ty::Opaque(..) => "opaque type".into(),
289-
ty::Error => "type error".into(),
289+
ty::Error(_) => "type error".into(),
290290
}
291291
}
292292

293293
pub fn prefix_string(&self) -> Cow<'static, str> {
294294
match self.kind {
295295
ty::Infer(_)
296-
| ty::Error
296+
| ty::Error(_)
297297
| ty::Bool
298298
| ty::Char
299299
| ty::Int(_)

Diff for: src/librustc_middle/ty/fast_reject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn simplify_type(
104104
}
105105
ty::Opaque(def_id, _) => Some(OpaqueSimplifiedType(def_id)),
106106
ty::Foreign(def_id) => Some(ForeignSimplifiedType(def_id)),
107-
ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) | ty::Error => None,
107+
ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) | ty::Error(_) => None,
108108
}
109109
}
110110

Diff for: src/librustc_middle/ty/flags.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl FlagComputation {
7070
| &ty::Str
7171
| &ty::Foreign(..) => {}
7272

73-
&ty::Error => self.add_flags(TypeFlags::HAS_ERROR),
73+
&ty::Error(_) => self.add_flags(TypeFlags::HAS_ERROR),
7474

7575
&ty::Param(_) => {
7676
self.add_flags(TypeFlags::HAS_TY_PARAM);
@@ -227,7 +227,7 @@ impl FlagComputation {
227227
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
228228
}
229229
ty::ConstKind::Value(_) => {}
230-
ty::ConstKind::Error => self.add_flags(TypeFlags::HAS_ERROR),
230+
ty::ConstKind::Error(_) => self.add_flags(TypeFlags::HAS_ERROR),
231231
}
232232
}
233233

Diff for: src/librustc_middle/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
12451245
bug!("Layout::compute: unexpected type `{}`", ty)
12461246
}
12471247

1248-
ty::Param(_) | ty::Error => {
1248+
ty::Param(_) | ty::Error(_) => {
12491249
return Err(LayoutError::Unknown(ty));
12501250
}
12511251
})
@@ -2141,7 +2141,7 @@ where
21412141
| ty::Opaque(..)
21422142
| ty::Param(_)
21432143
| ty::Infer(_)
2144-
| ty::Error => bug!("TyAndLayout::field_type: unexpected type `{}`", this.ty),
2144+
| ty::Error(_) => bug!("TyAndLayout::field_type: unexpected type `{}`", this.ty),
21452145
})
21462146
}
21472147

Diff for: src/librustc_middle/ty/outlives.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn compute_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Compo
171171
ty::Dynamic(..) | // OutlivesObject, OutlivesFragment (*)
172172
ty::Placeholder(..) |
173173
ty::Bound(..) |
174-
ty::Error => {
174+
ty::Error(_) => {
175175
// (*) Function pointers and trait objects are both binders.
176176
// In the RFC, this means we would add the bound regions to
177177
// the "bound regions list". In our representation, no such

Diff for: src/librustc_middle/ty/print/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
298298
| ty::Opaque(..)
299299
| ty::Infer(_)
300300
| ty::Bound(..)
301-
| ty::Error
301+
| ty::Error(_)
302302
| ty::GeneratorWitness(..)
303303
| ty::Never
304304
| ty::Float(_) => None,

Diff for: src/librustc_middle/ty/print/obsolete.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl DefPathBasedNames<'tcx> {
144144
let substs = substs.truncate_to(self.tcx, generics);
145145
self.push_generic_params(substs, iter::empty(), output, debug);
146146
}
147-
ty::Error
147+
ty::Error(_)
148148
| ty::Bound(..)
149149
| ty::Infer(_)
150150
| ty::Placeholder(..)

Diff for: src/librustc_middle/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ pub trait PrettyPrinter<'tcx>:
518518
p!(write("{}", infer_ty))
519519
}
520520
}
521-
ty::Error => p!(write("[type error]")),
521+
ty::Error(_) => p!(write("[type error]")),
522522
ty::Param(ref param_ty) => p!(write("{}", param_ty)),
523523
ty::Bound(debruijn, bound_ty) => match bound_ty.kind {
524524
ty::BoundTyKind::Anon => self.pretty_print_bound_var(debruijn, bound_ty.var)?,
@@ -919,7 +919,7 @@ pub trait PrettyPrinter<'tcx>:
919919
self.pretty_print_bound_var(debruijn, bound_var)?
920920
}
921921
ty::ConstKind::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
922-
ty::ConstKind::Error => p!(write("[const error]")),
922+
ty::ConstKind::Error(_) => p!(write("[const error]")),
923923
};
924924
Ok(self)
925925
}

Diff for: src/librustc_middle/ty/query/values.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<'tcx> Value<'tcx> for &'_ TyS<'_> {
1717
fn from_cycle_error(tcx: TyCtxt<'tcx>) -> Self {
1818
// SAFETY: This is never called when `Self` is not `Ty<'tcx>`.
1919
// FIXME: Represent the above fact in the trait system somehow.
20-
unsafe { std::mem::transmute::<Ty<'tcx>, Ty<'_>>(tcx.types.err) }
20+
unsafe { std::mem::transmute::<Ty<'tcx>, Ty<'_>>(tcx.ty_error()) }
2121
}
2222
}
2323

@@ -33,7 +33,7 @@ impl<'tcx> Value<'tcx> for AdtSizedConstraint<'_> {
3333
// FIXME: Represent the above fact in the trait system somehow.
3434
unsafe {
3535
std::mem::transmute::<AdtSizedConstraint<'tcx>, AdtSizedConstraint<'_>>(
36-
AdtSizedConstraint(tcx.intern_type_list(&[tcx.types.err])),
36+
AdtSizedConstraint(tcx.intern_type_list(&[tcx.ty_error()])),
3737
)
3838
}
3939
}

Diff for: src/librustc_middle/ty/relate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
354354
bug!("bound types encountered in super_relate_tys")
355355
}
356356

357-
(&ty::Error, _) | (_, &ty::Error) => Ok(tcx.types.err),
357+
(&ty::Error(_), _) | (_, &ty::Error(_)) => Ok(tcx.ty_error()),
358358

359359
(&ty::Never, _)
360360
| (&ty::Char, _)
@@ -524,7 +524,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
524524
bug!("var types encountered in super_relate_consts: {:?} {:?}", a, b)
525525
}
526526

527-
(ty::ConstKind::Error, _) | (_, ty::ConstKind::Error) => Ok(ty::ConstKind::Error),
527+
(ty::ConstKind::Error(d), _) | (_, ty::ConstKind::Error(d)) => Ok(ty::ConstKind::Error(d)),
528528

529529
(ty::ConstKind::Param(a_p), ty::ConstKind::Param(b_p)) if a_p.index == b_p.index => {
530530
return Ok(a);

Diff for: src/librustc_middle/ty/structural_impls.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
911911
| ty::Int(_)
912912
| ty::Uint(_)
913913
| ty::Float(_)
914-
| ty::Error
914+
| ty::Error(_)
915915
| ty::Infer(_)
916916
| ty::Param(..)
917917
| ty::Bound(..)
@@ -952,7 +952,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
952952
| ty::Int(_)
953953
| ty::Uint(_)
954954
| ty::Float(_)
955-
| ty::Error
955+
| ty::Error(_)
956956
| ty::Infer(_)
957957
| ty::Bound(..)
958958
| ty::Placeholder(..)
@@ -1051,7 +1051,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> {
10511051
ty::ConstKind::Value(_)
10521052
| ty::ConstKind::Bound(..)
10531053
| ty::ConstKind::Placeholder(..)
1054-
| ty::ConstKind::Error => *self,
1054+
| ty::ConstKind::Error(_) => *self,
10551055
}
10561056
}
10571057

@@ -1063,7 +1063,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> {
10631063
ty::ConstKind::Value(_)
10641064
| ty::ConstKind::Bound(..)
10651065
| ty::ConstKind::Placeholder(_)
1066-
| ty::ConstKind::Error => false,
1066+
| ty::ConstKind::Error(_) => false,
10671067
}
10681068
}
10691069
}

0 commit comments

Comments
 (0)