Skip to content

Commit 2645871

Browse files
committed
Use appropriate terminology based on heuristic
1 parent 0952856 commit 2645871

16 files changed

+58
-29
lines changed

src/libsyntax/parse/parser.rs

+24-13
Original file line numberDiff line numberDiff line change
@@ -6134,9 +6134,6 @@ impl<'a> Parser<'a> {
61346134

61356135
fn consume_block(&mut self, delim: token::DelimToken) {
61366136
let mut brace_depth = 0;
6137-
if !self.eat(&token::OpenDelim(delim)) {
6138-
return;
6139-
}
61406137
loop {
61416138
if self.eat(&token::OpenDelim(delim)) {
61426139
brace_depth += 1;
@@ -6147,7 +6144,7 @@ impl<'a> Parser<'a> {
61476144
brace_depth -= 1;
61486145
continue;
61496146
}
6150-
} else if self.eat(&token::Eof) || self.eat(&token::CloseDelim(token::NoDelim)) {
6147+
} else if self.token == token::Eof || self.eat(&token::CloseDelim(token::NoDelim)) {
61516148
return;
61526149
} else {
61536150
self.bump();
@@ -7397,17 +7394,27 @@ impl<'a> Parser<'a> {
73977394
return Err(err);
73987395
} else if self.look_ahead(1, |t| *t == token::OpenDelim(token::Paren)) {
73997396
let ident = self.parse_ident().unwrap();
7397+
self.bump(); // `(`
7398+
let kw_name = if let Ok(Some(_)) = self.parse_self_arg() {
7399+
"method"
7400+
} else {
7401+
"function"
7402+
};
74007403
self.consume_block(token::Paren);
7401-
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) ||
7402-
self.check(&token::OpenDelim(token::Brace))
7403-
{
7404-
("fn", "method", false)
7404+
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) {
7405+
self.eat_to_tokens(&[&token::OpenDelim(token::Brace)]);
7406+
self.bump(); // `{`
7407+
("fn", kw_name, false)
7408+
} else if self.check(&token::OpenDelim(token::Brace)) {
7409+
self.bump(); // `{`
7410+
("fn", kw_name, false)
74057411
} else if self.check(&token::Colon) {
74067412
let kw = "struct";
74077413
(kw, kw, false)
74087414
} else {
7409-
("fn` or `struct", "method or struct", true)
7415+
("fn` or `struct", "function or struct", true)
74107416
};
7417+
self.consume_block(token::Brace);
74117418

74127419
let msg = format!("missing `{}` for {} definition", kw, kw_name);
74137420
let mut err = self.diagnostic().struct_span_err(sp, &msg);
@@ -7437,13 +7444,17 @@ impl<'a> Parser<'a> {
74377444
} else if self.look_ahead(1, |t| *t == token::Lt) {
74387445
let ident = self.parse_ident().unwrap();
74397446
self.eat_to_tokens(&[&token::Gt]);
7440-
self.bump();
7441-
let (kw, kw_name, ambiguous) = if self.check(&token::OpenDelim(token::Paren)) {
7442-
("fn", "method", false)
7447+
self.bump(); // `>`
7448+
let (kw, kw_name, ambiguous) = if self.eat(&token::OpenDelim(token::Paren)) {
7449+
if let Ok(Some(_)) = self.parse_self_arg() {
7450+
("fn", "method", false)
7451+
} else {
7452+
("fn", "function", false)
7453+
}
74437454
} else if self.check(&token::OpenDelim(token::Brace)) {
74447455
("struct", "struct", false)
74457456
} else {
7446-
("fn` or `struct", "method or struct", true)
7457+
("fn` or `struct", "function or struct", true)
74477458
};
74487459
let msg = format!("missing `{}` for {} definition", kw, kw_name);
74497460
let mut err = self.diagnostic().struct_span_err(sp, &msg);

src/test/ui/pub/pub-ident-fn-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
pub foo(s: usize) { bar() }
12-
//~^ ERROR missing `fn` for method definition
12+
//~^ ERROR missing `fn` for function definition
1313

1414
fn main() {
1515
foo(2);

src/test/ui/pub/pub-ident-fn-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
error: missing `fn` for method definition
1+
error: missing `fn` for function definition
22
--> $DIR/pub-ident-fn-2.rs:11:4
33
|
44
LL | pub foo(s: usize) { bar() }
55
| ^
6-
help: add `fn` here to parse `foo` as a public method
6+
help: add `fn` here to parse `foo` as a public function
77
|
88
LL | pub fn foo(s: usize) { bar() }
99
| ^^

src/test/ui/pub/pub-ident-fn-or-struct-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
// except according to those terms.
1010

1111
pub S();
12-
//~^ ERROR missing `fn` or `struct` for method or struct definition
12+
//~^ ERROR missing `fn` or `struct` for function or struct definition
1313

1414
fn main() {}

src/test/ui/pub/pub-ident-fn-or-struct-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: missing `fn` or `struct` for method or struct definition
1+
error: missing `fn` or `struct` for function or struct definition
22
--> $DIR/pub-ident-fn-or-struct-2.rs:11:4
33
|
44
LL | pub S();

src/test/ui/pub/pub-ident-fn-or-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
// except according to those terms.
1010

1111
pub S (foo) bar
12-
//~^ ERROR missing `fn` or `struct` for method or struct definition
12+
//~^ ERROR missing `fn` or `struct` for function or struct definition
1313

1414
fn main() {}

src/test/ui/pub/pub-ident-fn-or-struct.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: missing `fn` or `struct` for method or struct definition
1+
error: missing `fn` or `struct` for function or struct definition
22
--> $DIR/pub-ident-fn-or-struct.rs:11:4
33
|
44
LL | pub S (foo) bar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub bar<'a>(&self, _s: &'a usize) -> bool { true }
2+
//~^ ERROR missing `fn` for method definition
3+
4+
fn main() {
5+
bar(2);
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: missing `fn` for method definition
2+
--> $DIR/pub-ident-fn-with-lifetime-2.rs:1:4
3+
|
4+
LL | pub bar<'a>(&self, _s: &'a usize) -> bool { true }
5+
| ^^^
6+
help: add `fn` here to parse `bar` as a public method
7+
|
8+
LL | pub fn bar<'a>(&self, _s: &'a usize) -> bool { true }
9+
| ^^
10+
11+
error: aborting due to previous error
12+

src/test/ui/pub/pub-ident-fn-with-lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub foo<'a>(_s: &'a usize) -> bool { true }
2-
//~^ ERROR missing `fn` for method definition
2+
//~^ ERROR missing `fn` for function definition
33

44
fn main() {
55
foo(2);

src/test/ui/pub/pub-ident-fn-with-lifetime.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
error: missing `fn` for method definition
1+
error: missing `fn` for function definition
22
--> $DIR/pub-ident-fn-with-lifetime.rs:1:4
33
|
44
LL | pub foo<'a>(_s: &'a usize) -> bool { true }
55
| ^^^
6-
help: add `fn` here to parse `foo` as a public method
6+
help: add `fn` here to parse `foo` as a public function
77
|
88
LL | pub fn foo<'a>(_s: &'a usize) -> bool { true }
99
| ^^

src/test/ui/pub/pub-ident-fn.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// run-rustfix
1212

1313
pub fn foo(_s: usize) -> bool { true }
14-
//~^ ERROR missing `fn` for method definition
14+
//~^ ERROR missing `fn` for function definition
1515

1616
fn main() {
1717
foo(2);

src/test/ui/pub/pub-ident-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// run-rustfix
1212

1313
pub foo(_s: usize) -> bool { true }
14-
//~^ ERROR missing `fn` for method definition
14+
//~^ ERROR missing `fn` for function definition
1515

1616
fn main() {
1717
foo(2);

src/test/ui/pub/pub-ident-fn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
error: missing `fn` for method definition
1+
error: missing `fn` for function definition
22
--> $DIR/pub-ident-fn.rs:13:4
33
|
44
LL | pub foo(_s: usize) -> bool { true }
55
| ^^^
6-
help: add `fn` here to parse `foo` as a public method
6+
help: add `fn` here to parse `foo` as a public function
77
|
88
LL | pub fn foo(_s: usize) -> bool { true }
99
| ^^

src/test/ui/pub/pub-ident-with-lifetime-incomplete.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ fn main() {
22
}
33

44
pub foo<'a>
5-
//~^ ERROR missing `fn` or `struct` for method or struct definition
5+
//~^ ERROR missing `fn` or `struct` for function or struct definition

src/test/ui/pub/pub-ident-with-lifetime-incomplete.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: missing `fn` or `struct` for method or struct definition
1+
error: missing `fn` or `struct` for function or struct definition
22
--> $DIR/pub-ident-with-lifetime-incomplete.rs:4:4
33
|
44
LL | pub foo<'a>

0 commit comments

Comments
 (0)