Skip to content

Commit 0e88db7

Browse files
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.
1 parent a9cd294 commit 0e88db7

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

compiler/rustc_lint/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#![feature(never_type)]
3636
#![feature(nll)]
3737
#![feature(or_patterns)]
38+
#![feature(half_open_range_patterns)]
39+
#![feature(exclusive_range_pattern)]
3840
#![recursion_limit = "256"]
3941

4042
#[macro_use]

compiler/rustc_lint/src/unused.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
250250
has_emitted
251251
}
252252
ty::Array(ty, len) => match len.try_eval_usize(cx.tcx, cx.param_env) {
253+
// If the array is empty we don't lint, to avoid false positives
254+
Some(0) | None => false,
253255
// If the array is definitely non-empty, we can do `#[must_use]` checking.
254-
Some(n) if n != 0 => {
256+
Some(n) => {
255257
let descr_pre = &format!("{}array{} of ", descr_pre, plural_suffix,);
256258
check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, n as usize + 1)
257259
}
258-
// Otherwise, we don't lint, to avoid false positives.
259-
_ => false,
260260
},
261261
ty::Closure(..) => {
262262
cx.struct_span_lint(UNUSED_MUST_USE, span, |lint| {

compiler/rustc_middle/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#![feature(associated_type_bounds)]
4848
#![feature(rustc_attrs)]
4949
#![feature(int_error_matching)]
50+
#![feature(half_open_range_patterns)]
51+
#![feature(exclusive_range_pattern)]
5052
#![recursion_limit = "512"]
5153

5254
#[macro_use]

compiler/rustc_middle/src/ty/inhabitedness/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ impl<'tcx> TyS<'tcx> {
201201
),
202202

203203
Array(ty, len) => match len.try_eval_usize(tcx, param_env) {
204+
Some(0) | None => DefIdForest::empty(),
204205
// If the array is definitely non-empty, it's uninhabited if
205206
// the type of its elements is uninhabited.
206-
Some(n) if n != 0 => ty.uninhabited_from(tcx, param_env),
207-
_ => DefIdForest::empty(),
207+
Some(1..) => ty.uninhabited_from(tcx, param_env),
208208
},
209209

210-
// References to uninitialised memory is valid for any type, including
210+
// References to uninitialised memory are valid for any type, including
211211
// uninhabited types, in unsafe code, so we treat all references as
212212
// inhabited.
213213
// The precise semantics of inhabitedness with respect to references is currently

compiler/rustc_middle/src/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1834,10 +1834,10 @@ impl<'tcx> TyS<'tcx> {
18341834
}
18351835
ty::Array(ty, len) => {
18361836
match len.try_eval_usize(tcx, ParamEnv::empty()) {
1837+
Some(0) | None => false,
18371838
// If the array is definitely non-empty, it's uninhabited if
18381839
// the type of its elements is uninhabited.
1839-
Some(n) if n != 0 => ty.conservative_is_privately_uninhabited(tcx),
1840-
_ => false,
1840+
Some(1..) => ty.conservative_is_privately_uninhabited(tcx),
18411841
}
18421842
}
18431843
ty::Ref(..) => {

compiler/rustc_session/src/filesearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
153153
const SECONDARY_LIB_DIR: &str = "lib";
154154

155155
match option_env!("CFG_LIBDIR_RELATIVE") {
156-
Some(libdir) if libdir != "lib" => libdir.into(),
157-
_ => {
156+
None | Some("lib") => {
158157
if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
159158
PRIMARY_LIB_DIR.into()
160159
} else {
161160
SECONDARY_LIB_DIR.into()
162161
}
163162
}
163+
Some(libdir) => libdir.into(),
164164
}
165165
}
166166

0 commit comments

Comments
 (0)