Skip to content

Commit bf48c85

Browse files
committed
Switch to trait for checking iterator in repetition
1 parent d3b4777 commit bf48c85

File tree

6 files changed

+23
-26
lines changed

6 files changed

+23
-26
lines changed

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ macro_rules! quote_token_with_context {
890890
use $crate::__private::ext::*;
891891
let has_iter = $crate::__private::ThereIsNoIteratorInRepetition;
892892
$crate::pounded_var_names!{quote_bind_into_iter!(has_iter) () $($inner)*}
893-
let _: $crate::__private::HasIterator = has_iter;
893+
<_ as $crate::__private::CheckHasIterator>::check(has_iter);
894894
// This is `while true` instead of `loop` because if there are no
895895
// iterators used inside of this repetition then the body would not
896896
// contain any `break`, so the compiler would emit unreachable code
@@ -913,7 +913,7 @@ macro_rules! quote_token_with_context {
913913
let mut _i = 0usize;
914914
let has_iter = $crate::__private::ThereIsNoIteratorInRepetition;
915915
$crate::pounded_var_names!{quote_bind_into_iter!(has_iter) () $($inner)*}
916-
let _: $crate::__private::HasIterator = has_iter;
916+
<_ as $crate::__private::CheckHasIterator>::check(has_iter);
917917
while true {
918918
$crate::pounded_var_names!{quote_bind_next_or_break!() () $($inner)*}
919919
if _i > 0 {
@@ -960,7 +960,7 @@ macro_rules! quote_token_with_context_spanned {
960960
use $crate::__private::ext::*;
961961
let has_iter = $crate::__private::ThereIsNoIteratorInRepetition;
962962
$crate::pounded_var_names!{quote_bind_into_iter!(has_iter) () $($inner)*}
963-
let _: $crate::__private::HasIterator = has_iter;
963+
<_ as $crate::__private::CheckHasIterator>::check(has_iter);
964964
while true {
965965
$crate::pounded_var_names!{quote_bind_next_or_break!() () $($inner)*}
966966
$crate::quote_each_token_spanned!{$tokens $span $($inner)*}
@@ -974,7 +974,7 @@ macro_rules! quote_token_with_context_spanned {
974974
let mut _i = 0usize;
975975
let has_iter = $crate::__private::ThereIsNoIteratorInRepetition;
976976
$crate::pounded_var_names!{quote_bind_into_iter!(has_iter) () $($inner)*}
977-
let _: $crate::__private::HasIterator = has_iter;
977+
<_ as $crate::__private::CheckHasIterator>::check(has_iter);
978978
while true {
979979
$crate::pounded_var_names!{quote_bind_next_or_break!() () $($inner)*}
980980
if _i > 0 {

src/runtime.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ impl BitOr<HasIterator> for HasIterator {
5050
}
5151
}
5252

53+
#[doc(hidden)]
54+
pub trait CheckHasIterator: Sized {
55+
fn check(self) {}
56+
}
57+
58+
impl CheckHasIterator for HasIterator {}
59+
5360
/// Extension traits used by the implementation of `quote!`. These are defined
5461
/// in separate traits, rather than as a single trait due to ambiguity issues.
5562
///
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
error[E0308]: mismatched types
1+
error[E0277]: the trait bound `ThereIsNoIteratorInRepetition: CheckHasIterator` is not satisfied
22
--> tests/ui/does-not-have-iter-interpolated-dup.rs:8:5
33
|
44
8 | quote!(#(#nonrep #nonrep)*);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
8-
| expected due to this
9-
| here the type of `has_iter` is inferred to be `ThereIsNoIteratorInRepetition`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `CheckHasIterator` is not implemented for `ThereIsNoIteratorInRepetition`
106
|
7+
= help: the trait `CheckHasIterator` is implemented for `HasIterator`
118
= note: this error originates in the macro `$crate::quote_token_with_context` which comes from the expansion of the macro `quote` (in Nightly builds, run with -Z macro-backtrace for more info)
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
error[E0308]: mismatched types
1+
error[E0277]: the trait bound `ThereIsNoIteratorInRepetition: CheckHasIterator` is not satisfied
22
--> tests/ui/does-not-have-iter-interpolated.rs:8:5
33
|
44
8 | quote!(#(#nonrep)*);
5-
| ^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
8-
| expected due to this
9-
| here the type of `has_iter` is inferred to be `ThereIsNoIteratorInRepetition`
5+
| ^^^^^^^^^^^^^^^^^^^ the trait `CheckHasIterator` is not implemented for `ThereIsNoIteratorInRepetition`
106
|
7+
= help: the trait `CheckHasIterator` is implemented for `HasIterator`
118
= note: this error originates in the macro `$crate::quote_token_with_context` which comes from the expansion of the macro `quote` (in Nightly builds, run with -Z macro-backtrace for more info)
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0308]: mismatched types
1+
error[E0277]: the trait bound `ThereIsNoIteratorInRepetition: CheckHasIterator` is not satisfied
22
--> tests/ui/does-not-have-iter-separated.rs:4:5
33
|
44
4 | quote!(#(a b),*);
5-
| ^^^^^^^^^^^^^^^^
6-
| |
7-
| expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
8-
| expected due to this
5+
| ^^^^^^^^^^^^^^^^ the trait `CheckHasIterator` is not implemented for `ThereIsNoIteratorInRepetition`
96
|
7+
= help: the trait `CheckHasIterator` is implemented for `HasIterator`
108
= note: this error originates in the macro `$crate::quote_token_with_context` which comes from the expansion of the macro `quote` (in Nightly builds, run with -Z macro-backtrace for more info)

tests/ui/does-not-have-iter.stderr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0308]: mismatched types
1+
error[E0277]: the trait bound `ThereIsNoIteratorInRepetition: CheckHasIterator` is not satisfied
22
--> tests/ui/does-not-have-iter.rs:4:5
33
|
44
4 | quote!(#(a b)*);
5-
| ^^^^^^^^^^^^^^^
6-
| |
7-
| expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
8-
| expected due to this
5+
| ^^^^^^^^^^^^^^^ the trait `CheckHasIterator` is not implemented for `ThereIsNoIteratorInRepetition`
96
|
7+
= help: the trait `CheckHasIterator` is implemented for `HasIterator`
108
= note: this error originates in the macro `$crate::quote_token_with_context` which comes from the expansion of the macro `quote` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)