1
Fork 0

Bless and add tests

This commit is contained in:
Boxy 2025-01-08 21:05:35 +00:00
parent 04d141b1fc
commit 6833c27090
23 changed files with 172 additions and 73 deletions

View file

@ -4637,3 +4637,6 @@ fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Deb
} }
DebugFn(f) DebugFn(f)
} }
#[cfg(test)]
mod tests;

View file

@ -0,0 +1,83 @@
use rustc_span::def_id::DefIndex;
use super::*;
macro_rules! define_tests {
($($name:ident $kind:ident $variant:ident {$($init:tt)*})*) => {$(
#[test]
fn $name() {
let unambig = $kind::$variant::<'_, ()> { $($init)* };
let unambig_to_ambig = unsafe { std::mem::transmute::<_, $kind<'_, AmbigArg>>(unambig) };
assert!(matches!(&unambig_to_ambig, $kind::$variant { $($init)* }));
let ambig_to_unambig = unsafe { std::mem::transmute::<_, $kind<'_, ()>>(unambig_to_ambig) };
assert!(matches!(&ambig_to_unambig, $kind::$variant { $($init)* }));
}
)*};
}
define_tests! {
cast_never TyKind Never {}
cast_tup TyKind Tup { 0: &[Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never }] }
cast_ptr TyKind Ptr { 0: MutTy { ty: &Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never }, mutbl: Mutability::Not }}
cast_array TyKind Array {
0: &Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never },
1: &ConstArg { hir_id: HirId::INVALID, kind: ConstArgKind::Anon(&AnonConst {
hir_id: HirId::INVALID,
def_id: LocalDefId { local_def_index: DefIndex::ZERO },
body: BodyId { hir_id: HirId::INVALID },
span: DUMMY_SP,
})}
}
cast_anon ConstArgKind Anon {
0: &AnonConst {
hir_id: HirId::INVALID,
def_id: LocalDefId { local_def_index: DefIndex::ZERO },
body: BodyId { hir_id: HirId::INVALID },
span: DUMMY_SP,
}
}
}
#[test]
fn trait_object_roundtrips() {
trait_object_roundtrips_impl(TraitObjectSyntax::Dyn);
trait_object_roundtrips_impl(TraitObjectSyntax::DynStar);
trait_object_roundtrips_impl(TraitObjectSyntax::None);
}
fn trait_object_roundtrips_impl(syntax: TraitObjectSyntax) {
let unambig = TyKind::TraitObject::<'_, ()>(
&[],
TaggedRef::new(
&const {
Lifetime {
hir_id: HirId::INVALID,
ident: Ident::new(sym::name, DUMMY_SP),
res: LifetimeName::Static,
}
},
syntax,
),
);
let unambig_to_ambig = unsafe { std::mem::transmute::<_, TyKind<'_, AmbigArg>>(unambig) };
match unambig_to_ambig {
TyKind::TraitObject(_, tagged_ref) => {
assert!(tagged_ref.tag() == syntax)
}
_ => panic!("`TyKind::TraitObject` did not roundtrip"),
};
let ambig_to_unambig = unsafe { std::mem::transmute::<_, TyKind<'_, ()>>(unambig_to_ambig) };
match ambig_to_unambig {
TyKind::TraitObject(_, tagged_ref) => {
assert!(tagged_ref.tag() == syntax)
}
_ => panic!("`TyKind::TraitObject` did not roundtrip"),
};
}

View file

@ -0,0 +1,9 @@
#![feature(generic_arg_infer, closure_lifetime_binder)]
struct Foo<const N: usize>([u32; N]);
fn main() {
let c = for<'a> |b: &'a Foo<_>| -> u32 { b.0[0] };
//~^ ERROR: implicit types in closure signatures are forbidden when `for<...>` is present
c(&Foo([1_u32; 1]));
}

View file

@ -0,0 +1,10 @@
error: implicit types in closure signatures are forbidden when `for<...>` is present
--> $DIR/forbid_ambig_const_infers.rs:6:33
|
LL | let c = for<'a> |b: &'a Foo<_>| -> u32 { b.0[0] };
| ------- ^
| |
| `for<...>` is here
error: aborting due to 1 previous error

View file

@ -0,0 +1,9 @@
#![feature(generic_arg_infer, closure_lifetime_binder)]
struct Foo<T>(T);
fn main() {
let c = for<'a> |b: &'a Foo<_>| -> u32 { b.0 };
//~^ ERROR: implicit types in closure signatures are forbidden when `for<...>` is present
c(&Foo(1_u32));
}

View file

@ -0,0 +1,10 @@
error: implicit types in closure signatures are forbidden when `for<...>` is present
--> $DIR/forbid_ambig_type_infers.rs:6:33
|
LL | let c = for<'a> |b: &'a Foo<_>| -> u32 { b.0 };
| ------- ^
| |
| `for<...>` is here
error: aborting due to 1 previous error

View file

@ -0,0 +1,7 @@
#![feature(generic_arg_infer, closure_lifetime_binder)]
fn main() {
let c = for<'a> |b: &'a [u32; _]| -> u32 { b[0] };
//~^ ERROR: implicit types in closure signatures are forbidden when `for<...>` is present
c(&[1_u32; 2]);
}

View file

@ -0,0 +1,10 @@
error: implicit types in closure signatures are forbidden when `for<...>` is present
--> $DIR/forbid_const_infer.rs:4:35
|
LL | let c = for<'a> |b: &'a [u32; _]| -> u32 { b[0] };
| ------- ^
| |
| `for<...>` is here
error: aborting due to 1 previous error

View file

@ -18,19 +18,17 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
LL + #![feature(adt_const_params)] LL + #![feature(adt_const_params)]
| |
error[E0747]: type provided when a constant was expected error[E0658]: const arguments cannot yet be inferred with `_`
--> $DIR/issue-62878.rs:10:11 --> $DIR/issue-62878.rs:10:11
| |
LL | foo::<_, { [1] }>(); LL | foo::<_, { [1] }>();
| ^ | ^
| |
= help: const arguments cannot yet be inferred with `_` = note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
LL + #![feature(generic_arg_infer)]
|
error: aborting due to 3 previous errors error: aborting due to 3 previous errors
Some errors have detailed explanations: E0747, E0770. Some errors have detailed explanations: E0658, E0770.
For more information about an error, try `rustc --explain E0747`. For more information about an error, try `rustc --explain E0658`.

View file

@ -8,5 +8,5 @@ fn foo<const N: usize, const A: [u8; N]>() {}
fn main() { fn main() {
foo::<_, { [1] }>(); foo::<_, { [1] }>();
//[min]~^ ERROR: type provided when a constant was expected //[min]~^ ERROR: const arguments cannot yet be inferred with `_`
} }

View file

@ -233,11 +233,6 @@ LL | fn foo<X: K<_, _>>(x: X) {}
| ^ ^ not allowed in type signatures | ^ ^ not allowed in type signatures
| | | |
| not allowed in type signatures | not allowed in type signatures
|
help: use type parameters instead
|
LL | fn foo<X: K<T, T>, T>(x: X) {}
| ~ ~ +++
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
--> $DIR/bad-assoc-ty.rs:54:34 --> $DIR/bad-assoc-ty.rs:54:34

View file

@ -8,17 +8,15 @@ LL | let _y: [u8; _] = [0; 3];
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0747]: type provided when a constant was expected error[E0658]: const arguments cannot yet be inferred with `_`
--> $DIR/feature-gate-generic_arg_infer.rs:18:20 --> $DIR/feature-gate-generic_arg_infer.rs:18:20
| |
LL | let _x = foo::<_>([1,2]); LL | let _x = foo::<_>([1, 2]);
| ^ | ^
| |
= help: const arguments cannot yet be inferred with `_` = note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
LL + #![feature(generic_arg_infer)]
|
error[E0658]: using `_` for array lengths is unstable error[E0658]: using `_` for array lengths is unstable
--> $DIR/feature-gate-generic_arg_infer.rs:11:27 --> $DIR/feature-gate-generic_arg_infer.rs:11:27
@ -32,5 +30,4 @@ LL | let _x: [u8; 3] = [0; _];
error: aborting due to 3 previous errors error: aborting due to 3 previous errors
Some errors have detailed explanations: E0658, E0747. For more information about this error, try `rustc --explain E0658`.
For more information about an error, try `rustc --explain E0658`.

