Skip to content

Commit c64a89b

Browse files
committed
Implemented more sane checks for breaking trait items. Fixes rust-lang#20.
1 parent 6fc7023 commit c64a89b

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/semcheck/changes.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,38 @@ impl<'tcx> Change<'tcx> {
322322
self.changes.push((type_, span));
323323
}
324324

325+
/// Check whether a trait item contains breaking changes preventing further analysis of it's
326+
/// child items.
327+
fn trait_item_breaking(&self) -> bool {
328+
for change in &self.changes {
329+
match change.0 {
330+
ItemMadePrivate |
331+
KindDifference |
332+
RegionParameterRemoved |
333+
TypeParameterRemoved { .. } |
334+
VariantAdded |
335+
VariantRemoved |
336+
VariantFieldAdded { .. } |
337+
VariantFieldRemoved { .. } |
338+
VariantStyleChanged { .. } |
339+
TypeChanged { .. } |
340+
FnConstChanged { now_const: false } |
341+
MethodSelfChanged { now_self: false } |
342+
Unknown => return true,
343+
RegionParameterAdded |
344+
MethodSelfChanged { now_self: true } |
345+
TraitItemAdded { .. } |
346+
TraitItemRemoved { .. } |
347+
ItemMadePublic |
348+
TypeParameterAdded { .. } |
349+
TraitUnsafetyChanged { .. } |
350+
FnConstChanged { now_const: true } => (),
351+
}
352+
}
353+
354+
false
355+
}
356+
325357
/// Get the change's category.
326358
fn to_category(&self) -> ChangeCategory {
327359
self.max.clone()
@@ -464,7 +496,16 @@ impl<'tcx> ChangeSet<'tcx> {
464496
// we only care about items that were present in both versions.
465497
self.changes
466498
.get(&old)
467-
.map(|changes| changes.to_category() == Breaking)
499+
.map(|change| change.to_category() == Breaking)
500+
.unwrap_or(false)
501+
}
502+
503+
/// Check whether a trait item contains breaking changes preventing further analysis of it's
504+
/// child items.
505+
pub fn trait_item_breaking(&self, old: DefId) -> bool {
506+
self.changes
507+
.get(&old)
508+
.map(|change| change.trait_item_breaking())
468509
.unwrap_or(false)
469510
}
470511

src/semcheck/traverse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ fn diff_types<'a, 'tcx>(changes: &mut ChangeSet<'tcx>,
543543

544544
if changes.item_breaking(old_def_id) ||
545545
id_mapping.get_trait_def(&old_def_id)
546-
.map_or(false, |did| changes.item_breaking(did)) {
546+
.map_or(false, |did| changes.trait_item_breaking(did)) {
547547
return;
548548
}
549549

tests/cases/traits/stdout

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ note: added defaulted item to trait (technically breaking)
3636
10 | | }
3737
| |_____^
3838

39+
warning: breaking changes in `test7`
40+
--> $REPO_PATH/tests/cases/traits/new.rs:11:5
41+
|
42+
11 | fn test7() -> u16;
43+
| ^^^^^^^^^^^^^^^^^^
44+
|
45+
= warning: type error: expected u8, found u16 (breaking)
46+
3947
warning: breaking changes in `test8`
4048
--> $REPO_PATH/tests/cases/traits/new.rs:12:5
4149
|

0 commit comments

Comments
 (0)