Tighter spans
This commit is contained in:
parent
9eae77381e
commit
00dc3b24b7
@ -20,7 +20,7 @@ use rustc_hir::{MethodKind, Target, Unsafety};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::error::ExpectedFound;
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_session::lint::builtin::{
|
||||
@ -2213,7 +2213,7 @@ impl CheckAttrVisitor<'_> {
|
||||
tcx.fn_sig(def_id).subst(tcx, fresh_substs),
|
||||
);
|
||||
|
||||
let cause = ObligationCause::misc(span, def_id);
|
||||
let mut cause = ObligationCause::misc(span, def_id);
|
||||
let sig = ocx.normalize(&cause, param_env, sig);
|
||||
|
||||
// proc macro is not WF.
|
||||
@ -2235,6 +2235,39 @@ impl CheckAttrVisitor<'_> {
|
||||
|
||||
if let Err(terr) = ocx.eq(&cause, param_env, expected_sig, sig) {
|
||||
let mut diag = tcx.sess.create_err(errors::ProcMacroBadSig { span, kind });
|
||||
|
||||
let hir_sig = tcx.hir().fn_sig_by_hir_id(hir_id);
|
||||
if let Some(hir_sig) = hir_sig {
|
||||
match terr {
|
||||
TypeError::ArgumentMutability(idx) | TypeError::ArgumentSorts(_, idx) => {
|
||||
if let Some(ty) = hir_sig.decl.inputs.get(idx) {
|
||||
diag.set_span(ty.span);
|
||||
cause.span = ty.span;
|
||||
} else if idx == hir_sig.decl.inputs.len() {
|
||||
let span = hir_sig.decl.output.span();
|
||||
diag.set_span(span);
|
||||
cause.span = span;
|
||||
}
|
||||
}
|
||||
TypeError::ArgCount => {
|
||||
if let Some(ty) = hir_sig.decl.inputs.get(expected_sig.inputs().len()) {
|
||||
diag.set_span(ty.span);
|
||||
cause.span = ty.span;
|
||||
}
|
||||
}
|
||||
TypeError::UnsafetyMismatch(_) => {
|
||||
// FIXME: Would be nice if we had a span here..
|
||||
}
|
||||
TypeError::AbiMismatch(_) => {
|
||||
// FIXME: Would be nice if we had a span here..
|
||||
}
|
||||
TypeError::VariadicMismatch(_) => {
|
||||
// FIXME: Would be nice if we had a span here..
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
infcx.err_ctxt().note_type_err(
|
||||
&mut diag,
|
||||
&cause,
|
||||
|
@ -26,10 +26,10 @@ LL | pub fn bad_everything(input: String) -> String {
|
||||
found signature `fn(std::string::String) -> std::string::String`
|
||||
|
||||
error: attribute proc macro has incorrect signature
|
||||
--> $DIR/signature-proc-macro-attribute.rs:28:1
|
||||
--> $DIR/signature-proc-macro-attribute.rs:28:52
|
||||
|
|
||||
LL | pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
|
||||
| ^^^^^^ incorrect number of function parameters
|
||||
|
|
||||
= note: expected signature `fn(proc_macro::TokenStream, proc_macro::TokenStream) -> proc_macro::TokenStream`
|
||||
found signature `fn(proc_macro::TokenStream, proc_macro::TokenStream, std::string::String) -> proc_macro::TokenStream`
|
||||
|
@ -1,35 +1,35 @@
|
||||
error: derive proc macro has incorrect signature
|
||||
--> $DIR/signature-proc-macro-derive.rs:10:1
|
||||
--> $DIR/signature-proc-macro-derive.rs:10:25
|
||||
|
|
||||
LL | pub fn bad_input(input: String) -> TokenStream {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
| ^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
|
|
||||
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
|
||||
found signature `fn(std::string::String) -> proc_macro::TokenStream`
|
||||
|
||||
error: derive proc macro has incorrect signature
|
||||
--> $DIR/signature-proc-macro-derive.rs:16:1
|
||||
--> $DIR/signature-proc-macro-derive.rs:16:42
|
||||
|
|
||||
LL | pub fn bad_output(input: TokenStream) -> String {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
| ^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
|
|
||||
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
|
||||
found signature `fn(proc_macro::TokenStream) -> std::string::String`
|
||||
|
||||
error: derive proc macro has incorrect signature
|
||||
--> $DIR/signature-proc-macro-derive.rs:22:1
|
||||
--> $DIR/signature-proc-macro-derive.rs:22:30
|
||||
|
|
||||
LL | pub fn bad_everything(input: String) -> String {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
| ^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
|
|
||||
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
|
||||
found signature `fn(std::string::String) -> std::string::String`
|
||||
|
||||
error: derive proc macro has incorrect signature
|
||||
--> $DIR/signature-proc-macro-derive.rs:28:1
|
||||
--> $DIR/signature-proc-macro-derive.rs:28:36
|
||||
|
|
||||
LL | pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
|
||||
| ^^^^^^^^^^^ incorrect number of function parameters
|
||||
|
|
||||
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
|
||||
found signature `fn(proc_macro::TokenStream, proc_macro::TokenStream, std::string::String) -> proc_macro::TokenStream`
|
||||
|
@ -1,35 +1,35 @@
|
||||
error: function-like proc macro has incorrect signature
|
||||
--> $DIR/signature-proc-macro.rs:10:1
|
||||
--> $DIR/signature-proc-macro.rs:10:25
|
||||
|
|
||||
LL | pub fn bad_input(input: String) -> TokenStream {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
| ^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
|
|
||||
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
|
||||
found signature `fn(std::string::String) -> proc_macro::TokenStream`
|
||||
|
||||
error: function-like proc macro has incorrect signature
|
||||
--> $DIR/signature-proc-macro.rs:16:1
|
||||
--> $DIR/signature-proc-macro.rs:16:42
|
||||
|
|
||||
LL | pub fn bad_output(input: TokenStream) -> String {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
| ^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
|
|
||||
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
|
||||
found signature `fn(proc_macro::TokenStream) -> std::string::String`
|
||||
|
||||
error: function-like proc macro has incorrect signature
|
||||
--> $DIR/signature-proc-macro.rs:22:1
|
||||
--> $DIR/signature-proc-macro.rs:22:30
|
||||
|
|
||||
LL | pub fn bad_everything(input: String) -> String {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
| ^^^^^^ expected `proc_macro::TokenStream`, found `std::string::String`
|
||||
|
|
||||
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
|
||||
found signature `fn(std::string::String) -> std::string::String`
|
||||
|
||||
error: function-like proc macro has incorrect signature
|
||||
--> $DIR/signature-proc-macro.rs:28:1
|
||||
--> $DIR/signature-proc-macro.rs:28:36
|
||||
|
|
||||
LL | pub fn too_many(a: TokenStream, b: TokenStream, c: String) -> TokenStream {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
|
||||
| ^^^^^^^^^^^ incorrect number of function parameters
|
||||
|
|
||||
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
|
||||
found signature `fn(proc_macro::TokenStream, proc_macro::TokenStream, std::string::String) -> proc_macro::TokenStream`
|
||||
|
Loading…
x
Reference in New Issue
Block a user