Skip to content
Permalink
Browse files

Auto merge of #64151 - estebank:binding-error, r=varkor

On obligation errors point at the unfulfilled binding when possible

CC #42855, #64130, #64135.
  • Loading branch information...
bors committed Sep 17, 2019
2 parents 5670d04 + eac2b02 commit 720a4a2c011ffdf099e8aa11dc7d666e1223091b
Showing with 712 additions and 605 deletions.
  1. +2 −0 src/etc/generate-deriving-span-tests.py
  2. +4 −1 src/librustc/hir/lowering.rs
  3. +12 −0 src/librustc/hir/mod.rs
  4. +18 −4 src/librustc/traits/error_reporting.rs
  5. +3 −0 src/librustc/traits/mod.rs
  6. +1 −0 src/librustc/traits/structural_impls.rs
  7. +4 −0 src/librustc/ty/mod.rs
  8. +38 −14 src/librustc_typeck/check/mod.rs
  9. +6 −5 src/libsyntax/parse/parser/path.rs
  10. +22 −22 src/test/ui/anonymous-higher-ranked-lifetime.stderr
  11. +2 −2 src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr
  12. +1 −1 src/test/ui/associated-types/associated-types-eq-3.stderr
  13. +42 −56 src/test/ui/associated-types/associated-types-eq-hr.stderr
  14. +1 −1 src/test/ui/associated-types/associated-types-issue-20346.stderr
  15. +2 −2 src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr
  16. +2 −2 src/test/ui/associated-types/associated-types-path-2.stderr
  17. +6 −6 src/test/ui/associated-types/higher-ranked-projection.bad.stderr
  18. +4 −4 src/test/ui/async-await/async-fn-nonsend.stderr
  19. +2 −0 src/test/ui/async-await/issues/issue-62009-1.rs
  20. +10 −7 src/test/ui/async-await/issues/issue-62009-1.stderr
  21. +1 −1 src/test/ui/chalkify/type_inference.stderr
  22. +24 −27 src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr
  23. +8 −9 src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr
  24. +1 −1 src/test/ui/closures/closure-bounds-subtype.stderr
  25. +2 −0 src/test/ui/closures/closure-move-sync.rs
  26. +14 −6 src/test/ui/closures/closure-move-sync.stderr
  27. +2 −1 src/test/ui/defaulted-never-note.rs
  28. +2 −2 src/test/ui/defaulted-never-note.stderr
  29. +2 −0 src/test/ui/derives/derives-span-Hash-enum-struct-variant.rs
  30. +5 −2 src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr
  31. +2 −0 src/test/ui/derives/derives-span-Hash-enum.rs
  32. +5 −2 src/test/ui/derives/derives-span-Hash-enum.stderr
  33. +2 −0 src/test/ui/derives/derives-span-Hash-struct.rs
  34. +5 −2 src/test/ui/derives/derives-span-Hash-struct.stderr
  35. +2 −0 src/test/ui/derives/derives-span-Hash-tuple-struct.rs
  36. +5 −2 src/test/ui/derives/derives-span-Hash-tuple-struct.stderr
  37. +3 −3 src/test/ui/derives/deriving-copyclone.stderr
  38. +1 −1 src/test/ui/did_you_mean/recursion_limit.stderr
  39. +5 −5 src/test/ui/error-codes/E0214.stderr
  40. +1 −1 src/test/ui/error-codes/E0271.stderr
  41. +1 −1 src/test/ui/error-codes/E0277-2.stderr
  42. +1 −1 src/test/ui/error-codes/E0277.stderr
  43. +1 −1 src/test/ui/error-should-say-copy-not-pod.stderr
  44. +2 −2 src/test/ui/extern/extern-types-not-sync-send.stderr
  45. +4 −4 src/test/ui/extern/extern-types-unsized.stderr
  46. +1 −1 src/test/ui/extern/extern-wrong-value-type.stderr
  47. +2 −2 src/test/ui/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr
  48. +2 −2 src/test/ui/fmt/send-sync.stderr
  49. +1 −1 src/test/ui/fn/fn-trait-formatting.stderr
  50. +6 −7 src/test/ui/generator-yielding-or-returning-itself.stderr
  51. +2 −2 src/test/ui/generator/not-send-sync.stderr
  52. +1 −1 src/test/ui/generator/static-not-unpin.stderr
  53. +6 −7 src/test/ui/hrtb/hrtb-conflate-regions.stderr
  54. +7 −8 src/test/ui/hrtb/hrtb-exists-forall-trait-contravariant.stderr
  55. +7 −8 src/test/ui/hrtb/hrtb-exists-forall-trait-covariant.stderr
  56. +7 −8 src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.stderr
  57. +6 −7 src/test/ui/hrtb/hrtb-higher-ranker-supertraits-transitive.stderr
  58. +12 −19 src/test/ui/hrtb/hrtb-higher-ranker-supertraits.stderr
  59. +12 −14 src/test/ui/hrtb/hrtb-just-for-static.stderr
  60. +1 −1 src/test/ui/hrtb/issue-46989.stderr
  61. +1 −1 src/test/ui/impl-trait/auto-trait-leak.stderr
  62. +2 −2 src/test/ui/impl-trait/auto-trait-leak2.stderr
  63. +2 −0 src/test/ui/interior-mutability/interior-mutability.rs
  64. +7 −3 src/test/ui/interior-mutability/interior-mutability.stderr
  65. +1 −1 src/test/ui/issues/issue-1920-1.stderr
  66. +1 −1 src/test/ui/issues/issue-1920-2.stderr
  67. +1 −1 src/test/ui/issues/issue-1920-3.stderr
  68. +2 −0 src/test/ui/issues/issue-21160.rs
  69. +5 −2 src/test/ui/issues/issue-21160.stderr
  70. +1 −1 src/test/ui/issues/issue-21763.stderr
  71. +5 −5 src/test/ui/issues/issue-23589.stderr
  72. +1 −1 src/test/ui/issues/issue-25076.stderr
  73. +1 −1 src/test/ui/issues/issue-32963.stderr
  74. +6 −6 src/test/ui/issues/issue-32995-2.stderr
  75. +14 −14 src/test/ui/issues/issue-32995.stderr
  76. +2 −2 src/test/ui/issues/issue-39687.stderr
  77. +2 −2 src/test/ui/issues/issue-40827.stderr
  78. +17 −21 src/test/ui/issues/issue-43623.stderr
  79. +9 −10 src/test/ui/issues/issue-47706.stderr
  80. +17 −15 src/test/ui/issues/issue-60283.stderr
  81. +11 −11 src/test/ui/kindck/kindck-copy.stderr
  82. +1 −1 src/test/ui/kindck/kindck-impl-type-params-2.stderr
  83. +1 −1 src/test/ui/kindck/kindck-inherited-copy-bound.stderr
  84. +1 −1 src/test/ui/kindck/kindck-nonsendable-1.stderr
  85. +2 −2 src/test/ui/kindck/kindck-send-object.stderr
  86. +2 −2 src/test/ui/kindck/kindck-send-object1.stderr
  87. +2 −2 src/test/ui/kindck/kindck-send-object2.stderr
  88. +1 −1 src/test/ui/kindck/kindck-send-owned.stderr
  89. +1 −1 src/test/ui/kindck/kindck-send-unsafe.stderr
  90. +1 −1 src/test/ui/marker_trait_attr/overlap-marker-trait.stderr
  91. +4 −4 src/test/ui/mismatched_types/E0631.stderr
  92. +3 −3 src/test/ui/mismatched_types/closure-arg-count.stderr
  93. +2 −2 src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr
  94. +2 −2 src/test/ui/mismatched_types/closure-mismatch.stderr
  95. +2 −2 src/test/ui/mismatched_types/fn-variance-1.stderr
  96. +2 −1 src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.rs
  97. +2 −2 src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr
  98. +1 −1 src/test/ui/mut/mutable-enum-indirect.stderr
  99. +1 −1 src/test/ui/mutexguard-sync.stderr
  100. +44 −44 src/test/ui/namespace/namespace-mix.stderr
  101. +2 −0 src/test/ui/no-send-res-ports.rs
  102. +8 −4 src/test/ui/no-send-res-ports.stderr
  103. +1 −1 src/test/ui/no_send-enum.stderr
  104. +1 −1 src/test/ui/no_send-rc.stderr
  105. +1 −1 src/test/ui/no_send-struct.stderr
  106. +1 −1 src/test/ui/no_share-enum.stderr
  107. +1 −1 src/test/ui/no_share-struct.stderr
  108. +2 −2 src/test/ui/not-panic/not-panic-safe-2.stderr
  109. +2 −2 src/test/ui/not-panic/not-panic-safe-3.stderr
  110. +2 −2 src/test/ui/not-panic/not-panic-safe-4.stderr
  111. +1 −1 src/test/ui/not-panic/not-panic-safe-5.stderr
  112. +2 −2 src/test/ui/not-panic/not-panic-safe-6.stderr
  113. +1 −1 src/test/ui/not-panic/not-panic-safe.stderr
  114. +6 −6 src/test/ui/not-sync.stderr
  115. +1 −1 src/test/ui/object-does-not-impl-trait.stderr
  116. +2 −2 src/test/ui/on-unimplemented/on-trait.stderr
  117. +1 −1 src/test/ui/overlap-marker-trait.stderr
  118. +2 −2 src/test/ui/parser/type-parameters-in-field-exprs.stderr
  119. +2 −2 src/test/ui/phantom-oibit.stderr
  120. +6 −6 src/test/ui/regions/regions-close-object-into-object-5.stderr
  121. +2 −0 src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.rs
  122. +6 −2 src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr
  123. +1 −1 src/test/ui/str/str-mut-idx.stderr
  124. +1 −1 src/test/ui/substs-ppaux.normal.stderr
  125. +1 −1 src/test/ui/substs-ppaux.verbose.stderr
  126. +1 −1 src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
  127. +1 −1 src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
  128. +1 −1 src/test/ui/suggestions/into-str.stderr
  129. +2 −2 src/test/ui/traits/trait-alias/trait-alias-cross-crate.stderr
  130. +2 −0 src/test/ui/traits/trait-suggest-where-clause.rs
  131. +27 −11 src/test/ui/traits/trait-suggest-where-clause.stderr
  132. +1 −1 src/test/ui/traits/traits-inductive-overflow-simultaneous.stderr
  133. +1 −1 src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr
  134. +1 −1 src/test/ui/traits/traits-inductive-overflow-supertrait.stderr
  135. +1 −1 src/test/ui/traits/traits-inductive-overflow-two-traits.stderr
  136. +5 −5 src/test/ui/traits/traits-negative-impls.stderr
  137. +1 −1 src/test/ui/trivial-bounds/trivial-bounds-leak.stderr
  138. +1 −1 src/test/ui/try-operator-on-main.stderr
  139. +2 −2 src/test/ui/type/ascription/issue-34255-1.stderr
  140. +1 −0 src/test/ui/type/type-annotation-needed.rs
  141. +2 −2 src/test/ui/type/type-annotation-needed.stderr
  142. +1 −1 src/test/ui/typeck/typeck-default-trait-impl-assoc-type.stderr
  143. +1 −1 src/test/ui/typeck/typeck-default-trait-impl-constituent-types-2.stderr
  144. +1 −1 src/test/ui/typeck/typeck-default-trait-impl-constituent-types.stderr
  145. +1 −1 src/test/ui/typeck/typeck-default-trait-impl-negation-send.stderr
  146. +3 −3 src/test/ui/typeck/typeck-default-trait-impl-negation-sync.stderr
  147. +2 −2 src/test/ui/typeck/typeck-default-trait-impl-negation.stderr
  148. +1 −1 src/test/ui/typeck/typeck-default-trait-impl-precedence.stderr
  149. +1 −1 src/test/ui/typeck/typeck-default-trait-impl-send-param.stderr
  150. +4 −4 src/test/ui/typeck/typeck-unsafe-always-share.stderr
  151. +1 −1 src/test/ui/unboxed-closures/unboxed-closure-sugar-default.stderr
  152. +1 −1 src/test/ui/unboxed-closures/unboxed-closure-sugar-equiv.stderr
  153. +2 −2 src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-1.stderr
  154. +5 −5 src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-3.stderr
  155. +2 −2 src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct.stderr
  156. +2 −2 src/test/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters-1.stderr
  157. +2 −2 src/test/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters-3.stderr
  158. +4 −4 src/test/ui/unboxed-closures/unboxed-closure-sugar-wrong-number-number-type-parameters.stderr
  159. +2 −2 src/test/ui/unboxed-closures/unboxed-closure-sugar-wrong-trait.stderr
  160. +1 −1 src/test/ui/unboxed-closures/unboxed-closures-fnmut-as-fn.stderr
  161. +5 −5 src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr
  162. +5 −5 src/test/ui/unboxed-closures/unboxed-closures-wrong-abi.stderr
  163. +5 −5 src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr
  164. +1 −1 src/test/ui/unsized/unsized-bare-typaram.stderr
  165. +1 −1 src/test/ui/unsized/unsized-struct.stderr
  166. +4 −4 src/test/ui/unsized3.stderr
  167. +1 −1 src/test/ui/where-clauses/where-clause-constraints-are-local-for-inherent-impl.stderr
  168. +1 −1 src/test/ui/where-clauses/where-clause-constraints-are-local-for-trait-impl.stderr
  169. +1 −1 src/test/ui/where-clauses/where-clauses-unsatisfied.stderr
  170. +6 −6 src/test/ui/where-clauses/where-for-self-2.stderr
@@ -14,6 +14,8 @@
os.path.join(os.path.dirname(__file__), '../test/ui/derives/'))

TEMPLATE = """\
// ignore-musl
// ^ due to stderr output differences
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
{error_deriving}
@@ -1893,10 +1893,13 @@ impl<'a> LoweringContext<'a> {
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
// Do not suggest going from `Trait()` to `Trait<>`
if data.inputs.len() > 0 {
let split = snippet.find('(').unwrap();
let trait_name = &snippet[0..split];
let args = &snippet[split + 1 .. snippet.len() - 1];
err.span_suggestion(
data.span,
"use angle brackets instead",
format!("<{}>", &snippet[1..snippet.len() - 1]),
format!("{}<{}>", trait_name, args),
Applicability::MaybeIncorrect,
);
}
@@ -2750,3 +2750,15 @@ pub enum Node<'hir> {

Crate,
}

impl Node<'_> {
pub fn ident(&self) -> Option<Ident> {
match self {
Node::TraitItem(TraitItem { ident, .. }) |
Node::ImplItem(ImplItem { ident, .. }) |
Node::ForeignItem(ForeignItem { ident, .. }) |
Node::Item(Item { ident, .. }) => Some(*ident),
_ => None,
}
}
}
@@ -40,10 +40,12 @@ use syntax::symbol::{sym, kw};
use syntax_pos::{DUMMY_SP, Span, ExpnKind};

impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub fn report_fulfillment_errors(&self,
errors: &[FulfillmentError<'tcx>],
body_id: Option<hir::BodyId>,
fallback_has_occurred: bool) {
pub fn report_fulfillment_errors(
&self,
errors: &[FulfillmentError<'tcx>],
body_id: Option<hir::BodyId>,
fallback_has_occurred: bool,
) {
#[derive(Debug)]
struct ErrorDescriptor<'tcx> {
predicate: ty::Predicate<'tcx>,
@@ -1623,6 +1625,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
err.note(&msg);
}
}
ObligationCauseCode::BindingObligation(item_def_id, span) => {
let item_name = tcx.def_path_str(item_def_id);
let msg = format!("required by this bound in `{}`", item_name);
if let Some(ident) = tcx.opt_item_name(item_def_id) {
err.span_label(ident.span, "");
}
if span != DUMMY_SP {
err.span_label(span, &msg);
} else {
err.note(&msg);
}
}
ObligationCauseCode::ObjectCastObligation(object_ty) => {
err.note(&format!("required for the cast to the object type `{}`",
self.ty_to_string(object_ty)));
@@ -176,6 +176,9 @@ pub enum ObligationCauseCode<'tcx> {
/// also implement all supertraits of `X`.
ItemObligation(DefId),

/// Like `ItemObligation`, but with extra detail on the source of the obligation.
BindingObligation(DefId, Span),

/// A type like `&'a T` is WF only if `T: 'a`.
ReferenceOutlivesReferent(Ty<'tcx>),

@@ -472,6 +472,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
super::TupleElem => Some(super::TupleElem),
super::ProjectionWf(proj) => tcx.lift(&proj).map(super::ProjectionWf),
super::ItemObligation(def_id) => Some(super::ItemObligation(def_id)),
super::BindingObligation(def_id, span) => Some(super::BindingObligation(def_id, span)),
super::ReferenceOutlivesReferent(ty) => {
tcx.lift(&ty).map(super::ReferenceOutlivesReferent)
}
@@ -2797,6 +2797,10 @@ impl<'tcx> TyCtxt<'tcx> {
})
}

pub fn opt_item_name(self, def_id: DefId) -> Option<Ident> {
self.hir().as_local_hir_id(def_id).and_then(|hir_id| self.hir().get(hir_id).ident())
}

pub fn opt_associated_item(self, def_id: DefId) -> Option<AssocItem> {
let is_associated_item = if let Some(hir_id) = self.hir().as_local_hir_id(def_id) {
match self.hir().get(hir_id) {
@@ -2579,16 +2579,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

/// As `instantiate_type_scheme`, but for the bounds found in a
/// generic type scheme.
fn instantiate_bounds(&self, span: Span, def_id: DefId, substs: SubstsRef<'tcx>)
-> ty::InstantiatedPredicates<'tcx> {
fn instantiate_bounds(
&self,
span: Span,
def_id: DefId,
substs: SubstsRef<'tcx>,
) -> (ty::InstantiatedPredicates<'tcx>, Vec<Span>) {
let bounds = self.tcx.predicates_of(def_id);
let spans: Vec<Span> = bounds.predicates.iter().map(|(_, span)| *span).collect();
let result = bounds.instantiate(self.tcx, substs);
let result = self.normalize_associated_types_in(span, &result);
debug!("instantiate_bounds(bounds={:?}, substs={:?}) = {:?}",
debug!(
"instantiate_bounds(bounds={:?}, substs={:?}) = {:?}, {:?}",
bounds,
substs,
result);
result
result,
spans,
);
(result, spans)
}

/// Replaces the opaque types from the given value with type variables,
@@ -3151,8 +3159,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// All the input types from the fn signature must outlive the call
// so as to validate implied bounds.
for &fn_input_ty in fn_inputs {
self.register_wf_obligation(fn_input_ty, sp, traits::MiscObligation);
for (fn_input_ty, arg_expr) in fn_inputs.iter().zip(args.iter()) {
self.register_wf_obligation(fn_input_ty, arg_expr.span, traits::MiscObligation);
}

let expected_arg_count = fn_inputs.len();
@@ -3513,7 +3521,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.write_user_type_annotation_from_substs(hir_id, did, substs, None);

// Check bounds on type arguments used in the path.
let bounds = self.instantiate_bounds(path_span, did, substs);
let (bounds, _) = self.instantiate_bounds(path_span, did, substs);
let cause = traits::ObligationCause::new(path_span, self.body_id,
traits::ItemObligation(did));
self.add_obligations_for_parameters(cause, &bounds);
@@ -4634,12 +4642,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// First, store the "user substs" for later.
self.write_user_type_annotation_from_substs(hir_id, def_id, substs, user_self_ty);

// Add all the obligations that are required, substituting and
// normalized appropriately.
let bounds = self.instantiate_bounds(span, def_id, &substs);
self.add_obligations_for_parameters(
traits::ObligationCause::new(span, self.body_id, traits::ItemObligation(def_id)),
&bounds);
self.add_required_obligations(span, def_id, &substs);

// Substitute the values for the type parameters into the type of
// the referenced item.
@@ -4676,6 +4679,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(ty_substituted, res)
}

/// Add all the obligations that are required, substituting and normalized appropriately.
fn add_required_obligations(&self, span: Span, def_id: DefId, substs: &SubstsRef<'tcx>) {
let (bounds, spans) = self.instantiate_bounds(span, def_id, &substs);

for (i, mut obligation) in traits::predicates_for_generics(
traits::ObligationCause::new(
span,
self.body_id,
traits::ItemObligation(def_id),
),
self.param_env,
&bounds,
).into_iter().enumerate() {
// This makes the error point at the bound, but we want to point at the argument
if let Some(span) = spans.get(i) {
obligation.cause.code = traits::BindingObligation(def_id, *span);
}
self.register_predicate(obligation);
}
}

fn check_rustc_args_require_const(&self,
def_id: DefId,
hir_id: hir::HirId,
@@ -129,10 +129,11 @@ impl<'a> Parser<'a> {
self.parse_path(style)
}

crate fn parse_path_segments(&mut self,
segments: &mut Vec<PathSegment>,
style: PathStyle)
-> PResult<'a, ()> {
crate fn parse_path_segments(
&mut self,
segments: &mut Vec<PathSegment>,
style: PathStyle,
) -> PResult<'a, ()> {
loop {
let segment = self.parse_path_segment(style)?;
if style == PathStyle::Expr {
@@ -201,7 +202,7 @@ impl<'a> Parser<'a> {
} else {
// `(T, U) -> R`
let (inputs, _) = self.parse_paren_comma_seq(|p| p.parse_ty())?;
let span = lo.to(self.prev_span);
let span = ident.span.to(self.prev_span);
let output = if self.eat(&token::RArrow) {
Some(self.parse_ty_common(false, false, false)?)
} else {

0 comments on commit 720a4a2

Please sign in to comment.
You can’t perform that action at this time.