Skip to content

Commit 0c146ac

Browse files
committed
add regression tests for overlapping spans
1 parent a2d54a2 commit 0c146ac

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Auxiliary lib for the issue 147973 regression test with ICEs due to overlapping spans.
2+
3+
#[macro_export]
4+
macro_rules! identity {
5+
($x:ident) => {
6+
$x
7+
};
8+
}
9+
10+
#[macro_export]
11+
macro_rules! do_loop {
12+
($x:ident) => {
13+
for $crate::identity!($x) in $x {}
14+
};
15+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// These are regression tests for some diagnostics ICEs encountered in the wild with suggestions
2+
// having overlapping parts under https://github.com/rust-lang/rust/pull/146121.
3+
4+
//@ aux-build: overlapping_spans_helper.rs
5+
extern crate overlapping_spans_helper;
6+
7+
// MCVE from issue 146261
8+
enum U {
9+
B(),
10+
}
11+
12+
fn mcve_146261() {
13+
A(U::C)
14+
//~^ ERROR: cannot find function, tuple struct or tuple variant `A`
15+
//~| ERROR: no variant or associated item named `C`
16+
}
17+
18+
// MCVE from issue 146706
19+
20+
type Alias<'a, T> = Foo<T>;
21+
22+
enum Foo<T> {
23+
Bar { t: T },
24+
}
25+
26+
fn mcve_146706() {
27+
Alias::Bar::<u32> { t: 0 };
28+
//~^ ERROR: type arguments are not allowed on this type
29+
}
30+
31+
// One MCVE from the beta crater run from issue 147973
32+
33+
fn mcve_147973() {
34+
let _name = Some(1);
35+
overlapping_spans_helper::do_loop!(_name);
36+
}
37+
38+
fn main() {}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error[E0425]: cannot find function, tuple struct or tuple variant `A` in this scope
2+
--> $DIR/overlapping-spans-in-suggestions.rs:13:5
3+
|
4+
LL | A(U::C)
5+
| ^ not found in this scope
6+
|
7+
help: you might be missing a const parameter
8+
|
9+
LL | fn mcve_146261<const A: /* Type */>() {
10+
| +++++++++++++++++++++
11+
12+
error[E0599]: no variant or associated item named `C` found for enum `U` in the current scope
13+
--> $DIR/overlapping-spans-in-suggestions.rs:13:10
14+
|
15+
LL | enum U {
16+
| ------ variant or associated item `C` not found for this enum
17+
...
18+
LL | A(U::C)
19+
| ^ variant or associated item not found in `U`
20+
|
21+
help: there is a variant with a similar name
22+
|
23+
LL - A(U::C)
24+
LL + A(B)
25+
|
26+
27+
error[E0109]: type arguments are not allowed on this type
28+
--> $DIR/overlapping-spans-in-suggestions.rs:27:18
29+
|
30+
LL | Alias::Bar::<u32> { t: 0 };
31+
| --- ^^^ type argument not allowed
32+
| |
33+
| not allowed on this type
34+
|
35+
= note: enum variants can't have type parameters
36+
help: you might have meant to specify type parameters on enum `Foo`
37+
|
38+
LL - Alias::Bar::<u32> { t: 0 };
39+
LL + Alias::<u32> { t: 0 };
40+
|
41+
42+
error: aborting due to 3 previous errors
43+
44+
Some errors have detailed explanations: E0109, E0425, E0599.
45+
For more information about an error, try `rustc --explain E0109`.

0 commit comments

Comments
 (0)