Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover require, include instead of use in item #100167

Merged
merged 1 commit into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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