@@ -3,7 +3,7 @@ use rustc_ast::ptr::P;
33use rustc_expand:: base:: { ExtCtxt , ResolverExpand } ;
44use rustc_expand:: expand:: ExpansionConfig ;
55use rustc_session:: Session ;
6- use rustc_span:: edition:: Edition ;
6+ use rustc_span:: edition:: Edition :: * ;
77use rustc_span:: hygiene:: AstPass ;
88use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
99use rustc_span:: DUMMY_SP ;
@@ -14,7 +14,7 @@ pub fn inject(
1414 sess : & Session ,
1515 alt_std_name : Option < Symbol > ,
1616) -> ast:: Crate {
17- let rust_2018 = sess. parse_sess . edition >= Edition :: Edition2018 ;
17+ let edition = sess. parse_sess . edition ;
1818
1919 // the first name in this list is the crate name of the crate with the prelude
2020 let names: & [ Symbol ] = if sess. contains_name ( & krate. attrs , sym:: no_core) {
@@ -43,7 +43,11 @@ pub fn inject(
4343
4444 // .rev() to preserve ordering above in combination with insert(0, ...)
4545 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+ } ;
4751 krate. items . insert (
4852 0 ,
4953 cx. item (
@@ -59,14 +63,18 @@ pub fn inject(
5963 // the one with the prelude.
6064 let name = names[ 0 ] ;
6165
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 ( ) ;
7078
7179 let use_item = cx. item (
7280 span,
0 commit comments