Skip to content

Commit

Permalink
Auto merge of rust-lang#94514 - matthiaskrgr:rollup-pdzn82h, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#94464 (Suggest adding a new lifetime parameter when two elided lifetimes should match up for traits and impls.)
 - rust-lang#94476 (7 - Make more use of `let_chains`)
 - rust-lang#94478 (Fix panic when handling intra doc links generated from macro)
 - rust-lang#94482 (compiler: fix some typos)
 - rust-lang#94490 (Update books)
 - rust-lang#94496 (tests: accept llvm intrinsic in align-checking test)
 - rust-lang#94498 (9 - Make more use of `let_chains`)
 - rust-lang#94503 (Provide C FFI types via core::ffi, not just in std)
 - rust-lang#94513 (update Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 2, 2022
2 parents 39a3b52 + e89ab08 commit 2a280de
Show file tree
Hide file tree
Showing 71 changed files with 873 additions and 567 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics: &Generics,
itctx: ImplTraitContext<'_, 'hir>,
) -> GenericsCtor<'hir> {
// Error if `?Trait` bounds in where clauses don't refer directly to type paramters.
// Error if `?Trait` bounds in where clauses don't refer directly to type parameters.
// Note: we used to clone these bounds directly onto the type parameter (and avoid lowering
// these into hir when we lower thee where clauses), but this makes it quite difficult to
// keep track of the Span info. Now, `add_implicitly_sized` in `AstConv` checks both param bounds and
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
.find_map(|constraint| {
if let ConstraintCategory::Predicate(predicate_span) = constraint.category {
// We currentl'y doesn't store the `DefId` in the `ConstraintCategory`
// for perforamnce reasons. The error reporting code used by NLL only
// for performances reasons. The error reporting code used by NLL only
// uses the span, so this doesn't cause any problems at the moment.
Some(ObligationCauseCode::BindingObligation(
CRATE_DEF_ID.to_def_id(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/cfg_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl CfgEval<'_, '_> {

// Re-parse the tokens, setting the `capture_cfg` flag to save extra information
// to the captured `AttrAnnotatedTokenStream` (specifically, we capture
// `AttrAnnotatedTokenTree::AttributesData` for all occurences of `#[cfg]` and `#[cfg_attr]`)
// `AttrAnnotatedTokenTree::AttributesData` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
let mut parser =
rustc_parse::stream_to_parser(&self.cfg.sess.parse_sess, orig_tokens, None);
parser.capture_cfg = true;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(

// ... and otherwise we're processing a `*.dwp` packed dwarf file.
//
// We cannot rely on the .o paths in the exectuable because they may have been
// We cannot rely on the .o paths in the executable because they may have been
// remapped by --remap-path-prefix and therefore invalid, so we need to provide
// the .o/.dwo paths explicitly.
SplitDebuginfo::Packed => link_dwarf_object(sess, codegen_results, out_filename),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ impl<'a> Linker for WasmLd<'a> {
}

// LLD will hide these otherwise-internal symbols since it only exports
// symbols explicity passed via the `--export` flags above and hides all
// symbols explicitly passed via the `--export` flags above and hides all
// others. Various bits and pieces of tooling use this, so be sure these
// symbols make their way out of the linker as well.
self.cmd.arg("--export=__heap_base");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sso/either_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::iter::Iterator;
/// one of two specific implementations.
///
/// Note: For most methods providing custom
/// implementation may margianlly
/// implementation may marginally
/// improve performance by avoiding
/// doing Left/Right match on every step
/// and doing it only once instead.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl DefPathTable {
// Continuing with colliding DefPathHashes can lead to correctness
// issues. We must abort compilation.
//
// The likelyhood of such a collision is very small, so actually
// The likelihood of such a collision is very small, so actually
// running into one could be indicative of a poor hash function
// being used.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,59 +166,61 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
if lifetime_sub.name.is_elided() && lifetime_sup.name.is_elided() {
if let Some(anon_reg) = self.tcx().is_suitable_region(sub) {
let hir_id = self.tcx().hir().local_def_id_to_hir_id(anon_reg.def_id);
if let hir::Node::Item(&hir::Item {
kind: hir::ItemKind::Fn(_, ref generics, ..),
..
}) = self.tcx().hir().get(hir_id)
{
let (suggestion_param_name, introduce_new) = generics
.params
.iter()
.find(|p| matches!(p.kind, GenericParamKind::Lifetime { .. }))
.and_then(|p| self.tcx().sess.source_map().span_to_snippet(p.span).ok())
.map(|name| (name, false))
.unwrap_or_else(|| ("'a".to_string(), true));

let mut suggestions = vec![
if let hir::LifetimeName::Underscore = lifetime_sub.name {
(lifetime_sub.span, suggestion_param_name.clone())
} else {
(
lifetime_sub.span.shrink_to_hi(),
suggestion_param_name.clone() + " ",
)
},
if let hir::LifetimeName::Underscore = lifetime_sup.name {
(lifetime_sup.span, suggestion_param_name.clone())
} else {
(
lifetime_sup.span.shrink_to_hi(),
suggestion_param_name.clone() + " ",
)
},
];

if introduce_new {
let new_param_suggestion = match &generics.params {
[] => (generics.span, format!("<{}>", suggestion_param_name)),
[first, ..] => (
first.span.shrink_to_lo(),
format!("{}, ", suggestion_param_name),
),
};

suggestions.push(new_param_suggestion);
}

err.multipart_suggestion(
"consider introducing a named lifetime parameter",
suggestions,
Applicability::MaybeIncorrect,
);
err.note(
"each elided lifetime in input position becomes a distinct lifetime",
);

let node = self.tcx().hir().get(hir_id);
let is_impl = matches!(&node, hir::Node::ImplItem(_));
let generics = match node {
hir::Node::Item(&hir::Item {
kind: hir::ItemKind::Fn(_, ref generics, ..),
..
})
| hir::Node::TraitItem(&hir::TraitItem { ref generics, .. })
| hir::Node::ImplItem(&hir::ImplItem { ref generics, .. }) => generics,
_ => return,
};

let (suggestion_param_name, introduce_new) = generics
.params
.iter()
.find(|p| matches!(p.kind, GenericParamKind::Lifetime { .. }))
.and_then(|p| self.tcx().sess.source_map().span_to_snippet(p.span).ok())
.map(|name| (name, false))
.unwrap_or_else(|| ("'a".to_string(), true));

let mut suggestions = vec![
if let hir::LifetimeName::Underscore = lifetime_sub.name {
(lifetime_sub.span, suggestion_param_name.clone())
} else {
(lifetime_sub.span.shrink_to_hi(), suggestion_param_name.clone() + " ")
},
if let hir::LifetimeName::Underscore = lifetime_sup.name {
(lifetime_sup.span, suggestion_param_name.clone())
} else {
(lifetime_sup.span.shrink_to_hi(), suggestion_param_name.clone() + " ")
},
];

if introduce_new {
let new_param_suggestion = match &generics.params {
[] => (generics.span, format!("<{}>", suggestion_param_name)),
[first, ..] => {
(first.span.shrink_to_lo(), format!("{}, ", suggestion_param_name))
}
};

suggestions.push(new_param_suggestion);
}

let mut sugg = String::from("consider introducing a named lifetime parameter");
if is_impl {
sugg.push_str(" and update trait if needed");
}
err.multipart_suggestion(
sugg.as_str(),
suggestions,
Applicability::MaybeIncorrect,
);
err.note("each elided lifetime in input position becomes a distinct lifetime");
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_mir_transform/src/const_debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ fn find_optimization_oportunities<'tcx>(body: &Body<'tcx>) -> Vec<(Local, Consta

let mut locals_to_debuginfo = BitSet::new_empty(body.local_decls.len());
for debuginfo in &body.var_debug_info {
if let VarDebugInfoContents::Place(p) = debuginfo.value {
if let Some(l) = p.as_local() {
locals_to_debuginfo.insert(l);
}
if let VarDebugInfoContents::Place(p) = debuginfo.value && let Some(l) = p.as_local() {
locals_to_debuginfo.insert(l);
}
}

Expand Down
50 changes: 23 additions & 27 deletions compiler/rustc_mir_transform/src/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,24 +633,22 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
fn propagate_operand(&mut self, operand: &mut Operand<'tcx>) {
match *operand {
Operand::Copy(l) | Operand::Move(l) => {
if let Some(value) = self.get_const(l) {
if self.should_const_prop(&value) {
// FIXME(felix91gr): this code only handles `Scalar` cases.
// For now, we're not handling `ScalarPair` cases because
// doing so here would require a lot of code duplication.
// We should hopefully generalize `Operand` handling into a fn,
// and use it to do const-prop here and everywhere else
// where it makes sense.
if let interpret::Operand::Immediate(interpret::Immediate::Scalar(
ScalarMaybeUninit::Scalar(scalar),
)) = *value
{
*operand = self.operand_from_scalar(
scalar,
value.layout.ty,
self.source_info.unwrap().span,
);
}
if let Some(value) = self.get_const(l) && self.should_const_prop(&value) {
// FIXME(felix91gr): this code only handles `Scalar` cases.
// For now, we're not handling `ScalarPair` cases because
// doing so here would require a lot of code duplication.
// We should hopefully generalize `Operand` handling into a fn,
// and use it to do const-prop here and everywhere else
// where it makes sense.
if let interpret::Operand::Immediate(interpret::Immediate::Scalar(
ScalarMaybeUninit::Scalar(scalar),
)) = *value
{
*operand = self.operand_from_scalar(
scalar,
value.layout.ty,
self.source_info.unwrap().span,
);
}
}
}
Expand Down Expand Up @@ -1086,15 +1084,13 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
// This will return None if the above `const_prop` invocation only "wrote" a
// type whose creation requires no write. E.g. a generator whose initial state
// consists solely of uninitialized memory (so it doesn't capture any locals).
if let Some(ref value) = self.get_const(place) {
if self.should_const_prop(value) {
trace!("replacing {:?} with {:?}", rval, value);
self.replace_with_const(rval, value, source_info);
if can_const_prop == ConstPropMode::FullConstProp
|| can_const_prop == ConstPropMode::OnlyInsideOwnBlock
{
trace!("propagated into {:?}", place);
}
if let Some(ref value) = self.get_const(place) && self.should_const_prop(value) {
trace!("replacing {:?} with {:?}", rval, value);
self.replace_with_const(rval, value, source_info);
if can_const_prop == ConstPropMode::FullConstProp
|| can_const_prop == ConstPropMode::OnlyInsideOwnBlock
{
trace!("propagated into {:?}", place);
}
}
match can_const_prop {
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_mir_transform/src/coverage/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,12 @@ impl DebugCounters {
if let Some(counters) = &self.some_counters {
if let Some(DebugCounter { counter_kind, some_block_label }) = counters.get(&operand) {
if let CoverageKind::Expression { .. } = counter_kind {
if let Some(block_label) = some_block_label {
if debug_options().counter_format.block {
return format!(
"{}:({})",
block_label,
self.format_counter_kind(counter_kind)
);
}
if let Some(label) = some_block_label && debug_options().counter_format.block {
return format!(
"{}:({})",
label,
self.format_counter_kind(counter_kind)
);
}
return format!("({})", self.format_counter_kind(counter_kind));
}
Expand Down
43 changes: 19 additions & 24 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,13 @@ impl CoverageSpan {
/// If the span is part of a macro, and the macro is visible (expands directly to the given
/// body_span), returns the macro name symbol.
pub fn visible_macro(&self, body_span: Span) -> Option<Symbol> {
if let Some(current_macro) = self.current_macro() {
if self
.expn_span
.parent_callsite()
.unwrap_or_else(|| bug!("macro must have a parent"))
.ctxt()
== body_span.ctxt()
{
return Some(current_macro);
}
if let Some(current_macro) = self.current_macro() && self
.expn_span
.parent_callsite()
.unwrap_or_else(|| bug!("macro must have a parent"))
.ctxt() == body_span.ctxt()
{
return Some(current_macro);
}
None
}
Expand Down Expand Up @@ -584,21 +581,19 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
/// In either case, no more spans will match the span of `pending_dups`, so
/// add the `pending_dups` if they don't overlap `curr`, and clear the list.
fn check_pending_dups(&mut self) {
if let Some(dup) = self.pending_dups.last() {
if dup.span != self.prev().span {
debug!(
" SAME spans, but pending_dups are NOT THE SAME, so BCBs matched on \
previous iteration, or prev started a new disjoint span"
);
if dup.span.hi() <= self.curr().span.lo() {
let pending_dups = self.pending_dups.split_off(0);
for dup in pending_dups.into_iter() {
debug!(" ...adding at least one pending={:?}", dup);
self.push_refined_span(dup);
}
} else {
self.pending_dups.clear();
if let Some(dup) = self.pending_dups.last() && dup.span != self.prev().span {
debug!(
" SAME spans, but pending_dups are NOT THE SAME, so BCBs matched on \
previous iteration, or prev started a new disjoint span"
);
if dup.span.hi() <= self.curr().span.lo() {
let pending_dups = self.pending_dups.split_off(0);
for dup in pending_dups.into_iter() {
debug!(" ...adding at least one pending={:?}", dup);
self.push_refined_span(dup);
}
} else {
self.pending_dups.clear();
}
}
}
Expand Down
Loading

0 comments on commit 2a280de

Please sign in to comment.