-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syntax: recovery for incorrect associated item paths like [T; N]::clone
#46788
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn main() { | ||
let a = [1, 2, 3, 4]; | ||
[i32; 4]::clone(&a); | ||
//~^ ERROR missing angle brackets in associated item path | ||
|
||
[i32]::as_ref(&a); | ||
//~^ ERROR missing angle brackets in associated item path | ||
|
||
(u8)::clone(&0); | ||
//~^ ERROR missing angle brackets in associated item path | ||
|
||
(u8, u8)::clone(&(0, 0)); | ||
//~^ ERROR missing angle brackets in associated item path | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error: missing angle brackets in associated item path | ||
--> $DIR/bad-assoc-expr.rs:13:5 | ||
| | ||
13 | [i32; 4]::clone(&a); | ||
| ^^^^^^^^^^^^^^^ help: try: `<[i32; 4]>::clone` | ||
|
||
error: missing angle brackets in associated item path | ||
--> $DIR/bad-assoc-expr.rs:16:5 | ||
| | ||
16 | [i32]::as_ref(&a); | ||
| ^^^^^^^^^^^^^ help: try: `<[i32]>::as_ref` | ||
|
||
error: missing angle brackets in associated item path | ||
--> $DIR/bad-assoc-expr.rs:19:5 | ||
| | ||
19 | (u8)::clone(&0); | ||
| ^^^^^^^^^^^ help: try: `<(u8)>::clone` | ||
|
||
error: missing angle brackets in associated item path | ||
--> $DIR/bad-assoc-expr.rs:22:5 | ||
| | ||
22 | (u8, u8)::clone(&(0, 0)); | ||
| ^^^^^^^^^^^^^^^ help: try: `<(u8, u8)>::clone` | ||
|
||
error: aborting due to 4 previous errors | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn main() { | ||
match 0u8 { | ||
[u8]::AssocItem => {} | ||
//~^ ERROR missing angle brackets in associated item path | ||
//~| ERROR no associated item named `AssocItem` found for type `[u8]` in the current scope | ||
(u8, u8)::AssocItem => {} | ||
//~^ ERROR missing angle brackets in associated item path | ||
//~| ERROR no associated item named `AssocItem` found for type `(u8, u8)` in the current sco | ||
_::AssocItem => {} | ||
//~^ ERROR missing angle brackets in associated item path | ||
//~| ERROR no associated item named `AssocItem` found for type `_` in the current scope | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
error: missing angle brackets in associated item path | ||
--> $DIR/bad-assoc-pat.rs:13:9 | ||
| | ||
13 | [u8]::AssocItem => {} | ||
| ^^^^^^^^^^^^^^^ help: try: `<[u8]>::AssocItem` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestions are reserved for cases where our level of certainty that they're correct is very high (sometimes going to the length of continuing parsing to verify our theory). Because this error happens at the parser level, we don't know whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, @oli-obk in the recent months moved everything containing code snippets to
The primary message already says roughly this, so I avoided repeating it in the label (I also like really short labels in general). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm working on suggestion levels. Just make everything a suggestion and let me worry about the probablitity of it being correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oli-obk I've been thinking about making the error more structured, basically having a struct for each possible error the compiler generates, that way we can start playing with having the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making the errors more explicit is definitely a good idea. Currently analysis code and error reporting is quite mangled. Maybe we can get it separated with this method. The most important thing is that the diagnostics API stays as usable as it is now. Making it more complex will only unnecessarily hold up regular development There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oli-obk I definitely agree. The only thing that worries me is decoupling the place where the error is emitted and where it is "defined" in different files might lead to harder maintenance, but the way I'm thinking about it it should still allow the current ad-hoc |
||
|
||
error: missing angle brackets in associated item path | ||
--> $DIR/bad-assoc-pat.rs:16:9 | ||
| | ||
16 | (u8, u8)::AssocItem => {} | ||
| ^^^^^^^^^^^^^^^^^^^ help: try: `<(u8, u8)>::AssocItem` | ||
|
||
error: missing angle brackets in associated item path | ||
--> $DIR/bad-assoc-pat.rs:19:9 | ||
| | ||
19 | _::AssocItem => {} | ||
| ^^^^^^^^^^^^ help: try: `<_>::AssocItem` | ||
|
||
error[E0599]: no associated item named `AssocItem` found for type `[u8]` in the current scope | ||
--> $DIR/bad-assoc-pat.rs:13:9 | ||
| | ||
13 | [u8]::AssocItem => {} | ||
| ^^^^^^^^^^^^^^^ associated item not found in `[u8]` | ||
|
||
error[E0599]: no associated item named `AssocItem` found for type `(u8, u8)` in the current scope | ||
--> $DIR/bad-assoc-pat.rs:16:9 | ||
| | ||
16 | (u8, u8)::AssocItem => {} | ||
| ^^^^^^^^^^^^^^^^^^^ associated item not found in `(u8, u8)` | ||
|
||
error[E0599]: no associated item named `AssocItem` found for type `_` in the current scope | ||
--> $DIR/bad-assoc-pat.rs:19:9 | ||
| | ||
19 | _::AssocItem => {} | ||
| ^^^^^^^^^^^^ associated item not found in `_` | ||
|
||
error: aborting due to 6 previous errors | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is customary to have the consts at the beginning of an impl, but don't bother to change it here, this is short enough to not make a difference :)