Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #71539

Merged
merged 20 commits into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3ae974f
fix misleading type annotation diagonstics
contrun Feb 25, 2020
a75c792
Make type alias private
ecstatic-morse Apr 19, 2020
274c85f
Don't cache result of `in_any_value_of_ty` for locals
ecstatic-morse Apr 19, 2020
1343797
Lazily run dataflow for const qualification
ecstatic-morse Apr 19, 2020
15f95b1
Cycle errors now occur during const-eval, not checking
ecstatic-morse Apr 19, 2020
03817ec
Improve PanicInfo examples readability
GuillaumeGomez Apr 23, 2020
787eddc
Add BinaryHeap::retain as suggested in #42849
Apr 23, 2020
a62a8b0
Remove useless "" args
Rustin170506 Apr 24, 2020
5a49578
Use `debug` to print illegal operations in a const context
ecstatic-morse Apr 24, 2020
0e34cb2
Remove unused `visit_local`
ecstatic-morse Apr 24, 2020
2325c20
Avoid unused Option::map results
cuviper Apr 24, 2020
0689efc
Fix typos in docs for keyword "in"
workingjubilee Apr 24, 2020
2e2080d
Rollup merge of #69456 - contrun:fix-misleading-compiler-error, r=est…
Dylan-DPC Apr 24, 2020
f3331cb
Rollup merge of #71330 - ecstatic-morse:const-qualif-lazy, r=oli-obk
Dylan-DPC Apr 24, 2020
a23d8ec
Rollup merge of #71480 - GuillaumeGomez:panic-info-example, r=Dylan-DPC
Dylan-DPC Apr 24, 2020
e20ca11
Rollup merge of #71485 - arlopurcell:binary_heap_retain, r=Amanieu
Dylan-DPC Apr 24, 2020
f136ba6
Rollup merge of #71512 - Rustin-Liu:rustin-patch-bootstrap, r=Mark-Si…
Dylan-DPC Apr 24, 2020
2ca6df7
Rollup merge of #71527 - ecstatic-morse:debug-check-consts, r=Dylan-DPC
Dylan-DPC Apr 24, 2020
d0db0a8
Rollup merge of #71534 - cuviper:unused-option-map, r=Mark-Simulacrum
Dylan-DPC Apr 24, 2020
32fb77d
Rollup merge of #71535 - workingjubilee:jubilee-markdown-fix, r=Mark-…
Dylan-DPC Apr 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/bootstrap/toolstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ static NIGHTLY_TOOLS: &[(&str, &str)] = &[
];

fn print_error(tool: &str, submodule: &str) {
eprintln!("");
eprintln!();
eprintln!("We detected that this PR updated '{}', but its tests failed.", tool);
eprintln!("");
eprintln!();
eprintln!("If you do intend to update '{}', please check the error messages above and", tool);
eprintln!("commit another update.");
eprintln!("");
eprintln!();
eprintln!("If you do NOT intend to update '{}', please ensure you did not accidentally", tool);
eprintln!("change the submodule at '{}'. You may ask your reviewer for the", submodule);
eprintln!("proper steps.");
Expand Down
28 changes: 28 additions & 0 deletions src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,34 @@ impl<T: Ord> BinaryHeap<T> {
pub fn drain_sorted(&mut self) -> DrainSorted<'_, T> {
DrainSorted { inner: self }
}

/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` such that `f(&e)` returns
/// `false`. The elements are visited in unsorted (and unspecified) order.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(binary_heap_retain)]
/// use std::collections::BinaryHeap;
///
/// let mut heap = BinaryHeap::from(vec![-10, -5, 1, 2, 4, 13]);
///
/// heap.retain(|x| x % 2 == 0); // only keep even numbers
///
/// assert_eq!(heap.into_sorted_vec(), [-10, 2, 4])
/// ```
#[unstable(feature = "binary_heap_retain", issue = "71503")]
pub fn retain<F>(&mut self, f: F)
where
F: FnMut(&T) -> bool,
{
self.data.retain(f);
self.rebuild();
}
}

impl<T> BinaryHeap<T> {
Expand Down
8 changes: 8 additions & 0 deletions src/liballoc/tests/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ fn assert_covariance() {
}
}

#[test]
fn test_retain() {
let mut a = BinaryHeap::from(vec![-10, -5, 1, 2, 4, 13]);
a.retain(|x| x % 2 == 0);

assert_eq!(a.into_sorted_vec(), [-10, 2, 4])
}

