@@ -3,7 +3,7 @@ use rustc_ast::ptr::P;
3
3
use rustc_expand:: base:: { ExtCtxt , ResolverExpand } ;
4
4
use rustc_expand:: expand:: ExpansionConfig ;
5
5
use rustc_session:: Session ;
6
- use rustc_span:: edition:: Edition ;
6
+ use rustc_span:: edition:: Edition :: * ;
7
7
use rustc_span:: hygiene:: AstPass ;
8
8
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
9
9
use rustc_span:: DUMMY_SP ;
@@ -14,7 +14,7 @@ pub fn inject(
14
14
sess : & Session ,
15
15
alt_std_name : Option < Symbol > ,
16
16
) -> ast:: Crate {
17
- let rust_2018 = sess. parse_sess . edition >= Edition :: Edition2018 ;
17
+ let edition = sess. parse_sess . edition ;
18
18
19
19
// the first name in this list is the crate name of the crate with the prelude
20
20
let names: & [ Symbol ] = if sess. contains_name ( & krate. attrs , sym:: no_core) {
@@ -43,7 +43,11 @@ pub fn inject(
43
43
44
44
// .rev() to preserve ordering above in combination with insert(0, ...)
45
45
for & name in names. iter ( ) . rev ( ) {
46
- let ident = if rust_2018 { Ident :: new ( name, span) } else { Ident :: new ( name, call_site) } ;
46
+ let ident = if edition >= Edition2018 {
47
+ Ident :: new ( name, span)
48
+ } else {
49
+ Ident :: new ( name, call_site)
50
+ } ;
47
51
krate. items . insert (
48
52
0 ,
49
53
cx. item (
@@ -59,14 +63,18 @@ pub fn inject(
59
63
// the one with the prelude.
60
64
let name = names[ 0 ] ;
61
65
62
- let import_path = if rust_2018 {
63
- [ name, sym:: prelude, sym:: v1] . iter ( ) . map ( |symbol| Ident :: new ( * symbol, span) ) . collect ( )
64
- } else {
65
- [ kw:: PathRoot , name, sym:: prelude, sym:: v1]
66
- . iter ( )
67
- . map ( |symbol| Ident :: new ( * symbol, span) )
68
- . collect ( )
69
- } ;
66
+ let root = ( edition == Edition2015 ) . then ( || kw:: PathRoot ) ;
67
+
68
+ let import_path = root
69
+ . iter ( )
70
+ . chain ( & [ name, sym:: prelude] )
71
+ . chain ( & [ match edition {
72
+ Edition2015 => sym:: rust_2015,
73
+ Edition2018 => sym:: rust_2018,
74
+ Edition2021 => sym:: rust_2021,
75
+ } ] )
76
+ . map ( |& symbol| Ident :: new ( symbol, span) )
77
+ . collect ( ) ;
70
78
71
79
let use_item = cx. item (
72
80
span,
0 commit comments