Skip to content

Commit ef4d2c1

Browse files
committed
change WellFormed predicate to GenericArg
1 parent 81831e1 commit ef4d2c1

File tree

28 files changed

+157
-255
lines changed

28 files changed

+157
-255
lines changed

src/librustc_infer/infer/combine.rs

+1-1
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).to_predicate(self.infcx.tcx),
310+
ty::PredicateKind::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
311311
));
312312
}
313313

src/librustc_infer/infer/outlives/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ pub fn explicit_outlives_bounds<'tcx>(
2020
| ty::PredicateKind::ClosureKind(..)
2121
| ty::PredicateKind::TypeOutlives(..)
2222
| ty::PredicateKind::ConstEvaluatable(..)
23-
| ty::PredicateKind::ConstEquate(..)
24-
| ty::PredicateKind::WellFormedConst(..) => None,
23+
| ty::PredicateKind::ConstEquate(..) => None,
2524
ty::PredicateKind::RegionOutlives(ref data) => data
2625
.no_bound_vars()
2726
.map(|ty::OutlivesPredicate(r_a, r_b)| OutlivesBound::RegionSubRegion(r_b, r_a)),

src/librustc_infer/traits/util.rs

-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ pub fn anonymize_predicate<'tcx>(
4545
}
4646

4747
ty::PredicateKind::ConstEquate(c1, c2) => ty::PredicateKind::ConstEquate(c1, c2),
48-
49-
ty::PredicateKind::WellFormedConst(ct) => ty::PredicateKind::WellFormedConst(ct),
5048
};
5149

5250
if new != *kind { new.to_predicate(tcx) } else { pred }
@@ -206,9 +204,6 @@ impl Elaborator<'tcx> {
206204
// Currently, we do not elaborate const-equate
207205
// predicates.
208206
}
209-
ty::PredicateKind::WellFormedConst(..) => {
210-
// Currently, we do not elaborate WF predicates.
211-
}
212207
ty::PredicateKind::RegionOutlives(..) => {
213208
// Nothing to elaborate from `'a: 'b`.
214209
}

src/librustc_lint/builtin.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
12181218
Projection(..) |
12191219
// Ignore bounds that a user can't type
12201220
WellFormed(..) |
1221-
WellFormedConst(..) |
12221221
ObjectSafe(..) |
12231222
ClosureKind(..) |
12241223
Subtype(..) |

src/librustc_middle/ty/mod.rs

+4-12
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::{InternalSubsts, Subst, SubstsRef};
17+
use crate::ty::subst::{GenericArg, 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(Ty<'tcx>),
1064+
WellFormed(GenericArg<'tcx>),
10651065

10661066
/// Trait must be object-safe.
10671067
ObjectSafe(DefId),
@@ -1079,9 +1079,6 @@ pub enum PredicateKind<'tcx> {
10791079

10801080
/// Constants must be equal. The first component is the const that is expected.
10811081
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
1082-
1083-
/// Constant must be well formed.
1084-
WellFormedConst(&'tcx Const<'tcx>),
10851082
}
10861083

10871084
/// The crate outlives map is computed during typeck and contains the
@@ -1198,9 +1195,6 @@ impl<'tcx> Predicate<'tcx> {
11981195
PredicateKind::ConstEquate(c1, c2) => {
11991196
PredicateKind::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs))
12001197
}
1201-
PredicateKind::WellFormedConst(c) => {
1202-
PredicateKind::WellFormedConst(c.subst(tcx, substs))
1203-
}
12041198
};
12051199

12061200
if new != *kind { new.to_predicate(tcx) } else { self }
@@ -1392,8 +1386,7 @@ impl<'tcx> Predicate<'tcx> {
13921386
| PredicateKind::ClosureKind(..)
13931387
| PredicateKind::TypeOutlives(..)
13941388
| PredicateKind::ConstEvaluatable(..)
1395-
| PredicateKind::ConstEquate(..)
1396-
| PredicateKind::WellFormedConst(..) => None,
1389+
| PredicateKind::ConstEquate(..) => None,
13971390
}
13981391
}
13991392

