-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
172 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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])); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters