Skip to content

Commit 9cc8deb

Browse files
author
Jonathan Turner
committed
Move issue-26480 cfail to ui test. Fix #33763
1 parent 4280992 commit 9cc8deb

File tree

3 files changed

+63
-31
lines changed

3 files changed

+63
-31
lines changed

src/test/run-make/unicode-input/span_length.rs

+44-21
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(rand, core)]
11+
#![feature(rand)]
1212

1313
use std::fs::File;
1414
use std::io::prelude::*;
@@ -18,6 +18,11 @@ use std::process::Command;
1818
use std::__rand::{thread_rng, Rng};
1919
use std::{char, env};
2020

21+
pub fn check_old_skool() -> bool {
22+
use std::env;
23+
env::var("RUST_NEW_ERROR_FORMAT").is_err()
24+
}
25+
2126
// creates a file with `fn main() { <random ident> }` and checks the
2227
// compiler emits a span of the appropriate length (for the
2328
// "unresolved name" message); currently just using the number of code
@@ -65,10 +70,17 @@ fn main() {
6570

6671
let err = String::from_utf8_lossy(&result.stderr);
6772

68-
// the span should end the line (e.g no extra ~'s)
69-
let expected_span = format!("^{}\n", repeat("~").take(n - 1)
70-
.collect::<String>());
71-
assert!(err.contains(&expected_span));
73+
if check_old_skool() {
74+
// the span should end the line (e.g no extra ~'s)
75+
let expected_span = format!("^{}\n", repeat("~").take(n - 1)
76+
.collect::<String>());
77+
assert!(err.contains(&expected_span));
78+
} else {
79+
// the span should end the line (e.g no extra ~'s)
80+
let expected_span = format!("^{}\n", repeat("^").take(n - 1)
81+
.collect::<String>());
82+
assert!(err.contains(&expected_span));
83+
}
7284
}
7385

7486
// Test multi-column characters and tabs
@@ -77,9 +89,6 @@ fn main() {
7789
r#"extern "路濫狼á́́" fn foo() {{}} extern "路濫狼á́" fn bar() {{}}"#);
7890
}
7991

80-
// Extra characters. Every line is preceded by `filename:lineno <actual code>`
81-
let offset = main_file.to_str().unwrap().len() + 3;
82-
8392
let result = Command::new("sh")
8493
.arg("-c")
8594
.arg(format!("{} {}",
@@ -91,17 +100,31 @@ fn main() {
91100

92101
// Test both the length of the snake and the leading spaces up to it
93102

94-
// First snake is 8 ~s long, with 7 preceding spaces (excluding file name/line offset)
95-
let expected_span = format!("\n{}^{}\n",
96-
repeat(" ").take(offset + 7).collect::<String>(),
97-
repeat("~").take(8).collect::<String>());
98-
assert!(err.contains(&expected_span));
99-
// Second snake is only 7 ~s long, with 36 preceding spaces,
100-
// because rustc counts chars() now rather than width(). This
101-
// is because width() functions are to be removed from
102-
// librustc_unicode
103-
let expected_span = format!("\n{}^{}\n",
104-
repeat(" ").take(offset + 36).collect::<String>(),
105-
repeat("~").take(7).collect::<String>());
106-
assert!(err.contains(&expected_span));
103+
if check_old_skool() {
104+
// Extra characters. Every line is preceded by `filename:lineno <actual code>`
105+
let offset = main_file.to_str().unwrap().len() + 3;
106+
107+
// First snake is 8 ~s long, with 7 preceding spaces (excluding file name/line offset)
108+
let expected_span = format!("\n{}^{}\n",
109+
repeat(" ").take(offset + 7).collect::<String>(),
110+
repeat("~").take(8).collect::<String>());
111+
assert!(err.contains(&expected_span));
112+
// Second snake is only 7 ~s long, with 36 preceding spaces,
113+
// because rustc counts chars() now rather than width(). This
114+
// is because width() functions are to be removed from
115+
// librustc_unicode
116+
let expected_span = format!("\n{}^{}\n",
117+
repeat(" ").take(offset + 36).collect::<String>(),
118+
repeat("~").take(7).collect::<String>());
119+
assert!(err.contains(&expected_span));
120+
} else {
121+
let expected_span = format!("\n |>{}{}\n",
122+
repeat(" ").take(8).collect::<String>(),
123+
repeat("^").take(9).collect::<String>());
124+
assert!(err.contains(&expected_span));
125+
let expected_span = format!("\n |>{}{}\n",
126+
repeat(" ").take(37).collect::<String>(),
127+
repeat("^").take(8).collect::<String>());
128+
assert!(err.contains(&expected_span));
129+
}
107130
}

src/test/compile-fail/issue-26480.rs renamed to src/test/ui/mismatched_types/issue-26480.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// rustc-env:RUST_NEW_ERROR_FORMAT
1112
extern {
1213
fn write(fildes: i32, buf: *const i8, nbyte: u64) -> i64;
1314
}
@@ -24,25 +25,16 @@ macro_rules! write {
2425
unsafe {
2526
write(stdout, $arr.as_ptr() as *const i8,
2627
$arr.len() * size_of($arr[0]));
27-
//~^ ERROR mismatched types
28-
//~| expected u64, found usize
29-
//~| expected type
30-
//~| found type
3128
}
3229
}}
3330
}
3431

3532
macro_rules! cast {
36-
($x:expr) => ($x as ()) //~ ERROR non-scalar cast
33+
($x:expr) => ($x as ())
3734
}
3835

3936
fn main() {
4037
let hello = ['H', 'e', 'y'];
4138
write!(hello);
42-
//~^ NOTE in this expansion of write!
43-
//~| NOTE in this expansion of write!
44-
//~| NOTE in this expansion of write!
45-
4639
cast!(2);
47-
//~^ NOTE in this expansion of cast!
4840
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: mismatched types [--explain E0308]
2+
--> $DIR/issue-26480.rs:27:19
3+
|>
4+
27 |> $arr.len() * size_of($arr[0]));
5+
|> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u64, found usize
6+
$DIR/issue-26480.rs:38:5: 38:19: note: in this expansion of write! (defined in $DIR/issue-26480.rs)
7+
8+
9+
error: non-scalar cast: `_` as `()`
10+
--> $DIR/issue-26480.rs:33:19
11+
|>
12+
33 |> ($x:expr) => ($x as ())
13+
|> ^^^^^^^^
14+
$DIR/issue-26480.rs:39:5: 39:14: note: in this expansion of cast! (defined in $DIR/issue-26480.rs)
15+
16+
17+
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)