-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.rs
src/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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.)
@@ -200,16 +183,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
arms: &'tcx [hir::Arm<'tcx>], | |||
source: hir::MatchSource, | |||
) { | |||
if self.diverges.get().is_always() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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