Skip to content

Commit 4038b5b

Browse files
committed
add def-ids from nominal types into TraitSelect
This way we distinguish, in particular, `Foo: Sized` and `Bar: Sized`, which fixes #33850.
1 parent 63bb084 commit 4038b5b

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

src/librustc/ty/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,28 @@ impl<'tcx> TraitPredicate<'tcx> {
946946

947947
/// Creates the dep-node for selecting/evaluating this trait reference.
948948
fn dep_node(&self) -> DepNode<DefId> {
949-
DepNode::TraitSelect(self.def_id(), vec![])
949+
// Ideally, the dep-node would just have all the input types
950+
// in it. But they are limited to including def-ids. So as an
951+
// approximation we include the def-ids for all nominal types
952+
// found somewhere. This means that we will e.g. conflate the
953+
// dep-nodes for `u32: SomeTrait` and `u64: SomeTrait`, but we
954+
// would have distinct dep-nodes for `Vec<u32>: SomeTrait`,
955+
// `Rc<u32>: SomeTrait`, and `(Vec<u32>, Rc<u32>): SomeTrait`.
956+
// Note that it's always sound to conflate dep-nodes, it jus
957+
// leads to more recompilation.
958+
let def_ids: Vec<_> =
959+
self.input_types()
960+
.iter()
961+
.flat_map(|t| t.walk())
962+
.filter_map(|t| match t.sty {
963+
ty::TyStruct(adt_def, _) |
964+
ty::TyEnum(adt_def, _) =>
965+
Some(adt_def.did),
966+
_ =>
967+
None
968+
})
969+
.collect();
970+
DepNode::TraitSelect(self.def_id(), def_ids)
950971
}
951972

952973
pub fn input_types(&self) -> &[Ty<'tcx>] {

src/test/incremental/struct_add_field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn use_EmbedX(embed: EmbedX) -> u32 {
4040
embed.x.x as u32
4141
}
4242

43-
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")] // FIXME(#33850) should be clean
43+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
4444
pub fn use_Y() {
4545
let x: Y = Y { y: 'c' };
4646
}

src/test/incremental/struct_change_field_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn use_EmbedX(embed: EmbedX) -> u32 {
4747
//[cfail2]~^ ERROR attempted access of field `x`
4848
}
4949

50-
#[rustc_dirty(label="TypeckItemBody", cfg="cfail2")] // FIXME(#33850) should be clean
50+
#[rustc_clean(label="TypeckItemBody", cfg="cfail2")]
5151
pub fn use_Y() {
5252
let x: Y = Y { y: 'c' };
5353
}

src/test/incremental/struct_change_field_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn use_EmbedX(x: EmbedX) -> u32 {
4545
x.x as u32
4646
}
4747

48-
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")] // FIXME(#33850) should be clean
48+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
4949
pub fn use_Y() {
5050
let x: Y = Y { y: 'c' };
5151
}

src/test/incremental/struct_change_field_type_cross_crate/b.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn use_EmbedX(embed: EmbedX) -> u32 {
2828
embed.x.x as u32
2929
}
3030

31-
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")] // FIXME(#33850) should be clean
31+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
3232
pub fn use_Y() {
3333
let x: Y = Y { y: 'c' };
3434
}

src/test/incremental/struct_remove_field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn use_EmbedX(embed: EmbedX) -> u32 {
4444
embed.x.x as u32
4545
}
4646

47-
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")] // FIXME(#33850) should be clean
47+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
4848
pub fn use_Y() {
4949
let x: Y = Y { y: 'c' };
5050
}

0 commit comments

Comments
 (0)