diff --git a/README.md b/README.md index d6df91ed..7a2e5b62 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-12-31` toolchain. -You can install it by using `rustup install nightly-2021-12-31` if you already have rustup. +It's recommended to use `nightly-2022-03-13` toolchain. +You can install it by using `rustup install nightly-2022-03-13` if you already have rustup. Then you can do: ```sh -$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-12-31 -$ cargo +nightly-2021-12-31 install --git https://github.com/rust-lang/rust-semverver +$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2022-03-13 +$ cargo +nightly-2022-03-13 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 ee8d5905..6ad567dd 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ # NOTE: Keep in sync with nightly date on README [toolchain] -channel = "nightly-2021-12-31" +channel = "nightly-2022-03-13" components = ["llvm-tools-preview", "rustc-dev"] diff --git a/src/changes.rs b/src/changes.rs index 4e676e43..a5d21a4b 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -202,7 +202,9 @@ impl PathChange { let msg = format!("path changes to `{}`", self.name.0); let mut builder = if cat == Breaking { - session.struct_span_err(self.def_span, &msg) + session + .struct_span_err(self.def_span, &msg) + .forget_guarantee() } else { session.struct_span_warn(self.def_span, &msg) }; @@ -903,7 +905,9 @@ impl<'tcx> Change<'tcx> { let msg = format!("{} changes in {}", self.max, self.name); let mut builder = if self.max == Breaking { - session.struct_span_err(self.new_span, &msg) + session + .struct_span_err(self.new_span, &msg) + .forget_guarantee() } else { session.struct_span_warn(self.new_span, &msg) }; diff --git a/src/lib.rs b/src/lib.rs index 5ead1ba5..e72c9962 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,7 @@ extern crate rustc_const_eval; // Requires `rustup component add rustc-dev` extern crate rustc_hir; extern crate rustc_infer; +extern crate rustc_metadata; extern crate rustc_middle; extern crate rustc_session; extern crate rustc_span; diff --git a/src/mapping.rs b/src/mapping.rs index c7329ad6..e88ca07b 100644 --- a/src/mapping.rs +++ b/src/mapping.rs @@ -9,7 +9,7 @@ use rustc_hir::{ HirId, }; use rustc_middle::{ - hir::exports::Export, + metadata::ModChild, ty::{AssocKind, GenericParamDef, GenericParamDefKind}, }; use rustc_span::symbol::Symbol; @@ -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,7 +343,7 @@ 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: ModChild, old: bool) { use rustc_hir::def::DefKind::*; use rustc_hir::def::Res::*; @@ -382,7 +382,7 @@ impl NameMapping { Closure | Generator => None, }, - PrimTy(_) | SelfTy(_, _) => Some(&mut self.type_map), + PrimTy(_) | SelfTy { .. } => Some(&mut self.type_map), SelfCtor(_) | Local(_) => Some(&mut self.value_map), _ => None, }; @@ -397,7 +397,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); } @@ -408,7 +408,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/mismatch.rs b/src/mismatch.rs index cc8dc1f1..2ba6d2bd 100644 --- a/src/mismatch.rs +++ b/src/mismatch.rs @@ -140,7 +140,7 @@ impl<'a, 'tcx> TypeRelation<'tcx> for MismatchRelation<'a, 'tcx> { // could potentially short-circuit somewhere). let dummy_type = self.tcx.types.unit; - if self.current_old_types.contains(a) || self.current_new_types.contains(b) { + if self.current_old_types.contains(&a) || self.current_new_types.contains(&b) { return Ok(dummy_type); } @@ -151,9 +151,9 @@ impl<'a, 'tcx> TypeRelation<'tcx> for MismatchRelation<'a, 'tcx> { let matching = match (a.kind(), b.kind()) { (&TyKind::Adt(a_def, a_substs), &TyKind::Adt(b_def, b_substs)) => { if self.check_substs(a_substs, b_substs) { - let _ = self.relate_item_substs(a_def.did, a_substs, b_substs)?; - let a_adt = self.tcx.adt_def(a_def.did); - let b_adt = self.tcx.adt_def(b_def.did); + let _ = self.relate_item_substs(a_def.did(), a_substs, b_substs)?; + let a_adt = self.tcx.adt_def(a_def.did()); + let b_adt = self.tcx.adt_def(b_def.did()); let b_fields: HashMap<_, _> = b_adt.all_fields().map(|f| (f.did, f)).collect(); @@ -172,19 +172,19 @@ impl<'a, 'tcx> TypeRelation<'tcx> for MismatchRelation<'a, 'tcx> { } let a = if a_def.is_struct() { - Res::Def(DefKind::Struct, a_def.did) + Res::Def(DefKind::Struct, a_def.did()) } else if a_def.is_union() { - Res::Def(DefKind::Union, a_def.did) + Res::Def(DefKind::Union, a_def.did()) } else { - Res::Def(DefKind::Enum, a_def.did) + Res::Def(DefKind::Enum, a_def.did()) }; let b = if b_def.is_struct() { - Res::Def(DefKind::Struct, b_def.did) + Res::Def(DefKind::Struct, b_def.did()) } else if b_def.is_union() { - Res::Def(DefKind::Union, b_def.did) + Res::Def(DefKind::Union, b_def.did()) } else { - Res::Def(DefKind::Enum, b_def.did) + Res::Def(DefKind::Enum, b_def.did()) }; Some((a, b)) @@ -270,8 +270,8 @@ impl<'a, 'tcx> TypeRelation<'tcx> for MismatchRelation<'a, 'tcx> { _ => None, }; - self.current_old_types.remove(a); - self.current_new_types.remove(b); + self.current_old_types.remove(&a); + self.current_new_types.remove(&b); if let Some((old, new)) = matching { let old_def_id = old.def_id(); @@ -298,9 +298,9 @@ impl<'a, 'tcx> TypeRelation<'tcx> for MismatchRelation<'a, 'tcx> { fn consts( &mut self, - a: &'tcx ty::Const<'tcx>, - _: &'tcx ty::Const<'tcx>, - ) -> RelateResult<'tcx, &'tcx ty::Const<'tcx>> { + a: ty::Const<'tcx>, + _: ty::Const<'tcx>, + ) -> RelateResult<'tcx, ty::Const<'tcx>> { Ok(a) // TODO } diff --git a/src/translate.rs b/src/translate.rs index 0875d32c..605408f2 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, Unevaluated, + GenericParamDefKind, ParamEnv, Predicate, Region, Term, TraitRef, Ty, TyCtxt, Unevaluated, }; use std::collections::HashMap; @@ -164,18 +164,18 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { use rustc_middle::ty::ExistentialPredicate::*; use rustc_middle::ty::TyKind; use rustc_middle::ty::TypeAndMut; - use rustc_middle::ty::{AdtDef, Binder, ExistentialProjection, ExistentialTraitRef}; + use rustc_middle::ty::{Binder, ExistentialProjection, ExistentialTraitRef}; orig.fold_with(&mut BottomUpFolder { tcx: self.tcx, ty_op: |ty| { match *ty.kind() { - TyKind::Adt(&AdtDef { ref did, .. }, substs) - if self.needs_translation(*did) => - { + TyKind::Adt(adt_def, substs) if self.needs_translation(adt_def.did()) => { // we fold bottom-up, so the code above is invalid, as it assumes the // substs (that have been folded already) are yet untranslated - if let Some(target_def_id) = (self.translate_orig)(self.id_mapping, *did) { + if let Some(target_def_id) = + (self.translate_orig)(self.id_mapping, adt_def.did()) + { let target_adt = self.tcx.adt_def(target_def_id); self.tcx.mk_adt(target_adt, substs) } else { @@ -261,7 +261,7 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { substs: self .tcx .intern_substs(&target_substs[1..]), - ty, + term: Term::Ty(ty), }) } else { success.set(false); @@ -420,7 +420,10 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { substs: target_substs, item_def_id: target_def_id, }, - ty: self.translate(index_map, pred.ty), + term: match pred.term { + Term::Ty(ty) => Term::Ty(self.translate(index_map, ty)), + Term::Const(_) => pred.term, + }, } } else { return None; @@ -451,7 +454,7 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> { }), PredicateKind::ConstEvaluatable(uv) => { if let Some((target_def_id, target_substs)) = - self.translate_orig_substs(index_map, uv.def.did, uv.substs(self.tcx)) + self.translate_orig_substs(index_map, uv.def.did, uv.substs) { // TODO: We could probably use translated version for // `WithOptConstParam::const_param_did` diff --git a/src/traverse.rs b/src/traverse.rs index d69bafcb..a25100bb 100644 --- a/src/traverse.rs +++ b/src/traverse.rs @@ -22,8 +22,9 @@ use rustc_hir::def_id::DefId; use rustc_hir::hir_id::HirId; use rustc_hir::lang_items::LangItem; use rustc_infer::infer::TyCtxtInferExt; +use rustc_metadata::creader::CStore; use rustc_middle::{ - hir::exports::Export, + metadata::ModChild, ty::{ subst::{InternalSubsts, Subst}, AssocItem, GenericParamDef, GenericParamDefKind, Generics, TraitRef, Ty, TyCtxt, TyKind, @@ -67,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: ModChild) -> Visibility { if outer_vis == Public { def.vis } else { @@ -85,7 +86,7 @@ pub fn run_traversal(tcx: TyCtxt, new: DefId) { // Pull a module from the queue, with its global visibility. while let Some((new_def_id, idents, new_vis)) = mod_queue.pop_front() { - for item in tcx.item_children(new_def_id).iter().copied() { + for item in tcx.module_children(new_def_id).iter().copied() { let n_vis = get_vis(new_vis, item); match item.res { Def(Mod, n_def_id) => { @@ -147,8 +148,8 @@ fn diff_structure<'tcx>( // Pull a matched module pair from the queue, with the modules' global visibility. while let Some((old_def_id, new_def_id, old_vis, new_vis)) = mod_queue.pop_front() { children.add( - tcx.item_children(old_def_id).to_vec(), // TODO: clean up - tcx.item_children(new_def_id).to_vec(), + tcx.module_children(old_def_id).to_vec(), // TODO: clean up + tcx.module_children(new_def_id).to_vec(), ); for items in children.drain() { @@ -427,23 +428,35 @@ fn diff_adts(changes: &mut ChangeSet, id_mapping: &mut IdMapping, tcx: TyCtxt, o let mut variants = BTreeMap::new(); let mut fields = BTreeMap::new(); - for variant in &old_def.variants { - variants.entry(variant.ident.name).or_insert((None, None)).0 = Some(variant); + for variant in old_def.variants() { + variants + .entry(variant.ident(tcx).name) + .or_insert((None, None)) + .0 = Some(variant); } - for variant in &new_def.variants { - variants.entry(variant.ident.name).or_insert((None, None)).1 = Some(variant); + for variant in new_def.variants() { + variants + .entry(variant.ident(tcx).name) + .or_insert((None, None)) + .1 = Some(variant); } for items in variants.values() { match *items { (Some(old), Some(new)) => { for field in &old.fields { - fields.entry(field.ident.name).or_insert((None, None)).0 = Some(field); + fields + .entry(field.ident(tcx).name) + .or_insert((None, None)) + .0 = Some(field); } for field in &new.fields { - fields.entry(field.ident.name).or_insert((None, None)).1 = Some(field); + fields + .entry(field.ident(tcx).name) + .or_insert((None, None)) + .1 = Some(field); } let mut total_private = true; @@ -533,7 +546,7 @@ fn diff_adts(changes: &mut ChangeSet, id_mapping: &mut IdMapping, tcx: TyCtxt, o id_mapping.add_inherent_item( old_def_id, item.kind, - item.ident.name, + item.ident(tcx).name, *impl_def_id, *item_def_id, ); @@ -546,7 +559,7 @@ fn diff_adts(changes: &mut ChangeSet, id_mapping: &mut IdMapping, tcx: TyCtxt, o id_mapping.add_inherent_item( new_def_id, item.kind, - item.ident.name, + item.ident(tcx).name, *impl_def_id, *item_def_id, ); @@ -609,13 +622,13 @@ fn diff_traits<'tcx>( for old_def_id in tcx.associated_item_def_ids(old).iter() { let item = tcx.associated_item(*old_def_id); - items.entry(item.ident.name).or_insert((None, None)).0 = Some(item); + items.entry(item.ident(tcx).name).or_insert((None, None)).0 = Some(item); // tcx.describe_def(*old_def_id).map(|d| (d, item)); } for new_def_id in tcx.associated_item_def_ids(new).iter() { let item = tcx.associated_item(*new_def_id); - items.entry(item.ident.name).or_insert((None, None)).1 = Some(item); + items.entry(item.ident(tcx).name).or_insert((None, None)).1 = Some(item); // tcx.describe_def(*new_def_id).map(|d| (d, item)); } @@ -1093,12 +1106,12 @@ fn diff_inherent_impls<'tcx>( fn is_impl_trait_public<'tcx>(tcx: TyCtxt<'tcx>, impl_def_id: DefId) -> bool { fn type_visibility(tcx: TyCtxt, ty: Ty) -> Visibility { match ty.kind() { - TyKind::Adt(def, _) => tcx.visibility(def.did), + TyKind::Adt(def, _) => tcx.visibility(def.did()), TyKind::Array(t, _) | TyKind::Slice(t) | TyKind::RawPtr(TypeAndMut { ty: t, .. }) - | TyKind::Ref(_, t, _) => type_visibility(tcx, t), + | TyKind::Ref(_, t, _) => type_visibility(tcx, *t), TyKind::Bool | TyKind::Char @@ -1149,51 +1162,46 @@ fn diff_trait_impls<'tcx>( let structural_peq_def_id = tcx.require_lang_item(LangItem::StructuralPeq, None); let structural_trait_def_ids = [structural_peq_def_id, structural_teq_def_id]; - for (old_impl_def_id, _) in tcx - .all_trait_implementations(id_mapping.get_old_crate()) - .iter() + let cstore = CStore::from_tcx(tcx); + for (old_trait_def_id, old_impl_def_id, _) in + cstore.trait_impls_in_crate_untracked(id_mapping.get_old_crate()) { - let old_trait_def_id = tcx.impl_trait_ref(*old_impl_def_id).unwrap().def_id; - if structural_trait_def_ids.contains(&old_trait_def_id) { continue; } - if !to_new.can_translate(old_trait_def_id) || !is_impl_trait_public(tcx, *old_impl_def_id) { + if !to_new.can_translate(old_trait_def_id) || !is_impl_trait_public(tcx, old_impl_def_id) { continue; } - if !match_trait_impl(tcx, &to_new, *old_impl_def_id) { + if !match_trait_impl(tcx, &to_new, old_impl_def_id) { changes.new_change_impl( - *old_impl_def_id, - tcx.def_path_str(*old_impl_def_id), - tcx.def_span(*old_impl_def_id), + old_impl_def_id, + tcx.def_path_str(old_impl_def_id), + tcx.def_span(old_impl_def_id), ); - changes.add_change(ChangeType::TraitImplTightened, *old_impl_def_id, None); + changes.add_change(ChangeType::TraitImplTightened, old_impl_def_id, None); } } - for (new_impl_def_id, _) in tcx - .all_trait_implementations(id_mapping.get_new_crate()) - .iter() + for (new_trait_def_id, new_impl_def_id, _) in + cstore.trait_impls_in_crate_untracked(id_mapping.get_new_crate()) { - let new_trait_def_id = tcx.impl_trait_ref(*new_impl_def_id).unwrap().def_id; - if structural_trait_def_ids.contains(&new_trait_def_id) { continue; } - if !to_old.can_translate(new_trait_def_id) || !is_impl_trait_public(tcx, *new_impl_def_id) { + if !to_old.can_translate(new_trait_def_id) || !is_impl_trait_public(tcx, new_impl_def_id) { continue; } - if !match_trait_impl(tcx, &to_old, *new_impl_def_id) { + if !match_trait_impl(tcx, &to_old, new_impl_def_id) { changes.new_change_impl( - *new_impl_def_id, - tcx.def_path_str(*new_impl_def_id), - tcx.def_span(*new_impl_def_id), + new_impl_def_id, + tcx.def_path_str(new_impl_def_id), + tcx.def_span(new_impl_def_id), ); - changes.add_change(ChangeType::TraitImplLoosened, *new_impl_def_id, None); + changes.add_change(ChangeType::TraitImplLoosened, new_impl_def_id, None); } } } diff --git a/tests/cases/trait_impls/stdout b/tests/cases/trait_impls/stdout index d4ce24bb..ee14cabd 100644 --- a/tests/cases/trait_impls/stdout +++ b/tests/cases/trait_impls/stdout @@ -51,5 +51,4 @@ warning: technically breaking changes in ` as new::Ab | = note: trait impl generalized or newly added (technically breaking) -error: aborting due to 2 previous errors; 4 warnings emitted - +error: aborting due to 2 previous errors; 4 warnings emitted \ No newline at end of file