Skip to content

Commit 0d4ebe1

Browse files
committed
Move sess function and use it more.
1 parent 3996447 commit 0d4ebe1

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

compiler/rustc_expand/src/parse/tests.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::tests::{
2-
matches_codepattern, string_to_stream, with_error_checking_parse, with_expected_parse_error,
2+
matches_codepattern, sess, string_to_stream, with_error_checking_parse,
3+
with_expected_parse_error,
34
};
45

56
use ast::token::IdentIsRaw;
@@ -16,13 +17,8 @@ use rustc_session::parse::ParseSess;
1617
use rustc_span::create_default_session_globals_then;
1718
use rustc_span::symbol::{kw, sym, Symbol};
1819
use rustc_span::{BytePos, FileName, Pos, Span};
19-
2020
use std::path::PathBuf;
2121

22-
fn sess() -> ParseSess {
23-
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE])
24-
}
25-
2622
/// Parses an item.
2723
///
2824
/// Returns `Ok(Some(item))` when successful, `Ok(None)` when no item was found, and `Err`

compiler/rustc_expand/src/tests.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ use std::path::{Path, PathBuf};
1818
use std::str;
1919
use std::sync::{Arc, Mutex};
2020

21+
pub(crate) fn sess() -> ParseSess {
22+
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE])
23+
}
24+
2125
/// Map string to parser (via tts).
2226
fn string_to_parser(ps: &ParseSess, source_str: String) -> Parser<'_> {
2327
new_parser_from_source_str(ps, PathBuf::from("bogofile").into(), source_str)
@@ -72,8 +76,7 @@ where
7276

7377
/// Maps a string to tts, using a made-up filename.
7478
pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
75-
let ps =
76-
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE]);
79+
let ps = sess();
7780
source_file_to_stream(
7881
&ps,
7982
ps.source_map().new_source_file(PathBuf::from("bogofile").into(), source_str),
@@ -83,8 +86,7 @@ pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
8386

8487
/// Parses a string, returns a crate.
8588
pub(crate) fn string_to_crate(source_str: String) -> ast::Crate {
86-
let ps =
87-
ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE]);
89+
let ps = sess();
8890
with_error_checking_parse(source_str, &ps, |p| p.parse_crate_mod())
8991
}
9092

0 commit comments

Comments
 (0)