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
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
};

let mut local_visitor = FindInferSourceVisitor::new(self, typeck_results, term, ty);
let mut body_from_expansion = false;
if let Some(body) =
self.tcx.hir_maybe_body_owned_by(self.tcx.typeck_root_def_id_local(body_def_id))
{
let expr = body.value;
local_visitor.visit_expr(expr);
body_from_expansion = body.value.span.from_expansion();
}

let Some(InferSource { span, kind }) = local_visitor.infer_source else {
Expand Down Expand Up @@ -566,6 +568,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
term,
&arg_data,
typeck_results,
body_from_expansion,
span,
);

Expand Down Expand Up @@ -705,6 +708,7 @@ impl<'tcx> InferSourceKind<'tcx> {
term: Term<'tcx>,
arg_data: &'local InferenceDiagnosticsData,
typeck_results: &TypeckResults<'tcx>,
body_from_expansion: bool,
span: Span,
) -> Option<SourceKindSubdiag<'local>>
where
Expand Down Expand Up @@ -799,7 +803,7 @@ impl<'tcx> InferSourceKind<'tcx> {
p.into_buffer()
};

let suggestion = if have_turbofish {
let suggestion = if have_turbofish || body_from_expansion {
None
} else if generic_args.len() == 1 && used_fallback {
match param.kind {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//@ edition: 2018
#![feature(proc_macro_quote)]
use proc_macro::{TokenStream, Ident, TokenTree, quote};

#[proc_macro_derive(Serialize, attributes(serde))]
pub fn serialize(input: TokenStream) -> TokenStream {
assert_eq!(
input.to_string(),
"pub struct Matrix { #[serde(serialize_with = \"f\")] matrix: (), }"
);

let TokenTree::Group(group) = input.into_iter().last().unwrap() else {
panic!("unexpected group");
};

let TokenTree::Group(group) = group.stream().into_iter().nth(1).unwrap() else {
panic!("expected group");
};

let TokenTree::Group(group) = group.stream().into_iter().nth(1).unwrap() else {
panic!("expected group");
};

let TokenTree::Literal(lit) = group.stream().into_iter().nth(2).unwrap() else {
panic!("expected literal");
};

let ident = Ident::new("f", lit.span());

quote! {
fn serialize() {
$ident();
}
}
.into()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@ proc-macro: derive-attribute-annotation-needed.rs
//@ edition: 2018


use derive_attribute_annotation_needed::Serialize;

fn f<T>() {}

#[derive(Serialize)]
pub struct Matrix {
#[serde(serialize_with = "f")]
//~^ ERROR type annotations needed
matrix: (),
}

fn main() {
f();
//~^ ERROR type annotations needed
//~| HELP consider specifying a concrete type for the type parameter `T`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0282]: type annotations needed
--> $DIR/derive-attribute-annotation-needed.rs:11:30
|
LL | #[serde(serialize_with = "f")]
| ^^^ cannot infer type of the type parameter `T` declared on the function `f`

error[E0282]: type annotations needed
--> $DIR/derive-attribute-annotation-needed.rs:17:5
|
LL | f();
| ^ cannot infer type of the type parameter `T` declared on the function `f`
|
help: consider specifying a concrete type for the type parameter `T`
|
LL | f::</* Type */>();
| ++++++++++++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0282`.
Loading