Skip to content

Commit fe55364

Browse files
committed
Auto merge of #145997 - matthiaskrgr:rollup-tsgylre, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #145675 (Rehome 30 `tests/ui/issues/` tests to other subdirectories under `tests/ui/` [#1 of Batch #2]) - #145676 (Rehome 30 `tests/ui/issues/` tests to other subdirectories under `tests/ui/` [#2 of Batch #2]) - #145982 (compiletest: Reduce the number of `println!` calls that don't have access to `TestCx`) - #145984 (`TokenStream` cleanups) r? `@ghost` `@rustbot` modify labels: rollup
2 parents db3fd47 + 197cb26 commit fe55364

File tree

95 files changed

+202
-276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+202
-276
lines changed

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 65 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
//! `TokenStream`s represent syntactic objects before they are converted into ASTs.
44
//! A `TokenStream` is, roughly speaking, a sequence of [`TokenTree`]s,
55
//! which are themselves a single [`Token`] or a `Delimited` subsequence of tokens.
6-
//!
7-
//! ## Ownership
8-
//!
9-
//! `TokenStream`s are persistent data structures constructed as ropes with reference
10-
//! counted-children. In general, this means that calling an operation on a `TokenStream`
11-
//! (such as `slice`) produces an entirely new `TokenStream` from the borrowed reference to
12-
//! the original. This essentially coerces `TokenStream`s into "views" of their subparts,
13-
//! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
14-
//! ownership of the original.
156
167
use std::borrow::Cow;
178
use std::ops::Range;
@@ -99,17 +90,6 @@ impl TokenTree {
9990
}
10091
}
10192

102-
impl<CTX> HashStable<CTX> for TokenStream
103-
where
104-
CTX: crate::HashStableContext,
105-
{
106-
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
107-
for sub_tt in self.iter() {
108-
sub_tt.hash_stable(hcx, hasher);
109-
}
110-
}
111-
}
112-
11393
/// A lazy version of [`AttrTokenStream`], which defers creation of an actual
11494
/// `AttrTokenStream` until it is needed.
11595
#[derive(Clone)]
@@ -556,10 +536,6 @@ pub struct AttrsTarget {
556536
pub tokens: LazyAttrTokenStream,
557537
}
558538

559-
/// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s.
560-
#[derive(Clone, Debug, Default, Encodable, Decodable)]
561-
pub struct TokenStream(pub(crate) Arc<Vec<TokenTree>>);
562-
563539
/// Indicates whether a token can join with the following token to form a
564540
/// compound token. Used for conversions to `proc_macro::Spacing`. Also used to
565541
/// guide pretty-printing, which is where the `JointHidden` value (which isn't
@@ -620,58 +596,9 @@ pub enum Spacing {
620596
JointHidden,
621597
}
622598

623-
impl TokenStream {
624-
/// Given a `TokenStream` with a `Stream` of only two arguments, return a new `TokenStream`
625-
/// separating the two arguments with a comma for diagnostic suggestions.
626-
pub fn add_comma(&self) -> Option<(TokenStream, Span)> {
627-
// Used to suggest if a user writes `foo!(a b);`
628-
let mut suggestion = None;
629-
let mut iter = self.0.iter().enumerate().peekable();
630-
while let Some((pos, ts)) = iter.next() {
631-
if let Some((_, next)) = iter.peek() {
632-
let sp = match (&ts, &next) {
633-
(_, TokenTree::Token(Token { kind: token::Comma, .. }, _)) => continue,
634-
(
635-
TokenTree::Token(token_left, Spacing::Alone),
636-
TokenTree::Token(token_right, _),
637-
) if (token_left.is_non_reserved_ident() || token_left.is_lit())
638-
&& (token_right.is_non_reserved_ident() || token_right.is_lit()) =>
639-
{
640-
token_left.span
641-
}
642-
(TokenTree::Delimited(sp, ..), _) => sp.entire(),
643-
_ => continue,
644-
};
645-
let sp = sp.shrink_to_hi();
646-
let comma = TokenTree::token_alone(token::Comma, sp);
647-
suggestion = Some((pos, comma, sp));
648-
}
649-
}
650-
if let Some((pos, comma, sp)) = suggestion {
651-
let mut new_stream = Vec::with_capacity(self.0.len() + 1);
652-
let parts = self.0.split_at(pos + 1);
653-
new_stream.extend_from_slice(parts.0);
654-
new_stream.push(comma);
655-
new_stream.extend_from_slice(parts.1);
656-
return Some((TokenStream::new(new_stream), sp));
657-
}
658-
None
659-
}
660-
}
661-
662-
impl FromIterator<TokenTree> for TokenStream {
663-
fn from_iter<I: IntoIterator<Item = TokenTree>>(iter: I) -> Self {
664-
TokenStream::new(iter.into_iter().collect::<Vec<TokenTree>>())
665-
}
666-
}
667-
668-
impl Eq for TokenStream {}
669-
670-
impl PartialEq<TokenStream> for TokenStream {
671-
fn eq(&self, other: &TokenStream) -> bool {
672-
self.iter().eq(other.iter())
673-
}
674-
}
599+
/// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s.
600+
#[derive(Clone, Debug, Default, Encodable, Decodable)]
601+
pub struct TokenStream(pub(crate) Arc<Vec<TokenTree>>);
675602

676603
impl TokenStream {
677604
pub fn new(tts: Vec<TokenTree>) -> TokenStream {
@@ -847,6 +774,68 @@ impl TokenStream {
847774
}
848775
}
849776
}
777+
778+
/// Given a `TokenStream` with a `Stream` of only two arguments, return a new `TokenStream`
779+
/// separating the two arguments with a comma for diagnostic suggestions.
780+
pub fn add_comma(&self) -> Option<(TokenStream, Span)> {
781+
// Used to suggest if a user writes `foo!(a b);`
782+
let mut suggestion = None;
783+
let mut iter = self.0.iter().enumerate().peekable();
784+
while let Some((pos, ts)) = iter.next() {
785+
if let Some((_, next)) = iter.peek() {
786+
let sp = match (&ts, &next) {
787+
(_, TokenTree::Token(Token { kind: token::Comma, .. }, _)) => continue,
788+
(
789+
TokenTree::Token(token_left, Spacing::Alone),
790+
TokenTree::Token(token_right, _),
791+
) if (token_left.is_non_reserved_ident() || token_left.is_lit())
792+
&& (token_right.is_non_reserved_ident() || token_right.is_lit()) =>
793+
{
794+
token_left.span
795+
}
796+
(TokenTree::Delimited(sp, ..), _) => sp.entire(),
797+
_ => continue,
798+
};
799+
let sp = sp.shrink_to_hi();
800+
let comma = TokenTree::token_alone(token::Comma, sp);
801+
suggestion = Some((pos, comma, sp));
802+
}
803+
}
804+
if let Some((pos, comma, sp)) = suggestion {
805+
let mut new_stream = Vec::with_capacity(self.0.len() + 1);
806+
let parts = self.0.split_at(pos + 1);
807+
new_stream.extend_from_slice(parts.0);
808+
new_stream.push(comma);
809+
new_stream.extend_from_slice(parts.1);
810+
return Some((TokenStream::new(new_stream), sp));
811+
}
812+
None
813+
}
814+
}
815+
816+
impl PartialEq<TokenStream> for TokenStream {
817+
fn eq(&self, other: &TokenStream) -> bool {
818+
self.iter().eq(other.iter())
819+
}
820+
}
821+
822+
impl Eq for TokenStream {}
823+
824+
impl FromIterator<TokenTree> for TokenStream {
825+
fn from_iter<I: IntoIterator<Item = TokenTree>>(iter: I) -> Self {
826+
TokenStream::new(iter.into_iter().collect::<Vec<TokenTree>>())
827+
}
828+
}
829+
830+
impl<CTX> HashStable<CTX> for TokenStream
831+
where
832+
CTX: crate::HashStableContext,
833+
{
834+
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
835+
for sub_tt in self.iter() {
836+
sub_tt.hash_stable(hcx, hasher);
837+
}
838+
}
850839
}
851840

852841
#[derive(Clone)]

src/tools/compiletest/src/bin/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::env;
22
use std::io::IsTerminal;
33
use std::sync::Arc;
44

5-
use compiletest::{early_config_check, log_config, parse_config, run_tests};
5+
use compiletest::{early_config_check, parse_config, run_tests};
66

77
fn main() {
88
tracing_subscriber::fmt::init();
@@ -19,6 +19,5 @@ fn main() {
1919

2020
early_config_check(&config);
2121

22-
log_config(&config);
2322
run_tests(config);
2423
}

src/tools/compiletest/src/lib.rs

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
mod tests;
1010

1111
pub mod common;
12-
pub mod compute_diff;
1312
mod debuggers;
1413
pub mod diagnostics;
1514
pub mod directives;
@@ -44,7 +43,6 @@ use crate::common::{
4443
};
4544
use crate::directives::DirectivesCache;
4645
use crate::executor::{CollectedTest, ColorConfig};
47-
use crate::util::logv;
4846

4947
/// Creates the `Config` instance for this invocation of compiletest.
5048
///
@@ -477,51 +475,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
477475
}
478476
}
479477

