Dogfood {exclusive,half-open} ranges in compiler (nfc)

In particular, this allows us to write more explicit matches that
avoid the pitfalls of using a fully general fall-through case, yet
remain fairly ergonomic. Less logic is in guard cases, more is in
the actual exhaustive case analysis.

No functional changes.
This commit is contained in:
Jubilee Young 2020-10-22 11:42:44 -07:00
parent a9cd294cf2
commit 0e88db7db4
6 changed files with 14 additions and 10 deletions

View File

@ -35,6 +35,8 @@
#![feature(never_type)]
#![feature(nll)]
#![feature(or_patterns)]
#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
#![recursion_limit = "256"]
#[macro_use]

View File

@ -250,13 +250,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
has_emitted
}
ty::Array(ty, len) => match len.try_eval_usize(cx.tcx, cx.param_env) {
// If the array is empty we don't lint, to avoid false positives
Some(0) | None => false,
// If the array is definitely non-empty, we can do `#[must_use]` checking.
Some(n) if n != 0 => {
Some(n) => {
let descr_pre = &format!("{}array{} of ", descr_pre, plural_suffix,);
check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, n as usize + 1)
}
// Otherwise, we don't lint, to avoid false positives.
_ => false,
},
ty::Closure(..) => {
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {

View File

@ -47,6 +47,8 @@
#![feature(associated_type_bounds)]
#![feature(rustc_attrs)]
#![feature(int_error_matching)]
#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
#![recursion_limit = "512"]
#[macro_use]

View File

@ -201,13 +201,13 @@ impl<'tcx> TyS<'tcx> {
),
Array(ty, len) => match len.try_eval_usize(tcx, param_env) {
Some(0) | None => DefIdForest::empty(),
// If the array is definitely non-empty, it's uninhabited if
// the type of its elements is uninhabited.
Some(n) if n != 0 => ty.uninhabited_from(tcx, param_env),
_ => DefIdForest::empty(),
Some(1..) => ty.uninhabited_from(tcx, param_env),
},
// References to uninitialised memory is valid for any type, including
// References to uninitialised memory are valid for any type, including
// uninhabited types, in unsafe code, so we treat all references as
// inhabited.
// The precise semantics of inhabitedness with respect to references is currently

View File

@ -1834,10 +1834,10 @@ impl<'tcx> TyS<'tcx> {
}
ty::Array(ty, len) => {
match len.try_eval_usize(tcx, ParamEnv::empty()) {
Some(0) | None => false,
// If the array is definitely non-empty, it's uninhabited if
// the type of its elements is uninhabited.
Some(n) if n != 0 => ty.conservative_is_privately_uninhabited(tcx),
_ => false,
Some(1..) => ty.conservative_is_privately_uninhabited(tcx),
}
}
ty::Ref(..) => {

View File

@ -153,14 +153,14 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
const SECONDARY_LIB_DIR: &str = "lib";
match option_env!("CFG_LIBDIR_RELATIVE") {
Some(libdir) if libdir != "lib" => libdir.into(),
_ => {
None | Some("lib") => {
if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
PRIMARY_LIB_DIR.into()
} else {
SECONDARY_LIB_DIR.into()
}
}
Some(libdir) => libdir.into(),
}
}