Skip to content

Commit 6833c27

Browse files
committed
Bless and add tests
1 parent 04d141b commit 6833c27

23 files changed

+172
-73
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4637,3 +4637,6 @@ fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Deb
46374637
}
46384638
DebugFn(f)
46394639
}
4640+
4641+
#[cfg(test)]
4642+
mod tests;

compiler/rustc_hir/src/hir/tests.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
use rustc_span::def_id::DefIndex;
2+
3+
use super::*;
4+
5+
macro_rules! define_tests {
6+
($($name:ident $kind:ident $variant:ident {$($init:tt)*})*) => {$(
7+
#[test]
8+
fn $name() {
9+
let unambig = $kind::$variant::<'_, ()> { $($init)* };
10+
let unambig_to_ambig = unsafe { std::mem::transmute::<_, $kind<'_, AmbigArg>>(unambig) };
11+
12+
assert!(matches!(&unambig_to_ambig, $kind::$variant { $($init)* }));
13+
14+
let ambig_to_unambig = unsafe { std::mem::transmute::<_, $kind<'_, ()>>(unambig_to_ambig) };
15+
16+
assert!(matches!(&ambig_to_unambig, $kind::$variant { $($init)* }));
17+
}
18+
)*};
19+
}
20+
21+
define_tests! {
22+
cast_never TyKind Never {}
23+
cast_tup TyKind Tup { 0: &[Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never }] }
24+
cast_ptr TyKind Ptr { 0: MutTy { ty: &Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never }, mutbl: Mutability::Not }}
25+
cast_array TyKind Array {
26+
0: &Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never },
27+
1: &ConstArg { hir_id: HirId::INVALID, kind: ConstArgKind::Anon(&AnonConst {
28+
hir_id: HirId::INVALID,
29+
def_id: LocalDefId { local_def_index: DefIndex::ZERO },
30+
body: BodyId { hir_id: HirId::INVALID },
31+
span: DUMMY_SP,
32+
})}
33+
}
34+
35+
cast_anon ConstArgKind Anon {
36+
0: &AnonConst {
37+
hir_id: HirId::INVALID,
38+
def_id: LocalDefId { local_def_index: DefIndex::ZERO },
39+
body: BodyId { hir_id: HirId::INVALID },
40+
span: DUMMY_SP,
41+
}
42+
}
43+
}
44+
45+
#[test]
46+
fn trait_object_roundtrips() {
47+
trait_object_roundtrips_impl(TraitObjectSyntax::Dyn);
48+
trait_object_roundtrips_impl(TraitObjectSyntax::DynStar);
49+
trait_object_roundtrips_impl(TraitObjectSyntax::None);
50+
}
51+
52+
fn trait_object_roundtrips_impl(syntax: TraitObjectSyntax) {
53+
let unambig = TyKind::TraitObject::<'_, ()>(
54+
&[],
55+
TaggedRef::new(
56+
&const {
57+
Lifetime {
58+
hir_id: HirId::INVALID,
59+
ident: Ident::new(sym::name, DUMMY_SP),
60+
res: LifetimeName::Static,
61+
}
62+
},
63+
syntax,
64+
),
65+
);
66+
let unambig_to_ambig = unsafe { std::mem::transmute::<_, TyKind<'_, AmbigArg>>(unambig) };
67+
68+
match unambig_to_ambig {
69+
TyKind::TraitObject(_, tagged_ref) => {
70+
assert!(tagged_ref.tag() == syntax)
71+
}
72+
_ => panic!("`TyKind::TraitObject` did not roundtrip"),
73+
};
74+
75+
let ambig_to_unambig = unsafe { std::mem::transmute::<_, TyKind<'_, ()>>(unambig_to_ambig) };
76+
77+
match ambig_to_unambig {
78+
TyKind::TraitObject(_, tagged_ref) => {
79+
assert!(tagged_ref.tag() == syntax)
80+
}
81+
_ => panic!("`TyKind::TraitObject` did not roundtrip"),
82+
};
83+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(generic_arg_infer, closure_lifetime_binder)]
2+
3+
struct Foo<const N: usize>([u32; N]);
4+
5+
fn main() {
6+
let c = for<'a> |b: &'a Foo<_>| -> u32 { b.0[0] };
7+
//~^ ERROR: implicit types in closure signatures are forbidden when `for<...>` is present
8+
c(&Foo([1_u32; 1]));
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: implicit types in closure signatures are forbidden when `for<...>` is present
2+
--> $DIR/forbid_ambig_const_infers.rs:6:33
3+
|
4+
LL | let c = for<'a> |b: &'a Foo<_>| -> u32 { b.0[0] };
5+
| ------- ^
6+
| |
7+
| `for<...>` is here
8+
9+
error: aborting due to 1 previous error
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(generic_arg_infer, closure_lifetime_binder)]
2+
3+
struct Foo<T>(T);
4+
5+
fn main() {
6+
let c = for<'a> |b: &'a Foo<_>| -> u32 { b.0 };
7+
//~^ ERROR: implicit types in closure signatures are forbidden when `for<...>` is present
8+
c(&Foo(1_u32));
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: implicit types in closure signatures are forbidden when `for<...>` is present
2+
--> $DIR/forbid_ambig_type_infers.rs:6:33
3+
|
4+
LL | let c = for<'a> |b: &'a Foo<_>| -> u32 { b.0 };
5+
| ------- ^
6+
| |
7+
| `for<...>` is here
8+
9+
error: aborting due to 1 previous error
10+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(generic_arg_infer, closure_lifetime_binder)]
2+
3+
fn main() {
4+
let c = for<'a> |b: &'a [u32; _]| -> u32 { b[0] };
5+
//~^ ERROR: implicit types in closure signatures are forbidden when `for<...>` is present
6+
c(&[1_u32; 2]);
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: implicit types in closure signatures are forbidden when `for<...>` is present
2+
--> $DIR/forbid_const_infer.rs:4:35
3+
|
4+
LL | let c = for<'a> |b: &'a [u32; _]| -> u32 { b[0] };
5+
| ------- ^
6+
| |
7+
| `for<...>` is here
8+
9+
error: aborting due to 1 previous error
10+

tests/ui/const-generics/issues/issue-62878.min.stderr

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
1818
LL + #![feature(adt_const_params)]
1919
|
2020

21-
error[E0747]: type provided when a constant was expected
21+
error[E0658]: const arguments cannot yet be inferred with `_`
2222
--> $DIR/issue-62878.rs:10:11
2323
|
2424
LL | foo::<_, { [1] }>();
2525
| ^
2626
|
27-
= help: const arguments cannot yet be inferred with `_`
28-
help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
29-
|
30-
LL + #![feature(generic_arg_infer)]
31-
|
27+
= note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
28+
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
29+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3230

3331
error: aborting due to 3 previous errors
3432

35-
Some errors have detailed explanations: E0747, E0770.
36-
For more information about an error, try `rustc --explain E0747`.
33+
Some errors have detailed explanations: E0658, E0770.
34+
For more information about an error, try `rustc --explain E0658`.

tests/ui/const-generics/issues/issue-62878.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ fn foo<const N: usize, const A: [u8; N]>() {}
88

99
fn main() {
1010
foo::<_, { [1] }>();
11-
//[min]~^ ERROR: type provided when a constant was expected
11+
//[min]~^ ERROR: const arguments cannot yet be inferred with `_`
1212
}

tests/ui/did_you_mean/bad-assoc-ty.stderr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@ LL | fn foo<X: K<_, _>>(x: X) {}
233233
| ^ ^ not allowed in type signatures
234234
| |
235235
| not allowed in type signatures
236-
|
237-
help: use type parameters instead
238-
|
239-
LL | fn foo<X: K<T, T>, T>(x: X) {}
240-
| ~ ~ +++
241236

242237
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
243238
--> $DIR/bad-assoc-ty.rs:54:34

tests/ui/feature-gates/feature-gate-generic_arg_infer.normal.stderr

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ LL | let _y: [u8; _] = [0; 3];
88
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

11-
error[E0747]: type provided when a constant was expected
11+
error[E0658]: const arguments cannot yet be inferred with `_`
1212
--> $DIR/feature-gate-generic_arg_infer.rs:18:20
1313
|
14-
LL | let _x = foo::<_>([1,2]);
14+
LL | let _x = foo::<_>([1, 2]);
1515
| ^
1616
|
17-
= help: const arguments cannot yet be inferred with `_`
18-
help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
19-
|
20-
LL + #![feature(generic_arg_infer)]
21-
|
17+
= note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
18+
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2220

2321
error[E0658]: using `_` for array lengths is unstable
2422
--> $DIR/feature-gate-generic_arg_infer.rs:11:27
@@ -32,5 +30,4 @@ LL | let _x: [u8; 3] = [0; _];
3230

3331
error: aborting due to 3 previous errors
3432

35-
Some errors have detailed explanations: E0658, E0747.
36-
For more information about an error, try `rustc --explain E0658`.
33+
For more information about this error, try `rustc --explain E0658`.

tests/ui/feature-gates/feature-gate-generic_arg_infer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![cfg_attr(feature, feature(generic_arg_infer))]
55

66
fn foo<const N: usize>(_: [u8; N]) -> [u8; N] {
7-
[0; N]
7+
[0; N]
88
}
99

1010
fn bar() {
@@ -15,7 +15,7 @@ fn bar() {
1515
}
1616

1717
fn main() {
18-
let _x = foo::<_>([1,2]);
19-
//[normal]~^ ERROR: type provided when a constant was expected
18+
let _x = foo::<_>([1, 2]);
19+
//[normal]~^ ERROR: const arguments cannot yet be inferred with `_`
2020
bar();
2121
}

tests/ui/generics/issue-79605.stderr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
33
|
44
LL | impl X<'_, _> {}
55
| ^ not allowed in type signatures
6-
|
7-
help: use type parameters instead
8-
|
9-
LL | impl<T> X<'_, T> {}
10-
| +++ ~
116

127
error: aborting due to 1 previous error
138

tests/ui/macros/macro-span-issue-116502.stderr

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ LL | T: Trait<m!()>;
1717
| ---- in this macro invocation
1818
|
1919
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
20-
help: use type parameters instead
21-
|
22-
LL ~ U
23-
LL | };
24-
LL | }
25-
LL ~ struct S<U>(m!(), T)
26-
|
2720

2821
error: aborting due to 1 previous error
2922

tests/ui/parser/issues/issue-14303-fncall.full.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0747]: type provided when a lifetime was expected
2-
--> $DIR/issue-14303-fncall.rs:15:26
1+
error[E0747]: placeholder provided when a lifetime was expected
2+
--> $DIR/issue-14303-fncall.rs:12:77
33
|
4-
LL | .collect::<Vec<S<_, 'a>>>();
5-
| ^
4+
LL | let _x = (*start..*end).map(|x| S { a: start, b: end }).collect::<Vec<S<_, 'a>>>();
5+
| ^
66

