Skip to content

Commit 4512f21

Browse files
committed
Accept less invalid Rust in rustdoc
1 parent 22b2712 commit 4512f21

35 files changed

+428
-127
lines changed

Diff for: library/core/src/primitive_docs.rs

-20
Original file line numberDiff line numberDiff line change
@@ -1077,26 +1077,6 @@ mod prim_tuple {}
10771077
#[doc(hidden)]
10781078
impl<T> (T,) {}
10791079

1080-
// Fake impl that's only really used for docs.
1081-
#[cfg(doc)]
1082-
#[stable(feature = "rust1", since = "1.0.0")]
1083-
#[doc(fake_variadic)]
1084-
/// This trait is implemented on arbitrary-length tuples.
1085-
impl<T: Clone> Clone for (T,) {
1086-
fn clone(&self) -> Self {
1087-
loop {}
1088-
}
1089-
}
1090-
1091-
// Fake impl that's only really used for docs.
1092-
#[cfg(doc)]
1093-
#[stable(feature = "rust1", since = "1.0.0")]
1094-
#[doc(fake_variadic)]
1095-
/// This trait is implemented on arbitrary-length tuples.
1096-
impl<T: Copy> Copy for (T,) {
1097-
// empty
1098-
}
1099-
11001080
#[rustc_doc_primitive = "f32"]
11011081
/// A 32-bit floating point type (specifically, the "binary32" type defined in IEEE 754-2008).
11021082
///

Diff for: src/librustdoc/core.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,14 @@ pub(crate) fn run_global_ctxt(
319319
tcx.hir().for_each_module(|module| tcx.ensure().collect_mod_item_types(module))
320320
});
321321