480-
pub fn log_config(config: &Config) {
481-
let c = config;
482-
logv(c, "configuration:".to_string());
483-
logv(c, format!("compile_lib_path: {}", config.compile_lib_path));
484-
logv(c, format!("run_lib_path: {}", config.run_lib_path));
485-
logv(c, format!("rustc_path: {}", config.rustc_path));
486-
logv(c, format!("cargo_path: {:?}", config.cargo_path));
487-
logv(c, format!("rustdoc_path: {:?}", config.rustdoc_path));
488-
489-
logv(c, format!("src_root: {}", config.src_root));
490-
logv(c, format!("src_test_suite_root: {}", config.src_test_suite_root));
491-
492-
logv(c, format!("build_root: {}", config.build_root));
493-
logv(c, format!("build_test_suite_root: {}", config.build_test_suite_root));
494-
495-
logv(c, format!("sysroot_base: {}", config.sysroot_base));
496-
497-
logv(c, format!("stage: {}", config.stage));
498-
logv(c, format!("stage_id: {}", config.stage_id));
499-
logv(c, format!("mode: {}", config.mode));
500-
logv(c, format!("run_ignored: {}", config.run_ignored));
501-
logv(c, format!("filters: {:?}", config.filters));
502-
logv(c, format!("skip: {:?}", config.skip));
503-
logv(c, format!("filter_exact: {}", config.filter_exact));
504-
logv(
505-
c,
506-
format!("force_pass_mode: {}", opt_str(&config.force_pass_mode.map(|m| format!("{}", m))),),
507-
);
508-
logv(c, format!("runner: {}", opt_str(&config.runner)));
509-
logv(c, format!("host-rustcflags: {:?}", config.host_rustcflags));
510-
logv(c, format!("target-rustcflags: {:?}", config.target_rustcflags));
511-
logv(c, format!("target: {}", config.target));
512-
logv(c, format!("host: {}", config.host));
513-
logv(c, format!("android-cross-path: {}", config.android_cross_path));
514-
logv(c, format!("adb_path: {}", config.adb_path));
515-
logv(c, format!("adb_test_dir: {}", config.adb_test_dir));
516-
logv(c, format!("adb_device_status: {}", config.adb_device_status));
517-
logv(c, format!("ar: {}", config.ar));
518-
logv(c, format!("target-linker: {:?}", config.target_linker));
519-
logv(c, format!("host-linker: {:?}", config.host_linker));
520-
logv(c, format!("verbose: {}", config.verbose));
521-
logv(c, format!("minicore_path: {}", config.minicore_path));
522-
logv(c, "\n".to_string());
523-
}
524-
525478
pub fn opt_str(maybestr: &Option<String>) -> &str {
526479
match *maybestr {
527480
None => "(none)",
@@ -538,6 +491,8 @@ pub fn opt_str2(maybestr: Option<String>) -> String {
538491

539492
/// Called by `main` after the config has been parsed.
540493
pub fn run_tests(config: Arc<Config>) {
494+
debug!(?config, "run_tests");
495+
541496
// If we want to collect rustfix coverage information,
542497
// we first make sure that the coverage file does not exist.
543498
// It will be created later on.

src/tools/compiletest/src/runtest.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::io::prelude::*;
77
use std::io::{self, BufReader};
88
use std::process::{Child, Command, ExitStatus, Output, Stdio};
99
use std::sync::Arc;
10-
use std::{env, iter, str};
10+
use std::{env, fmt, iter, str};
1111

1212
use build_helper::fs::remove_and_create_dir_all;
1313
use camino::{Utf8Path, Utf8PathBuf};
@@ -21,15 +21,13 @@ use crate::common::{
2121
UI_WINDOWS_SVG, expected_output_path, incremental_dir, output_base_dir, output_base_name,
2222
output_testname_unique,
2323
};
24-
use crate::compute_diff::{DiffLine, make_diff, write_diff, write_filtered_diff};
2524
use crate::directives::TestProps;
2625
use crate::errors::{Error, ErrorKind, load_errors};
2726
use crate::read2::{Truncated, read2_abbreviated};
28-
use crate::util::{Utf8PathBufExt, add_dylib_path, logv, static_regex};
27+
use crate::runtest::compute_diff::{DiffLine, make_diff, write_diff, write_filtered_diff};
28+
use crate::util::{Utf8PathBufExt, add_dylib_path, static_regex};
2929
use crate::{ColorConfig, help, json, stamp_file_path, warning};
3030

31-
mod debugger;
32-
3331
// Helper modules that implement test running logic for each test suite.
3432
// tidy-alphabetical-start
3533
mod assembly;
@@ -48,6 +46,8 @@ mod rustdoc_json;
4846
mod ui;
4947
// tidy-alphabetical-end
5048

49+
mod compute_diff;
50+
mod debugger;
5151
#[cfg(test)]
5252
mod tests;
5353

@@ -1459,7 +1459,7 @@ impl<'test> TestCx<'test> {
14591459
) -> ProcRes {
14601460
let cmdline = {
14611461
let cmdline = self.make_cmdline(&command, lib_path);
1462-
logv(self.config, format!("executing {}", cmdline));
1462+
self.logv(format_args!("executing {cmdline}"));
14631463
cmdline
14641464
};
14651465

@@ -2006,6 +2006,18 @@ impl<'test> TestCx<'test> {
20062006
output_base_name(self.config, self.testpaths, self.safe_revision())
20072007
}
20082008

2009+
/// Prints a message to (captured) stdout if `config.verbose` is true.
2010+
/// The message is also logged to `tracing::debug!` regardles of verbosity.
2011+
///
2012+
/// Use `format_args!` as the argument to perform formatting if required.
2013+
fn logv(&self, message: impl fmt::Display) {
2014+
debug!("{message}");
2015+
if self.config.verbose {
2016+
// Note: `./x test ... --verbose --no-capture` is needed to see this print.
2017+
println!("{message}");
2018+
}
2019+
}
2020+
20092021
/// Prefix to print before error messages. Normally just `error`, but also
20102022
/// includes the revision name for tests that use revisions.
20112023
#[must_use]
@@ -2666,20 +2678,17 @@ impl<'test> TestCx<'test> {
26662678
//
26672679
// It's not possible to detect paths in the error messages generally, but this is a
26682680
// decent enough heuristic.
2669-
static_regex!(
2670-
r#"(?x)
2681+
let re = static_regex!(
2682+
r#"(?x)
26712683
(?:
26722684
# Match paths that don't include spaces.
26732685
(?:\\[\pL\pN\.\-_']+)+\.\pL+
26742686
|
26752687
# If the path starts with a well-known root, then allow spaces and no file extension.
26762688
\$(?:DIR|SRC_DIR|TEST_BUILD_DIR|BUILD_DIR|LIB_DIR)(?:\\[\pL\pN\.\-_'\ ]+)+
26772689
)"#
2678-
)
2679-
.replace_all(&output, |caps: &Captures<'_>| {
2680-
println!("{}", &caps[0]);
2681-
caps[0].replace(r"\", "/")
2682-
})
2690+
);
2691+
re.replace_all(&output, |caps: &Captures<'_>| caps[0].replace(r"\", "/"))
26832692
.replace("\r\n", "\n")
26842693
}
26852694

src/tools/compiletest/src/runtest/debuginfo.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use super::debugger::DebuggerCommands;
1010
use super::{Debugger, Emit, ProcRes, TestCx, Truncated, WillExecute};
1111
use crate::common::Config;
1212
use crate::debuggers::{extract_gdb_version, is_android_gdb_target};
13-
use crate::util::logv;
1413

1514
impl TestCx<'_> {
1615
pub(super) fn run_debuginfo_test(&self) {
@@ -234,7 +233,7 @@ impl TestCx<'_> {
234233
gdb.args(debugger_opts);
235234
// FIXME(jieyouxu): don't pass an empty Path
236235
let cmdline = self.make_cmdline(&gdb, Utf8Path::new(""));
237-
logv(self.config, format!("executing {}", cmdline));
236+
self.logv(format_args!("executing {cmdline}"));
238237
cmdline
239238
};
240239

src/tools/compiletest/src/runtest/mir_opt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use miropt_test_tools::{MiroptTest, MiroptTestFile, files_for_miropt_test};
66
use tracing::debug;
77

88
use super::{Emit, TestCx, WillExecute};
9-
use crate::compute_diff::write_diff;
9+
use crate::runtest::compute_diff::write_diff;
1010

1111
impl TestCx<'_> {
1212
pub(super) fn run_mir_opt_test(&self) {

0 commit comments

Comments
 (0)