remove invalid suggestion of into_iter for extern macro
This commit is contained in:
parent
dc37ff82e8
commit
c45463ec8b
4 changed files with 56 additions and 5 deletions
|
|
@ -905,11 +905,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
} else if self.impl_into_iterator_should_be_iterator(rcvr_ty, span, unsatisfied_predicates)
|
||||
{
|
||||
err.span_label(span, format!("`{rcvr_ty}` is not an iterator"));
|
||||
err.multipart_suggestion_verbose(
|
||||
"call `.into_iter()` first",
|
||||
vec![(span.shrink_to_lo(), format!("into_iter()."))],
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
if !span.in_external_macro(self.tcx.sess.source_map()) {
|
||||
err.multipart_suggestion_verbose(
|
||||
"call `.into_iter()` first",
|
||||
vec![(span.shrink_to_lo(), format!("into_iter()."))],
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
return err.emit();
|
||||
} else if !unsatisfied_predicates.is_empty() && matches!(rcvr_ty.kind(), ty::Param(_)) {
|
||||
// We special case the situation where we are looking for `_` in
|
||||
|
|
|
|||
19
tests/ui/proc-macro/auxiliary/quote-issue-137345.rs
Normal file
19
tests/ui/proc-macro/auxiliary/quote-issue-137345.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
fn items() -> impl IntoIterator<Item = i32> {
|
||||
vec![1, 2, 3]
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! quote {
|
||||
// Rule for any other number of tokens.
|
||||
($($tt:tt)*) => {{
|
||||
fn items() -> impl IntoIterator<Item = i32> {
|
||||
vec![1, 2, 3]
|
||||
}
|
||||
let _s = TokenStream::new();
|
||||
let other_items = items().map(|i| i + 1);
|
||||
_s
|
||||
}};
|
||||
}
|
||||
17
tests/ui/proc-macro/valid-sugg-issue-137345.rs
Normal file
17
tests/ui/proc-macro/valid-sugg-issue-137345.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
//@ aux-crate: quote=quote-issue-137345.rs
|
||||
|
||||
extern crate proc_macro;
|
||||
extern crate quote;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
pub fn default_args_fn(_: TokenStream) -> TokenStream {
|
||||
let decl_macro = TokenStream::new();
|
||||
|
||||
quote::quote! {
|
||||
#(#decl_macro)*
|
||||
}
|
||||
.into() //~^^^ ERROR no method named `map` found for opaque type
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
13
tests/ui/proc-macro/valid-sugg-issue-137345.stderr
Normal file
13
tests/ui/proc-macro/valid-sugg-issue-137345.stderr
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
error[E0599]: no method named `map` found for opaque type `impl IntoIterator<Item = i32>` in the current scope
|
||||
--> $DIR/valid-sugg-issue-137345.rs:11:5
|
||||
|
|
||||
LL | / quote::quote! {
|
||||
LL | | #(#decl_macro)*
|
||||
LL | | }
|
||||
| |_____^ `impl IntoIterator<Item = i32>` is not an iterator
|
||||
|
|
||||
= note: this error originates in the macro `quote::quote` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0599`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue