Skip to content

Commit 26dfd86

Browse files
authored
Revert "WF-check all ty::Const's, not just array lengths."
1 parent e412475 commit 26dfd86

33 files changed

Lines changed: 174 additions & 386 deletions

File tree

src/librustc_infer/infer/combine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
307307
self.obligations.push(Obligation::new(
308308
self.trace.cause.clone(),
309309
self.param_env,
310-
ty::PredicateKind::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
310+
ty::PredicateKind::WellFormed(b_ty).to_predicate(self.infcx.tcx),
311311
));
312312
}
313313

src/librustc_middle/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::mir::Body;
1414
use crate::mir::GeneratorLayout;
1515
use crate::traits::{self, Reveal};
1616
use crate::ty;
17-
use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
17+
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef};
1818
use crate::ty::util::{Discr, IntTypeExt};
1919
use rustc_ast::ast;
2020
use rustc_attr as attr;
@@ -1061,7 +1061,7 @@ pub enum PredicateKind<'tcx> {
10611061
Projection(PolyProjectionPredicate<'tcx>),
10621062

10631063
/// No syntax: `T` well-formed.
1064-
WellFormed(GenericArg<'tcx>),
1064+
WellFormed(Ty<'tcx>),
10651065

10661066
/// Trait must be object-safe.
10671067
ObjectSafe(DefId),

src/librustc_middle/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ define_print_and_forward_display! {
20312031
ty::PredicateKind::RegionOutlives(predicate) => p!(print(predicate)),
20322032
ty::PredicateKind::TypeOutlives(predicate) => p!(print(predicate)),
20332033
ty::PredicateKind::Projection(predicate) => p!(print(predicate)),
2034-
ty::PredicateKind::WellFormed(arg) => p!(print(arg), write(" well-formed")),
2034+
ty::PredicateKind::WellFormed(ty) => p!(print(ty), write(" well-formed")),
20352035
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
20362036
p!(write("the trait `"),
20372037
print_def_path(trait_def_id, &[]),

src/librustc_middle/ty/structural_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl fmt::Debug for ty::PredicateKind<'tcx> {
236236
ty::PredicateKind::RegionOutlives(ref pair) => pair.fmt(f),
237237
ty::PredicateKind::TypeOutlives(ref pair) => pair.fmt(f),
238238
ty::PredicateKind::Projection(ref pair) => pair.fmt(f),
239-
ty::PredicateKind::WellFormed(data) => write!(f, "WellFormed({:?})", data),
239+
ty::PredicateKind::WellFormed(ty) => write!(f, "WellFormed({:?})", ty),
240240
ty::PredicateKind::ObjectSafe(trait_def_id) => {
241241
write!(f, "ObjectSafe({:?})", trait_def_id)
242242
}

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10161016
}
10171017

10181018
self.prove_predicate(
1019-
ty::PredicateKind::WellFormed(inferred_ty.into()).to_predicate(self.tcx()),
1019+
ty::PredicateKind::WellFormed(inferred_ty).to_predicate(self.tcx()),
10201020
Locations::All(span),
10211021
ConstraintCategory::TypeAnnotation,
10221022
);
@@ -1268,7 +1268,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12681268
obligations.obligations.push(traits::Obligation::new(
12691269
ObligationCause::dummy(),
12701270
param_env,
1271-
ty::PredicateKind::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx),
1271+
ty::PredicateKind::WellFormed(revealed_ty).to_predicate(infcx.tcx),
12721272
));
12731273
obligations.add(
12741274
infcx
@@ -1612,7 +1612,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16121612
self.check_call_dest(body, term, &sig, destination, term_location);
16131613

16141614
self.prove_predicates(
1615-
sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty.into())),
1615+
sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty)),
16161616
term_location.to_locations(),
16171617
ConstraintCategory::Boring,
16181618
);

src/librustc_trait_selection/traits/error_reporting/mod.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_hir::Node;
1919
use rustc_middle::mir::interpret::ErrorHandled;
2020
use rustc_middle::ty::error::ExpectedFound;
2121
use rustc_middle::ty::fold::TypeFolder;
22-
use rustc_middle::ty::subst::GenericArgKind;
2322
use rustc_middle::ty::{
2423
self, fast_reject, AdtKind, SubtypePredicate, ToPolyTraitRef, ToPredicate, Ty, TyCtxt,
2524
TypeFoldable, WithConstness,
@@ -1532,24 +1531,13 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
15321531
err
15331532
}
15341533

1535-
ty::PredicateKind::WellFormed(arg) => {
1534+
ty::PredicateKind::WellFormed(ty) => {
15361535
// Same hacky approach as above to avoid deluging user
15371536
// with error messages.
1538-
if arg.references_error() || self.tcx.sess.has_errors() {
1537+
if ty.references_error() || self.tcx.sess.has_errors() {
15391538
return;
15401539
}
1541-
1542-
match arg.unpack() {
1543-
GenericArgKind::Lifetime(lt) => {
1544-
span_bug!(span, "unexpected well formed predicate: {:?}", lt)
1545-
}
1546-
GenericArgKind::Type(ty) => {
1547-
self.need_type_info_err(body_id, span, ty, ErrorCode::E0282)
1548-
}
1549-
GenericArgKind::Const(ct) => {
1550-
self.need_type_info_err_const(body_id, span, ct, ErrorCode::E0282)
1551-
}
1552-
}
1540+
self.need_type_info_err(body_id, span, ty, ErrorCode::E0282)
15531541
}
15541542

15551543
ty::PredicateKind::Subtype(ref data) => {

src/librustc_trait_selection/traits/fulfill.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,17 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
459459
}
460460
}
461461

462-
&ty::PredicateKind::WellFormed(arg) => {
462+
&ty::PredicateKind::WellFormed(ty) => {
463463
match wf::obligations(
464464
self.selcx.infcx(),
465465
obligation.param_env,
466466
obligation.cause.body_id,
467-
arg,
467+
ty,
468468
obligation.cause.span,
469469
) {
470470
None => {
471471
pending_obligation.stalled_on =
472-
vec![TyOrConstInferVar::maybe_from_generic_arg(arg).unwrap()];
472+
vec![TyOrConstInferVar::maybe_from_ty(ty).unwrap()];
473473
ProcessResult::Unchanged
474474
}
475475
Some(os) => ProcessResult::Changed(mk_pending(os)),

src/librustc_trait_selection/traits/select/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
422422
}
423423
}
424424

425-
&ty::PredicateKind::WellFormed(arg) => match wf::obligations(
425+
&ty::PredicateKind::WellFormed(ty) => match wf::obligations(
426426
self.infcx,
427427
obligation.param_env,
428428
obligation.cause.body_id,
429-
arg,
429+
ty,
430430
obligation.cause.span,
431431
) {
432432
Some(mut obligations) => {

0 commit comments

Comments
 (0)