Skip to content

Commit 18ddb41

Browse files
authored
Rollup merge of #100167 - chenyukang:require-suggestion, r=estebank
Recover `require`, `include` instead of `use` in item Fix #100140
2 parents eabf1a2 + 2b15fc6 commit 18ddb41

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

compiler/rustc_parse/src/parser/item.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ impl<'a> Parser<'a> {
271271
// MACRO_RULES ITEM
272272
self.parse_item_macro_rules(vis, has_bang)?
273273
} else if self.isnt_macro_invocation()
274-
&& (self.token.is_ident_named(sym::import) || self.token.is_ident_named(sym::using))
274+
&& (self.token.is_ident_named(sym::import)
275+
|| self.token.is_ident_named(sym::using)
276+
|| self.token.is_ident_named(sym::include)
277+
|| self.token.is_ident_named(sym::require))
275278
{
276279
return self.recover_import_as_use();
277280
} else if self.isnt_macro_invocation() && vis.kind.is_pub() {

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,7 @@ symbols! {
11701170
repr_packed,
11711171
repr_simd,
11721172
repr_transparent,
1173+
require,
11731174
residual,
11741175
result,
11751176
rhs,

src/test/ui/did_you_mean/use_instead_of_import.fixed

+8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ use std::{
66
rc::Rc,
77
};
88

9+
use std::time::Duration;
10+
//~^ ERROR expected item, found `require`
11+
12+
use std::time::Instant;
13+
//~^ ERROR expected item, found `include`
14+
915
pub use std::io;
1016
//~^ ERROR expected item, found `using`
1117

1218
fn main() {
1319
let x = Rc::new(1);
1420
let _ = write!(io::stdout(), "{:?}", x);
21+
let _ = Duration::new(5, 0);
22+
let _ = Instant::now();
1523
}

src/test/ui/did_you_mean/use_instead_of_import.rs

+8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ import std::{
66
rc::Rc,
77
};
88

9+
require std::time::Duration;
10+
//~^ ERROR expected item, found `require`
11+
12+
include std::time::Instant;
13+
//~^ ERROR expected item, found `include`
14+
915
pub using std::io;
1016
//~^ ERROR expected item, found `using`
1117

1218
fn main() {
1319
let x = Rc::new(1);
1420
let _ = write!(io::stdout(), "{:?}", x);
21+
let _ = Duration::new(5, 0);
22+
let _ = Instant::now();
1523
}

src/test/ui/did_you_mean/use_instead_of_import.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ error: expected item, found `import`
44
LL | import std::{
55
| ^^^^^^ help: items are imported using the `use` keyword
66

7+
error: expected item, found `require`
8+
--> $DIR/use_instead_of_import.rs:9:1
9+
|
10+
LL | require std::time::Duration;
11+
| ^^^^^^^ help: items are imported using the `use` keyword
12+
13+
error: expected item, found `include`
14+
--> $DIR/use_instead_of_import.rs:12:1
15+
|
16+
LL | include std::time::Instant;
17+
| ^^^^^^^ help: items are imported using the `use` keyword
18+
719
error: expected item, found `using`
8-
--> $DIR/use_instead_of_import.rs:9:5
20+
--> $DIR/use_instead_of_import.rs:15:5
921
|
1022
LL | pub using std::io;
1123
| ^^^^^ help: items are imported using the `use` keyword
1224

13-
error: aborting due to 2 previous errors
25+
error: aborting due to 4 previous errors
1426

0 commit comments

Comments
 (0)