Skip to content

Commit 8df2f27

Browse files
author
Jake Hickey
committed
---
yaml --- r: 227750 b: refs/heads/try c: deee268 h: refs/heads/master v: v3
1 parent 37145b0 commit 8df2f27

File tree

8 files changed

+50
-138
lines changed

8 files changed

+50
-138
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: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: e749f724b07121e965120f6974aa0b3fda888944
4+
refs/heads/try: deee2680155a2b5c36d61fedb28d3aaf4ec1da40
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/trpl/error-handling.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ There's another way of doing this that's a bit nicer than `unwrap()`:
225225

226226
```rust,ignore
227227
let mut buffer = String::new();
228-
let input = io::stdin().read_line(&mut buffer)
229-
.ok()
230-
.expect("Failed to read line");
228+
let num_bytes_read = io::stdin().read_line(&mut buffer)
229+
.ok()
230+
.expect("Failed to read line");
231231
```
232232

233233
`ok()` converts the `Result` into an `Option`, and `expect()` does the same

branches/try/src/librustc_typeck/check/method/mod.rs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use middle::def;
1616
use middle::privacy::{AllPublic, DependsOn, LastPrivate, LastMod};
1717
use middle::subst;
1818
use middle::traits;
19-
use middle::ty::{self, AsPredicate, ToPolyTraitRef, TraitRef};
19+
use middle::ty::{self, AsPredicate, ToPolyTraitRef};
2020
use middle::infer;
2121

2222
use syntax::ast::DefId;
@@ -32,9 +32,11 @@ mod confirm;
3232
mod probe;
3333
mod suggest;
3434

