Skip to content

Commit

Permalink
Auto merge of #81018 - m-ou-se:rollup-7202dc7, r=m-ou-se
Browse files Browse the repository at this point in the history
Rollup of 17 pull requests

Successful merges:

 - #79982 (Add missing methods to unix ExitStatusExt)
 - #80017 (Suggest `_` and `..` if a pattern has too few fields)
 - #80169 (Recommend panic::resume_unwind instead of panicking.)
 - #80217 (Add a `std::io::read_to_string` function)
 - #80444 (Add as_ref and as_mut methods for Bound)
 - #80567 (Add Iterator::intersperse_with)
 - #80829 (Get rid of `DepConstructor`)
 - #80895 (Fix handling of malicious Readers in read_to_end)
 - #80966 (Deprecate atomic::spin_loop_hint in favour of hint::spin_loop)
 - #80969 (Use better ICE message when no MIR is available)
 - #80972 (Remove unstable deprecated Vec::remove_item)
 - #80973 (Update books)
 - #80980 (Fixed incorrect doc comment)
 - #80981 (Fix -Cpasses=list and llvm version print with -vV)
 - #80985 (Fix stabilisation version of slice_strip)
 - #80990 (llvm: Remove the unused context from CreateDebugLocation)
 - #80991 (Fix formatting specifiers doc links)

Failed merges:

 - #80944 (Use Option::map_or instead of `.map(..).unwrap_or(..)`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 14, 2021
