@@ -57,6 +57,7 @@ use tokenstream::{self, Delimited, ThinTokenStream, TokenTree, TokenStream};
57
57
use symbol:: { Symbol , keywords} ;
58
58
use util:: ThinVec ;
59
59
60
+ use std:: borrow:: Cow ;
60
61
use std:: cmp;
61
62
use std:: mem;
62
63
use std:: path:: { self , Path , PathBuf } ;
@@ -228,7 +229,7 @@ pub struct Parser<'a> {
228
229
prev_token_kind : PrevTokenKind ,
229
230
pub restrictions : Restrictions ,
230
231
/// Used to determine the path to externally loaded source files
231
- pub directory : Directory ,
232
+ pub directory : Directory < ' a > ,
232
233
/// Whether to parse sub-modules in other files.
233
234
pub recurse_into_file_modules : bool ,
234
235
/// Name of the root module this parser originated from. If `None`, then the
@@ -535,7 +536,7 @@ enum TokenExpectType {
535
536
impl < ' a > Parser < ' a > {
536
537
pub fn new ( sess : & ' a ParseSess ,
537
538
tokens : TokenStream ,
538
- directory : Option < Directory > ,
539
+ directory : Option < Directory < ' a > > ,
539
540
recurse_into_file_modules : bool ,
540
541
desugar_doc_comments : bool )
541
542
-> Self {
@@ -549,7 +550,7 @@ impl<'a> Parser<'a> {
549
550
restrictions : Restrictions :: empty ( ) ,
550
551
recurse_into_file_modules,
551
552
directory : Directory {
552
- path : PathBuf :: new ( ) ,
553
+ path : Cow :: from ( PathBuf :: new ( ) ) ,
553
554
ownership : DirectoryOwnership :: Owned { relative : None }
554
555
} ,
555
556
root_module_name : None ,
@@ -572,9 +573,9 @@ impl<'a> Parser<'a> {
572
573
if let Some ( directory) = directory {
573
574
parser. directory = directory;
574
575
} else if !parser. span . source_equal ( & DUMMY_SP ) {
575
- if let FileName :: Real ( path) = sess. codemap ( ) . span_to_unmapped_path ( parser. span ) {
576
- parser . directory . path = path ;
577
- parser. directory . path . pop ( ) ;
576
+ if let FileName :: Real ( mut path) = sess. codemap ( ) . span_to_unmapped_path ( parser. span ) {
577
+ path. pop ( ) ;
578
+ parser. directory . path = Cow :: from ( path ) ;
578
579
}
579
580
}
580
581
@@ -6000,10 +6001,10 @@ impl<'a> Parser<'a> {
6000
6001
6001
6002
fn push_directory ( & mut self , id : Ident , attrs : & [ Attribute ] ) {
6002
6003
if let Some ( path) = attr:: first_attr_value_str_by_name ( attrs, "path" ) {
6003
- self . directory . path . push ( & path. as_str ( ) ) ;
6004
+ self . directory . path . to_mut ( ) . push ( & path. as_str ( ) ) ;
6004
6005
self . directory . ownership = DirectoryOwnership :: Owned { relative : None } ;
6005
6006
} else {
6006
- self . directory . path . push ( & id. name . as_str ( ) ) ;
6007
+ self . directory . path . to_mut ( ) . push ( & id. name . as_str ( ) ) ;
6007
6008
}
6008
6009
}
6009
6010
0 commit comments