@@ -1408,8 +1401,7 @@ impl<'tcx> Predicate<'tcx> {
14081401
| PredicateKind::ObjectSafe(..)
14091402
| PredicateKind::ClosureKind(..)
14101403
| PredicateKind::ConstEvaluatable(..)
1411-
| PredicateKind::ConstEquate(..)
1412-
| PredicateKind::WellFormedConst(..) => None,
1404+
| PredicateKind::ConstEquate(..) => None,
14131405
}
14141406
}
14151407
}

src/librustc_middle/ty/print/pretty.rs

+1-4
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(ty) => p!(print(ty), write(" well-formed")),
2034+
ty::PredicateKind::WellFormed(arg) => p!(print(arg), write(" well-formed")),
20352035
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
20362036
p!(write("the trait `"),
20372037
print_def_path(trait_def_id, &[]),
@@ -2054,9 +2054,6 @@ define_print_and_forward_display! {
20542054
print(c2),
20552055
write("`"))
20562056
}
2057-
ty::PredicateKind::WellFormedConst(c) => {
2058-
p!(print(c), write(" well-formed"))
2059-
}
20602057
}
20612058
}
20622059

src/librustc_middle/ty/structural_impls.rs

+1-5
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(ty) => write!(f, "WellFormed({:?})", ty),
239+
ty::PredicateKind::WellFormed(data) => write!(f, "WellFormed({:?})", data),
240240
ty::PredicateKind::ObjectSafe(trait_def_id) => {
241241
write!(f, "ObjectSafe({:?})", trait_def_id)
242242
}
@@ -247,7 +247,6 @@ impl fmt::Debug for ty::PredicateKind<'tcx> {
247247
write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
248248
}
249249
ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
250-
ty::PredicateKind::WellFormedConst(c) => write!(f, "WellFormedConst({:?})", c),
251250
}
252251
}
253252
}
@@ -508,9 +507,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
508507
ty::PredicateKind::ConstEquate(c1, c2) => {
509508
tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2))
510509
}
511-
ty::PredicateKind::WellFormedConst(c) => {
512-
tcx.lift(&c).map(ty::PredicateKind::WellFormedConst)
513-
}
514510
}
515511
}
516512
}

src/librustc_mir/borrow_check/type_check/mod.rs

+3-3
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).to_predicate(self.tcx()),
1019+
ty::PredicateKind::WellFormed(inferred_ty.into()).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).to_predicate(infcx.tcx),
1271+
ty::PredicateKind::WellFormed(revealed_ty.into()).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)),
1615+
sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty.into())),
16161616
term_location.to_locations(),
16171617
ConstraintCategory::Boring,
16181618
);

src/librustc_mir/transform/qualify_min_const_fn.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
2929
| ty::PredicateKind::WellFormed(_)
3030
| ty::PredicateKind::Projection(_)
3131
| ty::PredicateKind::ConstEvaluatable(..)
32-
| ty::PredicateKind::ConstEquate(..)
33-
| ty::PredicateKind::WellFormedConst(..) => continue,
32+
| ty::PredicateKind::ConstEquate(..) => continue,
3433
ty::PredicateKind::ObjectSafe(_) => {
3534
bug!("object safe predicate on function: {:#?}", predicate)
3635
}

