Skip to content

Commit 490a49f

Browse files
committed
---
yaml --- r: 276909 b: refs/heads/try c: ffbbf24 h: refs/heads/master i: 276907: 172687b
1 parent 0290d17 commit 490a49f

File tree

173 files changed

+534
-730
lines changed

Some content is hidden

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

173 files changed

+534
-730
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: 444a118a8932c99b902548cb7ca8c249222c053a
4+
refs/heads/try: ffbbf241868588c5ca3880ed023e97aa806ea1d3
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/doc/book/closures.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,14 @@ assert_eq!(6, answer);
371371
This gives us these long, related errors:
372372

373373
```text
374-
error: the trait bound `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
374+
error: the trait `core::marker::Sized` is not implemented for the type
375+
`core::ops::Fn(i32) -> i32` [E0277]
375376
fn factory() -> (Fn(i32) -> i32) {
376377
^~~~~~~~~~~~~~~~
377378
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
378379
fn factory() -> (Fn(i32) -> i32) {
379380
^~~~~~~~~~~~~~~~
380-
error: the trait bound `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
381+
error: the trait `core::marker::Sized` is not implemented for the type `core::ops::Fn(i32) -> i32` [E0277]
381382
let f = factory();
382383
^
383384
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time

branches/try/src/doc/book/concurrency.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ fn main() {
234234
This won't work, however, and will give us the error:
235235

236236
```text
237-
13:9: 13:22 error: the trait bound `alloc::rc::Rc<collections::vec::Vec<i32>> : core::marker::Send`
238-
is not satisfied
237+
13:9: 13:22 error: the trait `core::marker::Send` is not
238+
implemented for the type `alloc::rc::Rc<collections::vec::Vec<i32>>`
239239
...
240240
13:9: 13:22 note: `alloc::rc::Rc<collections::vec::Vec<i32>>`
241241
cannot be sent between threads safely

branches/try/src/doc/book/traits.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ print_area(5);
154154
We get a compile-time error:
155155

156156
```text
157-
error: the trait bound `_ : HasArea` is not satisfied [E0277]
157+
error: the trait `HasArea` is not implemented for the type `_` [E0277]
158158
```
159159

160160
## Trait bounds on generic structs
@@ -496,7 +496,7 @@ impl FooBar for Baz {
496496
If we forget to implement `Foo`, Rust will tell us:
497497

498498
```text
499-
error: the trait bound `main::Baz : main::Foo` is not satisfied [E0277]
499+
error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277]
500500
```
501501

502502
# Deriving

branches/try/src/doc/book/vectors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ v[j];
5656
Indexing with a non-`usize` type gives an error that looks like this:
5757

5858
```text
59-
error: the trait bound `collections::vec::Vec<_> : core::ops::Index<i32>`
60-
is not satisfied [E0277]
59+
error: the trait `core::ops::Index<i32>` is not implemented for the type
60+
`collections::vec::Vec<_>` [E0277]
6161
v[j];
6262
^~~~
6363
note: the type `collections::vec::Vec<_>` cannot be indexed by `i32`

branches/try/src/doc/nomicon/coercions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn main() {
6464
```
6565

6666
```text
67-
<anon>:10:5: 10:8 error: the trait bound `&mut i32 : Trait` is not satisfied [E0277]
67+
<anon>:10:5: 10:8 error: the trait `Trait` is not implemented for the type `&mut i32` [E0277]
6868
<anon>:10 foo(t);
6969
^~~
7070
```

branches/try/src/librustc/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,8 @@ fn some_func<T: Foo>(foo: T) {
10061006
fn main() {
10071007
// we now call the method with the i32 type, which doesn't implement
10081008
// the Foo trait
1009-
some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied
1009+
some_func(5i32); // error: the trait `Foo` is not implemented for the
1010+
// type `i32`
10101011
}
10111012
```
10121013

branches/try/src/librustc/hir/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,15 +1437,6 @@ pub enum Visibility {
14371437
Inherited,
14381438
}
14391439

1440-
impl Visibility {
1441-
pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
1442-
match self {
1443-
&Inherited => parent_visibility,
1444-
&Public => *self,
1445-
}
1446-
}
1447-
}
1448-
14491440
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
14501441
pub struct StructField {
14511442
pub span: Span,

branches/try/src/librustc/traits/error_reporting.rs

Lines changed: 56 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ use super::{
1313
FulfillmentErrorCode,
1414
MismatchedProjectionTypes,
1515
Obligation,
16-
ObligationCause,
1716
ObligationCauseCode,
1817
OutputTypeParameterMismatch,
1918
TraitNotObjectSafe,
2019
PredicateObligation,
21-
SelectionContext,
2220
SelectionError,
2321
ObjectSafetyViolation,
2422
MethodViolationCode,
@@ -28,9 +26,8 @@ use super::{
2826
use fmt_macros::{Parser, Piece, Position};
2927
use hir::def_id::DefId;
3028
use infer::InferCtxt;
31-
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
29+
use ty::{self, ToPredicate, ToPolyTraitRef, TraitRef, Ty, TyCtxt, TypeFoldable};
3230
use ty::fast_reject;
33-
use ty::fold::{TypeFoldable, TypeFolder};
3431
use util::nodemap::{FnvHashMap, FnvHashSet};
3532

3633
use std::cmp;
@@ -93,7 +90,12 @@ pub fn report_projection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
9390
let predicate =
9491
infcx.resolve_type_vars_if_possible(&obligation.predicate);
9592

96-
if !predicate.references_error() {
93+
// The TyError created by normalize_to_error can end up being unified
94+
// into all obligations: for example, if our obligation is something
95+
// like `$X = <() as Foo<$X>>::Out` and () does not implement Foo<_>,
96+
// then $X will be unified with TyError, but the error still needs to be
97+
// reported.
98+
if !infcx.tcx.sess.has_errors() || !predicate.references_error() {
9799
let mut err = struct_span_err!(infcx.tcx.sess, obligation.cause.span, E0271,
98100
"type mismatch resolving `{}`: {}",
99101
predicate,
@@ -103,10 +105,9 @@ pub fn report_projection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
103105
}
104106
}
105107

106-
fn on_unimplemented_note<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
107-
trait_ref: ty::PolyTraitRef<'tcx>,
108-
span: Span) -> Option<String> {
109-
let trait_ref = trait_ref.skip_binder();
108+
fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
109+
trait_ref: &TraitRef<'tcx>,
110+
span: Span) -> Option<String> {
110111
let def_id = trait_ref.def_id;
111112
let mut report = None;
112113
for item in infcx.tcx.get_attrs(def_id).iter() {
@@ -174,53 +175,6 @@ fn on_unimplemented_note<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
174175
report
175176
}
176177

177-
fn find_similar_impl_candidates<'a, 'tcx>(
178-
infcx: &InferCtxt<'a, 'tcx>,
179-
trait_ref: ty::PolyTraitRef<'tcx>)
180-
-> Vec<ty::TraitRef<'tcx>>
181-
{
182-
let simp = fast_reject::simplify_type(infcx.tcx,
183-
trait_ref.skip_binder().self_ty(),
184-
true);
185-
let mut impl_candidates = Vec::new();
186-
let trait_def = infcx.tcx.lookup_trait_def(trait_ref.def_id());
187-
188-
match simp {
189-
Some(simp) => trait_def.for_each_impl(infcx.tcx, |def_id| {
190-
let imp = infcx.tcx.impl_trait_ref(def_id).unwrap();
191-
let imp_simp = fast_reject::simplify_type(infcx.tcx,
192-
imp.self_ty(),
193-
true);
194-
if let Some(imp_simp) = imp_simp {
195-
if simp != imp_simp {
196-
return;
197-
}
198-
}
199-
impl_candidates.push(imp);
200-
}),
201-
None => trait_def.for_each_impl(infcx.tcx, |def_id| {
202-
impl_candidates.push(
203-
infcx.tcx.impl_trait_ref(def_id).unwrap());
204-
})
205-
};
206-
impl_candidates
207-
}
208-
209-
fn report_similar_impl_candidates(span: Span,
210-
err: &mut DiagnosticBuilder,
211-
impl_candidates: &[ty::TraitRef])
212-
{
213-
err.fileline_help(span, &format!("the following implementations were found:"));
214-
215-
let end = cmp::min(4, impl_candidates.len());
216-
for candidate in &impl_candidates[0..end] {
217-
err.fileline_help(span, &format!(" {:?}", candidate));
218-
}
219-
if impl_candidates.len() > 4 {
220-
err.fileline_help(span, &format!("and {} others", impl_candidates.len()-4));
221-
}
222-
}
223-
224178
/// Reports that an overflow has occurred and halts compilation. We
225179
/// halt compilation unconditionally because it is important that
226180
/// overflows never be masked -- they basically represent computations
@@ -408,39 +362,56 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
408362
let trait_ref = trait_predicate.to_poly_trait_ref();
409363
let mut err = struct_span_err!(
410364
infcx.tcx.sess, obligation.cause.span, E0277,
411-
"the trait bound `{}` is not satisfied",
412-
trait_ref.to_predicate());
413-
414-
// Try to report a help message
415-
416-
if !trait_ref.has_infer_types() &&
417-
predicate_can_apply(infcx, trait_ref)
418-
{
419-
// If a where-clause may be useful, remind the
420-
// user that they can add it.
421-
//
422-
// don't display an on-unimplemented note, as
423-
// these notes will often be of the form
424-
// "the type `T` can't be frobnicated"
425-
// which is somewhat confusing.
426-
err.fileline_help(obligation.cause.span, &format!(
427-
"consider adding a `where {}` bound",
428-
trait_ref.to_predicate()
429-
));
430-
} else if let Some(s) = on_unimplemented_note(infcx, trait_ref,
431-
obligation.cause.span) {
432-
// Otherwise, if there is an on-unimplemented note,
433-
// display it.
365+
"the trait `{}` is not implemented for the type `{}`",
366+
trait_ref, trait_ref.self_ty());
367+
368+
// Check if it has a custom "#[rustc_on_unimplemented]"
369+
// error message, report with that message if it does
370+
let custom_note = report_on_unimplemented(infcx, &trait_ref.0,
371+
obligation.cause.span);
372+
if let Some(s) = custom_note {
434373
err.fileline_note(obligation.cause.span, &s);
435374
} else {
436-
// If we can't show anything useful, try to find
437-
// similar impls.
375+
let simp = fast_reject::simplify_type(infcx.tcx,
376+
trait_ref.self_ty(),
377+
true);
378+
let mut impl_candidates = Vec::new();
379+
let trait_def = infcx.tcx.lookup_trait_def(trait_ref.def_id());
380+
381+
match simp {
382+
Some(simp) => trait_def.for_each_impl(infcx.tcx, |def_id| {
383+
let imp = infcx.tcx.impl_trait_ref(def_id).unwrap();
384+
let imp_simp = fast_reject::simplify_type(infcx.tcx,
385+
imp.self_ty(),
386+
true);
387+
if let Some(imp_simp) = imp_simp {
388+
if simp != imp_simp {
389+
return;
390+
}
391+
}
392+
impl_candidates.push(imp);
393+
}),
394+
None => trait_def.for_each_impl(infcx.tcx, |def_id| {
395+
impl_candidates.push(
396+
infcx.tcx.impl_trait_ref(def_id).unwrap());
397+
})
398+
};
438399

439-
let impl_candidates =
440-
find_similar_impl_candidates(infcx, trait_ref);
441400
if impl_candidates.len() > 0 {
442-
report_similar_impl_candidates(obligation.cause.span,
443-
&mut err, &impl_candidates);
401+
err.fileline_help(
402+
obligation.cause.span,
403+
&format!("the following implementations were found:"));
404+
405+
let end = cmp::min(4, impl_candidates.len());
406+
for candidate in &impl_candidates[0..end] {
407+
err.fileline_help(obligation.cause.span,
408+
&format!(" {:?}", candidate));
409+
}
410+
if impl_candidates.len() > 4 {
411+
err.fileline_help(obligation.cause.span,
412+
&format!("and {} others",
413+
impl_candidates.len()-4));
414+
}
444415
}
445416
}
446417
note_obligation_cause(infcx, &mut err, obligation);
@@ -678,55 +649,6 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
678649
}
679650
}
680651

681-
/// Returns whether the trait predicate may apply for *some* assignment
682-
/// to the type parameters.
683-
fn predicate_can_apply<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
684-
pred: ty::PolyTraitRef<'tcx>)
685-
-> bool
686-
{
687-
struct ParamToVarFolder<'a, 'tcx: 'a> {
688-
infcx: &'a InferCtxt<'a, 'tcx>,
689-
var_map: FnvHashMap<Ty<'tcx>, Ty<'tcx>>
690-
}
691-
692-
impl<'a, 'tcx> TypeFolder<'tcx> for ParamToVarFolder<'a, 'tcx>
693-
{
694-
fn tcx(&self) -> &TyCtxt<'tcx> { self.infcx.tcx }
695-
696-
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
697-
if let ty::TyParam(..) = ty.sty {
698-
let infcx = self.infcx;
699-
self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var())
700-
} else {
701-
ty.super_fold_with(self)
702-
}
703-
}
704-
}
705-
706-
infcx.probe(|_| {
707-
let mut selcx = SelectionContext::new(infcx);
708-
709-
let cleaned_pred = pred.fold_with(&mut ParamToVarFolder {
710-
infcx: infcx,
711-
var_map: FnvHashMap()
712-
});
713-
714-
let cleaned_pred = super::project::normalize(
715-
&mut selcx,
716-
ObligationCause::dummy(),
717-
&cleaned_pred
718-
).value;
719-
720-
let obligation = Obligation::new(
721-
ObligationCause::dummy(),
722-
cleaned_pred.to_predicate()
723-
);
724-
725-
selcx.evaluate_obligation(&obligation)
726-
})
727-
}
728-
729-
730652
fn need_type_info<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
731653
span: Span,
732654
ty: Ty<'tcx>)

0 commit comments

Comments
 (0)