77
error: aborting due to 1 previous error
88

tests/ui/parser/issues/issue-14303-fncall.generic_arg.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0747]: inferred provided when a lifetime was expected
2-
--> $DIR/issue-14303-fncall.rs:15:26
1+
error[E0747]: placeholder provided when a lifetime was expected
2+
--> $DIR/issue-14303-fncall.rs:12:77
33
|
4-
LL | .collect::<Vec<S<_, 'a>>>();
5-
| ^
4+
LL | let _x = (*start..*end).map(|x| S { a: start, b: end }).collect::<Vec<S<_, 'a>>>();
5+
| ^
66

77
error: aborting due to 1 previous error
88

tests/ui/parser/issues/issue-14303-fncall.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
// we need the above to avoid ast borrowck failure in recovered code
44
#![cfg_attr(generic_arg, feature(generic_arg_infer))]
55

6-
76
struct S<'a, T> {
87
a: &'a T,
98
b: &'a T,
109
}
1110

1211
fn foo<'a, 'b>(start: &'a usize, end: &'a usize) {
13-
let _x = (*start..*end)
14-
.map(|x| S { a: start, b: end })
15-
.collect::<Vec<S<_, 'a>>>();
16-
//[generic_arg]~^ ERROR inferred provided when a lifetime was expected
17-
//[full]~^^ ERROR type provided when a lifetime was expected
12+
let _x = (*start..*end).map(|x| S { a: start, b: end }).collect::<Vec<S<_, 'a>>>();
13+
//[generic_arg]~^ ERROR placeholder provided when a lifetime was expected
14+
//[full]~^^ ERROR placeholder provided when a lifetime was expected
1815
}
1916