35-
pub enum MethodError<'tcx> {
36-
// Did not find an applicable method, but we did find various near-misses that may work.
37-
NoMatch(NoMatchData<'tcx>),
35+
pub enum MethodError {
36+
// Did not find an applicable method, but we did find various
37+
// static methods that may apply, as well as a list of
38+
// not-in-scope traits which may work.
39+
NoMatch(Vec<CandidateSource>, Vec<ast::DefId>, probe::Mode),
3840

3941
// Multiple methods might apply.
4042
Ambiguity(Vec<CandidateSource>),
@@ -43,32 +45,9 @@ pub enum MethodError<'tcx> {
4345
ClosureAmbiguity(/* DefId of fn trait */ ast::DefId),
4446
}
4547

46-
// Contains a list of static methods that may apply, a list of unsatisfied trait predicates which
47-
// could lead to matches if satisfied, and a list of not-in-scope traits which may work.
48-
pub struct NoMatchData<'tcx> {
49-
pub static_candidates: Vec<CandidateSource>,
50-
pub unsatisfied_predicates: Vec<TraitRef<'tcx>>,
51-
pub out_of_scope_traits: Vec<ast::DefId>,
52-
pub mode: probe::Mode
53-
}
54-
55-
impl<'tcx> NoMatchData<'tcx> {
56-
pub fn new(static_candidates: Vec<CandidateSource>,
57-
unsatisfied_predicates: Vec<TraitRef<'tcx>>,
58-
out_of_scope_traits: Vec<ast::DefId>,
59-
mode: probe::Mode) -> Self {
60-
NoMatchData {
61-
static_candidates: static_candidates,
62-
unsatisfied_predicates: unsatisfied_predicates,
63-
out_of_scope_traits: out_of_scope_traits,
64-
mode: mode
65-
}
66-
}
67-
}
68-
6948
// A pared down enum describing just the places from which a method
7049
// candidate can arise. Used for error reporting only.
71-
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
50+
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq)]
7251
pub enum CandidateSource {
7352
ImplSource(ast::DefId),
7453
TraitSource(/* trait id */ ast::DefId),
@@ -114,7 +93,7 @@ pub fn lookup<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
11493
supplied_method_types: Vec<ty::Ty<'tcx>>,
11594
call_expr: &'tcx ast::Expr,
11695
self_expr: &'tcx ast::Expr)
117-
-> Result<ty::MethodCallee<'tcx>, MethodError<'tcx>>
96+
-> Result<ty::MethodCallee<'tcx>, MethodError>
11897
{
11998
debug!("lookup(method_name={}, self_ty={:?}, call_expr={:?}, self_expr={:?})",
12099
method_name,
@@ -326,7 +305,7 @@ pub fn resolve_ufcs<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
326305
method_name: ast::Name,
327306
self_ty: ty::Ty<'tcx>,
328307
expr_id: ast::NodeId)
329-
-> Result<(def::Def, LastPrivate), MethodError<'tcx>>
308+
-> Result<(def::Def, LastPrivate), MethodError>
330309
{
331310
let mode = probe::Mode::Path;
332311
let pick = try!(probe::probe(fcx, span, mode, method_name, self_ty, expr_id));

branches/try/src/librustc_typeck/check/method/probe.rs

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
// except according to those terms.
1010

1111
use super::MethodError;
12-
use super::NoMatchData;
1312
use super::ItemIndex;
14-
use super::{CandidateSource, ImplSource, TraitSource};
13+
use super::{CandidateSource,ImplSource,TraitSource};
1514
use super::suggest;
1615

1716
use check;
@@ -20,7 +19,7 @@ use middle::fast_reject;
2019
use middle::subst;
2120
use middle::subst::Subst;
2221
use middle::traits;
23-
use middle::ty::{self, RegionEscape, Ty, ToPolyTraitRef, TraitRef};
22+
use middle::ty::{self, RegionEscape, Ty, ToPolyTraitRef};
2423
use middle::ty_fold::TypeFoldable;
2524
use middle::infer;
2625
use middle::infer::InferCtxt;
@@ -43,14 +42,7 @@ struct ProbeContext<'a, 'tcx:'a> {
4342
inherent_candidates: Vec<Candidate<'tcx>>,
4443
extension_candidates: Vec<Candidate<'tcx>>,
4544
impl_dups: HashSet<ast::DefId>,
46-
47-
/// Collects near misses when the candidate functions are missing a `self` keyword and is only
48-
/// used for error reporting
4945
static_candidates: Vec<CandidateSource>,
50-
51-
/// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
52-
/// for error reporting
53-
unsatisfied_predicates: Vec<TraitRef<'tcx>>
5446
}
5547

5648
#[derive(Debug)]
@@ -112,7 +104,7 @@ pub enum PickKind<'tcx> {
112104
WhereClausePick(/* Trait */ ty::PolyTraitRef<'tcx>, ItemIndex),
113105
}
114106

115-
pub type PickResult<'tcx> = Result<Pick<'tcx>, MethodError<'tcx>>;
107+
pub type PickResult<'tcx> = Result<Pick<'tcx>, MethodError>;
116108

117109
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
118110
pub enum Mode {
@@ -149,8 +141,7 @@ pub fn probe<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
149141
let steps = if mode == Mode::MethodCall {
150142
match create_steps(fcx, span, self_ty) {
151143
Some(steps) => steps,
152-
None =>return Err(MethodError::NoMatch(NoMatchData::new(Vec::new(), Vec::new(),
153-
Vec::new(), mode))),
144+
None => return Err(MethodError::NoMatch(Vec::new(), Vec::new(), mode)),
154145
}
155146
} else {
156147
vec![CandidateStep {
@@ -251,7 +242,6 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
251242
steps: Rc::new(steps),
252243
opt_simplified_steps: opt_simplified_steps,
253244
static_candidates: Vec::new(),
254-
unsatisfied_predicates: Vec::new(),
255245
}
256246
}
257247

@@ -573,7 +563,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
573563

574564
fn assemble_extension_candidates_for_traits_in_scope(&mut self,
575565
expr_id: ast::NodeId)
576-
-> Result<(), MethodError<'tcx>>
566+
-> Result<(),MethodError>
577567
{
578568
let mut duplicates = HashSet::new();
579569
let opt_applicable_traits = self.fcx.ccx.trait_map.get(&expr_id);
@@ -587,7 +577,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
587577
Ok(())
588578
}
589579

590-
fn assemble_extension_candidates_for_all_traits(&mut self) -> Result<(), MethodError<'tcx>> {
580+
fn assemble_extension_candidates_for_all_traits(&mut self) -> Result<(),MethodError> {
591581
let mut duplicates = HashSet::new();
592582
for trait_info in suggest::all_traits(self.fcx.ccx) {
593583
if duplicates.insert(trait_info.def_id) {
@@ -599,7 +589,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
599589

600590
fn assemble_extension_candidates_for_trait(&mut self,
601591
trait_def_id: ast::DefId)
602-
-> Result<(), MethodError<'tcx>>
592+
-> Result<(),MethodError>
603593
{
604594
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})",
605595
trait_def_id);
@@ -719,7 +709,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
719709
trait_def_id: ast::DefId,
720710
item: ty::ImplOrTraitItem<'tcx>,
721711
item_index: usize)
722-
-> Result<(), MethodError<'tcx>>
712+
-> Result<(),MethodError>
723713
{
724714
// Check if this is one of the Fn,FnMut,FnOnce traits.
725715
let tcx = self.tcx();
@@ -878,7 +868,6 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
878868
}
879869

880870
let static_candidates = mem::replace(&mut self.static_candidates, vec![]);
881-
let unsatisfied_predicates = mem::replace(&mut self.unsatisfied_predicates, vec![]);
882871

883872
// things failed, so lets look at all traits, for diagnostic purposes now:
884873
self.reset();
@@ -903,7 +892,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
903892
}
904893
}
905894
}).collect(),
906-
Some(Err(MethodError::NoMatch(NoMatchData { out_of_scope_traits: others, .. }))) => {
895+
Some(Err(MethodError::NoMatch(_, others, _))) => {
907896
assert!(others.is_empty());
908897
vec![]
909898
}
@@ -914,8 +903,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
914903
None => vec![],
915904
};
916905

