Skip to content

Commit d1fbd24

Browse files
Ariel Ben-Yehudaarielb1
Ariel Ben-Yehuda
authored andcommitted
---
yaml --- r: 276902 b: refs/heads/try c: 8a461d9 h: refs/heads/master
1 parent 254a3b0 commit d1fbd24

File tree

160 files changed

+422
-299
lines changed

Some content is hidden

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

160 files changed

+422
-299
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: 513d9f208cc52ab71e2899db30aaead5c82c1a74
4+
refs/heads/try: 8a461d940cc6019bd332b1ea732d79d3216d9108
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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,13 @@ assert_eq!(6, answer);
371371
This gives us these long, related errors:
372372

373373
```text
374-
error: the trait `core::marker::Sized` is not implemented for the type
375-
`core::ops::Fn(i32) -> i32` [E0277]
374+
error: the predicate `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
376375
fn factory() -> (Fn(i32) -> i32) {
377376
^~~~~~~~~~~~~~~~
378377
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
379378
fn factory() -> (Fn(i32) -> i32) {
380379
^~~~~~~~~~~~~~~~
381-
error: the trait `core::marker::Sized` is not implemented for the type `core::ops::Fn(i32) -> i32` [E0277]
380+
error: the predicate `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
382381
let f = factory();
383382
^
384383
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
@@ -231,8 +231,8 @@ fn main() {
231231
This won't work, however, and will give us the error:
232232

233233
```text
234-
13:9: 13:22 error: the trait `core::marker::Send` is not
235-
implemented for the type `alloc::rc::Rc<collections::vec::Vec<i32>>`
234+
13:9: 13:22 error: the predicate `alloc::rc::Rc<collections::vec::Vec<i32>> : core::marker::Send`
235+
is not satisfied
236236
...
237237
13:9: 13:22 note: `alloc::rc::Rc<collections::vec::Vec<i32>>`
238238
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 `HasArea` is not implemented for the type `_` [E0277]
157+
error: the predicate `_ : HasArea` is not satisfied [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 `main::Foo` is not implemented for the type `main::Baz` [E0277]
499+
error: the predicate `main::Baz : main::Foo` is not satisfied [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 `core::ops::Index<i32>` is not implemented for the type
60-
`collections::vec::Vec<_>` [E0277]
59+
error: the predicate `collections::vec::Vec<_> : core::ops::Index<i32>`
60+
is not satisfied [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 `Trait` is not implemented for the type `&mut i32` [E0277]
67+
<anon>:10:5: 10:8 error: the predicate `&mut i32 : Trait` is not satisfied [E0277]
6868
<anon>:10 foo(t);
6969
^~~
7070
```

branches/try/src/librustc/diagnostics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,7 @@ 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 `Foo` is not implemented for the
1010-
// type `i32`
1009+
some_func(5i32); // error: the predicate `i32 : Foo` is not satisfied
10111010
}
10121011
```
10131012

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

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ use super::{
1313
FulfillmentErrorCode,
1414
MismatchedProjectionTypes,
1515
Obligation,
16+
ObligationCause,
1617
ObligationCauseCode,
1718
OutputTypeParameterMismatch,
1819
TraitNotObjectSafe,
1920
PredicateObligation,
21+
SelectionContext,
2022
SelectionError,
2123
ObjectSafetyViolation,
2224
MethodViolationCode,
@@ -26,8 +28,9 @@ use super::{
2628
use fmt_macros::{Parser, Piece, Position};
2729
use middle::def_id::DefId;
2830
use infer::InferCtxt;
29-
use ty::{self, ToPredicate, ToPolyTraitRef, TraitRef, Ty, TyCtxt, TypeFoldable};
31+
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
3032
use ty::fast_reject;
33+
use ty::fold::{TypeFoldable, TypeFolder};
3134
use util::nodemap::{FnvHashMap, FnvHashSet};
3235

3336
use std::cmp;
@@ -100,9 +103,10 @@ pub fn report_projection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
100103
}
101104
}
102105

103-
fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
104-
trait_ref: &TraitRef<'tcx>,
105-
span: Span) -> Option<String> {
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();
106110
let def_id = trait_ref.def_id;
107111
let mut report = None;
108112
for item in infcx.tcx.get_attrs(def_id).iter() {
@@ -357,14 +361,20 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
357361
let trait_ref = trait_predicate.to_poly_trait_ref();
358362
let mut err = struct_span_err!(
359363
infcx.tcx.sess, obligation.cause.span, E0277,
360-
"the trait `{}` is not implemented for the type `{}`",
361-
trait_ref, trait_ref.self_ty());
362-
363-
// Check if it has a custom "#[rustc_on_unimplemented]"
364-
// error message, report with that message if it does
365-
let custom_note = report_on_unimplemented(infcx, &trait_ref.0,
366-
obligation.cause.span);
367-
if let Some(s) = custom_note {
364+
"the predicate `{}` is not satisfied",
365+
trait_ref.to_predicate());
366+
367+
// Try to report a good error message.
368+
369+
if !trait_ref.has_infer_types() &&
370+
predicate_can_apply(infcx, trait_ref)
371+
{
372+
err.fileline_help(obligation.cause.span, &format!(
373+
"consider adding a `where {}` bound",
374+
trait_ref.to_predicate()
375+
));
376+
} else if let Some(s) = on_unimplemented_note(infcx, trait_ref,
377+
obligation.cause.span) {
368378
err.fileline_note(obligation.cause.span, &s);
369379
} else {
370380
let simp = fast_reject::simplify_type(infcx.tcx,
@@ -644,6 +654,55 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
644654
}
645655
}
646656

657+
/// Returns whether the trait predicate may apply for *some* assignment
658+
/// to the type parameters.
659+
fn predicate_can_apply<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
660+
pred: ty::PolyTraitRef<'tcx>)
661+
-> bool
662+
{
663+
struct ParamToVarFolder<'a, 'tcx: 'a> {
664+
infcx: &'a InferCtxt<'a, 'tcx>,
665+
var_map: FnvHashMap<Ty<'tcx>, Ty<'tcx>>
666+
}
667+
668+
impl<'a, 'tcx> TypeFolder<'tcx> for ParamToVarFolder<'a, 'tcx>
669+
{
670+
fn tcx(&self) -> &TyCtxt<'tcx> { self.infcx.tcx }
671+
672+
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
673+
if let ty::TyParam(..) = ty.sty {
674+
let infcx = self.infcx;
675+
self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var())
676+
} else {
677+
ty.super_fold_with(self)
678+
}
679+
}
680+
}
681+
682+
infcx.probe(|_| {
683+
let mut selcx = SelectionContext::new(infcx);
684+
685+
let cleaned_pred = pred.fold_with(&mut ParamToVarFolder {
686+
infcx: infcx,
687+
var_map: FnvHashMap()
688+
});
689+
690+
let cleaned_pred = super::project::normalize(
691+
&mut selcx,
692+
ObligationCause::dummy(),
693+
&cleaned_pred
694+
).value;
695+
696+
let obligation = Obligation::new(
697+
ObligationCause::dummy(),
698+
cleaned_pred.to_predicate()
699+
);
700+
701+
selcx.evaluate_obligation(&obligation)
702+
})
703+
}
704+
705+
647706
fn need_type_info<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
648707
span: Span,
649708
ty: Ty<'tcx>)

branches/try/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ trait Add<RHS=Self> {
3131
fn ice<A>(a: A) {
3232
let r = loop {};
3333
r = r + a;
34-
//~^ ERROR not implemented
34+
//~^ ERROR E0277
3535
}

branches/try/src/test/compile-fail/associated-types-bound-failure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub trait GetToInt
2424
fn foo<G>(g: G) -> isize
2525
where G : GetToInt
2626
{
27-
ToInt::to_int(&g.get()) //~ ERROR not implemented
27+
ToInt::to_int(&g.get()) //~ ERROR E0277
2828
}
2929

3030
fn bar<G : GetToInt>(g: G) -> isize

branches/try/src/test/compile-fail/associated-types-for-unimpl-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait Get {
1515

1616
trait Other {
1717
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
18-
//~^ ERROR the trait `Get` is not implemented for the type `Self`
18+
//~^ ERROR the predicate `Self : Get` is not satisfied
1919
}
2020

2121
fn main() {

branches/try/src/test/compile-fail/associated-types-invalid-trait-ref-issue-18865.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait Foo<T> {
1818

1919
fn f<T:Foo<isize>>(t: &T) {
2020
let u: <T as Foo<usize>>::Bar = t.get_bar();
21-
//~^ ERROR the trait `Foo<usize>` is not implemented for the type `T`
21+
//~^ ERROR the predicate `T : Foo<usize>` is not satisfied
2222
}
2323

2424
fn main() { }

branches/try/src/test/compile-fail/associated-types-no-suitable-bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Struct {
1919

2020
impl Struct {
2121
fn uhoh<T>(foo: <T as Get>::Value) {}
22-
//~^ ERROR the trait `Get` is not implemented for the type `T`
22+
//~^ ERROR the predicate `T : Get` is not satisfied
2323
}
2424

2525
fn main() {

branches/try/src/test/compile-fail/associated-types-no-suitable-supertrait-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait Get {
2525

2626
trait Other {
2727
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
28-
//~^ ERROR the trait `Get` is not implemented for the type `Self`
28+
//~^ ERROR the predicate `Self : Get` is not satisfied
2929
}
3030

3131
fn main() { }

branches/try/src/test/compile-fail/associated-types-no-suitable-supertrait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ trait Get {
2525

2626
trait Other {
2727
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
28-
//~^ ERROR the trait `Get` is not implemented for the type `Self`
28+
//~^ ERROR the predicate `Self : Get` is not satisfied
2929
}
3030

3131
impl<T:Get> Other for T {
3232
fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
33-
//~^ ERROR the trait `Get` is not implemented for the type `(T, U)`
33+
//~^ ERROR the predicate `(T, U) : Get` is not satisfied
3434
}
3535

3636
fn main() { }

branches/try/src/test/compile-fail/associated-types-path-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ pub fn f1_int_uint() {
3838

3939
pub fn f1_uint_uint() {
4040
f1(2u32, 4u32);
41-
//~^ ERROR the trait `Foo` is not implemented
41+
//~^ ERROR `u32 : Foo` is not satisfied
4242
}
4343

4444
pub fn f1_uint_int() {
4545
f1(2u32, 4i32);
46-
//~^ ERROR the trait `Foo` is not implemented
46+
//~^ ERROR `u32 : Foo` is not satisfied
4747
}
4848

4949
pub fn f2_int() {

branches/try/src/test/compile-fail/associated-types-unsized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait Get {
1414
}
1515

1616
fn foo<T:Get>(t: T) {
17-
let x = t.get(); //~ ERROR the trait `std::marker::Sized` is not implemented
17+
let x = t.get(); //~ ERROR `<T as Get>::Value : std::marker::Sized` is not
1818
}
1919

2020
fn main() {

branches/try/src/test/compile-fail/bad-method-typaram-kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
fn foo<T:'static>() {
12-
1.bar::<T>(); //~ ERROR `std::marker::Send` is not implemented
12+
1.bar::<T>(); //~ ERROR `T : std::marker::Send` is not satisfied
1313
}
1414

1515
trait bar {

branches/try/src/test/compile-fail/bad-sized.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait Trait {}
1212

1313
pub fn main() {
1414
let x: Vec<Trait + Sized> = Vec::new();
15-
//~^ ERROR the trait `std::marker::Sized` is not implemented
16-
//~| ERROR the trait `std::marker::Sized` is not implemented
17-
//~| ERROR the trait `std::marker::Sized` is not implemented
15+
//~^ ERROR `Trait + Sized : std::marker::Sized` is not satisfied
16+
//~| ERROR `Trait + Sized : std::marker::Sized` is not satisfied
17+
//~| ERROR `Trait + Sized : std::marker::Sized` is not satisfied
1818
}

branches/try/src/test/compile-fail/builtin-superkinds-double-superkind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
trait Foo : Send+Sync { }
1515

16-
impl <T: Sync+'static> Foo for (T,) { } //~ ERROR the trait `std::marker::Send` is not implemented
16+
impl <T: Sync+'static> Foo for (T,) { } //~ ERROR `T : std::marker::Send` is not satisfied
1717

18-
impl <T: Send> Foo for (T,T) { } //~ ERROR the trait `std::marker::Sync` is not implemented
18+
impl <T: Send> Foo for (T,T) { } //~ ERROR `T : std::marker::Sync` is not satisfied
1919

2020
impl <T: Send+Sync> Foo for (T,T,T) { } // (ok)
2121

branches/try/src/test/compile-fail/builtin-superkinds-in-metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ struct X<T>(T);
2222
impl <T:Sync> RequiresShare for X<T> { }
2323

2424
impl <T:Sync+'static> RequiresRequiresShareAndSend for X<T> { }
25-
//~^ ERROR the trait `std::marker::Send` is not implemented
25+
//~^ ERROR `T : std::marker::Send` is not satisfied
2626

2727
fn main() { }

branches/try/src/test/compile-fail/builtin-superkinds-simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
trait Foo : Send { }
1515

1616
impl Foo for std::rc::Rc<i8> { }
17-
//~^ ERROR the trait `std::marker::Send` is not implemented
17+
//~^ ERROR `std::rc::Rc<i8> : std::marker::Send` is not satisfied
1818

1919
fn main() { }

branches/try/src/test/compile-fail/builtin-superkinds-typaram-not-send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212

1313
trait Foo : Send { }
1414

15-
impl <T: Sync+'static> Foo for T { } //~ ERROR the trait `std::marker::Send` is not implemented
15+
impl <T: Sync+'static> Foo for T { } //~ ERROR `T : std::marker::Send` is not satisfied
1616

1717
fn main() { }

branches/try/src/test/compile-fail/cast-rfc0401.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn main()
9191
let _ = 42usize as *const [u8]; //~ ERROR casting
9292
let _ = v as *const [u8]; //~ ERROR cannot cast
9393
let _ = fat_v as *const Foo;
94-
//~^ ERROR `std::marker::Sized` is not implemented for the type `[u8]`
94+
//~^ ERROR the predicate `[u8] : std::marker::Sized` is not satisfied
9595
//~^^ HELP run `rustc --explain E0277` to see a detailed explanation
9696
//~^^^ NOTE `[u8]` does not have a constant size known at compile-time
9797
//~^^^^ NOTE required for the cast to the object type `Foo`
@@ -106,7 +106,7 @@ fn main()
106106

107107
let a : *const str = "hello";
108108
let _ = a as *const Foo;
109-
//~^ ERROR `std::marker::Sized` is not implemented for the type `str`
109+
//~^ ERROR the predicate `str : std::marker::Sized` is not satisfied
110110
//~^^ HELP run `rustc --explain E0277` to see a detailed explanation
111111
//~^^^ NOTE `str` does not have a constant size known at compile-time
112112
//~^^^^ NOTE required for the cast to the object type `Foo`

branches/try/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct X<F> where F: FnOnce() + 'static + Send {
1313
}
1414

1515
fn foo<F>(blk: F) -> X<F> where F: FnOnce() + 'static {
16-
//~^ ERROR the trait `std::marker::Send` is not implemented for the type
16+
//~^ ERROR `F : std::marker::Send` is not satisfied
1717
return X { field: blk };
1818
}
1919

branches/try/src/test/compile-fail/closure-bounds-subtype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn give_any<F>(f: F) where F: FnOnce() {
2121

2222
fn give_owned<F>(f: F) where F: FnOnce() + Send {
2323
take_any(f);
24-
take_const_owned(f); //~ ERROR the trait `std::marker::Sync` is not implemented for the type
24+
take_const_owned(f); //~ ERROR `F : std::marker::Sync` is not satisfied
2525
}
2626

2727
fn main() {}

branches/try/src/test/compile-fail/cross-fn-cache-hole.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ trait Bar<X> { }
2323

2424
// We don't always check where clauses for sanity, but in this case
2525
// wfcheck does report an error here:
26-
fn vacuous<A>() //~ ERROR the trait `Bar<u32>` is not implemented for the type `i32`
26+
fn vacuous<A>() //~ ERROR the predicate `i32 : Bar<u32>` is not satisfied
2727
where i32: Foo<u32, A>
2828
{
2929
// ... the original intention was to check that we don't use that

0 commit comments

Comments
 (0)