Skip to content

Commit b146000

Browse files
committed
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.
1 parent 0f5be70 commit b146000

File tree

7 files changed

+64
-25
lines changed

7 files changed

+64
-25
lines changed

src/librustc_privacy/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,9 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
787787
// FIXME: This is some serious pessimization intended to workaround deficiencies
788788
// in the reachability pass (`middle/reachable.rs`). Types are marked as link-time
789789
// reachable if they are returned via `impl Trait`, even from private functions.
790-
let exist_level = cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait));
790+
let exist_level =
791+
cmp::max(item_level, Some(AccessLevel::ReachableFromImplTrait));
791792
self.reach(item.hir_id, exist_level).generics().predicates().ty();
792-
793793
}
794794
}
795795
// Visit everything.

src/librustc_typeck/check/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1967,10 +1967,16 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
19671967
check_union(tcx, it.hir_id, it.span);
19681968
}
19691969
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
1970-
let def_id = tcx.hir().local_def_id(it.hir_id);
1971-
1972-
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
1973-
check_opaque(tcx, def_id, substs, it.span, &origin);
1970+
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
1971+
// `async-std` (and `pub async fn` in general).
1972+
// Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at it!
1973+
// See https://github.com/rust-lang/rust/issues/75100
1974+
if !tcx.sess.opts.actually_rustdoc {
1975+
let def_id = tcx.hir().local_def_id(it.hir_id);
1976+
1977+
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
1978+
check_opaque(tcx, def_id, substs, it.span, &origin);
1979+
}
19741980
}
19751981
hir::ItemKind::TyAlias(..) => {
19761982
let def_id = tcx.hir().local_def_id(it.hir_id);

src/librustc_typeck/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
356356
tcx.sess.time("wf_checking", || check::check_wf_new(tcx));
357357
})?;
358358

359+
// NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync.
359360
tcx.sess.time("item_types_checking", || {
360361
for &module in tcx.hir().krate().modules.keys() {
361362
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));

src/librustdoc/core.rs

+17
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,23 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
449449
let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess).take();
450450

451451
global_ctxt.enter(|tcx| {
452+
// Certain queries assume that some checks were run elsewhere
453+
// (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425),
454+
// so type-check everything other than function bodies in this crate before running lints.
455+
456+
// NOTE: this does not call `tcx.analysis()` so that we won't
457+
// typeck function bodies or run the default rustc lints.
458+
// (see `override_queries` in the `config`)
459+
460+
// HACK(jynelson) this calls an _extremely_ limited subset of `typeck`
461+
// and might break if queries change their assumptions in the future.
462+
463+
// NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
464+
tcx.sess.time("item_types_checking", || {
465+
for &module in tcx.hir().krate().modules.keys() {
466+
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
467+
}
468+
});
452469
tcx.sess.abort_if_errors();
453470
sess.time("missing_docs", || {
454471
rustc_lint::check_crate(tcx, rustc_lint::builtin::MissingDoc::new);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn f() -> impl Sized {
2+
enum E {
3+
//~^ ERROR recursive type `f::E` has infinite size
4+
V(E),
5+
}
6+
unimplemented!()
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0072]: recursive type `f::E` has infinite size
2+
--> $DIR/infinite-recursive-type-impl-trait.rs:2:5
3+
|
4+
LL | enum E {
5+
| ^^^^^^ recursive type has infinite size
6+
LL |
7+
LL | V(E),
8+
| - recursive without indirection
9+
|
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `f::E` representable
11+
|
12+
LL | V(Box<E>),
13+
| ^^^^ ^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0072`.
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
error: internal compiler error[E0391]: cycle detected when computing `Sized` constraints for `E`
1+
error[E0072]: recursive type `E` has infinite size
22
--> $DIR/infinite-recursive-type.rs:1:1
33
|
44
LL | enum E {
5-
| ^^^^^^
5+
| ^^^^^^ recursive type has infinite size
6+
LL |
7+
LL | V(E),
8+
| - recursive without indirection
69
|
7-
= note: ...which again requires computing `Sized` constraints for `E`, completing the cycle
8-
= note: cycle used when evaluating trait selection obligation `E: std::convert::From<E>`
9-
10-
error: internal compiler error: TyKind::Error constructed but no error reported
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `E` representable
1111
|
12-
= note: delayed at /home/joshua/rustc/src/librustc_session/session.rs:436:27
13-
14-
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17
15-
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
16-
17-
error: internal compiler error: unexpected panic
18-
19-
note: the compiler unexpectedly panicked. this is a bug.
20-
21-
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
22-
23-
note: rustc 1.47.0-dev running on x86_64-unknown-linux-gnu
12+
LL | V(Box<E>),
13+
| ^^^^ ^
2414

25-
note: compiler flags: -Z threads=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z unstable-options -C debuginfo=0
15+
error: aborting due to previous error
2616

17+
For more information about this error, try `rustc --explain E0072`.

0 commit comments

Comments
 (0)