]> git.lizzy.rs Git - rust.git/commitdiff
add def-ids from nominal types into TraitSelect
authorNiko Matsakis <niko@alum.mit.edu>
Sat, 28 May 2016 01:19:11 +0000 (21:19 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Tue, 31 May 2016 23:59:57 +0000 (19:59 -0400)
This way we distinguish, in particular, `Foo: Sized`
and `Bar: Sized`, which fixes #33850.

src/librustc/ty/mod.rs
src/test/incremental/struct_add_field.rs
src/test/incremental/struct_change_field_name.rs
src/test/incremental/struct_change_field_type.rs
src/test/incremental/struct_change_field_type_cross_crate/b.rs
src/test/incremental/struct_remove_field.rs

index 423d57cfb328d4c110a2ffabb72e1f3c4c7197df..2a22e13d31ec4d6a99ba572d0d129e26b22fc1fd 100644 (file)
@@ -946,7 +946,28 @@ pub fn def_id(&self) -> DefId {
 
     /// Creates the dep-node for selecting/evaluating this trait reference.
     fn dep_node(&self) -> DepNode<DefId> {
-        DepNode::TraitSelect(self.def_id(), vec![])
+        // Ideally, the dep-node would just have all the input types
+        // in it.  But they are limited to including def-ids. So as an
+        // approximation we include the def-ids for all nominal types
+        // found somewhere. This means that we will e.g. conflate the
+        // dep-nodes for `u32: SomeTrait` and `u64: SomeTrait`, but we
+        // would have distinct dep-nodes for `Vec<u32>: SomeTrait`,
+        // `Rc<u32>: SomeTrait`, and `(Vec<u32>, Rc<u32>): SomeTrait`.
+        // Note that it's always sound to conflate dep-nodes, it jus
+        // leads to more recompilation.
+        let def_ids: Vec<_> =
+            self.input_types()
+                .iter()
+                .flat_map(|t| t.walk())
+                .filter_map(|t| match t.sty {
+                    ty::TyStruct(adt_def, _) |
+                    ty::TyEnum(adt_def, _) =>
+                        Some(adt_def.did),
+                    _ =>
+                        None
+                })
+                .collect();
+        DepNode::TraitSelect(self.def_id(), def_ids)
     }
 
     pub fn input_types(&self) -> &[Ty<'tcx>] {
index 425aa3e07a0ec6963deafb8ce70f5c50a4e3ad14..cc8ef8aedd77bbcf4472c882ba6f45a9f830e525 100644 (file)
@@ -40,7 +40,7 @@ pub fn use_EmbedX(embed: EmbedX) -> u32 {
     embed.x.x as u32
 }
 
-#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")] // FIXME(#33850) should be clean
+#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
 pub fn use_Y() {
     let x: Y = Y { y: 'c' };
 }
index cf6f89bd8a4c59db6d5be7bcb3c3adfba79fdc7c..fe29ad66b5fd8da5b8f4ee5621ef99cbfa251b17 100644 (file)
@@ -47,7 +47,7 @@ pub fn use_EmbedX(embed: EmbedX) -> u32 {
     //[cfail2]~^ ERROR attempted access of field `x`
 }
 
-#[rustc_dirty(label="TypeckItemBody", cfg="cfail2")] // FIXME(#33850) should be clean
+#[rustc_clean(label="TypeckItemBody", cfg="cfail2")]
 pub fn use_Y() {
     let x: Y = Y { y: 'c' };
 }
index 2bd61a3f559d45a622c8e6b1d59053f8727eef3a..1a50d515db6d07c08d568c23494b7279e2f9a19c 100644 (file)
@@ -45,7 +45,7 @@ pub fn use_EmbedX(x: EmbedX) -> u32 {
     x.x as u32
 }
 
-#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")] // FIXME(#33850) should be clean
+#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
 pub fn use_Y() {
     let x: Y = Y { y: 'c' };
 }
index 19f146ce176d74f5aa0166b61f61861225342bae..7a4900d1d9a903c5aedcd996ae4a13bdebaf87f6 100644 (file)
@@ -28,7 +28,7 @@ pub fn use_EmbedX(embed: EmbedX) -> u32 {
     embed.x.x as u32
 }
 
-#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")] // FIXME(#33850) should be clean
+#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
 pub fn use_Y() {
     let x: Y = Y { y: 'c' };
 }
index db49a7516275d24f3189ae08e5239d2fe97ddc2e..ae6399463b81b138ebb25adb4221b9875aaa48da 100644 (file)
@@ -44,7 +44,7 @@ pub fn use_EmbedX(embed: EmbedX) -> u32 {
     embed.x.x as u32
 }
 
-#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")] // FIXME(#33850) should be clean
+#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
 pub fn use_Y() {
     let x: Y = Y { y: 'c' };
 }