2024-06-09 04:20:25 -05:00
|
|
|
//@ run-rustfix
|
|
|
|
|
|
|
|
#![allow(unused_imports)]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::prelude::*;
|
|
|
|
|
|
|
|
fn test1() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let mut _file = File::create("foo.txt")?;
|
|
|
|
//~^ ERROR the `?` operator can only be used in a function
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test2() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let mut _file = File::create("foo.txt")?;
|
|
|
|
//~^ ERROR the `?` operator can only be used in a function
|
|
|
|
println!();
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! mac {
|
|
|
|
() => {
|
|
|
|
fn test3() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let mut _file = File::create("foo.txt")?;
|
|
|
|
//~^ ERROR the `?` operator can only be used in a function
|
|
|
|
println!();
|
2024-08-22 04:41:15 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
2024-06-09 04:20:25 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-07-22 21:24:45 -05:00
|
|
|
struct A;
|
|
|
|
|
|
|
|
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
|
2024-08-22 04:41:15 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
2024-07-22 21:24:45 -05:00
|
|
|
|
|
|
|
fn test5(&self) -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let mut _file = File::create("foo.txt")?;
|
|
|
|
//~^ ERROR the `?` operator can only be used in a method
|
|
|
|
println!();
|
2024-08-22 04:41:15 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
2024-07-22 21:24:45 -05:00
|
|
|
}
|
|
|
|
|
2024-06-09 04:20:25 -05:00
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let mut _file = File::create("foo.txt")?;
|
|
|
|
//~^ ERROR the `?` operator can only be used in a function
|
|
|
|
mac!();
|
|
|
|
Ok(())
|
|
|
|
}
|