322-
// NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
322+
// NOTE: These are copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
323+
let _ = tcx.sess.time("wf_checking", || {
324+
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
325+
});
323326
tcx.sess.time("item_types_checking", || {
324327
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module))
325328
});
329+
326330
tcx.sess.abort_if_errors();
327331
tcx.sess.time("missing_docs", || rustc_lint::check_crate(tcx));
328332
tcx.sess.time("check_mod_attrs", || {

Diff for: tests/rustdoc-gui/src/lib2/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ pub struct LongItemInfo2;
147147
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
148148
impl SimpleTrait for LongItemInfo2 {}
149149

150-
pub struct WhereWhitespace<T>;
150+
pub struct WhereWhitespace<T>(T);
151151

152152
impl<T> WhereWhitespace<T> {
153153
pub fn new<F>(f: F) -> Self
154154
where
155155
F: FnMut() -> i32,
156-
{}
156+
{todo!()}
157157
}
158158

159159
impl<K, T> Whitespace<&K> for WhereWhitespace<T>
@@ -187,6 +187,11 @@ impl ItemInfoAlignmentTest {
187187
pub mod scroll_traits {
188188
use std::iter::*;
189189

190+
struct Intersperse<T>(T);
191+
struct IntersperseWith<T, U>(T, U);
192+
struct Flatten<T>(T);
193+
struct Peekable<T>(T);
194+
190195
/// Shamelessly (partially) copied from `std::iter::Iterator`.
191196
/// It allows us to check that the scroll is working as expected on "hidden" items.
192197
pub trait Iterator {

Diff for: tests/rustdoc-json/enums/field_hidden.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Regression test for <https://github.com/rust-lang/rust/issues/100529>.
22

33
#![no_core]
4-
#![feature(no_core)]
4+
#![feature(no_core, lang_items)]
5+
6+
#[lang = "sized"]
7+
trait Sized {}
58

69
// @has "$.index[*][?(@.name=='ParseError')]"
710
// @has "$.index[*][?(@.name=='UnexpectedEndTag')]"

Diff for: tests/rustdoc-json/enums/kind.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// ignore-tidy-linelength
22

3-
#![feature(no_core)]
3+
#![feature(no_core, lang_items)]
44
#![no_core]
55

6+
#[lang = "sized"]
7+
trait Sized {}
8+
69
pub enum Foo {
710
// @set Unit = "$.index[*][?(@.name=='Unit')].id"
811
// @is "$.index[*][?(@.name=='Unit')].inner.variant.kind" '"plain"'

Diff for: tests/rustdoc-json/enums/tuple_fields_hidden.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
#![feature(no_core)]
1+
#![feature(no_core, lang_items)]
22
#![no_core]
33

4+
#[lang = "sized"]
5+
trait Sized {}
6+
47
// @set 1.1.0 = "$.index[*][?(@.docs=='1.1.0')].id"
58
// @set 2.1.0 = "$.index[*][?(@.docs=='2.1.0')].id"
69
// @set 2.1.1 = "$.index[*][?(@.docs=='2.1.1')].id"

Diff for: tests/rustdoc-json/generic-associated-types/gats.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// ignore-tidy-linelength
22

33
#![no_core]
4-
#![feature(lang_items, no_core)]
4+
#![feature(lang_items, no_core, arbitrary_self_types)]
55

66
#[lang = "sized"]
77
pub trait Sized {}
88

9+
#[lang = "receiver"]
10+
pub trait Receiver {}
11+
912
pub trait Display {}
1013

1114
pub trait LendingIterator {

Diff for: tests/rustdoc-json/impls/auto.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#![feature(no_core, auto_traits, lang_items)]
1+
#![feature(no_core, auto_traits, lang_items, arbitrary_self_types)]
22
#![no_core]
33

44
#[lang = "sized"]
55
trait Sized {}
66

7+
#[lang = "receiver"]
8+
pub trait Receiver {}
9+
710
pub auto trait Bar {}
811

912
/// has span
@@ -12,8 +15,8 @@ impl Foo {
1215
}
1316

1417
// Testing spans, so all tests below code
15-
// @is "$.index[*][?(@.docs=='has span')].span.begin" "[10, 0]"
16-
// @is "$.index[*][?(@.docs=='has span')].span.end" "[12, 1]"
18+
// @is "$.index[*][?(@.docs=='has span')].span.begin" "[13, 0]"
19+
// @is "$.index[*][?(@.docs=='has span')].span.end" "[15, 1]"
1720
// FIXME: this doesn't work due to https://github.com/freestrings/jsonpath/issues/91
1821
// is "$.index[*][?(@.inner.impl.synthetic==true)].span" null
1922
pub struct Foo;

Diff for: tests/rustdoc-json/type/inherent_associated_type_bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ pub struct Carrier<'a>(&'a ());
1616
pub fn user(_: for<'b> fn(Carrier<'b>::Focus<i32>)) {}
1717

1818
impl<'a> Carrier<'a> {
19-
pub type Focus<T> = &'a mut T;
19+
pub type Focus<T> = &'a mut T where T: 'a;
2020
}

Diff for: tests/rustdoc-ui/error-in-impl-trait/infinite-recursive-type-2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// check-pass
2-
31
pub fn f() -> impl Sized {
42
pub enum E {
3+
//~^ ERROR: recursive type
54
V(E),
65
}
76

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-2.rs:2:5
3+
|
4+
LL | pub enum E {
5+
| ^^^^^^^^^^
6+
LL |
7+
LL | V(E),
8+
| - recursive without indirection
9+
|
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
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`.

Diff for: tests/rustdoc-ui/error-in-impl-trait/infinite-recursive-type.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// check-pass
2-
31
fn f() -> impl Sized {
42
enum E {
3+
//~^ ERROR: recursive type
54
V(E),
65
}
76

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.rs:2:5
3+
|
4+
LL | enum E {
5+
| ^^^^^^
6+
LL |
7+
LL | V(E),
8+
| - recursive without indirection
9+
|
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
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`.

Diff for: tests/rustdoc-ui/invalid_const_in_lifetime_position.rs

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ trait X {
44
fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
55
//~^ ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
66
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
7+
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
8+
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
9+
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
10+
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
11+
//~| ERROR trait `X` cannot be made into an object

Diff for: tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr

+82-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,86 @@ note: associated type defined here, with 0 generic parameters
2828
LL | type Y<'a>;
2929
| ^
3030

31-
error: aborting due to 2 previous errors
31+
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
32+
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
33+
|
34+
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
35+
| ^ expected 1 lifetime argument
36+
|
37+
note: associated type defined here, with 1 lifetime parameter: `'a`
38+
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
39+
|
40+
LL | type Y<'a>;
41+
| ^ --
42+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
43+
help: add missing lifetime argument
44+
|
45+
LL | fn f<'a>(arg : Box<dyn X<Y<'_, 1> = &'a ()>>) {}
46+
| +++
47+
48+
error[E0107]: associated type takes 0 generic arguments but 1 generic argument was supplied
49+
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
50+
|
51+
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
52+
| ^--- help: remove these generics
53+
| |
54+
| expected 0 generic arguments
55+
|
56+
note: associated type defined here, with 0 generic parameters
57+
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
58+
|
59+
LL | type Y<'a>;
60+
| ^
61+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
62+
63+
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
64+
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
65+
|
66+
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
67+
| ^ expected 1 lifetime argument
68+
|
69+
note: associated type defined here, with 1 lifetime parameter: `'a`
70+
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
71+
|
72+
LL | type Y<'a>;
73+
| ^ --
74+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
75+
help: add missing lifetime argument
76+
|
77+
LL | fn f<'a>(arg : Box<dyn X<Y<'_, 1> = &'a ()>>) {}
78+
| +++
79+
80+
error[E0107]: associated type takes 0 generic arguments but 1 generic argument was supplied
81+
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
82+
|
83+
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
84+
| ^--- help: remove these generics
85+
| |
86+
| expected 0 generic arguments
87+
|
88+
note: associated type defined here, with 0 generic parameters
89+
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
90+
|
91+
LL | type Y<'a>;
92+
| ^
93+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
94+
95+
error[E0038]: the trait `X` cannot be made into an object
96+
--> $DIR/invalid_const_in_lifetime_position.rs:4:20
97+
|
98+
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
99+
| ^^^^^^^^^^^^^^^^^^^^ `X` cannot be made into an object
100+
|
101+
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
102+
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
103+
|
104+
LL | trait X {
105+
| - this trait cannot be made into an object...
106+
LL | type Y<'a>;
107+
| ^ ...because it contains the generic associated type `Y`
108+
= help: consider moving `Y` to another trait
109+
110+
error: aborting due to 7 previous errors
32111

33-
For more information about this error, try `rustc --explain E0107`.
112+
Some errors have detailed explanations: E0038, E0107.
113+
For more information about an error, try `rustc --explain E0038`.

Diff for: tests/rustdoc-ui/issues/issue-105742.rs

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub trait SVec: Index<
2121
//~| missing generics for associated type `SVec::Item`
2222
//~| missing generics for associated type `SVec::Item`
2323
//~| missing generics for associated type `SVec::Item`
24+
//~| missing generics for associated type `SVec::Item`
25+
//~| missing generics for associated type `SVec::Item`
2426
Output = <Index<<Self as SVec>::Item,
2527
//~^ expected 1 lifetime argument
2628
//~| expected 1 generic argument
@@ -30,6 +32,8 @@ pub trait SVec: Index<
3032
//~| missing generics for associated type `SVec::Item`
3133
//~| missing generics for associated type `SVec::Item`
3234
//~| missing generics for associated type `SVec::Item`
35+
//~| missing generics for associated type `SVec::Item`
36+
//~| missing generics for associated type `SVec::Item`
3337
Output = <Self as SVec>::Item> as SVec>::Item,
3438
//~^ expected 1 lifetime argument
3539
//~| expected 1 generic argument
@@ -47,6 +51,10 @@ pub trait SVec: Index<
4751
//~| missing generics for associated type `SVec::Item`
4852
//~| missing generics for associated type `SVec::Item`
4953
//~| missing generics for associated type `SVec::Item`
54+
//~| missing generics for associated type `SVec::Item`
55+
//~| missing generics for associated type `SVec::Item`
56+
//~| missing generics for associated type `SVec::Item`
57+
//~| missing generics for associated type `SVec::Item`
5058
> {
5159
type Item<'a, T>;
5260

0 commit comments

Comments
 (0)