From 2d603a2931c8f512ef1e7f8dc7360470e223eacd Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 13 Oct 2021 12:39:12 +0900 Subject: [PATCH 1/8] Rustup to rust-lang/rust#87375 --- README.md | 8 ++++---- rust-toolchain | 2 +- src/translate.rs | 4 ++-- src/traverse.rs | 2 +- src/typeck.rs | 10 ++++------ 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3437b87b..f2e9baa7 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ repository and compiled from source or installed from of the nightly toolchain is supported at any given time. -It's recommended to use `nightly-2021-07-23` toolchain. -You can install it by using `rustup install nightly-2021-07-23` if you already have rustup. +It's recommended to use `nightly-2021-08-16` toolchain. +You can install it by using `rustup install nightly-2021-08-16` if you already have rustup. Then you can do: ```sh -$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-07-23 -$ cargo +nightly-2021-07-23 install --git https://github.com/rust-lang/rust-semverver +$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-08-16 +$ cargo +nightly-2021-08-16 install --git https://github.com/rust-lang/rust-semverver ``` You'd also need `cmake` for some dependencies, and a few common libraries (if you hit diff --git a/rust-toolchain b/rust-toolchain index 13425aba..c292c946 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ # NOTE: Keep in sync with nightly date on README [toolchain] -channel = "nightly-2021-07-23" +channel = "nightly-2021-08-16" components = ["llvm-tools-preview", "rustc-dev"] diff --git a/src/translate.rs b/src/translate.rs index d8797395..fcda0e85 100644 --- a/src/translate.rs +++ b/src/translate.rs @@ -382,7 +382,7 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { Some( match predicate.kind().skip_binder() { - PredicateKind::Trait(pred, constness) => PredicateKind::Trait( + PredicateKind::Trait(pred) => PredicateKind::Trait( if let Some((target_def_id, target_substs)) = self.translate_orig_substs( index_map, pred.trait_ref.def_id, @@ -393,11 +393,11 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { def_id: target_def_id, substs: target_substs, }, + constness: pred.constness, } } else { return None; }, - constness, ), PredicateKind::RegionOutlives(pred) => PredicateKind::RegionOutlives({ let l = self.translate_region(pred.0); diff --git a/src/traverse.rs b/src/traverse.rs index 48455901..f09f7dee 100644 --- a/src/traverse.rs +++ b/src/traverse.rs @@ -590,7 +590,7 @@ fn diff_traits<'tcx>( let old_param_env = tcx.param_env(old); for bound in old_param_env.caller_bounds() { - if let PredicateKind::Trait(pred, _) = bound.kind().skip_binder() { + if let PredicateKind::Trait(pred) = bound.kind().skip_binder() { let trait_ref = pred.trait_ref; debug!("trait_ref substs (old): {:?}", trait_ref.substs); diff --git a/src/typeck.rs b/src/typeck.rs index 281485a4..5f0dfbb4 100644 --- a/src/typeck.rs +++ b/src/typeck.rs @@ -75,12 +75,10 @@ impl<'a, 'tcx> BoundContext<'a, 'tcx> { use rustc_hir::Constness; use rustc_middle::ty::{ToPredicate, TraitPredicate}; - let predicate = PredicateKind::Trait( - TraitPredicate { - trait_ref: checked_trait_ref, - }, - Constness::NotConst, - ) + let predicate = PredicateKind::Trait(TraitPredicate { + trait_ref: checked_trait_ref, + constness: Constness::NotConst, + }) .to_predicate(self.infcx.tcx); let obligation = Obligation::new(ObligationCause::dummy(), self.given_param_env, predicate); self.fulfill_cx From 523a3c75f8bd94a77cc17fcfa2f595386ef1169f Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 13 Oct 2021 12:59:51 +0900 Subject: [PATCH 2/8] Rustup to rust-lang/rust#88149 and rust-lang/rust#87280 --- README.md | 8 ++++---- rust-toolchain | 2 +- src/translate.rs | 20 ++++++++++++++------ src/typeck.rs | 5 ++--- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f2e9baa7..cbe156e0 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ repository and compiled from source or installed from of the nightly toolchain is supported at any given time. -It's recommended to use `nightly-2021-08-16` toolchain. -You can install it by using `rustup install nightly-2021-08-16` if you already have rustup. +It's recommended to use `nightly-2021-08-31` toolchain. +You can install it by using `rustup install nightly-2021-08-31` if you already have rustup. Then you can do: ```sh -$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-08-16 -$ cargo +nightly-2021-08-16 install --git https://github.com/rust-lang/rust-semverver +$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-08-31 +$ cargo +nightly-2021-08-31 install --git https://github.com/rust-lang/rust-semverver ``` You'd also need `cmake` for some dependencies, and a few common libraries (if you hit diff --git a/rust-toolchain b/rust-toolchain index c292c946..63050498 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ # NOTE: Keep in sync with nightly date on README [toolchain] -channel = "nightly-2021-08-16" +channel = "nightly-2021-08-31" components = ["llvm-tools-preview", "rustc-dev"] diff --git a/src/translate.rs b/src/translate.rs index fcda0e85..4c7610cd 100644 --- a/src/translate.rs +++ b/src/translate.rs @@ -8,7 +8,7 @@ use rustc_infer::infer::InferCtxt; use rustc_middle::ty::{ fold::{BottomUpFolder, TypeFoldable, TypeFolder}, subst::{GenericArg, InternalSubsts, SubstsRef}, - GenericParamDefKind, ParamEnv, Predicate, Region, TraitRef, Ty, TyCtxt, + GenericParamDefKind, ParamEnv, Predicate, Region, TraitRef, Ty, TyCtxt, Unevaluated, }; use std::collections::HashMap; @@ -376,8 +376,8 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { predicate: Predicate<'tcx>, ) -> Option> { use rustc_middle::ty::{ - OutlivesPredicate, PredicateKind, ProjectionPredicate, ProjectionTy, SubtypePredicate, - ToPredicate, TraitPredicate, WithOptConstParam, + CoercePredicate, OutlivesPredicate, PredicateKind, ProjectionPredicate, ProjectionTy, + SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam, }; Some( @@ -446,14 +446,22 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { b: r, } }), - PredicateKind::ConstEvaluatable(param, orig_substs) => { + PredicateKind::Coerce(pred) => PredicateKind::Coerce({ + let a = self.translate(index_map, pred.a); + let b = self.translate(index_map, pred.b); + CoercePredicate { a, b } + }), + PredicateKind::ConstEvaluatable(uv) => { if let Some((target_def_id, target_substs)) = - self.translate_orig_substs(index_map, param.did, orig_substs) + self.translate_orig_substs(index_map, uv.def.did, uv.substs(self.tcx)) { // TODO: We could probably use translated version for // `WithOptConstParam::const_param_did` let const_param = WithOptConstParam::unknown(target_def_id); - PredicateKind::ConstEvaluatable(const_param, target_substs) + PredicateKind::ConstEvaluatable(Unevaluated::new( + const_param, + target_substs, + )) } else { return None; } diff --git a/src/typeck.rs b/src/typeck.rs index 5f0dfbb4..bda964f2 100644 --- a/src/typeck.rs +++ b/src/typeck.rs @@ -72,12 +72,11 @@ impl<'a, 'tcx> BoundContext<'a, 'tcx> { /// Register the trait bound represented by a `TraitRef`. pub fn register_trait_ref(&mut self, checked_trait_ref: TraitRef<'tcx>) { - use rustc_hir::Constness; - use rustc_middle::ty::{ToPredicate, TraitPredicate}; + use rustc_middle::ty::{BoundConstness, ToPredicate, TraitPredicate}; let predicate = PredicateKind::Trait(TraitPredicate { trait_ref: checked_trait_ref, - constness: Constness::NotConst, + constness: BoundConstness::NotConst, }) .to_predicate(self.infcx.tcx); let obligation = Obligation::new(ObligationCause::dummy(), self.given_param_env, predicate); From c4b870222de8019859ebb642870c1c3c4fde95fb Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 13 Oct 2021 13:05:24 +0900 Subject: [PATCH 3/8] Rustup to rust-lang/rust#80522 --- README.md | 8 ++++---- rust-toolchain | 2 +- src/lib.rs | 4 ++-- src/traverse.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cbe156e0..2739175c 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ repository and compiled from source or installed from of the nightly toolchain is supported at any given time. -It's recommended to use `nightly-2021-08-31` toolchain. -You can install it by using `rustup install nightly-2021-08-31` if you already have rustup. +It's recommended to use `nightly-2021-09-10` toolchain. +You can install it by using `rustup install nightly-2021-09-10` if you already have rustup. Then you can do: ```sh -$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-08-31 -$ cargo +nightly-2021-08-31 install --git https://github.com/rust-lang/rust-semverver +$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-09-10 +$ cargo +nightly-2021-09-10 install --git https://github.com/rust-lang/rust-semverver ``` You'd also need `cmake` for some dependencies, and a few common libraries (if you hit diff --git a/rust-toolchain b/rust-toolchain index 63050498..544711cd 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ # NOTE: Keep in sync with nightly date on README [toolchain] -channel = "nightly-2021-08-31" +channel = "nightly-2021-09-10" components = ["llvm-tools-preview", "rustc-dev"] diff --git a/src/lib.rs b/src/lib.rs index 619d7d08..2a283e8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,10 +7,10 @@ #![allow(clippy::unnested_or_patterns)] #![deny(warnings)] -extern crate rustc_hir; // Requires `rustup component add rustc-dev` +extern crate rustc_const_eval; // Requires `rustup component add rustc-dev` +extern crate rustc_hir; extern crate rustc_infer; extern crate rustc_middle; -extern crate rustc_mir; extern crate rustc_session; extern crate rustc_span; extern crate rustc_trait_selection; diff --git a/src/traverse.rs b/src/traverse.rs index f09f7dee..14c951c6 100644 --- a/src/traverse.rs +++ b/src/traverse.rs @@ -17,6 +17,7 @@ use crate::{ typeck::{BoundContext, TypeComparisonContext}, }; use log::{debug, info}; +use rustc_const_eval::const_eval::is_const_fn; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res, Res::Def}; use rustc_hir::def_id::DefId; use rustc_hir::hir_id::HirId; @@ -31,7 +32,6 @@ use rustc_middle::{ Visibility::Public, }, }; -use rustc_mir::const_eval::is_const_fn; use std::collections::{BTreeMap, HashSet, VecDeque}; /// The main entry point to our analysis passes. From 7dbee3c6c3a1ba72f3532996863a38834ba72953 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 15 Oct 2021 10:30:14 +0900 Subject: [PATCH 4/8] Rustup to rust-lang/rust#84373, rust-lang/rust#87867, and rust-lang/rust#88677 --- README.md | 8 ++++---- rust-toolchain | 2 +- src/changes.rs | 24 ++++++++++++------------ src/mapping.rs | 12 +++++------- src/traverse.rs | 27 ++++++++++++++------------- 5 files changed, 36 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 2739175c..b48b37c6 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ repository and compiled from source or installed from of the nightly toolchain is supported at any given time. -It's recommended to use `nightly-2021-09-10` toolchain. -You can install it by using `rustup install nightly-2021-09-10` if you already have rustup. +It's recommended to use `nightly-2021-09-20` toolchain. +You can install it by using `rustup install nightly-2021-09-20` if you already have rustup. Then you can do: ```sh -$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-09-10 -$ cargo +nightly-2021-09-10 install --git https://github.com/rust-lang/rust-semverver +$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-09-20 +$ cargo +nightly-2021-09-20 install --git https://github.com/rust-lang/rust-semverver ``` You'd also need `cmake` for some dependencies, and a few common libraries (if you hit diff --git a/rust-toolchain b/rust-toolchain index 544711cd..a52f4999 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ # NOTE: Keep in sync with nightly date on README [toolchain] -channel = "nightly-2021-09-10" +channel = "nightly-2021-09-20" components = ["llvm-tools-preview", "rustc-dev"] diff --git a/src/changes.rs b/src/changes.rs index 3e83cada..55f15889 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -1230,7 +1230,7 @@ pub mod tests { use std::cmp::{max, min}; use rustc_span::hygiene::SyntaxContext; - use rustc_span::symbol::Interner; + use rustc_span::symbol::sym; use rustc_span::BytePos; /// A wrapper for `Span` that can be randomly generated. @@ -1239,7 +1239,12 @@ pub mod tests { impl Span_ { pub fn inner(self) -> Span { - Span::new(BytePos(self.0), BytePos(self.1), SyntaxContext::root()) + Span::new( + BytePos(self.0), + BytePos(self.1), + SyntaxContext::root(), + None, + ) } } @@ -1460,8 +1465,7 @@ pub mod tests { output: bool, changes: Vec<(ChangeType_, Option)>, ) -> Change<'a> { - let mut interner = Interner::default(); - let mut change = Change::new(Name::Symbol(RSymbol(interner.intern("test"))), s1, output); + let mut change = Change::new(Name::Symbol(RSymbol(sym::test)), s1, output); for (type_, span) in changes { change.insert(type_.inner(), span.map(|s| s.inner())); @@ -1475,8 +1479,7 @@ pub mod tests { /// Construct `PathChange`s from things that can be generated. fn build_path_change(s1: Span, spans: Vec<(bool, Span)>) -> PathChange { - let mut interner = Interner::default(); - let mut change = PathChange::new(interner.intern("test"), s1); + let mut change = PathChange::new(sym::test, s1); for (add, span) in spans { change.insert(span, add); @@ -1546,8 +1549,7 @@ pub mod tests { rustc_span::create_default_session_globals_then(|| { let mut set = ChangeSet::default(); - let mut interner = Interner::default(); - let name = interner.intern("test"); + let name = sym::test; let max = changes .iter() @@ -1579,8 +1581,7 @@ pub mod tests { rustc_span::create_default_session_globals_then(|| { let mut set = ChangeSet::default(); - let mut interner = Interner::default(); - let name = interner.intern("test"); + let name = sym::test; let max = changes .iter() @@ -1614,8 +1615,7 @@ pub mod tests { rustc_span::create_default_session_globals_then(|| { let mut set = ChangeSet::default(); - let mut interner = Interner::default(); - let name = interner.intern("test"); + let name = sym::test; let max = pchanges .iter() diff --git a/src/mapping.rs b/src/mapping.rs index 1a3b1283..6830b47f 100644 --- a/src/mapping.rs +++ b/src/mapping.rs @@ -325,7 +325,7 @@ impl IdMapping { } /// An export that could be missing from one of the crate versions. -type OptionalExport = Option>; +type OptionalExport = Option; /// A mapping from names to pairs of old and new exports. /// @@ -343,11 +343,11 @@ pub struct NameMapping { impl NameMapping { /// Insert a single export in the appropriate map, at the appropriate position. - fn insert(&mut self, item: Export, old: bool) { + fn insert(&mut self, item: Export, old: bool) { use rustc_hir::def::DefKind::*; use rustc_hir::def::Res::*; - let map = match item.res { + let map = match item.res.expect_non_local::() { Def(kind, _) => match kind { Mod | Struct | @@ -396,7 +396,7 @@ impl NameMapping { } /// Add all items from two vectors of old/new exports. - pub fn add(&mut self, old_items: Vec>, new_items: Vec>) { + pub fn add(&mut self, old_items: Vec, new_items: Vec) { for item in old_items { self.insert(item, true); } @@ -407,9 +407,7 @@ impl NameMapping { } /// Drain the item pairs being stored. - pub fn drain( - &mut self, - ) -> impl Iterator>, Option>)> + '_ { + pub fn drain(&mut self) -> impl Iterator, Option)> + '_ { self.type_map .drain() .chain(self.value_map.drain()) diff --git a/src/traverse.rs b/src/traverse.rs index 14c951c6..2cc67961 100644 --- a/src/traverse.rs +++ b/src/traverse.rs @@ -68,7 +68,7 @@ pub fn run_analysis(tcx: TyCtxt, old: DefId, new: DefId) -> ChangeSet { } // Get the visibility of the inner item, given the outer item's visibility. -fn get_vis(outer_vis: Visibility, def: Export) -> Visibility { +fn get_vis(outer_vis: Visibility, def: Export) -> Visibility { if outer_vis == Public { def.vis } else { @@ -156,7 +156,8 @@ fn diff_structure<'tcx>( match items { // an item pair is found (Some(o), Some(n)) => { - if let (Def(Mod, o_def_id), Def(Mod, n_def_id)) = (o.res, n.res) { + let (o_res, n_res) = (o.res.expect_non_local(), n.res.expect_non_local()); + if let (Def(Mod, o_def_id), Def(Mod, n_def_id)) = (o_res, n_res) { if visited.insert((o_def_id, n_def_id)) { let o_vis = get_vis(old_vis, o); let n_vis = get_vis(new_vis, n); @@ -182,16 +183,16 @@ fn diff_structure<'tcx>( mod_queue.push_back((o_def_id, n_def_id, o_vis, n_vis)); } - } else if id_mapping.add_export(o.res, n.res) { + } else if id_mapping.add_export(o_res, n_res) { // struct constructors are weird/hard - let's go shopping! if let (Def(Ctor(CtorOf::Struct, _), _), Def(Ctor(CtorOf::Struct, _), _)) = - (o.res, n.res) + (o_res, n_res) { continue; } - let o_def_id = o.res.def_id(); - let n_def_id = n.res.def_id(); + let o_def_id = o_res.def_id(); + let n_def_id = n_res.def_id(); let o_vis = get_vis(old_vis, o); let n_vis = get_vis(new_vis, n); @@ -211,7 +212,7 @@ fn diff_structure<'tcx>( changes.add_change(ChangeType::ItemMadePublic, o_def_id, None); } - let (o_kind, n_kind) = match (o.res, n.res) { + let (o_kind, n_kind) = match (o_res, n_res) { (Res::Def(o_kind, _), Res::Def(n_kind, _)) => (o_kind, n_kind), _ => { // a non-matching item pair (seriously broken though) - @@ -257,7 +258,7 @@ fn diff_structure<'tcx>( // that need to be compared (Fn, Fn) => { diff_generics(changes, id_mapping, tcx, true, o_def_id, n_def_id); - diff_fn(changes, tcx, o.res, n.res); + diff_fn(changes, tcx, o_res, n_res); } // type aliases can declare generics, too (TyAlias, TyAlias) => { @@ -268,7 +269,7 @@ fn diff_structure<'tcx>( // fields (Struct, Struct) | (Union, Union) | (Enum, Enum) => { diff_generics(changes, id_mapping, tcx, false, o_def_id, n_def_id); - diff_adts(changes, id_mapping, tcx, o.res, n.res); + diff_adts(changes, id_mapping, tcx, o_res, n_res); } // trait definitions can declare generics and require us to check // for trait item addition and removal, as well as changes to their @@ -298,7 +299,7 @@ fn diff_structure<'tcx>( // only an old item is found (Some(o), None) => { // struct constructors are weird/hard - let's go shopping! - if let Def(Ctor(CtorOf::Struct, _), _) = o.res { + if let Def(Ctor(CtorOf::Struct, _), _) = o.res.expect_non_local::() { continue; } @@ -310,7 +311,7 @@ fn diff_structure<'tcx>( // only a new item is found (None, Some(n)) => { // struct constructors are weird/hard - let's go shopping! - if let Def(Ctor(CtorOf::Struct, _), _) = n.res { + if let Def(Ctor(CtorOf::Struct, _), _) = n.res.expect_non_local::() { continue; } @@ -327,7 +328,7 @@ fn diff_structure<'tcx>( // finally, process item additions and removals for n in additions { - let n_def_id = n.res.def_id(); + let n_def_id = n.res.expect_non_local::().def_id(); if !id_mapping.contains_new_id(n_def_id) { id_mapping.add_non_mapped(n_def_id); @@ -338,7 +339,7 @@ fn diff_structure<'tcx>( } for o in removals { - let o_def_id = o.res.def_id(); + let o_def_id = o.res.expect_non_local::().def_id(); // reuse an already existing path change entry, if possible if id_mapping.contains_old_id(o_def_id) { From a3657c0452f49eb3b22ae5839f0848d483406273 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 15 Oct 2021 10:43:27 +0900 Subject: [PATCH 5/8] Rustup to rust-lang/rust#89001 --- README.md | 8 ++++---- rust-toolchain | 2 +- src/translate.rs | 11 +++++------ src/typeck.rs | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b48b37c6..aae20a85 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ repository and compiled from source or installed from of the nightly toolchain is supported at any given time. -It's recommended to use `nightly-2021-09-20` toolchain. -You can install it by using `rustup install nightly-2021-09-20` if you already have rustup. +It's recommended to use `nightly-2021-09-30` toolchain. +You can install it by using `rustup install nightly-2021-09-30` if you already have rustup. Then you can do: ```sh -$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-09-20 -$ cargo +nightly-2021-09-20 install --git https://github.com/rust-lang/rust-semverver +$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-09-30 +$ cargo +nightly-2021-09-30 install --git https://github.com/rust-lang/rust-semverver ``` You'd also need `cmake` for some dependencies, and a few common libraries (if you hit diff --git a/rust-toolchain b/rust-toolchain index a52f4999..be691470 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ # NOTE: Keep in sync with nightly date on README [toolchain] -channel = "nightly-2021-09-20" +channel = "nightly-2021-09-30" components = ["llvm-tools-preview", "rustc-dev"] diff --git a/src/translate.rs b/src/translate.rs index 4c7610cd..49835fef 100644 --- a/src/translate.rs +++ b/src/translate.rs @@ -377,11 +377,10 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { ) -> Option> { use rustc_middle::ty::{ CoercePredicate, OutlivesPredicate, PredicateKind, ProjectionPredicate, ProjectionTy, - SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam, + self, SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam, }; - Some( - match predicate.kind().skip_binder() { + let pred = match predicate.kind().skip_binder() { PredicateKind::Trait(pred) => PredicateKind::Trait( if let Some((target_def_id, target_substs)) = self.translate_orig_substs( index_map, @@ -472,9 +471,9 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { ), // NOTE: Only used for Chalk trait solver PredicateKind::TypeWellFormedFromEnv(_) => unimplemented!(), - } - .to_predicate(self.tcx), - ) + }; + + Some(ty::Binder::dummy(pred).to_predicate(self.tcx)) } /// Translate a slice of predicates in the context of an item. diff --git a/src/typeck.rs b/src/typeck.rs index bda964f2..2ab90066 100644 --- a/src/typeck.rs +++ b/src/typeck.rs @@ -72,12 +72,12 @@ impl<'a, 'tcx> BoundContext<'a, 'tcx> { /// Register the trait bound represented by a `TraitRef`. pub fn register_trait_ref(&mut self, checked_trait_ref: TraitRef<'tcx>) { - use rustc_middle::ty::{BoundConstness, ToPredicate, TraitPredicate}; + use rustc_middle::ty::{BoundConstness, self, ToPredicate, TraitPredicate}; - let predicate = PredicateKind::Trait(TraitPredicate { + let predicate = ty::Binder::dummy(PredicateKind::Trait(TraitPredicate { trait_ref: checked_trait_ref, constness: BoundConstness::NotConst, - }) + })) .to_predicate(self.infcx.tcx); let obligation = Obligation::new(ObligationCause::dummy(), self.given_param_env, predicate); self.fulfill_cx From 0905e424eceef2722b396a3e96d20f5db420b058 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 15 Oct 2021 10:49:59 +0900 Subject: [PATCH 6/8] Rustup to rust-lang/rust#89449 --- README.md | 8 +-- rust-toolchain | 2 +- src/translate.rs | 175 +++++++++++++++++++++++------------------------ src/traverse.rs | 5 +- src/typeck.rs | 2 +- 5 files changed, 93 insertions(+), 99 deletions(-) diff --git a/README.md b/README.md index aae20a85..921f5e38 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ repository and compiled from source or installed from of the nightly toolchain is supported at any given time. -It's recommended to use `nightly-2021-09-30` toolchain. -You can install it by using `rustup install nightly-2021-09-30` if you already have rustup. +It's recommended to use `nightly-2021-10-15` toolchain. +You can install it by using `rustup install nightly-2021-10-15` if you already have rustup. Then you can do: ```sh -$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-09-30 -$ cargo +nightly-2021-09-30 install --git https://github.com/rust-lang/rust-semverver +$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-10-15 +$ cargo +nightly-2021-10-15 install --git https://github.com/rust-lang/rust-semverver ``` You'd also need `cmake` for some dependencies, and a few common libraries (if you hit diff --git a/rust-toolchain b/rust-toolchain index be691470..085c7531 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ # NOTE: Keep in sync with nightly date on README [toolchain] -channel = "nightly-2021-09-30" +channel = "nightly-2021-10-15" components = ["llvm-tools-preview", "rustc-dev"] diff --git a/src/translate.rs b/src/translate.rs index 49835fef..08d349f2 100644 --- a/src/translate.rs +++ b/src/translate.rs @@ -376,102 +376,97 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { predicate: Predicate<'tcx>, ) -> Option> { use rustc_middle::ty::{ - CoercePredicate, OutlivesPredicate, PredicateKind, ProjectionPredicate, ProjectionTy, - self, SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam, + self, CoercePredicate, OutlivesPredicate, PredicateKind, ProjectionPredicate, + ProjectionTy, SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam, }; let pred = match predicate.kind().skip_binder() { - PredicateKind::Trait(pred) => PredicateKind::Trait( - if let Some((target_def_id, target_substs)) = self.translate_orig_substs( - index_map, - pred.trait_ref.def_id, - pred.trait_ref.substs, - ) { - TraitPredicate { - trait_ref: TraitRef { - def_id: target_def_id, - substs: target_substs, - }, - constness: pred.constness, - } - } else { - return None; - }, - ), - PredicateKind::RegionOutlives(pred) => PredicateKind::RegionOutlives({ - let l = self.translate_region(pred.0); - let r = self.translate_region(pred.1); - OutlivesPredicate(l, r) - }), - PredicateKind::TypeOutlives(pred) => PredicateKind::TypeOutlives({ - let l = self.translate(index_map, pred.0); - let r = self.translate_region(pred.1); - OutlivesPredicate(l, r) - }), - PredicateKind::Projection(pred) => PredicateKind::Projection( - if let Some((target_def_id, target_substs)) = self.translate_orig_substs( - index_map, - pred.projection_ty.item_def_id, - pred.projection_ty.substs, - ) { - ProjectionPredicate { - projection_ty: ProjectionTy { - substs: target_substs, - item_def_id: target_def_id, - }, - ty: self.translate(index_map, pred.ty), - } - } else { - return None; - }, - ), - PredicateKind::WellFormed(ty) => { - PredicateKind::WellFormed(self.translate(index_map, ty)) - } - PredicateKind::ObjectSafe(did) => { - PredicateKind::ObjectSafe(self.translate_orig(did)) - } - PredicateKind::ClosureKind(did, substs, kind) => PredicateKind::ClosureKind( - self.translate_orig(did), - self.translate(index_map, substs), - kind, - ), - PredicateKind::Subtype(pred) => PredicateKind::Subtype({ - let l = self.translate(index_map, pred.a); - let r = self.translate(index_map, pred.b); - SubtypePredicate { - a_is_expected: pred.a_is_expected, - a: l, - b: r, + PredicateKind::Trait(pred) => PredicateKind::Trait( + if let Some((target_def_id, target_substs)) = self.translate_orig_substs( + index_map, + pred.trait_ref.def_id, + pred.trait_ref.substs, + ) { + TraitPredicate { + trait_ref: TraitRef { + def_id: target_def_id, + substs: target_substs, + }, + constness: pred.constness, } - }), - PredicateKind::Coerce(pred) => PredicateKind::Coerce({ - let a = self.translate(index_map, pred.a); - let b = self.translate(index_map, pred.b); - CoercePredicate { a, b } - }), - PredicateKind::ConstEvaluatable(uv) => { - if let Some((target_def_id, target_substs)) = - self.translate_orig_substs(index_map, uv.def.did, uv.substs(self.tcx)) - { - // TODO: We could probably use translated version for - // `WithOptConstParam::const_param_did` - let const_param = WithOptConstParam::unknown(target_def_id); - PredicateKind::ConstEvaluatable(Unevaluated::new( - const_param, - target_substs, - )) - } else { - return None; + } else { + return None; + }, + ), + PredicateKind::RegionOutlives(pred) => PredicateKind::RegionOutlives({ + let l = self.translate_region(pred.0); + let r = self.translate_region(pred.1); + OutlivesPredicate(l, r) + }), + PredicateKind::TypeOutlives(pred) => PredicateKind::TypeOutlives({ + let l = self.translate(index_map, pred.0); + let r = self.translate_region(pred.1); + OutlivesPredicate(l, r) + }), + PredicateKind::Projection(pred) => PredicateKind::Projection( + if let Some((target_def_id, target_substs)) = self.translate_orig_substs( + index_map, + pred.projection_ty.item_def_id, + pred.projection_ty.substs, + ) { + ProjectionPredicate { + projection_ty: ProjectionTy { + substs: target_substs, + item_def_id: target_def_id, + }, + ty: self.translate(index_map, pred.ty), } + } else { + return None; + }, + ), + PredicateKind::WellFormed(ty) => { + PredicateKind::WellFormed(self.translate(index_map, ty)) + } + PredicateKind::ObjectSafe(did) => PredicateKind::ObjectSafe(self.translate_orig(did)), + PredicateKind::ClosureKind(did, substs, kind) => PredicateKind::ClosureKind( + self.translate_orig(did), + self.translate(index_map, substs), + kind, + ), + PredicateKind::Subtype(pred) => PredicateKind::Subtype({ + let l = self.translate(index_map, pred.a); + let r = self.translate(index_map, pred.b); + SubtypePredicate { + a_is_expected: pred.a_is_expected, + a: l, + b: r, } - PredicateKind::ConstEquate(c1, c2) => PredicateKind::ConstEquate( - self.translate(index_map, c1), - self.translate(index_map, c2), - ), - // NOTE: Only used for Chalk trait solver - PredicateKind::TypeWellFormedFromEnv(_) => unimplemented!(), - }; + }), + PredicateKind::Coerce(pred) => PredicateKind::Coerce({ + let a = self.translate(index_map, pred.a); + let b = self.translate(index_map, pred.b); + CoercePredicate { a, b } + }), + PredicateKind::ConstEvaluatable(uv) => { + if let Some((target_def_id, target_substs)) = + self.translate_orig_substs(index_map, uv.def.did, uv.substs(self.tcx)) + { + // TODO: We could probably use translated version for + // `WithOptConstParam::const_param_did` + let const_param = WithOptConstParam::unknown(target_def_id); + PredicateKind::ConstEvaluatable(Unevaluated::new(const_param, target_substs)) + } else { + return None; + } + } + PredicateKind::ConstEquate(c1, c2) => PredicateKind::ConstEquate( + self.translate(index_map, c1), + self.translate(index_map, c2), + ), + // NOTE: Only used for Chalk trait solver + PredicateKind::TypeWellFormedFromEnv(_) => unimplemented!(), + }; Some(ty::Binder::dummy(pred).to_predicate(self.tcx)) } diff --git a/src/traverse.rs b/src/traverse.rs index 2cc67961..c4c58139 100644 --- a/src/traverse.rs +++ b/src/traverse.rs @@ -17,7 +17,6 @@ use crate::{ typeck::{BoundContext, TypeComparisonContext}, }; use log::{debug, info}; -use rustc_const_eval::const_eval::is_const_fn; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res, Res::Def}; use rustc_hir::def_id::DefId; use rustc_hir::hir_id::HirId; @@ -363,8 +362,8 @@ fn diff_fn<'tcx>(changes: &mut ChangeSet, tcx: TyCtxt<'tcx>, old: Res, new: Res) let old_def_id = old.def_id(); let new_def_id = new.def_id(); - let old_const = is_const_fn(tcx, old_def_id); - let new_const = is_const_fn(tcx, new_def_id); + let old_const = tcx.is_const_fn(old_def_id); + let new_const = tcx.is_const_fn(new_def_id); if old_const != new_const { changes.add_change( diff --git a/src/typeck.rs b/src/typeck.rs index 2ab90066..ae490e8e 100644 --- a/src/typeck.rs +++ b/src/typeck.rs @@ -72,7 +72,7 @@ impl<'a, 'tcx> BoundContext<'a, 'tcx> { /// Register the trait bound represented by a `TraitRef`. pub fn register_trait_ref(&mut self, checked_trait_ref: TraitRef<'tcx>) { - use rustc_middle::ty::{BoundConstness, self, ToPredicate, TraitPredicate}; + use rustc_middle::ty::{self, BoundConstness, ToPredicate, TraitPredicate}; let predicate = ty::Binder::dummy(PredicateKind::Trait(TraitPredicate { trait_ref: checked_trait_ref, From 8eb0d65b1e34ddd837e5ea466cc6a1147f99b10d Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 20 Oct 2021 04:51:24 +0900 Subject: [PATCH 7/8] Revert "Rustup to rust-lang/rust#89449" This reverts commit 0905e424eceef2722b396a3e96d20f5db420b058. --- README.md | 8 +-- rust-toolchain | 2 +- src/translate.rs | 175 ++++++++++++++++++++++++----------------------- src/traverse.rs | 5 +- src/typeck.rs | 2 +- 5 files changed, 99 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 921f5e38..aae20a85 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ repository and compiled from source or installed from of the nightly toolchain is supported at any given time. -It's recommended to use `nightly-2021-10-15` toolchain. -You can install it by using `rustup install nightly-2021-10-15` if you already have rustup. +It's recommended to use `nightly-2021-09-30` toolchain. +You can install it by using `rustup install nightly-2021-09-30` if you already have rustup. Then you can do: ```sh -$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-10-15 -$ cargo +nightly-2021-10-15 install --git https://github.com/rust-lang/rust-semverver +$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-09-30 +$ cargo +nightly-2021-09-30 install --git https://github.com/rust-lang/rust-semverver ``` You'd also need `cmake` for some dependencies, and a few common libraries (if you hit diff --git a/rust-toolchain b/rust-toolchain index 085c7531..be691470 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ # NOTE: Keep in sync with nightly date on README [toolchain] -channel = "nightly-2021-10-15" +channel = "nightly-2021-09-30" components = ["llvm-tools-preview", "rustc-dev"] diff --git a/src/translate.rs b/src/translate.rs index 08d349f2..49835fef 100644 --- a/src/translate.rs +++ b/src/translate.rs @@ -376,97 +376,102 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { predicate: Predicate<'tcx>, ) -> Option> { use rustc_middle::ty::{ - self, CoercePredicate, OutlivesPredicate, PredicateKind, ProjectionPredicate, - ProjectionTy, SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam, + CoercePredicate, OutlivesPredicate, PredicateKind, ProjectionPredicate, ProjectionTy, + self, SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam, }; let pred = match predicate.kind().skip_binder() { - PredicateKind::Trait(pred) => PredicateKind::Trait( - if let Some((target_def_id, target_substs)) = self.translate_orig_substs( - index_map, - pred.trait_ref.def_id, - pred.trait_ref.substs, - ) { - TraitPredicate { - trait_ref: TraitRef { - def_id: target_def_id, - substs: target_substs, - }, - constness: pred.constness, + PredicateKind::Trait(pred) => PredicateKind::Trait( + if let Some((target_def_id, target_substs)) = self.translate_orig_substs( + index_map, + pred.trait_ref.def_id, + pred.trait_ref.substs, + ) { + TraitPredicate { + trait_ref: TraitRef { + def_id: target_def_id, + substs: target_substs, + }, + constness: pred.constness, + } + } else { + return None; + }, + ), + PredicateKind::RegionOutlives(pred) => PredicateKind::RegionOutlives({ + let l = self.translate_region(pred.0); + let r = self.translate_region(pred.1); + OutlivesPredicate(l, r) + }), + PredicateKind::TypeOutlives(pred) => PredicateKind::TypeOutlives({ + let l = self.translate(index_map, pred.0); + let r = self.translate_region(pred.1); + OutlivesPredicate(l, r) + }), + PredicateKind::Projection(pred) => PredicateKind::Projection( + if let Some((target_def_id, target_substs)) = self.translate_orig_substs( + index_map, + pred.projection_ty.item_def_id, + pred.projection_ty.substs, + ) { + ProjectionPredicate { + projection_ty: ProjectionTy { + substs: target_substs, + item_def_id: target_def_id, + }, + ty: self.translate(index_map, pred.ty), + } + } else { + return None; + }, + ), + PredicateKind::WellFormed(ty) => { + PredicateKind::WellFormed(self.translate(index_map, ty)) + } + PredicateKind::ObjectSafe(did) => { + PredicateKind::ObjectSafe(self.translate_orig(did)) + } + PredicateKind::ClosureKind(did, substs, kind) => PredicateKind::ClosureKind( + self.translate_orig(did), + self.translate(index_map, substs), + kind, + ), + PredicateKind::Subtype(pred) => PredicateKind::Subtype({ + let l = self.translate(index_map, pred.a); + let r = self.translate(index_map, pred.b); + SubtypePredicate { + a_is_expected: pred.a_is_expected, + a: l, + b: r, } - } else { - return None; - }, - ), - PredicateKind::RegionOutlives(pred) => PredicateKind::RegionOutlives({ - let l = self.translate_region(pred.0); - let r = self.translate_region(pred.1); - OutlivesPredicate(l, r) - }), - PredicateKind::TypeOutlives(pred) => PredicateKind::TypeOutlives({ - let l = self.translate(index_map, pred.0); - let r = self.translate_region(pred.1); - OutlivesPredicate(l, r) - }), - PredicateKind::Projection(pred) => PredicateKind::Projection( - if let Some((target_def_id, target_substs)) = self.translate_orig_substs( - index_map, - pred.projection_ty.item_def_id, - pred.projection_ty.substs, - ) { - ProjectionPredicate { - projection_ty: ProjectionTy { - substs: target_substs, - item_def_id: target_def_id, - }, - ty: self.translate(index_map, pred.ty), + }), + PredicateKind::Coerce(pred) => PredicateKind::Coerce({ + let a = self.translate(index_map, pred.a); + let b = self.translate(index_map, pred.b); + CoercePredicate { a, b } + }), + PredicateKind::ConstEvaluatable(uv) => { + if let Some((target_def_id, target_substs)) = + self.translate_orig_substs(index_map, uv.def.did, uv.substs(self.tcx)) + { + // TODO: We could probably use translated version for + // `WithOptConstParam::const_param_did` + let const_param = WithOptConstParam::unknown(target_def_id); + PredicateKind::ConstEvaluatable(Unevaluated::new( + const_param, + target_substs, + )) + } else { + return None; } - } else { - return None; - }, - ), - PredicateKind::WellFormed(ty) => { - PredicateKind::WellFormed(self.translate(index_map, ty)) - } - PredicateKind::ObjectSafe(did) => PredicateKind::ObjectSafe(self.translate_orig(did)), - PredicateKind::ClosureKind(did, substs, kind) => PredicateKind::ClosureKind( - self.translate_orig(did), - self.translate(index_map, substs), - kind, - ), - PredicateKind::Subtype(pred) => PredicateKind::Subtype({ - let l = self.translate(index_map, pred.a); - let r = self.translate(index_map, pred.b); - SubtypePredicate { - a_is_expected: pred.a_is_expected, - a: l, - b: r, } - }), - PredicateKind::Coerce(pred) => PredicateKind::Coerce({ - let a = self.translate(index_map, pred.a); - let b = self.translate(index_map, pred.b); - CoercePredicate { a, b } - }), - PredicateKind::ConstEvaluatable(uv) => { - if let Some((target_def_id, target_substs)) = - self.translate_orig_substs(index_map, uv.def.did, uv.substs(self.tcx)) - { - // TODO: We could probably use translated version for - // `WithOptConstParam::const_param_did` - let const_param = WithOptConstParam::unknown(target_def_id); - PredicateKind::ConstEvaluatable(Unevaluated::new(const_param, target_substs)) - } else { - return None; - } - } - PredicateKind::ConstEquate(c1, c2) => PredicateKind::ConstEquate( - self.translate(index_map, c1), - self.translate(index_map, c2), - ), - // NOTE: Only used for Chalk trait solver - PredicateKind::TypeWellFormedFromEnv(_) => unimplemented!(), - }; + PredicateKind::ConstEquate(c1, c2) => PredicateKind::ConstEquate( + self.translate(index_map, c1), + self.translate(index_map, c2), + ), + // NOTE: Only used for Chalk trait solver + PredicateKind::TypeWellFormedFromEnv(_) => unimplemented!(), + }; Some(ty::Binder::dummy(pred).to_predicate(self.tcx)) } diff --git a/src/traverse.rs b/src/traverse.rs index c4c58139..2cc67961 100644 --- a/src/traverse.rs +++ b/src/traverse.rs @@ -17,6 +17,7 @@ use crate::{ typeck::{BoundContext, TypeComparisonContext}, }; use log::{debug, info}; +use rustc_const_eval::const_eval::is_const_fn; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res, Res::Def}; use rustc_hir::def_id::DefId; use rustc_hir::hir_id::HirId; @@ -362,8 +363,8 @@ fn diff_fn<'tcx>(changes: &mut ChangeSet, tcx: TyCtxt<'tcx>, old: Res, new: Res) let old_def_id = old.def_id(); let new_def_id = new.def_id(); - let old_const = tcx.is_const_fn(old_def_id); - let new_const = tcx.is_const_fn(new_def_id); + let old_const = is_const_fn(tcx, old_def_id); + let new_const = is_const_fn(tcx, new_def_id); if old_const != new_const { changes.add_change( diff --git a/src/typeck.rs b/src/typeck.rs index ae490e8e..2ab90066 100644 --- a/src/typeck.rs +++ b/src/typeck.rs @@ -72,7 +72,7 @@ impl<'a, 'tcx> BoundContext<'a, 'tcx> { /// Register the trait bound represented by a `TraitRef`. pub fn register_trait_ref(&mut self, checked_trait_ref: TraitRef<'tcx>) { - use rustc_middle::ty::{self, BoundConstness, ToPredicate, TraitPredicate}; + use rustc_middle::ty::{BoundConstness, self, ToPredicate, TraitPredicate}; let predicate = ty::Binder::dummy(PredicateKind::Trait(TraitPredicate { trait_ref: checked_trait_ref, From 88e114b11bd7873ff06fd415a76f81f027239239 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 20 Oct 2021 05:00:48 +0900 Subject: [PATCH 8/8] Fix formatting --- src/translate.rs | 175 +++++++++++++++++++++++------------------------ src/typeck.rs | 2 +- 2 files changed, 86 insertions(+), 91 deletions(-) diff --git a/src/translate.rs b/src/translate.rs index 49835fef..08d349f2 100644 --- a/src/translate.rs +++ b/src/translate.rs @@ -376,102 +376,97 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { predicate: Predicate<'tcx>, ) -> Option> { use rustc_middle::ty::{ - CoercePredicate, OutlivesPredicate, PredicateKind, ProjectionPredicate, ProjectionTy, - self, SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam, + self, CoercePredicate, OutlivesPredicate, PredicateKind, ProjectionPredicate, + ProjectionTy, SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam, }; let pred = match predicate.kind().skip_binder() { - PredicateKind::Trait(pred) => PredicateKind::Trait( - if let Some((target_def_id, target_substs)) = self.translate_orig_substs( - index_map, - pred.trait_ref.def_id, - pred.trait_ref.substs, - ) { - TraitPredicate { - trait_ref: TraitRef { - def_id: target_def_id, - substs: target_substs, - }, - constness: pred.constness, - } - } else { - return None; - }, - ), - PredicateKind::RegionOutlives(pred) => PredicateKind::RegionOutlives({ - let l = self.translate_region(pred.0); - let r = self.translate_region(pred.1); - OutlivesPredicate(l, r) - }), - PredicateKind::TypeOutlives(pred) => PredicateKind::TypeOutlives({ - let l = self.translate(index_map, pred.0); - let r = self.translate_region(pred.1); - OutlivesPredicate(l, r) - }), - PredicateKind::Projection(pred) => PredicateKind::Projection( - if let Some((target_def_id, target_substs)) = self.translate_orig_substs( - index_map, - pred.projection_ty.item_def_id, - pred.projection_ty.substs, - ) { - ProjectionPredicate { - projection_ty: ProjectionTy { - substs: target_substs, - item_def_id: target_def_id, - }, - ty: self.translate(index_map, pred.ty), - } - } else { - return None; - }, - ), - PredicateKind::WellFormed(ty) => { - PredicateKind::WellFormed(self.translate(index_map, ty)) - } - PredicateKind::ObjectSafe(did) => { - PredicateKind::ObjectSafe(self.translate_orig(did)) - } - PredicateKind::ClosureKind(did, substs, kind) => PredicateKind::ClosureKind( - self.translate_orig(did), - self.translate(index_map, substs), - kind, - ), - PredicateKind::Subtype(pred) => PredicateKind::Subtype({ - let l = self.translate(index_map, pred.a); - let r = self.translate(index_map, pred.b); - SubtypePredicate { - a_is_expected: pred.a_is_expected, - a: l, - b: r, + PredicateKind::Trait(pred) => PredicateKind::Trait( + if let Some((target_def_id, target_substs)) = self.translate_orig_substs( + index_map, + pred.trait_ref.def_id, + pred.trait_ref.substs, + ) { + TraitPredicate { + trait_ref: TraitRef { + def_id: target_def_id, + substs: target_substs, + }, + constness: pred.constness, } - }), - PredicateKind::Coerce(pred) => PredicateKind::Coerce({ - let a = self.translate(index_map, pred.a); - let b = self.translate(index_map, pred.b); - CoercePredicate { a, b } - }), - PredicateKind::ConstEvaluatable(uv) => { - if let Some((target_def_id, target_substs)) = - self.translate_orig_substs(index_map, uv.def.did, uv.substs(self.tcx)) - { - // TODO: We could probably use translated version for - // `WithOptConstParam::const_param_did` - let const_param = WithOptConstParam::unknown(target_def_id); - PredicateKind::ConstEvaluatable(Unevaluated::new( - const_param, - target_substs, - )) - } else { - return None; + } else { + return None; + }, + ), + PredicateKind::RegionOutlives(pred) => PredicateKind::RegionOutlives({ + let l = self.translate_region(pred.0); + let r = self.translate_region(pred.1); + OutlivesPredicate(l, r) + }), + PredicateKind::TypeOutlives(pred) => PredicateKind::TypeOutlives({ + let l = self.translate(index_map, pred.0); + let r = self.translate_region(pred.1); + OutlivesPredicate(l, r) + }), + PredicateKind::Projection(pred) => PredicateKind::Projection( + if let Some((target_def_id, target_substs)) = self.translate_orig_substs( + index_map, + pred.projection_ty.item_def_id, + pred.projection_ty.substs, + ) { + ProjectionPredicate { + projection_ty: ProjectionTy { + substs: target_substs, + item_def_id: target_def_id, + }, + ty: self.translate(index_map, pred.ty), } + } else { + return None; + }, + ), + PredicateKind::WellFormed(ty) => { + PredicateKind::WellFormed(self.translate(index_map, ty)) + } + PredicateKind::ObjectSafe(did) => PredicateKind::ObjectSafe(self.translate_orig(did)), + PredicateKind::ClosureKind(did, substs, kind) => PredicateKind::ClosureKind( + self.translate_orig(did), + self.translate(index_map, substs), + kind, + ), + PredicateKind::Subtype(pred) => PredicateKind::Subtype({ + let l = self.translate(index_map, pred.a); + let r = self.translate(index_map, pred.b); + SubtypePredicate { + a_is_expected: pred.a_is_expected, + a: l, + b: r, } - PredicateKind::ConstEquate(c1, c2) => PredicateKind::ConstEquate( - self.translate(index_map, c1), - self.translate(index_map, c2), - ), - // NOTE: Only used for Chalk trait solver - PredicateKind::TypeWellFormedFromEnv(_) => unimplemented!(), - }; + }), + PredicateKind::Coerce(pred) => PredicateKind::Coerce({ + let a = self.translate(index_map, pred.a); + let b = self.translate(index_map, pred.b); + CoercePredicate { a, b } + }), + PredicateKind::ConstEvaluatable(uv) => { + if let Some((target_def_id, target_substs)) = + self.translate_orig_substs(index_map, uv.def.did, uv.substs(self.tcx)) + { + // TODO: We could probably use translated version for + // `WithOptConstParam::const_param_did` + let const_param = WithOptConstParam::unknown(target_def_id); + PredicateKind::ConstEvaluatable(Unevaluated::new(const_param, target_substs)) + } else { + return None; + } + } + PredicateKind::ConstEquate(c1, c2) => PredicateKind::ConstEquate( + self.translate(index_map, c1), + self.translate(index_map, c2), + ), + // NOTE: Only used for Chalk trait solver + PredicateKind::TypeWellFormedFromEnv(_) => unimplemented!(), + }; Some(ty::Binder::dummy(pred).to_predicate(self.tcx)) } diff --git a/src/typeck.rs b/src/typeck.rs index 2ab90066..ae490e8e 100644 --- a/src/typeck.rs +++ b/src/typeck.rs @@ -72,7 +72,7 @@ impl<'a, 'tcx> BoundContext<'a, 'tcx> { /// Register the trait bound represented by a `TraitRef`. pub fn register_trait_ref(&mut self, checked_trait_ref: TraitRef<'tcx>) { - use rustc_middle::ty::{BoundConstness, self, ToPredicate, TraitPredicate}; + use rustc_middle::ty::{self, BoundConstness, ToPredicate, TraitPredicate}; let predicate = ty::Binder::dummy(PredicateKind::Trait(TraitPredicate { trait_ref: checked_trait_ref,