Skip to content

Commit 75b9f53

Browse files
committed
Fix rust-lang#107113, avoid suggest for macro attributes
1 parent 7a5d2d0 commit 75b9f53

File tree

8 files changed

+63
-2
lines changed

8 files changed

+63
-2
lines changed

compiler/rustc_hir_typeck/src/demand.rs

+3
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
880880
expected: Ty<'tcx>,
881881
expr_ty: Ty<'tcx>,
882882
) -> bool {
883+
if in_external_macro(self.tcx.sess, expr.span) {
884+
return false;
885+
}
883886
if let ty::Adt(expected_adt, args) = expected.kind() {
884887
if let hir::ExprKind::Field(base, ident) = expr.kind {
885888
let base_ty = self.typeck_results.borrow().expr_ty(base);

compiler/rustc_middle/src/lint.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,11 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
449449
match expn_data.kind {
450450
ExpnKind::Root
451451
| ExpnKind::Desugaring(
452-
DesugaringKind::ForLoop | DesugaringKind::WhileLoop | DesugaringKind::OpaqueTy,
452+
DesugaringKind::ForLoop
453+
| DesugaringKind::WhileLoop
454+
| DesugaringKind::OpaqueTy
455+
| DesugaringKind::Async
456+
| DesugaringKind::Await,
453457
) => false,
454458
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
455459
ExpnKind::Macro(MacroKind::Bang, _) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// run-rustfix
2+
// edition:2018
3+
fn _consume_reference<T: ?Sized>(_: &T) {}
4+
5+
async fn _foo() {
6+
_consume_reference::<i32>(&Box::new(7_i32));
7+
_consume_reference::<i32>(&*async { Box::new(7_i32) }.await);
8+
//~^ ERROR mismatched types
9+
_consume_reference::<[i32]>(&vec![7_i32]);
10+
_consume_reference::<[i32]>(&async { vec![7_i32] }.await);
11+
}
12+
13+
fn main() { }

tests/ui/coercion/coerce-block-tail-83783.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// check-fail
1+
// run-rustfix
22
// edition:2018
33
fn _consume_reference<T: ?Sized>(_: &T) {}
44

tests/ui/coercion/coerce-block-tail-83783.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ LL | _consume_reference::<i32>(&async { Box::new(7_i32) }.await);
66
|
77
= note: expected type `i32`
88
found struct `Box<i32>`
9+
help: consider unboxing the value
10+
|
11+
LL | _consume_reference::<i32>(&*async { Box::new(7_i32) }.await);
12+
| +
913

1014
error: aborting due to previous error
1115

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
8+
use proc_macro::TokenStream;
9+
10+
#[proc_macro_attribute]
11+
pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
12+
"fn main() -> std::io::Result<()> { () } ".parse().unwrap()
13+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// edition:2021
2+
// aux-build:issue-107113.rs
3+
4+
#[macro_use]
5+
extern crate issue_107113;
6+
7+
#[issue_107113::main] //~ ERROR mismatched types [E0308]
8+
async fn main() -> std::io::Result<()> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-107113-wrap.rs:7:1
3+
|
4+
LL | #[issue_107113::main]
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| expected `Result<(), Error>`, found `()`
8+
| expected `Result<(), std::io::Error>` because of return type
9+
|
10+
= note: expected enum `Result<(), std::io::Error>`
11+
found unit type `()`
12+
= note: this error originates in the attribute macro `issue_107113::main` (in Nightly builds, run with -Z macro-backtrace for more info)
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)