Skip to content

Commit 0004b3b

Browse files
committed
Auto merge of #111960 - compiler-errors:rollup-onka2dl, r=compiler-errors
Rollup of 7 pull requests Successful merges: - #107522 (Add Median of Medians fallback to introselect) - #111152 (update `pulldown-cmark` to `0.9.3`) - #111757 (Consider lint check attributes on match arms) - #111831 (Always capture slice when pattern requires checking the length) - #111929 (Don't print newlines in APITs) - #111945 (Migrate GUI colors test to original CSS color format) - #111950 (Remove ExpnKind::Inlined.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a2b1646 + c2e3521 commit 0004b3b

File tree

37 files changed

+856
-411
lines changed

37 files changed

+856
-411
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2779,9 +2779,9 @@ dependencies = [
27792779

27802780
[[package]]
27812781
name = "pulldown-cmark"
2782-
version = "0.9.2"
2782+
version = "0.9.3"
27832783
source = "registry+https://github.com/rust-lang/crates.io-index"
2784-
checksum = "2d9cc634bc78768157b5cbfe988ffcd1dcba95cd2b2f03a88316c08c6d00ed63"
2784+
checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998"
27852785
dependencies = [
27862786
"bitflags",
27872787
"memchr",

compiler/rustc_ast_lowering/src/lib.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14251425
DefPathData::ImplTrait,
14261426
span,
14271427
);
1428-
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
1428+
1429+
// HACK: pprust breaks strings with newlines when the type
1430+
// gets too long. We don't want these to show up in compiler
1431+
// output or built artifacts, so replace them here...
1432+
// Perhaps we should instead format APITs more robustly.
1433+
let ident = Ident::from_str_and_span(
1434+
&pprust::ty_to_string(t).replace('\n', " "),
1435+
span,
1436+
);
1437+
14291438
let (param, bounds, path) = self.lower_universal_param_and_bounds(
14301439
*def_node_id,
14311440
span,

compiler/rustc_codegen_cranelift/src/common.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
413413

414414
// Note: must be kept in sync with get_caller_location from cg_ssa
415415
pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> {
416-
let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, mut span: Span| {
417-
// Remove `Inlined` marks as they pollute `expansion_cause`.
418-
while span.is_inlined() {
419-
span.remove_mark();
420-
}
416+
let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| {
421417
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
422418
let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo());
423419
let const_loc = fx.tcx.const_caller_location((

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1450,11 +1450,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14501450
) -> OperandRef<'tcx, Bx::Value> {
14511451
let tcx = bx.tcx();
14521452

1453-
let mut span_to_caller_location = |mut span: Span| {
1454-
// Remove `Inlined` marks as they pollute `expansion_cause`.
1455-
while span.is_inlined() {
1456-
span.remove_mark();
1457-
}
1453+
let mut span_to_caller_location = |span: Span| {
14581454
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
14591455
let caller = tcx.sess.source_map().lookup_char_pos(topmost.lo());
14601456
let const_loc = tcx.const_caller_location((

compiler/rustc_const_eval/src/interpret/eval_context.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
949949
// This deliberately does *not* honor `requires_caller_location` since it is used for much
950950
// more than just panics.
951951
for frame in stack.iter().rev() {
952-
let span = frame.current_span();
952+
let span = match frame.loc {
953+
Left(loc) => {
954+
// If the stacktrace passes through MIR-inlined source scopes, add them.
955+
let mir::SourceInfo { mut span, scope } = *frame.body.source_info(loc);
956+
let mut scope_data = &frame.body.source_scopes[scope];
957+
while let Some((instance, call_span)) = scope_data.inlined {
958+
frames.push(FrameInfo { span, instance });
959+
span = call_span;
960+
scope_data = &frame.body.source_scopes[scope_data.parent_scope.unwrap()];
961+
}
962+
span
963+
}
964+
Right(span) => span,
965+
};
953966
frames.push(FrameInfo { span, instance: frame.instance });
954967
}
955968
trace!("generate stacktrace: {:#?}", frames);

compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
111111
location
112112
}
113113

114-
pub(crate) fn location_triple_for_span(&self, mut span: Span) -> (Symbol, u32, u32) {
115-
// Remove `Inlined` marks as they pollute `expansion_cause`.
116-
while span.is_inlined() {
117-
span.remove_mark();
118-
}
114+
pub(crate) fn location_triple_for_span(&self, span: Span) -> (Symbol, u32, u32) {
119115
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
120116
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
121117
(

compiler/rustc_errors/src/emitter.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pub trait Emitter: Translate {
332332

333333
// Skip past non-macro entries, just in case there
334334
// are some which do actually involve macros.
335-
ExpnKind::Inlined | ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
335+
ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
336336

337337
ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
338338
}
@@ -403,7 +403,7 @@ pub trait Emitter: Translate {
403403
continue;
404404
}
405405

406-
if always_backtrace && !matches!(trace.kind, ExpnKind::Inlined) {
406+
if always_backtrace {
407407
new_labels.push((
408408
trace.def_site,
409409
format!(
@@ -442,7 +442,6 @@ pub trait Emitter: Translate {
442442
"this derive macro expansion".into()
443443
}
444444
ExpnKind::Macro(MacroKind::Bang, _) => "this macro invocation".into(),
445-
ExpnKind::Inlined => "this inlined function call".into(),
446445
ExpnKind::Root => "the crate root".into(),
447446
ExpnKind::AstPass(kind) => kind.descr().into(),
448447
ExpnKind::Desugaring(kind) => {

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,19 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
438438
// to borrow discr.
439439
needs_to_be_read = true;
440440
}
441-
PatKind::Or(_)
442-
| PatKind::Box(_)
443-
| PatKind::Slice(..)
444-
| PatKind::Ref(..)
445-
| PatKind::Wild => {
446-
// If the PatKind is Or, Box, Slice or Ref, the decision is made later
441+
PatKind::Slice(lhs, wild, rhs) => {
442+
// We don't need to test the length if the pattern is `[..]`
443+
if matches!((lhs, wild, rhs), (&[], Some(_), &[]))
444+
// Arrays have a statically known size, so
445+
// there is no need to read their length
446+
|| discr_place.place.base_ty.is_array()
447+
{
448+
} else {
449+
needs_to_be_read = true;
450+
}
451+
}
452+
PatKind::Or(_) | PatKind::Box(_) | PatKind::Ref(..) | PatKind::Wild => {
453+
// If the PatKind is Or, Box, or Ref, the decision is made later
447454
// as these patterns contains subpatterns
448455
// If the PatKind is Wild, the decision is made based on the other patterns being
449456
// examined

compiler/rustc_lint/src/late.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,10 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
240240
}
241241

242242
fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) {
243-
lint_callback!(self, check_arm, a);
244-
hir_visit::walk_arm(self, a);
243+
self.with_lint_attrs(a.hir_id, |cx| {
244+
lint_callback!(cx, check_arm, a);
245+
hir_visit::walk_arm(cx, a);
246+
})
245247
}
246248

247249
fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) {

compiler/rustc_middle/src/lint.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ pub fn struct_lint_level(
468468
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
469469
let expn_data = span.ctxt().outer_expn_data();
470470
match expn_data.kind {
471-
ExpnKind::Inlined
472-
| ExpnKind::Root
471+
ExpnKind::Root
473472
| ExpnKind::Desugaring(
474473
DesugaringKind::ForLoop | DesugaringKind::WhileLoop | DesugaringKind::OpaqueTy,
475474
) => false,

compiler/rustc_middle/src/ty/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2488,9 +2488,7 @@ impl<'tcx> TyCtxt<'tcx> {
24882488
&& if self.features().collapse_debuginfo {
24892489
span.in_macro_expansion_with_collapse_debuginfo()
24902490
} else {
2491-
// Inlined spans should not be collapsed as that leads to all of the
2492-
// inlined code being attributed to the inline callsite.
2493-
span.from_expansion() && !span.is_inlined()
2491+
span.from_expansion()
24942492
}
24952493
}
24962494

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+35-23
Original file line numberDiff line numberDiff line change
@@ -90,35 +90,34 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for MatchVisitor<'a, '_, 'tcx> {
9090

9191
#[instrument(level = "trace", skip(self))]
9292
fn visit_arm(&mut self, arm: &Arm<'tcx>) {
93-
match arm.guard {
94-
Some(Guard::If(expr)) => {
95-
self.with_let_source(LetSource::IfLetGuard, |this| {
96-
this.visit_expr(&this.thir[expr])
97-
});
98-
}
99-
Some(Guard::IfLet(ref pat, expr)) => {
100-
self.with_let_source(LetSource::IfLetGuard, |this| {
101-
this.check_let(pat, expr, LetSource::IfLetGuard, pat.span);
102-
this.visit_pat(pat);
103-
this.visit_expr(&this.thir[expr]);
104-
});
93+
self.with_lint_level(arm.lint_level, |this| {
94+
match arm.guard {
95+
Some(Guard::If(expr)) => {
96+
this.with_let_source(LetSource::IfLetGuard, |this| {
97+
this.visit_expr(&this.thir[expr])
98+
});
99+
}
100+
Some(Guard::IfLet(ref pat, expr)) => {
101+
this.with_let_source(LetSource::IfLetGuard, |this| {
102+
this.check_let(pat, expr, LetSource::IfLetGuard, pat.span);
103+
this.visit_pat(pat);
104+
this.visit_expr(&this.thir[expr]);
105+
});
106+
}
107+
None => {}
105108
}
106-
None => {}
107-
}
108-
self.visit_pat(&arm.pattern);
109-
self.visit_expr(&self.thir[arm.body]);
109+
this.visit_pat(&arm.pattern);
110+
this.visit_expr(&self.thir[arm.body]);
111+
});
110112
}
111113

112114
#[instrument(level = "trace", skip(self))]
113115
fn visit_expr(&mut self, ex: &Expr<'tcx>) {
114116
match ex.kind {
115117
ExprKind::Scope { value, lint_level, .. } => {
116-
let old_lint_level = self.lint_level;
117-
if let LintLevel::Explicit(hir_id) = lint_level {
118-
self.lint_level = hir_id;
119-
}
120-
self.visit_expr(&self.thir[value]);
121-
self.lint_level = old_lint_level;
118+
self.with_lint_level(lint_level, |this| {
119+
this.visit_expr(&this.thir[value]);
120+
});
122121
return;
123122
}
124123
ExprKind::If { cond, then, else_opt, if_then_scope: _ } => {
@@ -190,6 +189,17 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
190189
self.let_source = old_let_source;
191190
}
192191

192+
fn with_lint_level(&mut self, new_lint_level: LintLevel, f: impl FnOnce(&mut Self)) {
193+
if let LintLevel::Explicit(hir_id) = new_lint_level {
194+
let old_lint_level = self.lint_level;
195+
self.lint_level = hir_id;
196+
f(self);
197+
self.lint_level = old_lint_level;
198+
} else {
199+
f(self);
200+
}
201+
}
202+
193203
fn check_patterns(&self, pat: &Pat<'tcx>, rf: RefutableFlag) {
194204
pat.walk_always(|pat| check_borrow_conflicts_in_at_patterns(self, pat));
195205
check_for_bindings_named_same_as_variants(self, pat, rf);
@@ -236,7 +246,9 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
236246
for &arm in arms {
237247
// Check the arm for some things unrelated to exhaustiveness.
238248
let arm = &self.thir.arms[arm];
239-
self.check_patterns(&arm.pattern, Refutable);
249+
self.with_lint_level(arm.lint_level, |this| {
250+
this.check_patterns(&arm.pattern, Refutable);
251+
});
240252
}
241253

242254
let tarms: Vec<_> = arms

compiler/rustc_mir_transform/src/inline.rs

-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_middle::mir::*;
1010
use rustc_middle::ty::TypeVisitableExt;
1111
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
1212
use rustc_session::config::OptLevel;
13-
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
1413
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
1514
use rustc_target::spec::abi::Abi;
1615

@@ -551,16 +550,6 @@ impl<'tcx> Inliner<'tcx> {
551550
// Copy the arguments if needed.
552551
let args: Vec<_> = self.make_call_args(args, &callsite, caller_body, &callee_body);
553552

554-
let mut expn_data = ExpnData::default(
555-
ExpnKind::Inlined,
556-
callsite.source_info.span,
557-
self.tcx.sess.edition(),
558-
None,
559-
None,
560-
);
561-
expn_data.def_site = callee_body.span;
562-
let expn_data =
563-
self.tcx.with_stable_hashing_context(|hcx| LocalExpnId::fresh(expn_data, hcx));
564553
let mut integrator = Integrator {
565554
args: &args,
566555
new_locals: Local::new(caller_body.local_decls.len())..,
@@ -572,7 +561,6 @@ impl<'tcx> Inliner<'tcx> {
572561
cleanup_block: unwind,
573562
in_cleanup_block: false,
574563
tcx: self.tcx,
575-
expn_data,
576564
always_live_locals: BitSet::new_filled(callee_body.local_decls.len()),
577565
};
578566

@@ -956,7 +944,6 @@ struct Integrator<'a, 'tcx> {
956944
cleanup_block: UnwindAction,
957945
in_cleanup_block: bool,
958946
tcx: TyCtxt<'tcx>,
959-
expn_data: LocalExpnId,
960947
always_live_locals: BitSet<Local>,
961948
}
962949

@@ -1042,11 +1029,6 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
10421029
*scope = self.map_scope(*scope);
10431030
}
10441031

1045-
fn visit_span(&mut self, span: &mut Span) {
1046-
// Make sure that all spans track the fact that they were inlined.
1047-
*span = span.fresh_expansion(self.expn_data);
1048-
}
1049-
10501032
fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
10511033
self.in_cleanup_block = data.is_cleanup;
10521034
self.super_basic_block_data(block, data);

compiler/rustc_resolve/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
bitflags = "1.2.1"
10-
pulldown-cmark = { version = "0.9.2", default-features = false }
10+
pulldown-cmark = { version = "0.9.3", default-features = false }
1111
rustc_arena = { path = "../rustc_arena" }
1212
rustc_ast = { path = "../rustc_ast" }
1313
rustc_ast_pretty = { path = "../rustc_ast_pretty" }

compiler/rustc_span/src/hygiene.rs

-4
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ impl ExpnId {
320320
// Stop going up the backtrace once include! is encountered
321321
if expn_data.is_root()
322322
|| expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include)
323-
|| expn_data.kind == ExpnKind::Inlined
324323
{
325324
break;
326325
}
@@ -1058,8 +1057,6 @@ pub enum ExpnKind {
10581057
AstPass(AstPass),
10591058
/// Desugaring done by the compiler during HIR lowering.
10601059
Desugaring(DesugaringKind),
1061-
/// MIR inlining
1062-
Inlined,
10631060
}
10641061

10651062
impl ExpnKind {
@@ -1073,7 +1070,6 @@ impl ExpnKind {
10731070
},
10741071
ExpnKind::AstPass(kind) => kind.descr().to_string(),
10751072
ExpnKind::Desugaring(kind) => format!("desugaring of {}", kind.descr()),
1076-
ExpnKind::Inlined => "inlined source".to_string(),
10771073
}
10781074
}
10791075
}

compiler/rustc_span/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,6 @@ impl Span {
594594
matches!(outer_expn.kind, ExpnKind::Macro(..)) && outer_expn.collapse_debuginfo
595595
}
596596

597-
/// Returns `true` if this span comes from MIR inlining.
598-
pub fn is_inlined(self) -> bool {
599-
let outer_expn = self.ctxt().outer_expn_data();
600-
matches!(outer_expn.kind, ExpnKind::Inlined)
601-
}
602-
603597
/// Returns `true` if `span` originates in a derive-macro's expansion.
604598
pub fn in_derive_expansion(self) -> bool {
605599
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))

library/core/src/slice/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ mod index;
4242
mod iter;
4343
mod raw;
4444
mod rotate;
45+
mod select;
4546
mod specialize;
4647

4748
#[unstable(feature = "str_internals", issue = "none")]
@@ -3034,7 +3035,7 @@ impl<T> [T] {
30343035
where
30353036
T: Ord,
30363037
{
3037-
sort::partition_at_index(self, index, T::lt)
3038+
select::partition_at_index(self, index, T::lt)
30383039
}
30393040

30403041
/// Reorder the slice with a comparator function such that the element at `index` is at its
@@ -3089,7 +3090,7 @@ impl<T> [T] {
30893090
where
30903091
F: FnMut(&T, &T) -> Ordering,
30913092
{
3092-
sort::partition_at_index(self, index, |a: &T, b: &T| compare(a, b) == Less)
3093+
select::partition_at_index(self, index, |a: &T, b: &T| compare(a, b) == Less)
30933094
}
30943095

30953096
/// Reorder the slice with a key extraction function such that the element at `index` is at its
@@ -3145,7 +3146,7 @@ impl<T> [T] {
31453146
F: FnMut(&T) -> K,
31463147
K: Ord,
31473148
{
3148-
sort::partition_at_index(self, index, |a: &T, b: &T| f(a).lt(&f(b)))
3149+
select::partition_at_index(self, index, |a: &T, b: &T| f(a).lt(&f(b)))
31493150
}
31503151

31513152
/// Moves all consecutive repeated elements to the end of the slice according to the

0 commit comments

Comments
 (0)