917-
Err(MethodError::NoMatch(NoMatchData::new(static_candidates, unsatisfied_predicates,
918-
out_of_scope_traits, self.mode)))
906+
Err(MethodError::NoMatch(static_candidates, out_of_scope_traits, self.mode))
919907
}
920908

921909
fn pick_core(&mut self) -> Option<PickResult<'tcx>> {
@@ -1003,35 +991,25 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
1003991
fn pick_method(&mut self, self_ty: Ty<'tcx>) -> Option<PickResult<'tcx>> {
1004992
debug!("pick_method(self_ty={})", self.infcx().ty_to_string(self_ty));
1005993

1006-
let mut possibly_unsatisfied_predicates = Vec::new();
1007-
1008994
debug!("searching inherent candidates");
1009-
match self.consider_candidates(self_ty, &self.inherent_candidates,
1010-
&mut possibly_unsatisfied_predicates) {
995+
match self.consider_candidates(self_ty, &self.inherent_candidates) {
1011996
None => {}
1012997
Some(pick) => {
1013998
return Some(pick);
1014999
}
10151000
}
10161001

10171002
debug!("searching extension candidates");
1018-
let res = self.consider_candidates(self_ty, &self.extension_candidates,
1019-
&mut possibly_unsatisfied_predicates);
1020-
if let None = res {
1021-
self.unsatisfied_predicates.extend(possibly_unsatisfied_predicates);
1022-
}
1023-
res
1003+
self.consider_candidates(self_ty, &self.extension_candidates)
10241004
}
10251005

10261006
fn consider_candidates(&self,
10271007
self_ty: Ty<'tcx>,
1028-
probes: &[Candidate<'tcx>],
1029-
possibly_unsatisfied_predicates: &mut Vec<TraitRef<'tcx>>)
1008+
probes: &[Candidate<'tcx>])
10301009
-> Option<PickResult<'tcx>> {
10311010
let mut applicable_candidates: Vec<_> =
10321011
probes.iter()
1033-
.filter(|&probe| self.consider_probe(self_ty,
1034-
probe,possibly_unsatisfied_predicates))
1012+
.filter(|&probe| self.consider_probe(self_ty, probe))
10351013
.collect();
10361014

10371015
debug!("applicable_candidates: {:?}", applicable_candidates);
@@ -1054,8 +1032,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
10541032
})
10551033
}
10561034

1057-
fn consider_probe(&self, self_ty: Ty<'tcx>, probe: &Candidate<'tcx>,
1058-
possibly_unsatisfied_predicates: &mut Vec<TraitRef<'tcx>>) -> bool {
1035+
fn consider_probe(&self, self_ty: Ty<'tcx>, probe: &Candidate<'tcx>) -> bool {
10591036
debug!("consider_probe: self_ty={:?} probe={:?}",
10601037
self_ty,
10611038
probe);
@@ -1094,18 +1071,10 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
10941071
debug!("impl_obligations={:?}", obligations);
10951072

10961073
// Evaluate those obligations to see if they might possibly hold.
1097-
let mut all_true = true;
1098-
for o in obligations.iter()
1099-
.chain(norm_obligations.iter())
1100-
.chain(ref_obligations.iter()) {
1101-
if !selcx.evaluate_obligation(o) {
1102-
all_true = false;
1103-
if let &ty::Predicate::Trait(ref pred) = &o.predicate {
1104-
possibly_unsatisfied_predicates.push(pred.0.trait_ref);
1105-
}
1106-
}
1107-
}
1108-
all_true
1074+
obligations.iter()
1075+
.chain(norm_obligations.iter()).chain(ref_obligations.iter())
1076+
.all(|o| selcx.evaluate_obligation(o))
1077+
11091078
}
11101079

11111080
ProjectionCandidate(..) |

branches/try/src/librustc_typeck/check/method/suggest.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,23 @@ use syntax::print::pprust;
2929
use std::cell;
3030
use std::cmp::Ordering;
3131

32-
use super::{MethodError, NoMatchData, CandidateSource, impl_item, trait_item};
32+
use super::{MethodError, CandidateSource, impl_item, trait_item};
3333
use super::probe::Mode;
3434

3535
pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
3636
span: Span,
3737
rcvr_ty: Ty<'tcx>,
3838
item_name: ast::Name,
3939
rcvr_expr: Option<&ast::Expr>,
40-
error: MethodError<'tcx>)
40+
error: MethodError)
4141
{
4242
// avoid suggestions when we don't know what's going on.
4343
if ty::type_is_error(rcvr_ty) {
4444
return
4545
}
4646

4747
match error {
48-
MethodError::NoMatch(NoMatchData { static_candidates: static_sources,
49-
unsatisfied_predicates,
50-
out_of_scope_traits,
51-
mode }) => {
48+
MethodError::NoMatch(static_sources, out_of_scope_traits, mode) => {
5249
let cx = fcx.tcx();
5350

5451
fcx.type_error_message(
@@ -121,28 +118,13 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
121118
}
122119

123120
if !static_sources.is_empty() {
124-
cx.sess.fileline_note(
121+
fcx.tcx().sess.fileline_note(
125122
span,
126123
"found defined static methods, maybe a `self` is missing?");
127124

128125
report_candidates(fcx, span, item_name, static_sources);
129126
}
130127

131-
if !unsatisfied_predicates.is_empty() {
132-
let bound_list = unsatisfied_predicates.iter()
133-
.map(|p| format!("`{} : {}`",
134-
p.self_ty(),
135-
p))
136-
.collect::<Vec<_>>()
137-
.connect(", ");
138-
cx.sess.fileline_note(
139-
span,
140-
&format!("the method `{}` exists but the \
141-
following trait bounds were not satisfied: {}",
142-
item_name,
143-
bound_list));
144-
}
145-
146128
suggest_traits_to_import(fcx, span, rcvr_ty, item_name,
147129
rcvr_expr, out_of_scope_traits)
148130
}

branches/try/src/libstd/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ pub trait BufRead: Read {
571571
read_until(self, byte, buf)
572572
}
573573

574-
/// Read all bytes until a newline (the 0xA byte) is reached, and
574+
/// Read all bytes until a newline byte (the 0xA byte) is reached, and
575575
/// append them to the provided buffer.
576576
///
577577
/// This function will continue to read (and buffer) bytes from the

0 commit comments

Comments
 (0)