Skip to content

Commit e780b89

Browse files
authored
Rollup merge of #137415 - chenyukang:yukang-fix-137345-invalid-sugg, r=estebank
Remove invalid suggestion of into_iter for extern macro Fixes #137345 #109082 is closed due to performance issue, do we have any other solution for this kind of issue?
2 parents 88ed69c + c45463e commit e780b89

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
905905
} else if self.impl_into_iterator_should_be_iterator(rcvr_ty, span, unsatisfied_predicates)
906906
{
907907
err.span_label(span, format!("`{rcvr_ty}` is not an iterator"));
908-
err.multipart_suggestion_verbose(
909-
"call `.into_iter()` first",
910-
vec![(span.shrink_to_lo(), format!("into_iter()."))],
911-
Applicability::MaybeIncorrect,
912-
);
908+
if !span.in_external_macro(self.tcx.sess.source_map()) {
909+
err.multipart_suggestion_verbose(
910+
"call `.into_iter()` first",
911+
vec![(span.shrink_to_lo(), format!("into_iter()."))],
912+
Applicability::MaybeIncorrect,
913+
);
914+
}
913915
return err.emit();
914916
} else if !unsatisfied_predicates.is_empty() && matches!(rcvr_ty.kind(), ty::Param(_)) {
915917
// We special case the situation where we are looking for `_` in
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
extern crate proc_macro;
2+
use proc_macro::TokenStream;
3+
4+
fn items() -> impl IntoIterator<Item = i32> {
5+
vec![1, 2, 3]
6+
}
7+
8+
#[macro_export]
9+
macro_rules! quote {
10+
// Rule for any other number of tokens.
11+
($($tt:tt)*) => {{
12+
fn items() -> impl IntoIterator<Item = i32> {
13+
vec![1, 2, 3]
14+
}
15+
let _s = TokenStream::new();
16+
let other_items = items().map(|i| i + 1);
17+
_s
18+
}};
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ aux-crate: quote=quote-issue-137345.rs
2+
3+
extern crate proc_macro;
4+
extern crate quote;
5+
6+
use proc_macro::TokenStream;
7+
8+
pub fn default_args_fn(_: TokenStream) -> TokenStream {
9+
let decl_macro = TokenStream::new();
10+
11+
quote::quote! {
12+
#(#decl_macro)*
13+
}
14+
.into() //~^^^ ERROR no method named `map` found for opaque type
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0599]: no method named `map` found for opaque type `impl IntoIterator<Item = i32>` in the current scope
2+
--> $DIR/valid-sugg-issue-137345.rs:11:5
3+
|
4+
LL | / quote::quote! {
5+
LL | | #(#decl_macro)*
6+
LL | | }
7+
| |_____^ `impl IntoIterator<Item = i32>` is not an iterator
8+
|
9+
= note: this error originates in the macro `quote::quote` (in Nightly builds, run with -Z macro-backtrace for more info)
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)