Skip to content

Commit e37d84b

Browse files
traviscrossehuss
authored andcommitted
Fix check for new and unexpected roots
We track the "roots" in our grammar -- those productions that aren't used in any other production. We want to report when a new root appears or when something that's expected to be a root no longer is one. However, we were reporting the latter case as the former instead of reporting it separately as intended. Let's fix that.
1 parent 1214d68 commit e37d84b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

mdbook-spec/src/grammar.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ fn check_unexpected_roots(grammar: &Grammar, diag: &mut Diagnostics) {
200200
.into_iter()
201201
.collect();
202202
if set != expected {
203-
let new: Vec<_> = set.symmetric_difference(&expected).collect();
204-
let removed: Vec<_> = expected.symmetric_difference(&set).collect();
203+
let new: Vec<_> = set.difference(&expected).collect();
205204
if !new.is_empty() {
206205
warn_or_err!(
207206
diag,
@@ -210,15 +209,15 @@ fn check_unexpected_roots(grammar: &Grammar, diag: &mut Diagnostics) {
210209
If not, make sure it is spelled correctly and used in another production.\n\
211210
The new names are: {new:?}\n"
212211
);
213-
} else if !removed.is_empty() {
212+
}
213+
let removed: Vec<_> = expected.difference(&set).collect();
214+
if !removed.is_empty() {
214215
warn_or_err!(
215216
diag,
216217
"Old grammar production root seems to have been removed.\n\
217218
If this is expected, remove it from the `check_unexpected_roots` function.\n\
218219
The removed names are: {removed:?}\n"
219220
);
220-
} else {
221-
unreachable!("unexpected");
222221
}
223222
}
224223
}

0 commit comments

Comments
 (0)