Skip to content

Commit 9d388d4

Browse files
authored
Rollup merge of #70551 - mark-i-m:ty-err-2, r=varkor
Make all uses of ty::Error delay a span bug r? @eddyb A second attempt at #70245 resolves #70866
2 parents e55d3f9 + cfdbbb5 commit 9d388d4

File tree

72 files changed

+254
-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.

72 files changed

+254
-225
lines changed

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(..)

src/librustc_errors/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
66
#![feature(crate_visibility_modifier)]
77
#![feature(nll)]
8+
#![feature(track_caller)]
89

910
pub use emitter::ColorConfig;
1011

@@ -621,6 +622,7 @@ impl Handler {
621622
self.inner.borrow_mut().span_bug(span, msg)
622623
}
623624

625+
#[track_caller]
624626
pub fn delay_span_bug(&self, span: impl Into<MultiSpan>, msg: &str) {
625627
self.inner.borrow_mut().delay_span_bug(span, msg)
626628
}
@@ -873,6 +875,7 @@ impl HandlerInner {
873875
self.emit_diagnostic(diag.set_span(sp));
874876
}
875877

878+
#[track_caller]
876879
fn delay_span_bug(&mut self, sp: impl Into<MultiSpan>, msg: &str) {
877880
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
878881
// incrementing `err_count` by one, so we need to +1 the comparing.
@@ -883,6 +886,7 @@ impl HandlerInner {
883886
}
884887
let mut diagnostic = Diagnostic::new(Level::Bug, msg);
885888
diagnostic.set_span(sp.into());
889+
diagnostic.note(&format!("delayed at {}", std::panic::Location::caller()));
886890
self.delay_as_bug(diagnostic)
887891
}
888892

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(..)

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
}

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)

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
}

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);

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
_ => {

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(..)

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),

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
}

src/librustc_middle/ty/context.rs

+27-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`.
@@ -803,7 +802,6 @@ impl<'tcx> CommonTypes<'tcx> {
803802
bool: mk(Bool),
804803
char: mk(Char),
805804
never: mk(Never),
806-
err: mk(Error),
807805
isize: mk(Int(ast::IntTy::Isize)),
808806
i8: mk(Int(ast::IntTy::I8)),
809807
i16: mk(Int(ast::IntTy::I16)),
@@ -1142,6 +1140,31 @@ impl<'tcx> TyCtxt<'tcx> {
11421140
}
11431141
}
11441142

1143+
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
1144+
#[track_caller]
1145+
pub fn ty_error(self) -> Ty<'tcx> {
1146+
self.ty_error_with_message(DUMMY_SP, "TyKind::Error constructed but no error reported")
1147+
}
1148+
1149+
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` with the given `msg to
1150+
/// ensure it gets used.
1151+
#[track_caller]
1152+
pub fn ty_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Ty<'tcx> {
1153+
self.sess.delay_span_bug(span, msg);
1154+
self.mk_ty(Error(super::sty::DelaySpanBugEmitted(())))
1155+
}
1156+
1157+
/// Like `err` but for constants.
1158+
#[track_caller]
1159+
pub fn const_error(self, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
1160+
self.sess
1161+
.delay_span_bug(DUMMY_SP, "ty::ConstKind::Error constructed but no error reported.");
1162+
self.mk_const(ty::Const {
1163+
val: ty::ConstKind::Error(super::sty::DelaySpanBugEmitted(())),
1164+
ty,
1165+
})
1166+
}
1167+
11451168
pub fn consider_optimizing<T: Fn() -> String>(&self, msg: T) -> bool {
11461169
let cname = self.crate_name(LOCAL_CRATE).as_str();
11471170
self.sess.consider_optimizing(&cname, msg)
@@ -1845,7 +1868,7 @@ macro_rules! sty_debug_print {
18451868
let variant = match t.kind {
18461869
ty::Bool | ty::Char | ty::Int(..) | ty::Uint(..) |
18471870
ty::Float(..) | ty::Str | ty::Never => continue,
1848-
ty::Error => /* unimportant */ continue,
1871+
ty::Error(_) => /* unimportant */ continue,
18491872
$(ty::$variant(..) => &mut $variant,)*
18501873
};
18511874
let lt = t.flags.intersects(ty::TypeFlags::HAS_RE_INFER);

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(_)

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

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

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

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

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,

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(..)

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
}

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
}

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);

0 commit comments

Comments
 (0)