diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index f2c25c8716783..a56ed668bfdf4 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -189,6 +189,9 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>( vec![] } } + // Synthetic nodes are created by query feeding for items like RPITIT + // opaque types that have no corresponding HIR type to walk. + hir::Node::Synthetic => vec![], ref node => bug!("Unexpected node {:?}", node), }, WellFormedLoc::Param { function: _, param_idx } => { diff --git a/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-2-issue-148630.rs b/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-2-issue-148630.rs new file mode 100644 index 0000000000000..8e490d26a4db9 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-2-issue-148630.rs @@ -0,0 +1,21 @@ +// Regression test for #148630 (simpler reproduction). + +#![feature(unboxed_closures)] + +trait Tr {} +trait Foo { + fn foo() -> impl Sized + //~^ ERROR expected a `FnOnce<&'a i32>` closure, found `()` + //~| ERROR expected a `FnOnce<&'a i32>` closure, found `()` + //~| ERROR expected a `FnOnce<&'a i32>` closure, found `()` + //~| ERROR expected a `FnOnce<&'a i32>` closure, found `()` + //~| ERROR expected a `FnOnce<&'a i32>` closure, found `()` + //~| ERROR expected a `FnOnce<&'a i32>` closure, found `()` + //~| ERROR expected a `FnOnce<&'a i32>` closure, found `()` + where + for<'a> <() as FnOnce<&'a i32>>::Output: Tr, + { + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-2-issue-148630.stderr b/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-2-issue-148630.stderr new file mode 100644 index 0000000000000..5b3b4abf791ef --- /dev/null +++ b/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-2-issue-148630.stderr @@ -0,0 +1,65 @@ +error[E0277]: expected a `FnOnce<&'a i32>` closure, found `()` + --> $DIR/unexpected-node-synthetic-2-issue-148630.rs:7:17 + | +LL | fn foo() -> impl Sized + | ^^^^^^^^^^ expected an `FnOnce<&'a i32>` closure, found `()` + | + = help: the trait `for<'a> FnOnce<&'a i32>` is not implemented for `()` + +error[E0277]: expected a `FnOnce<&'a i32>` closure, found `()` + --> $DIR/unexpected-node-synthetic-2-issue-148630.rs:7:17 + | +LL | fn foo() -> impl Sized + | ^^^^^^^^^^ expected an `FnOnce<&'a i32>` closure, found `()` + | + = help: the trait `for<'a> FnOnce<&'a i32>` is not implemented for `()` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0277]: expected a `FnOnce<&'a i32>` closure, found `()` + --> $DIR/unexpected-node-synthetic-2-issue-148630.rs:7:5 + | +LL | / fn foo() -> impl Sized +... | +LL | | where +LL | | for<'a> <() as FnOnce<&'a i32>>::Output: Tr, + | |____________________________________________________^ expected an `FnOnce<&'a i32>` closure, found `()` + | + = help: the trait `for<'a> FnOnce<&'a i32>` is not implemented for `()` + +error[E0277]: expected a `FnOnce<&'a i32>` closure, found `()` + --> $DIR/unexpected-node-synthetic-2-issue-148630.rs:7:17 + | +LL | fn foo() -> impl Sized + | ^^^^^^^^^^ expected an `FnOnce<&'a i32>` closure, found `()` + | + = help: the trait `for<'a> FnOnce<&'a i32>` is not implemented for `()` + +error[E0277]: expected a `FnOnce<&'a i32>` closure, found `()` + --> $DIR/unexpected-node-synthetic-2-issue-148630.rs:7:22 + | +LL | fn foo() -> impl Sized + | ^^^^^ expected an `FnOnce<&'a i32>` closure, found `()` + | + = help: the trait `for<'a> FnOnce<&'a i32>` is not implemented for `()` + +error[E0277]: expected a `FnOnce<&'a i32>` closure, found `()` + --> $DIR/unexpected-node-synthetic-2-issue-148630.rs:7:17 + | +LL | fn foo() -> impl Sized + | ^^^^^^^^^^ expected an `FnOnce<&'a i32>` closure, found `()` + | + = help: the trait `for<'a> FnOnce<&'a i32>` is not implemented for `()` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0277]: expected a `FnOnce<&'a i32>` closure, found `()` + --> $DIR/unexpected-node-synthetic-2-issue-148630.rs:7:17 + | +LL | fn foo() -> impl Sized + | ^^^^^^^^^^ expected an `FnOnce<&'a i32>` closure, found `()` + | + = help: the trait `for<'a> FnOnce<&'a i32>` is not implemented for `()` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-issue-148630.rs b/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-issue-148630.rs new file mode 100644 index 0000000000000..5f8151d54d823 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-issue-148630.rs @@ -0,0 +1,23 @@ +// Regression test for #148630. + +#![feature(unboxed_closures)] + +use std::future::Future; + +trait Foo { + fn foo() -> impl Sized + //~^ ERROR expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + //~| ERROR expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + //~| ERROR expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + //~| ERROR expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + //~| ERROR expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + //~| ERROR expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + //~| ERROR expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + where + for<'a> >::Output: Future + 'a, + //~^ ERROR the trait `Foo` is not dyn compatible [E0038] + { + } +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-issue-148630.stderr b/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-issue-148630.stderr new file mode 100644 index 0000000000000..cb63cbbff3368 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/unexpected-node-synthetic-issue-148630.stderr @@ -0,0 +1,89 @@ +error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + --> $DIR/unexpected-node-synthetic-issue-148630.rs:8:17 + | +LL | fn foo() -> impl Sized + | ^^^^^^^^^^ expected an `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + | + = help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `(dyn Foo + 'static)` + +error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + --> $DIR/unexpected-node-synthetic-issue-148630.rs:8:17 + | +LL | fn foo() -> impl Sized + | ^^^^^^^^^^ expected an `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + | + = help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `(dyn Foo + 'static)` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + --> $DIR/unexpected-node-synthetic-issue-148630.rs:8:5 + | +LL | / fn foo() -> impl Sized +... | +LL | | where +LL | | for<'a> >::Output: Future + 'a, + | |______________________________________________________________________________________^ expected an `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + | + = help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `(dyn Foo + 'static)` + +error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + --> $DIR/unexpected-node-synthetic-issue-148630.rs:8:17 + | +LL | fn foo() -> impl Sized + | ^^^^^^^^^^ expected an `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + | + = help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `(dyn Foo + 'static)` + +error[E0038]: the trait `Foo` is not dyn compatible + --> $DIR/unexpected-node-synthetic-issue-148630.rs:17:84 + | +LL | for<'a> >::Output: Future + 'a, + | ^^ `Foo` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/unexpected-node-synthetic-issue-148630.rs:8:8 + | +LL | trait Foo { + | --- this trait is not dyn compatible... +LL | fn foo() -> impl Sized + | ^^^ ...because associated function `foo` has no `self` parameter +help: consider turning `foo` into a method by giving it a `&self` argument + | +LL | fn foo(&self) -> impl Sized + | +++++ +help: alternatively, consider constraining `foo` so it does not apply to trait objects + | +LL | for<'a> >::Output: Future + 'a, Self: Sized + | +++++++++++ + +error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + --> $DIR/unexpected-node-synthetic-issue-148630.rs:8:22 + | +LL | fn foo() -> impl Sized + | ^^^^^ expected an `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + | + = help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `(dyn Foo + 'static)` + +error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + --> $DIR/unexpected-node-synthetic-issue-148630.rs:8:17 + | +LL | fn foo() -> impl Sized + | ^^^^^^^^^^ expected an `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + | + = help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `(dyn Foo + 'static)` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + --> $DIR/unexpected-node-synthetic-issue-148630.rs:8:17 + | +LL | fn foo() -> impl Sized + | ^^^^^^^^^^ expected an `FnOnce(&'a mut i32)` closure, found `(dyn Foo + 'static)` + | + = help: the trait `for<'a> FnOnce(&'a mut i32)` is not implemented for `(dyn Foo + 'static)` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 8 previous errors + +Some errors have detailed explanations: E0038, E0277. +For more information about an error, try `rustc --explain E0038`.