View file

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

View file

@ -3,11 +3,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
| |
LL | impl X<'_, _> {} LL | impl X<'_, _> {}
| ^ not allowed in type signatures | ^ not allowed in type signatures
|
help: use type parameters instead
|
LL | impl<T> X<'_, T> {}
| +++ ~
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -17,13 +17,6 @@ LL | T: Trait<m!()>;
| ---- in this macro invocation | ---- in this macro invocation
| |
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
help: use type parameters instead
|
LL ~ U
LL | };
LL | }
LL ~ struct S<U>(m!(), T)
|
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -1,7 +1,7 @@
error[E0747]: type provided when a lifetime was expected error[E0747]: placeholder provided when a lifetime was expected
--> $DIR/issue-14303-fncall.rs:15:26 --> $DIR/issue-14303-fncall.rs:12:77
| |
LL | .collect::<Vec<S<_, 'a>>>(); LL | let _x = (*start..*end).map(|x| S { a: start, b: end }).collect::<Vec<S<_, 'a>>>();
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -1,7 +1,7 @@
error[E0747]: inferred provided when a lifetime was expected error[E0747]: placeholder provided when a lifetime was expected
--> $DIR/issue-14303-fncall.rs:15:26 --> $DIR/issue-14303-fncall.rs:12:77
| |
LL | .collect::<Vec<S<_, 'a>>>(); LL | let _x = (*start..*end).map(|x| S { a: start, b: end }).collect::<Vec<S<_, 'a>>>();
| ^ | ^
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -3,18 +3,15 @@
// we need the above to avoid ast borrowck failure in recovered code // we need the above to avoid ast borrowck failure in recovered code
#![cfg_attr(generic_arg, feature(generic_arg_infer))] #![cfg_attr(generic_arg, feature(generic_arg_infer))]
struct S<'a, T> { struct S<'a, T> {
a: &'a T, a: &'a T,
b: &'a T, b: &'a T,
} }
fn foo<'a, 'b>(start: &'a usize, end: &'a usize) { fn foo<'a, 'b>(start: &'a usize, end: &'a usize) {
let _x = (*start..*end) let _x = (*start..*end).map(|x| S { a: start, b: end }).collect::<Vec<S<_, 'a>>>();
.map(|x| S { a: start, b: end }) //[generic_arg]~^ ERROR placeholder provided when a lifetime was expected
.collect::<Vec<S<_, 'a>>>(); //[full]~^^ ERROR placeholder provided when a lifetime was expected
//[generic_arg]~^ ERROR inferred provided when a lifetime was expected
//[full]~^^ ERROR type provided when a lifetime was expected
} }
fn main() {} fn main() {}

