Skip to content

Commit

Permalink
recover require,include instead of use in item
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Aug 5, 2022
1 parent 2da8820 commit 2b15fc6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
5 changes: 4 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,7 @@ symbols! {
repr_packed,
repr_simd,
repr_transparent,
require,
residual,
result,
rhs,
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/did_you_mean/use_instead_of_import.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
8 changes: 8 additions & 0 deletions src/test/ui/did_you_mean/use_instead_of_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
16 changes: 14 additions & 2 deletions src/test/ui/did_you_mean/use_instead_of_import.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2b15fc6

Please sign in to comment.