Skip to content

Commit

Permalink
Auto merge of #111960 - compiler-errors:rollup-onka2dl, r=compiler-er…
Browse files Browse the repository at this point in the history
…rors

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
  • Loading branch information
bors committed May 25, 2023
2 parents a2b1646 + c2e3521 commit 0004b3b
Show file tree
Hide file tree
Showing 37 changed files with 856 additions and 411 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2779,9 +2779,9 @@ dependencies = [

[[package]]
name = "pulldown-cmark"
version = "0.9.2"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d9cc634bc78768157b5cbfe988ffcd1dcba95cd2b2f03a88316c08c6d00ed63"
checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998"
dependencies = [
"bitflags",
"memchr",
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
DefPathData::ImplTrait,
span,
);
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);

// HACK: pprust breaks strings with newlines when the type
// gets too long. We don't want these to show up in compiler
// output or built artifacts, so replace them here...
// Perhaps we should instead format APITs more robustly.
let ident = Ident::from_str_and_span(
&pprust::ty_to_string(t).replace('\n', " "),
span,
);

let (param, bounds, path) = self.lower_universal_param_and_bounds(
*def_node_id,
span,
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_cranelift/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {

// Note: must be kept in sync with get_caller_location from cg_ssa
pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> {
let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, mut span: Span| {
// Remove `Inlined` marks as they pollute `expansion_cause`.
while span.is_inlined() {
span.remove_mark();
}
let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| {
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo());
let const_loc = fx.tcx.const_caller_location((
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,11 +1450,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
) -> OperandRef<'tcx, Bx::Value> {
let tcx = bx.tcx();

let mut span_to_caller_location = |mut span: Span| {
// Remove `Inlined` marks as they pollute `expansion_cause`.
while span.is_inlined() {
span.remove_mark();
}
let mut span_to_caller_location = |span: Span| {
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = tcx.sess.source_map().lookup_char_pos(topmost.lo());
let const_loc = tcx.const_caller_location((
Expand Down
15 changes: 14 additions & 1 deletion compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// This deliberately does *not* honor `requires_caller_location` since it is used for much
// more than just panics.
for frame in stack.iter().rev() {
let span = frame.current_span();
let span = match frame.loc {
Left(loc) => {
// If the stacktrace passes through MIR-inlined source scopes, add them.
let mir::SourceInfo { mut span, scope } = *frame.body.source_info(loc);
let mut scope_data = &frame.body.source_scopes[scope];
while let Some((instance, call_span)) = scope_data.inlined {
frames.push(FrameInfo { span, instance });
span = call_span;
scope_data = &frame.body.source_scopes[scope_data.parent_scope.unwrap()];
}
span
}
Right(span) => span,
};
frames.push(FrameInfo { span, instance: frame.instance });
}
trace!("generate stacktrace: {:#?}", frames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
location
}

pub(crate) fn location_triple_for_span(&self, mut span: Span) -> (Symbol, u32, u32) {
// Remove `Inlined` marks as they pollute `expansion_cause`.
while span.is_inlined() {
span.remove_mark();
}
pub(crate) fn location_triple_for_span(&self, span: Span) -> (Symbol, u32, u32) {
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
(
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub trait Emitter: Translate {

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

ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
}
Expand Down Expand Up @@ -403,7 +403,7 @@ pub trait Emitter: Translate {
continue;
}

if always_backtrace && !matches!(trace.kind, ExpnKind::Inlined) {
if always_backtrace {
new_labels.push((
trace.def_site,
format!(
Expand Down Expand Up @@ -442,7 +442,6 @@ pub trait Emitter: Translate {
"this derive macro expansion".into()
}
ExpnKind::Macro(MacroKind::Bang, _) => "this macro invocation".into(),
ExpnKind::Inlined => "this inlined function call".into(),
ExpnKind::Root => "the crate root".into(),
ExpnKind::AstPass(kind) => kind.descr().into(),
ExpnKind::Desugaring(kind) => {
Expand Down
19 changes: 13 additions & 6 deletions compiler/rustc_hir_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,19 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
// to borrow discr.
needs_to_be_read = true;
}
PatKind::Or(_)
| PatKind::Box(_)
| PatKind::Slice(..)
| PatKind::Ref(..)
| PatKind::Wild => {
// If the PatKind is Or, Box, Slice or Ref, the decision is made later
PatKind::Slice(lhs, wild, rhs) => {
// We don't need to test the length if the pattern is `[..]`
if matches!((lhs, wild, rhs), (&[], Some(_), &[]))
// Arrays have a statically known size, so
// there is no need to read their length
|| discr_place.place.base_ty.is_array()
{
} else {
needs_to_be_read = true;
}
}
PatKind::Or(_) | PatKind::Box(_) | PatKind::Ref(..) | PatKind::Wild => {
// If the PatKind is Or, Box, or Ref, the decision is made later
// as these patterns contains subpatterns
// If the PatKind is Wild, the decision is made based on the other patterns being
// examined
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
}

fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) {
lint_callback!(self, check_arm, a);
hir_visit::walk_arm(self, a);
self.with_lint_attrs(a.hir_id, |cx| {
lint_callback!(cx, check_arm, a);
hir_visit::walk_arm(cx, a);
})
}

fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,7 @@ pub fn struct_lint_level(
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
let expn_data = span.ctxt().outer_expn_data();
match expn_data.kind {
ExpnKind::Inlined
| ExpnKind::Root
ExpnKind::Root
| ExpnKind::Desugaring(
DesugaringKind::ForLoop | DesugaringKind::WhileLoop | DesugaringKind::OpaqueTy,
) => false,
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2488,9 +2488,7 @@ impl<'tcx> TyCtxt<'tcx> {
&& if self.features().collapse_debuginfo {
span.in_macro_expansion_with_collapse_debuginfo()
} else {
// Inlined spans should not be collapsed as that leads to all of the
// inlined code being attributed to the inline callsite.
span.from_expansion() && !span.is_inlined()
span.from_expansion()
}
}

Expand Down
58 changes: 35 additions & 23 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,35 +90,34 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for MatchVisitor<'a, '_, 'tcx> {

#[instrument(level = "trace", skip(self))]
fn visit_arm(&mut self, arm: &Arm<'tcx>) {
match arm.guard {
Some(Guard::If(expr)) => {
self.with_let_source(LetSource::IfLetGuard, |this| {
this.visit_expr(&this.thir[expr])
});
}
Some(Guard::IfLet(ref pat, expr)) => {
self.with_let_source(LetSource::IfLetGuard, |this| {
this.check_let(pat, expr, LetSource::IfLetGuard, pat.span);
this.visit_pat(pat);
this.visit_expr(&this.thir[expr]);
});
self.with_lint_level(arm.lint_level, |this| {
match arm.guard {
Some(Guard::If(expr)) => {
this.with_let_source(LetSource::IfLetGuard, |this| {
this.visit_expr(&this.thir[expr])
});
}
Some(Guard::IfLet(ref pat, expr)) => {
this.with_let_source(LetSource::IfLetGuard, |this| {
this.check_let(pat, expr, LetSource::IfLetGuard, pat.span);
this.visit_pat(pat);
this.visit_expr(&this.thir[expr]);
});
}
None => {}
}
None => {}
}
self.visit_pat(&arm.pattern);
self.visit_expr(&self.thir[arm.body]);
this.visit_pat(&arm.pattern);
this.visit_expr(&self.thir[arm.body]);
});
}

#[instrument(level = "trace", skip(self))]
fn visit_expr(&mut self, ex: &Expr<'tcx>) {
match ex.kind {
ExprKind::Scope { value, lint_level, .. } => {
let old_lint_level = self.lint_level;
if let LintLevel::Explicit(hir_id) = lint_level {
self.lint_level = hir_id;
}
self.visit_expr(&self.thir[value]);
self.lint_level = old_lint_level;
self.with_lint_level(lint_level, |this| {
this.visit_expr(&this.thir[value]);
});
return;
}
ExprKind::If { cond, then, else_opt, if_then_scope: _ } => {
Expand Down Expand Up @@ -190,6 +189,17 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
self.let_source = old_let_source;
}

fn with_lint_level(&mut self, new_lint_level: LintLevel, f: impl FnOnce(&mut Self)) {
if let LintLevel::Explicit(hir_id) = new_lint_level {
let old_lint_level = self.lint_level;
self.lint_level = hir_id;
f(self);
self.lint_level = old_lint_level;
} else {
f(self);
}
}

fn check_patterns(&self, pat: &Pat<'tcx>, rf: RefutableFlag) {
pat.walk_always(|pat| check_borrow_conflicts_in_at_patterns(self, pat));
check_for_bindings_named_same_as_variants(self, pat, rf);
Expand Down Expand Up @@ -236,7 +246,9 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
for &arm in arms {
// Check the arm for some things unrelated to exhaustiveness.
let arm = &self.thir.arms[arm];
self.check_patterns(&arm.pattern, Refutable);
self.with_lint_level(arm.lint_level, |this| {
this.check_patterns(&arm.pattern, Refutable);
});
}

let tarms: Vec<_> = arms
Expand Down
18 changes: 0 additions & 18 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use rustc_middle::mir::*;
use rustc_middle::ty::TypeVisitableExt;
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
use rustc_session::config::OptLevel;
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
use rustc_target::spec::abi::Abi;

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

let mut expn_data = ExpnData::default(
ExpnKind::Inlined,
callsite.source_info.span,
self.tcx.sess.edition(),
None,
None,
);
expn_data.def_site = callee_body.span;
let expn_data =
self.tcx.with_stable_hashing_context(|hcx| LocalExpnId::fresh(expn_data, hcx));
let mut integrator = Integrator {
args: &args,
new_locals: Local::new(caller_body.local_decls.len())..,
Expand All @@ -572,7 +561,6 @@ impl<'tcx> Inliner<'tcx> {
cleanup_block: unwind,
in_cleanup_block: false,
tcx: self.tcx,
expn_data,
always_live_locals: BitSet::new_filled(callee_body.local_decls.len()),
};

Expand Down Expand Up @@ -956,7 +944,6 @@ struct Integrator<'a, 'tcx> {
cleanup_block: UnwindAction,
in_cleanup_block: bool,
tcx: TyCtxt<'tcx>,
expn_data: LocalExpnId,
always_live_locals: BitSet<Local>,
}

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

fn visit_span(&mut self, span: &mut Span) {
// Make sure that all spans track the fact that they were inlined.
*span = span.fresh_expansion(self.expn_data);
}

fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
self.in_cleanup_block = data.is_cleanup;
self.super_basic_block_data(block, data);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
bitflags = "1.2.1"
pulldown-cmark = { version = "0.9.2", default-features = false }
pulldown-cmark = { version = "0.9.3", default-features = false }
rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ impl ExpnId {
// Stop going up the backtrace once include! is encountered
if expn_data.is_root()
|| expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include)
|| expn_data.kind == ExpnKind::Inlined
{
break;
}
Expand Down Expand Up @@ -1058,8 +1057,6 @@ pub enum ExpnKind {
AstPass(AstPass),
/// Desugaring done by the compiler during HIR lowering.
Desugaring(DesugaringKind),
/// MIR inlining
Inlined,
}

impl ExpnKind {
Expand All @@ -1073,7 +1070,6 @@ impl ExpnKind {
},
ExpnKind::AstPass(kind) => kind.descr().to_string(),
ExpnKind::Desugaring(kind) => format!("desugaring of {}", kind.descr()),
ExpnKind::Inlined => "inlined source".to_string(),
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,6 @@ impl Span {
matches!(outer_expn.kind, ExpnKind::Macro(..)) && outer_expn.collapse_debuginfo
}

/// Returns `true` if this span comes from MIR inlining.
pub fn is_inlined(self) -> bool {
let outer_expn = self.ctxt().outer_expn_data();
matches!(outer_expn.kind, ExpnKind::Inlined)
}

/// Returns `true` if `span` originates in a derive-macro's expansion.
pub fn in_derive_expansion(self) -> bool {
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))
Expand Down
7 changes: 4 additions & 3 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod index;
mod iter;
mod raw;
mod rotate;
mod select;
mod specialize;

#[unstable(feature = "str_internals", issue = "none")]
Expand Down Expand Up @@ -3034,7 +3035,7 @@ impl<T> [T] {
where
T: Ord,
{
sort::partition_at_index(self, index, T::lt)
select::partition_at_index(self, index, T::lt)
}

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

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

/// Moves all consecutive repeated elements to the end of the slice according to the
Expand Down
Loading

0 comments on commit 0004b3b

Please sign in to comment.