typeck: simplify the handling of diverges#68422
Conversation
| let scrut_diverges = self.diverges.get(); | ||
| self.diverges.set(Diverges::Maybe); | ||
| // Otherwise, we have to union together the types that the arms produce and so forth. | ||
| let scrut_diverges = self.diverges.replace(Diverges::Maybe); |
There was a problem hiding this comment.
Ohh, we might have more similar places where we use get and set, predating Cell::replace.
I found some in these two files, if someone wants to take them:
src/librustc/ty/print/pretty.rssrc/librustc/infer/mod.rs
(there's others, but they use the result of get() to compute the value to set, and I don't think we have a nice abstraction for that)
| // #55810: Type check patterns first so we get types for all bindings. | ||
| for arm in arms { | ||
| self.check_pat_top(&arm.pat, scrut_ty, Some(scrut.span), true); | ||
| } |
There was a problem hiding this comment.
I assume "they're now subsumed by unreachable_patterns warnings" in the deleted comment is why you can do this change now?
There was a problem hiding this comment.
Filed #68429.
(To recap what I said in private: check/pat.rs does not mention diverges, except indirectly by type checking expressions, which only occur in literals and range patterns, but those cannot be typed at a diverging type, so removing this code has no effect.)
| arms: &'tcx [hir::Arm<'tcx>], | ||
| source: hir::MatchSource, | ||
| ) { | ||
| if self.diverges.get().is_always() { |
There was a problem hiding this comment.
I think this was a performance microopt?
|
@bors r+ |
|
📌 Commit 7dceff9 has been approved by |
typeck: simplify the handling of `diverges` Some drive-by cleanup while working on `hir::ExprKind::Let`. Ostensibly, this has some perf benefits due to reduced allocation and whatnot as well. r? @eddyb
typeck: simplify the handling of `diverges` Some drive-by cleanup while working on `hir::ExprKind::Let`. Ostensibly, this has some perf benefits due to reduced allocation and whatnot as well. r? @eddyb
Some drive-by cleanup while working on
hir::ExprKind::Let.Ostensibly, this has some perf benefits due to reduced allocation and whatnot as well.
r? @eddyb