Skip to content

Commit 8a431cc

Browse files
committed
---
yaml --- r: 174394 b: refs/heads/auto c: 135cac8 h: refs/heads/master v: v3
1 parent adba044 commit 8a431cc

File tree

8 files changed

+63
-73
lines changed

8 files changed

+63
-73
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 3f0cc8011aef3f530663302d525bd2d8cb493db5
13+
refs/heads/auto: 135cac852822afe822cc1e4eb9546b96eb2cb35d
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/liblibc/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,10 +2207,10 @@ pub mod consts {
22072207
pub const IPPROTO_TCP: c_int = 6;
22082208
pub const IPPROTO_IP: c_int = 0;
22092209
pub const IPPROTO_IPV6: c_int = 41;
2210-
pub const IP_MULTICAST_TTL: c_int = 3;
2211-
pub const IP_MULTICAST_LOOP: c_int = 4;
2212-
pub const IP_ADD_MEMBERSHIP: c_int = 5;
2213-
pub const IP_DROP_MEMBERSHIP: c_int = 6;
2210+
pub const IP_MULTICAST_TTL: c_int = 10;
2211+
pub const IP_MULTICAST_LOOP: c_int = 11;
2212+
pub const IP_ADD_MEMBERSHIP: c_int = 12;
2213+
pub const IP_DROP_MEMBERSHIP: c_int = 13;
22142214
pub const IPV6_ADD_MEMBERSHIP: c_int = 5;
22152215
pub const IPV6_DROP_MEMBERSHIP: c_int = 6;
22162216
pub const IP_TTL: c_int = 4;

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

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ struct ProbeContext<'a, 'tcx:'a> {
4444
extension_candidates: Vec<Candidate<'tcx>>,
4545
impl_dups: HashSet<ast::DefId>,
4646
static_candidates: Vec<CandidateSource>,
47-
all_traits_search: bool,
4847
}
4948

5049
struct CandidateStep<'tcx> {
@@ -211,7 +210,6 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
211210
steps: Rc::new(steps),
212211
opt_simplified_steps: opt_simplified_steps,
213212
static_candidates: Vec::new(),
214-
all_traits_search: false,
215213
}
216214
}
217215

@@ -724,60 +722,53 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
724722
// THE ACTUAL SEARCH
725723

