Fix #107113, avoid suggest for macro attributes
This commit is contained in:
parent
7a5d2d0138
commit
75b9f53e47
@ -880,6 +880,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
expected: Ty<'tcx>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
if in_external_macro(self.tcx.sess, expr.span) {
|
||||
return false;
|
||||
}
|
||||
if let ty::Adt(expected_adt, args) = expected.kind() {
|
||||
if let hir::ExprKind::Field(base, ident) = expr.kind {
|
||||
let base_ty = self.typeck_results.borrow().expr_ty(base);
|
||||
|
@ -449,7 +449,11 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
|
||||
match expn_data.kind {
|
||||
ExpnKind::Root
|
||||
| ExpnKind::Desugaring(
|
||||
DesugaringKind::ForLoop | DesugaringKind::WhileLoop | DesugaringKind::OpaqueTy,
|
||||
DesugaringKind::ForLoop
|
||||
| DesugaringKind::WhileLoop
|
||||
| DesugaringKind::OpaqueTy
|
||||
| DesugaringKind::Async
|
||||
| DesugaringKind::Await,
|
||||
) => false,
|
||||
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
|
||||
ExpnKind::Macro(MacroKind::Bang, _) => {
|
||||
|
13
tests/ui/coercion/coerce-block-tail-83783.fixed
Normal file
13
tests/ui/coercion/coerce-block-tail-83783.fixed
Normal file
@ -0,0 +1,13 @@
|
||||
// run-rustfix
|
||||
// edition:2018
|
||||
fn _consume_reference<T: ?Sized>(_: &T) {}
|
||||
|
||||
async fn _foo() {
|
||||
_consume_reference::<i32>(&Box::new(7_i32));
|
||||
_consume_reference::<i32>(&*async { Box::new(7_i32) }.await);
|
||||
//~^ ERROR mismatched types
|
||||
_consume_reference::<[i32]>(&vec![7_i32]);
|
||||
_consume_reference::<[i32]>(&async { vec![7_i32] }.await);
|
||||
}
|
||||
|
||||
fn main() { }
|
@ -1,4 +1,4 @@
|
||||
// check-fail
|
||||
// run-rustfix
|
||||
// edition:2018
|
||||
fn _consume_reference<T: ?Sized>(_: &T) {}
|
||||
|
||||
|
@ -6,6 +6,10 @@ LL | _consume_reference::<i32>(&async { Box::new(7_i32) }.await);
|
||||
|
|
||||
= note: expected type `i32`
|
||||
found struct `Box<i32>`
|
||||
help: consider unboxing the value
|
||||
|
|
||||
LL | _consume_reference::<i32>(&*async { Box::new(7_i32) }.await);
|
||||
| +
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
13
tests/ui/proc-macro/auxiliary/issue-107113.rs
Normal file
13
tests/ui/proc-macro/auxiliary/issue-107113.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// force-host
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "proc-macro"]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||
"fn main() -> std::io::Result<()> { () } ".parse().unwrap()
|
||||
}
|
8
tests/ui/proc-macro/issue-107113-wrap.rs
Normal file
8
tests/ui/proc-macro/issue-107113-wrap.rs
Normal file
@ -0,0 +1,8 @@
|
||||
// edition:2021
|
||||
// aux-build:issue-107113.rs
|
||||
|
||||
#[macro_use]
|
||||
extern crate issue_107113;
|
||||
|
||||
#[issue_107113::main] //~ ERROR mismatched types [E0308]
|
||||
async fn main() -> std::io::Result<()> {}
|
16
tests/ui/proc-macro/issue-107113-wrap.stderr
Normal file
16
tests/ui/proc-macro/issue-107113-wrap.stderr
Normal file
@ -0,0 +1,16 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-107113-wrap.rs:7:1
|
||||
|
|
||||
LL | #[issue_107113::main]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| expected `Result<(), Error>`, found `()`
|
||||
| expected `Result<(), std::io::Error>` because of return type
|
||||
|
|
||||
= note: expected enum `Result<(), std::io::Error>`
|
||||
found unit type `()`
|
||||
= note: this error originates in the attribute macro `issue_107113::main` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
x
Reference in New Issue
Block a user