8750e24247
According to comments: https://github.com/rust-lang/rust/pull/128084#issuecomment-2295254576 https://github.com/rust-lang/rust/pull/126187/files#r1634897691
56 lines
1.4 KiB
Rust
56 lines
1.4 KiB
Rust
//@ 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!();
|
|
Ok(())
|
|
}
|
|
};
|
|
}
|
|
|
|
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
|
|
Ok(())
|
|
}
|
|
|
|
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!();
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
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(())
|
|
}
|