mirror of
				https://github.com/rust-lang/rust.git
				synced 2025-11-03 22:49:17 +00:00 
			
		
		
		
	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 #125997
		
	
			
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
//@ run-rustfix
 | 
						|
 | 
						|
#![allow(unused_imports)]
 | 
						|
#![allow(dead_code)]
 | 
						|
 | 
						|
use std::fs::File;
 | 
						|
use std::io::prelude::*;
 | 
						|
 | 
						|
fn test1() {
 | 
						|
    let mut _file = File::create("foo.txt")?;
 | 
						|
    //~^ ERROR the `?` operator can only be used in a function
 | 
						|
}
 | 
						|
 | 
						|
fn test2() {
 | 
						|
    let mut _file = File::create("foo.txt")?;
 | 
						|
    //~^ ERROR the `?` operator can only be used in a function
 | 
						|
    println!();
 | 
						|
}
 | 
						|
 | 
						|
macro_rules! mac {
 | 
						|
    () => {
 | 
						|
        fn test3() {
 | 
						|
            let mut _file = File::create("foo.txt")?;
 | 
						|
            //~^ ERROR the `?` operator can only be used in a function
 | 
						|
            println!();
 | 
						|
        }
 | 
						|
    };
 | 
						|
}
 | 
						|
 | 
						|
struct A;
 | 
						|
 | 
						|
impl A {
 | 
						|
    fn test4(&self) {
 | 
						|
        let mut _file = File::create("foo.txt")?;
 | 
						|
        //~^ ERROR the `?` operator can only be used in a method
 | 
						|
    }
 | 
						|
 | 
						|
    fn test5(&self) {
 | 
						|
        let mut _file = File::create("foo.txt")?;
 | 
						|
        //~^ ERROR the `?` operator can only be used in a method
 | 
						|
        println!();
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
fn main() {
 | 
						|
    let mut _file = File::create("foo.txt")?;
 | 
						|
    //~^ ERROR the `?` operator can only be used in a function
 | 
						|
    mac!();
 | 
						|
}
 |