-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Tweak suggestion for this
-> self
#75509
Merged
bors
merged 3 commits into
rust-lang:master
from
estebank:coming-merrily-from-java-land
Aug 15, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
error[E0424]: expected value, found module `self` | ||
--> $DIR/E0424.rs:7:9 | ||
| | ||
LL | / fn foo() { | ||
LL | | self.bar(); | ||
| | ^^^^ `self` value is a keyword only available in methods with a `self` parameter | ||
LL | | } | ||
| |_____- this function doesn't have a `self` parameter | ||
LL | fn foo() { | ||
| --- this function doesn't have a `self` parameter | ||
LL | self.bar(); | ||
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter | ||
| | ||
help: add a `self` receiver parameter to make the associated `fn` a method | ||
| | ||
LL | fn foo(&self) { | ||
| ^^^^^ | ||
|
||
error[E0424]: expected value, found module `self` | ||
--> $DIR/E0424.rs:11:9 | ||
| | ||
LL | fn baz(_: i32) { | ||
| --- this function doesn't have a `self` parameter | ||
LL | self.bar(); | ||
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter | ||
| | ||
help: add a `self` receiver parameter to make the associated `fn` a method | ||
| | ||
LL | fn baz(&self, _: i32) { | ||
| ^^^^^^ | ||
|
||
error[E0424]: expected unit struct, unit variant or constant, found module `self` | ||
--> $DIR/E0424.rs:12:9 | ||
--> $DIR/E0424.rs:16:9 | ||
| | ||
LL | / fn main () { | ||
LL | | let self = "self"; | ||
| | ^^^^ `self` value is a keyword and may not be bound to variables or shadowed | ||
LL | | } | ||
| |_- this function doesn't have a `self` parameter | ||
LL | fn main () { | ||
| ---- this function can't have a `self` parameter | ||
LL | let self = "self"; | ||
| ^^^^ `self` value is a keyword and may not be bound to variables or shadowed | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0424`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
trait B < A > { fn a() -> A { this.a } } //~ ERROR cannot find value `this` in this scope | ||
trait B <A> { | ||
fn a() -> A { | ||
this.a //~ ERROR cannot find value `this` in this scope | ||
} | ||
fn b(x: i32) { | ||
this.b(x); //~ ERROR cannot find value `this` in this scope | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
error[E0425]: cannot find value `this` in this scope | ||
--> $DIR/issue-5099.rs:1:31 | ||
--> $DIR/issue-5099.rs:3:9 | ||
| | ||
LL | trait B < A > { fn a() -> A { this.a } } | ||
| ^^^^ not found in this scope | ||
LL | this.a | ||
| ^^^^ not found in this scope | ||
| | ||
help: you might have meant to use `self` here instead | ||
| | ||
LL | self.a | ||
| ^^^^ | ||
help: if you meant to use `self`, you are also missing a `self` receiver argument | ||
| | ||
LL | fn a(&self) -> A { | ||
| ^^^^^ | ||
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.
^ |
||
|
||
error[E0425]: cannot find value `this` in this scope | ||
--> $DIR/issue-5099.rs:6:9 | ||
| | ||
LL | this.b(x); | ||
| ^^^^ not found in this scope | ||
| | ||
help: you might have meant to use `self` here instead | ||
| | ||
LL | self.b(x); | ||
| ^^^^ | ||
help: if you meant to use `self`, you are also missing a `self` receiver argument | ||
| | ||
LL | fn b(&self, x: i32) { | ||
| ^^^^^^ | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wouldn't this be incorrect for
fn test<const N: [u8; 3 / (7 + 2)]>()
. Not sure how easy this is to fix but it seems like getting an empty span after the opening paren of the argument list might be something we can put into a method after getting it right once.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.
You're correct. This is not the only place where that problem exists though, and wanted to keep this PR small by not threading a
Span
from the AST all the way to resolve for this corner case. It seems to me that the cases where the suggestion is needed are unlikely to be using const generics, but even then they are not yet stable :)I'll follow up in a bigger PR to refactor all the
Span
wrangling cases at a later date, including this one.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.
This won't even be a problem with
min_const_generics
because arrays won't be allowed as const params at the start, so this isn't really a pressing issue, though it is something I should keep in mind before trying to stabilize it 😅