View file

@ -17,10 +17,6 @@ error[E0282]: type annotations needed
LL | .sum::<_>() LL | .sum::<_>()
| ^^^ cannot infer type of the type parameter `S` declared on the method `sum` | ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
| |
help: consider specifying the generic argument
|
LL | .sum::<S>()
| ~~~~~
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -28,10 +28,7 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
--> $DIR/issue-77179.rs:18:25 --> $DIR/issue-77179.rs:18:25
| |
LL | fn bar() -> Pointer<_>; LL | fn bar() -> Pointer<_>;
| ^ | ^ not allowed in type signatures
| |
| not allowed in type signatures
| help: use type parameters instead: `T`
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View file

@ -4,7 +4,7 @@
type Pat<const START: u32, const END: u32> = type Pat<const START: u32, const END: u32> =
std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>); std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>);
//~^ ERROR type and const arguments are not allowed on const parameter `START` //~^ ERROR type and const arguments are not allowed on const parameter `START`
//~| ERROR type arguments are not allowed on const parameter `END` //~| ERROR generic arguments are not allowed on const parameter `END`
//~| ERROR associated item constraints are not allowed here //~| ERROR associated item constraints are not allowed here
fn main() {} fn main() {}

View file

@ -12,11 +12,11 @@ note: const parameter `START` defined here
LL | type Pat<const START: u32, const END: u32> = LL | type Pat<const START: u32, const END: u32> =
| ^^^^^ | ^^^^^
error[E0109]: type arguments are not allowed on const parameter `END` error[E0109]: generic arguments are not allowed on const parameter `END`
--> $DIR/bad_const_generics_args_on_const_param.rs:5:64 --> $DIR/bad_const_generics_args_on_const_param.rs:5:64
| |
LL | std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>); LL | std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>);
| --- ^ type argument not allowed | --- ^ generic argument not allowed
| | | |
| not allowed on const parameter `END` | not allowed on const parameter `END`
| |

View file

@ -507,22 +507,12 @@ LL | impl BadTrait<_> for BadStruct<_> {}
| ^ ^ not allowed in type signatures | ^ ^ not allowed in type signatures
| | | |
| not allowed in type signatures | not allowed in type signatures
|
help: use type parameters instead
|
LL | impl<T> BadTrait<T> for BadStruct<T> {}
| +++ ~ ~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
--> $DIR/typeck_type_placeholder_item.rs:162:34 --> $DIR/typeck_type_placeholder_item.rs:162:34
| |
LL | fn impl_trait() -> impl BadTrait<_> { LL | fn impl_trait() -> impl BadTrait<_> {
| ^ not allowed in type signatures | ^ not allowed in type signatures
|
help: use type parameters instead
|
LL | fn impl_trait<T>() -> impl BadTrait<T> {
| +++ ~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs
--> $DIR/typeck_type_placeholder_item.rs:167:25 --> $DIR/typeck_type_placeholder_item.rs:167:25