Skip to content

Commit 029e261

Browse files
committed
rustc/ty: simplify common patterns
1 parent 91fc573 commit 029e261

File tree

6 files changed

+25
-41
lines changed

6 files changed

+25
-41
lines changed

src/librustc/ty/context.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,13 @@ impl<'tcx> TypeckTables<'tcx> {
540540
}
541541

542542
pub fn node_id_to_type(&self, id: hir::HirId) -> Ty<'tcx> {
543-
match self.node_id_to_type_opt(id) {
544-
Some(ty) => ty,
545-
None => {
546-
bug!("node_id_to_type: no type for node `{}`",
547-
tls::with(|tcx| {
548-
let id = tcx.hir.hir_to_node_id(id);
549-
tcx.hir.node_to_string(id)
550-
}))
551-
}
552-
}
543+
self.node_id_to_type_opt(id).unwrap_or_else(||
544+
bug!("node_id_to_type: no type for node `{}`",
545+
tls::with(|tcx| {
546+
let id = tcx.hir.hir_to_node_id(id);
547+
tcx.hir.node_to_string(id)
548+
}))
549+
)
553550
}
554551

555552
pub fn node_id_to_type_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {

src/librustc/ty/error.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
252252
db.note("no two closures, even if identical, have the same type");
253253
db.help("consider boxing your closure and/or using it as a trait object");
254254
}
255-
match (&values.found.sty, &values.expected.sty) { // Issue #53280
256-
(ty::Infer(ty::IntVar(_)), ty::Float(_)) => {
257-
if let Ok(snippet) = self.sess.source_map().span_to_snippet(sp) {
258-
if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') {
259-
db.span_suggestion_with_applicability(
260-
sp,
261-
"use a float literal",
262-
format!("{}.0", snippet),
263-
Applicability::MachineApplicable
264-
);
265-
}
255+
if let (ty::Infer(ty::IntVar(_)), ty::Float(_)) =
256+
(&values.found.sty, &values.expected.sty) // Issue #53280
257+
{
258+
if let Ok(snippet) = self.sess.source_map().span_to_snippet(sp) {
259+
if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') {
260+
db.span_suggestion_with_applicability(
261+
sp,
262+
"use a float literal",
263+
format!("{}.0", snippet),
264+
Applicability::MachineApplicable
265+
);
266266
}
267-
},
268-
_ => {}
267+
}
269268
}
270269
},
271270
OldStyleLUB(err) => {

src/librustc/ty/flags.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ impl FlagComputation {
6262
let outer_exclusive_binder = computation.outer_exclusive_binder;
6363
if outer_exclusive_binder > ty::INNERMOST {
6464
self.add_exclusive_binder(outer_exclusive_binder.shifted_out(1));
65-
} else {
66-
// otherwise, this binder captures nothing
67-
}
65+
} // otherwise, this binder captures nothing
6866
}
6967

7068
fn add_sty(&mut self, st: &ty::TyKind<'_>) {

src/librustc/ty/inhabitedness/def_id_forest.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
6666
tcx: TyCtxt<'a, 'gcx, 'tcx>,
6767
id: DefId) -> bool
6868
{
69-
for root_id in self.root_ids.iter() {
70-
if tcx.is_descendant_of(id, *root_id) {
71-
return true;
72-
}
73-
}
74-
false
69+
self.root_ids.iter().any(|root_id| tcx.is_descendant_of(id, *root_id))
7570
}
7671

7772
/// Calculate the intersection of a collection of forests.

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ impl<'sess> OnDiskCache<'sess> {
441441
tcx.dep_graph.with_ignore(|| {
442442
let current_cnums = tcx.all_crate_nums(LOCAL_CRATE).iter().map(|&cnum| {
443443
let crate_name = tcx.original_crate_name(cnum)
444-
.as_str()
445444
.to_string();
446445
let crate_disambiguator = tcx.crate_disambiguator(cnum);
447446
((crate_name, crate_disambiguator), cnum)

src/librustc/ty/query/plumbing.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,8 @@ macro_rules! define_queries_inner {
753753
}
754754
// The def_span query is used to calculate default_span,
755755
// so exit to avoid infinite recursion
756-
match *self {
757-
Query::def_span(..) => return span,
758-
_ => ()
756+
if let Query::def_span(..) = *self {
757+
return span
759758
}
760759
match *self {
761760
$(Query::$name(key) => key.default_span(tcx),)*
@@ -1028,13 +1027,10 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
10281027
)
10291028
);
10301029

1031-
match tcx.force_query::<::ty::query::queries::$query<'_>>(
1030+
if let Err(e) = tcx.force_query::<::ty::query::queries::$query<'_>>(
10321031
$key, DUMMY_SP, *dep_node
10331032
) {
1034-
Ok(_) => {},
1035-
Err(e) => {
1036-
tcx.report_cycle(e).emit();
1037-
}
1033+
tcx.report_cycle(e).emit();
10381034
}
10391035
}
10401036
}

0 commit comments

Comments
 (0)