Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Testing #70551 with de-abuse PRs #71939

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
03ceec5
make all uses of ty::Error or ConstKind::Error delay a span bug
mark-i-m May 6, 2020
b9ec308
lazily construct errors
mark-i-m May 6, 2020
3633832
use trait_object_dummy_self instead of err
mark-i-m May 6, 2020
2218f59
Factor the code that generates TyErrs
Nadrieril Apr 13, 2020
7037bcc
We already handle arrays of unknown length correctly
Nadrieril Apr 13, 2020
40553dc
Only need TyErr for uninhabited types
Nadrieril Apr 13, 2020
31acfb9
Small tweaks
Nadrieril Apr 13, 2020
e73b84a
Factor out the condition for hiding fields
Nadrieril Apr 13, 2020
76df2f4
Remove caching of wildcard_subpatterns
Nadrieril May 4, 2020
72beeae
Factor out a struct holding the fields of a variant
Nadrieril May 4, 2020
710fc8a
Swap responsibility for generating wildcard fields
Nadrieril May 4, 2020
d49fda9
`wildcards_subpatterns` returns PatStack
Nadrieril May 4, 2020
05623fd
Prepare VariantsFields for filtering
Nadrieril May 4, 2020
0c55f7f
Filter out fields that should not be seen.
Nadrieril May 4, 2020
f6a9045
Rename VariantFields to StructFields
Nadrieril May 5, 2020
b879567
Restore caching of wildcard subfields
Nadrieril May 5, 2020
7ad17a5
Fix incorrect ordering
Nadrieril May 5, 2020
c8e36a2
Use `Fields` everywhere relevant
Nadrieril May 5, 2020
9d9d3c9
We don't use TyErr anymore
Nadrieril May 5, 2020
af175e0
Document Fields a bit
Nadrieril May 5, 2020
f95cbac
Inline cx methods used only once
Nadrieril May 5, 2020
b12aab5
Inline StructFields into Fields
Nadrieril May 5, 2020
c67da30
Revert "We don't use TyErr anymore"
mark-i-m May 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
self.tcx
.mk_const(ty::Const {
val: ty::ConstKind::Placeholder(placeholder_mapped),
ty: self.tcx.types.err, // FIXME(const_generics)
ty: self.tcx.err(), // FIXME(const_generics)
})
.into()
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,7 @@ impl<'tcx> TypeTrace<'tcx> {
pub fn dummy(tcx: TyCtxt<'tcx>) -> TypeTrace<'tcx> {
TypeTrace {
cause: ObligationCause::dummy(),
values: Types(ExpectedFound { expected: tcx.types.err, found: tcx.types.err }),
values: Types(ExpectedFound { expected: tcx.err(), found: tcx.err() }),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_infer/infer/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
match t.kind {
ty::Infer(ty::TyVar(vid)) => {
self.err = Some(FixupError::UnresolvedTy(vid));
self.tcx().types.err
self.tcx().err()
}
ty::Infer(ty::IntVar(vid)) => {
self.err = Some(FixupError::UnresolvedIntTy(vid));
self.tcx().types.err
self.tcx().err()
}
ty::Infer(ty::FloatVar(vid)) => {
self.err = Some(FixupError::UnresolvedFloatTy(vid));
self.tcx().types.err
self.tcx().err()
}
ty::Infer(_) => {
bug!("Unexpected type in full type resolver: {:?}", t);
Expand Down Expand Up @@ -227,7 +227,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
match c.val {
ty::ConstKind::Infer(InferConst::Var(vid)) => {
self.err = Some(FixupError::UnresolvedConst(vid));
return self.tcx().mk_const(ty::Const { val: ty::ConstKind::Error, ty: c.ty });
return self.tcx().err_const(c.ty);
}
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
bug!("Unexpected const in full const resolver: {:?}", c);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {

(&ty::Error, _) | (_, &ty::Error) => {
infcx.set_tainted_by_errors();
Ok(self.tcx().types.err)
Ok(self.tcx().err())
}

_ => {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_middle/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#![feature(rustc_attrs)]
#![feature(hash_raw_entry)]
#![feature(int_error_matching)]
#![feature(track_caller)]
#![recursion_limit = "512"]

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl TypeRelation<'tcx> for Match<'tcx> {
Err(TypeError::Sorts(relate::expected_found(self, &a, &b)))
}

(&ty::Error, _) | (_, &ty::Error) => Ok(self.tcx().types.err),
(&ty::Error, _) | (_, &ty::Error) => Ok(self.tcx().err()),

_ => relate::super_relate_tys(self, a, b),
}
Expand Down
30 changes: 27 additions & 3 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use rustc_session::lint::{Level, Lint};
use rustc_session::Session;
use rustc_span::source_map::MultiSpan;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{Layout, TargetDataLayout, VariantIdx};
use rustc_target::spec::abi;

Expand Down Expand Up @@ -152,7 +152,6 @@ pub struct CommonTypes<'tcx> {
pub f64: Ty<'tcx>,
pub never: Ty<'tcx>,
pub self_param: Ty<'tcx>,
pub err: Ty<'tcx>,

/// Dummy type used for the `Self` of a `TraitRef` created for converting
/// a trait object, and which gets removed in `ExistentialTraitRef`.
Expand Down Expand Up @@ -811,7 +810,6 @@ impl<'tcx> CommonTypes<'tcx> {
bool: mk(Bool),
char: mk(Char),
never: mk(Never),
err: mk(Error),
isize: mk(Int(ast::IntTy::Isize)),
i8: mk(Int(ast::IntTy::I8)),
i16: mk(Int(ast::IntTy::I16)),
Expand Down Expand Up @@ -1180,6 +1178,32 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
#[track_caller]
pub fn err(self) -> Ty<'tcx> {
self.sess.delay_span_bug(
DUMMY_SP,
&format!(
"TyKind::Error constructed but no error reported. {}",
std::panic::Location::caller()
),
);
self.mk_ty(Error)
}

/// Like `err` but for constants.
#[track_caller]
pub fn err_const(self, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
self.sess.delay_span_bug(
DUMMY_SP,
&format!(
"ty::ConstKind::Error constructed but no error reported. {}",
std::panic::Location::caller()
),
);
self.mk_const(ty::Const { val: ty::ConstKind::Error, ty })
}

pub fn consider_optimizing<T: Fn() -> String>(&self, msg: T) -> bool {
let cname = self.crate_name(LOCAL_CRATE).as_str();
self.sess.consider_optimizing(&cname, msg)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/query/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<'tcx, T> Value<'tcx> for T {

impl<'tcx> Value<'tcx> for Ty<'tcx> {
fn from_cycle_error(tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
tcx.types.err
tcx.err()
}
}

Expand All @@ -27,6 +27,6 @@ impl<'tcx> Value<'tcx> for ty::SymbolName {

impl<'tcx> Value<'tcx> for AdtSizedConstraint<'tcx> {
fn from_cycle_error(tcx: TyCtxt<'tcx>) -> Self {
AdtSizedConstraint(tcx.intern_type_list(&[tcx.types.err]))
AdtSizedConstraint(tcx.intern_type_list(&[tcx.err()]))
}
}
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
bug!("bound types encountered in super_relate_tys")
}

(&ty::Error, _) | (_, &ty::Error) => Ok(tcx.types.err),
(&ty::Error, _) | (_, &ty::Error) => Ok(tcx.err()),

(&ty::Never, _)
| (&ty::Char, _)
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_middle/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2378,9 +2378,7 @@ impl<'tcx> Const<'tcx> {
// can leak through `val` into the const we return.
Ok(val) => Const::from_value(tcx, val, self.ty),
Err(ErrorHandled::TooGeneric | ErrorHandled::Linted) => self,
Err(ErrorHandled::Reported(ErrorReported)) => {
tcx.mk_const(ty::Const { val: ty::ConstKind::Error, ty: self.ty })
}
Err(ErrorHandled::Reported(ErrorReported)) => tcx.err_const(self.ty),
}
} else {
self
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
if place_ty.variant_index.is_none() {
if place_ty.ty.references_error() {
assert!(self.errors_reported);
return PlaceTy::from_ty(self.tcx().types.err);
return PlaceTy::from_ty(self.tcx().err());
}
}
place_ty = self.sanitize_projection(place_ty, elem, place, location)
Expand Down Expand Up @@ -721,7 +721,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {

fn error(&mut self) -> Ty<'tcx> {
self.errors_reported = true;
self.tcx().types.err
self.tcx().err()
}

fn field_ty(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ fn construct_error<'a, 'tcx>(hir: Cx<'a, 'tcx>, body_id: hir::BodyId) -> Body<'t
let tcx = hir.tcx();
let owner_id = tcx.hir().body_owner(body_id);
let span = tcx.hir().span(owner_id);
let ty = tcx.types.err;
let ty = tcx.err();
let num_params = match hir.body_owner_kind {
hir::BodyOwnerKind::Fn => tcx.hir().fn_decl_by_hir_id(owner_id).unwrap().inputs.len(),
hir::BodyOwnerKind::Closure => {
Expand Down
Loading