2017
fn main() {}

tests/ui/span/issue-42234-unknown-receiver-type.generic_arg.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ error[E0282]: type annotations needed
1717
LL | .sum::<_>()
1818
| ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
1919
|
20-
help: consider specifying the generic argument
21-
|
22-
LL | .sum::<S>()
23-
| ~~~~~
2420

2521
error: aborting due to 2 previous errors
2622

tests/ui/type-alias-impl-trait/issue-77179.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
2828
--> $DIR/issue-77179.rs:18:25
2929
|
3030
LL | fn bar() -> Pointer<_>;
31-
| ^
32-
| |
33-
| not allowed in type signatures
34-
| help: use type parameters instead: `T`
31+
| ^ not allowed in type signatures
3532

3633
error: aborting due to 3 previous errors
3734

tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
type Pat<const START: u32, const END: u32> =
55
std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>);
66
//~^ ERROR type and const arguments are not allowed on const parameter `START`
7-
//~| ERROR type arguments are not allowed on const parameter `END`
7+
//~| ERROR generic arguments are not allowed on const parameter `END`
88
//~| ERROR associated item constraints are not allowed here
99

1010
fn main() {}

tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ note: const parameter `START` defined here
1212
LL | type Pat<const START: u32, const END: u32> =
1313
| ^^^^^
1414

