Skip to content

Commit

Permalink
Fixed rust-lang#34.
Browse files Browse the repository at this point in the history
We crawl all trait implementations in the `old` and `new` crates and
thus check private implementations inside functions and methods as well.
This has now been fixed in the obvious manner.
  • Loading branch information
ibabushkin committed Oct 5, 2017
1 parent 4cd76f1 commit cebffbc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/semcheck/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,13 +854,21 @@ fn diff_inherent_impls<'a, 'tcx>(changes: &mut ChangeSet<'tcx>,
fn diff_trait_impls<'a, 'tcx>(changes: &mut ChangeSet<'tcx>,
id_mapping: &IdMapping,
tcx: TyCtxt<'a, 'tcx, 'tcx>) {
use rustc::hir::def::Def;
let to_new = TranslationContext::target_new(tcx, id_mapping, false);
let to_old = TranslationContext::target_old(tcx, id_mapping, false);

for old_impl_def_id in tcx.all_trait_implementations(id_mapping.get_old_crate()).iter() {
let old_trait_def_id = tcx.impl_trait_ref(*old_impl_def_id).unwrap().def_id;

if !to_new.can_translate(old_trait_def_id) {
let old_impl_parent_def =
tcx.parent_def_id(*old_impl_def_id).and_then(|did| tcx.describe_def(did));
let old_impl_parent_is_fn = match old_impl_parent_def {
Some(Def::Fn(_)) | Some(Def::Method(_)) => true,
_ => false,
};

if !to_new.can_translate(old_trait_def_id) || old_impl_parent_is_fn {
continue;
}

Expand All @@ -875,7 +883,14 @@ fn diff_trait_impls<'a, 'tcx>(changes: &mut ChangeSet<'tcx>,
for new_impl_def_id in tcx.all_trait_implementations(id_mapping.get_new_crate()).iter() {
let new_trait_def_id = tcx.impl_trait_ref(*new_impl_def_id).unwrap().def_id;

if !to_old.can_translate(new_trait_def_id) {
let new_impl_parent_def =
tcx.parent_def_id(*new_impl_def_id).and_then(|did| tcx.describe_def(did));
let new_impl_parent_is_fn = match new_impl_parent_def {
Some(Def::Fn(_)) | Some(Def::Method(_)) => true,
_ => false,
};

if !to_old.can_translate(new_trait_def_id) || new_impl_parent_is_fn {
continue;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/cases/issue_34/new.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::marker::PhantomData;

pub fn missing_field<'de, V, E>() -> Result<V, E> {
#[allow(dead_code)]
struct MissingFieldDeserializer<E>(PhantomData<E>);

impl<E> Deserializer for MissingFieldDeserializer<E> {}
unimplemented!()
}

pub trait Deserializer {}
11 changes: 11 additions & 0 deletions tests/cases/issue_34/old.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::marker::PhantomData;

pub fn missing_field<'de, V, E>() -> Result<V, E> {
#[allow(dead_code)]
struct MissingFieldDeserializer<E>(PhantomData<E>);

impl<E> Deserializer for MissingFieldDeserializer<E> {}
unimplemented!()
}

pub trait Deserializer {}
1 change: 1 addition & 0 deletions tests/cases/issue_34/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version bump: 1.0.0 -> (patch) -> 1.0.1
1 change: 1 addition & 0 deletions tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ test!(func_local_items);
test!(infer);
test!(infer_regress);
test!(inherent_impls);
test!(issue_34);
test!(kind_change);
test!(macros);
test!(max_priv);
Expand Down

0 comments on commit cebffbc

Please sign in to comment.