// old binaryheap failed this test
//
// Integrity means that all elements are present after a comparison panics,
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![feature(binary_heap_drain_sorted)]
#![feature(vec_remove_item)]
#![feature(split_inclusive)]
#![feature(binary_heap_retain)]

use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
Expand Down
12 changes: 9 additions & 3 deletions src/libcore/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ impl<'a> PanicInfo<'a> {
/// use std::panic;
///
/// panic::set_hook(Box::new(|panic_info| {
/// println!("panic occurred: {:?}", panic_info.payload().downcast_ref::<&str>().unwrap());
/// if let Some(s) = panic_info.payload().downcast_ref::<&str>() {
/// println!("panic occurred: {:?}", s);
/// } else {
/// println!("panic occurred");
/// }
/// }));
///
/// panic!("Normal panic");
Expand Down Expand Up @@ -112,8 +116,10 @@ impl<'a> PanicInfo<'a> {
///
/// panic::set_hook(Box::new(|panic_info| {
/// if let Some(location) = panic_info.location() {
/// println!("panic occurred in file '{}' at line {}", location.file(),
/// location.line());
/// println!("panic occurred in file '{}' at line {}",
/// location.file(),
/// location.line(),
/// );
/// } else {
/// println!("panic occurred but can't get location information...");
/// }
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
}
}

diagnostic.map(|d| {
if let Some(d) = diagnostic {
struct_span_err!(d, attr.span, E0633, "malformed `unwind` attribute input")
.span_label(attr.span, "invalid argument")
.span_suggestions(
Expand All @@ -110,7 +110,7 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
Applicability::MachineApplicable,
)
.emit();
});
};
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_expand/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,10 +1172,10 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
// ignore derives so they remain unused
let (attr, after_derive) = self.classify_nonitem(&mut expr);