15-
error[E0109]: type arguments are not allowed on const parameter `END`
15+
error[E0109]: generic arguments are not allowed on const parameter `END`
1616
--> $DIR/bad_const_generics_args_on_const_param.rs:5:64
1717
|
1818
LL | std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>);
19-
| --- ^ type argument not allowed
19+
| --- ^ generic argument not allowed
2020
| |
2121
| not allowed on const parameter `END`
2222
|

tests/ui/typeck/typeck_type_placeholder_item.stderr

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -507,22 +507,12 @@ LL | impl BadTrait<_> for BadStruct<_> {}
507507
| ^ ^ not allowed in type signatures
508508
| |
509509
| not allowed in type signatures
510-
|
511-
help: use type parameters instead
512-
|
513-
LL | impl<T> BadTrait<T> for BadStruct<T> {}
514-
| +++ ~ ~
515510

516511
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
517512
--> $DIR/typeck_type_placeholder_item.rs:162:34
518513
|
519514
LL | fn impl_trait() -> impl BadTrait<_> {
520515
| ^ not allowed in type signatures
521-
|
522-
help: use type parameters instead
523-
|
524-
LL | fn impl_trait<T>() -> impl BadTrait<T> {
525-
| +++ ~
526516

527517
error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs
528518
--> $DIR/typeck_type_placeholder_item.rs:167:25

0 commit comments

Comments
 (0)