Skip to content

Commit 2bded34

Browse files
committed
Auto merge of rust-lang#119363 - matthiaskrgr:rollup-o0ncmsn, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#119336 (coverage: Unexpand spans with `find_ancestor_inside_same_ctxt`) - rust-lang#119349 (refactor(liveness): move walk_expr outside of every match branch) - rust-lang#119359 (Simplify Parser::ident_or_error) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 89e2160 + aeed023 commit 2bded34

File tree

4 files changed

+12
-42
lines changed

4 files changed

+12
-42
lines changed

compiler/rustc_mir_transform/src/coverage/mod.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_middle::mir::{
2323
use rustc_middle::ty::TyCtxt;
2424
use rustc_span::def_id::LocalDefId;
2525
use rustc_span::source_map::SourceMap;
26-
use rustc_span::{ExpnKind, Span, Symbol};
26+
use rustc_span::{Span, Symbol};
2727

2828
/// Inserts `StatementKind::Coverage` statements that either instrument the binary with injected
2929
/// counters, via intrinsic `llvm.instrprof.increment`, and/or inject metadata used during codegen
@@ -346,21 +346,10 @@ fn get_body_span<'tcx>(
346346
let mut body_span = hir_body.value.span;
347347

348348
if tcx.is_closure(def_id.to_def_id()) {
349-
// If the MIR function is a closure, and if the closure body span
350-
// starts from a macro, but it's content is not in that macro, try
351-
// to find a non-macro callsite, and instrument the spans there
352-
// instead.
353-
loop {
354-
let expn_data = body_span.ctxt().outer_expn_data();
355-
if expn_data.is_root() {
356-
break;
357-
}
358-
if let ExpnKind::Macro { .. } = expn_data.kind {
359-
body_span = expn_data.call_site;
360-
} else {
361-
break;
362-
}
363-
}
349+
// If the current function is a closure, and its "body" span was created
350+
// by macro expansion or compiler desugaring, try to walk backwards to
351+
// the pre-expansion call site or body.
352+
body_span = body_span.source_callsite();
364353
}
365354

366355
body_span

compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,5 @@ fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option<Span> {
204204
/// etc.).
205205
#[inline]
206206
fn unexpand_into_body_span(span: Span, body_span: Span) -> Option<Span> {
207-
use rustc_span::source_map::original_sp;
208-
209-
// FIXME(#118525): Consider switching from `original_sp` to `Span::find_ancestor_inside`,
210-
// which is similar but gives slightly different results in some edge cases.
211-
let original_span = original_sp(span, body_span).with_ctxt(body_span.ctxt());
212-
body_span.contains(original_span).then_some(original_span)
207+
span.find_ancestor_inside_same_ctxt(body_span)
213208
}

compiler/rustc_parse/src/parser/mod.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -504,18 +504,10 @@ impl<'a> Parser<'a> {
504504
}
505505

506506
fn ident_or_err(&mut self, recover: bool) -> PResult<'a, (Ident, /* is_raw */ bool)> {
507-
let result = self.token.ident().ok_or_else(|| self.expected_ident_found(recover));
508-
509-
let (ident, is_raw) = match result {
510-
Ok(ident) => ident,
511-
Err(err) => match err {
512-
// we recovered!
513-
Ok(ident) => ident,
514-
Err(err) => return Err(err),
515-
},
516-
};
517-
518-
Ok((ident, is_raw))
507+
match self.token.ident() {
508+
Some(ident) => Ok(ident),
509+
None => self.expected_ident_found(recover),
510+
}
519511
}
520512

521513
/// Checks if the next token is `tok`, and returns `true` if so.

compiler/rustc_passes/src/liveness.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
405405
if let Res::Local(_var_hir_id) = path.res {
406406
self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id));
407407
}
408-
intravisit::walk_expr(self, expr);
409408
}
410409
hir::ExprKind::Closure(closure) => {
411410
// Interesting control flow (for loops can contain labeled
@@ -425,12 +424,10 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
425424
}));
426425
}
427426
self.set_captures(expr.hir_id, call_caps);
428-
intravisit::walk_expr(self, expr);
429427
}
430428

431429
hir::ExprKind::Let(let_expr) => {
432430
self.add_from_pat(let_expr.pat);
433-
intravisit::walk_expr(self, expr);
434431
}
435432

436433
// live nodes required for interesting control flow:
@@ -439,11 +436,9 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
439436
| hir::ExprKind::Loop(..)
440437
| hir::ExprKind::Yield(..) => {
441438
self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id));
442-
intravisit::walk_expr(self, expr);
443439
}
444440
hir::ExprKind::Binary(op, ..) if op.node.is_lazy() => {
445441
self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id));
446-
intravisit::walk_expr(self, expr);
447442
}
448443

449444
// otherwise, live nodes are not required:
@@ -474,10 +469,9 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
474469
| hir::ExprKind::Type(..)
475470
| hir::ExprKind::Err(_)
476471
| hir::ExprKind::Path(hir::QPath::TypeRelative(..))
477-
| hir::ExprKind::Path(hir::QPath::LangItem(..)) => {
478-
intravisit::walk_expr(self, expr);
479-
}
472+
| hir::ExprKind::Path(hir::QPath::LangItem(..)) => {}
480473
}
474+
intravisit::walk_expr(self, expr);
481475
}
482476
}
483477

0 commit comments

Comments
 (0)