Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/proc-macro/auxiliary/quote-issue-137345.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions tests/ui/proc-macro/valid-sugg-issue-137345.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions tests/ui/proc-macro/valid-sugg-issue-137345.stderr
Original file line number Diff line number Diff line change
@@ -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