Skip to content

Commit 88f66f1

Browse files
authored
Rollup merge of rust-lang#69255 - estebank:e0599-details, r=varkor
Add more context to E0599 errors Point at the intermediary unfulfilled trait bounds. Fix rust-lang#52523, fix rust-lang#61661, cc rust-lang#36513, fix rust-lang#68131, fix rust-lang#64417, fix rust-lang#61768, cc rust-lang#57457, cc rust-lang#9082, fix rust-lang#57994, cc rust-lang#64934, cc rust-lang#65149.
2 parents 0c3a8cd + c02e56a commit 88f66f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+617
-152
lines changed

src/librustc/traits/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,20 @@ impl<'tcx, N> Vtable<'tcx, N> {
581581
}
582582
}
583583

584+
pub fn borrow_nested_obligations(&self) -> &[N] {
585+
match &self {
586+
VtableImpl(i) => &i.nested[..],
587+
VtableParam(n) => &n[..],
588+
VtableBuiltin(i) => &i.nested[..],
589+
VtableAutoImpl(d) => &d.nested[..],
590+
VtableClosure(c) => &c.nested[..],
591+
VtableGenerator(c) => &c.nested[..],
592+
VtableObject(d) => &d.nested[..],
593+
VtableFnPointer(d) => &d.nested[..],
594+
VtableTraitAlias(d) => &d.nested[..],
595+
}
596+
}
597+
584598
pub fn map<M, F>(self, f: F) -> Vtable<'tcx, M>
585599
where
586600
F: FnMut(N) -> M,

src/librustc_infer/infer/error_reporting/note.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
645645
self.tcx.sess,
646646
span,
647647
E0491,
648-
"in type `{}`, reference has a longer lifetime \
649-
than the data it references",
648+
"in type `{}`, reference has a longer lifetime than the data it references",
650649
self.ty_to_string(ty)
651650
);
652651
note_and_explain_region(

src/librustc_parse/parser/generics.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::Parser;
22

33
use rustc_errors::PResult;
4-
use rustc_span::source_map::DUMMY_SP;
54
use rustc_span::symbol::{kw, sym};
65
use syntax::ast::{self, Attribute, GenericBounds, GenericParam, GenericParamKind, WhereClause};
76
use syntax::token;
@@ -160,7 +159,10 @@ impl<'a> Parser<'a> {
160159
};
161160
Ok(ast::Generics {
162161
params,
163-
where_clause: WhereClause { predicates: Vec::new(), span: DUMMY_SP },
162+
where_clause: WhereClause {
163+
predicates: Vec::new(),
164+
span: self.prev_span.shrink_to_hi(),
165+
},
164166
span,
165167
})
166168
}

src/librustc_typeck/check/method/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::check::FnCtxt;
1414
use rustc::ty::subst::Subst;
1515
use rustc::ty::subst::{InternalSubsts, SubstsRef};
1616
use rustc::ty::GenericParamDefKind;
17-
use rustc::ty::{self, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TypeFoldable, WithConstness};
17+
use rustc::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TypeFoldable, WithConstness};
1818
use rustc_data_structures::sync::Lrc;
1919
use rustc_errors::{Applicability, DiagnosticBuilder};
2020
use rustc_hir as hir;
@@ -67,7 +67,7 @@ pub enum MethodError<'tcx> {
6767
// could lead to matches if satisfied, and a list of not-in-scope traits which may work.
6868
pub struct NoMatchData<'tcx> {
6969
pub static_candidates: Vec<CandidateSource>,
70-
pub unsatisfied_predicates: Vec<TraitRef<'tcx>>,
70+
pub unsatisfied_predicates: Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>)>,
7171
pub out_of_scope_traits: Vec<DefId>,
7272
pub lev_candidate: Option<ty::AssocItem>,
7373
pub mode: probe::Mode,
@@ -76,7 +76,7 @@ pub struct NoMatchData<'tcx> {
7676
impl<'tcx> NoMatchData<'tcx> {
7777
pub fn new(
7878
static_candidates: Vec<CandidateSource>,
79-
unsatisfied_predicates: Vec<TraitRef<'tcx>>,
79+
unsatisfied_predicates: Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>)>,
8080
out_of_scope_traits: Vec<DefId>,
8181
lev_candidate: Option<ty::AssocItem>,
8282
mode: probe::Mode,

src/librustc_typeck/check/method/probe.rs

+46-19
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use rustc::session::config::nightly_options;
1414
use rustc::ty::subst::{InternalSubsts, Subst, SubstsRef};
1515
use rustc::ty::GenericParamDefKind;
1616
use rustc::ty::{
17-
self, ParamEnvAnd, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable,
18-
WithConstness,
17+
self, ParamEnvAnd, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
1918
};
2019
use rustc_data_structures::fx::FxHashSet;
2120
use rustc_data_structures::sync::Lrc;
@@ -78,7 +77,7 @@ struct ProbeContext<'a, 'tcx> {
7877

7978
/// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
8079
/// for error reporting
81-
unsatisfied_predicates: Vec<TraitRef<'tcx>>,
80+
unsatisfied_predicates: Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>)>,
8281

8382
is_suggestion: IsSuggestion,
8483
}
@@ -1224,7 +1223,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12241223
&self,
12251224
self_ty: Ty<'tcx>,
12261225
probes: ProbesIter,
1227-
possibly_unsatisfied_predicates: &mut Vec<TraitRef<'tcx>>,
1226+
possibly_unsatisfied_predicates: &mut Vec<(
1227+
ty::Predicate<'tcx>,
1228+
Option<ty::Predicate<'tcx>>,
1229+
)>,
12281230
unstable_candidates: Option<&mut Vec<(&'b Candidate<'tcx>, Symbol)>>,
12291231
) -> Option<PickResult<'tcx>>
12301232
where
@@ -1343,7 +1345,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
13431345
&self,
13441346
self_ty: Ty<'tcx>,
13451347
probe: &Candidate<'tcx>,
1346-
possibly_unsatisfied_predicates: &mut Vec<TraitRef<'tcx>>,
1348+
possibly_unsatisfied_predicates: &mut Vec<(
1349+
ty::Predicate<'tcx>,
1350+
Option<ty::Predicate<'tcx>>,
1351+
)>,
13471352
) -> ProbeResult {
13481353
debug!("consider_probe: self_ty={:?} probe={:?}", self_ty, probe);
13491354

@@ -1398,21 +1403,45 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
13981403
let predicate = trait_ref.without_const().to_predicate();
13991404
let obligation = traits::Obligation::new(cause, self.param_env, predicate);
14001405
if !self.predicate_may_hold(&obligation) {
1401-
if self.probe(|_| self.select_trait_candidate(trait_ref).is_err()) {
1406+
if self.probe(|_| {
1407+
match self.select_trait_candidate(trait_ref) {
1408+
Err(_) => return true,
1409+
Ok(Some(vtable))
1410+
if !vtable.borrow_nested_obligations().is_empty() =>
1411+
{
1412+
for obligation in vtable.borrow_nested_obligations() {
1413+
// Determine exactly which obligation wasn't met, so
1414+
// that we can give more context in the error.
1415+
if !self.predicate_may_hold(&obligation) {
1416+
result = ProbeResult::NoMatch;
1417+
let o = self.resolve_vars_if_possible(obligation);
1418+
let predicate =
1419+
self.resolve_vars_if_possible(&predicate);
1420+
let p = if predicate == o.predicate {
1421+
// Avoid "`MyStruct: Foo` which is required by
1422+
// `MyStruct: Foo`" in E0599.
1423+
None
1424+
} else {
1425+
Some(predicate)
1426+
};
1427+
possibly_unsatisfied_predicates.push((o.predicate, p));
1428+
}
1429+
}
1430+
}
1431+
_ => {
1432+
// Some nested subobligation of this predicate
1433+
// failed.
1434+
result = ProbeResult::NoMatch;
1435+
let predicate = self.resolve_vars_if_possible(&predicate);
1436+
possibly_unsatisfied_predicates.push((predicate, None));
1437+
}
1438+
}
1439+
false
1440+
}) {
14021441
// This candidate's primary obligation doesn't even
14031442
// select - don't bother registering anything in
14041443
// `potentially_unsatisfied_predicates`.
14051444
return ProbeResult::NoMatch;
1406-
} else {
1407-
// Some nested subobligation of this predicate
1408-
// failed.
1409-
//
1410-
// FIXME: try to find the exact nested subobligation
1411-
// and point at it rather than reporting the entire
1412-
// trait-ref?
1413-
result = ProbeResult::NoMatch;
1414-
let trait_ref = self.resolve_vars_if_possible(&trait_ref);
1415-
possibly_unsatisfied_predicates.push(trait_ref);
14161445
}
14171446
}
14181447
vec![]
@@ -1429,9 +1458,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14291458
let o = self.resolve_vars_if_possible(&o);
14301459
if !self.predicate_may_hold(&o) {
14311460
result = ProbeResult::NoMatch;
1432-
if let &ty::Predicate::Trait(ref pred, _) = &o.predicate {
1433-
possibly_unsatisfied_predicates.push(pred.skip_binder().trait_ref);
1434-
}
1461+
possibly_unsatisfied_predicates.push((o.predicate, None));
14351462
}
14361463
}
14371464

0 commit comments

Comments
 (0)