From 91ee3d1c31e5d1684e0d2ec5036dc69993b6f992 Mon Sep 17 00:00:00 2001 From: Bryan Donlan Date: Thu, 24 Oct 2019 20:09:35 +0000 Subject: [PATCH 01/10] Stabilize `std::{rc,sync}::Weak::{weak_count, strong_count}` Closes: #57977 --- src/liballoc/rc.rs | 4 ++-- src/liballoc/sync.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index a11f9e8c14579..12f86bf880f13 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1803,7 +1803,7 @@ impl Weak { /// If `self` was created using [`Weak::new`], this will return 0. /// /// [`Weak::new`]: #method.new - #[unstable(feature = "weak_counts", issue = "57977")] + #[stable(feature = "weak_counts", since = "1.40.0")] pub fn strong_count(&self) -> usize { if let Some(inner) = self.inner() { inner.strong() @@ -1819,7 +1819,7 @@ impl Weak { /// allocation. /// /// [`Weak::new`]: #method.new - #[unstable(feature = "weak_counts", issue = "57977")] + #[stable(feature = "weak_counts", since = "1.40.0")] pub fn weak_count(&self) -> Option { self.inner().map(|inner| { if inner.strong() > 0 { diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 4b10f089c2950..3f86dfb469eab 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -1496,7 +1496,7 @@ impl Weak { /// If `self` was created using [`Weak::new`], this will return 0. /// /// [`Weak::new`]: #method.new - #[unstable(feature = "weak_counts", issue = "57977")] + #[stable(feature = "weak_counts", since = "1.40.0")] pub fn strong_count(&self) -> usize { if let Some(inner) = self.inner() { inner.strong.load(SeqCst) @@ -1519,7 +1519,7 @@ impl Weak { /// `Weak`s pointing to the same allocation. /// /// [`Weak::new`]: #method.new - #[unstable(feature = "weak_counts", issue = "57977")] + #[stable(feature = "weak_counts", since = "1.40.0")] pub fn weak_count(&self) -> Option { // Due to the implicit weak pointer added when any strong pointers are // around, we cannot implement `weak_count` correctly since it From 0d0b283c2c5a4df891ca47b27f0851ef2549ac3b Mon Sep 17 00:00:00 2001 From: Bryan Donlan Date: Thu, 21 Nov 2019 19:48:39 +0000 Subject: [PATCH 02/10] Make Weak::weak_count() return zero when no strong refs remain --- src/liballoc/rc.rs | 12 ++++-------- src/liballoc/rc/tests.rs | 14 +++++++------- src/liballoc/sync.rs | 36 +++++++++++++----------------------- src/liballoc/sync/tests.rs | 14 +++++++------- 4 files changed, 31 insertions(+), 45 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 12f86bf880f13..0dab68b155d87 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1814,20 +1814,16 @@ impl Weak { /// Gets the number of `Weak` pointers pointing to this allocation. /// - /// If `self` was created using [`Weak::new`], this will return `None`. If - /// not, the returned value is at least 1, since `self` still points to the - /// allocation. - /// - /// [`Weak::new`]: #method.new + /// If no strong pointers remain, this will return zero. #[stable(feature = "weak_counts", since = "1.40.0")] - pub fn weak_count(&self) -> Option { + pub fn weak_count(&self) -> usize { self.inner().map(|inner| { if inner.strong() > 0 { inner.weak() - 1 // subtract the implicit weak ptr } else { - inner.weak() + 0 } - }) + }).unwrap_or(0) } /// Returns `None` when the pointer is dangling and there is no allocated `RcBox` diff --git a/src/liballoc/rc/tests.rs b/src/liballoc/rc/tests.rs index 6fd3f90935714..bf5c85a5c5960 100644 --- a/src/liballoc/rc/tests.rs +++ b/src/liballoc/rc/tests.rs @@ -114,28 +114,28 @@ fn test_weak_count() { #[test] fn weak_counts() { - assert_eq!(Weak::weak_count(&Weak::::new()), None); + assert_eq!(Weak::weak_count(&Weak::::new()), 0); assert_eq!(Weak::strong_count(&Weak::::new()), 0); let a = Rc::new(0); let w = Rc::downgrade(&a); assert_eq!(Weak::strong_count(&w), 1); - assert_eq!(Weak::weak_count(&w), Some(1)); + assert_eq!(Weak::weak_count(&w), 1); let w2 = w.clone(); assert_eq!(Weak::strong_count(&w), 1); - assert_eq!(Weak::weak_count(&w), Some(2)); + assert_eq!(Weak::weak_count(&w), 2); assert_eq!(Weak::strong_count(&w2), 1); - assert_eq!(Weak::weak_count(&w2), Some(2)); + assert_eq!(Weak::weak_count(&w2), 2); drop(w); assert_eq!(Weak::strong_count(&w2), 1); - assert_eq!(Weak::weak_count(&w2), Some(1)); + assert_eq!(Weak::weak_count(&w2), 1); let a2 = a.clone(); assert_eq!(Weak::strong_count(&w2), 2); - assert_eq!(Weak::weak_count(&w2), Some(1)); + assert_eq!(Weak::weak_count(&w2), 1); drop(a2); drop(a); assert_eq!(Weak::strong_count(&w2), 0); - assert_eq!(Weak::weak_count(&w2), Some(1)); + assert_eq!(Weak::weak_count(&w2), 0); drop(w2); } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 3f86dfb469eab..1bfe3b802496b 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -12,7 +12,7 @@ use core::sync::atomic; use core::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst}; use core::borrow; use core::fmt; -use core::cmp::{self, Ordering}; +use core::cmp::Ordering; use core::iter; use core::intrinsics::abort; use core::mem::{self, align_of, align_of_val, size_of_val}; @@ -1508,9 +1508,8 @@ impl Weak { /// Gets an approximation of the number of `Weak` pointers pointing to this /// allocation. /// - /// If `self` was created using [`Weak::new`], this will return 0. If not, - /// the returned value is at least 1, since `self` still points to the - /// allocation. + /// If `self` was created using [`Weak::new`], or if there are no remaining + /// strong pointers, this will return 0. /// /// # Accuracy /// @@ -1520,30 +1519,21 @@ impl Weak { /// /// [`Weak::new`]: #method.new #[stable(feature = "weak_counts", since = "1.40.0")] - pub fn weak_count(&self) -> Option { - // Due to the implicit weak pointer added when any strong pointers are - // around, we cannot implement `weak_count` correctly since it - // necessarily requires accessing the strong count and weak count in an - // unsynchronized fashion. So this version is a bit racy. + pub fn weak_count(&self) -> usize { self.inner().map(|inner| { - let strong = inner.strong.load(SeqCst); let weak = inner.weak.load(SeqCst); + let strong = inner.strong.load(SeqCst); if strong == 0 { - // If the last `Arc` has *just* been dropped, it might not yet - // have removed the implicit weak count, so the value we get - // here might be 1 too high. - weak + 0 } else { - // As long as there's still at least 1 `Arc` around, subtract - // the implicit weak pointer. - // Note that the last `Arc` might get dropped between the 2 - // loads we do above, removing the implicit weak pointer. This - // means that the value might be 1 too low here. In order to not - // return 0 here (which would happen if we're the only weak - // pointer), we guard against that specifically. - cmp::max(1, weak - 1) + // Since we observed that there was at least one strong pointer + // after reading the weak count, we know that the implicit weak + // reference (present whenever any strong references are alive) + // was still around when we observed the weak count, and can + // therefore safely subtract it. + weak - 1 } - }) + }).unwrap_or(0) } /// Returns `None` when the pointer is dangling and there is no allocated `ArcInner`, diff --git a/src/liballoc/sync/tests.rs b/src/liballoc/sync/tests.rs index 9220f5e0333ef..be0200c9a4613 100644 --- a/src/liballoc/sync/tests.rs +++ b/src/liballoc/sync/tests.rs @@ -62,28 +62,28 @@ fn test_arc_get_mut() { #[test] fn weak_counts() { - assert_eq!(Weak::weak_count(&Weak::::new()), None); + assert_eq!(Weak::weak_count(&Weak::::new()), 0); assert_eq!(Weak::strong_count(&Weak::::new()), 0); let a = Arc::new(0); let w = Arc::downgrade(&a); assert_eq!(Weak::strong_count(&w), 1); - assert_eq!(Weak::weak_count(&w), Some(1)); + assert_eq!(Weak::weak_count(&w), 1); let w2 = w.clone(); assert_eq!(Weak::strong_count(&w), 1); - assert_eq!(Weak::weak_count(&w), Some(2)); + assert_eq!(Weak::weak_count(&w), 2); assert_eq!(Weak::strong_count(&w2), 1); - assert_eq!(Weak::weak_count(&w2), Some(2)); + assert_eq!(Weak::weak_count(&w2), 2); drop(w); assert_eq!(Weak::strong_count(&w2), 1); - assert_eq!(Weak::weak_count(&w2), Some(1)); + assert_eq!(Weak::weak_count(&w2), 1); let a2 = a.clone(); assert_eq!(Weak::strong_count(&w2), 2); - assert_eq!(Weak::weak_count(&w2), Some(1)); + assert_eq!(Weak::weak_count(&w2), 1); drop(a2); drop(a); assert_eq!(Weak::strong_count(&w2), 0); - assert_eq!(Weak::weak_count(&w2), Some(1)); + assert_eq!(Weak::weak_count(&w2), 0); drop(w2); } From 8cae411ae3f8fb2cc2c14218a6f5a87462016e95 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 20 Nov 2019 09:42:02 +0000 Subject: [PATCH 03/10] stabilize Result::map_or --- src/libcore/result.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 1a0845f3a6dda..fb4dc62d8c176 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -520,7 +520,6 @@ impl Result { /// # Examples /// /// ``` - /// #![feature(result_map_or)] /// let x: Result<_, &str> = Ok("foo"); /// assert_eq!(x.map_or(42, |v| v.len()), 3); /// @@ -528,7 +527,7 @@ impl Result { /// assert_eq!(x.map_or(42, |v| v.len()), 42); /// ``` #[inline] - #[unstable(feature = "result_map_or", issue = "66293")] + #[stable(feature = "result_map_or", since = "1.41.0")] pub fn map_or U>(self, default: U, f: F) -> U { match self { Ok(t) => f(t), From 93438fd839fd48c3714afd9ff5056720bc40ba62 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 25 Nov 2019 13:22:55 +0000 Subject: [PATCH 04/10] make use of Result::map_or --- src/librustc_mir/transform/const_prop.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 2 +- src/libterm/terminfo/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 67958af3460fc..69374e1236d7a 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -505,7 +505,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let left_bits = place_layout.size.bits(); let right_size = r.layout.size; let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size)); - if r_bits.ok().map_or(false, |b| b >= left_bits as u128) { + if r_bits.map_or(false, |b| b >= left_bits as u128) { let lint_root = match &self.source_scopes[source_info.scope].local_data { ClearCrossCrate::Set(data) => data.lint_root, ClearCrossCrate::Clear => return None, diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 9717190045afb..2699d3c267e9d 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1460,7 +1460,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { pcx.method_name = Some(method_name); pcx.assemble_inherent_candidates(); pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID) - .ok().map_or(None, |_| { + .map_or(None, |_| { pcx.pick_core() .and_then(|pick| pick.ok()) .and_then(|pick| Some(pick.item)) diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index be90195065eb7..09bea80c95a93 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -74,7 +74,7 @@ impl TermInfo { Err(..) => return Err(Error::TermUnset), }; - if term.is_err() && env::var("MSYSCON").ok().map_or(false, |s| "mintty.exe" == s) { + if term.is_err() && env::var("MSYSCON").map_or(false, |s| "mintty.exe" == s) { // msys terminal Ok(msys_terminfo()) } else { From 8a4632dec69082301d3fe67e48d422bc9fb665be Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Fri, 13 Dec 2019 19:54:18 +0100 Subject: [PATCH 05/10] Indicate origin of where type parameter for uninferred types --- .../infer/error_reporting/need_type_info.rs | 78 +++++++++++++++---- src/librustc/infer/mod.rs | 5 +- src/librustc/infer/resolve.rs | 2 +- src/librustc/infer/type_variable.rs | 3 +- src/librustc/traits/error_reporting.rs | 2 +- .../async-await/unresolved_type_param.stderr | 2 +- .../fn-const-param-infer.stderr | 2 +- src/test/ui/consts/issue-64662.stderr | 4 +- src/test/ui/error-codes/E0401.stderr | 2 +- src/test/ui/issues/issue-12028.stderr | 2 +- src/test/ui/issues/issue-16966.stderr | 2 +- src/test/ui/issues/issue-17551.stderr | 2 +- src/test/ui/issues/issue-25368.stderr | 2 +- src/test/ui/issues/issue-5062.stderr | 2 +- src/test/ui/issues/issue-6458-2.stderr | 2 +- src/test/ui/issues/issue-6458-3.stderr | 2 +- src/test/ui/issues/issue-6458.stderr | 2 +- .../missing-type-parameter.stderr | 2 +- .../span/type-annotations-needed-expr.stderr | 2 +- ...ts-multidispatch-convert-ambig-dest.stderr | 2 +- .../or_else-multiple-type-params.stderr | 2 +- src/test/ui/type-inference/sort_by_key.stderr | 2 +- .../unbounded-associated-type.stderr | 2 +- ...ed-type-param-in-fn-with-assoc-type.stderr | 2 +- .../unbounded-type-param-in-fn.stderr | 2 +- .../ui/type/type-annotation-needed.stderr | 2 +- src/test/ui/unconstrained-none.stderr | 2 +- src/test/ui/unconstrained-ref.stderr | 2 +- 28 files changed, 97 insertions(+), 41 deletions(-) diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 8878683f3a7a4..ebb94cc72ffe0 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -3,7 +3,7 @@ use crate::hir::{self, Body, FunctionRetTy, Expr, ExprKind, HirId, Local, Pat}; use crate::hir::intravisit::{self, Visitor, NestedVisitorMap}; use crate::infer::InferCtxt; use crate::infer::type_variable::TypeVariableOriginKind; -use crate::ty::{self, Ty, Infer, TyVar}; +use crate::ty::{self, Ty, Infer, TyVar, DefIdTree}; use crate::ty::print::Print; use syntax::source_map::DesugaringKind; use syntax::symbol::kw; @@ -117,6 +117,8 @@ fn closure_return_type_suggestion( descr: &str, name: &str, ret: &str, + parent_name: Option, + parent_descr: Option<&str>, ) { let (arrow, post) = match output { FunctionRetTy::DefaultReturn(_) => ("-> ", " "), @@ -138,7 +140,12 @@ fn closure_return_type_suggestion( suggestion, Applicability::HasPlaceholders, ); - err.span_label(span, InferCtxt::missing_type_msg(&name, &descr)); + err.span_label(span, InferCtxt::missing_type_msg( + &name, + &descr, + parent_name, + parent_descr + )); } /// Given a closure signature, return a `String` containing a list of all its argument types. @@ -177,16 +184,31 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &self, ty: Ty<'tcx>, highlight: Option, - ) -> (String, Option, Cow<'static, str>) { + ) -> (String, Option, Cow<'static, str>, Option, Option<&'static str>) { if let ty::Infer(ty::TyVar(ty_vid)) = ty.kind { let ty_vars = self.type_variables.borrow(); let var_origin = ty_vars.var_origin(ty_vid); - if let TypeVariableOriginKind::TypeParameterDefinition(name) = var_origin.kind { + if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) = var_origin.kind { + let parent_def_id = def_id.and_then(|def_id| self.tcx.parent(def_id)); + let (parent_name, parent_desc) = if let Some(parent_def_id) = parent_def_id { + let parent_name = self.tcx.def_key(parent_def_id).disambiguated_data.data + .get_opt_name().map(|parent_symbol| parent_symbol.to_string()); + + let type_parent_desc = self.tcx.def_kind(parent_def_id) + .map(|parent_def_kind| parent_def_kind.descr(parent_def_id)); + + (parent_name, type_parent_desc) + } else { + (None, None) + }; + if name != kw::SelfUpper { return ( name.to_string(), Some(var_origin.span), "type parameter".into(), + parent_name, + parent_desc, ); } } @@ -198,7 +220,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { printer.region_highlight_mode = highlight; } let _ = ty.print(printer); - (s, None, ty.prefix_string()) + (s, None, ty.prefix_string(), None, None) } pub fn need_type_info_err( @@ -209,7 +231,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { error_code: TypeAnnotationNeeded, ) -> DiagnosticBuilder<'tcx> { let ty = self.resolve_vars_if_possible(&ty); - let (name, name_sp, descr) = self.extract_type_name(&ty, None); + let (name, name_sp, descr, parent_name, parent_descr) = self.extract_type_name(&ty, None); + let mut local_visitor = FindLocalByTypeVisitor::new(&self, ty, &self.tcx.hir()); let ty_to_string = |ty: Ty<'tcx>| -> String { @@ -218,7 +241,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let ty_vars = self.type_variables.borrow(); let getter = move |ty_vid| { let var_origin = ty_vars.var_origin(ty_vid); - if let TypeVariableOriginKind::TypeParameterDefinition(name) = var_origin.kind { + if let TypeVariableOriginKind::TypeParameterDefinition(name, _) = var_origin.kind { return Some(name.to_string()); } None @@ -317,6 +340,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &descr, &name, &ret, + parent_name, + parent_descr, ); // We don't want to give the other suggestions when the problem is the // closure return type. @@ -433,8 +458,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if !err.span.span_labels().iter().any(|span_label| { span_label.label.is_some() && span_label.span == span }) && local_visitor.found_arg_pattern.is_none() - { // Avoid multiple labels pointing at `span`. - err.span_label(span, InferCtxt::missing_type_msg(&name, &descr)); + { + // Avoid multiple labels pointing at `span`. + err.span_label( + span, + InferCtxt::missing_type_msg(&name, &descr, parent_name, parent_descr) + ); } err @@ -496,19 +525,42 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { ty: Ty<'tcx>, ) -> DiagnosticBuilder<'tcx> { let ty = self.resolve_vars_if_possible(&ty); - let (name, _, descr) = self.extract_type_name(&ty, None); + let (name, _, descr, parent_name, parent_descr) = self.extract_type_name(&ty, None); + let mut err = struct_span_err!( self.tcx.sess, span, E0698, "type inside {} must be known in this context", kind, ); - err.span_label(span, InferCtxt::missing_type_msg(&name, &descr)); + err.span_label(span, InferCtxt::missing_type_msg( + &name, + &descr, + parent_name, + parent_descr + )); err } - fn missing_type_msg(type_name: &str, descr: &str) -> Cow<'static, str>{ + fn missing_type_msg( + type_name: &str, + descr: &str, + parent_name: Option, + parent_descr: Option<&str>, + ) -> Cow<'static, str> { if type_name == "_" { "cannot infer type".into() } else { - format!("cannot infer type for {} `{}`", descr, type_name).into() + let parent_desc = if let Some(parent_name) = parent_name { + let parent_type_descr = if let Some(parent_descr) = parent_descr { + format!(" the {}", parent_descr) + } else { + "".into() + }; + + format!(" declared on{} `{}`", parent_type_descr, parent_name) + } else { + "".to_string() + }; + + format!("cannot infer type for {} `{}`{}", descr, type_name, parent_desc).into() } } } diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 73977878af337..996a722e157fa 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -1135,7 +1135,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { self.universe(), false, TypeVariableOrigin { - kind: TypeVariableOriginKind::TypeParameterDefinition(param.name), + kind: TypeVariableOriginKind::TypeParameterDefinition( + param.name, + Some(param.def_id) + ), span, }, ); diff --git a/src/librustc/infer/resolve.rs b/src/librustc/infer/resolve.rs index 613f66d7ffd7e..ea4a28c22a9e7 100644 --- a/src/librustc/infer/resolve.rs +++ b/src/librustc/infer/resolve.rs @@ -124,7 +124,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> { if let ty::TyVar(ty_vid) = infer_ty { let ty_vars = self.infcx.type_variables.borrow(); if let TypeVariableOrigin { - kind: TypeVariableOriginKind::TypeParameterDefinition(_), + kind: TypeVariableOriginKind::TypeParameterDefinition(_, _), span, } = *ty_vars.var_origin(ty_vid) { diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index f79a30c7ae8f3..5a12de25f4b75 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -1,6 +1,7 @@ use syntax::symbol::Symbol; use syntax_pos::Span; use crate::ty::{self, Ty, TyVid}; +use crate::hir::def_id::DefId; use std::cmp; use std::marker::PhantomData; @@ -49,7 +50,7 @@ pub enum TypeVariableOriginKind { MiscVariable, NormalizeProjectionType, TypeInference, - TypeParameterDefinition(Symbol), + TypeParameterDefinition(Symbol, Option), /// One of the upvars or closure kind parameters in a `ClosureSubsts` /// (before it has been determined). diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index da36b31038de7..018bed9666487 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -2113,7 +2113,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var( TypeVariableOrigin { - kind: TypeVariableOriginKind::TypeParameterDefinition(name), + kind: TypeVariableOriginKind::TypeParameterDefinition(name, None), span: DUMMY_SP, } ) diff --git a/src/test/ui/async-await/unresolved_type_param.stderr b/src/test/ui/async-await/unresolved_type_param.stderr index b9b4f5133b9a7..3ffdb8ce6b9a1 100644 --- a/src/test/ui/async-await/unresolved_type_param.stderr +++ b/src/test/ui/async-await/unresolved_type_param.stderr @@ -2,7 +2,7 @@ error[E0698]: type inside `async fn` body must be known in this context --> $DIR/unresolved_type_param.rs:9:5 | LL | bar().await; - | ^^^ cannot infer type for type parameter `T` + | ^^^ cannot infer type for type parameter `T` declared on the function `bar` | note: the type is part of the `async fn` body because of this `await` --> $DIR/unresolved_type_param.rs:9:5 diff --git a/src/test/ui/const-generics/fn-const-param-infer.stderr b/src/test/ui/const-generics/fn-const-param-infer.stderr index 9ccad7bcdd7e6..44eab8baa40a6 100644 --- a/src/test/ui/const-generics/fn-const-param-infer.stderr +++ b/src/test/ui/const-generics/fn-const-param-infer.stderr @@ -30,7 +30,7 @@ error[E0282]: type annotations needed --> $DIR/fn-const-param-infer.rs:22:23 | LL | let _ = Checked::; - | ^^^^^^^ cannot infer type for type parameter `T` + | ^^^^^^^ cannot infer type for type parameter `T` declared on the function `generic` error[E0308]: mismatched types --> $DIR/fn-const-param-infer.rs:25:40 diff --git a/src/test/ui/consts/issue-64662.stderr b/src/test/ui/consts/issue-64662.stderr index b3c673ec027ef..dd281e911da96 100644 --- a/src/test/ui/consts/issue-64662.stderr +++ b/src/test/ui/consts/issue-64662.stderr @@ -2,13 +2,13 @@ error[E0282]: type annotations needed --> $DIR/issue-64662.rs:2:9 | LL | A = foo(), - | ^^^ cannot infer type for type parameter `T` + | ^^^ cannot infer type for type parameter `T` declared on the function `foo` error[E0282]: type annotations needed --> $DIR/issue-64662.rs:3:9 | LL | B = foo(), - | ^^^ cannot infer type for type parameter `T` + | ^^^ cannot infer type for type parameter `T` declared on the function `foo` error: aborting due to 2 previous errors diff --git a/src/test/ui/error-codes/E0401.stderr b/src/test/ui/error-codes/E0401.stderr index 0adf982d71c90..8b1d4e6c07ceb 100644 --- a/src/test/ui/error-codes/E0401.stderr +++ b/src/test/ui/error-codes/E0401.stderr @@ -36,7 +36,7 @@ error[E0282]: type annotations needed --> $DIR/E0401.rs:11:5 | LL | bfnr(x); - | ^^^^ cannot infer type for type parameter `U` + | ^^^^ cannot infer type for type parameter `U` declared on the function `bfnr` error: aborting due to 4 previous errors diff --git a/src/test/ui/issues/issue-12028.stderr b/src/test/ui/issues/issue-12028.stderr index 5f2dd729c739f..fe7e8f89f7f1a 100644 --- a/src/test/ui/issues/issue-12028.stderr +++ b/src/test/ui/issues/issue-12028.stderr @@ -2,7 +2,7 @@ error[E0284]: type annotations needed --> $DIR/issue-12028.rs:27:14 | LL | self.input_stream(&mut stream); - | ^^^^^^^^^^^^ cannot infer type for type parameter `H` + | ^^^^^^^^^^^^ cannot infer type for type parameter `H` declared on the trait `StreamHash` | = note: cannot resolve `<_ as StreamHasher>::S == ::S` diff --git a/src/test/ui/issues/issue-16966.stderr b/src/test/ui/issues/issue-16966.stderr index 0d565af79b5de..49a12cc200947 100644 --- a/src/test/ui/issues/issue-16966.stderr +++ b/src/test/ui/issues/issue-16966.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-16966.rs:2:5 | LL | panic!(std::default::Default::default()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `M` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `M` declared on the function `begin_panic` | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-17551.stderr b/src/test/ui/issues/issue-17551.stderr index 5468268e7de94..48405a292f3aa 100644 --- a/src/test/ui/issues/issue-17551.stderr +++ b/src/test/ui/issues/issue-17551.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `B` --> $DIR/issue-17551.rs:6:15 | LL | let foo = B(marker::PhantomData); - | --- ^ cannot infer type for type parameter `T` + | --- ^ cannot infer type for type parameter `T` declared on the struct `B` | | | consider giving `foo` the explicit type `B`, where the type parameter `T` is specified diff --git a/src/test/ui/issues/issue-25368.stderr b/src/test/ui/issues/issue-25368.stderr index de020d4b56ba1..a09de86a708f8 100644 --- a/src/test/ui/issues/issue-25368.stderr +++ b/src/test/ui/issues/issue-25368.stderr @@ -5,7 +5,7 @@ LL | let (tx, rx) = channel(); | -------- consider giving this pattern the explicit type `(std::sync::mpsc::Sender>, std::sync::mpsc::Receiver>)`, where the type parameter `T` is specified ... LL | tx.send(Foo{ foo: PhantomData }); - | ^^^ cannot infer type for type parameter `T` + | ^^^ cannot infer type for type parameter `T` declared on the struct `Foo` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-5062.stderr b/src/test/ui/issues/issue-5062.stderr index a20118d691170..9fa15dc967914 100644 --- a/src/test/ui/issues/issue-5062.stderr +++ b/src/test/ui/issues/issue-5062.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-5062.rs:1:29 | LL | fn main() { format!("{:?}", None); } - | ^^^^ cannot infer type for type parameter `T` + | ^^^^ cannot infer type for type parameter `T` declared on the enum `Option` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-6458-2.stderr b/src/test/ui/issues/issue-6458-2.stderr index d538a69045f32..da16f95dc3de6 100644 --- a/src/test/ui/issues/issue-6458-2.stderr +++ b/src/test/ui/issues/issue-6458-2.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-6458-2.rs:3:21 | LL | format!("{:?}", None); - | ^^^^ cannot infer type for type parameter `T` + | ^^^^ cannot infer type for type parameter `T` declared on the enum `Option` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-6458-3.stderr b/src/test/ui/issues/issue-6458-3.stderr index 6b3f469ee3789..a71c159db0b0e 100644 --- a/src/test/ui/issues/issue-6458-3.stderr +++ b/src/test/ui/issues/issue-6458-3.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-6458-3.rs:4:5 | LL | mem::transmute(0); - | ^^^^^^^^^^^^^^ cannot infer type for type parameter `U` + | ^^^^^^^^^^^^^^ cannot infer type for type parameter `U` declared on the function `transmute` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-6458.stderr b/src/test/ui/issues/issue-6458.stderr index de315659b6df9..f1a982616a4a1 100644 --- a/src/test/ui/issues/issue-6458.stderr +++ b/src/test/ui/issues/issue-6458.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-6458.rs:9:4 | LL | foo(TypeWithState(marker::PhantomData)); - | ^^^ cannot infer type for type parameter `State` + | ^^^ cannot infer type for type parameter `State` declared on the function `foo` error: aborting due to previous error diff --git a/src/test/ui/missing/missing-items/missing-type-parameter.stderr b/src/test/ui/missing/missing-items/missing-type-parameter.stderr index be97f2373c313..1219badc5b3fc 100644 --- a/src/test/ui/missing/missing-items/missing-type-parameter.stderr +++ b/src/test/ui/missing/missing-items/missing-type-parameter.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/missing-type-parameter.rs:4:5 | LL | foo(); - | ^^^ cannot infer type for type parameter `X` + | ^^^ cannot infer type for type parameter `X` declared on the function `foo` error: aborting due to previous error diff --git a/src/test/ui/span/type-annotations-needed-expr.stderr b/src/test/ui/span/type-annotations-needed-expr.stderr index 8366285edcda8..2b92f9b93bff2 100644 --- a/src/test/ui/span/type-annotations-needed-expr.stderr +++ b/src/test/ui/span/type-annotations-needed-expr.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | let _ = (vec![1,2,3]).into_iter().sum() as f64; | ^^^ | | - | cannot infer type for type parameter `S` + | cannot infer type for type parameter `S` declared on the method `sum` | help: consider specifying the type argument in the method call: `sum::` | = note: type must be known at this point diff --git a/src/test/ui/traits/traits-multidispatch-convert-ambig-dest.stderr b/src/test/ui/traits/traits-multidispatch-convert-ambig-dest.stderr index 7bcda234c4b0d..338c8cbf2e4f2 100644 --- a/src/test/ui/traits/traits-multidispatch-convert-ambig-dest.stderr +++ b/src/test/ui/traits/traits-multidispatch-convert-ambig-dest.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/traits-multidispatch-convert-ambig-dest.rs:26:5 | LL | test(22, std::default::Default::default()); - | ^^^^ cannot infer type for type parameter `U` + | ^^^^ cannot infer type for type parameter `U` declared on the function `test` error: aborting due to previous error diff --git a/src/test/ui/type-inference/or_else-multiple-type-params.stderr b/src/test/ui/type-inference/or_else-multiple-type-params.stderr index 141cc25ffe22d..b9258b20f5add 100644 --- a/src/test/ui/type-inference/or_else-multiple-type-params.stderr +++ b/src/test/ui/type-inference/or_else-multiple-type-params.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | .or_else(|err| { | ^^^^^^^ | | - | cannot infer type for type parameter `F` + | cannot infer type for type parameter `F` declared on the method `or_else` | help: consider specifying the type arguments in the method call: `or_else::` error: aborting due to previous error diff --git a/src/test/ui/type-inference/sort_by_key.stderr b/src/test/ui/type-inference/sort_by_key.stderr index 1d386bd1f42c9..e74c0dfa5e20c 100644 --- a/src/test/ui/type-inference/sort_by_key.stderr +++ b/src/test/ui/type-inference/sort_by_key.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | lst.sort_by_key(|&(v, _)| v.iter().sum()); | ^^^^^^^^^^^ --- help: consider specifying the type argument in the method call: `sum::` | | - | cannot infer type for type parameter `K` + | cannot infer type for type parameter `K` declared on the method `sort_by_key` error: aborting due to previous error diff --git a/src/test/ui/type-inference/unbounded-associated-type.stderr b/src/test/ui/type-inference/unbounded-associated-type.stderr index 726dd4b475817..19e2bd4513dc5 100644 --- a/src/test/ui/type-inference/unbounded-associated-type.stderr +++ b/src/test/ui/type-inference/unbounded-associated-type.stderr @@ -8,7 +8,7 @@ LL | S(std::marker::PhantomData).foo(); | ^-------------------------------- | | | this method call resolves to `::A` - | cannot infer type for type parameter `X` + | cannot infer type for type parameter `X` declared on the struct `S` error: aborting due to previous error diff --git a/src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.stderr b/src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.stderr index 52039d0e934e6..d60ca4a49325c 100644 --- a/src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.stderr +++ b/src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/unbounded-type-param-in-fn-with-assoc-type.rs:8:5 | LL | foo(); - | ^^^ cannot infer type for type parameter `T` + | ^^^ cannot infer type for type parameter `T` declared on the function `foo` error: aborting due to previous error diff --git a/src/test/ui/type-inference/unbounded-type-param-in-fn.stderr b/src/test/ui/type-inference/unbounded-type-param-in-fn.stderr index 8d317df6ce95a..45d879d8d5670 100644 --- a/src/test/ui/type-inference/unbounded-type-param-in-fn.stderr +++ b/src/test/ui/type-inference/unbounded-type-param-in-fn.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/unbounded-type-param-in-fn.rs:6:5 | LL | foo(); - | ^^^ cannot infer type for type parameter `T` + | ^^^ cannot infer type for type parameter `T` declared on the function `foo` error: aborting due to previous error diff --git a/src/test/ui/type/type-annotation-needed.stderr b/src/test/ui/type/type-annotation-needed.stderr index 94425440d333c..c6a811e836342 100644 --- a/src/test/ui/type/type-annotation-needed.stderr +++ b/src/test/ui/type/type-annotation-needed.stderr @@ -7,7 +7,7 @@ LL | fn foo>(x: i32) {} LL | foo(42); | ^^^ | | - | cannot infer type for type parameter `T` + | cannot infer type for type parameter `T` declared on the function `foo` | help: consider specifying the type argument in the function call: `foo::` | = note: cannot resolve `_: std::convert::Into` diff --git a/src/test/ui/unconstrained-none.stderr b/src/test/ui/unconstrained-none.stderr index 6c4fde94a6199..fbd71bd091d0b 100644 --- a/src/test/ui/unconstrained-none.stderr +++ b/src/test/ui/unconstrained-none.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/unconstrained-none.rs:4:5 | LL | None; - | ^^^^ cannot infer type for type parameter `T` + | ^^^^ cannot infer type for type parameter `T` declared on the enum `Option` error: aborting due to previous error diff --git a/src/test/ui/unconstrained-ref.stderr b/src/test/ui/unconstrained-ref.stderr index d6985a61daf0b..eb8ebb5165d18 100644 --- a/src/test/ui/unconstrained-ref.stderr +++ b/src/test/ui/unconstrained-ref.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/unconstrained-ref.rs:6:5 | LL | S { o: &None }; - | ^ cannot infer type for type parameter `T` + | ^ cannot infer type for type parameter `T` declared on the struct `S` error: aborting due to previous error From e5d39ee842aaa0c5c450a2edec4b8f4c26262ed8 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 10 Dec 2019 11:54:10 -0800 Subject: [PATCH 06/10] Update cargo, books --- Cargo.lock | 2 +- src/doc/book | 2 +- src/doc/embedded-book | 2 +- src/doc/nomicon | 2 +- src/doc/rust-by-example | 2 +- src/tools/cargo | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1af0442dde7fc..db2294b45f290 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -338,7 +338,7 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.0" +version = "0.1.1" dependencies = [ "serde", ] diff --git a/src/doc/book b/src/doc/book index 81ebaa2a3f88d..ef8bb568035de 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 81ebaa2a3f88d4d106516c489682e64cacba4f60 +Subproject commit ef8bb568035ded8ddfa30a9309026638cc3c8136 diff --git a/src/doc/embedded-book b/src/doc/embedded-book index 5ca585c4a7552..c262349302822 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit 5ca585c4a7552efb546e7681c3de0712f4ae4fdc +Subproject commit c26234930282210849256e4ecab925f0f2daf3be diff --git a/src/doc/nomicon b/src/doc/nomicon index 041c46e692a25..8be35b201f9cf 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit 041c46e692a2592853aeca132c8dfe8eb5a79a9e +Subproject commit 8be35b201f9cf0a4c3fcc96c83ac21671dcf3112 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 4835e02582672..b7ac1bc76b7d0 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 4835e025826729827a94fdeb7cb85fed288d08bb +Subproject commit b7ac1bc76b7d02a43c83b3a931d226f708aa1ff4 diff --git a/src/tools/cargo b/src/tools/cargo index 626f0f40efd32..5a139f7e6d67f 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 626f0f40efd32e6b3dbade50cd53fdfaa08446ba +Subproject commit 5a139f7e6d67fd8a416a3f19d8e01581d24c0333 From 5141c48ef14bf9b330e164defce0f3fa3b61b1a2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 14 Dec 2019 14:13:54 -0800 Subject: [PATCH 07/10] Update cargo --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index 5a139f7e6d67f..19a0de242f442 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 5a139f7e6d67fd8a416a3f19d8e01581d24c0333 +Subproject commit 19a0de242f442ac7149c511031599aafa35b36dc From 9778e03665edbed80eb684ba893abd4e18a0a583 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 14 Dec 2019 19:26:25 -0800 Subject: [PATCH 08/10] Bump Weak::strong_count/weak_count stabilizations from 1.40 to 1.41 --- src/liballoc/rc.rs | 4 ++-- src/liballoc/sync.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 0dab68b155d87..8cfb9fdf8ea93 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1803,7 +1803,7 @@ impl Weak { /// If `self` was created using [`Weak::new`], this will return 0. /// /// [`Weak::new`]: #method.new - #[stable(feature = "weak_counts", since = "1.40.0")] + #[stable(feature = "weak_counts", since = "1.41.0")] pub fn strong_count(&self) -> usize { if let Some(inner) = self.inner() { inner.strong() @@ -1815,7 +1815,7 @@ impl Weak { /// Gets the number of `Weak` pointers pointing to this allocation. /// /// If no strong pointers remain, this will return zero. - #[stable(feature = "weak_counts", since = "1.40.0")] + #[stable(feature = "weak_counts", since = "1.41.0")] pub fn weak_count(&self) -> usize { self.inner().map(|inner| { if inner.strong() > 0 { diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 1bfe3b802496b..d7653f78598ec 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -1496,7 +1496,7 @@ impl Weak { /// If `self` was created using [`Weak::new`], this will return 0. /// /// [`Weak::new`]: #method.new - #[stable(feature = "weak_counts", since = "1.40.0")] + #[stable(feature = "weak_counts", since = "1.41.0")] pub fn strong_count(&self) -> usize { if let Some(inner) = self.inner() { inner.strong.load(SeqCst) @@ -1518,7 +1518,7 @@ impl Weak { /// `Weak`s pointing to the same allocation. /// /// [`Weak::new`]: #method.new - #[stable(feature = "weak_counts", since = "1.40.0")] + #[stable(feature = "weak_counts", since = "1.41.0")] pub fn weak_count(&self) -> usize { self.inner().map(|inner| { let weak = inner.weak.load(SeqCst); From e28153e7a60f2ba62aa438e68cf086f07f0d3894 Mon Sep 17 00:00:00 2001 From: lcnr/Bastian Kauschke Date: Sun, 15 Dec 2019 12:59:02 +0100 Subject: [PATCH 09/10] fix doc comment --- src/libcore/any.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/any.rs b/src/libcore/any.rs index b0e3021e0bf4d..7935c9b1b392d 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -476,7 +476,7 @@ pub const fn type_name() -> &'static str { /// /// This is intended for diagnostic use. The exact contents and format of the /// string are not specified, other than being a best-effort description of the -/// type. For example, `type_name_of::>(None)` could return the +/// type. For example, `type_name_of::>(None)` could return /// `"Option"` or `"std::option::Option"`, but not /// `"foobar"`. In addition, the output may change between versions of the /// compiler. From 8a5969d2e91d9791f508f8f4631234f87099ae41 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 15 Dec 2019 15:40:47 +0100 Subject: [PATCH 10/10] Fix repetition in matches/mod.rs --- src/librustc_mir/build/matches/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 032ea7d8161cb..718e8bd4e936d 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -69,8 +69,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// 3. Create the decision tree and record the places that we bind or test. /// 4. Determine the fake borrows that are needed from the above places. /// Create the required temporaries for them. - /// 5. Create everything else: Create everything else: the guards and the - /// arms. + /// 5. Create everything else: the guards and the arms. /// /// ## Fake Reads and borrows ///