From fbd1750652864ec921577df8013e95dec54c6f20 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 23 May 2018 16:19:20 +0200 Subject: [PATCH] Remove the now redundant CodeMap::new_filemap_with_lines() method. --- src/libsyntax/codemap.rs | 14 +++----------- src/libsyntax/ext/expand.rs | 6 ++++-- src/libsyntax/ext/source_util.rs | 8 +++++--- src/libsyntax/test_snippet.rs | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 18594c25d071f..db669f9119b15 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -211,8 +211,7 @@ impl CodeMap { } } - /// Creates a new filemap without setting its line information. If you don't - /// intend to set the line information yourself, you should use new_filemap_and_lines. + /// Creates a new filemap. /// This does not ensure that only one FileMap exists per file name. pub fn new_filemap(&self, filename: FileName, src: String) -> Lrc { let start_pos = self.next_start_pos(); @@ -247,13 +246,6 @@ impl CodeMap { filemap } - /// Creates a new filemap and sets its line information. - /// This does not ensure that only one FileMap exists per file name. - pub fn new_filemap_and_lines(&self, filename: &Path, src: &str) -> Lrc { - self.new_filemap(filename.to_owned().into(), src.to_owned()) - } - - /// Allocates a new FileMap representing a source file from an external /// crate. The source code of such an "imported filemap" is not available, /// but we still know enough to generate accurate debuginfo location @@ -1116,7 +1108,7 @@ mod tests { let cm = CodeMap::new(FilePathMapping::empty()); let inputtext = "aaaaa\nbbbbBB\nCCC\nDDDDDddddd\neee\n"; let selection = " \n ~~\n~~~\n~~~~~ \n \n"; - cm.new_filemap_and_lines(Path::new("blork.rs"), inputtext); + cm.new_filemap(Path::new("blork.rs").to_owned().into(), inputtext.to_string()); let span = span_from_selection(inputtext, selection); // check that we are extracting the text we thought we were extracting @@ -1159,7 +1151,7 @@ mod tests { let inputtext = "bbbb BB\ncc CCC\n"; let selection1 = " ~~\n \n"; let selection2 = " \n ~~~\n"; - cm.new_filemap_and_lines(Path::new("blork.rs"), inputtext); + cm.new_filemap(Path::new("blork.rs").to_owned().into(), inputtext.to_owned()); let span1 = span_from_selection(inputtext, selection1); let span2 = span_from_selection(inputtext, selection2); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 146db632c07ba..6cff17dba01d9 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1451,9 +1451,11 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { match String::from_utf8(buf) { Ok(src) => { + let src_interned = Symbol::intern(&src); + // Add this input file to the code map to make it available as // dependency information - self.cx.codemap().new_filemap_and_lines(&filename, &src); + self.cx.codemap().new_filemap(filename.into(), src); let include_info = vec![ dummy_spanned(ast::NestedMetaItemKind::MetaItem( @@ -1461,7 +1463,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { dummy_spanned(file)))), dummy_spanned(ast::NestedMetaItemKind::MetaItem( attr::mk_name_value_item_str(Ident::from_str("contents"), - dummy_spanned(Symbol::intern(&src))))), + dummy_spanned(src_interned)))), ]; let include_ident = Ident::from_str("include"); diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index d6dce63ea5e4b..669536f519ce3 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -150,11 +150,13 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenT }; match String::from_utf8(bytes) { Ok(src) => { + let interned_src = Symbol::intern(&src); + // Add this input file to the code map to make it available as // dependency information - cx.codemap().new_filemap_and_lines(&file, &src); + cx.codemap().new_filemap(file.into(), src); - base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&src))) + base::MacEager::expr(cx.expr_str(sp, interned_src)) } Err(_) => { cx.span_err(sp, @@ -182,7 +184,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke Ok(..) => { // Add this input file to the code map to make it available as // dependency information, but don't enter it's contents - cx.codemap().new_filemap_and_lines(&file, ""); + cx.codemap().new_filemap(file.into(), "".to_string()); base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))) } diff --git a/src/libsyntax/test_snippet.rs b/src/libsyntax/test_snippet.rs index 81dcc1998edd1..c7e4fbd1073d7 100644 --- a/src/libsyntax/test_snippet.rs +++ b/src/libsyntax/test_snippet.rs @@ -51,7 +51,7 @@ fn test_harness(file_text: &str, span_labels: Vec, expected_output: & let output = Arc::new(Mutex::new(Vec::new())); let code_map = Lrc::new(CodeMap::new(FilePathMapping::empty())); - code_map.new_filemap_and_lines(Path::new("test.rs"), &file_text); + code_map.new_filemap(Path::new("test.rs").to_owned().into(), file_text.to_owned()); let primary_span = make_span(&file_text, &span_labels[0].start, &span_labels[0].end); let mut msp = MultiSpan::from_span(primary_span);