src/librustc_trait_selection/opaque_types.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,7 @@ crate fn required_region_bounds(
12771277
| ty::PredicateKind::ClosureKind(..)
12781278
| ty::PredicateKind::RegionOutlives(..)
12791279
| ty::PredicateKind::ConstEvaluatable(..)
1280-
| ty::PredicateKind::ConstEquate(..)
1281-
| ty::PredicateKind::WellFormedConst(..) => None,
1280+
| ty::PredicateKind::ConstEquate(..) => None,
12821281
ty::PredicateKind::TypeOutlives(predicate) => {
12831282
// Search for a bound of the form `erased_self_ty
12841283
// : 'a`, but be wary of something like `for<'a>

src/librustc_trait_selection/traits/error_reporting/mod.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ 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;
2223
use rustc_middle::ty::{
2324
self, fast_reject, AdtKind, SubtypePredicate, ToPolyTraitRef, ToPredicate, Ty, TyCtxt,
2425
TypeFoldable, WithConstness,
@@ -610,15 +611,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
610611
}
611612
}
612613

613-
ty::PredicateKind::WellFormedConst(ct) => {
614-
// Const WF predicates cannot themselves make
615-
// errors. They can only block due to
616-
// ambiguity; otherwise, they always
617-
// degenerate into other obligations
618-
// (which may fail).
619-
span_bug!(span, "const WF predicate not satisfied for {:?}", ct);
620-
}
621-
622614
ty::PredicateKind::ConstEvaluatable(..) => {
623615
// Errors for `ConstEvaluatable` predicates show up as
624616
// `SelectionError::ConstEvalFailure`,
@@ -1540,22 +1532,24 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
15401532
err
15411533
}
15421534

1543-
ty::PredicateKind::WellFormed(ty) => {
1535+
ty::PredicateKind::WellFormed(arg) => {
15441536
// Same hacky approach as above to avoid deluging user
15451537
// with error messages.
1546-
if ty.references_error() || self.tcx.sess.has_errors() {
1538+
if arg.references_error() || self.tcx.sess.has_errors() {
15471539
return;
15481540
}
1549-
self.need_type_info_err(body_id, span, ty, ErrorCode::E0282)
1550-
}
15511541

1552-
ty::PredicateKind::WellFormedConst(ct) => {
1553-
// Same hacky approach as above to avoid deluging user
1554-
// with error messages.
1555-
if ct.references_error() || self.tcx.sess.has_errors() {
1556-
return;
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+
}
15571552
}
1558-
self.need_type_info_err_const(body_id, span, ct, ErrorCode::E0282)
15591553
}
15601554

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

src/librustc_trait_selection/traits/fulfill.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -459,38 +459,23 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
459459
}
460460
}
461461

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

479-
ty::PredicateKind::WellFormedConst(constant) => match wf::const_obligations(
480-
self.selcx.infcx(),
481-
obligation.param_env,
482-
obligation.cause.body_id,
483-
constant,
484-
obligation.cause.span,
485-
) {
486-
Some(predicates) => ProcessResult::Changed(mk_pending(predicates)),
487-
None => {
488-
pending_obligation.stalled_on =
489-
vec![TyOrConstInferVar::maybe_from_const(constant).unwrap()];
490-
ProcessResult::Unchanged
491-
}
492-
},
493-
494479
&ty::PredicateKind::Subtype(subtype) => {
495480
match self.selcx.infcx().subtype_predicate(
496481
&obligation.cause,

src/librustc_trait_selection/traits/object_safety.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ fn predicates_reference_self(
283283
| ty::PredicateKind::ClosureKind(..)
284284
| ty::PredicateKind::Subtype(..)
285285
| ty::PredicateKind::ConstEvaluatable(..)
286-
| ty::PredicateKind::ConstEquate(..)
287-
| ty::PredicateKind::WellFormedConst(..) => None,
286+
| ty::PredicateKind::ConstEquate(..) => None,
288287
}
289288
})
290289
.collect()
@@ -319,8 +318,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
319318
| ty::PredicateKind::ClosureKind(..)
320319
| ty::PredicateKind::TypeOutlives(..)
321320
| ty::PredicateKind::ConstEvaluatable(..)
322-
| ty::PredicateKind::ConstEquate(..)
323-
| ty::PredicateKind::WellFormedConst(..) => false,
321+
| ty::PredicateKind::ConstEquate(..) => false,
324322
}
325323
})
326324
}

src/librustc_trait_selection/traits/select.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -436,25 +436,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
436436
}
437437
}
438438

439-
&ty::PredicateKind::WellFormed(ty) => match wf::obligations(
439+
&ty::PredicateKind::WellFormed(arg) => match wf::obligations(
440440
self.infcx,
441441
obligation.param_env,
442442
obligation.cause.body_id,
443-
ty,
444-
obligation.cause.span,
445-
) {
446-
Some(mut obligations) => {
447-
self.add_depth(obligations.iter_mut(), obligation.recursion_depth);
448-
self.evaluate_predicates_recursively(previous_stack, obligations.into_iter())
449-
}
450-
None => Ok(EvaluatedToAmbig),
451-
},
452-
453-
ty::PredicateKind::WellFormedConst(constant) => match wf::const_obligations(
454-
self.infcx,
455-
obligation.param_env,
456-
obligation.cause.body_id,
457-
constant,
443+
arg,
458444
obligation.cause.span,
459445
) {
460446
Some(mut obligations) => {

0 commit comments

Comments
 (0)