Rollup merge of #100167 - chenyukang:require-suggestion, r=estebank

Recover `require`, `include` instead of `use` in item

Fix #100140
This commit is contained in:
Matthias Krüger 2022-08-06 16:15:59 +02:00 committed by GitHub
commit 18ddb41184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 3 deletions

View File

@ -271,7 +271,10 @@ impl<'a> Parser<'a> {
// MACRO_RULES ITEM
self.parse_item_macro_rules(vis, has_bang)?
} else if self.isnt_macro_invocation()
&& (self.token.is_ident_named(sym::import) || self.token.is_ident_named(sym::using))
&& (self.token.is_ident_named(sym::import)
|| self.token.is_ident_named(sym::using)
|| self.token.is_ident_named(sym::include)
|| self.token.is_ident_named(sym::require))
{
return self.recover_import_as_use();
} else if self.isnt_macro_invocation() && vis.kind.is_pub() {

View File

@ -1170,6 +1170,7 @@ symbols! {
repr_packed,
repr_simd,
repr_transparent,
require,
residual,
result,
rhs,

View File

@ -6,10 +6,18 @@ use std::{
rc::Rc,
};
use std::time::Duration;
//~^ ERROR expected item, found `require`
use std::time::Instant;
//~^ ERROR expected item, found `include`
pub use std::io;
//~^ ERROR expected item, found `using`
fn main() {
let x = Rc::new(1);
let _ = write!(io::stdout(), "{:?}", x);
let _ = Duration::new(5, 0);
let _ = Instant::now();
}

View File

@ -6,10 +6,18 @@ import std::{
rc::Rc,
};
require std::time::Duration;
//~^ ERROR expected item, found `require`
include std::time::Instant;
//~^ ERROR expected item, found `include`
pub using std::io;
//~^ ERROR expected item, found `using`
fn main() {
let x = Rc::new(1);
let _ = write!(io::stdout(), "{:?}", x);
let _ = Duration::new(5, 0);
let _ = Instant::now();
}

View File

@ -4,11 +4,23 @@ error: expected item, found `import`
LL | import std::{
| ^^^^^^ help: items are imported using the `use` keyword
error: expected item, found `require`
--> $DIR/use_instead_of_import.rs:9:1
|
LL | require std::time::Duration;
| ^^^^^^^ help: items are imported using the `use` keyword
error: expected item, found `include`
--> $DIR/use_instead_of_import.rs:12:1
|
LL | include std::time::Instant;
| ^^^^^^^ help: items are imported using the `use` keyword
error: expected item, found `using`
--> $DIR/use_instead_of_import.rs:9:5
--> $DIR/use_instead_of_import.rs:15:5
|
LL | pub using std::io;
| ^^^^^ help: items are imported using the `use` keyword
error: aborting due to 2 previous errors
error: aborting due to 4 previous errors