726724
fn pick(mut self) -> PickResult<'tcx> {
727-
let steps = self.steps.clone();
728-
729-
for step in steps.iter() {
730-
match self.pick_step(step) {
731-
Some(r) => {
732-
return r;
733-
}
734-
None => { }
735-
}
725+
match self.pick_core() {
726+
Some(r) => return r,
727+
None => {}
736728
}
737729

738730
let static_candidates = mem::replace(&mut self.static_candidates, vec![]);
739731

740-
let out_of_scope_traits = if !self.all_traits_search {
741-
// things failed, and we haven't yet looked through all
742-
// traits, so lets do that now:
743-
self.reset();
744-
self.all_traits_search = true;
745-
746-
let span = self.span;
747-
let tcx = self.tcx();
748-
749-
self.assemble_extension_candidates_for_all_traits();
750-
751-
match self.pick() {
752-
Ok(p) => vec![p.method_ty.container.id()],
753-
Err(Ambiguity(v)) => v.into_iter().map(|source| {
754-
match source {
755-
TraitSource(id) => id,
756-
ImplSource(impl_id) => {
757-
match ty::trait_id_of_impl(tcx, impl_id) {
758-
Some(id) => id,
759-
None => tcx.sess.span_bug(span,
760-
"found inherent method when looking \
761-
at traits")
762-
}
732+
// things failed, so lets look at all traits, for diagnostic purposes now:
733+
self.reset();
734+
735+
let span = self.span;
736+
let tcx = self.tcx();
737+
738+
self.assemble_extension_candidates_for_all_traits();
739+
740+
let out_of_scope_traits = match self.pick_core() {
741+
Some(Ok(p)) => vec![p.method_ty.container.id()],
742+
Some(Err(Ambiguity(v))) => v.into_iter().map(|source| {
743+
match source {
744+
TraitSource(id) => id,
745+
ImplSource(impl_id) => {
746+
match ty::trait_id_of_impl(tcx, impl_id) {
747+
Some(id) => id,
748+
None =>
749+
tcx.sess.span_bug(span,
750+
"found inherent method when looking at traits")
763751
}
764752
}
765-
}).collect(),
766-
// it'd be really weird for this assertion to trigger,
767-
// given the `vec![]` in the else branch below
768-
Err(NoMatch(_, others)) => {
769-
assert!(others.is_empty());
770-
vec![]
771753
}
754+
}).collect(),
755+
Some(Err(NoMatch(_, others))) => {
756+
assert!(others.is_empty());
757+
vec![]
772758
}
773-
} else {
774-
// we've just looked through all traits and didn't find
775-
// anything at all.
776-
vec![]
759+
None => vec![],
777760
};
761+
;
778762
Err(NoMatch(static_candidates, out_of_scope_traits))
779763
}
780764

765+
fn pick_core(&mut self) -> Option<PickResult<'tcx>> {
766+
let steps = self.steps.clone();
767+
768+
// find the first step that works
769+
steps.iter().filter_map(|step| self.pick_step(step)).next()
770+
}
771+
781772
fn pick_step(&mut self, step: &CandidateStep<'tcx>) -> Option<PickResult<'tcx>> {
782773
debug!("pick_step: step={}", step.repr(self.tcx()));
783774

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,16 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
147147
candidates.sort();
148148
let msg = format!(
149149
"methods from traits can only be called if the trait is in scope; \
150-
the following {traits_are} implemented and {define} a method `{name}`:",
150+
the following {traits_are} implemented but not in scope, \
151+
perhaps add a `use` for {one_of_them}:",
151152
traits_are = if candidates.len() == 1 {"trait is"} else {"traits are"},
152-
define = if candidates.len() == 1 {"defines"} else {"define"},
153-
name = method_ustring);
153+
one_of_them = if candidates.len() == 1 {"it"} else {"one of them"});
154154

155155
fcx.sess().fileline_help(span, &msg[]);
156156

157157
for (i, trait_did) in candidates.iter().enumerate() {
158158
fcx.sess().fileline_help(span,
159-
&*format!("candidate #{}: `{}`",
159+
&*format!("candidate #{}: use `{}`",
160160
i + 1,
161161
ty::item_path_str(fcx.tcx(), *trait_did)))
162162

@@ -174,9 +174,11 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
174174
candidates.sort_by(|a, b| a.cmp(b).reverse());
175175

176176
let msg = format!(
177-
"methods from traits can only be called if the trait is implemented and \
178-
in scope; no such traits are but the following {traits_define} a method `{name}`:",
177+
"methods from traits can only be called if the trait is implemented and in scope; \
178+
the following {traits_define} a method `{name}`, \
179+
perhaps you need to implement {one_of_them}:",
179180
traits_define = if candidates.len() == 1 {"trait defines"} else {"traits define"},
181+
one_of_them = if candidates.len() == 1 {"it"} else {"one of them"},
180182
name = method_ustring);
181183

182184
fcx.sess().fileline_help(span, &msg[]);

branches/auto/src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,7 @@ impl<'a> Parser<'a> {
21362136

21372137
let ex: Expr_;
21382138

2139+
// Note: when adding new syntax here, don't forget to adjust Token::can_begin_expr().
21392140
match self.token {
21402141
token::OpenDelim(token::Paren) => {
21412142
self.bump();
@@ -2773,6 +2774,7 @@ impl<'a> Parser<'a> {
27732774
let lo = self.span.lo;
27742775
let hi;
27752776

2777+
// Note: when adding new unary operators, don't forget to adjust Token::can_begin_expr()
27762778
let ex;
27772779
match self.token {
27782780
token::Not => {
@@ -5517,13 +5519,6 @@ impl<'a> Parser<'a> {
55175519
(id, ItemEnum(enum_definition, generics), None)
55185520
}
55195521

5520-
fn fn_expr_lookahead(tok: &token::Token) -> bool {
5521-
match *tok {
5522-
token::OpenDelim(token::Paren) | token::At | token::Tilde | token::BinOp(_) => true,
5523-
_ => false
5524-
}
5525-
}
5526-
55275522
/// Parses a string as an ABI spec on an extern type or module. Consumes
55285523
/// the `extern` keyword, if one is found.
55295524
fn parse_opt_abi(&mut self) -> Option<abi::Abi> {
@@ -5696,8 +5691,7 @@ impl<'a> Parser<'a> {
56965691
maybe_append(attrs, extra_attrs));
56975692
return IoviItem(item);
56985693
}
5699-
if self.token.is_keyword(keywords::Fn) &&
5700-
self.look_ahead(1, |f| !Parser::fn_expr_lookahead(f)) {
5694+
if self.token.is_keyword(keywords::Fn) {
57015695
// FUNCTION ITEM
57025696
self.bump();
57035697
let (ident, item_, extra_attrs) =

branches/auto/src/libsyntax/parse/token.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ impl Token {
183183
Underscore => true,
184184
Tilde => true,
185185
Literal(_, _) => true,
186-
Pound => true,
187-
At => true,
188186
Not => true,
189187
BinOp(Minus) => true,
190188
BinOp(Star) => true,
191189
BinOp(And) => true,
192190
BinOp(Or) => true, // in lambda syntax
193191
OrOr => true, // in lambda syntax
192+
AndAnd => true, // double borrow
193+
DotDot => true, // range notation
194194
ModSep => true,
195195
Interpolated(NtExpr(..)) => true,
196196
Interpolated(NtIdent(..)) => true,

branches/auto/src/test/compile-fail/no-method-suggested-traits.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ mod foo {
2626

2727
fn main() {
2828
1u32.method();
29-
//~^ ERROR does not implement
30-
//~^^ HELP the following traits are implemented and define a method `method`
29+
//~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them
30+
//~^^ ERROR does not implement
3131
//~^^^ HELP `foo::Bar`
3232
//~^^^^ HELP `no_method_suggested_traits::foo::PubPub`
3333

3434
'a'.method();
3535
//~^ ERROR does not implement
36-
//~^^ HELP the following trait is implemented and defines a method `method`
36+
//~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it:
3737
//~^^^ HELP `foo::Bar`
3838

3939
1i32.method();
4040
//~^ ERROR does not implement
41-
//~^^ HELP the following trait is implemented and defines a method `method`
41+
//~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it:
4242
//~^^^ HELP `no_method_suggested_traits::foo::PubPub`
4343

4444
1u64.method();
4545
//~^ ERROR does not implement
46-
//~^^ HELP the following traits define a method `method`
46+
//~^^ HELP following traits define a method `method`, perhaps you need to implement one of them
4747
//~^^^ HELP `foo::Bar`
4848
//~^^^^ HELP `no_method_suggested_traits::foo::PubPub`
4949
//~^^^^^ HELP `no_method_suggested_traits::reexport::Reexported`
@@ -53,10 +53,10 @@ fn main() {
5353

5454
1u64.method2();
5555
//~^ ERROR does not implement
56-
//~^^ HELP the following trait defines a method `method2`
56+
//~^^ HELP the following trait defines a method `method2`, perhaps you need to implement it
5757
//~^^^ HELP `foo::Bar`
5858
1u64.method3();
5959
//~^ ERROR does not implement
60-
//~^^ HELP the following trait defines a method `method3`
60+
//~^^ HELP the following trait defines a method `method3`, perhaps you need to implement it
6161
//~^^^ HELP `no_method_suggested_traits::foo::PubPub`
6262
}

branches/auto/src/test/run-pass/range.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
fn foo() -> int { 42 }
1414

15+
// Test that range syntax works in return statements
16+
fn return_range_to() -> ::std::ops::RangeTo<i32> { return ..1; }
17+
1518
pub fn main() {
1619
let mut count = 0;
1720
for i in 0u..10 {

0 commit comments

Comments
 (0)