From 31fcda170a0671195b7a1506b09c5f655fc4d7e9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 3 Aug 2020 21:13:13 -0400 Subject: [PATCH 1/5] Fix async-std at the price of breaking half the test suite - Don't mark impl trait as an error --- src/librustc_privacy/lib.rs | 9 ++---- src/librustdoc/core.rs | 7 ----- .../rustdoc-ui/error-in-impl-trait/async.rs | 7 ++--- .../error-in-impl-trait/async.stderr | 12 -------- .../rustdoc-ui/error-in-impl-trait/closure.rs | 2 +- .../error-in-impl-trait/closure.stderr | 12 -------- .../error-in-impl-trait/generic-argument.rs | 2 +- .../generic-argument.stderr | 12 -------- .../impl-keyword-closure.rs | 2 +- .../impl-keyword-closure.stderr | 12 -------- .../error-in-impl-trait/impl-keyword.rs | 2 +- .../error-in-impl-trait/impl-keyword.stderr | 12 -------- .../trait-alias-closure.rs | 2 +- .../trait-alias-closure.stderr | 12 -------- .../error-in-impl-trait/trait-alias.rs | 2 +- .../error-in-impl-trait/trait-alias.stderr | 12 -------- .../rustdoc-ui/infinite-recursive-type.stderr | 29 ++++++++++++------- 17 files changed, 29 insertions(+), 119 deletions(-) delete mode 100644 src/test/rustdoc-ui/error-in-impl-trait/async.stderr delete mode 100644 src/test/rustdoc-ui/error-in-impl-trait/closure.stderr delete mode 100644 src/test/rustdoc-ui/error-in-impl-trait/generic-argument.stderr delete mode 100644 src/test/rustdoc-ui/error-in-impl-trait/impl-keyword-closure.stderr delete mode 100644 src/test/rustdoc-ui/error-in-impl-trait/impl-keyword.stderr delete mode 100644 src/test/rustdoc-ui/error-in-impl-trait/trait-alias-closure.stderr delete mode 100644 src/test/rustdoc-ui/error-in-impl-trait/trait-alias.stderr diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index fc00050f405..797b2d35e9d 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -778,13 +778,8 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } // The interface is empty. hir::ItemKind::GlobalAsm(..) => {} - hir::ItemKind::OpaqueTy(..) => { - // FIXME: This is some serious pessimization intended to workaround deficiencies - // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time - // reachable if they are returned via `impl Trait`, even from private functions. - let exist_level = cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait)); - self.reach(item.hir_id, exist_level).generics().predicates().ty(); - } + // assume the type is never reachable - since it's opaque, no one can use it from this interface + hir::ItemKind::OpaqueTy(..) => {} // Visit everything. hir::ItemKind::Const(..) | hir::ItemKind::Static(..) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index cbd0ca0de64..eab310ddf89 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -449,13 +449,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess).take(); global_ctxt.enter(|tcx| { - // Certain queries assume that some checks were run elsewhere - // (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425), - // so type-check everything other than function bodies in this crate before running lints. - // NOTE: this does not call `tcx.analysis()` so that we won't - // typeck function bodies or run the default rustc lints. - // (see `override_queries` in the `config`) - let _ = rustc_typeck::check_crate(tcx); tcx.sess.abort_if_errors(); sess.time("missing_docs", || { rustc_lint::check_crate(tcx, rustc_lint::builtin::MissingDoc::new); diff --git a/src/test/rustdoc-ui/error-in-impl-trait/async.rs b/src/test/rustdoc-ui/error-in-impl-trait/async.rs index 112a2c494a5..cda53bff07a 100644 --- a/src/test/rustdoc-ui/error-in-impl-trait/async.rs +++ b/src/test/rustdoc-ui/error-in-impl-trait/async.rs @@ -1,10 +1,7 @@ // edition:2018 +// check-pass -/// This used to work with ResolveBodyWithLoop. -/// However now that we ignore type checking instead of modifying the function body, -/// the return type is seen as `impl Future`, not a `u32`. -/// So it no longer allows errors in the function body. +/// Should compile fine pub async fn a() -> u32 { error::_in::async_fn() - //~^ ERROR failed to resolve } diff --git a/src/test/rustdoc-ui/error-in-impl-trait/async.stderr b/src/test/rustdoc-ui/error-in-impl-trait/async.stderr deleted file mode 100644 index 086db1be722..00000000000 --- a/src/test/rustdoc-ui/error-in-impl-trait/async.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0433]: failed to resolve: could not resolve path `error::_in::async_fn` - --> $DIR/async.rs:8:5 - | -LL | error::_in::async_fn() - | ^^^^^^^^^^^^^^^^^^^^ could not resolve path `error::_in::async_fn` - | - = note: this error was originally ignored because you are running `rustdoc` - = note: try running again with `rustc` or `cargo check` and you may get a more detailed error - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/rustdoc-ui/error-in-impl-trait/closure.rs b/src/test/rustdoc-ui/error-in-impl-trait/closure.rs index df40c121d57..f1fd85bb23c 100644 --- a/src/test/rustdoc-ui/error-in-impl-trait/closure.rs +++ b/src/test/rustdoc-ui/error-in-impl-trait/closure.rs @@ -1,5 +1,5 @@ +// check-pass // manually desugared version of an `async fn` (but with a closure instead of a generator) pub fn a() -> impl Fn() -> u32 { || content::doesnt::matter() - //~^ ERROR failed to resolve } diff --git a/src/test/rustdoc-ui/error-in-impl-trait/closure.stderr b/src/test/rustdoc-ui/error-in-impl-trait/closure.stderr deleted file mode 100644 index 4ee9c4d1f43..00000000000 --- a/src/test/rustdoc-ui/error-in-impl-trait/closure.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0433]: failed to resolve: could not resolve path `content::doesnt::matter` - --> $DIR/closure.rs:3:8 - | -LL | || content::doesnt::matter() - | ^^^^^^^^^^^^^^^^^^^^^^^ could not resolve path `content::doesnt::matter` - | - = note: this error was originally ignored because you are running `rustdoc` - = note: try running again with `rustc` or `cargo check` and you may get a more detailed error - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/rustdoc-ui/error-in-impl-trait/generic-argument.rs b/src/test/rustdoc-ui/error-in-impl-trait/generic-argument.rs index 0ccf2e3866f..dcec379d47e 100644 --- a/src/test/rustdoc-ui/error-in-impl-trait/generic-argument.rs +++ b/src/test/rustdoc-ui/error-in-impl-trait/generic-argument.rs @@ -1,7 +1,7 @@ +// check-pass trait ValidTrait {} /// This has docs pub fn f() -> impl ValidTrait { Vec::::new() - //~^ ERROR failed to resolve } diff --git a/src/test/rustdoc-ui/error-in-impl-trait/generic-argument.stderr b/src/test/rustdoc-ui/error-in-impl-trait/generic-argument.stderr deleted file mode 100644 index 72716c258dc..00000000000 --- a/src/test/rustdoc-ui/error-in-impl-trait/generic-argument.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0433]: failed to resolve: could not resolve path `DoesNotExist` - --> $DIR/generic-argument.rs:5:11 - | -LL | Vec::::new() - | ^^^^^^^^^^^^ could not resolve path `DoesNotExist` - | - = note: this error was originally ignored because you are running `rustdoc` - = note: try running again with `rustc` or `cargo check` and you may get a more detailed error - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword-closure.rs b/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword-closure.rs index 399fb827517..b935b0832f0 100644 --- a/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword-closure.rs +++ b/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword-closure.rs @@ -1,6 +1,6 @@ +// check-pass pub trait ValidTrait {} /// This returns impl trait pub fn g() -> impl ValidTrait { (|| error::_in::impl_trait::alias::nested::closure())() - //~^ ERROR failed to resolve } diff --git a/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword-closure.stderr b/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword-closure.stderr deleted file mode 100644 index 55f9b609a11..00000000000 --- a/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword-closure.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0433]: failed to resolve: could not resolve path `error::_in::impl_trait::alias::nested::closure` - --> $DIR/impl-keyword-closure.rs:4:9 - | -LL | (|| error::_in::impl_trait::alias::nested::closure())() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not resolve path `error::_in::impl_trait::alias::nested::closure` - | - = note: this error was originally ignored because you are running `rustdoc` - = note: try running again with `rustc` or `cargo check` and you may get a more detailed error - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword.rs b/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword.rs index 24b5734dbd0..701126f87a1 100644 --- a/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword.rs +++ b/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword.rs @@ -1,6 +1,6 @@ +// check-pass pub trait ValidTrait {} /// This returns impl trait pub fn g() -> impl ValidTrait { error::_in::impl_trait() - //~^ ERROR failed to resolve } diff --git a/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword.stderr b/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword.stderr deleted file mode 100644 index 3257079f942..00000000000 --- a/src/test/rustdoc-ui/error-in-impl-trait/impl-keyword.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0433]: failed to resolve: could not resolve path `error::_in::impl_trait` - --> $DIR/impl-keyword.rs:4:5 - | -LL | error::_in::impl_trait() - | ^^^^^^^^^^^^^^^^^^^^^^ could not resolve path `error::_in::impl_trait` - | - = note: this error was originally ignored because you are running `rustdoc` - = note: try running again with `rustc` or `cargo check` and you may get a more detailed error - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/rustdoc-ui/error-in-impl-trait/trait-alias-closure.rs b/src/test/rustdoc-ui/error-in-impl-trait/trait-alias-closure.rs index 1498fa4f890..31dd786cbbf 100644 --- a/src/test/rustdoc-ui/error-in-impl-trait/trait-alias-closure.rs +++ b/src/test/rustdoc-ui/error-in-impl-trait/trait-alias-closure.rs @@ -1,3 +1,4 @@ +// check-pass #![feature(type_alias_impl_trait)] pub trait ValidTrait {} @@ -6,5 +7,4 @@ type ImplTrait = impl ValidTrait; /// This returns impl trait, but using a type alias pub fn h() -> ImplTrait { (|| error::_in::impl_trait::alias::nested::closure())() - //~^ ERROR failed to resolve } diff --git a/src/test/rustdoc-ui/error-in-impl-trait/trait-alias-closure.stderr b/src/test/rustdoc-ui/error-in-impl-trait/trait-alias-closure.stderr deleted file mode 100644 index 84b28139dbc..00000000000 --- a/src/test/rustdoc-ui/error-in-impl-trait/trait-alias-closure.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0433]: failed to resolve: could not resolve path `error::_in::impl_trait::alias::nested::closure` - --> $DIR/trait-alias-closure.rs:8:9 - | -LL | (|| error::_in::impl_trait::alias::nested::closure())() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not resolve path `error::_in::impl_trait::alias::nested::closure` - | - = note: this error was originally ignored because you are running `rustdoc` - = note: try running again with `rustc` or `cargo check` and you may get a more detailed error - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/rustdoc-ui/error-in-impl-trait/trait-alias.rs b/src/test/rustdoc-ui/error-in-impl-trait/trait-alias.rs index cf9bc48c7f8..c18a024af4b 100644 --- a/src/test/rustdoc-ui/error-in-impl-trait/trait-alias.rs +++ b/src/test/rustdoc-ui/error-in-impl-trait/trait-alias.rs @@ -1,3 +1,4 @@ +// check-pass #![feature(type_alias_impl_trait)] pub trait ValidTrait {} @@ -6,5 +7,4 @@ type ImplTrait = impl ValidTrait; /// This returns impl trait, but using a type alias pub fn h() -> ImplTrait { error::_in::impl_trait::alias() - //~^ ERROR failed to resolve } diff --git a/src/test/rustdoc-ui/error-in-impl-trait/trait-alias.stderr b/src/test/rustdoc-ui/error-in-impl-trait/trait-alias.stderr deleted file mode 100644 index 9be6a3d8d6b..00000000000 --- a/src/test/rustdoc-ui/error-in-impl-trait/trait-alias.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0433]: failed to resolve: could not resolve path `error::_in::impl_trait::alias` - --> $DIR/trait-alias.rs:8:5 - | -LL | error::_in::impl_trait::alias() - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not resolve path `error::_in::impl_trait::alias` - | - = note: this error was originally ignored because you are running `rustdoc` - = note: try running again with `rustc` or `cargo check` and you may get a more detailed error - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/rustdoc-ui/infinite-recursive-type.stderr b/src/test/rustdoc-ui/infinite-recursive-type.stderr index 897445f200c..8d12392c567 100644 --- a/src/test/rustdoc-ui/infinite-recursive-type.stderr +++ b/src/test/rustdoc-ui/infinite-recursive-type.stderr @@ -1,17 +1,26 @@ -error[E0072]: recursive type `E` has infinite size +error: internal compiler error[E0391]: cycle detected when computing `Sized` constraints for `E` --> $DIR/infinite-recursive-type.rs:1:1 | LL | enum E { - | ^^^^^^ recursive type has infinite size -LL | -LL | V(E), - | - recursive without indirection + | ^^^^^^ | -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `E` representable + = note: ...which again requires computing `Sized` constraints for `E`, completing the cycle + = note: cycle used when evaluating trait selection obligation `E: std::convert::From` + +error: internal compiler error: TyKind::Error constructed but no error reported | -LL | V(Box), - | ^^^^ ^ + = note: delayed at /home/joshua/rustc/src/librustc_session/session.rs:436:27 -error: aborting due to previous error +thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace + +error: internal compiler error: unexpected panic + +note: the compiler unexpectedly panicked. this is a bug. + +note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md + +note: rustc 1.47.0-dev running on x86_64-unknown-linux-gnu + +note: compiler flags: -Z threads=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z unstable-options -C debuginfo=0 -For more information about this error, try `rustc --explain E0072`. From 70697d8be87635d294f29c9c7a2a31b8ed08e49c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 3 Aug 2020 21:21:33 -0400 Subject: [PATCH 2/5] Add more realistic example of async error --- .../error-in-impl-trait/realistic-async.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/rustdoc-ui/error-in-impl-trait/realistic-async.rs diff --git a/src/test/rustdoc-ui/error-in-impl-trait/realistic-async.rs b/src/test/rustdoc-ui/error-in-impl-trait/realistic-async.rs new file mode 100644 index 00000000000..248575d3528 --- /dev/null +++ b/src/test/rustdoc-ui/error-in-impl-trait/realistic-async.rs @@ -0,0 +1,28 @@ +// edition:2018 +// check-pass + +mod windows { + pub trait WinFoo { + fn foo(&self) {} + } + + impl WinFoo for () {} +} + +#[cfg(any(windows, doc))] +use windows::*; + +mod unix { + pub trait UnixFoo { + fn foo(&self) {} + } + + impl UnixFoo for () {} +} + +#[cfg(any(unix, doc))] +use unix::*; + +async fn bar() { + ().foo() +} From 0f5be70ea4c3ec4544cdeb80e3138832e15815f9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 3 Aug 2020 21:50:24 -0400 Subject: [PATCH 3/5] Revert to the old `impl Trait` behavior for everyone except rustdoc --- src/librustc_privacy/lib.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 797b2d35e9d..48d846dfefd 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -778,8 +778,20 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } // The interface is empty. hir::ItemKind::GlobalAsm(..) => {} - // assume the type is never reachable - since it's opaque, no one can use it from this interface - hir::ItemKind::OpaqueTy(..) => {} + hir::ItemKind::OpaqueTy(..) => { + // HACK(jynelson): trying to infer the type of `impl trait` breaks `async-std` (and `pub async fn` in general) + // Since rustdoc never need to do codegen and doesn't care about link-time reachability, + // mark this as unreachable. + // See https://github.com/rust-lang/rust/issues/75100 + if !self.tcx.sess.opts.actually_rustdoc { + // FIXME: This is some serious pessimization intended to workaround deficiencies + // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time + // reachable if they are returned via `impl Trait`, even from private functions. + let exist_level = cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait)); + self.reach(item.hir_id, exist_level).generics().predicates().ty(); + + } + } // Visit everything. hir::ItemKind::Const(..) | hir::ItemKind::Static(..) From b146000e910ccd60bdcde89363cb6aa14ecc0d95 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 7 Aug 2020 20:07:07 -0400 Subject: [PATCH 4/5] EXTREMELY hacky fix This runs _just_ enough of typeck that later queries don't panic. Because this is in the same part of the compiler that errors on `impl Trait`, this special-cases impl Trait for rustdoc and no one else. Everything is fine. --- src/librustc_privacy/lib.rs | 4 +-- src/librustc_typeck/check/mod.rs | 12 ++++++-- src/librustc_typeck/lib.rs | 1 + src/librustdoc/core.rs | 17 +++++++++++ .../infinite-recursive-type-impl-trait.rs | 7 +++++ .../infinite-recursive-type-impl-trait.stderr | 17 +++++++++++ .../rustdoc-ui/infinite-recursive-type.stderr | 29 +++++++------------ 7 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs create mode 100644 src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 48d846dfefd..1f418fe7f7f 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -787,9 +787,9 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { // FIXME: This is some serious pessimization intended to workaround deficiencies // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time // reachable if they are returned via `impl Trait`, even from private functions. - let exist_level = cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait)); + let exist_level = + cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait)); self.reach(item.hir_id, exist_level).generics().predicates().ty(); - } } // Visit everything. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 6cefc99f7b1..9169b5aa58a 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1967,10 +1967,16 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { check_union(tcx, it.hir_id, it.span); } hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => { - let def_id = tcx.hir().local_def_id(it.hir_id); + // HACK(jynelson): trying to infer the type of `impl trait` breaks documenting + // `async-std` (and `pub async fn` in general). + // Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at it! + // See https://github.com/rust-lang/rust/issues/75100 + if !tcx.sess.opts.actually_rustdoc { + let def_id = tcx.hir().local_def_id(it.hir_id); - let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); - check_opaque(tcx, def_id, substs, it.span, &origin); + let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); + check_opaque(tcx, def_id, substs, it.span, &origin); + } } hir::ItemKind::TyAlias(..) => { let def_id = tcx.hir().local_def_id(it.hir_id); diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 9ba2545ba63..bea0f1e1f08 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -356,6 +356,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> { tcx.sess.time("wf_checking", || check::check_wf_new(tcx)); })?; + // NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync. tcx.sess.time("item_types_checking", || { for &module in tcx.hir().krate().modules.keys() { tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module)); diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index eab310ddf89..b13acaae1bf 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -449,6 +449,23 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess).take(); global_ctxt.enter(|tcx| { + // Certain queries assume that some checks were run elsewhere + // (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425), + // so type-check everything other than function bodies in this crate before running lints. + + // NOTE: this does not call `tcx.analysis()` so that we won't + // typeck function bodies or run the default rustc lints. + // (see `override_queries` in the `config`) + + // HACK(jynelson) this calls an _extremely_ limited subset of `typeck` + // and might break if queries change their assumptions in the future. + + // NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes. + tcx.sess.time("item_types_checking", || { + for &module in tcx.hir().krate().modules.keys() { + tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module)); + } + }); tcx.sess.abort_if_errors(); sess.time("missing_docs", || { rustc_lint::check_crate(tcx, rustc_lint::builtin::MissingDoc::new); diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs new file mode 100644 index 00000000000..b3a7ee56313 --- /dev/null +++ b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs @@ -0,0 +1,7 @@ +fn f() -> impl Sized { + enum E { + //~^ ERROR recursive type `f::E` has infinite size + V(E), + } + unimplemented!() +} diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr new file mode 100644 index 00000000000..ec1bb786fe5 --- /dev/null +++ b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr @@ -0,0 +1,17 @@ +error[E0072]: recursive type `f::E` has infinite size + --> $DIR/infinite-recursive-type-impl-trait.rs:2:5 + | +LL | enum E { + | ^^^^^^ recursive type has infinite size +LL | +LL | V(E), + | - recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `f::E` representable + | +LL | V(Box), + | ^^^^ ^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0072`. diff --git a/src/test/rustdoc-ui/infinite-recursive-type.stderr b/src/test/rustdoc-ui/infinite-recursive-type.stderr index 8d12392c567..897445f200c 100644 --- a/src/test/rustdoc-ui/infinite-recursive-type.stderr +++ b/src/test/rustdoc-ui/infinite-recursive-type.stderr @@ -1,26 +1,17 @@ -error: internal compiler error[E0391]: cycle detected when computing `Sized` constraints for `E` +error[E0072]: recursive type `E` has infinite size --> $DIR/infinite-recursive-type.rs:1:1 | LL | enum E { - | ^^^^^^ + | ^^^^^^ recursive type has infinite size +LL | +LL | V(E), + | - recursive without indirection | - = note: ...which again requires computing `Sized` constraints for `E`, completing the cycle - = note: cycle used when evaluating trait selection obligation `E: std::convert::From` - -error: internal compiler error: TyKind::Error constructed but no error reported +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `E` representable | - = note: delayed at /home/joshua/rustc/src/librustc_session/session.rs:436:27 +LL | V(Box), + | ^^^^ ^ -thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17 -note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace - -error: internal compiler error: unexpected panic - -note: the compiler unexpectedly panicked. this is a bug. - -note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md - -note: rustc 1.47.0-dev running on x86_64-unknown-linux-gnu - -note: compiler flags: -Z threads=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z unstable-options -C debuginfo=0 +error: aborting due to previous error +For more information about this error, try `rustc --explain E0072`. From a306e12874e3d9da225e41a904d27dd53629ca54 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 8 Aug 2020 10:19:56 -0400 Subject: [PATCH 5/5] Add another test --- ...infinite-recursive-type-impl-trait-return.rs | 15 +++++++++++++++ ...nite-recursive-type-impl-trait-return.stderr | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs create mode 100644 src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs new file mode 100644 index 00000000000..acce0f77a25 --- /dev/null +++ b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs @@ -0,0 +1,15 @@ +// normalize-stderr-test: "`.*`" -> "`DEF_ID`" +// normalize-stdout-test: "`.*`" -> "`DEF_ID`" +// edition:2018 + +pub async fn f() -> impl std::fmt::Debug { + #[derive(Debug)] + enum E { + //~^ ERROR recursive type `f::{{closure}}#0::E` has infinite size + This(E), + Unit, + } + E::Unit +} + +fn main() {} diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr new file mode 100644 index 00000000000..991dc6eec1d --- /dev/null +++ b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr @@ -0,0 +1,17 @@ +error[E0072]: recursive type `DEF_ID` has infinite size + --> $DIR/infinite-recursive-type-impl-trait-return.rs:7:5 + | +LL | enum E { + | ^^^^^^ recursive type has infinite size +LL | +LL | This(E), + | - recursive without indirection + | +help: insert some indirection (e.g., a `DEF_ID` representable + | +LL | This(Box), + | ^^^^ ^ + +error: aborting due to previous error + +For more information about this error, try `DEF_ID`.