if attr.is_some() {
if let Some(ref attr_value) = attr {
// Collect the invoc regardless of whether or not attributes are permitted here
// expansion will eat the attribute so it won't error later.
attr.as_ref().map(|a| self.cfg.maybe_emit_expr_attr_err(a));
self.cfg.maybe_emit_expr_attr_err(attr_value);

// AstFragmentKind::Expr requires the macro to emit an expression.
return self
Expand Down Expand Up @@ -1322,8 +1322,8 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
// Ignore derives so they remain unused.
let (attr, after_derive) = self.classify_nonitem(&mut expr);

if attr.is_some() {
attr.as_ref().map(|a| self.cfg.maybe_emit_expr_attr_err(a));
if let Some(ref attr_value) = attr {
self.cfg.maybe_emit_expr_attr_err(attr_value);

return self
.collect_attr(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_hir/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl DefPath {

let mut opt_delimiter = None;
for component in &self.data {
opt_delimiter.map(|d| s.push(d));
s.extend(opt_delimiter);
opt_delimiter = Some('-');
if component.disambiguator == 0 {
write!(s, "{}", component.data.as_symbol()).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
},
ObligationCauseCode::IfExpression(box IfExpressionCause { then, outer, semicolon }) => {
err.span_label(then, "expected because of this");
outer.map(|sp| err.span_label(sp, "`if` and `else` have incompatible types"));
if let Some(sp) = outer {
err.span_label(sp, "`if` and `else` have incompatible types");
}
if let Some(sp) = semicolon {
err.span_suggestion_short(
sp,
Expand Down
58 changes: 52 additions & 6 deletions src/librustc_infer/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ use std::borrow::Cow;
struct FindHirNodeVisitor<'a, 'tcx> {
infcx: &'a InferCtxt<'a, 'tcx>,
target: GenericArg<'tcx>,
target_span: Span,
found_node_ty: Option<Ty<'tcx>>,
found_local_pattern: Option<&'tcx Pat<'tcx>>,
found_arg_pattern: Option<&'tcx Pat<'tcx>>,
found_closure: Option<&'tcx Expr<'tcx>>,
found_method_call: Option<&'tcx Expr<'tcx>>,
found_exact_method_call: Option<&'tcx Expr<'tcx>>,
}

impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
fn new(infcx: &'a InferCtxt<'a, 'tcx>, target: GenericArg<'tcx>) -> Self {
fn new(infcx: &'a InferCtxt<'a, 'tcx>, target: GenericArg<'tcx>, target_span: Span) -> Self {
Self {
infcx,
target,
target_span,
found_node_ty: None,
found_local_pattern: None,
found_arg_pattern: None,
found_closure: None,
found_method_call: None,
found_exact_method_call: None,
}
}

Expand Down Expand Up @@ -103,6 +107,17 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
}

fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
if let ExprKind::MethodCall(_, call_span, exprs) = expr.kind {
if call_span == self.target_span
&& Some(self.target)
== self.infcx.in_progress_tables.and_then(|tables| {
tables.borrow().node_type_opt(exprs.first().unwrap().hir_id).map(Into::into)
})
{
self.found_exact_method_call = Some(&expr);
return;
}
}
if self.node_ty_contains_target(expr.hir_id).is_some() {
match expr.kind {
ExprKind::Closure(..) => self.found_closure = Some(&expr),
Expand Down Expand Up @@ -234,7 +249,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let ty = self.resolve_vars_if_possible(&ty);
let (name, name_sp, descr, parent_name, parent_descr) = self.extract_type_name(&ty, None);

let mut local_visitor = FindHirNodeVisitor::new(&self, ty.into());
let mut local_visitor = FindHirNodeVisitor::new(&self, ty.into(), span);
let ty_to_string = |ty: Ty<'tcx>| -> String {
let mut s = String::new();
let mut printer = ty::print::FmtPrinter::new(self.tcx, &mut s, Namespace::TypeNS);
Expand Down Expand Up @@ -287,14 +302,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
(!ty.is_impl_trait() || self.tcx.features().impl_trait_in_bindings)
};

let ty_msg = match local_visitor.found_node_ty {
Some(ty::TyS { kind: ty::Closure(_, substs), .. }) => {
let ty_msg = match (local_visitor.found_node_ty, local_visitor.found_exact_method_call) {
(_, Some(_)) => String::new(),
(Some(ty::TyS { kind: ty::Closure(_, substs), .. }), _) => {
let fn_sig = substs.as_closure().sig();
let args = closure_args(&fn_sig);
let ret = fn_sig.output().skip_binder().to_string();
format!(" for the closure `fn({}) -> {}`", args, ret)
}
Some(ty) if is_named_and_not_impl_trait(ty) => {
(Some(ty), _) if is_named_and_not_impl_trait(ty) => {
let ty = ty_to_string(ty);
format!(" for `{}`", ty)
}
Expand Down Expand Up @@ -370,7 +386,37 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
_ => "a type".to_string(),
};

if let Some(pattern) = local_visitor.found_arg_pattern {
if let Some(e) = local_visitor.found_exact_method_call {
if let ExprKind::MethodCall(segment, ..) = &e.kind {
// Suggest specifying type params or point out the return type of the call:
//
// error[E0282]: type annotations needed
// --> $DIR/type-annotations-needed-expr.rs:2:39
// |
// LL | let _ = x.into_iter().sum() as f64;
// | ^^^
// | |
// | cannot infer type for `S`
// | help: consider specifying the type argument in
// | the method call: `sum::<S>`
// |
// = note: type must be known at this point
//
// or
//
// error[E0282]: type annotations needed
// --> $DIR/issue-65611.rs:59:20
// |
// LL | let x = buffer.last().unwrap().0.clone();
// | -------^^^^--
// | | |
// | | cannot infer type for `T`
// | this method call resolves to `std::option::Option<&T>`
// |
// = note: type must be known at this point
self.annotate_method_call(segment, e, &mut err);
}
} else if let Some(pattern) = local_visitor.found_arg_pattern {
// We don't want to show the default label for closures.
//
// So, before clearing, the output would look something like this:
Expand Down
12 changes: 9 additions & 3 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,15 @@ fn dump_crates(cstore: &CStore) {
info!(" hash: {}", data.hash());
info!(" reqd: {:?}", data.dep_kind());
let CrateSource { dylib, rlib, rmeta } = data.source();
dylib.as_ref().map(|dl| info!(" dylib: {}", dl.0.display()));
rlib.as_ref().map(|rl| info!(" rlib: {}", rl.0.display()));
rmeta.as_ref().map(|rl| info!(" rmeta: {}", rl.0.display()));
if let Some(dylib) = dylib {
info!(" dylib: {}", dylib.0.display());
}
if let Some(rlib) = rlib {
info!(" rlib: {}", rlib.0.display());
}
if let Some(rmeta) = rmeta {
info!(" rmeta: {}", rmeta.0.display());
}
});
}

Expand Down
Loading