mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
Use appropriate terminology based on heuristic
This commit is contained in:
parent
0952856e6c
commit
2645871111
@ -6134,9 +6134,6 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
fn consume_block(&mut self, delim: token::DelimToken) {
|
fn consume_block(&mut self, delim: token::DelimToken) {
|
||||||
let mut brace_depth = 0;
|
let mut brace_depth = 0;
|
||||||
if !self.eat(&token::OpenDelim(delim)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
loop {
|
loop {
|
||||||
if self.eat(&token::OpenDelim(delim)) {
|
if self.eat(&token::OpenDelim(delim)) {
|
||||||
brace_depth += 1;
|
brace_depth += 1;
|
||||||
@ -6147,7 +6144,7 @@ impl<'a> Parser<'a> {
|
|||||||
brace_depth -= 1;
|
brace_depth -= 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if self.eat(&token::Eof) || self.eat(&token::CloseDelim(token::NoDelim)) {
|
} else if self.token == token::Eof || self.eat(&token::CloseDelim(token::NoDelim)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
self.bump();
|
self.bump();
|
||||||
@ -7397,17 +7394,27 @@ impl<'a> Parser<'a> {
|
|||||||
return Err(err);
|
return Err(err);
|
||||||
} else if self.look_ahead(1, |t| *t == token::OpenDelim(token::Paren)) {
|
} else if self.look_ahead(1, |t| *t == token::OpenDelim(token::Paren)) {
|
||||||
let ident = self.parse_ident().unwrap();
|
let ident = self.parse_ident().unwrap();
|
||||||
|
self.bump(); // `(`
|
||||||
|
let kw_name = if let Ok(Some(_)) = self.parse_self_arg() {
|
||||||
|
"method"
|
||||||
|
} else {
|
||||||
|
"function"
|
||||||
|
};
|
||||||
self.consume_block(token::Paren);
|
self.consume_block(token::Paren);
|
||||||
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) ||
|
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) {
|
||||||
self.check(&token::OpenDelim(token::Brace))
|
self.eat_to_tokens(&[&token::OpenDelim(token::Brace)]);
|
||||||
{
|
self.bump(); // `{`
|
||||||
("fn", "method", false)
|
("fn", kw_name, false)
|
||||||
|
} else if self.check(&token::OpenDelim(token::Brace)) {
|
||||||
|
self.bump(); // `{`
|
||||||
|
("fn", kw_name, false)
|
||||||
} else if self.check(&token::Colon) {
|
} else if self.check(&token::Colon) {
|
||||||
let kw = "struct";
|
let kw = "struct";
|
||||||
(kw, kw, false)
|
(kw, kw, false)
|
||||||
} else {
|
} else {
|
||||||
("fn` or `struct", "method or struct", true)
|
("fn` or `struct", "function or struct", true)
|
||||||
};
|
};
|
||||||
|
self.consume_block(token::Brace);
|
||||||
|
|
||||||
let msg = format!("missing `{}` for {} definition", kw, kw_name);
|
let msg = format!("missing `{}` for {} definition", kw, kw_name);
|
||||||
let mut err = self.diagnostic().struct_span_err(sp, &msg);
|
let mut err = self.diagnostic().struct_span_err(sp, &msg);
|
||||||
@ -7437,13 +7444,17 @@ impl<'a> Parser<'a> {
|
|||||||
} else if self.look_ahead(1, |t| *t == token::Lt) {
|
} else if self.look_ahead(1, |t| *t == token::Lt) {
|
||||||
let ident = self.parse_ident().unwrap();
|
let ident = self.parse_ident().unwrap();
|
||||||
self.eat_to_tokens(&[&token::Gt]);
|
self.eat_to_tokens(&[&token::Gt]);
|
||||||
self.bump();
|
self.bump(); // `>`
|
||||||
let (kw, kw_name, ambiguous) = if self.check(&token::OpenDelim(token::Paren)) {
|
let (kw, kw_name, ambiguous) = if self.eat(&token::OpenDelim(token::Paren)) {
|
||||||
|
if let Ok(Some(_)) = self.parse_self_arg() {
|
||||||
("fn", "method", false)
|
("fn", "method", false)
|
||||||
|
} else {
|
||||||
|
("fn", "function", false)
|
||||||
|
}
|
||||||
} else if self.check(&token::OpenDelim(token::Brace)) {
|
} else if self.check(&token::OpenDelim(token::Brace)) {
|
||||||
("struct", "struct", false)
|
("struct", "struct", false)
|
||||||
} else {
|
} else {
|
||||||
("fn` or `struct", "method or struct", true)
|
("fn` or `struct", "function or struct", true)
|
||||||
};
|
};
|
||||||
let msg = format!("missing `{}` for {} definition", kw, kw_name);
|
let msg = format!("missing `{}` for {} definition", kw, kw_name);
|
||||||
let mut err = self.diagnostic().struct_span_err(sp, &msg);
|
let mut err = self.diagnostic().struct_span_err(sp, &msg);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub foo(s: usize) { bar() }
|
pub foo(s: usize) { bar() }
|
||||||
//~^ ERROR missing `fn` for method definition
|
//~^ ERROR missing `fn` for function definition
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
foo(2);
|
foo(2);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
error: missing `fn` for method definition
|
error: missing `fn` for function definition
|
||||||
--> $DIR/pub-ident-fn-2.rs:11:4
|
--> $DIR/pub-ident-fn-2.rs:11:4
|
||||||
|
|
|
|
||||||
LL | pub foo(s: usize) { bar() }
|
LL | pub foo(s: usize) { bar() }
|
||||||
| ^
|
| ^
|
||||||
help: add `fn` here to parse `foo` as a public method
|
help: add `fn` here to parse `foo` as a public function
|
||||||
|
|
|
|
||||||
LL | pub fn foo(s: usize) { bar() }
|
LL | pub fn foo(s: usize) { bar() }
|
||||||
| ^^
|
| ^^
|
||||||
|
@ -9,6 +9,6 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub S();
|
pub S();
|
||||||
//~^ ERROR missing `fn` or `struct` for method or struct definition
|
//~^ ERROR missing `fn` or `struct` for function or struct definition
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error: missing `fn` or `struct` for method or struct definition
|
error: missing `fn` or `struct` for function or struct definition
|
||||||
--> $DIR/pub-ident-fn-or-struct-2.rs:11:4
|
--> $DIR/pub-ident-fn-or-struct-2.rs:11:4
|
||||||
|
|
|
|
||||||
LL | pub S();
|
LL | pub S();
|
||||||
|
@ -9,6 +9,6 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub S (foo) bar
|
pub S (foo) bar
|
||||||
//~^ ERROR missing `fn` or `struct` for method or struct definition
|
//~^ ERROR missing `fn` or `struct` for function or struct definition
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error: missing `fn` or `struct` for method or struct definition
|
error: missing `fn` or `struct` for function or struct definition
|
||||||
--> $DIR/pub-ident-fn-or-struct.rs:11:4
|
--> $DIR/pub-ident-fn-or-struct.rs:11:4
|
||||||
|
|
|
|
||||||
LL | pub S (foo) bar
|
LL | pub S (foo) bar
|
||||||
|
6
src/test/ui/pub/pub-ident-fn-with-lifetime-2.rs
Normal file
6
src/test/ui/pub/pub-ident-fn-with-lifetime-2.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
pub bar<'a>(&self, _s: &'a usize) -> bool { true }
|
||||||
|
//~^ ERROR missing `fn` for method definition
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
bar(2);
|
||||||
|
}
|
12
src/test/ui/pub/pub-ident-fn-with-lifetime-2.stderr
Normal file
12
src/test/ui/pub/pub-ident-fn-with-lifetime-2.stderr
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
error: missing `fn` for method definition
|
||||||
|
--> $DIR/pub-ident-fn-with-lifetime-2.rs:1:4
|
||||||
|
|
|
||||||
|
LL | pub bar<'a>(&self, _s: &'a usize) -> bool { true }
|
||||||
|
| ^^^
|
||||||
|
help: add `fn` here to parse `bar` as a public method
|
||||||
|
|
|
||||||
|
LL | pub fn bar<'a>(&self, _s: &'a usize) -> bool { true }
|
||||||
|
| ^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
pub foo<'a>(_s: &'a usize) -> bool { true }
|
pub foo<'a>(_s: &'a usize) -> bool { true }
|
||||||
//~^ ERROR missing `fn` for method definition
|
//~^ ERROR missing `fn` for function definition
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
foo(2);
|
foo(2);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
error: missing `fn` for method definition
|
error: missing `fn` for function definition
|
||||||
--> $DIR/pub-ident-fn-with-lifetime.rs:1:4
|
--> $DIR/pub-ident-fn-with-lifetime.rs:1:4
|
||||||
|
|
|
|
||||||
LL | pub foo<'a>(_s: &'a usize) -> bool { true }
|
LL | pub foo<'a>(_s: &'a usize) -> bool { true }
|
||||||
| ^^^
|
| ^^^
|
||||||
help: add `fn` here to parse `foo` as a public method
|
help: add `fn` here to parse `foo` as a public function
|
||||||
|
|
|
|
||||||
LL | pub fn foo<'a>(_s: &'a usize) -> bool { true }
|
LL | pub fn foo<'a>(_s: &'a usize) -> bool { true }
|
||||||
| ^^
|
| ^^
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
pub fn foo(_s: usize) -> bool { true }
|
pub fn foo(_s: usize) -> bool { true }
|
||||||
//~^ ERROR missing `fn` for method definition
|
//~^ ERROR missing `fn` for function definition
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
foo(2);
|
foo(2);
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
pub foo(_s: usize) -> bool { true }
|
pub foo(_s: usize) -> bool { true }
|
||||||
//~^ ERROR missing `fn` for method definition
|
//~^ ERROR missing `fn` for function definition
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
foo(2);
|
foo(2);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
error: missing `fn` for method definition
|
error: missing `fn` for function definition
|
||||||
--> $DIR/pub-ident-fn.rs:13:4
|
--> $DIR/pub-ident-fn.rs:13:4
|
||||||
|
|
|
|
||||||
LL | pub foo(_s: usize) -> bool { true }
|
LL | pub foo(_s: usize) -> bool { true }
|
||||||
| ^^^
|
| ^^^
|
||||||
help: add `fn` here to parse `foo` as a public method
|
help: add `fn` here to parse `foo` as a public function
|
||||||
|
|
|
|
||||||
LL | pub fn foo(_s: usize) -> bool { true }
|
LL | pub fn foo(_s: usize) -> bool { true }
|
||||||
| ^^
|
| ^^
|
||||||
|
@ -2,4 +2,4 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub foo<'a>
|
pub foo<'a>
|
||||||
//~^ ERROR missing `fn` or `struct` for method or struct definition
|
//~^ ERROR missing `fn` or `struct` for function or struct definition
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
error: missing `fn` or `struct` for method or struct definition
|
error: missing `fn` or `struct` for function or struct definition
|
||||||
--> $DIR/pub-ident-with-lifetime-incomplete.rs:4:4
|
--> $DIR/pub-ident-with-lifetime-incomplete.rs:4:4
|
||||||
|
|
|
|
||||||
LL | pub foo<'a>
|
LL | pub foo<'a>
|
||||||
|
Loading…
Reference in New Issue
Block a user