Skip to content

Commit f840a95

Browse files
committed
Remove the Cow from Directory.
The previous commit wrapped `Parser` within a `Cow` for the hot macro parsing path. As a result, there's no need for the `Cow` within `Directory`, because it lies within `Parser`.
1 parent 6bf2cc2 commit f840a95

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

Diff for: src/librustc_expand/mbe/macro_rules.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ fn generic_extension<'cx>(
260260
}
261261

262262
let directory = Directory {
263-
path: Cow::from(cx.current_expansion.module.directory.as_path()),
263+
path: cx.current_expansion.module.directory.clone(),
264264
ownership: cx.current_expansion.directory_ownership,
265265
};
266266
let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), true, false, None);
@@ -1218,7 +1218,7 @@ fn base_parser_from_cx<'cx>(
12181218
tts: TokenStream,
12191219
) -> Parser<'cx> {
12201220
let directory = Directory {
1221-
path: Cow::from(current_expansion.module.directory.as_path()),
1221+
path: current_expansion.module.directory.clone(),
12221222
ownership: current_expansion.directory_ownership,
12231223
};
12241224
Parser::new(sess, tts, Some(directory), true, true, rustc_parse::MACRO_ARGUMENTS)

Diff for: src/librustc_parse/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use syntax::ast;
1212
use syntax::token::{self, Nonterminal};
1313
use syntax::tokenstream::{self, TokenStream, TokenTree};
1414

15-
use std::borrow::Cow;
16-
use std::path::Path;
15+
use std::path::{Path, PathBuf};
1716
use std::str;
1817

1918
use log::info;
@@ -29,8 +28,8 @@ pub mod validate_attr;
2928
pub mod config;
3029

3130
#[derive(Clone)]
32-
pub struct Directory<'a> {
33-
pub path: Cow<'a, Path>,
31+
pub struct Directory {
32+
pub path: PathBuf,
3433
pub ownership: DirectoryOwnership,
3534
}
3635

@@ -274,7 +273,7 @@ pub fn stream_to_parser<'a>(
274273
pub fn stream_to_parser_with_base_dir<'a>(
275274
sess: &'a ParseSess,
276275
stream: TokenStream,
277-
base_dir: Directory<'a>,
276+
base_dir: Directory,
278277
) -> Parser<'a> {
279278
Parser::new(sess, stream, Some(base_dir), true, false, None)
280279
}

Diff for: src/librustc_parse/parser/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use syntax::token::{self, DelimToken, Token, TokenKind};
2929
use syntax::tokenstream::{self, DelimSpan, TokenStream, TokenTree, TreeAndJoint};
3030
use syntax::util::comments::{doc_comment_style, strip_doc_comment_decoration};
3131

32-
use std::borrow::Cow;
3332
use std::path::PathBuf;
3433
use std::{cmp, mem, slice};
3534

@@ -114,7 +113,7 @@ pub struct Parser<'a> {
114113
prev_token_kind: PrevTokenKind,
115114
restrictions: Restrictions,
116115
/// Used to determine the path to externally loaded source files.
117-
pub(super) directory: Directory<'a>,
116+
pub(super) directory: Directory,
118117
/// `true` to parse sub-modules in other files.
119118
// Public for rustfmt usage.
120119
pub recurse_into_file_modules: bool,
@@ -376,7 +375,7 @@ impl<'a> Parser<'a> {
376375
pub fn new(
377376
sess: &'a ParseSess,
378377
tokens: TokenStream,
379-
directory: Option<Directory<'a>>,
378+
directory: Option<Directory>,
380379
recurse_into_file_modules: bool,
381380
desugar_doc_comments: bool,
382381
subparser_name: Option<&'static str>,
@@ -390,7 +389,7 @@ impl<'a> Parser<'a> {
390389
restrictions: Restrictions::empty(),
391390
recurse_into_file_modules,
392391
directory: Directory {
393-
path: Cow::from(PathBuf::new()),
392+
path: PathBuf::new(),
394393
ownership: DirectoryOwnership::Owned { relative: None },
395394
},
396395
root_module_name: None,
@@ -418,7 +417,7 @@ impl<'a> Parser<'a> {
418417
&sess.source_map().lookup_char_pos(parser.token.span.lo()).file.unmapped_path
419418
{
420419
if let Some(directory_path) = path.parent() {
421-
parser.directory.path = Cow::from(directory_path.to_path_buf());
420+
parser.directory.path = directory_path.to_path_buf();
422421
}
423422
}
424423
}

Diff for: src/librustc_parse/parser/module.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<'a> Parser<'a> {
285285

286286
fn push_directory(&mut self, id: Ident, attrs: &[Attribute]) {
287287
if let Some(path) = attr::first_attr_value_str_by_name(attrs, sym::path) {
288-
self.directory.path.to_mut().push(&*path.as_str());
288+
self.directory.path.push(&*path.as_str());
289289
self.directory.ownership = DirectoryOwnership::Owned { relative: None };
290290
} else {
291291
// We have to push on the current module name in the case of relative
@@ -297,10 +297,10 @@ impl<'a> Parser<'a> {
297297
if let DirectoryOwnership::Owned { relative } = &mut self.directory.ownership {
298298
if let Some(ident) = relative.take() {
299299
// remove the relative offset
300-
self.directory.path.to_mut().push(&*ident.as_str());
300+
self.directory.path.push(&*ident.as_str());
301301
}
302302
}
303-
self.directory.path.to_mut().push(&*id.as_str());
303+
self.directory.path.push(&*id.as_str());
304304
}
305305
}
306306
}

0 commit comments

Comments
 (0)