2 parents 4275ef6 + 9c75ee6 commit e38fb30
Show file tree
Hide file tree
Showing 42 changed files with 798 additions and 163 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {

unsafe {
llvm::LLVMRustDIBuilderCreateDebugLocation(
utils::debug_context(self).llcontext,
line.unwrap_or(UNKNOWN_LINE_NUMBER),
col.unwrap_or(UNKNOWN_COLUMN_NUMBER),
scope,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,6 @@ extern "C" {
);

pub fn LLVMRustDIBuilderCreateDebugLocation(
Context: &'a Context,
Line: c_uint,
Column: c_uint,
Scope: &'a DIScope,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ pub fn version(binary: &str, matches: &getopts::Matches) {
println!("commit-date: {}", unw(util::commit_date_str()));
println!("host: {}", config::host_triple());
println!("release: {}", unw(util::release_str()));
if cfg!(llvm) {
if cfg!(feature = "llvm") {
get_builtin_codegen_backend("llvm")().print_version();
}
}
Expand Down Expand Up @@ -1087,7 +1087,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
}

if cg_flags.iter().any(|x| *x == "passes=list") {
if cfg!(llvm) {
if cfg!(feature = "llvm") {
get_builtin_codegen_backend("llvm")().print_passes();
}
return None;
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,11 +994,9 @@ LLVMRustDICompositeTypeReplaceArrays(LLVMRustDIBuilderRef Builder,
}

extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef ContextRef, unsigned Line,
unsigned Column, LLVMMetadataRef Scope,
LLVMRustDIBuilderCreateDebugLocation(unsigned Line, unsigned Column,
LLVMMetadataRef Scope,
LLVMMetadataRef InlinedAt) {
LLVMContext &Context = *unwrap(ContextRef);

DebugLoc debug_loc = DebugLoc::get(Line, Column, unwrapDIPtr<MDNode>(Scope),
unwrapDIPtr<MDNode>(InlinedAt));

Expand Down
45 changes: 13 additions & 32 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
//! contained no `DefId` for thing that had been removed.
//!
//! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
//! defines the `DepKind` enum and a corresponding `dep_constructor` module. The
//! `dep_constructor` module links a `DepKind` to the parameters that are needed at
//! runtime in order to construct a valid `DepNode` fingerprint.
//! defines the `DepKind` enum. Each `DepKind` has its own parameters that are
//! needed at runtime in order to construct a valid `DepNode` fingerprint.
//! However, only `CompileCodegenUnit` is constructed explicitly (with
//! `make_compile_codegen_unit`).
//!
//! Because the macro sees what parameters a given `DepKind` requires, it can
//! "infer" some properties for each kind of `DepNode`:
Expand All @@ -44,22 +45,14 @@
//! `DefId` it was computed from. In other cases, too much information gets
//! lost during fingerprint computation.
//!
//! The `dep_constructor` module, together with `DepNode::new()`, ensures that only
//! `make_compile_codegen_unit`, together with `DepNode::new()`, ensures that only
//! valid `DepNode` instances can be constructed. For example, the API does not
//! allow for constructing parameterless `DepNode`s with anything other
//! than a zeroed out fingerprint. More generally speaking, it relieves the
//! user of the `DepNode` API of having to know how to compute the expected
//! fingerprint for a given set of node parameters.
use crate::mir::interpret::{GlobalId, LitToConstInput};
use crate::traits;
use crate::traits::query::{
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
};
use crate::ty::subst::{GenericArg, SubstsRef};
use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
use crate::ty::TyCtxt;

use rustc_data_structures::fingerprint::Fingerprint;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
Expand Down Expand Up @@ -338,25 +331,6 @@ macro_rules! define_dep_nodes {
$($variant),*
}

#[allow(non_camel_case_types)]
pub mod dep_constructor {
use super::*;

$(
#[inline(always)]
#[allow(unreachable_code, non_snake_case)]
pub fn $variant(_tcx: TyCtxt<'_>, $(arg: $tuple_arg_ty)*) -> DepNode {
// tuple args
$({
erase!($tuple_arg_ty);
return DepNode::construct(_tcx, DepKind::$variant, &arg)
})*

return DepNode::construct(_tcx, DepKind::$variant, &())
}
)*
}

fn dep_kind_from_label_string(label: &str) -> Result<DepKind, ()> {
match label {
$(stringify!($variant) => Ok(DepKind::$variant),)*
Expand Down Expand Up @@ -384,9 +358,16 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>

[anon] TraitSelect,

// WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.
[] CompileCodegenUnit(Symbol),
]);

// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
// Be very careful changing this type signature!
crate fn make_compile_codegen_unit(tcx: TyCtxt<'_>, name: Symbol) -> DepNode {
DepNode::construct(tcx, DepKind::CompileCodegenUnit, &name)
}

pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;

// We keep a lot of `DepNode`s in memory during compilation. It's not
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ pub use rustc_query_system::dep_graph::{
WorkProduct, WorkProductId,
};

pub use dep_node::{dep_constructor, label_strs, DepKind, DepNode, DepNodeExt};
crate use dep_node::make_compile_codegen_unit;
pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};

pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::dep_graph::{dep_constructor, DepNode, WorkProduct, WorkProductId};
use crate::dep_graph::{DepNode, WorkProduct, WorkProductId};
use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
use rustc_attr::InlineAttr;
Expand Down Expand Up @@ -362,7 +362,7 @@ impl<'tcx> CodegenUnit<'tcx> {
}

pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
dep_constructor::CompileCodegenUnit(tcx, self.name())
crate::dep_graph::make_compile_codegen_unit(tcx, self.name())
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) ->
}

if !tcx.is_mir_available(def_id) {
bug!("cannot create local mono-item for {:?}", def_id)
bug!("no MIR available for {:?}", def_id);
}

true
Expand Down
57 changes: 52 additions & 5 deletions compiler/rustc_typeck/src/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rustc_span::hygiene::DesugaringKind;
use rustc_span::lev_distance::find_best_match_for_name;
use rustc_span::source_map::{Span, Spanned};
use rustc_span::symbol::Ident;
use rustc_span::{BytePos, DUMMY_SP};
use rustc_trait_selection::traits::{ObligationCause, Pattern};

use std::cmp;
Expand Down Expand Up @@ -1001,7 +1002,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// More generally, the expected type wants a tuple variant with one field of an
// N-arity-tuple, e.g., `V_i((p_0, .., p_N))`. Meanwhile, the user supplied a pattern
// with the subpatterns directly in the tuple variant pattern, e.g., `V_i(p_0, .., p_N)`.
let missing_parenthesis = match (&expected.kind(), fields, had_err) {
let missing_parentheses = match (&expected.kind(), fields, had_err) {
// #67037: only do this if we could successfully type-check the expected type against
// the tuple struct pattern. Otherwise the substs could get out of range on e.g.,
// `let P() = U;` where `P != U` with `struct P<T>(T);`.
Expand All @@ -1014,13 +1015,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
_ => false,
};
if missing_parenthesis {
if missing_parentheses {
let (left, right) = match subpats {
// This is the zero case; we aim to get the "hi" part of the `QPath`'s
// span as the "lo" and then the "hi" part of the pattern's span as the "hi".
// This looks like:
//
// help: missing parenthesis
// help: missing parentheses
// |
// L | let A(()) = A(());
// | ^ ^
Expand All @@ -1029,17 +1030,63 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// last sub-pattern. In the case of `A(x)` the first and last may coincide.
// This looks like:
//
// help: missing parenthesis
// help: missing parentheses
// |
// L | let A((x, y)) = A((1, 2));
// | ^ ^
[first, ..] => (first.span.shrink_to_lo(), subpats.last().unwrap().span),
};
err.multipart_suggestion(
"missing parenthesis",
"missing parentheses",
vec![(left, "(".to_string()), (right.shrink_to_hi(), ")".to_string())],
Applicability::MachineApplicable,
);
} else if fields.len() > subpats.len() {
let after_fields_span = if pat_span == DUMMY_SP {
pat_span
} else {
pat_span.with_hi(pat_span.hi() - BytePos(1)).shrink_to_hi()
};
let all_fields_span = match subpats {
[] => after_fields_span,
[field] => field.span,
[first, .., last] => first.span.to(last.span),
};

// Check if all the fields in the pattern are wildcards.
let all_wildcards = subpats.iter().all(|pat| matches!(pat.kind, PatKind::Wild));

let mut wildcard_sugg = vec!["_"; fields.len() - subpats.len()].join(", ");
if !subpats.is_empty() {
wildcard_sugg = String::from(", ") + &wildcard_sugg;
}

err.span_suggestion_verbose(
after_fields_span,
"use `_` to explicitly ignore each field",
wildcard_sugg,
Applicability::MaybeIncorrect,
);

// Only suggest `..` if more than one field is missing
// or the pattern consists of all wildcards.
if fields.len() - subpats.len() > 1 || all_wildcards {
if subpats.is_empty() || all_wildcards {
err.span_suggestion_verbose(
all_fields_span,
"use `..` to ignore all fields",
String::from(".."),
Applicability::MaybeIncorrect,
);
} else {
err.span_suggestion_verbose(
after_fields_span,
"use `..` to ignore the rest of the fields",
String::from(", .."),
Applicability::MaybeIncorrect,
);
}
}
}

err.emit();
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/sync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ fn test_weak_count_locked() {
let n = Arc::weak_count(&a2);
assert!(n < 2, "bad weak count: {}", n);
#[cfg(miri)] // Miri's scheduler does not guarantee liveness, and thus needs this hint.
atomic::spin_loop_hint();
std::hint::spin_loop();
}
t.join().unwrap();
}
Expand Down
21 changes: 0 additions & 21 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1953,27 +1953,6 @@ impl<T: PartialEq, A: Allocator> Vec<T, A> {
}
}

impl<T, A: Allocator> Vec<T, A> {
/// Removes the first instance of `item` from the vector if the item exists.
///
/// This method will be removed soon.
#[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")]
#[rustc_deprecated(
reason = "Removing the first item equal to a needle is already easily possible \
with iterators and the current Vec methods. Furthermore, having a method for \
one particular case of removal (linear search, only the first item, no swap remove) \
but not for others is inconsistent. This method will be removed soon.",
since = "1.46.0"
)]
pub fn remove_item<V>(&mut self, item: &V) -> Option<T>
where
T: PartialEq<V>,
{
let pos = self.iter().position(|x| *x == *item)?;
Some(self.remove(pos))
}
}

////////////////////////////////////////////////////////////////////////////////
// Internal methods and functions
////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit e38fb30

Please sign in to comment.