1
Fork 0

Add note that str cannot be matched exhaustively

This commit is contained in:
Sebastian Toh 2023-08-27 20:14:56 +08:00
parent f320f42c59
commit a293619caa
4 changed files with 41 additions and 6 deletions

View file

@ -735,17 +735,21 @@ fn non_exhaustive_match<'p, 'tcx>(
collect_non_exhaustive_tys(&witnesses[0], &mut non_exhaustive_tys);
for ty in non_exhaustive_tys {
if ty == cx.tcx.types.usize || ty == cx.tcx.types.isize {
if ty.is_ptr_sized_integral() {
err.note(format!(
"`{ty}` does not have a fixed maximum value, so a wildcard `_` is necessary to match \
exhaustively",
));
exhaustively",
));
if cx.tcx.sess.is_nightly_build() {
err.help(format!(
"add `#![feature(precise_pointer_size_matching)]` to the crate attributes to \
enable precise `{ty}` matching",
));
"add `#![feature(precise_pointer_size_matching)]` to the crate attributes to \
enable precise `{ty}` matching",
));
}
} else if ty == cx.tcx.types.str_ {
err.note(format!(
"`{ty}` cannot be matched exhaustively, so a wildcard `_` is necessary",
));
}
}
}