Skip to content

Commit cc3eee7

Browse files
committed
Auto merge of #149419 - matthiaskrgr:rollup-v3q93fq, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #147952 (Add a timeout to the `remote-test-client` connection) - #149321 (Fix ICE when include_str! reads binary files) - #149398 (add regression test for issue #143987) - #149411 (Tidying up UI tests [5/N]) - #149413 (add test for issue 143821) - #149415 (Remove test-float-parse from workspace list in tidy) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9050733 + 3730b40 commit cc3eee7

Some content is hidden

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

46 files changed

+258
-151
lines changed

compiler/rustc_parse/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ pub fn utf8_error<E: EmissionGuarantee>(
130130
};
131131
let contents = String::from_utf8_lossy(contents).to_string();
132132
let source = sm.new_source_file(PathBuf::from(path).into(), contents);
133+
134+
// Avoid out-of-bounds span from lossy UTF-8 conversion.
135+
if start as u32 > source.normalized_source_len.0 {
136+
err.note(note);
137+
return;
138+
}
139+
133140
let span = Span::with_root_ctxt(
134141
source.normalized_byte_pos(start as u32),
135142
source.normalized_byte_pos(start as u32),

src/doc/rustc-dev-guide/src/tests/running.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ Tests are built on the machine running `x` not on the remote machine.
321321
Tests which fail to build unexpectedly (or `ui` tests producing incorrect build
322322
output) may fail without ever running on the remote machine.
323323

324+
There is a default timeout of 30 minutes in case the `remote-test-server`
325+
cannot be reached by the `x` command. This timeout can be modified by using the
326+
`TEST_DEVICE_CONNECT_TIMEOUT_SECONDS` environment variable.
327+
324328
## Testing on emulators
325329

326330
Some platforms are tested via an emulator for architectures that aren't readily available.

src/tools/remote-test-client/src/main.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ use std::io::{self, BufWriter};
1111
use std::net::TcpStream;
1212
use std::path::{Path, PathBuf};
1313
use std::process::{Command, Stdio};
14-
use std::time::Duration;
14+
use std::time::{Duration, Instant};
1515
use std::{env, thread};
1616

1717
const REMOTE_ADDR_ENV: &str = "TEST_DEVICE_ADDR";
1818
const DEFAULT_ADDR: &str = "127.0.0.1:12345";
1919

20+
const CONNECT_TIMEOUT_ENV: &str = "TEST_DEVICE_CONNECT_TIMEOUT_SECONDS";
21+
/// The default timeout is high to not break slow CI or slow device starts.
22+
const DEFAULT_CONNECT_TIMEOUT: Duration = Duration::from_mins(30);
23+
2024
macro_rules! t {
2125
($e:expr) => {
2226
match $e {
@@ -56,6 +60,17 @@ fn main() {
5660
}
5761
}
5862

63+
fn connect_timeout() -> Duration {
64+
match env::var(CONNECT_TIMEOUT_ENV).ok() {
65+
Some(timeout) => timeout.parse().map(Duration::from_secs).unwrap_or_else(|e| {
66+
panic!(
67+
"error: parsing `{CONNECT_TIMEOUT_ENV}` value \"{timeout}\" as seconds failed: {e}"
68+
)
69+
}),
70+
None => DEFAULT_CONNECT_TIMEOUT,
71+
}
72+
}
73+
5974
fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option<PathBuf>) {
6075
let device_address = env::var(REMOTE_ADDR_ENV).unwrap_or(DEFAULT_ADDR.to_string());
6176

@@ -69,20 +84,28 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option<Pat
6984
}
7085

7186
// Wait for the emulator to come online
72-
loop {
87+
let timeout = connect_timeout();
88+
let mut successful_read = false;
89+
let start_time = Instant::now();
90+
while start_time.elapsed() < timeout {
7391
let dur = Duration::from_millis(2000);
7492
if let Ok(mut client) = TcpStream::connect(&device_address) {
7593
t!(client.set_read_timeout(Some(dur)));
7694
t!(client.set_write_timeout(Some(dur)));
7795
if client.write_all(b"ping").is_ok() {
7896
let mut b = [0; 4];
7997
if client.read_exact(&mut b).is_ok() {
98+
successful_read = true;
8099
break;
81100
}
82101
}
83102
}
84103
thread::sleep(dur);
85104
}
105+
106+
if !successful_read {
107+
panic!("Gave up trying to connect to test device at {device_address} after {timeout:?}");
108+
}
86109
}
87110

88111
fn start_android_emulator(server: &Path) {

src/tools/remote-test-client/tests/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,18 @@ fn test_help() {
88
let stdout = String::from_utf8(output.stdout.clone()).unwrap();
99
assert!(stdout.trim().starts_with("Usage:"));
1010
}
11+
12+
#[test]
13+
fn test_timeout() {
14+
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!();
15+
cmd.env("TEST_DEVICE_CONNECT_TIMEOUT_SECONDS", "1");
16+
cmd.env("TEST_DEVICE_ADDR", "127.69.69.69:6969");
17+
cmd.args(["spawn-emulator", "dummy-target", "dummy-server", "dummy-tmpdir"]);
18+
19+
let assert = cmd.assert().failure();
20+
let output = assert.get_output();
21+
22+
let stderr = String::from_utf8(output.stderr.clone()).unwrap();
23+
let pass_msg = "Gave up trying to connect to test device";
24+
assert!(stderr.contains(pass_msg), "Could not find `{pass_msg}` in `{stderr}`");
25+
}

src/tools/tidy/src/deps.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ pub(crate) const WORKSPACES: &[WorkspaceInfo<'static>] = &[
168168
crates_and_deps: None,
169169
submodules: &["src/tools/rustc-perf"],
170170
},
171-
WorkspaceInfo {
172-
path: "src/tools/test-float-parse",
173-
exceptions: EXCEPTIONS,
174-
crates_and_deps: None,
175-
submodules: &[],
176-
},
177171
WorkspaceInfo {
178172
path: "tests/run-make-cargo/uefi-qemu/uefi_qemu_test",
179173
exceptions: EXCEPTIONS_UEFI_QEMU_TEST,

src/tools/tidy/src/ui_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ fn check_unexpected_extension(check: &mut RunningCheck, file_path: &Path, ext: &
157157
"tests/ui/crate-loading/auxiliary/libfoo.rlib", // testing loading a manually created rlib
158158
"tests/ui/include-macros/data.bin", // testing including data with the include macros
159159
"tests/ui/include-macros/file.txt", // testing including data with the include macros
160+
"tests/ui/include-macros/invalid-utf8-binary-file.bin", // testing including data with the include macros
160161
"tests/ui/macros/macro-expanded-include/file.txt", // testing including data with the include macros
161162
"tests/ui/macros/not-utf8.bin", // testing including data with the include macros
162163
"tests/ui/macros/syntax-extension-source-utils-files/includeme.fragment", // more include

tests/ui/README.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -891,12 +891,6 @@ Exercise *Link-Time Optimization* (LTO), involving the flags `-C lto` or `-Z thi
891891

892892
Tests on changes to inference variable lattice LUB/GLB, see <https://github.com/rust-lang/rust/pull/45853>.
893893

894-
## `tests/ui/macro_backtrace/`: `-Zmacro-backtrace`
895-
896-
Contains a single test, checking the unstable command-line flag to enable detailed macro backtraces.
897-
898-
**FIXME**: This could be merged with `ui/macros`, which already contains other macro backtrace tests.
899-
900894
## `tests/ui/macros/`
901895

902896
Broad category of tests on macros.
@@ -945,12 +939,6 @@ Something is missing which could be added to fix (e.g. suggestions).
945939

946940
**FIXME**: this is way too vague, tests should be rehomed.
947941

948-
## `tests/ui/missing_non_modrs_mod/`
949-
950-
This directory is a small tree of `mod` dependencies, but the root, `foo.rs`, is looking for a file which does not exist. The test checks that the error is reported at the top-level module.
951-
952-
**FIXME**: Merge with `tests/ui/modules/`.
953-
954942
## `tests/ui/missing-trait-bounds/`
955943

956944
Tests for checking missing trait bounds, and their diagnostics.
@@ -963,10 +951,6 @@ Tests on the module system.
963951

964952
**FIXME**: `tests/ui/imports/` should probably be merged with this.
965953

966-
## `tests/ui/modules_and_files_visibility/`
967-
968-
**FIXME**: Merge with `tests/ui/modules/`.
969-
970954
## `tests/ui/moves`
971955

972956
Tests on moves (destructive moves).
@@ -1135,12 +1119,6 @@ A large category about function and type public/private visibility, and its impa
11351119

11361120
**FIXME**: merge with `tests/ui/privacy/`.
11371121

1138-
## `tests/ui/qualified/`
1139-
1140-
Contains few tests on qualified paths where a type parameter is provided at the end: `type A = <S as Tr>::A::f<u8>;`. The tests check if this fails during type checking, not parsing.
1141-
1142-
**FIXME**: Should be rehomed to `ui/typeck`.
1143-
11441122
## `tests/ui/query-system/`
11451123

11461124
Tests on Rust methods and functions which use the query system, such as `std::mem::size_of`. These compute information about the current runtime and return it. See [Query system | rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/query.html).
@@ -1583,12 +1561,6 @@ Tests on various well-formedness checks, e.g. [Type-checking normal functions](h
15831561

15841562
Tests on `where` clauses. See [Where clauses | Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses).
15851563

1586-
## `tests/ui/while/`
1587-
1588-
Tests on the `while` keyword and the `while` construct.
1589-
1590-
**FIXME**: merge with `ui/for-loop-while`.
1591-
15921564
## `tests/ui/windows-subsystem/`: `#![windows_subsystem = ""]`
15931565

15941566
See [the `windows_subsystem` attribute](https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute).
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Regression test for issue https://github.com/rust-lang/rust/issues/143987
2+
// Ensure that using `#[align]` on struct fields produces an error
3+
// instead of causing an ICE (Internal Compiler Error)
4+
5+
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
6+
#![feature(rustc_attrs)]
7+
#![feature(fn_align)]
8+
9+
struct Data {
10+
#[rustc_align(8)] //~ ERROR `#[rustc_align]` attribute cannot be used on struct fields
11+
x: usize,
12+
}
13+
14+
// Test with invalid type to match the original issue more closely
15+
struct DataInvalid {
16+
#[rustc_align(8)] //~ ERROR `#[rustc_align]` attribute cannot be used on struct fields
17+
x: usize8, //~ ERROR cannot find type `usize8` in this scope
18+
}
19+
20+
// Test with tuple struct
21+
struct TupleData(
22+
#[rustc_align(32)] //~ ERROR `#[rustc_align]` attribute cannot be used on struct fields
23+
u32
24+
);
25+
26+
// Test that it works correctly on functions (no error)
27+
#[rustc_align(16)]
28+
fn aligned_function() {}
29+
30+
fn main() {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0412]: cannot find type `usize8` in this scope
2+
--> $DIR/align-on-fields-143987.rs:17:8
3+
|
4+
LL | x: usize8,
5+
| ^^^^^^ help: a builtin type with a similar name exists: `usize`
6+
7+
error: `#[rustc_align]` attribute cannot be used on struct fields
8+
--> $DIR/align-on-fields-143987.rs:10:5
9+
|
10+
LL | #[rustc_align(8)]
11+
| ^^^^^^^^^^^^^^^^^
12+
|
13+
= help: `#[rustc_align]` can only be applied to functions
14+
15+
error: `#[rustc_align]` attribute cannot be used on struct fields
16+
--> $DIR/align-on-fields-143987.rs:16:5
17+
|
18+
LL | #[rustc_align(8)]
19+
| ^^^^^^^^^^^^^^^^^
20+
|
21+
= help: `#[rustc_align]` can only be applied to functions
22+
23+
error: `#[rustc_align]` attribute cannot be used on struct fields
24+
--> $DIR/align-on-fields-143987.rs:22:5
25+
|
26+
LL | #[rustc_align(32)]
27+
| ^^^^^^^^^^^^^^^^^^
28+
|
29+
= help: `#[rustc_align]` can only be applied to functions
30+
31+
error: aborting due to 4 previous errors
32+
33+
For more information about this error, try `rustc --explain E0412`.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ check-pass
2+
// Regression test for issue https://github.com/rust-lang/rust/issues/143821
3+
// Tests that we don't ICE when borrow-checking nested closures with generic type parameters
4+
// and late-bound lifetime parameters.
5+
6+
fn data_<T: 'static>(_: &()) -> &T {
7+
loop {}
8+
}
9+
10+
fn register<T, F>(f: F) -> IfaceToken<T>
11+
where
12+
T: 'static,
13+
F: FnOnce(&()),
14+
{
15+
loop {}
16+
}
17+
18+
fn method_with_cr_async<CB>(cb: CB)
19+
where
20+
CB: Fn(),
21+
{
22+
loop {}
23+
}
24+
25+
struct IfaceToken<T: 'static>(T);
26+
27+
fn foo<T>() -> IfaceToken<T> {
28+
register::<T, _>(|b: &()| {
29+
method_with_cr_async(|| {
30+
data_::<T>(&());
31+
});
32+
})
33+
}
34+
35+
struct A();
36+
37+
fn main() {
38+
foo::<A>();
39+
}

0 commit comments

Comments
 (0)