Skip to content

Commit cebffbc

Browse files
committed
Fixed rust-lang#34.
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.
1 parent 4cd76f1 commit cebffbc

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

src/semcheck/traverse.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -854,13 +854,21 @@ fn diff_inherent_impls<'a, 'tcx>(changes: &mut ChangeSet<'tcx>,
854854
fn diff_trait_impls<'a, 'tcx>(changes: &mut ChangeSet<'tcx>,
855855
id_mapping: &IdMapping,
856856
tcx: TyCtxt<'a, 'tcx, 'tcx>) {
857+
use rustc::hir::def::Def;
857858
let to_new = TranslationContext::target_new(tcx, id_mapping, false);
858859
let to_old = TranslationContext::target_old(tcx, id_mapping, false);
859860

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

863-
if !to_new.can_translate(old_trait_def_id) {
864+
let old_impl_parent_def =
865+
tcx.parent_def_id(*old_impl_def_id).and_then(|did| tcx.describe_def(did));
866+
let old_impl_parent_is_fn = match old_impl_parent_def {
867+
Some(Def::Fn(_)) | Some(Def::Method(_)) => true,
868+
_ => false,
869+
};
870+
871+
if !to_new.can_translate(old_trait_def_id) || old_impl_parent_is_fn {
864872
continue;
865873
}
866874

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

878-
if !to_old.can_translate(new_trait_def_id) {
886+
let new_impl_parent_def =
887+
tcx.parent_def_id(*new_impl_def_id).and_then(|did| tcx.describe_def(did));
888+
let new_impl_parent_is_fn = match new_impl_parent_def {
889+
Some(Def::Fn(_)) | Some(Def::Method(_)) => true,
890+
_ => false,
891+
};
892+
893+
if !to_old.can_translate(new_trait_def_id) || new_impl_parent_is_fn {
879894
continue;
880895
}
881896

tests/cases/issue_34/new.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use std::marker::PhantomData;
2+
3+
pub fn missing_field<'de, V, E>() -> Result<V, E> {
4+
#[allow(dead_code)]
5+
struct MissingFieldDeserializer<E>(PhantomData<E>);
6+
7+
impl<E> Deserializer for MissingFieldDeserializer<E> {}
8+
unimplemented!()
9+
}
10+
11+
pub trait Deserializer {}

tests/cases/issue_34/old.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use std::marker::PhantomData;
2+
3+
pub fn missing_field<'de, V, E>() -> Result<V, E> {
4+
#[allow(dead_code)]
5+
struct MissingFieldDeserializer<E>(PhantomData<E>);
6+
7+
impl<E> Deserializer for MissingFieldDeserializer<E> {}
8+
unimplemented!()
9+
}
10+
11+
pub trait Deserializer {}

tests/cases/issue_34/stdout

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version bump: 1.0.0 -> (patch) -> 1.0.1

tests/examples.rs

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ test!(func_local_items);
109109
test!(infer);
110110
test!(infer_regress);
111111
test!(inherent_impls);
112+
test!(issue_34);
112113
test!(kind_change);
113114
test!(macros);
114115
test!(max_priv);

0 commit comments

Comments
 (0)