-
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
Suggest changing main
s return type on E0277 (?
/ from_residual
)
#125997
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
epage
added
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Jun 4, 2024
camelid
added
the
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
label
Jun 4, 2024
@rustbot claim |
surechen
added a commit
to surechen/rust
that referenced
this issue
Jun 9, 2024
…g QuesionMark `?` in the body. fixes rust-lang#125997
workingjubilee
added a commit
to workingjubilee/rustc
that referenced
this issue
Jun 12, 2024
For E0277 suggest adding `Result` return type for function when using QuestionMark `?` in the body. Adding suggestions for following function in E0277. ```rust fn main() { let mut _file = File::create("foo.txt")?; } ``` to ```rust fn main() -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; return Ok(()); } ``` According to the issue rust-lang#125997, only the code examples in the issue are targeted, but the issue covers a wider range of situations. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> -->
workingjubilee
added a commit
to workingjubilee/rustc
that referenced
this issue
Jun 12, 2024
For E0277 suggest adding `Result` return type for function when using QuestionMark `?` in the body. Adding suggestions for following function in E0277. ```rust fn main() { let mut _file = File::create("foo.txt")?; } ``` to ```rust fn main() -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; return Ok(()); } ``` According to the issue rust-lang#125997, only the code examples in the issue are targeted, but the issue covers a wider range of situations. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> -->
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Jun 12, 2024
Rollup merge of rust-lang#126187 - surechen:fix_125997, r=oli-obk For E0277 suggest adding `Result` return type for function when using QuestionMark `?` in the body. Adding suggestions for following function in E0277. ```rust fn main() { let mut _file = File::create("foo.txt")?; } ``` to ```rust fn main() -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; return Ok(()); } ``` According to the issue rust-lang#125997, only the code examples in the issue are targeted, but the issue covers a wider range of situations. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> -->
surechen
added a commit
to surechen/rust
that referenced
this issue
Jul 23, 2024
For following: ```rust struct A; impl A { fn test4(&self) { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method } ``` Suggest: ```rust impl A { fn test4(&self) -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method Ok(()) } } ``` For rust-lang#125997
jieyouxu
added a commit
to jieyouxu/rust
that referenced
this issue
Aug 18, 2024
Suggest adding Result return type for associated method in E0277. Recommit rust-lang#126515 because I messed up during rebase, Suggest adding Result return type for associated method in E0277. For following: ```rust struct A; impl A { fn test4(&self) { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method } ``` Suggest: ```rust impl A { fn test4(&self) -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method Ok(()) } } ``` For rust-lang#125997 r? `@cjgillot`
jieyouxu
added a commit
to jieyouxu/rust
that referenced
this issue
Aug 18, 2024
Suggest adding Result return type for associated method in E0277. Recommit rust-lang#126515 because I messed up during rebase, Suggest adding Result return type for associated method in E0277. For following: ```rust struct A; impl A { fn test4(&self) { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method } ``` Suggest: ```rust impl A { fn test4(&self) -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method Ok(()) } } ``` For rust-lang#125997 r? ``@cjgillot``
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Aug 18, 2024
Suggest adding Result return type for associated method in E0277. Recommit rust-lang#126515 because I messed up during rebase, Suggest adding Result return type for associated method in E0277. For following: ```rust struct A; impl A { fn test4(&self) { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method } ``` Suggest: ```rust impl A { fn test4(&self) -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method Ok(()) } } ``` For rust-lang#125997 r? ```@cjgillot```
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Aug 18, 2024
Suggest adding Result return type for associated method in E0277. Recommit rust-lang#126515 because I messed up during rebase, Suggest adding Result return type for associated method in E0277. For following: ```rust struct A; impl A { fn test4(&self) { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method } ``` Suggest: ```rust impl A { fn test4(&self) -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method Ok(()) } } ``` For rust-lang#125997 r? ````@cjgillot````
tgross35
added a commit
to tgross35/rust
that referenced
this issue
Aug 19, 2024
Suggest adding Result return type for associated method in E0277. Recommit rust-lang#126515 because I messed up during rebase, Suggest adding Result return type for associated method in E0277. For following: ```rust struct A; impl A { fn test4(&self) { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method } ``` Suggest: ```rust impl A { fn test4(&self) -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method Ok(()) } } ``` For rust-lang#125997 r? `@cjgillot`
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Aug 19, 2024
Rollup merge of rust-lang#128084 - surechen:fix_125997_v1, r=cjgillot Suggest adding Result return type for associated method in E0277. Recommit rust-lang#126515 because I messed up during rebase, Suggest adding Result return type for associated method in E0277. For following: ```rust struct A; impl A { fn test4(&self) { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method } ``` Suggest: ```rust impl A { fn test4(&self) -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method Ok(()) } } ``` For rust-lang#125997 r? `@cjgillot`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
To suggest changing
to
Rationale and extra context
In rust-lang/cargo#14007, concern was raised over people generating a trivial
fn main() {}
withcargo new
and copy/pasting example code that uses?
(which is encouraged in API guidelines). Regardless of the decision made forcargo new
, this applies just as well to users hand writing a trivialfn main() {}
. These are likely new users who would be intimidated by the current message and wouldn't know what next steps to takeOther cases
No response
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: