Skip to content

Commit 14f33a5

Browse files
committed
Auto merge of #30778 - fhahn:issue-21195-expect-help, r=nikomatsakis
This is a PR for #21195. It changes the way unspecified `help` and `ǹote` messages are handled in compile-fail tests as suggested by @oli-obk in the issue: if there are some `note` or `help` annotations, there must be annotations for all `help` or `note` messages of this test. Maybe it makes also sense to add an option to specify that the this test should fail if there are unspecified `help` or `note` messages. With this change, the following tests fail: [compile-fail] compile-fail/changing-crates.rs [compile-fail] compile-fail/default_ty_param_conflict_cross_crate.rs [compile-fail] compile-fail/lifetime-inference-give-expl-lifetime-param.rs [compile-fail] compile-fail/privacy1.rs [compile-fail] compile-fail/svh-change-lit.rs [compile-fail] compile-fail/svh-change-significant-cfg.rs [compile-fail] compile-fail/svh-change-trait-bound.rs [compile-fail] compile-fail/svh-change-type-arg.rs [compile-fail] compile-fail/svh-change-type-ret.rs [compile-fail] compile-fail/svh-change-type-static.rs [compile-fail] compile-fail/svh-use-trait.rs I'll add the missing annotations if we decide to accept this change.
2 parents 449e8bf + 526965a commit 14f33a5

12 files changed

+63
-15
lines changed

src/compiletest/runtest.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,13 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError>,
929929
format!("{}:{}:", testfile.display(), ee.line)
930930
}).collect::<Vec<String>>();
931931

932+
let (expect_help, expect_note) =
933+
expected_errors.iter()
934+
.fold((false, false),
935+
|(acc_help, acc_note), ee|
936+
(acc_help || ee.kind == "help:", acc_note ||
937+
ee.kind == "note:"));
938+
932939
fn prefix_matches(line: &str, prefix: &str) -> bool {
933940
use std::ascii::AsciiExt;
934941
// On windows just translate all '\' path separators to '/'
@@ -992,8 +999,8 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError>,
992999
was_expected = true;
9931000
}
9941001

995-
if !was_expected && is_compiler_error_or_warning(line) {
996-
fatal_proc_rec(&format!("unexpected compiler error or warning: '{}'",
1002+
if !was_expected && is_unexpected_compiler_message(line, expect_help, expect_note) {
1003+
fatal_proc_rec(&format!("unexpected compiler message: '{}'",
9971004
line),
9981005
proc_res);
9991006
}
@@ -1009,16 +1016,15 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError>,
10091016
}
10101017
}
10111018

1012-
fn is_compiler_error_or_warning(line: &str) -> bool {
1019+
fn is_unexpected_compiler_message(line: &str, expect_help: bool, expect_note: bool) -> bool {
10131020
let mut c = Path::new(line).components();
10141021
let line = match c.next() {
10151022
Some(Component::Prefix(_)) => c.as_path().to_str().unwrap(),
10161023
_ => line,
10171024
};
10181025

10191026
let mut i = 0;
1020-
return
1021-
scan_until_char(line, ':', &mut i) &&
1027+
return scan_until_char(line, ':', &mut i) &&
10221028
scan_char(line, ':', &mut i) &&
10231029
scan_integer(line, &mut i) &&
10241030
scan_char(line, ':', &mut i) &&
@@ -1030,7 +1036,10 @@ fn is_compiler_error_or_warning(line: &str) -> bool {
10301036
scan_integer(line, &mut i) &&
10311037
scan_char(line, ' ', &mut i) &&
10321038
(scan_string(line, "error", &mut i) ||
1033-
scan_string(line, "warning", &mut i));
1039+
scan_string(line, "warning", &mut i) ||
1040+
(expect_help && scan_string(line, "help", &mut i)) ||
1041+
(expect_note && scan_string(line, "note", &mut i))
1042+
);
10341043
}
10351044

10361045
fn scan_until_char(haystack: &str, needle: char, idx: &mut usize) -> bool {

src/test/compile-fail/changing-crates.rs

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

11+
// ignore-msvc FIXME #31306
12+
1113
// note that these aux-build directives must be in this order
1214
// aux-build:changing-crates-a1.rs
1315
// aux-build:changing-crates-b.rs
1416
// aux-build:changing-crates-a2.rs
1517

1618
extern crate a;
1719
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
18-
//~^ NOTE: perhaps this crate needs to be recompiled
20+
//~| NOTE: perhaps this crate needs to be recompiled
21+
//~| NOTE: crate `a` path #1:
22+
//~| NOTE: crate `b` path #1:
1923

2024
fn main() {}

src/test/compile-fail/default_ty_param_conflict_cross_crate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ fn main() {
2626
meh(foo);
2727
//~^ ERROR: mismatched types:
2828
//~| NOTE: conflicting type parameter defaults `bool` and `char`
29+
//~| NOTE: ...that was applied to an unconstrained type variable here
2930
}

src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct Baz<'x> {
4949

5050
impl<'a> Baz<'a> {
5151
fn baz2<'b>(&self, x: &isize) -> (&'b isize, &'b isize) {
52+
//~^ HELP: parameter as shown: fn baz2<'b>(&self, x: &'b isize) -> (&'a isize, &'a isize)
5253
// The lifetime that gets assigned to `x` seems somewhat random.
5354
// I have disabled this test for the time being. --pcwalton
5455
(self.bar, x) //~ ERROR: cannot infer

src/test/compile-fail/privacy1.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,17 @@ mod foo {
129129
::bar::baz::foo(); //~ ERROR: function `foo` is inaccessible
130130
//~^ NOTE: module `baz` is private
131131
::bar::baz::bar(); //~ ERROR: function `bar` is inaccessible
132+
//~^ NOTE: module `baz` is private
132133
}
133134

134135
fn test2() {
135136
use bar::baz::{foo, bar};
136137
//~^ ERROR: function `foo` is inaccessible
137-
//~^^ ERROR: function `bar` is inaccessible
138+
//~| NOTE: module `baz` is private
139+
//~| ERROR: function `bar` is inaccessible
140+
//~| NOTE: module `baz` is private
141+
142+
138143
foo();
139144
bar();
140145
}

src/test/compile-fail/svh-change-lit.rs

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

11+
// ignore-msvc FIXME #31306
12+
1113
// note that these aux-build directives must be in this order
1214
// aux-build:svh-a-base.rs
1315
// aux-build:svh-b.rs
1416
// aux-build:svh-a-change-lit.rs
1517

1618
extern crate a;
1719
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
18-
//~^ NOTE: perhaps this crate needs to be recompiled
20+
//~| NOTE: perhaps this crate needs to be recompiled
21+
//~| NOTE: crate `a` path #1:
22+
//~| NOTE: crate `b` path #1:
1923

2024
fn main() {
2125
b::foo()

src/test/compile-fail/svh-change-significant-cfg.rs

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

11+
// ignore-msvc FIXME #31306
12+
1113
// note that these aux-build directives must be in this order
1214
// aux-build:svh-a-base.rs
1315
// aux-build:svh-b.rs
1416
// aux-build:svh-a-change-significant-cfg.rs
1517

1618
extern crate a;
1719
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
18-
//~^ NOTE: perhaps this crate needs to be recompiled
20+
//~| NOTE: perhaps this crate needs to be recompiled
21+
//~| NOTE: crate `a` path #1:
22+
//~| NOTE: crate `b` path #1:
1923

2024
fn main() {
2125
b::foo()

src/test/compile-fail/svh-change-trait-bound.rs

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

11+
// ignore-msvc FIXME #31306
12+
1113
// note that these aux-build directives must be in this order
1214
// aux-build:svh-a-base.rs
1315
// aux-build:svh-b.rs
1416
// aux-build:svh-a-change-trait-bound.rs
1517

1618
extern crate a;
1719
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
18-
//~^ NOTE: perhaps this crate needs to be recompiled
20+
//~| NOTE: perhaps this crate needs to be recompiled
21+
//~| NOTE: crate `a` path #1:
22+
//~| NOTE: crate `b` path #1:
1923

2024
fn main() {
2125
b::foo()

src/test/compile-fail/svh-change-type-arg.rs

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

11+
// ignore-msvc FIXME #31306
12+
1113
// note that these aux-build directives must be in this order
1214
// aux-build:svh-a-base.rs
1315
// aux-build:svh-b.rs
1416
// aux-build:svh-a-change-type-arg.rs
1517

1618
extern crate a;
1719
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
18-
//~^ NOTE: perhaps this crate needs to be recompiled
20+
//~| NOTE: perhaps this crate needs to be recompiled
21+
//~| NOTE: crate `a` path #1:
22+
//~| NOTE: crate `b` path #1:
1923

2024
fn main() {
2125
b::foo()

src/test/compile-fail/svh-change-type-ret.rs

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

11+
// ignore-msvc FIXME #31306
12+
1113
// note that these aux-build directives must be in this order
1214
// aux-build:svh-a-base.rs
1315
// aux-build:svh-b.rs
1416
// aux-build:svh-a-change-type-ret.rs
1517

1618
extern crate a;
1719
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
18-
//~^ NOTE: perhaps this crate needs to be recompiled
20+
//~| NOTE: perhaps this crate needs to be recompiled
21+
//~| NOTE: crate `a` path #1:
22+
//~| NOTE: crate `b` path #1:
1923

2024
fn main() {
2125
b::foo()

src/test/compile-fail/svh-change-type-static.rs

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

11+
// ignore-msvc FIXME #31306
12+
1113
// note that these aux-build directives must be in this order
1214
// aux-build:svh-a-base.rs
1315
// aux-build:svh-b.rs
1416
// aux-build:svh-a-change-type-static.rs
1517

1618
extern crate a;
1719
extern crate b; //~ ERROR: found possibly newer version of crate `a` which `b` depends on
18-
//~^ NOTE: perhaps this crate needs to be recompiled
20+
//~| NOTE: perhaps this crate needs to be recompiled
21+
//~| NOTE: crate `a` path #1:
22+
//~| NOTE: crate `b` path #1:
1923

2024
fn main() {
2125
b::foo()

src/test/compile-fail/svh-use-trait.rs

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

11+
// ignore-msvc FIXME #31306
12+
1113
// note that these aux-build directives must be in this order
1214
// aux-build:svh-uta-base.rs
1315
// aux-build:svh-utb.rs
@@ -20,7 +22,9 @@
2022
2123
extern crate uta;
2224
extern crate utb; //~ ERROR: found possibly newer version of crate `uta` which `utb` depends
23-
//~^ NOTE: perhaps this crate needs to be recompiled
25+
//~| NOTE: perhaps this crate needs to be recompiled?
26+
//~| NOTE: crate `uta` path #1:
27+
//~| NOTE: crate `utb` path #1:
2428

2529
fn main() {
2630
utb::foo()

0 commit comments

Comments
 (0)