Skip to content

Commit 57628de

Browse files
committed
Check std::prelude hygiene in codegen tests (#1195, #1194)
1 parent a433a27 commit 57628de

19 files changed

+808
-711
lines changed

juniper/src/macros/reflect.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -693,17 +693,19 @@ macro_rules! assert_field_args {
693693
$field_name: expr $(,)?
694694
) => {
695695
const _: () = {
696-
const BASE_NAME: &str = <$base_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME;
697-
const IMPL_NAME: &str = <$impl_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME;
698-
const ERR_PREFIX: &str = $crate::const_concat!(
696+
const BASE_NAME: &::core::primitive::str =
697+
<$base_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME;
698+
const IMPL_NAME: &::core::primitive::str =
699+
<$impl_ty as $crate::macros::reflect::BaseType<$scalar>>::NAME;
700+
const ERR_PREFIX: &::core::primitive::str = $crate::const_concat!(
699701
"Failed to implement interface `",
700702
BASE_NAME,
701703
"` on `",
702704
IMPL_NAME,
703705
"`: ",
704706
);
705707

706-
const FIELD_NAME: &str = $field_name;
708+
const FIELD_NAME: &::core::primitive::str = $field_name;
707709

708710
const BASE_ARGS: ::juniper::macros::reflect::Arguments =
709711
<$base_ty as $crate::macros::reflect::FieldMeta<
@@ -728,20 +730,20 @@ macro_rules! assert_field_args {
728730
TypeMismatch,
729731
}
730732

731-
const fn unwrap_error(v: ::std::result::Result<(), Error>) -> Error {
733+
const fn unwrap_error(v: ::core::result::Result<(), Error>) -> Error {
732734
match v {
733735
// Unfortunately we can't use `unreachable!()` here, as this
734736
// branch will be executed either way.
735-
Ok(()) => Error {
737+
::core::result::Result::Ok(()) => Error {
736738
cause: Cause::RequiredField,
737739
base: ("unreachable", "unreachable", 1),
738740
implementation: ("unreachable", "unreachable", 1),
739741
},
740-
Err(err) => err,
742+
::core::result::Result::Err(err) => err,
741743
}
742744
}
743745

744-
const fn check() -> Result<(), Error> {
746+
const fn check() -> ::core::result::Result<(), Error> {
745747
let mut base_i = 0;
746748
while base_i < BASE_ARGS.len() {
747749
let (base_name, base_type, base_wrap_val) = BASE_ARGS[base_i];
@@ -800,18 +802,18 @@ macro_rules! assert_field_args {
800802
base_i += 1;
801803
}
802804
if !was_found {
803-
return Err(Error {
805+
return ::core::result::Result::Err(Error {
804806
cause: Cause::AdditionalNonNullableField,
805807
base: (impl_name, impl_type, impl_wrapped_val),
806808
implementation: (impl_name, impl_type, impl_wrapped_val),
807809
});
808810
}
809811
}
810812

811-
Ok(())
813+
::core::result::Result::Ok(())
812814
}
813815

814-
const RES: ::std::result::Result<(), Error> = check();
816+
const RES: ::core::result::Result<(), Error> = check();
815817
if RES.is_err() {
816818
const ERROR: Error = unwrap_error(RES);
817819

@@ -822,7 +824,7 @@ macro_rules! assert_field_args {
822824
const IMPL_TYPE_FORMATTED: &str =
823825
$crate::format_type!(ERROR.implementation.1, ERROR.implementation.2);
824826

825-
const MSG: &str = match ERROR.cause {
827+
const MSG: &::core::primitive::str = match ERROR.cause {
826828
Cause::TypeMismatch => {
827829
$crate::const_concat!(
828830
"Argument `",
@@ -865,9 +867,9 @@ macro_rules! assert_field_args {
865867
#[macro_export]
866868
macro_rules! const_concat {
867869
($($s:expr),* $(,)?) => {{
868-
const LEN: usize = 0 $(+ $s.as_bytes().len())*;
869-
const CNT: usize = [$($s),*].len();
870-
const fn concat(input: [&str; CNT]) -> [u8; LEN] {
870+
const LEN: ::core::primitive::usize = 0 $(+ $s.as_bytes().len())*;
871+
const CNT: ::core::primitive::usize = [$($s),*].len();
872+
const fn concat(input: [&::core::primitive::str; CNT]) -> [::core::primitive::u8; LEN] {
871873
let mut bytes = [0; LEN];
872874
let (mut i, mut byte) = (0, 0);
873875
while i < CNT {
@@ -881,12 +883,12 @@ macro_rules! const_concat {
881883
}
882884
bytes
883885
}
884-
const CON: [u8; LEN] = concat([$($s),*]);
886+
const CON: [::core::primitive::u8; LEN] = concat([$($s),*]);
885887

886888
// TODO: Use `.unwrap()` once it becomes `const`.
887-
match ::std::str::from_utf8(&CON) {
888-
::std::result::Result::Ok(s) => s,
889-
_ => unreachable!(),
889+
match ::core::str::from_utf8(&CON) {
890+
::core::result::Result::Ok(s) => s,
891+
_ => ::core::unreachable!(),
890892
}
891893
}};
892894
}
@@ -936,13 +938,13 @@ macro_rules! format_type {
936938
) = ($ty, $wrapped_value);
937939
const RES_LEN: usize = $crate::macros::reflect::type_len_with_wrapped_val(TYPE.0, TYPE.1);
938940

939-
const OPENING_BRACKET: &str = "[";
940-
const CLOSING_BRACKET: &str = "]";
941-
const BANG: &str = "!";
941+
const OPENING_BRACKET: &::core::primitive::str = "[";
942+
const CLOSING_BRACKET: &::core::primitive::str = "]";
943+
const BANG: &::core::primitive::str = "!";
942944

943-
const fn format_type_arr() -> [u8; RES_LEN] {
945+
const fn format_type_arr() -> [::core::primitive::u8; RES_LEN] {
944946
let (ty, wrap_val) = TYPE;
945-
let mut type_arr: [u8; RES_LEN] = [0; RES_LEN];
947+
let mut type_arr: [::core::primitive::u8; RES_LEN] = [0; RES_LEN];
946948

947949
let mut current_start = 0;
948950
let mut current_end = RES_LEN - 1;
@@ -1003,13 +1005,14 @@ macro_rules! format_type {
10031005
type_arr
10041006
}
10051007

1006-
const TYPE_ARR: [u8; RES_LEN] = format_type_arr();
1008+
const TYPE_ARR: [::core::primitive::u8; RES_LEN] = format_type_arr();
10071009

10081010
// TODO: Use `.unwrap()` once it becomes `const`.
1009-
const TYPE_FORMATTED: &str = match ::std::str::from_utf8(TYPE_ARR.as_slice()) {
1010-
::std::result::Result::Ok(s) => s,
1011-
_ => unreachable!(),
1012-
};
1011+
const TYPE_FORMATTED: &::core::primitive::str =
1012+
match ::core::str::from_utf8(TYPE_ARR.as_slice()) {
1013+
::core::result::Result::Ok(s) => s,
1014+
_ => unreachable!(),
1015+
};
10131016

10141017
TYPE_FORMATTED
10151018
}};

tests/codegen/pass/local_results.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/codegen/pass/local_send.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/codegen/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,3 @@ fn test_failing_compilation() {
77
let t = trybuild::TestCases::new();
88
t.compile_fail("fail/**/*.rs");
99
}
10-
11-
#[rustversion::nightly]
12-
#[test]
13-
fn test_passing_compilation() {
14-
let t = trybuild::TestCases::new();
15-
t.pass("pass/**/*.rs");
16-
}

tests/integration/tests/codegen_enum_derive.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use juniper::{
99

1010
use self::common::util::{schema, schema_with_scalar};
1111

12+
// Override `std::prelude` items to check whether macros expand hygienically.
13+
#[allow(unused_imports)]
14+
use self::common::hygiene::*;
15+
1216
mod trivial {
1317
use super::*;
1418

@@ -863,7 +867,7 @@ mod bounded_generic_scalar {
863867
use super::*;
864868

865869
#[derive(GraphQLEnum)]
866-
#[graphql(scalar = S: ScalarValue + Clone)]
870+
#[graphql(scalar = S: ScalarValue + prelude::Clone)]
867871
enum Character {
868872
Human,
869873
Droid,
@@ -896,7 +900,7 @@ mod bounded_generic_scalar {
896900
mod explicit_custom_context {
897901
use super::*;
898902

899-
struct CustomContext(String);
903+
struct CustomContext(prelude::String);
900904

901905
impl juniper::Context for CustomContext {}
902906

tests/integration/tests/codegen_input_object_derive.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use juniper::{
99

1010
use self::common::util::schema;
1111

12+
// Override `std::prelude` items to check whether macros expand hygienically.
13+
#[allow(unused_imports)]
14+
use self::common::hygiene::*;
15+
1216
mod trivial {
1317
use super::*;
1418

@@ -267,16 +271,16 @@ mod default_nullable_value {
267271
#[derive(GraphQLInputObject)]
268272
struct Point2D {
269273
#[graphql(default = 10.0)]
270-
x: Option<f64>,
274+
x: prelude::Option<f64>,
271275
#[graphql(default = 10.0)]
272-
y: Option<f64>,
276+
y: prelude::Option<f64>,
273277
}
274278

275279
struct QueryRoot;
276280

277281
#[graphql_object]
278282
impl QueryRoot {
279-
fn x(point: Point2D) -> Option<f64> {
283+
fn x(point: Point2D) -> prelude::Option<f64> {
280284
point.x
281285
}
282286
}

0 commit comments

Comments
 (0)