From a3f30bbc2d28572f9fa429cf3b31d7f95d3b0dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 12 May 2020 10:56:26 -0700 Subject: [PATCH 01/13] Don't `type_of` on trait assoc ty without default Fix #72076. --- src/librustc_middle/ty/error.rs | 13 +++---- src/test/ui/issues/issue-72076.rs | 6 +++ src/test/ui/issues/issue-72076.stderr | 14 +++++++ ...ith-missing-associated-type-restriction.rs | 1 + ...missing-associated-type-restriction.stderr | 37 ++++++++++++++----- 5 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 src/test/ui/issues/issue-72076.rs create mode 100644 src/test/ui/issues/issue-72076.stderr diff --git a/src/librustc_middle/ty/error.rs b/src/librustc_middle/ty/error.rs index f3b6a53dfeb82..00be12f46fe21 100644 --- a/src/librustc_middle/ty/error.rs +++ b/src/librustc_middle/ty/error.rs @@ -817,19 +817,18 @@ fn foo(&self) -> Self::T { String::new() } for item in &items[..] { match item.kind { hir::AssocItemKind::Type | hir::AssocItemKind::OpaqueTy => { - if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found { - if let hir::Defaultness::Default { has_value: true } = - item.defaultness - { + // FIXME: account for returning some type in a trait fn impl that has + // an assoc type as a return type (#72076). + if let hir::Defaultness::Default { has_value: true } = item.defaultness + { + if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found { db.span_label( item.span, "associated type defaults can't be assumed inside the \ trait defining them", ); - } else { - db.span_label(item.span, "expected this associated type"); + return true; } - return true; } } _ => {} diff --git a/src/test/ui/issues/issue-72076.rs b/src/test/ui/issues/issue-72076.rs new file mode 100644 index 0000000000000..1659044a64fe1 --- /dev/null +++ b/src/test/ui/issues/issue-72076.rs @@ -0,0 +1,6 @@ +trait X { + type S; + fn f() -> Self::S {} //~ ERROR mismatched types +} + +fn main() {} diff --git a/src/test/ui/issues/issue-72076.stderr b/src/test/ui/issues/issue-72076.stderr new file mode 100644 index 0000000000000..b942cf75b06a7 --- /dev/null +++ b/src/test/ui/issues/issue-72076.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/issue-72076.rs:3:23 + | +LL | fn f() -> Self::S {} + | ^^ expected associated type, found `()` + | + = note: expected associated type `::S` + found unit type `()` + = help: consider constraining the associated type `::S` to `()` or calling a method that returns `::S` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/trait-with-missing-associated-type-restriction.rs b/src/test/ui/suggestions/trait-with-missing-associated-type-restriction.rs index 7465049787f59..0d90e449523a3 100644 --- a/src/test/ui/suggestions/trait-with-missing-associated-type-restriction.rs +++ b/src/test/ui/suggestions/trait-with-missing-associated-type-restriction.rs @@ -7,6 +7,7 @@ trait Trait { fn func(&self) -> Self::A; fn funk(&self, _: Self::A); + fn funq(&self) -> Self::A {} //~ ERROR mismatched types } fn foo(_: impl Trait, x: impl Trait) { diff --git a/src/test/ui/suggestions/trait-with-missing-associated-type-restriction.stderr b/src/test/ui/suggestions/trait-with-missing-associated-type-restriction.stderr index 5ae1d45c6b703..e629f8f970d32 100644 --- a/src/test/ui/suggestions/trait-with-missing-associated-type-restriction.stderr +++ b/src/test/ui/suggestions/trait-with-missing-associated-type-restriction.stderr @@ -1,5 +1,19 @@ error[E0308]: mismatched types - --> $DIR/trait-with-missing-associated-type-restriction.rs:13:9 + --> $DIR/trait-with-missing-associated-type-restriction.rs:10:31 + | +LL | fn funq(&self) -> Self::A {} + | ^^ expected associated type, found `()` + | + = note: expected associated type `>::A` + found unit type `()` +help: a method is available that returns `>::A` + --> $DIR/trait-with-missing-associated-type-restriction.rs:8:5 + | +LL | fn func(&self) -> Self::A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ consider calling `Trait::func` + +error[E0308]: mismatched types + --> $DIR/trait-with-missing-associated-type-restriction.rs:14:9 | LL | qux(x.func()) | ^^^^^^^^ expected `usize`, found associated type @@ -12,7 +26,7 @@ LL | fn foo(_: impl Trait, x: impl Trait) { | ^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/trait-with-missing-associated-type-restriction.rs:17:9 + --> $DIR/trait-with-missing-associated-type-restriction.rs:18:9 | LL | qux(x.func()) | ^^^^^^^^ expected `usize`, found associated type @@ -25,7 +39,7 @@ LL | fn bar>(x: T) { | ^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/trait-with-missing-associated-type-restriction.rs:21:9 + --> $DIR/trait-with-missing-associated-type-restriction.rs:22:9 | LL | qux(x.func()) | ^^^^^^^^ expected `usize`, found associated type @@ -38,25 +52,28 @@ LL | fn foo2(x: impl Trait) { | ^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/trait-with-missing-associated-type-restriction.rs:25:12 + --> $DIR/trait-with-missing-associated-type-restriction.rs:26:12 | LL | x.funk(3); | ^ expected associated type, found integer | = note: expected associated type `>::A` found type `{integer}` -help: a method is available that returns `>::A` +help: some methods are available that return `>::A` --> $DIR/trait-with-missing-associated-type-restriction.rs:8:5 | LL | fn func(&self) -> Self::A; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ consider calling `Trait::func` +LL | fn funk(&self, _: Self::A); +LL | fn funq(&self) -> Self::A {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ consider calling `Trait::funq` help: consider constraining the associated type `>::A` to `{integer}` | LL | fn bar2>(x: T) { | ^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/trait-with-missing-associated-type-restriction.rs:26:9 + --> $DIR/trait-with-missing-associated-type-restriction.rs:27:9 | LL | qux(x.func()) | ^^^^^^^^ expected `usize`, found associated type @@ -69,7 +86,7 @@ LL | fn bar2>(x: T) { | ^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/trait-with-missing-associated-type-restriction.rs:30:9 + --> $DIR/trait-with-missing-associated-type-restriction.rs:31:9 | LL | fn baz>(x: T) { | - this type parameter @@ -80,13 +97,13 @@ LL | qux(x.func()) found type parameter `D` error[E0308]: mismatched types - --> $DIR/trait-with-missing-associated-type-restriction.rs:34:9 + --> $DIR/trait-with-missing-associated-type-restriction.rs:35:9 | LL | qux(x.func()) | ^^^^^^^^ expected `usize`, found `()` error[E0308]: mismatched types - --> $DIR/trait-with-missing-associated-type-restriction.rs:38:9 + --> $DIR/trait-with-missing-associated-type-restriction.rs:39:9 | LL | qux(x.func()) | ^^^^^^^^ expected `usize`, found associated type @@ -98,6 +115,6 @@ help: consider constraining the associated type `::A` to `usize` LL | fn ban(x: T) where T: Trait { | ^^^^^^^^^^^ -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0308`. From fc4c9a6c7f27dc4cc68d8b2afe77e88a29ff8a31 Mon Sep 17 00:00:00 2001 From: Tymoteusz Jankowski Date: Tue, 19 May 2020 13:54:22 +0200 Subject: [PATCH 02/13] Make intra-link resolve links for both trait and impl items --- .../passes/collect_intra_doc_links.rs | 61 +++++++++++-------- src/test/rustdoc/issue-72340.rs | 19 ++++++ 2 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 src/test/rustdoc/issue-72340.rs diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index a3ef350a0487e..05f3b598ecdf4 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -232,37 +232,46 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias, did, ) => { - // We need item's parent to know if it's - // trait impl or struct/enum/etc impl - let item_parent = item_opt + // Checks if item_name belongs to `impl SomeItem` + let impl_item = cx + .tcx + .inherent_impls(did) + .iter() + .flat_map(|imp| cx.tcx.associated_items(*imp).in_definition_order()) + .find(|item| item.ident.name == item_name); + let trait_item = item_opt .and_then(|item| self.cx.as_local_hir_id(item.def_id)) .and_then(|item_hir| { + // Checks if item_name belongs to `impl SomeTrait for SomeItem` let parent_hir = self.cx.tcx.hir().get_parent_item(item_hir); - self.cx.tcx.hir().find(parent_hir) + let item_parent = self.cx.tcx.hir().find(parent_hir); + match item_parent { + Some(hir::Node::Item(hir::Item { + kind: hir::ItemKind::Impl { of_trait: Some(_), self_ty, .. }, + .. + })) => cx + .tcx + .associated_item_def_ids(self_ty.hir_id.owner) + .iter() + .map(|child| { + let associated_item = cx.tcx.associated_item(*child); + associated_item + }) + .find(|child| child.ident.name == item_name), + _ => None, + } }); - let item = match item_parent { - Some(hir::Node::Item(hir::Item { - kind: hir::ItemKind::Impl { of_trait: Some(_), self_ty, .. }, - .. - })) => { - // trait impl - cx.tcx - .associated_item_def_ids(self_ty.hir_id.owner) - .iter() - .map(|child| { - let associated_item = cx.tcx.associated_item(*child); - associated_item - }) - .find(|child| child.ident.name == item_name) - } - _ => { - // struct/enum/etc. impl - cx.tcx - .inherent_impls(did) - .iter() - .flat_map(|imp| cx.tcx.associated_items(*imp).in_definition_order()) - .find(|item| item.ident.name == item_name) + let item = match (impl_item, trait_item) { + (Some(from_impl), Some(_)) => { + // Although it's ambiguous, return impl version for compat. sake. + // To handle that properly resolve() would have to support + // something like + // [`ambi_fn`](::ambi_fn) + Some(from_impl) } + (None, Some(from_trait)) => Some(from_trait), + (Some(from_impl), None) => Some(from_impl), + _ => None, }; if let Some(item) = item { diff --git a/src/test/rustdoc/issue-72340.rs b/src/test/rustdoc/issue-72340.rs new file mode 100644 index 0000000000000..6ed3bfbe3e54b --- /dev/null +++ b/src/test/rustdoc/issue-72340.rs @@ -0,0 +1,19 @@ +#![crate_name = "foo"] + +pub struct Body; + +impl Body { + pub fn empty() -> Self { + Body + } + +} + +impl Default for Body { + // @has foo/struct.Body.html '//a/@href' '../foo/struct.Body.html#method.empty' + + /// Returns [`Body::empty()`](Body::empty). + fn default() -> Body { + Body::empty() + } +} From cad8fe90fd61c410ac3e7e97a6be37c96ca66a72 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 11 May 2020 21:09:57 +0200 Subject: [PATCH 03/13] rename `Predicate` to `PredicateKind`, introduce alias --- .../infer/canonical/query_response.rs | 10 +- src/librustc_infer/infer/combine.rs | 2 +- src/librustc_infer/infer/outlives/mod.rs | 20 ++-- src/librustc_infer/infer/sub.rs | 2 +- src/librustc_infer/traits/util.rs | 60 ++++++------ src/librustc_lint/builtin.rs | 6 +- src/librustc_lint/unused.rs | 2 +- src/librustc_middle/ty/codec.rs | 4 +- src/librustc_middle/ty/mod.rs | 98 ++++++++++--------- src/librustc_middle/ty/print/pretty.rs | 18 ++-- src/librustc_middle/ty/structural_impls.rs | 56 ++++++----- src/librustc_middle/ty/sty.rs | 2 +- .../borrow_check/diagnostics/region_errors.rs | 2 +- .../borrow_check/type_check/mod.rs | 10 +- .../transform/qualify_min_const_fn.rs | 24 ++--- src/librustc_privacy/lib.rs | 8 +- src/librustc_trait_selection/opaque_types.rs | 22 ++--- .../traits/auto_trait.rs | 16 +-- .../traits/error_reporting/mod.rs | 36 +++---- .../traits/error_reporting/suggestions.rs | 2 +- .../traits/fulfill.rs | 18 ++-- src/librustc_trait_selection/traits/mod.rs | 2 +- .../traits/object_safety.rs | 40 ++++---- .../traits/project.rs | 8 +- .../traits/query/type_op/prove_predicate.rs | 4 +- src/librustc_trait_selection/traits/select.rs | 22 ++--- src/librustc_trait_selection/traits/wf.rs | 38 +++---- .../implied_outlives_bounds.rs | 20 ++-- .../normalize_erasing_regions.rs | 18 ++-- src/librustc_traits/type_op.rs | 7 +- src/librustc_typeck/astconv.rs | 4 +- src/librustc_typeck/check/closure.rs | 6 +- src/librustc_typeck/check/coercion.rs | 4 +- src/librustc_typeck/check/demand.rs | 2 +- src/librustc_typeck/check/dropck.rs | 6 +- src/librustc_typeck/check/method/confirm.rs | 2 +- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 20 ++-- src/librustc_typeck/check/method/suggest.rs | 10 +- src/librustc_typeck/check/mod.rs | 38 +++---- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/collect.rs | 14 +-- .../constrained_generic_params.rs | 2 +- .../impl_wf_check/min_specialization.rs | 26 ++--- src/librustc_typeck/outlives/explicit.rs | 20 ++-- src/librustc_typeck/outlives/mod.rs | 8 +- src/librustdoc/clean/auto_trait.rs | 6 +- src/librustdoc/clean/mod.rs | 28 +++--- src/librustdoc/clean/simplify.rs | 2 +- .../clippy_lints/src/future_not_send.rs | 2 +- .../clippy/clippy_lints/src/methods/mod.rs | 4 +- .../src/needless_pass_by_value.rs | 2 +- .../clippy/clippy_lints/src/utils/mod.rs | 2 +- 53 files changed, 406 insertions(+), 383 deletions(-) diff --git a/src/librustc_infer/infer/canonical/query_response.rs b/src/librustc_infer/infer/canonical/query_response.rs index c7a7cf89b4f1b..67c8265cb1153 100644 --- a/src/librustc_infer/infer/canonical/query_response.rs +++ b/src/librustc_infer/infer/canonical/query_response.rs @@ -532,12 +532,12 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { cause.clone(), param_env, match k1.unpack() { - GenericArgKind::Lifetime(r1) => ty::Predicate::RegionOutlives( + GenericArgKind::Lifetime(r1) => ty::PredicateKind::RegionOutlives( ty::Binder::bind(ty::OutlivesPredicate(r1, r2)), ), - GenericArgKind::Type(t1) => { - ty::Predicate::TypeOutlives(ty::Binder::bind(ty::OutlivesPredicate(t1, r2))) - } + GenericArgKind::Type(t1) => ty::PredicateKind::TypeOutlives(ty::Binder::bind( + ty::OutlivesPredicate(t1, r2), + )), GenericArgKind::Const(..) => { // Consts cannot outlive one another, so we don't expect to // ecounter this branch. @@ -664,7 +664,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> { self.obligations.push(Obligation { cause: self.cause.clone(), param_env: self.param_env, - predicate: ty::Predicate::RegionOutlives(ty::Binder::dummy(ty::OutlivesPredicate( + predicate: ty::PredicateKind::RegionOutlives(ty::Binder::dummy(ty::OutlivesPredicate( sup, sub, ))), recursion_depth: 0, diff --git a/src/librustc_infer/infer/combine.rs b/src/librustc_infer/infer/combine.rs index 3467457b44997..2a188b2120556 100644 --- a/src/librustc_infer/infer/combine.rs +++ b/src/librustc_infer/infer/combine.rs @@ -307,7 +307,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { self.obligations.push(Obligation::new( self.trace.cause.clone(), self.param_env, - ty::Predicate::WellFormed(b_ty), + ty::PredicateKind::WellFormed(b_ty), )); } diff --git a/src/librustc_infer/infer/outlives/mod.rs b/src/librustc_infer/infer/outlives/mod.rs index 289457e2bd0c2..e423137da8f74 100644 --- a/src/librustc_infer/infer/outlives/mod.rs +++ b/src/librustc_infer/infer/outlives/mod.rs @@ -12,16 +12,16 @@ pub fn explicit_outlives_bounds<'tcx>( ) -> impl Iterator> + 'tcx { debug!("explicit_outlives_bounds()"); param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate { - ty::Predicate::Projection(..) - | ty::Predicate::Trait(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::TypeOutlives(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => None, - ty::Predicate::RegionOutlives(ref data) => data + ty::PredicateKind::Projection(..) + | ty::PredicateKind::Trait(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::TypeOutlives(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => None, + ty::PredicateKind::RegionOutlives(ref data) => data .no_bound_vars() .map(|ty::OutlivesPredicate(r_a, r_b)| OutlivesBound::RegionSubRegion(r_b, r_a)), }) diff --git a/src/librustc_infer/infer/sub.rs b/src/librustc_infer/infer/sub.rs index 1ec67ef2efa9d..22231488b7b5c 100644 --- a/src/librustc_infer/infer/sub.rs +++ b/src/librustc_infer/infer/sub.rs @@ -100,7 +100,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> { self.fields.obligations.push(Obligation::new( self.fields.trace.cause.clone(), self.fields.param_env, - ty::Predicate::Subtype(ty::Binder::dummy(ty::SubtypePredicate { + ty::PredicateKind::Subtype(ty::Binder::dummy(ty::SubtypePredicate { a_is_expected: self.a_is_expected, a, b, diff --git a/src/librustc_infer/traits/util.rs b/src/librustc_infer/traits/util.rs index ee903b676bae9..400fe4d1321ca 100644 --- a/src/librustc_infer/traits/util.rs +++ b/src/librustc_infer/traits/util.rs @@ -11,39 +11,39 @@ pub fn anonymize_predicate<'tcx>( pred: &ty::Predicate<'tcx>, ) -> ty::Predicate<'tcx> { match *pred { - ty::Predicate::Trait(ref data, constness) => { - ty::Predicate::Trait(tcx.anonymize_late_bound_regions(data), constness) + ty::PredicateKind::Trait(ref data, constness) => { + ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness) } - ty::Predicate::RegionOutlives(ref data) => { - ty::Predicate::RegionOutlives(tcx.anonymize_late_bound_regions(data)) + ty::PredicateKind::RegionOutlives(ref data) => { + ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data)) } - ty::Predicate::TypeOutlives(ref data) => { - ty::Predicate::TypeOutlives(tcx.anonymize_late_bound_regions(data)) + ty::PredicateKind::TypeOutlives(ref data) => { + ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data)) } - ty::Predicate::Projection(ref data) => { - ty::Predicate::Projection(tcx.anonymize_late_bound_regions(data)) + ty::PredicateKind::Projection(ref data) => { + ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)) } - ty::Predicate::WellFormed(data) => ty::Predicate::WellFormed(data), + ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data), - ty::Predicate::ObjectSafe(data) => ty::Predicate::ObjectSafe(data), + ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data), - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) } - ty::Predicate::Subtype(ref data) => { - ty::Predicate::Subtype(tcx.anonymize_late_bound_regions(data)) + ty::PredicateKind::Subtype(ref data) => { + ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)) } - ty::Predicate::ConstEvaluatable(def_id, substs) => { - ty::Predicate::ConstEvaluatable(def_id, substs) + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) } - ty::Predicate::ConstEquate(c1, c2) => ty::Predicate::ConstEquate(c1, c2), + ty::PredicateKind::ConstEquate(c1, c2) => ty::Predicate::ConstEquate(c1, c2), } } @@ -146,7 +146,7 @@ impl Elaborator<'tcx> { fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) { let tcx = self.visited.tcx; match obligation.predicate { - ty::Predicate::Trait(ref data, _) => { + ty::PredicateKind::Trait(ref data, _) => { // Get predicates declared on the trait. let predicates = tcx.super_predicates_of(data.def_id()); @@ -167,36 +167,36 @@ impl Elaborator<'tcx> { self.stack.extend(obligations); } - ty::Predicate::WellFormed(..) => { + ty::PredicateKind::WellFormed(..) => { // Currently, we do not elaborate WF predicates, // although we easily could. } - ty::Predicate::ObjectSafe(..) => { + ty::PredicateKind::ObjectSafe(..) => { // Currently, we do not elaborate object-safe // predicates. } - ty::Predicate::Subtype(..) => { + ty::PredicateKind::Subtype(..) => { // Currently, we do not "elaborate" predicates like `X <: Y`, // though conceivably we might. } - ty::Predicate::Projection(..) => { + ty::PredicateKind::Projection(..) => { // Nothing to elaborate in a projection predicate. } - ty::Predicate::ClosureKind(..) => { + ty::PredicateKind::ClosureKind(..) => { // Nothing to elaborate when waiting for a closure's kind to be inferred. } - ty::Predicate::ConstEvaluatable(..) => { + ty::PredicateKind::ConstEvaluatable(..) => { // Currently, we do not elaborate const-evaluatable // predicates. } - ty::Predicate::ConstEquate(..) => { + ty::PredicateKind::ConstEquate(..) => { // Currently, we do not elaborate const-equate // predicates. } - ty::Predicate::RegionOutlives(..) => { + ty::PredicateKind::RegionOutlives(..) => { // Nothing to elaborate from `'a: 'b`. } - ty::Predicate::TypeOutlives(ref data) => { + ty::PredicateKind::TypeOutlives(ref data) => { // We know that `T: 'a` for some type `T`. We can // often elaborate this. For example, if we know that // `[U]: 'a`, that implies that `U: 'a`. Similarly, if @@ -228,7 +228,7 @@ impl Elaborator<'tcx> { if r.is_late_bound() { None } else { - Some(ty::Predicate::RegionOutlives(ty::Binder::dummy( + Some(ty::PredicateKind::RegionOutlives(ty::Binder::dummy( ty::OutlivesPredicate(r, r_min), ))) } @@ -236,7 +236,7 @@ impl Elaborator<'tcx> { Component::Param(p) => { let ty = tcx.mk_ty_param(p.index, p.name); - Some(ty::Predicate::TypeOutlives(ty::Binder::dummy( + Some(ty::PredicateKind::TypeOutlives(ty::Binder::dummy( ty::OutlivesPredicate(ty, r_min), ))) } @@ -317,7 +317,7 @@ impl<'tcx, I: Iterator>> Iterator for FilterToT fn next(&mut self) -> Option> { while let Some(obligation) = self.base_iterator.next() { - if let ty::Predicate::Trait(data, _) = obligation.predicate { + if let ty::PredicateKind::Trait(data, _) = obligation.predicate { return Some(data.to_poly_trait_ref()); } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index bca91fb7b5d16..6e1258e25bbaf 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1202,7 +1202,7 @@ declare_lint_pass!( impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'tcx>) { use rustc_middle::ty::fold::TypeFoldable; - use rustc_middle::ty::Predicate::*; + use rustc_middle::ty::PredicateKind::*; if cx.tcx.features().trivial_bounds { let def_id = cx.tcx.hir().local_def_id(item.hir_id); @@ -1498,7 +1498,7 @@ impl ExplicitOutlivesRequirements { inferred_outlives .iter() .filter_map(|(pred, _)| match pred { - ty::Predicate::RegionOutlives(outlives) => { + ty::PredicateKind::RegionOutlives(outlives) => { let outlives = outlives.skip_binder(); match outlives.0 { ty::ReEarlyBound(ebr) if ebr.index == index => Some(outlives.1), @@ -1517,7 +1517,7 @@ impl ExplicitOutlivesRequirements { inferred_outlives .iter() .filter_map(|(pred, _)| match pred { - ty::Predicate::TypeOutlives(outlives) => { + ty::PredicateKind::TypeOutlives(outlives) => { let outlives = outlives.skip_binder(); outlives.0.is_param(index).then_some(outlives.1) } diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index c24079a6e4be2..19146f68fce80 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -146,7 +146,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { ty::Opaque(def, _) => { let mut has_emitted = false; for (predicate, _) in cx.tcx.predicates_of(def).predicates { - if let ty::Predicate::Trait(ref poly_trait_predicate, _) = predicate { + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate { let trait_ref = poly_trait_predicate.skip_binder().trait_ref; let def_id = trait_ref.def_id; let descr_pre = diff --git a/src/librustc_middle/ty/codec.rs b/src/librustc_middle/ty/codec.rs index cbbc937ed7d31..7ebeb6243be41 100644 --- a/src/librustc_middle/ty/codec.rs +++ b/src/librustc_middle/ty/codec.rs @@ -201,9 +201,9 @@ where assert!(pos >= SHORTHAND_OFFSET); let shorthand = pos - SHORTHAND_OFFSET; - decoder.with_position(shorthand, ty::Predicate::decode) + decoder.with_position(shorthand, ty::PredicateKind::decode) } else { - ty::Predicate::decode(decoder) + ty::PredicateKind::decode(decoder) }?; Ok((predicate, Decodable::decode(decoder)?)) }) diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 36bc44f5e5032..e3aeb242dc034 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1016,9 +1016,11 @@ impl<'tcx> GenericPredicates<'tcx> { } } +pub type Predicate<'tcx> = PredicateKind<'tcx>; + #[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] #[derive(HashStable, TypeFoldable)] -pub enum Predicate<'tcx> { +pub enum PredicateKind<'tcx> { /// Corresponds to `where Foo: Bar`. `Foo` here would be /// the `Self` type of the trait reference and `A`, `B`, and `C` /// would be the type parameters. @@ -1079,7 +1081,7 @@ impl<'tcx> AsRef> for Predicate<'tcx> { } } -impl<'tcx> Predicate<'tcx> { +impl<'tcx> PredicateKind<'tcx> { /// Performs a substitution suitable for going from a /// poly-trait-ref to supertraits that must hold if that /// poly-trait-ref holds. This is slightly different from a normal @@ -1152,31 +1154,31 @@ impl<'tcx> Predicate<'tcx> { let substs = &trait_ref.skip_binder().substs; match *self { - Predicate::Trait(ref binder, constness) => { - Predicate::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness) + PredicateKind::Trait(ref binder, constness) => { + PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness) } - Predicate::Subtype(ref binder) => { - Predicate::Subtype(binder.map_bound(|data| data.subst(tcx, substs))) + PredicateKind::Subtype(ref binder) => { + PredicateKind::Subtype(binder.map_bound(|data| data.subst(tcx, substs))) } - Predicate::RegionOutlives(ref binder) => { - Predicate::RegionOutlives(binder.map_bound(|data| data.subst(tcx, substs))) + PredicateKind::RegionOutlives(ref binder) => { + PredicateKind::RegionOutlives(binder.map_bound(|data| data.subst(tcx, substs))) } - Predicate::TypeOutlives(ref binder) => { - Predicate::TypeOutlives(binder.map_bound(|data| data.subst(tcx, substs))) + PredicateKind::TypeOutlives(ref binder) => { + PredicateKind::TypeOutlives(binder.map_bound(|data| data.subst(tcx, substs))) } - Predicate::Projection(ref binder) => { - Predicate::Projection(binder.map_bound(|data| data.subst(tcx, substs))) + PredicateKind::Projection(ref binder) => { + PredicateKind::Projection(binder.map_bound(|data| data.subst(tcx, substs))) } - Predicate::WellFormed(data) => Predicate::WellFormed(data.subst(tcx, substs)), - Predicate::ObjectSafe(trait_def_id) => Predicate::ObjectSafe(trait_def_id), - Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { - Predicate::ClosureKind(closure_def_id, closure_substs.subst(tcx, substs), kind) + PredicateKind::WellFormed(data) => PredicateKind::WellFormed(data.subst(tcx, substs)), + PredicateKind::ObjectSafe(trait_def_id) => PredicateKind::ObjectSafe(trait_def_id), + PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { + PredicateKind::ClosureKind(closure_def_id, closure_substs.subst(tcx, substs), kind) } - Predicate::ConstEvaluatable(def_id, const_substs) => { - Predicate::ConstEvaluatable(def_id, const_substs.subst(tcx, substs)) + PredicateKind::ConstEvaluatable(def_id, const_substs) => { + PredicateKind::ConstEvaluatable(def_id, const_substs.subst(tcx, substs)) } - Predicate::ConstEquate(c1, c2) => { - Predicate::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs)) + PredicateKind::ConstEquate(c1, c2) => { + PredicateKind::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs)) } } } @@ -1298,7 +1300,7 @@ pub trait ToPredicate<'tcx> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(&self) -> Predicate<'tcx> { - ty::Predicate::Trait( + ty::PredicateKind::Trait( ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value }), self.constness, ) @@ -1307,7 +1309,7 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> { fn to_predicate(&self) -> Predicate<'tcx> { - ty::Predicate::Trait( + ty::PredicateKind::Trait( ty::Binder::dummy(ty::TraitPredicate { trait_ref: *self.value }), self.constness, ) @@ -1316,62 +1318,62 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> { impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { fn to_predicate(&self) -> Predicate<'tcx> { - ty::Predicate::Trait(self.value.to_poly_trait_predicate(), self.constness) + ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness) } } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&PolyTraitRef<'tcx>> { fn to_predicate(&self) -> Predicate<'tcx> { - ty::Predicate::Trait(self.value.to_poly_trait_predicate(), self.constness) + ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness) } } impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { fn to_predicate(&self) -> Predicate<'tcx> { - Predicate::RegionOutlives(*self) + PredicateKind::RegionOutlives(*self) } } impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { fn to_predicate(&self) -> Predicate<'tcx> { - Predicate::TypeOutlives(*self) + PredicateKind::TypeOutlives(*self) } } impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { fn to_predicate(&self) -> Predicate<'tcx> { - Predicate::Projection(*self) + PredicateKind::Projection(*self) } } -impl<'tcx> Predicate<'tcx> { +impl<'tcx> PredicateKind<'tcx> { pub fn to_opt_poly_trait_ref(&self) -> Option> { match *self { - Predicate::Trait(ref t, _) => Some(t.to_poly_trait_ref()), - Predicate::Projection(..) - | Predicate::Subtype(..) - | Predicate::RegionOutlives(..) - | Predicate::WellFormed(..) - | Predicate::ObjectSafe(..) - | Predicate::ClosureKind(..) - | Predicate::TypeOutlives(..) - | Predicate::ConstEvaluatable(..) - | Predicate::ConstEquate(..) => None, + PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()), + PredicateKind::Projection(..) + | PredicateKind::Subtype(..) + | PredicateKind::RegionOutlives(..) + | PredicateKind::WellFormed(..) + | PredicateKind::ObjectSafe(..) + | PredicateKind::ClosureKind(..) + | PredicateKind::TypeOutlives(..) + | PredicateKind::ConstEvaluatable(..) + | PredicateKind::ConstEquate(..) => None, } } pub fn to_opt_type_outlives(&self) -> Option> { match *self { - Predicate::TypeOutlives(data) => Some(data), - Predicate::Trait(..) - | Predicate::Projection(..) - | Predicate::Subtype(..) - | Predicate::RegionOutlives(..) - | Predicate::WellFormed(..) - | Predicate::ObjectSafe(..) - | Predicate::ClosureKind(..) - | Predicate::ConstEvaluatable(..) - | Predicate::ConstEquate(..) => None, + PredicateKind::TypeOutlives(data) => Some(data), + PredicateKind::Trait(..) + | PredicateKind::Projection(..) + | PredicateKind::Subtype(..) + | PredicateKind::RegionOutlives(..) + | PredicateKind::WellFormed(..) + | PredicateKind::ObjectSafe(..) + | PredicateKind::ClosureKind(..) + | PredicateKind::ConstEvaluatable(..) + | PredicateKind::ConstEquate(..) => None, } } } diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index 2502a4a13a8f0..c224c937b07fe 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -2032,28 +2032,28 @@ define_print_and_forward_display! { ty::Predicate<'tcx> { match *self { - ty::Predicate::Trait(ref data, constness) => { + ty::PredicateKind::Trait(ref data, constness) => { if let hir::Constness::Const = constness { p!(write("const ")); } p!(print(data)) } - ty::Predicate::Subtype(ref predicate) => p!(print(predicate)), - ty::Predicate::RegionOutlives(ref predicate) => p!(print(predicate)), - ty::Predicate::TypeOutlives(ref predicate) => p!(print(predicate)), - ty::Predicate::Projection(ref predicate) => p!(print(predicate)), - ty::Predicate::WellFormed(ty) => p!(print(ty), write(" well-formed")), - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::Subtype(ref predicate) => p!(print(predicate)), + ty::PredicateKind::RegionOutlives(ref predicate) => p!(print(predicate)), + ty::PredicateKind::TypeOutlives(ref predicate) => p!(print(predicate)), + ty::PredicateKind::Projection(ref predicate) => p!(print(predicate)), + ty::PredicateKind::WellFormed(ty) => p!(print(ty), write(" well-formed")), + ty::PredicateKind::ObjectSafe(trait_def_id) => { p!(write("the trait `"), print_def_path(trait_def_id, &[]), write("` is object-safe")) } - ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) => { + ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => { p!(write("the closure `"), print_value_path(closure_def_id, &[]), write("` implements the trait `{}`", kind)) } - ty::Predicate::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { p!(write("the constant `"), print_value_path(def_id, substs), write("` can be evaluated")) diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index c23a351ac515c..54f34a3e07815 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -219,25 +219,27 @@ impl fmt::Debug for ty::ProjectionPredicate<'tcx> { } } -impl fmt::Debug for ty::Predicate<'tcx> { +impl fmt::Debug for ty::PredicateKind<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - ty::Predicate::Trait(ref a, constness) => { + ty::PredicateKind::Trait(ref a, constness) => { if let hir::Constness::Const = constness { write!(f, "const ")?; } a.fmt(f) } - ty::Predicate::Subtype(ref pair) => pair.fmt(f), - ty::Predicate::RegionOutlives(ref pair) => pair.fmt(f), - ty::Predicate::TypeOutlives(ref pair) => pair.fmt(f), - ty::Predicate::Projection(ref pair) => pair.fmt(f), - ty::Predicate::WellFormed(ty) => write!(f, "WellFormed({:?})", ty), - ty::Predicate::ObjectSafe(trait_def_id) => write!(f, "ObjectSafe({:?})", trait_def_id), - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { + ty::PredicateKind::Subtype(ref pair) => pair.fmt(f), + ty::PredicateKind::RegionOutlives(ref pair) => pair.fmt(f), + ty::PredicateKind::TypeOutlives(ref pair) => pair.fmt(f), + ty::PredicateKind::Projection(ref pair) => pair.fmt(f), + ty::PredicateKind::WellFormed(ty) => write!(f, "WellFormed({:?})", ty), + ty::PredicateKind::ObjectSafe(trait_def_id) => { + write!(f, "ObjectSafe({:?})", trait_def_id) + } + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind) } - ty::Predicate::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs) } ty::Predicate::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2), @@ -471,30 +473,32 @@ impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> { type Lifted = ty::Predicate<'tcx>; fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option { match *self { - ty::Predicate::Trait(ref binder, constness) => { - tcx.lift(binder).map(|binder| ty::Predicate::Trait(binder, constness)) + ty::PredicateKind::Trait(ref binder, constness) => { + tcx.lift(binder).map(|binder| ty::PredicateKind::Trait(binder, constness)) + } + ty::PredicateKind::Subtype(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::Subtype) } - ty::Predicate::Subtype(ref binder) => tcx.lift(binder).map(ty::Predicate::Subtype), - ty::Predicate::RegionOutlives(ref binder) => { - tcx.lift(binder).map(ty::Predicate::RegionOutlives) + ty::PredicateKind::RegionOutlives(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::RegionOutlives) } - ty::Predicate::TypeOutlives(ref binder) => { - tcx.lift(binder).map(ty::Predicate::TypeOutlives) + ty::PredicateKind::TypeOutlives(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::TypeOutlives) } - ty::Predicate::Projection(ref binder) => { - tcx.lift(binder).map(ty::Predicate::Projection) + ty::PredicateKind::Projection(ref binder) => { + tcx.lift(binder).map(ty::PredicateKind::Projection) } - ty::Predicate::WellFormed(ty) => tcx.lift(&ty).map(ty::Predicate::WellFormed), - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { + ty::PredicateKind::WellFormed(ty) => tcx.lift(&ty).map(ty::PredicateKind::WellFormed), + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { tcx.lift(&closure_substs).map(|closure_substs| { - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) }) } - ty::Predicate::ObjectSafe(trait_def_id) => { - Some(ty::Predicate::ObjectSafe(trait_def_id)) + ty::PredicateKind::ObjectSafe(trait_def_id) => { + Some(ty::PredicateKind::ObjectSafe(trait_def_id)) } - ty::Predicate::ConstEvaluatable(def_id, substs) => { - tcx.lift(&substs).map(|substs| ty::Predicate::ConstEvaluatable(def_id, substs)) + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + tcx.lift(&substs).map(|substs| ty::PredicateKind::ConstEvaluatable(def_id, substs)) } ty::Predicate::ConstEquate(c1, c2) => { tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::Predicate::ConstEquate(c1, c2)) diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 2ad673b2c1943..8962b243911b2 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -615,7 +615,7 @@ impl<'tcx> Binder> { Binder(tr).with_self_ty(tcx, self_ty).without_const().to_predicate() } ExistentialPredicate::Projection(p) => { - ty::Predicate::Projection(Binder(p.with_self_ty(tcx, self_ty))) + ty::PredicateKind::Projection(Binder(p.with_self_ty(tcx, self_ty))) } ExistentialPredicate::AutoTrait(did) => { let trait_ref = diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index 98c0542f9c0dc..d7ea88725ed1b 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -576,7 +576,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let mut found = false; for predicate in bounds.predicates { - if let ty::Predicate::TypeOutlives(binder) = predicate { + if let ty::PredicateKind::TypeOutlives(binder) = predicate { if let ty::OutlivesPredicate(_, ty::RegionKind::ReStatic) = binder.skip_binder() { diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 08aa434010710..d3b1b92bdcd10 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -1016,7 +1016,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } self.prove_predicate( - ty::Predicate::WellFormed(inferred_ty), + ty::PredicateKind::WellFormed(inferred_ty), Locations::All(span), ConstraintCategory::TypeAnnotation, ); @@ -1268,7 +1268,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { obligations.obligations.push(traits::Obligation::new( ObligationCause::dummy(), param_env, - ty::Predicate::WellFormed(revealed_ty), + ty::PredicateKind::WellFormed(revealed_ty), )); obligations.add( infcx @@ -1612,7 +1612,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.check_call_dest(body, term, &sig, destination, term_location); self.prove_predicates( - sig.inputs_and_output.iter().map(|ty| ty::Predicate::WellFormed(ty)), + sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty)), term_location.to_locations(), ConstraintCategory::Boring, ); @@ -2017,7 +2017,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { traits::ObligationCauseCode::RepeatVec(should_suggest), ), self.param_env, - ty::Predicate::Trait( + ty::PredicateKind::Trait( ty::Binder::bind(ty::TraitPredicate { trait_ref: ty::TraitRef::new( self.tcx().require_lang_item( @@ -2686,7 +2686,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { category: ConstraintCategory, ) { self.prove_predicates( - Some(ty::Predicate::Trait( + Some(ty::PredicateKind::Trait( trait_ref.to_poly_trait_ref().to_poly_trait_predicate(), hir::Constness::NotConst, )), diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 0750284889391..7fdf9133dd4b9 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -3,7 +3,7 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_middle::mir::*; use rustc_middle::ty::subst::GenericArgKind; -use rustc_middle::ty::{self, adjustment::PointerCast, Predicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; use std::borrow::Cow; @@ -24,20 +24,22 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) - let predicates = tcx.predicates_of(current); for (predicate, _) in predicates.predicates { match predicate { - Predicate::RegionOutlives(_) - | Predicate::TypeOutlives(_) - | Predicate::WellFormed(_) - | Predicate::Projection(_) - | Predicate::ConstEvaluatable(..) - | Predicate::ConstEquate(..) => continue, - Predicate::ObjectSafe(_) => { + ty::PredicateKind::RegionOutlives(_) + | ty::PredicateKind::TypeOutlives(_) + | ty::PredicateKind::WellFormed(_) + | ty::PredicateKind::Projection(_) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => continue, + ty::PredicateKind::ObjectSafe(_) => { bug!("object safe predicate on function: {:#?}", predicate) } - Predicate::ClosureKind(..) => { + ty::PredicateKind::ClosureKind(..) => { bug!("closure kind predicate on function: {:#?}", predicate) } - Predicate::Subtype(_) => bug!("subtype predicate on function: {:#?}", predicate), - Predicate::Trait(pred, constness) => { + ty::PredicateKind::Subtype(_) => { + bug!("subtype predicate on function: {:#?}", predicate) + } + ty::PredicateKind::Trait(pred, constness) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index b474b23ac4f5c..64a2a9055f323 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -91,13 +91,13 @@ where let ty::GenericPredicates { parent: _, predicates } = predicates; for (predicate, _span) in predicates { match predicate { - ty::Predicate::Trait(poly_predicate, _) => { + ty::PredicateKind::Trait(poly_predicate, _) => { let ty::TraitPredicate { trait_ref } = *poly_predicate.skip_binder(); if self.visit_trait(trait_ref) { return true; } } - ty::Predicate::Projection(poly_predicate) => { + ty::PredicateKind::Projection(poly_predicate) => { let ty::ProjectionPredicate { projection_ty, ty } = *poly_predicate.skip_binder(); if ty.visit_with(self) { @@ -107,13 +107,13 @@ where return true; } } - ty::Predicate::TypeOutlives(poly_predicate) => { + ty::PredicateKind::TypeOutlives(poly_predicate) => { let ty::OutlivesPredicate(ty, _region) = *poly_predicate.skip_binder(); if ty.visit_with(self) { return true; } } - ty::Predicate::RegionOutlives(..) => {} + ty::PredicateKind::RegionOutlives(..) => {} _ => bug!("unexpected predicate: {:?}", predicate), } } diff --git a/src/librustc_trait_selection/opaque_types.rs b/src/librustc_trait_selection/opaque_types.rs index 396965fcfb8b7..472f93201c382 100644 --- a/src/librustc_trait_selection/opaque_types.rs +++ b/src/librustc_trait_selection/opaque_types.rs @@ -1168,7 +1168,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { debug!("instantiate_opaque_types: ty_var={:?}", ty_var); for predicate in &bounds.predicates { - if let ty::Predicate::Projection(projection) = &predicate { + if let ty::PredicateKind::Projection(projection) = &predicate { if projection.skip_binder().ty.references_error() { // No point on adding these obligations since there's a type error involved. return ty_var; @@ -1270,16 +1270,16 @@ crate fn required_region_bounds( .filter_map(|obligation| { debug!("required_region_bounds(obligation={:?})", obligation); match obligation.predicate { - ty::Predicate::Projection(..) - | ty::Predicate::Trait(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::RegionOutlives(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => None, - ty::Predicate::TypeOutlives(predicate) => { + ty::PredicateKind::Projection(..) + | ty::PredicateKind::Trait(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::RegionOutlives(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => None, + ty::PredicateKind::TypeOutlives(predicate) => { // Search for a bound of the form `erased_self_ty // : 'a`, but be wary of something like `for<'a> // erased_self_ty : 'a` (we interpret a diff --git a/src/librustc_trait_selection/traits/auto_trait.rs b/src/librustc_trait_selection/traits/auto_trait.rs index e19ddcd9e5e98..af9623c49981d 100644 --- a/src/librustc_trait_selection/traits/auto_trait.rs +++ b/src/librustc_trait_selection/traits/auto_trait.rs @@ -341,7 +341,7 @@ impl AutoTraitFinder<'tcx> { already_visited.remove(&pred); self.add_user_pred( &mut user_computed_preds, - ty::Predicate::Trait(pred, hir::Constness::NotConst), + ty::PredicateKind::Trait(pred, hir::Constness::NotConst), ); predicates.push_back(pred); } else { @@ -411,8 +411,10 @@ impl AutoTraitFinder<'tcx> { ) { let mut should_add_new = true; user_computed_preds.retain(|&old_pred| { - if let (&ty::Predicate::Trait(new_trait, _), ty::Predicate::Trait(old_trait, _)) = - (&new_pred, old_pred) + if let ( + &ty::PredicateKind::Trait(new_trait, _), + ty::PredicateKind::Trait(old_trait, _), + ) = (&new_pred, old_pred) { if new_trait.def_id() == old_trait.def_id() { let new_substs = new_trait.skip_binder().trait_ref.substs; @@ -631,7 +633,7 @@ impl AutoTraitFinder<'tcx> { // We check this by calling is_of_param on the relevant types // from the various possible predicates match &predicate { - &ty::Predicate::Trait(p, _) => { + &ty::PredicateKind::Trait(p, _) => { if self.is_param_no_infer(p.skip_binder().trait_ref.substs) && !only_projections && is_new_pred @@ -640,7 +642,7 @@ impl AutoTraitFinder<'tcx> { } predicates.push_back(p); } - &ty::Predicate::Projection(p) => { + &ty::PredicateKind::Projection(p) => { debug!( "evaluate_nested_obligations: examining projection predicate {:?}", predicate @@ -765,12 +767,12 @@ impl AutoTraitFinder<'tcx> { } } } - &ty::Predicate::RegionOutlives(ref binder) => { + &ty::PredicateKind::RegionOutlives(ref binder) => { if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() { return false; } } - &ty::Predicate::TypeOutlives(ref binder) => { + &ty::PredicateKind::TypeOutlives(ref binder) => { match ( binder.no_bound_vars(), binder.map_bound_ref(|pred| pred.0).no_bound_vars(), diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index 139b860072224..ac119a0c3d811 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -253,7 +253,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { return; } match obligation.predicate { - ty::Predicate::Trait(ref trait_predicate, _) => { + ty::PredicateKind::Trait(ref trait_predicate, _) => { let trait_predicate = self.resolve_vars_if_possible(trait_predicate); if self.tcx.sess.has_errors() && trait_predicate.references_error() { @@ -468,7 +468,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { trait_pred }); let unit_obligation = Obligation { - predicate: ty::Predicate::Trait( + predicate: ty::PredicateKind::Trait( predicate, hir::Constness::NotConst, ), @@ -489,14 +489,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err } - ty::Predicate::Subtype(ref predicate) => { + ty::PredicateKind::Subtype(ref predicate) => { // Errors for Subtype predicates show up as // `FulfillmentErrorCode::CodeSubtypeError`, // not selection error. span_bug!(span, "subtype requirement gave wrong error: `{:?}`", predicate) } - ty::Predicate::RegionOutlives(ref predicate) => { + ty::PredicateKind::RegionOutlives(ref predicate) => { let predicate = self.resolve_vars_if_possible(predicate); let err = self .region_outlives_predicate(&obligation.cause, &predicate) @@ -512,7 +512,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) } - ty::Predicate::Projection(..) | ty::Predicate::TypeOutlives(..) => { + ty::PredicateKind::Projection(..) | ty::PredicateKind::TypeOutlives(..) => { let predicate = self.resolve_vars_if_possible(&obligation.predicate); struct_span_err!( self.tcx.sess, @@ -523,12 +523,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) } - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::ObjectSafe(trait_def_id) => { let violations = self.tcx.object_safety_violations(trait_def_id); report_object_safety_error(self.tcx, span, trait_def_id, violations) } - ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { let found_kind = self.closure_kind(closure_substs).unwrap(); let closure_span = self.tcx.sess.source_map().guess_head_span( @@ -587,7 +587,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { return; } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { if !self.tcx.sess.opts.debugging_opts.chalk { // WF predicates cannot themselves make // errors. They can only block due to @@ -605,7 +605,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } - ty::Predicate::ConstEvaluatable(..) => { + ty::PredicateKind::ConstEvaluatable(..) => { // Errors for `ConstEvaluatable` predicates show up as // `SelectionError::ConstEvalFailure`, // not `Unimplemented`. @@ -1047,7 +1047,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { } let (cond, error) = match (cond, error) { - (&ty::Predicate::Trait(..), &ty::Predicate::Trait(ref error, _)) => (cond, error), + (&ty::PredicateKind::Trait(..), &ty::PredicateKind::Trait(ref error, _)) => { + (cond, error) + } _ => { // FIXME: make this work in other cases too. return false; @@ -1055,7 +1057,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { }; for obligation in super::elaborate_predicates(self.tcx, std::iter::once(*cond)) { - if let ty::Predicate::Trait(implication, _) = obligation.predicate { + if let ty::PredicateKind::Trait(implication, _) = obligation.predicate { let error = error.to_poly_trait_ref(); let implication = implication.to_poly_trait_ref(); // FIXME: I'm just not taking associated types at all here. @@ -1135,7 +1137,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { // // this can fail if the problem was higher-ranked, in which // cause I have no idea for a good error message. - if let ty::Predicate::Projection(ref data) = predicate { + if let ty::PredicateKind::Projection(ref data) = predicate { let mut selcx = SelectionContext::new(self); let (data, _) = self.replace_bound_vars_with_fresh_vars( obligation.cause.span, @@ -1416,7 +1418,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { } let mut err = match predicate { - ty::Predicate::Trait(ref data, _) => { + ty::PredicateKind::Trait(ref data, _) => { let trait_ref = data.to_poly_trait_ref(); let self_ty = trait_ref.self_ty(); debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind, trait_ref); @@ -1515,7 +1517,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { err } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { // Same hacky approach as above to avoid deluging user // with error messages. if ty.references_error() || self.tcx.sess.has_errors() { @@ -1524,7 +1526,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { self.need_type_info_err(body_id, span, ty, ErrorCode::E0282) } - ty::Predicate::Subtype(ref data) => { + ty::PredicateKind::Subtype(ref data) => { if data.references_error() || self.tcx.sess.has_errors() { // no need to overload user in such cases return; @@ -1534,7 +1536,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { assert!(a.is_ty_var() && b.is_ty_var()); self.need_type_info_err(body_id, span, a, ErrorCode::E0282) } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { let trait_ref = data.to_poly_trait_ref(self.tcx); let self_ty = trait_ref.self_ty(); let ty = data.skip_binder().ty; @@ -1658,7 +1660,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { obligation: &PredicateObligation<'tcx>, ) { if let ( - ty::Predicate::Trait(pred, _), + ty::PredicateKind::Trait(pred, _), ObligationCauseCode::BindingObligation(item_def_id, span), ) = (&obligation.predicate, &obligation.cause.code) { diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index b8771d59dd4bd..5baaf838caa72 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -1238,7 +1238,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // bound was introduced. At least one generator should be present for this diagnostic to be // modified. let (mut trait_ref, mut target_ty) = match obligation.predicate { - ty::Predicate::Trait(p, _) => { + ty::PredicateKind::Trait(p, _) => { (Some(p.skip_binder().trait_ref), Some(p.skip_binder().self_ty())) } _ => (None, None), diff --git a/src/librustc_trait_selection/traits/fulfill.rs b/src/librustc_trait_selection/traits/fulfill.rs index 98f6ac0e54728..0497dec4029d1 100644 --- a/src/librustc_trait_selection/traits/fulfill.rs +++ b/src/librustc_trait_selection/traits/fulfill.rs @@ -323,7 +323,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { let infcx = self.selcx.infcx(); match obligation.predicate { - ty::Predicate::Trait(ref data, _) => { + ty::PredicateKind::Trait(ref data, _) => { let trait_obligation = obligation.with(*data); if data.is_global() { @@ -378,14 +378,14 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::Predicate::RegionOutlives(ref binder) => { + ty::PredicateKind::RegionOutlives(ref binder) => { match infcx.region_outlives_predicate(&obligation.cause, binder) { Ok(()) => ProcessResult::Changed(vec![]), Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)), } } - ty::Predicate::TypeOutlives(ref binder) => { + ty::PredicateKind::TypeOutlives(ref binder) => { // Check if there are higher-ranked vars. match binder.no_bound_vars() { // If there are, inspect the underlying type further. @@ -429,7 +429,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { let project_obligation = obligation.with(*data); match project::poly_project_and_unify_type(self.selcx, &project_obligation) { Ok(None) => { @@ -443,7 +443,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::ObjectSafe(trait_def_id) => { if !self.selcx.tcx().is_object_safe(trait_def_id) { ProcessResult::Error(CodeSelectionError(Unimplemented)) } else { @@ -451,7 +451,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::Predicate::ClosureKind(_, closure_substs, kind) => { + ty::PredicateKind::ClosureKind(_, closure_substs, kind) => { match self.selcx.infcx().closure_kind(closure_substs) { Some(closure_kind) => { if closure_kind.extends(kind) { @@ -464,7 +464,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::Predicate::WellFormed(ty) => { + ty::PredicateKind::WellFormed(ty) => { match wf::obligations( self.selcx.infcx(), obligation.param_env, @@ -481,7 +481,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::Predicate::Subtype(ref subtype) => { + ty::PredicateKind::Subtype(ref subtype) => { match self.selcx.infcx().subtype_predicate( &obligation.cause, obligation.param_env, @@ -510,7 +510,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::Predicate::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { match self.selcx.infcx().const_eval_resolve( obligation.param_env, def_id, diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index 9592f93ce2e76..99d434c5c9292 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -334,7 +334,7 @@ pub fn normalize_param_env_or_error<'tcx>( // TypeOutlives predicates - these are normally used by regionck. let outlives_predicates: Vec<_> = predicates .drain_filter(|predicate| match predicate { - ty::Predicate::TypeOutlives(..) => true, + ty::PredicateKind::TypeOutlives(..) => true, _ => false, }) .collect(); diff --git a/src/librustc_trait_selection/traits/object_safety.rs b/src/librustc_trait_selection/traits/object_safety.rs index 1bfcacd6ccdc1..bb727055d03fb 100644 --- a/src/librustc_trait_selection/traits/object_safety.rs +++ b/src/librustc_trait_selection/traits/object_safety.rs @@ -246,7 +246,7 @@ fn predicates_reference_self( .map(|(predicate, sp)| (predicate.subst_supertrait(tcx, &trait_ref), sp)) .filter_map(|(predicate, &sp)| { match predicate { - ty::Predicate::Trait(ref data, _) => { + ty::PredicateKind::Trait(ref data, _) => { // In the case of a trait predicate, we can skip the "self" type. if data.skip_binder().trait_ref.substs[1..].iter().any(has_self_ty) { Some(sp) @@ -254,7 +254,7 @@ fn predicates_reference_self( None } } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { // And similarly for projections. This should be redundant with // the previous check because any projection should have a // matching `Trait` predicate with the same inputs, but we do @@ -276,14 +276,14 @@ fn predicates_reference_self( None } } - ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::TypeOutlives(..) - | ty::Predicate::RegionOutlives(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => None, + ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::TypeOutlives(..) + | ty::PredicateKind::RegionOutlives(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => None, } }) .collect() @@ -305,18 +305,18 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool { let predicates = tcx.predicates_of(def_id); let predicates = predicates.instantiate_identity(tcx).predicates; elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| match obligation.predicate { - ty::Predicate::Trait(ref trait_pred, _) => { + ty::PredicateKind::Trait(ref trait_pred, _) => { trait_pred.def_id() == sized_def_id && trait_pred.skip_binder().self_ty().is_param(0) } - ty::Predicate::Projection(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::RegionOutlives(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::TypeOutlives(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => false, + ty::PredicateKind::Projection(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::RegionOutlives(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::TypeOutlives(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => false, }) } diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index c4cb72fa08c08..54b064359dcbd 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -671,7 +671,9 @@ fn prune_cache_value_obligations<'a, 'tcx>( // indirect obligations (e.g., we project to `?0`, // but we have `T: Foo` and `?1: Bar`). - ty::Predicate::Projection(ref data) => infcx.unresolved_type_vars(&data.ty()).is_some(), + ty::PredicateKind::Projection(ref data) => { + infcx.unresolved_type_vars(&data.ty()).is_some() + } // We are only interested in `T: Foo` predicates, whre // `U` references one of `unresolved_type_vars`. =) @@ -928,7 +930,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>( let infcx = selcx.infcx(); for predicate in env_predicates { debug!("assemble_candidates_from_predicates: predicate={:?}", predicate); - if let ty::Predicate::Projection(data) = predicate { + if let ty::PredicateKind::Projection(data) = predicate { let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id; let is_match = same_def_id @@ -1164,7 +1166,7 @@ fn confirm_object_candidate<'cx, 'tcx>( // select only those projections that are actually projecting an // item with the correct name let env_predicates = env_predicates.filter_map(|o| match o.predicate { - ty::Predicate::Projection(data) => { + ty::PredicateKind::Projection(data) => { if data.projection_def_id() == obligation.predicate.item_def_id { Some(data) } else { diff --git a/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs b/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs index 981745af80544..c0470084072a9 100644 --- a/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs +++ b/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs @@ -1,6 +1,6 @@ use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse}; use crate::traits::query::Fallible; -use rustc_middle::ty::{ParamEnvAnd, Predicate, TyCtxt}; +use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt}; pub use rustc_middle::traits::query::type_op::ProvePredicate; @@ -15,7 +15,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> { // `&T`, accounts for about 60% percentage of the predicates // we have to prove. No need to canonicalize and all that for // such cases. - if let Predicate::Trait(trait_ref, _) = key.value.predicate { + if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate { if let Some(sized_def_id) = tcx.lang_items().sized_trait() { if trait_ref.def_id() == sized_def_id { if trait_ref.skip_binder().self_ty().is_trivially_sized(tcx) { diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs index 70c6cbef102c5..02da6033a0064 100644 --- a/src/librustc_trait_selection/traits/select.rs +++ b/src/librustc_trait_selection/traits/select.rs @@ -414,13 +414,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } match obligation.predicate { - ty::Predicate::Trait(ref t, _) => { + ty::PredicateKind::Trait(ref t, _) => { debug_assert!(!t.has_escaping_bound_vars()); let obligation = obligation.with(*t); self.evaluate_trait_predicate_recursively(previous_stack, obligation) } - ty::Predicate::Subtype(ref p) => { + ty::PredicateKind::Subtype(ref p) => { // Does this code ever run? match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) { Some(Ok(InferOk { mut obligations, .. })) => { @@ -435,7 +435,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::Predicate::WellFormed(ty) => match wf::obligations( + ty::PredicateKind::WellFormed(ty) => match wf::obligations( self.infcx, obligation.param_env, obligation.cause.body_id, @@ -449,12 +449,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { None => Ok(EvaluatedToAmbig), }, - ty::Predicate::TypeOutlives(..) | ty::Predicate::RegionOutlives(..) => { + ty::PredicateKind::TypeOutlives(..) | ty::PredicateKind::RegionOutlives(..) => { // We do not consider region relationships when evaluating trait matches. Ok(EvaluatedToOkModuloRegions) } - ty::Predicate::ObjectSafe(trait_def_id) => { + ty::PredicateKind::ObjectSafe(trait_def_id) => { if self.tcx().is_object_safe(trait_def_id) { Ok(EvaluatedToOk) } else { @@ -462,7 +462,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { let project_obligation = obligation.with(*data); match project::poly_project_and_unify_type(self, &project_obligation) { Ok(Some(mut subobligations)) => { @@ -483,7 +483,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::Predicate::ClosureKind(_, closure_substs, kind) => { + ty::PredicateKind::ClosureKind(_, closure_substs, kind) => { match self.infcx.closure_kind(closure_substs) { Some(closure_kind) => { if closure_kind.extends(kind) { @@ -496,7 +496,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::Predicate::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { match self.tcx().const_eval_resolve( obligation.param_env, def_id, @@ -676,7 +676,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // if the regions match exactly. let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth); let cycle = cycle.map(|stack| { - ty::Predicate::Trait(stack.obligation.predicate, hir::Constness::NotConst) + ty::PredicateKind::Trait(stack.obligation.predicate, hir::Constness::NotConst) }); if self.coinductive_match(cycle) { debug!("evaluate_stack({:?}) --> recursive, coinductive", stack.fresh_trait_ref); @@ -792,7 +792,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool { let result = match predicate { - ty::Predicate::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()), + ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()), _ => false, }; debug!("coinductive_predicate({:?}) = {:?}", predicate, result); @@ -2921,7 +2921,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligations.push(Obligation::new( obligation.cause.clone(), obligation.param_env, - ty::Predicate::ClosureKind(closure_def_id, substs, kind), + ty::PredicateKind::ClosureKind(closure_def_id, substs, kind), )); } diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index 4d3bbfa77c37d..b1b50eb2331e2 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -73,28 +73,28 @@ pub fn predicate_obligations<'a, 'tcx>( // (*) ok to skip binders, because wf code is prepared for it match *predicate { - ty::Predicate::Trait(ref t, _) => { + ty::PredicateKind::Trait(ref t, _) => { wf.compute_trait_ref(&t.skip_binder().trait_ref, Elaborate::None); // (*) } - ty::Predicate::RegionOutlives(..) => {} - ty::Predicate::TypeOutlives(ref t) => { + ty::PredicateKind::RegionOutlives(..) => {} + ty::PredicateKind::TypeOutlives(ref t) => { wf.compute(t.skip_binder().0); } - ty::Predicate::Projection(ref t) => { + ty::PredicateKind::Projection(ref t) => { let t = t.skip_binder(); // (*) wf.compute_projection(t.projection_ty); wf.compute(t.ty); } - ty::Predicate::WellFormed(t) => { + ty::PredicateKind::WellFormed(t) => { wf.compute(t); } - ty::Predicate::ObjectSafe(_) => {} - ty::Predicate::ClosureKind(..) => {} - ty::Predicate::Subtype(ref data) => { + ty::PredicateKind::ObjectSafe(_) => {} + ty::PredicateKind::ClosureKind(..) => {} + ty::PredicateKind::Subtype(ref data) => { wf.compute(data.skip_binder().a); // (*) wf.compute(data.skip_binder().b); // (*) } - ty::Predicate::ConstEvaluatable(def_id, substs) => { + ty::PredicateKind::ConstEvaluatable(def_id, substs) => { let obligations = wf.nominal_obligations(def_id, substs); wf.out.extend(obligations); @@ -171,7 +171,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( _ => impl_item_ref.span, }; match pred { - ty::Predicate::Projection(proj) => { + ty::PredicateKind::Projection(proj) => { // The obligation comes not from the current `impl` nor the `trait` being // implemented, but rather from a "second order" obligation, like in // `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs`. @@ -194,7 +194,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( } } } - ty::Predicate::Trait(pred, _) => { + ty::PredicateKind::Trait(pred, _) => { // An associated item obligation born out of the `trait` failed to be met. An example // can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`. debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred); @@ -276,7 +276,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { } self.out.extend(trait_ref.substs.types().filter(|ty| !ty.has_escaping_bound_vars()).map( - |ty| traits::Obligation::new(cause.clone(), param_env, ty::Predicate::WellFormed(ty)), + |ty| { + traits::Obligation::new(cause.clone(), param_env, ty::PredicateKind::WellFormed(ty)) + }, )); } @@ -305,7 +307,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { let obligations = self.nominal_obligations(def_id, substs); self.out.extend(obligations); - let predicate = ty::Predicate::ConstEvaluatable(def_id, substs); + let predicate = ty::PredicateKind::ConstEvaluatable(def_id, substs); let cause = self.cause(traits::MiscObligation); self.out.push(traits::Obligation::new(cause, self.param_env, predicate)); } @@ -411,9 +413,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { self.out.push(traits::Obligation::new( cause, param_env, - ty::Predicate::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate( - rty, r, - ))), + ty::PredicateKind::TypeOutlives(ty::Binder::dummy( + ty::OutlivesPredicate(rty, r), + )), )); } } @@ -502,7 +504,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { traits::Obligation::new( cause.clone(), param_env, - ty::Predicate::ObjectSafe(did), + ty::PredicateKind::ObjectSafe(did), ) })); } @@ -528,7 +530,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { self.out.push(traits::Obligation::new( cause, param_env, - ty::Predicate::WellFormed(ty), + ty::PredicateKind::WellFormed(ty), )); } else { // Yes, resolved, proceed with the result. diff --git a/src/librustc_traits/implied_outlives_bounds.rs b/src/librustc_traits/implied_outlives_bounds.rs index eaaab87ab7474..aed5729b34a2c 100644 --- a/src/librustc_traits/implied_outlives_bounds.rs +++ b/src/librustc_traits/implied_outlives_bounds.rs @@ -95,27 +95,27 @@ fn compute_implied_outlives_bounds<'tcx>( implied_bounds.extend(obligations.into_iter().flat_map(|obligation| { assert!(!obligation.has_escaping_bound_vars()); match obligation.predicate { - ty::Predicate::Trait(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::Projection(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => vec![], + ty::PredicateKind::Trait(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::Projection(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => vec![], - ty::Predicate::WellFormed(subty) => { + ty::PredicateKind::WellFormed(subty) => { wf_types.push(subty); vec![] } - ty::Predicate::RegionOutlives(ref data) => match data.no_bound_vars() { + ty::PredicateKind::RegionOutlives(ref data) => match data.no_bound_vars() { None => vec![], Some(ty::OutlivesPredicate(r_a, r_b)) => { vec![OutlivesBound::RegionSubRegion(r_b, r_a)] } }, - ty::Predicate::TypeOutlives(ref data) => match data.no_bound_vars() { + ty::PredicateKind::TypeOutlives(ref data) => match data.no_bound_vars() { None => vec![], Some(ty::OutlivesPredicate(ty_a, r_b)) => { let ty_a = infcx.resolve_vars_if_possible(&ty_a); diff --git a/src/librustc_traits/normalize_erasing_regions.rs b/src/librustc_traits/normalize_erasing_regions.rs index ed30ed5313e5c..11604cc31870f 100644 --- a/src/librustc_traits/normalize_erasing_regions.rs +++ b/src/librustc_traits/normalize_erasing_regions.rs @@ -41,14 +41,14 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>( fn not_outlives_predicate(p: &ty::Predicate<'_>) -> bool { match p { - ty::Predicate::RegionOutlives(..) | ty::Predicate::TypeOutlives(..) => false, - ty::Predicate::Trait(..) - | ty::Predicate::Projection(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => true, + ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false, + ty::PredicateKind::Trait(..) + | ty::PredicateKind::Projection(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => true, } } diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index aeb31c2cb7367..58fa927c021e0 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -7,7 +7,8 @@ use rustc_infer::traits::TraitEngineExt as _; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts}; use rustc_middle::ty::{ - FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, Ty, TyCtxt, TypeFoldable, Variance, + self, FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, Ty, TyCtxt, TypeFoldable, + Variance, }; use rustc_span::DUMMY_SP; use rustc_trait_selection::infer::InferCtxtBuilderExt; @@ -140,7 +141,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { self.relate(self_ty, Variance::Invariant, impl_self_ty)?; - self.prove_predicate(Predicate::WellFormed(impl_self_ty)); + self.prove_predicate(ty::PredicateKind::WellFormed(impl_self_ty)); } // In addition to proving the predicates, we have to @@ -154,7 +155,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { // them? This would only be relevant if some input // type were ill-formed but did not appear in `ty`, // which...could happen with normalization... - self.prove_predicate(Predicate::WellFormed(ty)); + self.prove_predicate(ty::PredicateKind::WellFormed(ty)); Ok(()) } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 6529d784ad452..a697ae7cb877c 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1597,7 +1597,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { obligation.predicate ); match obligation.predicate { - ty::Predicate::Trait(pred, _) => { + ty::PredicateKind::Trait(pred, _) => { associated_types.entry(span).or_default().extend( tcx.associated_items(pred.def_id()) .in_definition_order() @@ -1605,7 +1605,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .map(|item| item.def_id), ); } - ty::Predicate::Projection(pred) => { + ty::PredicateKind::Projection(pred) => { // A `Self` within the original bound will be substituted with a // `trait_object_dummy_self`, so check for that. let references_self = diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 87a6f119acb09..6ade48b80c8a5 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -206,7 +206,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { obligation.predicate ); - if let ty::Predicate::Projection(ref proj_predicate) = obligation.predicate { + if let ty::PredicateKind::Projection(ref proj_predicate) = obligation.predicate { // Given a Projection predicate, we can potentially infer // the complete signature. self.deduce_sig_from_projection(Some(obligation.cause.span), proj_predicate) @@ -526,7 +526,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { all_obligations.push(Obligation::new( cause, self.param_env, - ty::Predicate::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate( + ty::PredicateKind::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate( supplied_ty, closure_body_region, ))), @@ -641,7 +641,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // where R is the return type we are expecting. This type `T` // will be our output. let output_ty = self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| { - if let ty::Predicate::Projection(ref proj_predicate) = obligation.predicate { + if let ty::PredicateKind::Projection(ref proj_predicate) = obligation.predicate { self.deduce_future_output_from_projection(obligation.cause.span, proj_predicate) } else { None diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 54562cf38addd..8a93b05ac8db0 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -597,7 +597,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let obligation = queue.remove(0); debug!("coerce_unsized resolve step: {:?}", obligation); let trait_pred = match obligation.predicate { - ty::Predicate::Trait(trait_pred, _) if traits.contains(&trait_pred.def_id()) => { + ty::PredicateKind::Trait(trait_pred, _) + if traits.contains(&trait_pred.def_id()) => + { if unsize_did == trait_pred.def_id() { let unsize_ty = trait_pred.skip_binder().trait_ref.substs[1].expect_ty(); if let ty::Tuple(..) = unsize_ty.kind { diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 9694ce9450c27..550a236279550 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -644,7 +644,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .unwrap() .def_id; let predicate = - ty::Predicate::Projection(ty::Binder::bind(ty::ProjectionPredicate { + ty::PredicateKind::Projection(ty::Binder::bind(ty::ProjectionPredicate { // `::Output` projection_ty: ty::ProjectionTy { // `T` diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 478a848cf09dd..51d28f7c57c65 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -231,8 +231,10 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( let predicate_matches_closure = |p: &'_ Predicate<'tcx>| { let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env); match (predicate, p) { - (Predicate::Trait(a, _), Predicate::Trait(b, _)) => relator.relate(a, b).is_ok(), - (Predicate::Projection(a), Predicate::Projection(b)) => { + (ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => { + relator.relate(a, b).is_ok() + } + (ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => { relator.relate(a, b).is_ok() } _ => predicate == p, diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index c4805c54a7d43..64917bf4c9f44 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -575,7 +575,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied()) .filter_map(|obligation| match obligation.predicate { - ty::Predicate::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => { + ty::PredicateKind::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => { let span = predicates .predicates .iter() diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index a254aecf07bab..135e02d6b5fac 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -401,7 +401,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { obligations.push(traits::Obligation::new( cause, self.param_env, - ty::Predicate::WellFormed(method_ty), + ty::PredicateKind::WellFormed(method_ty), )); let callee = MethodCallee { def_id, substs: trait_ref.substs, sig: fn_sig }; diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index e21db9035e25d..fbe8e7b767511 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -797,21 +797,21 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // FIXME: do we want to commit to this behavior for param bounds? let bounds = self.param_env.caller_bounds.iter().filter_map(|predicate| match *predicate { - ty::Predicate::Trait(ref trait_predicate, _) => { + ty::PredicateKind::Trait(ref trait_predicate, _) => { match trait_predicate.skip_binder().trait_ref.self_ty().kind { ty::Param(ref p) if *p == param_ty => Some(trait_predicate.to_poly_trait_ref()), _ => None, } } - ty::Predicate::Subtype(..) - | ty::Predicate::Projection(..) - | ty::Predicate::RegionOutlives(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::TypeOutlives(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => None, + ty::PredicateKind::Subtype(..) + | ty::PredicateKind::Projection(..) + | ty::PredicateKind::RegionOutlives(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::TypeOutlives(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => None, }); self.elaborate_bounds(bounds, |this, poly_trait_ref, item| { diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index cf26c94418e2d..e0ab25e49224e 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -574,7 +574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut bound_spans = vec![]; let mut collect_type_param_suggestions = |self_ty: Ty<'_>, parent_pred: &ty::Predicate<'_>, obligation: &str| { - if let (ty::Param(_), ty::Predicate::Trait(p, _)) = + if let (ty::Param(_), ty::PredicateKind::Trait(p, _)) = (&self_ty.kind, parent_pred) { if let ty::Adt(def, _) = p.skip_binder().trait_ref.self_ty().kind { @@ -628,7 +628,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let mut format_pred = |pred| { match pred { - ty::Predicate::Projection(pred) => { + ty::PredicateKind::Projection(pred) => { // `::Item = String`. let trait_ref = pred.skip_binder().projection_ty.trait_ref(self.tcx); @@ -646,7 +646,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { bound_span_label(trait_ref.self_ty(), &obligation, &quiet); Some((obligation, trait_ref.self_ty())) } - ty::Predicate::Trait(poly_trait_ref, _) => { + ty::PredicateKind::Trait(poly_trait_ref, _) => { let p = poly_trait_ref.skip_binder().trait_ref; let self_ty = p.self_ty(); let path = p.print_only_trait_path(); @@ -949,8 +949,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { unsatisfied_predicates.iter().all(|(p, _)| match p { // Hide traits if they are present in predicates as they can be fixed without // having to implement them. - ty::Predicate::Trait(t, _) => t.def_id() == info.def_id, - ty::Predicate::Projection(p) => p.item_def_id() == info.def_id, + ty::PredicateKind::Trait(t, _) => t.def_id() == info.def_id, + ty::PredicateKind::Projection(p) => p.item_def_id() == info.def_id, _ => false, }) && (type_is_local || info.def_id.is_local()) && self diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d72c74e4188ee..79cb7a7fd0ffa 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2224,7 +2224,7 @@ fn bounds_from_generic_predicates( for (predicate, _) in predicates.predicates { debug!("predicate {:?}", predicate); match predicate { - ty::Predicate::Trait(trait_predicate, _) => { + ty::PredicateKind::Trait(trait_predicate, _) => { let entry = types.entry(trait_predicate.skip_binder().self_ty()).or_default(); let def_id = trait_predicate.skip_binder().def_id(); if Some(def_id) != tcx.lang_items().sized_trait() { @@ -2233,7 +2233,7 @@ fn bounds_from_generic_predicates( entry.push(trait_predicate.skip_binder().def_id()); } } - ty::Predicate::Projection(projection_pred) => { + ty::PredicateKind::Projection(projection_pred) => { projections.push(projection_pred); } _ => {} @@ -2770,7 +2770,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { parent: None, predicates: tcx.arena.alloc_from_iter(self.param_env.caller_bounds.iter().filter_map( |&predicate| match predicate { - ty::Predicate::Trait(ref data, _) + ty::PredicateKind::Trait(ref data, _) if data.skip_binder().self_ty().is_param(index) => { // HACK(eddyb) should get the original `Span`. @@ -3379,7 +3379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_predicate(traits::Obligation::new( cause, self.param_env, - ty::Predicate::ConstEvaluatable(def_id, substs), + ty::PredicateKind::ConstEvaluatable(def_id, substs), )); } @@ -3428,7 +3428,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_predicate(traits::Obligation::new( cause, self.param_env, - ty::Predicate::WellFormed(ty), + ty::PredicateKind::WellFormed(ty), )); } @@ -3858,17 +3858,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .pending_obligations() .into_iter() .filter_map(move |obligation| match obligation.predicate { - ty::Predicate::Projection(ref data) => { + ty::PredicateKind::Projection(ref data) => { Some((data.to_poly_trait_ref(self.tcx), obligation)) } - ty::Predicate::Trait(ref data, _) => Some((data.to_poly_trait_ref(), obligation)), - ty::Predicate::Subtype(..) => None, - ty::Predicate::RegionOutlives(..) => None, - ty::Predicate::TypeOutlives(..) => None, - ty::Predicate::WellFormed(..) => None, - ty::Predicate::ObjectSafe(..) => None, - ty::Predicate::ConstEvaluatable(..) => None, - ty::Predicate::ConstEquate(..) => None, + ty::PredicateKind::Trait(ref data, _) => { + Some((data.to_poly_trait_ref(), obligation)) + } + ty::PredicateKind::Subtype(..) => None, + ty::PredicateKind::RegionOutlives(..) => None, + ty::PredicateKind::TypeOutlives(..) => None, + ty::PredicateKind::WellFormed(..) => None, + ty::PredicateKind::ObjectSafe(..) => None, + ty::PredicateKind::ConstEvaluatable(..) => None, + ty::PredicateKind::ConstEquate(..) => None, // N.B., this predicate is created by breaking down a // `ClosureType: FnFoo()` predicate, where // `ClosureType` represents some `Closure`. It can't @@ -3877,7 +3879,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // this closure yet; this is exactly why the other // code is looking for a self type of a unresolved // inference variable. - ty::Predicate::ClosureKind(..) => None, + ty::PredicateKind::ClosureKind(..) => None, }) .filter(move |(tr, _)| self.self_type_matches_expected_vid(*tr, ty_var_root)) } @@ -4206,7 +4208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { continue; } - if let ty::Predicate::Trait(predicate, _) = error.obligation.predicate { + if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate { // Collect the argument position for all arguments that could have caused this // `FulfillmentError`. let mut referenced_in = final_arg_types @@ -4253,7 +4255,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let hir::ExprKind::Path(qpath) = &path.kind { if let hir::QPath::Resolved(_, path) = &qpath { for error in errors { - if let ty::Predicate::Trait(predicate, _) = error.obligation.predicate { + if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate { // If any of the type arguments in this path segment caused the // `FullfillmentError`, point at its span (#61860). for arg in path @@ -5322,7 +5324,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let predicate = - ty::Predicate::Projection(ty::Binder::bind(ty::ProjectionPredicate { + ty::PredicateKind::Projection(ty::Binder::bind(ty::ProjectionPredicate { projection_ty, ty: expected, })); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index b79ac50da8fa3..cb3ee8d1ded0a 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -425,7 +425,7 @@ fn check_type_defn<'tcx, F>( fcx.register_predicate(traits::Obligation::new( cause, fcx.param_env, - ty::Predicate::ConstEvaluatable(discr_def_id.to_def_id(), discr_substs), + ty::PredicateKind::ConstEvaluatable(discr_def_id.to_def_id(), discr_substs), )); } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index fe3028102c685..c39df5df977ed 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -549,7 +549,9 @@ fn type_param_predicates( icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true)) .into_iter() .filter(|(predicate, _)| match predicate { - ty::Predicate::Trait(ref data, _) => data.skip_binder().self_ty().is_param(index), + ty::PredicateKind::Trait(ref data, _) => { + data.skip_binder().self_ty().is_param(index) + } _ => false, }), ); @@ -994,7 +996,7 @@ fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredi // which will, in turn, reach indirect supertraits. for &(pred, span) in superbounds { debug!("superbound: {:?}", pred); - if let ty::Predicate::Trait(bound, _) = pred { + if let ty::PredicateKind::Trait(bound, _) = pred { tcx.at(span).super_predicates_of(bound.def_id()); } } @@ -1899,7 +1901,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat let re_root_empty = tcx.lifetimes.re_root_empty; let predicate = ty::OutlivesPredicate(ty, re_root_empty); predicates.push(( - ty::Predicate::TypeOutlives(ty::Binder::dummy(predicate)), + ty::PredicateKind::TypeOutlives(ty::Binder::dummy(predicate)), span, )); } @@ -1928,7 +1930,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat &hir::GenericBound::Outlives(ref lifetime) => { let region = AstConv::ast_region_to_region(&icx, lifetime, None); let pred = ty::Binder::bind(ty::OutlivesPredicate(ty, region)); - predicates.push((ty::Predicate::TypeOutlives(pred), lifetime.span)) + predicates.push((ty::PredicateKind::TypeOutlives(pred), lifetime.span)) } } } @@ -1945,7 +1947,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat }; let pred = ty::Binder::bind(ty::OutlivesPredicate(r1, r2)); - (ty::Predicate::RegionOutlives(pred), span) + (ty::PredicateKind::RegionOutlives(pred), span) })) } @@ -2116,7 +2118,7 @@ fn predicates_from_bound<'tcx>( hir::GenericBound::Outlives(ref lifetime) => { let region = astconv.ast_region_to_region(lifetime, None); let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region)); - vec![(ty::Predicate::TypeOutlives(pred), lifetime.span)] + vec![(ty::PredicateKind::TypeOutlives(pred), lifetime.span)] } } } diff --git a/src/librustc_typeck/constrained_generic_params.rs b/src/librustc_typeck/constrained_generic_params.rs index 07ff3bc85cc19..c1be430b93e98 100644 --- a/src/librustc_typeck/constrained_generic_params.rs +++ b/src/librustc_typeck/constrained_generic_params.rs @@ -180,7 +180,7 @@ pub fn setup_constraining_predicates<'tcx>( changed = false; for j in i..predicates.len() { - if let ty::Predicate::Projection(ref poly_projection) = predicates[j].0 { + if let ty::PredicateKind::Projection(ref poly_projection) = predicates[j].0 { // Note that we can skip binder here because the impl // trait ref never contains any late-bound regions. let projection = poly_projection.skip_binder(); diff --git a/src/librustc_typeck/impl_wf_check/min_specialization.rs b/src/librustc_typeck/impl_wf_check/min_specialization.rs index 919bcc9943d48..89d63107a9c29 100644 --- a/src/librustc_typeck/impl_wf_check/min_specialization.rs +++ b/src/librustc_typeck/impl_wf_check/min_specialization.rs @@ -204,7 +204,7 @@ fn unconstrained_parent_impl_substs<'tcx>( // the functions in `cgp` add the constrained parameters to a list of // unconstrained parameters. for (predicate, _) in impl_generic_predicates.predicates.iter() { - if let ty::Predicate::Projection(proj) = predicate { + if let ty::PredicateKind::Projection(proj) = predicate { let projection_ty = proj.skip_binder().projection_ty; let projected_ty = proj.skip_binder().ty; @@ -374,7 +374,7 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: &ty::Predicate<'t _ if predicate.is_global() => (), // We allow specializing on explicitly marked traits with no associated // items. - ty::Predicate::Trait(pred, hir::Constness::NotConst) => { + ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { if !matches!( trait_predicate_kind(tcx, predicate), Some(TraitSpecializationKind::Marker) @@ -402,18 +402,18 @@ fn trait_predicate_kind<'tcx>( predicate: &ty::Predicate<'tcx>, ) -> Option { match predicate { - ty::Predicate::Trait(pred, hir::Constness::NotConst) => { + ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { Some(tcx.trait_def(pred.def_id()).specialization_kind) } - ty::Predicate::Trait(_, hir::Constness::Const) - | ty::Predicate::RegionOutlives(_) - | ty::Predicate::TypeOutlives(_) - | ty::Predicate::Projection(_) - | ty::Predicate::WellFormed(_) - | ty::Predicate::Subtype(_) - | ty::Predicate::ObjectSafe(_) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => None, + ty::PredicateKind::Trait(_, hir::Constness::Const) + | ty::PredicateKind::RegionOutlives(_) + | ty::PredicateKind::TypeOutlives(_) + | ty::PredicateKind::Projection(_) + | ty::PredicateKind::WellFormed(_) + | ty::PredicateKind::Subtype(_) + | ty::PredicateKind::ObjectSafe(_) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => None, } } diff --git a/src/librustc_typeck/outlives/explicit.rs b/src/librustc_typeck/outlives/explicit.rs index 66daf0e7f7d9d..bc8d25f953820 100644 --- a/src/librustc_typeck/outlives/explicit.rs +++ b/src/librustc_typeck/outlives/explicit.rs @@ -30,7 +30,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { // process predicates and convert to `RequiredPredicates` entry, see below for &(predicate, span) in predicates.predicates { match predicate { - ty::Predicate::TypeOutlives(predicate) => { + ty::PredicateKind::TypeOutlives(predicate) => { let OutlivesPredicate(ref ty, ref reg) = predicate.skip_binder(); insert_outlives_predicate( tcx, @@ -41,7 +41,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { ) } - ty::Predicate::RegionOutlives(predicate) => { + ty::PredicateKind::RegionOutlives(predicate) => { let OutlivesPredicate(ref reg1, ref reg2) = predicate.skip_binder(); insert_outlives_predicate( tcx, @@ -52,14 +52,14 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { ) } - ty::Predicate::Trait(..) - | ty::Predicate::Projection(..) - | ty::Predicate::WellFormed(..) - | ty::Predicate::ObjectSafe(..) - | ty::Predicate::ClosureKind(..) - | ty::Predicate::Subtype(..) - | ty::Predicate::ConstEvaluatable(..) - | ty::Predicate::ConstEquate(..) => (), + ty::PredicateKind::Trait(..) + | ty::PredicateKind::Projection(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => (), } } diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index a49d8e5ed0f0a..d88fda3550500 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -31,8 +31,8 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate let mut pred: Vec = predicates .iter() .map(|(out_pred, _)| match out_pred { - ty::Predicate::RegionOutlives(p) => p.to_string(), - ty::Predicate::TypeOutlives(p) => p.to_string(), + ty::PredicateKind::RegionOutlives(p) => p.to_string(), + ty::PredicateKind::TypeOutlives(p) => p.to_string(), err => bug!("unexpected predicate {:?}", err), }) .collect(); @@ -84,13 +84,13 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica let predicates = &*tcx.arena.alloc_from_iter(set.iter().filter_map( |(ty::OutlivesPredicate(kind1, region2), &span)| match kind1.unpack() { GenericArgKind::Type(ty1) => Some(( - ty::Predicate::TypeOutlives(ty::Binder::bind(ty::OutlivesPredicate( + ty::PredicateKind::TypeOutlives(ty::Binder::bind(ty::OutlivesPredicate( ty1, region2, ))), span, )), GenericArgKind::Lifetime(region1) => Some(( - ty::Predicate::RegionOutlives(ty::Binder::bind(ty::OutlivesPredicate( + ty::PredicateKind::RegionOutlives(ty::Binder::bind(ty::OutlivesPredicate( region1, region2, ))), span, diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 144c1699a3ca8..ff05c4e583269 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -316,10 +316,10 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { pred: ty::Predicate<'tcx>, ) -> FxHashSet { let regions = match pred { - ty::Predicate::Trait(poly_trait_pred, _) => { + ty::PredicateKind::Trait(poly_trait_pred, _) => { tcx.collect_referenced_late_bound_regions(&poly_trait_pred) } - ty::Predicate::Projection(poly_proj_pred) => { + ty::PredicateKind::Projection(poly_proj_pred) => { tcx.collect_referenced_late_bound_regions(&poly_proj_pred) } _ => return FxHashSet::default(), @@ -466,7 +466,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { .filter(|p| { !orig_bounds.contains(p) || match p { - ty::Predicate::Trait(pred, _) => pred.def_id() == sized_trait, + ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait, _ => false, } }) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c130ed3f46dbb..002af495ff226 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -481,20 +481,18 @@ impl Clean for hir::WherePredicate<'_> { impl<'a> Clean> for ty::Predicate<'a> { fn clean(&self, cx: &DocContext<'_>) -> Option { - use rustc_middle::ty::Predicate; - match *self { - Predicate::Trait(ref pred, _) => Some(pred.clean(cx)), - Predicate::Subtype(ref pred) => Some(pred.clean(cx)), - Predicate::RegionOutlives(ref pred) => pred.clean(cx), - Predicate::TypeOutlives(ref pred) => pred.clean(cx), - Predicate::Projection(ref pred) => Some(pred.clean(cx)), + ty::PredicateKind::Trait(ref pred, _) => Some(pred.clean(cx)), + ty::PredicateKind::Subtype(ref pred) => Some(pred.clean(cx)), + ty::PredicateKind::RegionOutlives(ref pred) => pred.clean(cx), + ty::PredicateKind::TypeOutlives(ref pred) => pred.clean(cx), + ty::PredicateKind::Projection(ref pred) => Some(pred.clean(cx)), - Predicate::WellFormed(..) - | Predicate::ObjectSafe(..) - | Predicate::ClosureKind(..) - | Predicate::ConstEvaluatable(..) - | Predicate::ConstEquate(..) => panic!("not user writable"), + ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => panic!("not user writable"), } } } @@ -765,7 +763,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, ty::GenericPredicates<'tcx if let ty::Param(param) = outlives.skip_binder().0.kind { return Some(param.index); } - } else if let ty::Predicate::Projection(p) = p { + } else if let ty::PredicateKind::Projection(p) = p { if let ty::Param(param) = p.skip_binder().projection_ty.self_ty().kind { projection = Some(p); return Some(param.index); @@ -1663,7 +1661,7 @@ impl<'tcx> Clean for Ty<'tcx> { .filter_map(|predicate| { let trait_ref = if let Some(tr) = predicate.to_opt_poly_trait_ref() { tr - } else if let ty::Predicate::TypeOutlives(pred) = *predicate { + } else if let ty::PredicateKind::TypeOutlives(pred) = *predicate { // these should turn up at the end if let Some(r) = pred.skip_binder().1.clean(cx) { regions.push(GenericBound::Outlives(r)); @@ -1684,7 +1682,7 @@ impl<'tcx> Clean for Ty<'tcx> { .predicates .iter() .filter_map(|pred| { - if let ty::Predicate::Projection(proj) = *pred { + if let ty::PredicateKind::Projection(proj) = *pred { let proj = proj.skip_binder(); if proj.projection_ty.trait_ref(cx.tcx) == *trait_ref.skip_binder() diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 1404d45ea8938..cc91c50346180 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -141,7 +141,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) .predicates .iter() .filter_map(|(pred, _)| { - if let ty::Predicate::Trait(ref pred, _) = *pred { + if let ty::PredicateKind::Trait(ref pred, _) = *pred { if pred.skip_binder().trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 704a95ec0a090..2c2965433fd0e 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -3,7 +3,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Opaque, Predicate::Trait, ToPolyTraitRef}; +use rustc_middle::ty::{Opaque, PredicateKind::Trait, ToPolyTraitRef}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt; diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 626427c15ecf5..79c21d9bc0a64 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -18,7 +18,7 @@ use rustc_lint::{LateContext, LateLintPass, Lint, LintContext}; use rustc_middle::hir::map::Map; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; -use rustc_middle::ty::{self, Predicate, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::{sym, SymbolStr}; @@ -1497,7 +1497,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { // one of the associated types must be Self for predicate in cx.tcx.predicates_of(def_id).predicates { match predicate { - (Predicate::Projection(poly_projection_predicate), _) => { + (ty::PredicateKind::Projection(poly_projection_predicate), _) => { let binder = poly_projection_predicate.ty(); let associated_type = binder.skip_binder(); diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index ed48ab548978c..8f94f143bae71 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter().copied()) .filter(|p| !p.is_global()) .filter_map(|obligation| { - if let ty::Predicate::Trait(poly_trait_ref, _) = obligation.predicate { + if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate { if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars() { return None; diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs index 438a9f42ccd23..3f5693d7e6809 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -1299,7 +1299,7 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { - if let ty::Predicate::Trait(ref poly_trait_predicate, _) = predicate { + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate { if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() { return true; } From 034c25f33e496f602edebd845ddb4f940ac176cf Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 7 May 2020 10:12:19 +0000 Subject: [PATCH 04/13] make `to_predicate` take a `tcx` argument --- src/librustc_infer/traits/engine.rs | 2 +- src/librustc_infer/traits/util.rs | 4 +- src/librustc_middle/ty/mod.rs | 18 ++--- src/librustc_middle/ty/sty.rs | 4 +- .../traits/error_reporting/mod.rs | 14 ++-- .../traits/error_reporting/suggestions.rs | 73 ++++++++++--------- src/librustc_trait_selection/traits/mod.rs | 4 +- .../traits/object_safety.rs | 6 +- .../traits/project.rs | 11 +-- src/librustc_trait_selection/traits/select.rs | 6 +- src/librustc_trait_selection/traits/util.rs | 9 ++- src/librustc_trait_selection/traits/wf.rs | 6 +- src/librustc_ty/ty.rs | 2 +- src/librustc_typeck/astconv.rs | 8 +- src/librustc_typeck/check/autoderef.rs | 2 +- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 7 +- src/librustc_typeck/collect.rs | 8 +- src/librustdoc/clean/blanket_impl.rs | 2 +- 22 files changed, 102 insertions(+), 92 deletions(-) diff --git a/src/librustc_infer/traits/engine.rs b/src/librustc_infer/traits/engine.rs index a95257ba6820a..2710debea9478 100644 --- a/src/librustc_infer/traits/engine.rs +++ b/src/librustc_infer/traits/engine.rs @@ -33,7 +33,7 @@ pub trait TraitEngine<'tcx>: 'tcx { cause, recursion_depth: 0, param_env, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(infcx.tcx), }, ); } diff --git a/src/librustc_infer/traits/util.rs b/src/librustc_infer/traits/util.rs index 400fe4d1321ca..b9cafc530cd47 100644 --- a/src/librustc_infer/traits/util.rs +++ b/src/librustc_infer/traits/util.rs @@ -99,14 +99,14 @@ pub fn elaborate_trait_ref<'tcx>( tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>, ) -> Elaborator<'tcx> { - elaborate_predicates(tcx, std::iter::once(trait_ref.without_const().to_predicate())) + elaborate_predicates(tcx, std::iter::once(trait_ref.without_const().to_predicate(tcx))) } pub fn elaborate_trait_refs<'tcx>( tcx: TyCtxt<'tcx>, trait_refs: impl Iterator>, ) -> Elaborator<'tcx> { - let predicates = trait_refs.map(|trait_ref| trait_ref.without_const().to_predicate()); + let predicates = trait_refs.map(|trait_ref| trait_ref.without_const().to_predicate(tcx)); elaborate_predicates(tcx, predicates) } diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index e3aeb242dc034..16a44328b82fa 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1295,11 +1295,11 @@ impl<'tcx> ToPolyTraitRef<'tcx> for PolyTraitPredicate<'tcx> { } pub trait ToPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx>; + fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx>; } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait( ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value }), self.constness, @@ -1308,7 +1308,7 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait( ty::Binder::dummy(ty::TraitPredicate { trait_ref: *self.value }), self.constness, @@ -1317,31 +1317,31 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> { } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness) } } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&PolyTraitRef<'tcx>> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness) } } impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { PredicateKind::RegionOutlives(*self) } } impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { PredicateKind::TypeOutlives(*self) } } impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { - fn to_predicate(&self) -> Predicate<'tcx> { + fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { PredicateKind::Projection(*self) } } @@ -1619,7 +1619,7 @@ pub struct ConstnessAnd { pub value: T, } -// FIXME(ecstaticmorse): Audit all occurrences of `without_const().to_predicate()` to ensure that +// FIXME(ecstaticmorse): Audit all occurrences of `without_const().to_predicate(tcx)` to ensure that // the constness of trait bounds is being propagated correctly. pub trait WithConstness: Sized { #[inline] diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 8962b243911b2..1e4aaa6054525 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -612,7 +612,7 @@ impl<'tcx> Binder> { use crate::ty::ToPredicate; match *self.skip_binder() { ExistentialPredicate::Trait(tr) => { - Binder(tr).with_self_ty(tcx, self_ty).without_const().to_predicate() + Binder(tr).with_self_ty(tcx, self_ty).without_const().to_predicate(tcx) } ExistentialPredicate::Projection(p) => { ty::PredicateKind::Projection(Binder(p.with_self_ty(tcx, self_ty))) @@ -620,7 +620,7 @@ impl<'tcx> Binder> { ExistentialPredicate::AutoTrait(did) => { let trait_ref = Binder(ty::TraitRef { def_id: did, substs: tcx.mk_substs_trait(self_ty, &[]) }); - trait_ref.without_const().to_predicate() + trait_ref.without_const().to_predicate(tcx) } } } diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index ac119a0c3d811..f997fbadd89fc 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -308,7 +308,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { "{}", message.unwrap_or_else(|| format!( "the trait bound `{}` is not satisfied{}", - trait_ref.without_const().to_predicate(), + trait_ref.without_const().to_predicate(tcx), post_message, )) ); @@ -1021,13 +1021,13 @@ trait InferCtxtPrivExt<'tcx> { fn note_obligation_cause( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, ); fn suggest_unsized_bound_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, ); @@ -1390,7 +1390,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { ) -> PredicateObligation<'tcx> { let new_trait_ref = ty::TraitRef { def_id, substs: self.tcx.mk_substs_trait(output_ty, &[]) }; - Obligation::new(cause, param_env, new_trait_ref.without_const().to_predicate()) + Obligation::new(cause, param_env, new_trait_ref.without_const().to_predicate(self.tcx)) } fn maybe_report_ambiguity( @@ -1629,7 +1629,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { let obligation = Obligation::new( ObligationCause::dummy(), param_env, - cleaned_pred.without_const().to_predicate(), + cleaned_pred.without_const().to_predicate(selcx.tcx()), ); self.predicate_may_hold(&obligation) @@ -1638,7 +1638,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { fn note_obligation_cause( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, ) { // First, attempt to add note to this error with an async-await-specific @@ -1656,7 +1656,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_unsized_bound_if_applicable( &self, - err: &mut DiagnosticBuilder<'_>, + err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx>, ) { if let ( diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index 5baaf838caa72..cbc93278353be 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -38,14 +38,14 @@ pub trait InferCtxtExt<'tcx> { fn suggest_restricting_param_bound( &self, err: &mut DiagnosticBuilder<'_>, - trait_ref: ty::PolyTraitRef<'_>, + trait_ref: ty::PolyTraitRef<'tcx>, body_id: hir::HirId, ); fn suggest_borrow_on_unsized_slice( &self, code: &ObligationCauseCode<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, ); fn get_closure_name( @@ -66,7 +66,7 @@ pub trait InferCtxtExt<'tcx> { fn suggest_add_reference_to_arg( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, points_at_arg: bool, has_custom_message: bool, @@ -75,14 +75,14 @@ pub trait InferCtxtExt<'tcx> { fn suggest_remove_reference( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, ); fn suggest_change_mut( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, points_at_arg: bool, ); @@ -90,7 +90,7 @@ pub trait InferCtxtExt<'tcx> { fn suggest_semicolon_removal( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, span: Span, trait_ref: &ty::Binder>, ); @@ -99,7 +99,7 @@ pub trait InferCtxtExt<'tcx> { fn suggest_impl_trait( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, span: Span, obligation: &PredicateObligation<'tcx>, trait_ref: &ty::Binder>, @@ -107,7 +107,7 @@ pub trait InferCtxtExt<'tcx> { fn point_at_returns_when_relevant( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, obligation: &PredicateObligation<'tcx>, ); @@ -138,11 +138,11 @@ pub trait InferCtxtExt<'tcx> { err: &mut DiagnosticBuilder<'_>, interior_or_upvar_span: GeneratorInteriorOrUpvar, interior_extra_info: Option<(Option, Span, Option, Option)>, - inner_generator_body: Option<&hir::Body<'_>>, + inner_generator_body: Option<&hir::Body<'tcx>>, outer_generator: Option, - trait_ref: ty::TraitRef<'_>, + trait_ref: ty::TraitRef<'tcx>, target_ty: Ty<'tcx>, - tables: &ty::TypeckTables<'_>, + tables: &ty::TypeckTables<'tcx>, obligation: &PredicateObligation<'tcx>, next_code: Option<&ObligationCauseCode<'tcx>>, ); @@ -183,12 +183,13 @@ fn predicate_constraint(generics: &hir::Generics<'_>, pred: String) -> (Span, St /// it can also be an `impl Trait` param that needs to be decomposed to a type /// param for cleaner code. fn suggest_restriction( - generics: &hir::Generics<'_>, + tcx: TyCtxt<'tcx>, + generics: &hir::Generics<'tcx>, msg: &str, err: &mut DiagnosticBuilder<'_>, fn_sig: Option<&hir::FnSig<'_>>, projection: Option<&ty::ProjectionTy<'_>>, - trait_ref: ty::PolyTraitRef<'_>, + trait_ref: ty::PolyTraitRef<'tcx>, super_traits: Option<(&Ident, &hir::GenericBounds<'_>)>, ) { // When we are dealing with a trait, `super_traits` will be `Some`: @@ -243,7 +244,7 @@ fn suggest_restriction( // FIXME: modify the `trait_ref` instead of string shenanigans. // Turn `::Bar: Qux` into `::Bar: Qux`. - let pred = trait_ref.without_const().to_predicate().to_string(); + let pred = trait_ref.without_const().to_predicate(tcx).to_string(); let pred = pred.replace(&impl_trait_str, &type_param_name); let mut sugg = vec![ match generics @@ -285,9 +286,10 @@ fn suggest_restriction( } else { // Trivial case: `T` needs an extra bound: `T: Bound`. let (sp, suggestion) = match super_traits { - None => { - predicate_constraint(generics, trait_ref.without_const().to_predicate().to_string()) - } + None => predicate_constraint( + generics, + trait_ref.without_const().to_predicate(tcx).to_string(), + ), Some((ident, bounds)) => match bounds { [.., bound] => ( bound.span().shrink_to_hi(), @@ -313,7 +315,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_restricting_param_bound( &self, mut err: &mut DiagnosticBuilder<'_>, - trait_ref: ty::PolyTraitRef<'_>, + trait_ref: ty::PolyTraitRef<'tcx>, body_id: hir::HirId, ) { let self_ty = trait_ref.self_ty(); @@ -336,6 +338,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { assert!(param_ty); // Restricting `Self` for a single method. suggest_restriction( + self.tcx, &generics, "`Self`", err, @@ -355,7 +358,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { assert!(param_ty); // Restricting `Self` for a single method. suggest_restriction( - &generics, "`Self`", err, None, projection, trait_ref, None, + self.tcx, &generics, "`Self`", err, None, projection, trait_ref, None, ); return; } @@ -375,6 +378,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { }) if projection.is_some() => { // Missing restriction on associated type of type parameter (unmet projection). suggest_restriction( + self.tcx, &generics, "the associated type", err, @@ -393,6 +397,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { }) if projection.is_some() => { // Missing restriction on associated type of type parameter (unmet projection). suggest_restriction( + self.tcx, &generics, "the associated type", err, @@ -450,7 +455,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_borrow_on_unsized_slice( &self, code: &ObligationCauseCode<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, ) { if let &ObligationCauseCode::VariableType(hir_id) = code { let parent_node = self.tcx.hir().get_parent_node(hir_id); @@ -601,7 +606,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_add_reference_to_arg( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, points_at_arg: bool, has_custom_message: bool, @@ -624,7 +629,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let new_obligation = Obligation::new( ObligationCause::dummy(), param_env, - new_trait_ref.without_const().to_predicate(), + new_trait_ref.without_const().to_predicate(self.tcx), ); if self.predicate_must_hold_modulo_regions(&new_obligation) { if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { @@ -673,7 +678,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_remove_reference( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, ) { let trait_ref = trait_ref.skip_binder(); @@ -735,7 +740,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_change_mut( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, trait_ref: &ty::Binder>, points_at_arg: bool, ) { @@ -806,7 +811,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn suggest_semicolon_removal( &self, obligation: &PredicateObligation<'tcx>, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, span: Span, trait_ref: &ty::Binder>, ) { @@ -852,7 +857,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// emitted. fn suggest_impl_trait( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, span: Span, obligation: &PredicateObligation<'tcx>, trait_ref: &ty::Binder>, @@ -1048,7 +1053,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { fn point_at_returns_when_relevant( &self, - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, obligation: &PredicateObligation<'tcx>, ) { match obligation.cause.code.peel_derives() { @@ -1430,11 +1435,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err: &mut DiagnosticBuilder<'_>, interior_or_upvar_span: GeneratorInteriorOrUpvar, interior_extra_info: Option<(Option, Span, Option, Option)>, - inner_generator_body: Option<&hir::Body<'_>>, + inner_generator_body: Option<&hir::Body<'tcx>>, outer_generator: Option, - trait_ref: ty::TraitRef<'_>, + trait_ref: ty::TraitRef<'tcx>, target_ty: Ty<'tcx>, - tables: &ty::TypeckTables<'_>, + tables: &ty::TypeckTables<'tcx>, obligation: &PredicateObligation<'tcx>, next_code: Option<&ObligationCauseCode<'tcx>>, ) { @@ -1788,7 +1793,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { err.note(&format!("required because it appears within the type `{}`", ty)); obligated_types.push(ty); - let parent_predicate = parent_trait_ref.without_const().to_predicate(); + let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx); if !self.is_recursive_obligation(obligated_types, &data.parent_code) { self.note_obligation_cause_code( err, @@ -1805,7 +1810,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { parent_trait_ref.print_only_trait_path(), parent_trait_ref.skip_binder().self_ty() )); - let parent_predicate = parent_trait_ref.without_const().to_predicate(); + let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx); self.note_obligation_cause_code( err, &parent_predicate, @@ -1815,7 +1820,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } ObligationCauseCode::DerivedObligation(ref data) => { let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); - let parent_predicate = parent_trait_ref.without_const().to_predicate(); + let parent_predicate = parent_trait_ref.without_const().to_predicate(tcx); self.note_obligation_cause_code( err, &parent_predicate, @@ -2061,7 +2066,7 @@ impl NextTypeParamName for &[hir::GenericParam<'_>] { } fn suggest_trait_object_return_type_alternatives( - err: &mut DiagnosticBuilder<'tcx>, + err: &mut DiagnosticBuilder<'_>, ret_ty: Span, trait_obj: &str, is_object_safe: bool, diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index 99d434c5c9292..f67669769a10d 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -143,7 +143,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'tcx>( param_env, cause: ObligationCause::misc(span, hir::CRATE_HIR_ID), recursion_depth: 0, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(infcx.tcx), }; let result = infcx.predicate_must_hold_modulo_regions(&obligation); @@ -557,7 +557,7 @@ fn type_implements_trait<'tcx>( cause: ObligationCause::dummy(), param_env, recursion_depth: 0, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(tcx), }; tcx.infer_ctxt().enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation)) } diff --git a/src/librustc_trait_selection/traits/object_safety.rs b/src/librustc_trait_selection/traits/object_safety.rs index bb727055d03fb..4839a25d85fc9 100644 --- a/src/librustc_trait_selection/traits/object_safety.rs +++ b/src/librustc_trait_selection/traits/object_safety.rs @@ -636,7 +636,7 @@ fn receiver_is_dispatchable<'tcx>( substs: tcx.mk_substs_trait(tcx.types.self_param, &[unsized_self_ty.into()]), } .without_const() - .to_predicate(); + .to_predicate(tcx); // U: Trait let trait_predicate = { @@ -649,7 +649,7 @@ fn receiver_is_dispatchable<'tcx>( } }); - ty::TraitRef { def_id: unsize_did, substs }.without_const().to_predicate() + ty::TraitRef { def_id: unsize_did, substs }.without_const().to_predicate(tcx) }; let caller_bounds: Vec> = param_env @@ -672,7 +672,7 @@ fn receiver_is_dispatchable<'tcx>( substs: tcx.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]), } .without_const() - .to_predicate(); + .to_predicate(tcx); Obligation::new(ObligationCause::dummy(), param_env, predicate) }; diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index 54b064359dcbd..79b6ac3f7ad09 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -432,7 +432,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>( }); let projection = ty::Binder::dummy(ty::ProjectionPredicate { projection_ty, ty: ty_var }); let obligation = - Obligation::with_depth(cause, depth + 1, param_env, projection.to_predicate()); + Obligation::with_depth(cause, depth + 1, param_env, projection.to_predicate(tcx)); obligations.push(obligation); ty_var }) @@ -722,7 +722,7 @@ fn get_paranoid_cache_value_obligation<'a, 'tcx>( cause, recursion_depth: depth, param_env, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(infcx.tcx), } } @@ -757,7 +757,7 @@ fn normalize_to_error<'a, 'tcx>( cause, recursion_depth: depth, param_env, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(selcx.tcx()), }; let tcx = selcx.infcx().tcx; let def_id = projection_ty.item_def_id; @@ -1158,8 +1158,9 @@ fn confirm_object_candidate<'cx, 'tcx>( object_ty ), }; - let env_predicates = - data.projection_bounds().map(|p| p.with_self_ty(selcx.tcx(), object_ty).to_predicate()); + let env_predicates = data + .projection_bounds() + .map(|p| p.with_self_ty(selcx.tcx(), object_ty).to_predicate(selcx.tcx())); let env_predicate = { let env_predicates = elaborate_predicates(selcx.tcx(), env_predicates); diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs index 02da6033a0064..2aae0f2703152 100644 --- a/src/librustc_trait_selection/traits/select.rs +++ b/src/librustc_trait_selection/traits/select.rs @@ -3031,7 +3031,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { cause, obligation.recursion_depth + 1, obligation.param_env, - ty::Binder::bind(outlives).to_predicate(), + ty::Binder::bind(outlives).to_predicate(tcx), )); } @@ -3074,12 +3074,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { tcx.require_lang_item(lang_items::SizedTraitLangItem, None), tcx.mk_substs_trait(source, &[]), ); - nested.push(predicate_to_obligation(tr.without_const().to_predicate())); + nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx))); // If the type is `Foo + 'a`, ensure that the type // being cast to `Foo + 'a` outlives `'a`: let outlives = ty::OutlivesPredicate(source, r); - nested.push(predicate_to_obligation(ty::Binder::dummy(outlives).to_predicate())); + nested.push(predicate_to_obligation(ty::Binder::dummy(outlives).to_predicate(tcx))); } // `[T; n]` -> `[T]` diff --git a/src/librustc_trait_selection/traits/util.rs b/src/librustc_trait_selection/traits/util.rs index eff73cf4a2d8a..f2d3f0e1116e2 100644 --- a/src/librustc_trait_selection/traits/util.rs +++ b/src/librustc_trait_selection/traits/util.rs @@ -97,7 +97,7 @@ impl<'tcx> TraitAliasExpander<'tcx> { fn expand(&mut self, item: &TraitAliasExpansionInfo<'tcx>) -> bool { let tcx = self.tcx; let trait_ref = item.trait_ref(); - let pred = trait_ref.without_const().to_predicate(); + let pred = trait_ref.without_const().to_predicate(tcx); debug!("expand_trait_aliases: trait_ref={:?}", trait_ref); @@ -110,7 +110,7 @@ impl<'tcx> TraitAliasExpander<'tcx> { // Don't recurse if this trait alias is already on the stack for the DFS search. let anon_pred = anonymize_predicate(tcx, &pred); if item.path.iter().rev().skip(1).any(|(tr, _)| { - anonymize_predicate(tcx, &tr.without_const().to_predicate()) == anon_pred + anonymize_predicate(tcx, &tr.without_const().to_predicate(tcx)) == anon_pred }) { return false; } @@ -234,6 +234,7 @@ pub fn predicates_for_generics<'tcx>( } pub fn predicate_for_trait_ref<'tcx>( + tcx: TyCtxt<'tcx>, cause: ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, trait_ref: ty::TraitRef<'tcx>, @@ -243,7 +244,7 @@ pub fn predicate_for_trait_ref<'tcx>( cause, param_env, recursion_depth, - predicate: trait_ref.without_const().to_predicate(), + predicate: trait_ref.without_const().to_predicate(tcx), } } @@ -258,7 +259,7 @@ pub fn predicate_for_trait_def( ) -> PredicateObligation<'tcx> { let trait_ref = ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(self_ty, params) }; - predicate_for_trait_ref(cause, param_env, trait_ref, recursion_depth) + predicate_for_trait_ref(tcx, cause, param_env, trait_ref, recursion_depth) } /// Casts a trait reference into a reference to one of its super diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index b1b50eb2331e2..a6f4819277c20 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -292,7 +292,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { self.compute_trait_ref(&trait_ref, Elaborate::None); if !data.has_escaping_bound_vars() { - let predicate = trait_ref.without_const().to_predicate(); + let predicate = trait_ref.without_const().to_predicate(self.infcx.tcx); let cause = self.cause(traits::ProjectionWf(data)); self.out.push(traits::Obligation::new(cause, self.param_env, predicate)); } @@ -323,7 +323,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { self.out.push(traits::Obligation::new( cause, self.param_env, - trait_ref.without_const().to_predicate(), + trait_ref.without_const().to_predicate(self.infcx.tcx), )); } } @@ -610,7 +610,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { self.out.push(traits::Obligation::new( cause, self.param_env, - outlives.to_predicate(), + outlives.to_predicate(self.infcx.tcx), )); } } diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index 1aa11a761c821..3da5da2d9efb8 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -61,7 +61,7 @@ fn sized_constraint_for_ty<'tcx>( substs: tcx.mk_substs_trait(ty, &[]), }) .without_const() - .to_predicate(); + .to_predicate(tcx); let predicates = tcx.predicates_of(adtdef.did).predicates; if predicates.iter().any(|(p, _)| *p == sized_predicate) { vec![] } else { vec![ty] } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index a697ae7cb877c..f8144d4aade4e 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -3042,7 +3042,7 @@ impl<'tcx> Bounds<'tcx> { def_id: sized, substs: tcx.mk_substs_trait(param_ty, &[]), }); - (trait_ref.without_const().to_predicate(), span) + (trait_ref.without_const().to_predicate(tcx), span) }) }); @@ -3057,16 +3057,16 @@ impl<'tcx> Bounds<'tcx> { // or it's a generic associated type that deliberately has escaping bound vars. let region_bound = ty::fold::shift_region(tcx, region_bound, 1); let outlives = ty::OutlivesPredicate(param_ty, region_bound); - (ty::Binder::bind(outlives).to_predicate(), span) + (ty::Binder::bind(outlives).to_predicate(tcx), span) }) .chain(self.trait_bounds.iter().map(|&(bound_trait_ref, span, constness)| { - let predicate = bound_trait_ref.with_constness(constness).to_predicate(); + let predicate = bound_trait_ref.with_constness(constness).to_predicate(tcx); (predicate, span) })) .chain( self.projection_bounds .iter() - .map(|&(projection, span)| (projection.to_predicate(), span)), + .map(|&(projection, span)| (projection.to_predicate(tcx), span)), ), ) .collect() diff --git a/src/librustc_typeck/check/autoderef.rs b/src/librustc_typeck/check/autoderef.rs index ae6c1738da77d..8ca0861090605 100644 --- a/src/librustc_typeck/check/autoderef.rs +++ b/src/librustc_typeck/check/autoderef.rs @@ -125,7 +125,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { let obligation = traits::Obligation::new( cause.clone(), self.param_env, - trait_ref.without_const().to_predicate(), + trait_ref.without_const().to_predicate(tcx), ); if !self.infcx.predicate_may_hold(&obligation) { debug!("overloaded_deref_ty: cannot match obligation"); diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 135e02d6b5fac..d1da0bbda540a 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -324,7 +324,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span, self.body_id, self.param_env, - poly_trait_ref.without_const().to_predicate(), + poly_trait_ref.without_const().to_predicate(self.tcx), ); // Now we want to know if this can be matched diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index fbe8e7b767511..f1a1c48da166a 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1374,7 +1374,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } TraitCandidate(trait_ref) => { - let predicate = trait_ref.without_const().to_predicate(); + let predicate = trait_ref.without_const().to_predicate(self.tcx); let obligation = traits::Obligation::new(cause, self.param_env, predicate); if !self.predicate_may_hold(&obligation) { result = ProbeResult::NoMatch; diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index e0ab25e49224e..321cc7a3c4bf5 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -58,7 +58,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span, self.body_id, self.param_env, - poly_trait_ref.without_const().to_predicate(), + poly_trait_ref.without_const().to_predicate(tcx), ); self.predicate_may_hold(&obligation) }) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 79cb7a7fd0ffa..b9055722bb571 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1458,7 +1458,7 @@ fn check_fn<'a, 'tcx>( inherited.register_predicate(traits::Obligation::new( cause, param_env, - trait_ref.without_const().to_predicate(), + trait_ref.without_const().to_predicate(tcx), )); } } diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index cb3ee8d1ded0a..aa3865059392f 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -1174,8 +1174,11 @@ fn receiver_is_implemented( substs: fcx.tcx.mk_substs_trait(receiver_ty, &[]), }; - let obligation = - traits::Obligation::new(cause, fcx.param_env, trait_ref.without_const().to_predicate()); + let obligation = traits::Obligation::new( + cause, + fcx.param_env, + trait_ref.without_const().to_predicate(fcx.tcx), + ); if fcx.predicate_must_hold_modulo_regions(&obligation) { true diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index c39df5df977ed..529c9f9f50508 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -528,7 +528,7 @@ fn type_param_predicates( if param_id == item_hir_id { let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id); extend = - Some((identity_trait_ref.without_const().to_predicate(), item.span)); + Some((identity_trait_ref.without_const().to_predicate(tcx), item.span)); } generics } @@ -1657,7 +1657,7 @@ fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> { let span = tcx.sess.source_map().guess_head_span(tcx.def_span(def_id)); result.predicates = tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once(( - ty::TraitRef::identity(tcx, def_id).without_const().to_predicate(), + ty::TraitRef::identity(tcx, def_id).without_const().to_predicate(tcx), span, )))); } @@ -1832,7 +1832,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat // set of defaults that can be incorporated into another impl. if let Some(trait_ref) = is_default_impl_trait { predicates.push(( - trait_ref.to_poly_trait_ref().without_const().to_predicate(), + trait_ref.to_poly_trait_ref().without_const().to_predicate(tcx), tcx.def_span(def_id), )); } @@ -1855,7 +1855,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat hir::GenericBound::Outlives(lt) => { let bound = AstConv::ast_region_to_region(&icx, <, None); let outlives = ty::Binder::bind(ty::OutlivesPredicate(region, bound)); - predicates.push((outlives.to_predicate(), lt.span)); + predicates.push((outlives.to_predicate(tcx), lt.span)); } _ => bug!(), }); diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index d987505e42735..3d2785541beea 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -65,7 +65,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { match infcx.evaluate_obligation(&traits::Obligation::new( cause, param_env, - trait_ref.without_const().to_predicate(), + trait_ref.without_const().to_predicate(infcx.tcx), )) { Ok(eval_result) => eval_result.may_apply(), Err(traits::OverflowError) => true, // overflow doesn't mean yes *or* no From f3164790bdea9ae4f23631f78a4c52dc1b3bdf06 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 11 May 2020 22:06:41 +0200 Subject: [PATCH 05/13] introduce newtype'd `Predicate<'tcx>` --- .../infer/canonical/query_response.rs | 11 ++- src/librustc_infer/infer/combine.rs | 14 ++-- src/librustc_infer/infer/outlives/mod.rs | 2 +- src/librustc_infer/infer/sub.rs | 5 +- src/librustc_infer/traits/util.rs | 34 ++++++--- src/librustc_lint/builtin.rs | 6 +- src/librustc_lint/unused.rs | 4 +- src/librustc_middle/ty/codec.rs | 5 +- src/librustc_middle/ty/context.rs | 9 ++- src/librustc_middle/ty/mod.rs | 53 +++++++++---- src/librustc_middle/ty/print/pretty.rs | 4 +- src/librustc_middle/ty/structural_impls.rs | 16 ++-- src/librustc_middle/ty/sty.rs | 1 + .../borrow_check/diagnostics/region_errors.rs | 2 +- .../borrow_check/type_check/mod.rs | 14 ++-- .../transform/qualify_min_const_fn.rs | 4 +- src/librustc_privacy/lib.rs | 2 +- src/librustc_trait_selection/opaque_types.rs | 4 +- .../traits/auto_trait.rs | 17 +++-- .../traits/error_reporting/mod.rs | 21 +++--- .../traits/error_reporting/suggestions.rs | 2 +- .../traits/fulfill.rs | 4 +- src/librustc_trait_selection/traits/mod.rs | 2 +- .../traits/object_safety.rs | 29 +++---- .../traits/project.rs | 6 +- .../traits/query/type_op/prove_predicate.rs | 2 +- src/librustc_trait_selection/traits/select.rs | 11 ++- src/librustc_trait_selection/traits/wf.rs | 30 +++++--- src/librustc_traits/chalk/lowering.rs | 75 ++++++++++--------- .../implied_outlives_bounds.rs | 2 +- .../normalize_erasing_regions.rs | 2 +- src/librustc_traits/type_op.rs | 10 ++- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/closure.rs | 11 ++- src/librustc_typeck/check/coercion.rs | 2 +- src/librustc_typeck/check/demand.rs | 5 +- src/librustc_typeck/check/dropck.rs | 6 +- src/librustc_typeck/check/method/confirm.rs | 2 +- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 35 +++++---- src/librustc_typeck/check/method/suggest.rs | 8 +- src/librustc_typeck/check/mod.rs | 19 +++-- src/librustc_typeck/check/wfcheck.rs | 3 +- src/librustc_typeck/collect.rs | 16 ++-- .../constrained_generic_params.rs | 2 +- .../impl_wf_check/min_specialization.rs | 6 +- src/librustc_typeck/outlives/explicit.rs | 2 +- src/librustc_typeck/outlives/mod.rs | 40 +++++----- src/librustdoc/clean/auto_trait.rs | 4 +- src/librustdoc/clean/mod.rs | 8 +- src/librustdoc/clean/simplify.rs | 2 +- .../clippy_lints/src/future_not_send.rs | 2 +- .../clippy/clippy_lints/src/methods/mod.rs | 6 +- .../src/needless_pass_by_value.rs | 2 +- .../clippy/clippy_lints/src/utils/mod.rs | 2 +- 55 files changed, 345 insertions(+), 245 deletions(-) diff --git a/src/librustc_infer/infer/canonical/query_response.rs b/src/librustc_infer/infer/canonical/query_response.rs index 67c8265cb1153..23c9eeb21bb8d 100644 --- a/src/librustc_infer/infer/canonical/query_response.rs +++ b/src/librustc_infer/infer/canonical/query_response.rs @@ -25,7 +25,7 @@ use rustc_middle::arena::ArenaAllocatable; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; -use rustc_middle::ty::{self, BoundVar, Const, Ty, TyCtxt}; +use rustc_middle::ty::{self, BoundVar, Const, ToPredicate, Ty, TyCtxt}; use std::fmt::Debug; impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { @@ -534,10 +534,12 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { match k1.unpack() { GenericArgKind::Lifetime(r1) => ty::PredicateKind::RegionOutlives( ty::Binder::bind(ty::OutlivesPredicate(r1, r2)), - ), + ) + .to_predicate(self.tcx), GenericArgKind::Type(t1) => ty::PredicateKind::TypeOutlives(ty::Binder::bind( ty::OutlivesPredicate(t1, r2), - )), + )) + .to_predicate(self.tcx), GenericArgKind::Const(..) => { // Consts cannot outlive one another, so we don't expect to // ecounter this branch. @@ -666,7 +668,8 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> { param_env: self.param_env, predicate: ty::PredicateKind::RegionOutlives(ty::Binder::dummy(ty::OutlivesPredicate( sup, sub, - ))), + ))) + .to_predicate(self.infcx.tcx), recursion_depth: 0, }); } diff --git a/src/librustc_infer/infer/combine.rs b/src/librustc_infer/infer/combine.rs index 2a188b2120556..75f288f1cdcd2 100644 --- a/src/librustc_infer/infer/combine.rs +++ b/src/librustc_infer/infer/combine.rs @@ -39,7 +39,7 @@ use rustc_hir::def_id::DefId; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation}; use rustc_middle::ty::subst::SubstsRef; -use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc_middle::ty::{IntType, UintType}; use rustc_span::{Span, DUMMY_SP}; @@ -307,7 +307,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { self.obligations.push(Obligation::new( self.trace.cause.clone(), self.param_env, - ty::PredicateKind::WellFormed(b_ty), + ty::PredicateKind::WellFormed(b_ty).to_predicate(self.infcx.tcx), )); } @@ -398,11 +398,15 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { b: &'tcx ty::Const<'tcx>, ) { let predicate = if a_is_expected { - ty::Predicate::ConstEquate(a, b) + ty::PredicateKind::ConstEquate(a, b) } else { - ty::Predicate::ConstEquate(b, a) + ty::PredicateKind::ConstEquate(b, a) }; - self.obligations.push(Obligation::new(self.trace.cause.clone(), self.param_env, predicate)); + self.obligations.push(Obligation::new( + self.trace.cause.clone(), + self.param_env, + predicate.to_predicate(self.tcx()), + )); } } diff --git a/src/librustc_infer/infer/outlives/mod.rs b/src/librustc_infer/infer/outlives/mod.rs index e423137da8f74..fd3b38e9d67b0 100644 --- a/src/librustc_infer/infer/outlives/mod.rs +++ b/src/librustc_infer/infer/outlives/mod.rs @@ -11,7 +11,7 @@ pub fn explicit_outlives_bounds<'tcx>( param_env: ty::ParamEnv<'tcx>, ) -> impl Iterator> + 'tcx { debug!("explicit_outlives_bounds()"); - param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate { + param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate.kind() { ty::PredicateKind::Projection(..) | ty::PredicateKind::Trait(..) | ty::PredicateKind::Subtype(..) diff --git a/src/librustc_infer/infer/sub.rs b/src/librustc_infer/infer/sub.rs index 22231488b7b5c..b51af19883fdd 100644 --- a/src/librustc_infer/infer/sub.rs +++ b/src/librustc_infer/infer/sub.rs @@ -6,7 +6,7 @@ use crate::traits::Obligation; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation}; use rustc_middle::ty::TyVar; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt}; use std::mem; /// Ensures `a` is made a subtype of `b`. Returns `a` on success. @@ -104,7 +104,8 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> { a_is_expected: self.a_is_expected, a, b, - })), + })) + .to_predicate(self.tcx()), )); Ok(a) diff --git a/src/librustc_infer/traits/util.rs b/src/librustc_infer/traits/util.rs index b9cafc530cd47..3175ad6c5a44e 100644 --- a/src/librustc_infer/traits/util.rs +++ b/src/librustc_infer/traits/util.rs @@ -10,40 +10,49 @@ pub fn anonymize_predicate<'tcx>( tcx: TyCtxt<'tcx>, pred: &ty::Predicate<'tcx>, ) -> ty::Predicate<'tcx> { - match *pred { + match pred.kind() { ty::PredicateKind::Trait(ref data, constness) => { ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness) + .to_predicate(tcx) } ty::PredicateKind::RegionOutlives(ref data) => { ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data)) + .to_predicate(tcx) } ty::PredicateKind::TypeOutlives(ref data) => { ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data)) + .to_predicate(tcx) } ty::PredicateKind::Projection(ref data) => { - ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)) + ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx) } - ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data), + ty::PredicateKind::WellFormed(data) => { + ty::PredicateKind::WellFormed(data).to_predicate(tcx) + } - ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data), + ty::PredicateKind::ObjectSafe(data) => { + ty::PredicateKind::ObjectSafe(data).to_predicate(tcx) + } ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { - ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) + ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind).to_predicate(tcx) } ty::PredicateKind::Subtype(ref data) => { - ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)) + ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx) } ty::PredicateKind::ConstEvaluatable(def_id, substs) => { - ty::PredicateKind::ConstEvaluatable(def_id, substs) + ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(tcx) } - ty::PredicateKind::ConstEquate(c1, c2) => ty::Predicate::ConstEquate(c1, c2), + ty::PredicateKind::ConstEquate(c1, c2) => { + ty::PredicateKind::ConstEquate(c1, c2).to_predicate(tcx) + } } } @@ -145,7 +154,7 @@ impl Elaborator<'tcx> { fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) { let tcx = self.visited.tcx; - match obligation.predicate { + match obligation.predicate.kind() { ty::PredicateKind::Trait(ref data, _) => { // Get predicates declared on the trait. let predicates = tcx.super_predicates_of(data.def_id()); @@ -250,8 +259,9 @@ impl Elaborator<'tcx> { None } }) - .filter(|p| visited.insert(p)) - .map(|p| predicate_obligation(p, None)), + .map(|predicate_kind| predicate_kind.to_predicate(tcx)) + .filter(|predicate| visited.insert(predicate)) + .map(|predicate| predicate_obligation(predicate, None)), ); } } @@ -317,7 +327,7 @@ impl<'tcx, I: Iterator>> Iterator for FilterToT fn next(&mut self) -> Option> { while let Some(obligation) = self.base_iterator.next() { - if let ty::PredicateKind::Trait(data, _) = obligation.predicate { + if let ty::PredicateKind::Trait(data, _) = obligation.predicate.kind() { return Some(data.to_poly_trait_ref()); } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 6e1258e25bbaf..e17e8b7b9640e 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1208,7 +1208,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints { let def_id = cx.tcx.hir().local_def_id(item.hir_id); let predicates = cx.tcx.predicates_of(def_id); for &(predicate, span) in predicates.predicates { - let predicate_kind_name = match predicate { + let predicate_kind_name = match predicate.kind() { Trait(..) => "Trait", TypeOutlives(..) | RegionOutlives(..) => "Lifetime", @@ -1497,7 +1497,7 @@ impl ExplicitOutlivesRequirements { ) -> Vec> { inferred_outlives .iter() - .filter_map(|(pred, _)| match pred { + .filter_map(|(pred, _)| match pred.kind() { ty::PredicateKind::RegionOutlives(outlives) => { let outlives = outlives.skip_binder(); match outlives.0 { @@ -1516,7 +1516,7 @@ impl ExplicitOutlivesRequirements { ) -> Vec> { inferred_outlives .iter() - .filter_map(|(pred, _)| match pred { + .filter_map(|(pred, _)| match pred.kind() { ty::PredicateKind::TypeOutlives(outlives) => { let outlives = outlives.skip_binder(); outlives.0.is_param(index).then_some(outlives.1) diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 19146f68fce80..dea8293431370 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -146,7 +146,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { ty::Opaque(def, _) => { let mut has_emitted = false; for (predicate, _) in cx.tcx.predicates_of(def).predicates { - if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate { + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = + predicate.kind() + { let trait_ref = poly_trait_predicate.skip_binder().trait_ref; let def_id = trait_ref.def_id; let descr_pre = diff --git a/src/librustc_middle/ty/codec.rs b/src/librustc_middle/ty/codec.rs index 7ebeb6243be41..68a4ccc3c9e67 100644 --- a/src/librustc_middle/ty/codec.rs +++ b/src/librustc_middle/ty/codec.rs @@ -10,7 +10,7 @@ use crate::arena::ArenaAllocatable; use crate::infer::canonical::{CanonicalVarInfo, CanonicalVarInfos}; use crate::mir::{self, interpret::Allocation}; use crate::ty::subst::SubstsRef; -use crate::ty::{self, List, Ty, TyCtxt}; +use crate::ty::{self, List, ToPredicate, Ty, TyCtxt}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder}; @@ -196,7 +196,7 @@ where (0..decoder.read_usize()?) .map(|_| { // Handle shorthands first, if we have an usize > 0x80. - let predicate = if decoder.positioned_at_shorthand() { + let predicate_kind = if decoder.positioned_at_shorthand() { let pos = decoder.read_usize()?; assert!(pos >= SHORTHAND_OFFSET); let shorthand = pos - SHORTHAND_OFFSET; @@ -205,6 +205,7 @@ where } else { ty::PredicateKind::decode(decoder) }?; + let predicate = predicate_kind.to_predicate(tcx); Ok((predicate, Decodable::decode(decoder)?)) }) .collect::, _>>()?, diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index c005455a3aab6..4a9175d8c1838 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -29,7 +29,9 @@ use crate::ty::{self, DefIdTree, Ty, TypeAndMut}; use crate::ty::{AdtDef, AdtKind, Const, Region}; use crate::ty::{BindingMode, BoundVar}; use crate::ty::{ConstVid, FloatVar, FloatVid, IntVar, IntVid, TyVar, TyVid}; -use crate::ty::{ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, ProjectionTy}; +use crate::ty::{ + ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, PredicateKind, ProjectionTy, +}; use crate::ty::{InferConst, ParamConst}; use crate::ty::{List, TyKind, TyS}; use rustc_ast::ast; @@ -2103,6 +2105,11 @@ impl<'tcx> TyCtxt<'tcx> { self.interners.intern_ty(st) } + #[inline] + pub fn mk_predicate(&self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> { + Predicate { kind } + } + pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> { match tm { ast::IntTy::Isize => self.types.isize, diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 16a44328b82fa..3c4c4574bfd54 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1016,7 +1016,17 @@ impl<'tcx> GenericPredicates<'tcx> { } } -pub type Predicate<'tcx> = PredicateKind<'tcx>; +#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Lift)] +#[derive(HashStable, TypeFoldable)] +pub struct Predicate<'tcx> { + kind: PredicateKind<'tcx>, +} + +impl Predicate<'tcx> { + pub fn kind(&self) -> PredicateKind<'tcx> { + self.kind + } +} #[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] #[derive(HashStable, TypeFoldable)] @@ -1081,7 +1091,7 @@ impl<'tcx> AsRef> for Predicate<'tcx> { } } -impl<'tcx> PredicateKind<'tcx> { +impl<'tcx> Predicate<'tcx> { /// Performs a substitution suitable for going from a /// poly-trait-ref to supertraits that must hold if that /// poly-trait-ref holds. This is slightly different from a normal @@ -1153,7 +1163,7 @@ impl<'tcx> PredicateKind<'tcx> { // this trick achieves that). let substs = &trait_ref.skip_binder().substs; - match *self { + match self.kind() { PredicateKind::Trait(ref binder, constness) => { PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness) } @@ -1181,6 +1191,7 @@ impl<'tcx> PredicateKind<'tcx> { PredicateKind::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs)) } } + .to_predicate(tcx) } } @@ -1298,57 +1309,67 @@ pub trait ToPredicate<'tcx> { fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx>; } +impl ToPredicate<'tcx> for PredicateKind<'tcx> { + fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + tcx.mk_predicate(*self) + } +} + impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { - fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait( ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value }), self.constness, ) + .to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> { - fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait( ty::Binder::dummy(ty::TraitPredicate { trait_ref: *self.value }), self.constness, ) + .to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd> { - fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness) + .to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&PolyTraitRef<'tcx>> { - fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness) + .to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> { - fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - PredicateKind::RegionOutlives(*self) + fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + PredicateKind::RegionOutlives(*self).to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> { - fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - PredicateKind::TypeOutlives(*self) + fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + PredicateKind::TypeOutlives(*self).to_predicate(tcx) } } impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { - fn to_predicate(&self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { - PredicateKind::Projection(*self) + fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> { + PredicateKind::Projection(*self).to_predicate(tcx) } } -impl<'tcx> PredicateKind<'tcx> { +impl<'tcx> Predicate<'tcx> { pub fn to_opt_poly_trait_ref(&self) -> Option> { - match *self { + match self.kind() { PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()), PredicateKind::Projection(..) | PredicateKind::Subtype(..) @@ -1363,7 +1384,7 @@ impl<'tcx> PredicateKind<'tcx> { } pub fn to_opt_type_outlives(&self) -> Option> { - match *self { + match self.kind() { PredicateKind::TypeOutlives(data) => Some(data), PredicateKind::Trait(..) | PredicateKind::Projection(..) diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index c224c937b07fe..786fe55519e7b 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -2031,7 +2031,7 @@ define_print_and_forward_display! { } ty::Predicate<'tcx> { - match *self { + match self.kind() { ty::PredicateKind::Trait(ref data, constness) => { if let hir::Constness::Const = constness { p!(write("const ")); @@ -2058,7 +2058,7 @@ define_print_and_forward_display! { print_value_path(def_id, substs), write("` can be evaluated")) } - ty::Predicate::ConstEquate(c1, c2) => { + ty::PredicateKind::ConstEquate(c1, c2) => { p!(write("the constant `"), print(c1), write("` equals `"), diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index 54f34a3e07815..ca7cf97f4af34 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -219,6 +219,12 @@ impl fmt::Debug for ty::ProjectionPredicate<'tcx> { } } +impl fmt::Debug for ty::Predicate<'tcx> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{:?}", self.kind()) + } +} + impl fmt::Debug for ty::PredicateKind<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { @@ -242,7 +248,7 @@ impl fmt::Debug for ty::PredicateKind<'tcx> { ty::PredicateKind::ConstEvaluatable(def_id, substs) => { write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs) } - ty::Predicate::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2), + ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2), } } } @@ -469,8 +475,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> { } } -impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> { - type Lifted = ty::Predicate<'tcx>; +impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> { + type Lifted = ty::PredicateKind<'tcx>; fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option { match *self { ty::PredicateKind::Trait(ref binder, constness) => { @@ -500,8 +506,8 @@ impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> { ty::PredicateKind::ConstEvaluatable(def_id, substs) => { tcx.lift(&substs).map(|substs| ty::PredicateKind::ConstEvaluatable(def_id, substs)) } - ty::Predicate::ConstEquate(c1, c2) => { - tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::Predicate::ConstEquate(c1, c2)) + ty::PredicateKind::ConstEquate(c1, c2) => { + tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2)) } } } diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 1e4aaa6054525..0c9eef8093f33 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -616,6 +616,7 @@ impl<'tcx> Binder> { } ExistentialPredicate::Projection(p) => { ty::PredicateKind::Projection(Binder(p.with_self_ty(tcx, self_ty))) + .to_predicate(tcx) } ExistentialPredicate::AutoTrait(did) => { let trait_ref = diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index d7ea88725ed1b..ebc8021a3c577 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -576,7 +576,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let mut found = false; for predicate in bounds.predicates { - if let ty::PredicateKind::TypeOutlives(binder) = predicate { + if let ty::PredicateKind::TypeOutlives(binder) = predicate.kind() { if let ty::OutlivesPredicate(_, ty::RegionKind::ReStatic) = binder.skip_binder() { diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index d3b1b92bdcd10..bdbce1de745ad 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -27,8 +27,8 @@ use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef, UserSubsts}; use rustc_middle::ty::{ - self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, RegionVid, ToPolyTraitRef, Ty, - TyCtxt, UserType, UserTypeAnnotationIndex, + self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, RegionVid, ToPolyTraitRef, + ToPredicate, Ty, TyCtxt, UserType, UserTypeAnnotationIndex, }; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::VariantIdx; @@ -1016,7 +1016,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } self.prove_predicate( - ty::PredicateKind::WellFormed(inferred_ty), + ty::PredicateKind::WellFormed(inferred_ty).to_predicate(self.tcx()), Locations::All(span), ConstraintCategory::TypeAnnotation, ); @@ -1268,7 +1268,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { obligations.obligations.push(traits::Obligation::new( ObligationCause::dummy(), param_env, - ty::PredicateKind::WellFormed(revealed_ty), + ty::PredicateKind::WellFormed(revealed_ty).to_predicate(infcx.tcx), )); obligations.add( infcx @@ -2028,7 +2028,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ), }), hir::Constness::NotConst, - ), + ) + .to_predicate(self.tcx()), ), &traits::SelectionError::Unimplemented, false, @@ -2708,11 +2709,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { fn prove_predicates( &mut self, - predicates: impl IntoIterator>, + predicates: impl IntoIterator>, locations: Locations, category: ConstraintCategory, ) { for predicate in predicates { + let predicate = predicate.to_predicate(self.tcx()); debug!("prove_predicates(predicate={:?}, locations={:?})", predicate, locations,); self.prove_predicate(predicate, locations, category); diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 7fdf9133dd4b9..55be4f55a569c 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -23,7 +23,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) - loop { let predicates = tcx.predicates_of(current); for (predicate, _) in predicates.predicates { - match predicate { + match predicate.kind() { ty::PredicateKind::RegionOutlives(_) | ty::PredicateKind::TypeOutlives(_) | ty::PredicateKind::WellFormed(_) @@ -46,7 +46,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) - match pred.skip_binder().self_ty().kind { ty::Param(ref p) => { // Allow `T: ?const Trait` - if *constness == hir::Constness::NotConst + if constness == hir::Constness::NotConst && feature_allowed(tcx, def_id, sym::const_trait_bound_opt_out) { continue; diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 64a2a9055f323..9a63e39f535c1 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -90,7 +90,7 @@ where fn visit_predicates(&mut self, predicates: ty::GenericPredicates<'tcx>) -> bool { let ty::GenericPredicates { parent: _, predicates } = predicates; for (predicate, _span) in predicates { - match predicate { + match predicate.kind() { ty::PredicateKind::Trait(poly_predicate, _) => { let ty::TraitPredicate { trait_ref } = *poly_predicate.skip_binder(); if self.visit_trait(trait_ref) { diff --git a/src/librustc_trait_selection/opaque_types.rs b/src/librustc_trait_selection/opaque_types.rs index 472f93201c382..2544e4ddea2ec 100644 --- a/src/librustc_trait_selection/opaque_types.rs +++ b/src/librustc_trait_selection/opaque_types.rs @@ -1168,7 +1168,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { debug!("instantiate_opaque_types: ty_var={:?}", ty_var); for predicate in &bounds.predicates { - if let ty::PredicateKind::Projection(projection) = &predicate { + if let ty::PredicateKind::Projection(projection) = predicate.kind() { if projection.skip_binder().ty.references_error() { // No point on adding these obligations since there's a type error involved. return ty_var; @@ -1269,7 +1269,7 @@ crate fn required_region_bounds( traits::elaborate_predicates(tcx, predicates) .filter_map(|obligation| { debug!("required_region_bounds(obligation={:?})", obligation); - match obligation.predicate { + match obligation.predicate.kind() { ty::PredicateKind::Projection(..) | ty::PredicateKind::Trait(..) | ty::PredicateKind::Subtype(..) diff --git a/src/librustc_trait_selection/traits/auto_trait.rs b/src/librustc_trait_selection/traits/auto_trait.rs index af9623c49981d..bea4725226753 100644 --- a/src/librustc_trait_selection/traits/auto_trait.rs +++ b/src/librustc_trait_selection/traits/auto_trait.rs @@ -341,7 +341,8 @@ impl AutoTraitFinder<'tcx> { already_visited.remove(&pred); self.add_user_pred( &mut user_computed_preds, - ty::PredicateKind::Trait(pred, hir::Constness::NotConst), + ty::PredicateKind::Trait(pred, hir::Constness::NotConst) + .to_predicate(self.tcx), ); predicates.push_back(pred); } else { @@ -412,9 +413,9 @@ impl AutoTraitFinder<'tcx> { let mut should_add_new = true; user_computed_preds.retain(|&old_pred| { if let ( - &ty::PredicateKind::Trait(new_trait, _), + ty::PredicateKind::Trait(new_trait, _), ty::PredicateKind::Trait(old_trait, _), - ) = (&new_pred, old_pred) + ) = (new_pred.kind(), old_pred.kind()) { if new_trait.def_id() == old_trait.def_id() { let new_substs = new_trait.skip_binder().trait_ref.substs; @@ -632,8 +633,8 @@ impl AutoTraitFinder<'tcx> { // // We check this by calling is_of_param on the relevant types // from the various possible predicates - match &predicate { - &ty::PredicateKind::Trait(p, _) => { + match predicate.kind() { + ty::PredicateKind::Trait(p, _) => { if self.is_param_no_infer(p.skip_binder().trait_ref.substs) && !only_projections && is_new_pred @@ -642,7 +643,7 @@ impl AutoTraitFinder<'tcx> { } predicates.push_back(p); } - &ty::PredicateKind::Projection(p) => { + ty::PredicateKind::Projection(p) => { debug!( "evaluate_nested_obligations: examining projection predicate {:?}", predicate @@ -767,12 +768,12 @@ impl AutoTraitFinder<'tcx> { } } } - &ty::PredicateKind::RegionOutlives(ref binder) => { + ty::PredicateKind::RegionOutlives(ref binder) => { if select.infcx().region_outlives_predicate(&dummy_cause, binder).is_err() { return false; } } - &ty::PredicateKind::TypeOutlives(ref binder) => { + ty::PredicateKind::TypeOutlives(ref binder) => { match ( binder.no_bound_vars(), binder.map_bound_ref(|pred| pred.0).no_bound_vars(), diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index f997fbadd89fc..f85735064c838 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -252,7 +252,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { .emit(); return; } - match obligation.predicate { + match obligation.predicate.kind() { ty::PredicateKind::Trait(ref trait_predicate, _) => { let trait_predicate = self.resolve_vars_if_possible(trait_predicate); @@ -471,7 +471,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { predicate: ty::PredicateKind::Trait( predicate, hir::Constness::NotConst, - ), + ) + .to_predicate(self.tcx), ..obligation.clone() }; if self.predicate_may_hold(&unit_obligation) { @@ -616,7 +617,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) } - ty::Predicate::ConstEquate(..) => { + ty::PredicateKind::ConstEquate(..) => { // Errors for `ConstEquate` predicates show up as // `SelectionError::ConstEvalFailure`, // not `Unimplemented`. @@ -1046,10 +1047,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { return true; } - let (cond, error) = match (cond, error) { - (&ty::PredicateKind::Trait(..), &ty::PredicateKind::Trait(ref error, _)) => { - (cond, error) - } + let (cond, error) = match (cond.kind(), error.kind()) { + (ty::PredicateKind::Trait(..), ty::PredicateKind::Trait(error, _)) => (cond, error), _ => { // FIXME: make this work in other cases too. return false; @@ -1057,7 +1056,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { }; for obligation in super::elaborate_predicates(self.tcx, std::iter::once(*cond)) { - if let ty::PredicateKind::Trait(implication, _) = obligation.predicate { + if let ty::PredicateKind::Trait(implication, _) = obligation.predicate.kind() { let error = error.to_poly_trait_ref(); let implication = implication.to_poly_trait_ref(); // FIXME: I'm just not taking associated types at all here. @@ -1137,7 +1136,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { // // this can fail if the problem was higher-ranked, in which // cause I have no idea for a good error message. - if let ty::PredicateKind::Projection(ref data) = predicate { + if let ty::PredicateKind::Projection(ref data) = predicate.kind() { let mut selcx = SelectionContext::new(self); let (data, _) = self.replace_bound_vars_with_fresh_vars( obligation.cause.span, @@ -1417,7 +1416,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { return; } - let mut err = match predicate { + let mut err = match predicate.kind() { ty::PredicateKind::Trait(ref data, _) => { let trait_ref = data.to_poly_trait_ref(); let self_ty = trait_ref.self_ty(); @@ -1662,7 +1661,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { if let ( ty::PredicateKind::Trait(pred, _), ObligationCauseCode::BindingObligation(item_def_id, span), - ) = (&obligation.predicate, &obligation.cause.code) + ) = (obligation.predicate.kind(), &obligation.cause.code) { if let (Some(generics), true) = ( self.tcx.hir().get_if_local(*item_def_id).as_ref().and_then(|n| n.generics()), diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index cbc93278353be..6167412642eab 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -1242,7 +1242,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // the type. The last generator (`outer_generator` below) has information about where the // bound was introduced. At least one generator should be present for this diagnostic to be // modified. - let (mut trait_ref, mut target_ty) = match obligation.predicate { + let (mut trait_ref, mut target_ty) = match obligation.predicate.kind() { ty::PredicateKind::Trait(p, _) => { (Some(p.skip_binder().trait_ref), Some(p.skip_binder().self_ty())) } diff --git a/src/librustc_trait_selection/traits/fulfill.rs b/src/librustc_trait_selection/traits/fulfill.rs index 0497dec4029d1..88ff97e793af4 100644 --- a/src/librustc_trait_selection/traits/fulfill.rs +++ b/src/librustc_trait_selection/traits/fulfill.rs @@ -322,7 +322,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { let infcx = self.selcx.infcx(); - match obligation.predicate { + match obligation.predicate.kind() { ty::PredicateKind::Trait(ref data, _) => { let trait_obligation = obligation.with(*data); @@ -523,7 +523,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::Predicate::ConstEquate(c1, c2) => { + ty::PredicateKind::ConstEquate(c1, c2) => { debug!("equating consts: c1={:?} c2={:?}", c1, c2); let stalled_on = &mut pending_obligation.stalled_on; diff --git a/src/librustc_trait_selection/traits/mod.rs b/src/librustc_trait_selection/traits/mod.rs index f67669769a10d..3daa9109aafe8 100644 --- a/src/librustc_trait_selection/traits/mod.rs +++ b/src/librustc_trait_selection/traits/mod.rs @@ -333,7 +333,7 @@ pub fn normalize_param_env_or_error<'tcx>( // This works fairly well because trait matching does not actually care about param-env // TypeOutlives predicates - these are normally used by regionck. let outlives_predicates: Vec<_> = predicates - .drain_filter(|predicate| match predicate { + .drain_filter(|predicate| match predicate.kind() { ty::PredicateKind::TypeOutlives(..) => true, _ => false, }) diff --git a/src/librustc_trait_selection/traits/object_safety.rs b/src/librustc_trait_selection/traits/object_safety.rs index 4839a25d85fc9..b2d684e674f02 100644 --- a/src/librustc_trait_selection/traits/object_safety.rs +++ b/src/librustc_trait_selection/traits/object_safety.rs @@ -245,7 +245,7 @@ fn predicates_reference_self( .iter() .map(|(predicate, sp)| (predicate.subst_supertrait(tcx, &trait_ref), sp)) .filter_map(|(predicate, &sp)| { - match predicate { + match predicate.kind() { ty::PredicateKind::Trait(ref data, _) => { // In the case of a trait predicate, we can skip the "self" type. if data.skip_binder().trait_ref.substs[1..].iter().any(has_self_ty) { @@ -304,19 +304,22 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool { // Search for a predicate like `Self : Sized` amongst the trait bounds. let predicates = tcx.predicates_of(def_id); let predicates = predicates.instantiate_identity(tcx).predicates; - elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| match obligation.predicate { - ty::PredicateKind::Trait(ref trait_pred, _) => { - trait_pred.def_id() == sized_def_id && trait_pred.skip_binder().self_ty().is_param(0) + elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| { + match obligation.predicate.kind() { + ty::PredicateKind::Trait(ref trait_pred, _) => { + trait_pred.def_id() == sized_def_id + && trait_pred.skip_binder().self_ty().is_param(0) + } + ty::PredicateKind::Projection(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::RegionOutlives(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::TypeOutlives(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => false, } - ty::PredicateKind::Projection(..) - | ty::PredicateKind::Subtype(..) - | ty::PredicateKind::RegionOutlives(..) - | ty::PredicateKind::WellFormed(..) - | ty::PredicateKind::ObjectSafe(..) - | ty::PredicateKind::ClosureKind(..) - | ty::PredicateKind::TypeOutlives(..) - | ty::PredicateKind::ConstEvaluatable(..) - | ty::PredicateKind::ConstEquate(..) => false, }) } diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index 79b6ac3f7ad09..bcf28cb29cb85 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -661,7 +661,7 @@ fn prune_cache_value_obligations<'a, 'tcx>( let mut obligations: Vec<_> = result .obligations .iter() - .filter(|obligation| match obligation.predicate { + .filter(|obligation| match obligation.predicate.kind() { // We found a `T: Foo` predicate, let's check // if `U` references any unresolved type // variables. In principle, we only care if this @@ -930,7 +930,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>( let infcx = selcx.infcx(); for predicate in env_predicates { debug!("assemble_candidates_from_predicates: predicate={:?}", predicate); - if let ty::PredicateKind::Projection(data) = predicate { + if let ty::PredicateKind::Projection(data) = predicate.kind() { let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id; let is_match = same_def_id @@ -1166,7 +1166,7 @@ fn confirm_object_candidate<'cx, 'tcx>( // select only those projections that are actually projecting an // item with the correct name - let env_predicates = env_predicates.filter_map(|o| match o.predicate { + let env_predicates = env_predicates.filter_map(|o| match o.predicate.kind() { ty::PredicateKind::Projection(data) => { if data.projection_def_id() == obligation.predicate.item_def_id { Some(data) diff --git a/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs b/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs index c0470084072a9..5c8719da14e6f 100644 --- a/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs +++ b/src/librustc_trait_selection/traits/query/type_op/prove_predicate.rs @@ -15,7 +15,7 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> { // `&T`, accounts for about 60% percentage of the predicates // we have to prove. No need to canonicalize and all that for // such cases. - if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate { + if let ty::PredicateKind::Trait(trait_ref, _) = key.value.predicate.kind() { if let Some(sized_def_id) = tcx.lang_items().sized_trait() { if trait_ref.def_id() == sized_def_id { if trait_ref.skip_binder().self_ty().is_trivially_sized(tcx) { diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs index 2aae0f2703152..59d85281d633b 100644 --- a/src/librustc_trait_selection/traits/select.rs +++ b/src/librustc_trait_selection/traits/select.rs @@ -413,7 +413,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { None => self.check_recursion_limit(&obligation, &obligation)?, } - match obligation.predicate { + match obligation.predicate.kind() { ty::PredicateKind::Trait(ref t, _) => { debug_assert!(!t.has_escaping_bound_vars()); let obligation = obligation.with(*t); @@ -510,7 +510,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::Predicate::ConstEquate(c1, c2) => { + ty::PredicateKind::ConstEquate(c1, c2) => { debug!("evaluate_predicate_recursively: equating consts c1={:?} c2={:?}", c1, c2); let evaluate = |c: &'tcx ty::Const<'tcx>| { @@ -675,8 +675,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // trait refs. This is important because it's only a cycle // if the regions match exactly. let cycle = stack.iter().skip(1).take_while(|s| s.depth >= cycle_depth); + let tcx = self.tcx(); let cycle = cycle.map(|stack| { ty::PredicateKind::Trait(stack.obligation.predicate, hir::Constness::NotConst) + .to_predicate(tcx) }); if self.coinductive_match(cycle) { debug!("evaluate_stack({:?}) --> recursive, coinductive", stack.fresh_trait_ref); @@ -791,7 +793,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool { - let result = match predicate { + let result = match predicate.kind() { ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()), _ => false, }; @@ -2921,7 +2923,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligations.push(Obligation::new( obligation.cause.clone(), obligation.param_env, - ty::PredicateKind::ClosureKind(closure_def_id, substs, kind), + ty::PredicateKind::ClosureKind(closure_def_id, substs, kind) + .to_predicate(self.tcx()), )); } diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index a6f4819277c20..1d89ba4efe0ac 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -72,7 +72,7 @@ pub fn predicate_obligations<'a, 'tcx>( let mut wf = WfPredicates { infcx, param_env, body_id, span, out: vec![], item: None }; // (*) ok to skip binders, because wf code is prepared for it - match *predicate { + match predicate.kind() { ty::PredicateKind::Trait(ref t, _) => { wf.compute_trait_ref(&t.skip_binder().trait_ref, Elaborate::None); // (*) } @@ -102,7 +102,7 @@ pub fn predicate_obligations<'a, 'tcx>( wf.compute(ty); } } - ty::Predicate::ConstEquate(c1, c2) => { + ty::PredicateKind::ConstEquate(c1, c2) => { wf.compute(c1.ty); wf.compute(c2.ty); } @@ -170,7 +170,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( hir::ImplItemKind::Const(ty, _) | hir::ImplItemKind::TyAlias(ty) => ty.span, _ => impl_item_ref.span, }; - match pred { + match pred.kind() { ty::PredicateKind::Projection(proj) => { // The obligation comes not from the current `impl` nor the `trait` being // implemented, but rather from a "second order" obligation, like in @@ -216,6 +216,10 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( } impl<'a, 'tcx> WfPredicates<'a, 'tcx> { + fn tcx(&self) -> TyCtxt<'tcx> { + self.infcx.tcx + } + fn cause(&mut self, code: traits::ObligationCauseCode<'tcx>) -> traits::ObligationCause<'tcx> { traits::ObligationCause::new(self.span, self.body_id, code) } @@ -275,9 +279,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { self.out.extend(obligations); } + let tcx = self.tcx(); self.out.extend(trait_ref.substs.types().filter(|ty| !ty.has_escaping_bound_vars()).map( |ty| { - traits::Obligation::new(cause.clone(), param_env, ty::PredicateKind::WellFormed(ty)) + traits::Obligation::new( + cause.clone(), + param_env, + ty::PredicateKind::WellFormed(ty).to_predicate(tcx), + ) }, )); } @@ -307,7 +316,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { let obligations = self.nominal_obligations(def_id, substs); self.out.extend(obligations); - let predicate = ty::PredicateKind::ConstEvaluatable(def_id, substs); + let predicate = + ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(self.tcx()); let cause = self.cause(traits::MiscObligation); self.out.push(traits::Obligation::new(cause, self.param_env, predicate)); } @@ -415,7 +425,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { param_env, ty::PredicateKind::TypeOutlives(ty::Binder::dummy( ty::OutlivesPredicate(rty, r), - )), + )) + .to_predicate(self.tcx()), )); } } @@ -495,16 +506,17 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { // obligations that don't refer to Self and // checking those - let defer_to_coercion = self.infcx.tcx.features().object_safe_for_dispatch; + let defer_to_coercion = self.tcx().features().object_safe_for_dispatch; if !defer_to_coercion { let cause = self.cause(traits::MiscObligation); let component_traits = data.auto_traits().chain(data.principal_def_id()); + let tcx = self.tcx(); self.out.extend(component_traits.map(|did| { traits::Obligation::new( cause.clone(), param_env, - ty::PredicateKind::ObjectSafe(did), + ty::PredicateKind::ObjectSafe(did).to_predicate(tcx), ) })); } @@ -530,7 +542,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { self.out.push(traits::Obligation::new( cause, param_env, - ty::PredicateKind::WellFormed(ty), + ty::PredicateKind::WellFormed(ty).to_predicate(self.tcx()), )); } else { // Yes, resolved, proceed with the result. diff --git a/src/librustc_traits/chalk/lowering.rs b/src/librustc_traits/chalk/lowering.rs index 184b9a9dc1040..7d48b45753810 100644 --- a/src/librustc_traits/chalk/lowering.rs +++ b/src/librustc_traits/chalk/lowering.rs @@ -38,8 +38,7 @@ use rustc_middle::traits::{ use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::subst::{GenericArg, SubstsRef}; use rustc_middle::ty::{ - self, Binder, BoundRegion, Predicate, Region, RegionKind, Ty, TyCtxt, TyKind, TypeFoldable, - TypeVisitor, + self, Binder, BoundRegion, Region, RegionKind, Ty, TyCtxt, TyKind, TypeFoldable, TypeVisitor, }; use rustc_span::def_id::DefId; @@ -78,8 +77,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment chalk_ir::InEnvironment>> { let clauses = self.environment.into_iter().filter_map(|clause| match clause { ChalkEnvironmentClause::Predicate(predicate) => { - match predicate { - ty::Predicate::Trait(predicate, _) => { + match &predicate.kind() { + ty::PredicateKind::Trait(predicate, _) => { let (predicate, binders, _named_regions) = collect_bound_vars(interner, interner.tcx, predicate); @@ -100,9 +99,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment None, - ty::Predicate::TypeOutlives(_) => None, - ty::Predicate::Projection(predicate) => { + ty::PredicateKind::RegionOutlives(_) => None, + ty::PredicateKind::TypeOutlives(_) => None, + ty::PredicateKind::Projection(predicate) => { let (predicate, binders, _named_regions) = collect_bound_vars(interner, interner.tcx, predicate); @@ -122,12 +121,14 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment bug!("unexpected predicate {}", predicate), + ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => { + bug!("unexpected predicate {}", predicate) + } } } ChalkEnvironmentClause::TypeFromEnv(ty) => Some( @@ -154,17 +155,17 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predicate<'tcx> { fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData> { - match self { - Predicate::Trait(predicate, _) => predicate.lower_into(interner), + match self.kind() { + ty::PredicateKind::Trait(predicate, _) => predicate.lower_into(interner), // FIXME(chalk): we need to register constraints. - Predicate::RegionOutlives(_predicate) => { + ty::PredicateKind::RegionOutlives(_predicate) => { chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)) } - Predicate::TypeOutlives(_predicate) => { + ty::PredicateKind::TypeOutlives(_predicate) => { chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)) } - Predicate::Projection(predicate) => predicate.lower_into(interner), - Predicate::WellFormed(ty) => match ty.kind { + ty::PredicateKind::Projection(predicate) => predicate.lower_into(interner), + ty::PredicateKind::WellFormed(ty) => match ty.kind { // These types are always WF. ty::Str | ty::Placeholder(..) | ty::Error | ty::Never => { chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)) @@ -188,11 +189,13 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predi // // We can defer this, but ultimately we'll want to express // some of these in terms of chalk operations. - Predicate::ObjectSafe(..) - | Predicate::ClosureKind(..) - | Predicate::Subtype(..) - | Predicate::ConstEvaluatable(..) - | Predicate::ConstEquate(..) => chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)), + ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => { + chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)) + } } } } @@ -439,8 +442,8 @@ impl<'tcx> LowerInto<'tcx, Option, ) -> Option>> { - match &self { - Predicate::Trait(predicate, _) => { + match &self.kind() { + ty::PredicateKind::Trait(predicate, _) => { let (predicate, binders, _named_regions) = collect_bound_vars(interner, interner.tcx, predicate); @@ -449,16 +452,16 @@ impl<'tcx> LowerInto<'tcx, Option None, - Predicate::TypeOutlives(_predicate) => None, - Predicate::Projection(_predicate) => None, - Predicate::WellFormed(_ty) => None, - - Predicate::ObjectSafe(..) - | Predicate::ClosureKind(..) - | Predicate::Subtype(..) - | Predicate::ConstEvaluatable(..) - | Predicate::ConstEquate(..) => bug!("unexpected predicate {}", &self), + ty::PredicateKind::RegionOutlives(_predicate) => None, + ty::PredicateKind::TypeOutlives(_predicate) => None, + ty::PredicateKind::Projection(_predicate) => None, + ty::PredicateKind::WellFormed(_ty) => None, + + ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::Subtype(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => bug!("unexpected predicate {}", &self), } } } diff --git a/src/librustc_traits/implied_outlives_bounds.rs b/src/librustc_traits/implied_outlives_bounds.rs index aed5729b34a2c..5dee71a2338cc 100644 --- a/src/librustc_traits/implied_outlives_bounds.rs +++ b/src/librustc_traits/implied_outlives_bounds.rs @@ -94,7 +94,7 @@ fn compute_implied_outlives_bounds<'tcx>( // region relationships. implied_bounds.extend(obligations.into_iter().flat_map(|obligation| { assert!(!obligation.has_escaping_bound_vars()); - match obligation.predicate { + match obligation.predicate.kind() { ty::PredicateKind::Trait(..) | ty::PredicateKind::Subtype(..) | ty::PredicateKind::Projection(..) diff --git a/src/librustc_traits/normalize_erasing_regions.rs b/src/librustc_traits/normalize_erasing_regions.rs index 11604cc31870f..fcb75142269df 100644 --- a/src/librustc_traits/normalize_erasing_regions.rs +++ b/src/librustc_traits/normalize_erasing_regions.rs @@ -40,7 +40,7 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>( } fn not_outlives_predicate(p: &ty::Predicate<'_>) -> bool { - match p { + match p.kind() { ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false, ty::PredicateKind::Trait(..) | ty::PredicateKind::Projection(..) diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index 58fa927c021e0..2a338383c9a07 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -7,8 +7,8 @@ use rustc_infer::traits::TraitEngineExt as _; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts}; use rustc_middle::ty::{ - self, FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, Ty, TyCtxt, TypeFoldable, - Variance, + self, FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, ToPredicate, Ty, TyCtxt, + TypeFoldable, Variance, }; use rustc_span::DUMMY_SP; use rustc_trait_selection::infer::InferCtxtBuilderExt; @@ -141,7 +141,9 @@ impl AscribeUserTypeCx<'me, 'tcx> { self.relate(self_ty, Variance::Invariant, impl_self_ty)?; - self.prove_predicate(ty::PredicateKind::WellFormed(impl_self_ty)); + self.prove_predicate( + ty::PredicateKind::WellFormed(impl_self_ty).to_predicate(self.tcx()), + ); } // In addition to proving the predicates, we have to @@ -155,7 +157,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { // them? This would only be relevant if some input // type were ill-formed but did not appear in `ty`, // which...could happen with normalization... - self.prove_predicate(ty::PredicateKind::WellFormed(ty)); + self.prove_predicate(ty::PredicateKind::WellFormed(ty).to_predicate(self.tcx())); Ok(()) } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index f8144d4aade4e..3526a1b59f384 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1596,7 +1596,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { "conv_object_ty_poly_trait_ref: observing object predicate `{:?}`", obligation.predicate ); - match obligation.predicate { + match obligation.predicate.kind() { ty::PredicateKind::Trait(pred, _) => { associated_types.entry(span).or_default().extend( tcx.associated_items(pred.def_id()) diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 6ade48b80c8a5..f393121a0adb8 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -12,7 +12,7 @@ use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_infer::infer::{InferOk, InferResult}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::InternalSubsts; -use rustc_middle::ty::{self, GenericParamDefKind, Ty}; +use rustc_middle::ty::{self, GenericParamDefKind, ToPredicate, Ty}; use rustc_span::source_map::Span; use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits::error_reporting::ArgKind; @@ -206,7 +206,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { obligation.predicate ); - if let ty::PredicateKind::Projection(ref proj_predicate) = obligation.predicate { + if let ty::PredicateKind::Projection(ref proj_predicate) = + obligation.predicate.kind() + { // Given a Projection predicate, we can potentially infer // the complete signature. self.deduce_sig_from_projection(Some(obligation.cause.span), proj_predicate) @@ -529,7 +531,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::PredicateKind::TypeOutlives(ty::Binder::dummy(ty::OutlivesPredicate( supplied_ty, closure_body_region, - ))), + ))) + .to_predicate(self.tcx), )); } @@ -641,7 +644,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // where R is the return type we are expecting. This type `T` // will be our output. let output_ty = self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| { - if let ty::PredicateKind::Projection(ref proj_predicate) = obligation.predicate { + if let ty::PredicateKind::Projection(ref proj_predicate) = obligation.predicate.kind() { self.deduce_future_output_from_projection(obligation.cause.span, proj_predicate) } else { None diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 8a93b05ac8db0..705bace4a9ccc 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -596,7 +596,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { while !queue.is_empty() { let obligation = queue.remove(0); debug!("coerce_unsized resolve step: {:?}", obligation); - let trait_pred = match obligation.predicate { + let trait_pred = match obligation.predicate.kind() { ty::PredicateKind::Trait(trait_pred, _) if traits.contains(&trait_pred.def_id()) => { diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 550a236279550..fc7a9c1d59b76 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -10,7 +10,7 @@ use rustc_hir as hir; use rustc_hir::lang_items::{CloneTraitLangItem, DerefTraitLangItem}; use rustc_hir::{is_range_literal, Node}; use rustc_middle::ty::adjustment::AllowTwoPhase; -use rustc_middle::ty::{self, AssocItem, Ty, TypeAndMut}; +use rustc_middle::ty::{self, AssocItem, ToPredicate, Ty, TypeAndMut}; use rustc_span::symbol::sym; use rustc_span::Span; @@ -654,7 +654,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, // `U` ty: expected, - })); + })) + .to_predicate(self.tcx); let obligation = traits::Obligation::new(self.misc(sp), self.param_env, predicate); let impls_deref = self.infcx.predicate_may_hold(&obligation); diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 51d28f7c57c65..3843b97f23d41 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -230,12 +230,12 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( // could be extended easily also to the other `Predicate`. let predicate_matches_closure = |p: &'_ Predicate<'tcx>| { let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env); - match (predicate, p) { + match (predicate.kind(), p.kind()) { (ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => { - relator.relate(a, b).is_ok() + relator.relate(&a, &b).is_ok() } (ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => { - relator.relate(a, b).is_ok() + relator.relate(&a, &b).is_ok() } _ => predicate == p, } diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 64917bf4c9f44..410c5efdf37d4 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -574,7 +574,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { }; traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied()) - .filter_map(|obligation| match obligation.predicate { + .filter_map(|obligation| match obligation.predicate.kind() { ty::PredicateKind::Trait(trait_pred, _) if trait_pred.def_id() == sized_def_id => { let span = predicates .predicates diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index d1da0bbda540a..aae02ea0273f9 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -401,7 +401,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { obligations.push(traits::Obligation::new( cause, self.param_env, - ty::PredicateKind::WellFormed(method_ty), + ty::PredicateKind::WellFormed(method_ty).to_predicate(tcx), )); let callee = MethodCallee { def_id, substs: trait_ref.substs, sig: fn_sig }; diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index f1a1c48da166a..91562d576ea80 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -796,23 +796,26 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) { // FIXME: do we want to commit to this behavior for param bounds? - let bounds = self.param_env.caller_bounds.iter().filter_map(|predicate| match *predicate { - ty::PredicateKind::Trait(ref trait_predicate, _) => { - match trait_predicate.skip_binder().trait_ref.self_ty().kind { - ty::Param(ref p) if *p == param_ty => Some(trait_predicate.to_poly_trait_ref()), - _ => None, + let bounds = + self.param_env.caller_bounds.iter().filter_map(|predicate| match predicate.kind() { + ty::PredicateKind::Trait(ref trait_predicate, _) => { + match trait_predicate.skip_binder().trait_ref.self_ty().kind { + ty::Param(ref p) if *p == param_ty => { + Some(trait_predicate.to_poly_trait_ref()) + } + _ => None, + } } - } - ty::PredicateKind::Subtype(..) - | ty::PredicateKind::Projection(..) - | ty::PredicateKind::RegionOutlives(..) - | ty::PredicateKind::WellFormed(..) - | ty::PredicateKind::ObjectSafe(..) - | ty::PredicateKind::ClosureKind(..) - | ty::PredicateKind::TypeOutlives(..) - | ty::PredicateKind::ConstEvaluatable(..) - | ty::PredicateKind::ConstEquate(..) => None, - }); + ty::PredicateKind::Subtype(..) + | ty::PredicateKind::Projection(..) + | ty::PredicateKind::RegionOutlives(..) + | ty::PredicateKind::WellFormed(..) + | ty::PredicateKind::ObjectSafe(..) + | ty::PredicateKind::ClosureKind(..) + | ty::PredicateKind::TypeOutlives(..) + | ty::PredicateKind::ConstEvaluatable(..) + | ty::PredicateKind::ConstEquate(..) => None, + }); self.elaborate_bounds(bounds, |this, poly_trait_ref, item| { let trait_ref = this.erase_late_bound_regions(&poly_trait_ref); diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 321cc7a3c4bf5..7ca3eb884d88f 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -575,7 +575,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut collect_type_param_suggestions = |self_ty: Ty<'_>, parent_pred: &ty::Predicate<'_>, obligation: &str| { if let (ty::Param(_), ty::PredicateKind::Trait(p, _)) = - (&self_ty.kind, parent_pred) + (&self_ty.kind, parent_pred.kind()) { if let ty::Adt(def, _) = p.skip_binder().trait_ref.self_ty().kind { let node = def.did.as_local().map(|def_id| { @@ -626,8 +626,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => {} } }; - let mut format_pred = |pred| { - match pred { + let mut format_pred = |pred: ty::Predicate<'tcx>| { + match pred.kind() { ty::PredicateKind::Projection(pred) => { // `::Item = String`. let trait_ref = @@ -946,7 +946,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // this isn't perfect (that is, there are cases when // implementing a trait would be legal but is rejected // here). - unsatisfied_predicates.iter().all(|(p, _)| match p { + unsatisfied_predicates.iter().all(|(p, _)| match p.kind() { // Hide traits if they are present in predicates as they can be fixed without // having to implement them. ty::PredicateKind::Trait(t, _) => t.def_id() == info.def_id, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index b9055722bb571..c452859414cfb 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2223,7 +2223,7 @@ fn bounds_from_generic_predicates( let mut projections = vec![]; for (predicate, _) in predicates.predicates { debug!("predicate {:?}", predicate); - match predicate { + match predicate.kind() { ty::PredicateKind::Trait(trait_predicate, _) => { let entry = types.entry(trait_predicate.skip_binder().self_ty()).or_default(); let def_id = trait_predicate.skip_binder().def_id(); @@ -2769,7 +2769,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { ty::GenericPredicates { parent: None, predicates: tcx.arena.alloc_from_iter(self.param_env.caller_bounds.iter().filter_map( - |&predicate| match predicate { + |&predicate| match predicate.kind() { ty::PredicateKind::Trait(ref data, _) if data.skip_binder().self_ty().is_param(index) => { @@ -3379,7 +3379,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_predicate(traits::Obligation::new( cause, self.param_env, - ty::PredicateKind::ConstEvaluatable(def_id, substs), + ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(self.tcx), )); } @@ -3428,7 +3428,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.register_predicate(traits::Obligation::new( cause, self.param_env, - ty::PredicateKind::WellFormed(ty), + ty::PredicateKind::WellFormed(ty).to_predicate(self.tcx), )); } @@ -3857,7 +3857,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .borrow() .pending_obligations() .into_iter() - .filter_map(move |obligation| match obligation.predicate { + .filter_map(move |obligation| match obligation.predicate.kind() { ty::PredicateKind::Projection(ref data) => { Some((data.to_poly_trait_ref(self.tcx), obligation)) } @@ -4208,7 +4208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { continue; } - if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate { + if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate.kind() { // Collect the argument position for all arguments that could have caused this // `FulfillmentError`. let mut referenced_in = final_arg_types @@ -4255,7 +4255,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let hir::ExprKind::Path(qpath) = &path.kind { if let hir::QPath::Resolved(_, path) = &qpath { for error in errors { - if let ty::PredicateKind::Trait(predicate, _) = error.obligation.predicate { + if let ty::PredicateKind::Trait(predicate, _) = + error.obligation.predicate.kind() + { // If any of the type arguments in this path segment caused the // `FullfillmentError`, point at its span (#61860). for arg in path @@ -5327,7 +5329,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::PredicateKind::Projection(ty::Binder::bind(ty::ProjectionPredicate { projection_ty, ty: expected, - })); + })) + .to_predicate(self.tcx); let obligation = traits::Obligation::new(self.misc(sp), self.param_env, predicate); debug!("suggest_missing_await: trying obligation {:?}", obligation); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index aa3865059392f..d5db613d9dcad 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -425,7 +425,8 @@ fn check_type_defn<'tcx, F>( fcx.register_predicate(traits::Obligation::new( cause, fcx.param_env, - ty::PredicateKind::ConstEvaluatable(discr_def_id.to_def_id(), discr_substs), + ty::PredicateKind::ConstEvaluatable(discr_def_id.to_def_id(), discr_substs) + .to_predicate(fcx.tcx), )); } } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 529c9f9f50508..fa4c9edcd218d 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -548,7 +548,7 @@ fn type_param_predicates( let extra_predicates = extend.into_iter().chain( icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, OnlySelfBounds(true)) .into_iter() - .filter(|(predicate, _)| match predicate { + .filter(|(predicate, _)| match predicate.kind() { ty::PredicateKind::Trait(ref data, _) => { data.skip_binder().self_ty().is_param(index) } @@ -996,7 +996,7 @@ fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredi // which will, in turn, reach indirect supertraits. for &(pred, span) in superbounds { debug!("superbound: {:?}", pred); - if let ty::PredicateKind::Trait(bound, _) = pred { + if let ty::PredicateKind::Trait(bound, _) = pred.kind() { tcx.at(span).super_predicates_of(bound.def_id()); } } @@ -1901,7 +1901,8 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat let re_root_empty = tcx.lifetimes.re_root_empty; let predicate = ty::OutlivesPredicate(ty, re_root_empty); predicates.push(( - ty::PredicateKind::TypeOutlives(ty::Binder::dummy(predicate)), + ty::PredicateKind::TypeOutlives(ty::Binder::dummy(predicate)) + .to_predicate(tcx), span, )); } @@ -1930,7 +1931,10 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat &hir::GenericBound::Outlives(ref lifetime) => { let region = AstConv::ast_region_to_region(&icx, lifetime, None); let pred = ty::Binder::bind(ty::OutlivesPredicate(ty, region)); - predicates.push((ty::PredicateKind::TypeOutlives(pred), lifetime.span)) + predicates.push(( + ty::PredicateKind::TypeOutlives(pred).to_predicate(tcx), + lifetime.span, + )) } } } @@ -1947,7 +1951,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat }; let pred = ty::Binder::bind(ty::OutlivesPredicate(r1, r2)); - (ty::PredicateKind::RegionOutlives(pred), span) + (ty::PredicateKind::RegionOutlives(pred).to_predicate(icx.tcx), span) })) } @@ -2118,7 +2122,7 @@ fn predicates_from_bound<'tcx>( hir::GenericBound::Outlives(ref lifetime) => { let region = astconv.ast_region_to_region(lifetime, None); let pred = ty::Binder::bind(ty::OutlivesPredicate(param_ty, region)); - vec![(ty::PredicateKind::TypeOutlives(pred), lifetime.span)] + vec![(ty::PredicateKind::TypeOutlives(pred).to_predicate(astconv.tcx()), lifetime.span)] } } } diff --git a/src/librustc_typeck/constrained_generic_params.rs b/src/librustc_typeck/constrained_generic_params.rs index c1be430b93e98..34497d12a4ece 100644 --- a/src/librustc_typeck/constrained_generic_params.rs +++ b/src/librustc_typeck/constrained_generic_params.rs @@ -180,7 +180,7 @@ pub fn setup_constraining_predicates<'tcx>( changed = false; for j in i..predicates.len() { - if let ty::PredicateKind::Projection(ref poly_projection) = predicates[j].0 { + if let ty::PredicateKind::Projection(ref poly_projection) = predicates[j].0.kind() { // Note that we can skip binder here because the impl // trait ref never contains any late-bound regions. let projection = poly_projection.skip_binder(); diff --git a/src/librustc_typeck/impl_wf_check/min_specialization.rs b/src/librustc_typeck/impl_wf_check/min_specialization.rs index 89d63107a9c29..d30dc1b7a475e 100644 --- a/src/librustc_typeck/impl_wf_check/min_specialization.rs +++ b/src/librustc_typeck/impl_wf_check/min_specialization.rs @@ -204,7 +204,7 @@ fn unconstrained_parent_impl_substs<'tcx>( // the functions in `cgp` add the constrained parameters to a list of // unconstrained parameters. for (predicate, _) in impl_generic_predicates.predicates.iter() { - if let ty::PredicateKind::Projection(proj) = predicate { + if let ty::PredicateKind::Projection(proj) = predicate.kind() { let projection_ty = proj.skip_binder().projection_ty; let projected_ty = proj.skip_binder().ty; @@ -368,7 +368,7 @@ fn check_predicates<'tcx>( fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: &ty::Predicate<'tcx>, span: Span) { debug!("can_specialize_on(predicate = {:?})", predicate); - match predicate { + match predicate.kind() { // Global predicates are either always true or always false, so we // are fine to specialize on. _ if predicate.is_global() => (), @@ -401,7 +401,7 @@ fn trait_predicate_kind<'tcx>( tcx: TyCtxt<'tcx>, predicate: &ty::Predicate<'tcx>, ) -> Option { - match predicate { + match predicate.kind() { ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => { Some(tcx.trait_def(pred.def_id()).specialization_kind) } diff --git a/src/librustc_typeck/outlives/explicit.rs b/src/librustc_typeck/outlives/explicit.rs index bc8d25f953820..5740cc224cc57 100644 --- a/src/librustc_typeck/outlives/explicit.rs +++ b/src/librustc_typeck/outlives/explicit.rs @@ -29,7 +29,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { // process predicates and convert to `RequiredPredicates` entry, see below for &(predicate, span) in predicates.predicates { - match predicate { + match predicate.kind() { ty::PredicateKind::TypeOutlives(predicate) => { let OutlivesPredicate(ref ty, ref reg) = predicate.skip_binder(); insert_outlives_predicate( diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index d88fda3550500..1b2b08a2e62ee 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -3,7 +3,7 @@ use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::GenericArgKind; -use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt}; +use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt}; use rustc_span::symbol::sym; use rustc_span::Span; @@ -30,7 +30,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate if tcx.has_attr(item_def_id, sym::rustc_outlives) { let mut pred: Vec = predicates .iter() - .map(|(out_pred, _)| match out_pred { + .map(|(out_pred, _)| match out_pred.kind() { ty::PredicateKind::RegionOutlives(p) => p.to_string(), ty::PredicateKind::TypeOutlives(p) => p.to_string(), err => bug!("unexpected predicate {:?}", err), @@ -82,22 +82,26 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica .iter() .map(|(&def_id, set)| { let predicates = &*tcx.arena.alloc_from_iter(set.iter().filter_map( - |(ty::OutlivesPredicate(kind1, region2), &span)| match kind1.unpack() { - GenericArgKind::Type(ty1) => Some(( - ty::PredicateKind::TypeOutlives(ty::Binder::bind(ty::OutlivesPredicate( - ty1, region2, - ))), - span, - )), - GenericArgKind::Lifetime(region1) => Some(( - ty::PredicateKind::RegionOutlives(ty::Binder::bind(ty::OutlivesPredicate( - region1, region2, - ))), - span, - )), - GenericArgKind::Const(_) => { - // Generic consts don't impose any constraints. - None + |(ty::OutlivesPredicate(kind1, region2), &span)| { + match kind1.unpack() { + GenericArgKind::Type(ty1) => Some(( + ty::PredicateKind::TypeOutlives(ty::Binder::bind( + ty::OutlivesPredicate(ty1, region2), + )) + .to_predicate(tcx), + span, + )), + GenericArgKind::Lifetime(region1) => Some(( + ty::PredicateKind::RegionOutlives(ty::Binder::bind( + ty::OutlivesPredicate(region1, region2), + )) + .to_predicate(tcx), + span, + )), + GenericArgKind::Const(_) => { + // Generic consts don't impose any constraints. + None + } } }, )); diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index ff05c4e583269..423160f3a9e01 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -315,7 +315,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { tcx: TyCtxt<'tcx>, pred: ty::Predicate<'tcx>, ) -> FxHashSet { - let regions = match pred { + let regions = match pred.kind() { ty::PredicateKind::Trait(poly_trait_pred, _) => { tcx.collect_referenced_late_bound_regions(&poly_trait_pred) } @@ -465,7 +465,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { .iter() .filter(|p| { !orig_bounds.contains(p) - || match p { + || match p.kind() { ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait, _ => false, } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 002af495ff226..cf1a39232bc78 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -481,7 +481,7 @@ impl Clean for hir::WherePredicate<'_> { impl<'a> Clean> for ty::Predicate<'a> { fn clean(&self, cx: &DocContext<'_>) -> Option { - match *self { + match self.kind() { ty::PredicateKind::Trait(ref pred, _) => Some(pred.clean(cx)), ty::PredicateKind::Subtype(ref pred) => Some(pred.clean(cx)), ty::PredicateKind::RegionOutlives(ref pred) => pred.clean(cx), @@ -763,7 +763,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, ty::GenericPredicates<'tcx if let ty::Param(param) = outlives.skip_binder().0.kind { return Some(param.index); } - } else if let ty::PredicateKind::Projection(p) = p { + } else if let ty::PredicateKind::Projection(p) = p.kind() { if let ty::Param(param) = p.skip_binder().projection_ty.self_ty().kind { projection = Some(p); return Some(param.index); @@ -1661,7 +1661,7 @@ impl<'tcx> Clean for Ty<'tcx> { .filter_map(|predicate| { let trait_ref = if let Some(tr) = predicate.to_opt_poly_trait_ref() { tr - } else if let ty::PredicateKind::TypeOutlives(pred) = *predicate { + } else if let ty::PredicateKind::TypeOutlives(pred) = predicate.kind() { // these should turn up at the end if let Some(r) = pred.skip_binder().1.clean(cx) { regions.push(GenericBound::Outlives(r)); @@ -1682,7 +1682,7 @@ impl<'tcx> Clean for Ty<'tcx> { .predicates .iter() .filter_map(|pred| { - if let ty::PredicateKind::Projection(proj) = *pred { + if let ty::PredicateKind::Projection(proj) = pred.kind() { let proj = proj.skip_binder(); if proj.projection_ty.trait_ref(cx.tcx) == *trait_ref.skip_binder() diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index cc91c50346180..37c613f41224a 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -141,7 +141,7 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) .predicates .iter() .filter_map(|(pred, _)| { - if let ty::PredicateKind::Trait(ref pred, _) = *pred { + if let ty::PredicateKind::Trait(ref pred, _) = pred.kind() { if pred.skip_binder().trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 2c2965433fd0e..0a02aa7533c17 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -91,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FutureNotSend { cx.tcx.infer_ctxt().enter(|infcx| { for FulfillmentError { obligation, .. } in send_errors { infcx.maybe_note_obligation_cause_for_async_await(db, &obligation); - if let Trait(trait_pred, _) = obligation.predicate { + if let Trait(trait_pred, _) = obligation.predicate.kind() { let trait_ref = trait_pred.to_poly_trait_ref(); db.note(&*format!( "`{}` doesn't implement `{}`", diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 79c21d9bc0a64..810a226b50d2a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -1496,8 +1496,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { if let ty::Opaque(def_id, _) = ret_ty.kind { // one of the associated types must be Self for predicate in cx.tcx.predicates_of(def_id).predicates { - match predicate { - (ty::PredicateKind::Projection(poly_projection_predicate), _) => { + match predicate.0.kind() { + ty::PredicateKind::Projection(poly_projection_predicate) => { let binder = poly_projection_predicate.ty(); let associated_type = binder.skip_binder(); @@ -1506,7 +1506,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { return; } }, - (_, _) => {}, + _ => {}, } } } diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index 8f94f143bae71..60c5360054334 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.iter().copied()) .filter(|p| !p.is_global()) .filter_map(|obligation| { - if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate { + if let ty::PredicateKind::Trait(poly_trait_ref, _) = obligation.predicate.kind() { if poly_trait_ref.def_id() == sized_trait || poly_trait_ref.skip_binder().has_escaping_bound_vars() { return None; diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs index 3f5693d7e6809..f22473275c466 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -1299,7 +1299,7 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { - if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate { + if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) = predicate.kind() { if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() { return true; } From 57746f943bef5720d97ad2cb413c54b0f432566b Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 11 May 2020 22:04:22 +0200 Subject: [PATCH 06/13] intern `PredicateKind` --- src/librustc_infer/traits/mod.rs | 2 +- src/librustc_middle/ty/context.rs | 23 +++++++++++++++---- src/librustc_middle/ty/mod.rs | 6 ++--- src/librustc_middle/ty/structural_impls.rs | 10 ++++++++ .../traits/fulfill.rs | 2 +- src/librustc_traits/type_op.rs | 6 ++--- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/librustc_infer/traits/mod.rs b/src/librustc_infer/traits/mod.rs index 8d95904b355da..892a62855a0a2 100644 --- a/src/librustc_infer/traits/mod.rs +++ b/src/librustc_infer/traits/mod.rs @@ -59,7 +59,7 @@ pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>; // `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(target_arch = "x86_64")] -static_assert_size!(PredicateObligation<'_>, 112); +static_assert_size!(PredicateObligation<'_>, 88); pub type Obligations<'tcx, O> = Vec>; pub type PredicateObligations<'tcx> = Vec>; diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index 4a9175d8c1838..7d192a44eaf2a 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -29,10 +29,9 @@ use crate::ty::{self, DefIdTree, Ty, TypeAndMut}; use crate::ty::{AdtDef, AdtKind, Const, Region}; use crate::ty::{BindingMode, BoundVar}; use crate::ty::{ConstVid, FloatVar, FloatVid, IntVar, IntVid, TyVar, TyVid}; -use crate::ty::{ - ExistentialPredicate, InferTy, ParamTy, PolyFnSig, Predicate, PredicateKind, ProjectionTy, -}; +use crate::ty::{ExistentialPredicate, Predicate, PredicateKind}; use crate::ty::{InferConst, ParamConst}; +use crate::ty::{InferTy, ParamTy, PolyFnSig, ProjectionTy}; use crate::ty::{List, TyKind, TyS}; use rustc_ast::ast; use rustc_ast::expand::allocator::AllocatorKind; @@ -91,6 +90,7 @@ pub struct CtxtInterners<'tcx> { canonical_var_infos: InternedSet<'tcx, List>, region: InternedSet<'tcx, RegionKind>, existential_predicates: InternedSet<'tcx, List>>, + predicate_kind: InternedSet<'tcx, PredicateKind<'tcx>>, predicates: InternedSet<'tcx, List>>, projs: InternedSet<'tcx, List>, place_elems: InternedSet<'tcx, List>>, @@ -109,6 +109,7 @@ impl<'tcx> CtxtInterners<'tcx> { region: Default::default(), existential_predicates: Default::default(), canonical_var_infos: Default::default(), + predicate_kind: Default::default(), predicates: Default::default(), projs: Default::default(), place_elems: Default::default(), @@ -1579,6 +1580,7 @@ macro_rules! nop_list_lift { nop_lift! {type_; Ty<'a> => Ty<'tcx>} nop_lift! {region; Region<'a> => Region<'tcx>} nop_lift! {const_; &'a Const<'a> => &'tcx Const<'tcx>} +nop_lift! {predicate_kind; &'a PredicateKind<'a> => &'tcx PredicateKind<'tcx>} nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>} nop_list_lift! {existential_predicates; ExistentialPredicate<'a> => ExistentialPredicate<'tcx>} @@ -2017,8 +2019,14 @@ impl<'tcx> Borrow<[traits::ChalkEnvironmentClause<'tcx>]> } } +impl<'tcx> Borrow> for Interned<'tcx, PredicateKind<'tcx>> { + fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> { + &self.0 + } +} + macro_rules! direct_interners { - ($($name:ident: $method:ident($ty:ty)),+) => { + ($($name:ident: $method:ident($ty:ty),)+) => { $(impl<'tcx> PartialEq for Interned<'tcx, $ty> { fn eq(&self, other: &Self) -> bool { self.0 == other.0 @@ -2043,7 +2051,11 @@ macro_rules! direct_interners { } } -direct_interners!(region: mk_region(RegionKind), const_: mk_const(Const<'tcx>)); +direct_interners!( + region: mk_region(RegionKind), + const_: mk_const(Const<'tcx>), + predicate_kind: intern_predicate_kind(PredicateKind<'tcx>), +); macro_rules! slice_interners { ($($field:ident: $method:ident($ty:ty)),+) => ( @@ -2107,6 +2119,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_predicate(&self, kind: PredicateKind<'tcx>) -> Predicate<'tcx> { + let kind = self.intern_predicate_kind(kind); Predicate { kind } } diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 3c4c4574bfd54..72c785074996b 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1017,14 +1017,14 @@ impl<'tcx> GenericPredicates<'tcx> { } #[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Lift)] -#[derive(HashStable, TypeFoldable)] +#[derive(HashStable)] pub struct Predicate<'tcx> { - kind: PredicateKind<'tcx>, + kind: &'tcx PredicateKind<'tcx>, } impl Predicate<'tcx> { pub fn kind(&self) -> PredicateKind<'tcx> { - self.kind + *self.kind } } diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index ca7cf97f4af34..babe0c54801e8 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -987,6 +987,16 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { } } +impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { + fn super_fold_with>(&self, folder: &mut F) -> Self { + folder.tcx().mk_predicate(ty::PredicateKind::super_fold_with(self.kind, folder)) + } + + fn super_visit_with>(&self, visitor: &mut V) -> bool { + ty::PredicateKind::super_visit_with(self.kind, visitor) + } +} + impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { fn super_fold_with>(&self, folder: &mut F) -> Self { fold_list(*self, folder, |tcx, v| tcx.intern_predicates(v)) diff --git a/src/librustc_trait_selection/traits/fulfill.rs b/src/librustc_trait_selection/traits/fulfill.rs index 88ff97e793af4..6f6430c100da9 100644 --- a/src/librustc_trait_selection/traits/fulfill.rs +++ b/src/librustc_trait_selection/traits/fulfill.rs @@ -83,7 +83,7 @@ pub struct PendingPredicateObligation<'tcx> { // `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(target_arch = "x86_64")] -static_assert_size!(PendingPredicateObligation<'_>, 136); +static_assert_size!(PendingPredicateObligation<'_>, 112); impl<'a, 'tcx> FulfillmentContext<'tcx> { /// Creates a new fulfillment context. diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index 2a338383c9a07..22077b49c3b77 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -6,10 +6,8 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::traits::TraitEngineExt as _; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts}; -use rustc_middle::ty::{ - self, FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, ToPredicate, Ty, TyCtxt, - TypeFoldable, Variance, -}; +use rustc_middle::ty::{self, FnSig, Lift, PolyFnSig, Ty, TyCtxt, TypeFoldable, Variance}; +use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Predicate, ToPredicate}; use rustc_span::DUMMY_SP; use rustc_trait_selection::infer::InferCtxtBuilderExt; use rustc_trait_selection::infer::InferCtxtExt; From 6544d7b6b1c06b1c5607118365fb992a39075b0c Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 11 May 2020 16:54:55 +0200 Subject: [PATCH 07/13] change `Predicate::kind` to return a reference --- src/librustc_infer/traits/util.rs | 18 +++++----- src/librustc_middle/ty/mod.rs | 33 ++++++++++--------- src/librustc_middle/ty/print/pretty.rs | 16 ++++----- .../transform/qualify_min_const_fn.rs | 2 +- .../traits/auto_trait.rs | 4 +-- .../traits/error_reporting/mod.rs | 4 +-- .../traits/fulfill.rs | 10 +++--- .../traits/project.rs | 12 +++---- src/librustc_trait_selection/traits/select.rs | 14 ++++---- src/librustc_trait_selection/traits/wf.rs | 12 +++---- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/coercion.rs | 2 +- src/librustc_typeck/check/dropck.rs | 4 +-- 13 files changed, 66 insertions(+), 67 deletions(-) diff --git a/src/librustc_infer/traits/util.rs b/src/librustc_infer/traits/util.rs index 3175ad6c5a44e..88fc1460475df 100644 --- a/src/librustc_infer/traits/util.rs +++ b/src/librustc_infer/traits/util.rs @@ -11,42 +11,42 @@ pub fn anonymize_predicate<'tcx>( pred: &ty::Predicate<'tcx>, ) -> ty::Predicate<'tcx> { match pred.kind() { - ty::PredicateKind::Trait(ref data, constness) => { + &ty::PredicateKind::Trait(ref data, constness) => { ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness) .to_predicate(tcx) } - ty::PredicateKind::RegionOutlives(ref data) => { + ty::PredicateKind::RegionOutlives(data) => { ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data)) .to_predicate(tcx) } - ty::PredicateKind::TypeOutlives(ref data) => { + ty::PredicateKind::TypeOutlives(data) => { ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data)) .to_predicate(tcx) } - ty::PredicateKind::Projection(ref data) => { + ty::PredicateKind::Projection(data) => { ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx) } - ty::PredicateKind::WellFormed(data) => { + &ty::PredicateKind::WellFormed(data) => { ty::PredicateKind::WellFormed(data).to_predicate(tcx) } - ty::PredicateKind::ObjectSafe(data) => { + &ty::PredicateKind::ObjectSafe(data) => { ty::PredicateKind::ObjectSafe(data).to_predicate(tcx) } - ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { + &ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind).to_predicate(tcx) } - ty::PredicateKind::Subtype(ref data) => { + ty::PredicateKind::Subtype(data) => { ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx) } - ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + &ty::PredicateKind::ConstEvaluatable(def_id, substs) => { ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(tcx) } diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 72c785074996b..6bb47a8f30e74 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1023,8 +1023,8 @@ pub struct Predicate<'tcx> { } impl Predicate<'tcx> { - pub fn kind(&self) -> PredicateKind<'tcx> { - *self.kind + pub fn kind(&self) -> &'tcx PredicateKind<'tcx> { + self.kind } } @@ -1163,35 +1163,36 @@ impl<'tcx> Predicate<'tcx> { // this trick achieves that). let substs = &trait_ref.skip_binder().substs; - match self.kind() { - PredicateKind::Trait(ref binder, constness) => { + let predicate = match self.kind() { + &PredicateKind::Trait(ref binder, constness) => { PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness) } - PredicateKind::Subtype(ref binder) => { + PredicateKind::Subtype(binder) => { PredicateKind::Subtype(binder.map_bound(|data| data.subst(tcx, substs))) } - PredicateKind::RegionOutlives(ref binder) => { + PredicateKind::RegionOutlives(binder) => { PredicateKind::RegionOutlives(binder.map_bound(|data| data.subst(tcx, substs))) } - PredicateKind::TypeOutlives(ref binder) => { + PredicateKind::TypeOutlives(binder) => { PredicateKind::TypeOutlives(binder.map_bound(|data| data.subst(tcx, substs))) } - PredicateKind::Projection(ref binder) => { + PredicateKind::Projection(binder) => { PredicateKind::Projection(binder.map_bound(|data| data.subst(tcx, substs))) } - PredicateKind::WellFormed(data) => PredicateKind::WellFormed(data.subst(tcx, substs)), - PredicateKind::ObjectSafe(trait_def_id) => PredicateKind::ObjectSafe(trait_def_id), - PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { + &PredicateKind::WellFormed(data) => PredicateKind::WellFormed(data.subst(tcx, substs)), + &PredicateKind::ObjectSafe(trait_def_id) => PredicateKind::ObjectSafe(trait_def_id), + &PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { PredicateKind::ClosureKind(closure_def_id, closure_substs.subst(tcx, substs), kind) } - PredicateKind::ConstEvaluatable(def_id, const_substs) => { + &PredicateKind::ConstEvaluatable(def_id, const_substs) => { PredicateKind::ConstEvaluatable(def_id, const_substs.subst(tcx, substs)) } PredicateKind::ConstEquate(c1, c2) => { PredicateKind::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs)) } - } - .to_predicate(tcx) + }; + + predicate.to_predicate(tcx) } } @@ -1370,7 +1371,7 @@ impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { impl<'tcx> Predicate<'tcx> { pub fn to_opt_poly_trait_ref(&self) -> Option> { match self.kind() { - PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()), + &PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()), PredicateKind::Projection(..) | PredicateKind::Subtype(..) | PredicateKind::RegionOutlives(..) @@ -1385,7 +1386,7 @@ impl<'tcx> Predicate<'tcx> { pub fn to_opt_type_outlives(&self) -> Option> { match self.kind() { - PredicateKind::TypeOutlives(data) => Some(data), + &PredicateKind::TypeOutlives(data) => Some(data), PredicateKind::Trait(..) | PredicateKind::Projection(..) | PredicateKind::Subtype(..) diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index 786fe55519e7b..f4b795e548867 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -2032,28 +2032,28 @@ define_print_and_forward_display! { ty::Predicate<'tcx> { match self.kind() { - ty::PredicateKind::Trait(ref data, constness) => { + &ty::PredicateKind::Trait(ref data, constness) => { if let hir::Constness::Const = constness { p!(write("const ")); } p!(print(data)) } - ty::PredicateKind::Subtype(ref predicate) => p!(print(predicate)), - ty::PredicateKind::RegionOutlives(ref predicate) => p!(print(predicate)), - ty::PredicateKind::TypeOutlives(ref predicate) => p!(print(predicate)), - ty::PredicateKind::Projection(ref predicate) => p!(print(predicate)), + ty::PredicateKind::Subtype(predicate) => p!(print(predicate)), + ty::PredicateKind::RegionOutlives(predicate) => p!(print(predicate)), + ty::PredicateKind::TypeOutlives(predicate) => p!(print(predicate)), + ty::PredicateKind::Projection(predicate) => p!(print(predicate)), ty::PredicateKind::WellFormed(ty) => p!(print(ty), write(" well-formed")), - ty::PredicateKind::ObjectSafe(trait_def_id) => { + &ty::PredicateKind::ObjectSafe(trait_def_id) => { p!(write("the trait `"), print_def_path(trait_def_id, &[]), write("` is object-safe")) } - ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => { + &ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => { p!(write("the closure `"), print_value_path(closure_def_id, &[]), write("` implements the trait `{}`", kind)) } - ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + &ty::PredicateKind::ConstEvaluatable(def_id, substs) => { p!(write("the constant `"), print_value_path(def_id, substs), write("` can be evaluated")) diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 55be4f55a569c..ead530bded861 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -39,7 +39,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) - ty::PredicateKind::Subtype(_) => { bug!("subtype predicate on function: {:#?}", predicate) } - ty::PredicateKind::Trait(pred, constness) => { + &ty::PredicateKind::Trait(pred, constness) => { if Some(pred.def_id()) == tcx.lang_items().sized_trait() { continue; } diff --git a/src/librustc_trait_selection/traits/auto_trait.rs b/src/librustc_trait_selection/traits/auto_trait.rs index bea4725226753..716cbce60dcc9 100644 --- a/src/librustc_trait_selection/traits/auto_trait.rs +++ b/src/librustc_trait_selection/traits/auto_trait.rs @@ -634,7 +634,7 @@ impl AutoTraitFinder<'tcx> { // We check this by calling is_of_param on the relevant types // from the various possible predicates match predicate.kind() { - ty::PredicateKind::Trait(p, _) => { + &ty::PredicateKind::Trait(p, _) => { if self.is_param_no_infer(p.skip_binder().trait_ref.substs) && !only_projections && is_new_pred @@ -643,7 +643,7 @@ impl AutoTraitFinder<'tcx> { } predicates.push_back(p); } - ty::PredicateKind::Projection(p) => { + &ty::PredicateKind::Projection(p) => { debug!( "evaluate_nested_obligations: examining projection predicate {:?}", predicate diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index f85735064c838..2aef8aaf0e303 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -524,12 +524,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ) } - ty::PredicateKind::ObjectSafe(trait_def_id) => { + &ty::PredicateKind::ObjectSafe(trait_def_id) => { let violations = self.tcx.object_safety_violations(trait_def_id); report_object_safety_error(self.tcx, span, trait_def_id, violations) } - ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { + &ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { let found_kind = self.closure_kind(closure_substs).unwrap(); let closure_span = self.tcx.sess.source_map().guess_head_span( diff --git a/src/librustc_trait_selection/traits/fulfill.rs b/src/librustc_trait_selection/traits/fulfill.rs index 6f6430c100da9..e44163f7bb1a4 100644 --- a/src/librustc_trait_selection/traits/fulfill.rs +++ b/src/librustc_trait_selection/traits/fulfill.rs @@ -443,7 +443,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateKind::ObjectSafe(trait_def_id) => { + &ty::PredicateKind::ObjectSafe(trait_def_id) => { if !self.selcx.tcx().is_object_safe(trait_def_id) { ProcessResult::Error(CodeSelectionError(Unimplemented)) } else { @@ -451,7 +451,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateKind::ClosureKind(_, closure_substs, kind) => { + &ty::PredicateKind::ClosureKind(_, closure_substs, kind) => { match self.selcx.infcx().closure_kind(closure_substs) { Some(closure_kind) => { if closure_kind.extends(kind) { @@ -464,7 +464,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateKind::WellFormed(ty) => { + &ty::PredicateKind::WellFormed(ty) => { match wf::obligations( self.selcx.infcx(), obligation.param_env, @@ -481,7 +481,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateKind::Subtype(ref subtype) => { + ty::PredicateKind::Subtype(subtype) => { match self.selcx.infcx().subtype_predicate( &obligation.cause, obligation.param_env, @@ -510,7 +510,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { } } - ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + &ty::PredicateKind::ConstEvaluatable(def_id, substs) => { match self.selcx.infcx().const_eval_resolve( obligation.param_env, def_id, diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index bcf28cb29cb85..7b72cf15da4d8 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -930,7 +930,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>( let infcx = selcx.infcx(); for predicate in env_predicates { debug!("assemble_candidates_from_predicates: predicate={:?}", predicate); - if let ty::PredicateKind::Projection(data) = predicate.kind() { + if let &ty::PredicateKind::Projection(data) = predicate.kind() { let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id; let is_match = same_def_id @@ -1167,12 +1167,10 @@ fn confirm_object_candidate<'cx, 'tcx>( // select only those projections that are actually projecting an // item with the correct name let env_predicates = env_predicates.filter_map(|o| match o.predicate.kind() { - ty::PredicateKind::Projection(data) => { - if data.projection_def_id() == obligation.predicate.item_def_id { - Some(data) - } else { - None - } + &ty::PredicateKind::Projection(data) + if data.projection_def_id() == obligation.predicate.item_def_id => + { + Some(data) } _ => None, }); diff --git a/src/librustc_trait_selection/traits/select.rs b/src/librustc_trait_selection/traits/select.rs index 59d85281d633b..0574da38f56bf 100644 --- a/src/librustc_trait_selection/traits/select.rs +++ b/src/librustc_trait_selection/traits/select.rs @@ -414,13 +414,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } match obligation.predicate.kind() { - ty::PredicateKind::Trait(ref t, _) => { + ty::PredicateKind::Trait(t, _) => { debug_assert!(!t.has_escaping_bound_vars()); let obligation = obligation.with(*t); self.evaluate_trait_predicate_recursively(previous_stack, obligation) } - ty::PredicateKind::Subtype(ref p) => { + ty::PredicateKind::Subtype(p) => { // Does this code ever run? match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) { Some(Ok(InferOk { mut obligations, .. })) => { @@ -435,7 +435,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateKind::WellFormed(ty) => match wf::obligations( + &ty::PredicateKind::WellFormed(ty) => match wf::obligations( self.infcx, obligation.param_env, obligation.cause.body_id, @@ -454,7 +454,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { Ok(EvaluatedToOkModuloRegions) } - ty::PredicateKind::ObjectSafe(trait_def_id) => { + &ty::PredicateKind::ObjectSafe(trait_def_id) => { if self.tcx().is_object_safe(trait_def_id) { Ok(EvaluatedToOk) } else { @@ -462,7 +462,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateKind::Projection(ref data) => { + ty::PredicateKind::Projection(data) => { let project_obligation = obligation.with(*data); match project::poly_project_and_unify_type(self, &project_obligation) { Ok(Some(mut subobligations)) => { @@ -483,7 +483,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateKind::ClosureKind(_, closure_substs, kind) => { + &ty::PredicateKind::ClosureKind(_, closure_substs, kind) => { match self.infcx.closure_kind(closure_substs) { Some(closure_kind) => { if closure_kind.extends(kind) { @@ -496,7 +496,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + &ty::PredicateKind::ConstEvaluatable(def_id, substs) => { match self.tcx().const_eval_resolve( obligation.param_env, def_id, diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index 1d89ba4efe0ac..5118859765ed7 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -73,28 +73,28 @@ pub fn predicate_obligations<'a, 'tcx>( // (*) ok to skip binders, because wf code is prepared for it match predicate.kind() { - ty::PredicateKind::Trait(ref t, _) => { + ty::PredicateKind::Trait(t, _) => { wf.compute_trait_ref(&t.skip_binder().trait_ref, Elaborate::None); // (*) } ty::PredicateKind::RegionOutlives(..) => {} - ty::PredicateKind::TypeOutlives(ref t) => { + ty::PredicateKind::TypeOutlives(t) => { wf.compute(t.skip_binder().0); } - ty::PredicateKind::Projection(ref t) => { + ty::PredicateKind::Projection(t) => { let t = t.skip_binder(); // (*) wf.compute_projection(t.projection_ty); wf.compute(t.ty); } - ty::PredicateKind::WellFormed(t) => { + &ty::PredicateKind::WellFormed(t) => { wf.compute(t); } ty::PredicateKind::ObjectSafe(_) => {} ty::PredicateKind::ClosureKind(..) => {} - ty::PredicateKind::Subtype(ref data) => { + ty::PredicateKind::Subtype(data) => { wf.compute(data.skip_binder().a); // (*) wf.compute(data.skip_binder().b); // (*) } - ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + &ty::PredicateKind::ConstEvaluatable(def_id, substs) => { let obligations = wf.nominal_obligations(def_id, substs); wf.out.extend(obligations); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 3526a1b59f384..9a5fe9552d35a 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1605,7 +1605,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .map(|item| item.def_id), ); } - ty::PredicateKind::Projection(pred) => { + &ty::PredicateKind::Projection(pred) => { // A `Self` within the original bound will be substituted with a // `trait_object_dummy_self`, so check for that. let references_self = diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 705bace4a9ccc..2a1c6b895ce20 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -597,7 +597,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let obligation = queue.remove(0); debug!("coerce_unsized resolve step: {:?}", obligation); let trait_pred = match obligation.predicate.kind() { - ty::PredicateKind::Trait(trait_pred, _) + &ty::PredicateKind::Trait(trait_pred, _) if traits.contains(&trait_pred.def_id()) => { if unsize_did == trait_pred.def_id() { diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 3843b97f23d41..594cdab852fda 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -232,10 +232,10 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env); match (predicate.kind(), p.kind()) { (ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => { - relator.relate(&a, &b).is_ok() + relator.relate(a, b).is_ok() } (ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => { - relator.relate(&a, &b).is_ok() + relator.relate(a, b).is_ok() } _ => predicate == p, } From 3dd830b70ccb2d6937857e07470a5c15dd574ddd Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 11 May 2020 20:23:15 +0200 Subject: [PATCH 08/13] ptr eq for `Predicate` --- src/librustc_middle/ty/mod.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 6bb47a8f30e74..9e8456689094f 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1016,14 +1016,23 @@ impl<'tcx> GenericPredicates<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Lift)] +#[derive(Clone, Copy, Hash, RustcEncodable, RustcDecodable, Lift)] #[derive(HashStable)] pub struct Predicate<'tcx> { kind: &'tcx PredicateKind<'tcx>, } -impl Predicate<'tcx> { - pub fn kind(&self) -> &'tcx PredicateKind<'tcx> { +impl<'tcx> PartialEq for Predicate<'tcx> { + fn eq(&self, other: &Self) -> bool { + // `self.kind` is always interned. + ptr::eq(self.kind, other.kind) + } +} + +impl<'tcx> Eq for Predicate<'tcx> {} + +impl<'tcx> Predicate<'tcx> { + pub fn kind(self) -> &'tcx PredicateKind<'tcx> { self.kind } } @@ -1098,7 +1107,7 @@ impl<'tcx> Predicate<'tcx> { /// substitution in terms of what happens with bound regions. See /// lengthy comment below for details. pub fn subst_supertrait( - &self, + self, tcx: TyCtxt<'tcx>, trait_ref: &ty::PolyTraitRef<'tcx>, ) -> ty::Predicate<'tcx> { @@ -1369,7 +1378,7 @@ impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> { } impl<'tcx> Predicate<'tcx> { - pub fn to_opt_poly_trait_ref(&self) -> Option> { + pub fn to_opt_poly_trait_ref(self) -> Option> { match self.kind() { &PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()), PredicateKind::Projection(..) @@ -1384,7 +1393,7 @@ impl<'tcx> Predicate<'tcx> { } } - pub fn to_opt_type_outlives(&self) -> Option> { + pub fn to_opt_type_outlives(self) -> Option> { match self.kind() { &PredicateKind::TypeOutlives(data) => Some(data), PredicateKind::Trait(..) From 6778c7a7c147385fc8a95ead842844b005409301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Wed, 20 May 2020 00:00:00 +0000 Subject: [PATCH 09/13] Show default values for debug-assertions & debug-assertions-std --- config.toml.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.toml.example b/config.toml.example index ffe907c9da97c..cf8fe4e082ac3 100644 --- a/config.toml.example +++ b/config.toml.example @@ -312,11 +312,11 @@ # Whether or not debug assertions are enabled for the compiler and standard # library. -#debug-assertions = false +#debug-assertions = debug # Whether or not debug assertions are enabled for the standard library. # Overrides the `debug-assertions` option, if defined. -#debug-assertions-std = false +#debug-assertions-std = debug-assertions # Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`. # `0` - no debug info From 20b499c60a5778b9ad00c807fe33d225c36c095e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 21 May 2020 12:22:03 +0200 Subject: [PATCH 10/13] Fix anchor display when hovering impl --- src/librustdoc/html/static/rustdoc.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index ab52475172333..2cb3347135c1b 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -625,7 +625,7 @@ a { display: initial; } -.in-band:hover > .anchor { +.in-band:hover > .anchor, .impl:hover > .anchor { display: inline-block; position: absolute; } From 94aa02855defad20fe63d46a5df9506e82b78ff3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 21 May 2020 16:30:27 +0200 Subject: [PATCH 11/13] fix discriminant sign extension --- src/librustc_mir/interpret/intrinsics.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index 42b969c99917f..fc4be82ad90ad 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -219,7 +219,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let place = self.deref_operand(args[0])?; let discr_val = self.read_discriminant(place.into())?.0; let scalar = match dest.layout.ty.kind { - ty::Int(_) => Scalar::from_int(discr_val as i128, dest.layout.size), + ty::Int(_) => Scalar::from_int( + self.sign_extend(discr_val, dest.layout) as i128, + dest.layout.size, + ), ty::Uint(_) => Scalar::from_uint(discr_val, dest.layout.size), _ => bug!("invalid `discriminant_value` return layout: {:?}", dest.layout), }; From a81e9a781b19153d19898c421c80d713dc739d8e Mon Sep 17 00:00:00 2001 From: Daniel Henry-Mantilla Date: Tue, 19 May 2020 15:37:06 +0200 Subject: [PATCH 12/13] Improve documentation of `slice::from_raw_parts` This is to provide a more explicit statement against a code pattern that many people end up coming with, since the reason of it being unsound comes from the badly known single-allocation validity rule. Providing that very pattern as a counter-example could help mitigate that. Co-authored-by: Ralf Jung --- src/libcore/slice/mod.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 9582ac33ff6b7..2e1dd89433d9e 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -5740,7 +5740,8 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunksExactMut<'a, T> { /// and it must be properly aligned. This means in particular: /// /// * The entire memory range of this slice must be contained within a single allocated object! -/// Slices can never span across multiple allocated objects. +/// Slices can never span across multiple allocated objects. See [below](#incorrect-usage) +/// for an example incorrectly not taking this into account. /// * `data` must be non-null and aligned even for zero-length slices. One /// reason for this is that enum layout optimizations may rely on references /// (including slices of any length) being aligned and non-null to distinguish @@ -5773,6 +5774,34 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunksExactMut<'a, T> { /// assert_eq!(slice[0], 42); /// ``` /// +/// ### Incorrect usage +/// +/// The following `join_slices` function is **unsound** ⚠️ +/// +/// ```rust,no_run +/// use std::slice; +/// +/// fn join_slices<'a, T>(fst: &'a [T], snd: &'a [T]) -> &'a [T] { +/// let fst_end = fst.as_ptr().wrapping_add(fst.len()); +/// let snd_start = snd.as_ptr(); +/// assert_eq!(fst_end, snd_start, "Slices must be contiguous!"); +/// unsafe { +/// // The assertion above ensures `fst` and `snd` are contiguous, but they might +/// // still be contained within _different allocated objects_, in which case +/// // creating this slice is undefined behavior. +/// slice::from_raw_parts(fst.as_ptr(), fst.len() + snd.len()) +/// } +/// } +/// +/// fn main() { +/// // `a` and `b` are different allocated objects... +/// let a = 42; +/// let b = 27; +/// // ... which may nevertheless be laid out contiguous in memory: | a | b | +/// let _ = join_slices(slice::from_ref(&a), slice::from_ref(&b)); // UB +/// } +/// ``` +/// /// [valid]: ../../std/ptr/index.html#safety /// [`NonNull::dangling()`]: ../../std/ptr/struct.NonNull.html#method.dangling /// [`pointer::offset`]: ../../std/primitive.pointer.html#method.offset From 67e075589b7e19a87130a700b7e59015a1b80f11 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 21 May 2020 19:07:59 +0200 Subject: [PATCH 13/13] Typo --- src/libcore/slice/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 2e1dd89433d9e..b5ce165cb43db 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -5797,7 +5797,7 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunksExactMut<'a, T> { /// // `a` and `b` are different allocated objects... /// let a = 42; /// let b = 27; -/// // ... which may nevertheless be laid out contiguous in memory: | a | b | +/// // ... which may nevertheless be laid out contiguously in memory: | a | b | /// let _ = join_slices(slice::from_ref(&a), slice::from_ref(&b)); // UB /// } /// ```