Skip to content

Commit b3ddfeb

Browse files
committed
Auto merge of rust-lang#105457 - GuillaumeGomez:prevent-auto-blanket-impl-retrieval, r=notriddle
rustdoc: Prevent auto/blanket impl retrieval if there were compiler errors Fixes rust-lang#105404. I'm not sure happy about this fix but since it's how passes work (ie, even if there are errors, it runs all passes), I think it's fine as is. Just as a sidenote: I also gave a try to prevent running all passes in case there were compiler errors but then a lot of rustdoc tests were failing so I went for this fix instead. r? `@notriddle`
2 parents e1c9121 + 183a770 commit b3ddfeb

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/librustdoc/passes/collect_trait_impls.rs

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ pub(crate) const COLLECT_TRAIT_IMPLS: Pass = Pass {
1919
};
2020

2121
pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate {
22+
// We need to check if there are errors before running this pass because it would crash when
23+
// we try to get auto and blanket implementations.
24+
if cx.tcx.sess.diagnostic().has_errors_or_lint_errors().is_some() {
25+
return krate;
26+
}
27+
2228
let synth_impls = cx.sess().time("collect_synthetic_impls", || {
2329
let mut synth = SyntheticImplCollector { cx, impls: Vec::new() };
2430
synth.visit_crate(&krate);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This test ensures that it's not crashing rustdoc.
2+
3+
pub struct Foo<'a, 'b, T> {
4+
field1: dyn Bar<'a, 'b,>,
5+
//~^ ERROR
6+
//~^^ ERROR
7+
}
8+
9+
pub trait Bar<'x, 's, U>
10+
where U: 'x,
11+
Self:'x,
12+
Self:'s
13+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied
2+
--> $DIR/unable-fulfill-trait.rs:4:17
3+
|
4+
LL | field1: dyn Bar<'a, 'b,>,
5+
| ^^^ expected 1 generic argument
6+
|
7+
note: trait defined here, with 1 generic parameter: `U`
8+
--> $DIR/unable-fulfill-trait.rs:9:11
9+
|
10+
LL | pub trait Bar<'x, 's, U>
11+
| ^^^ -
12+
help: add missing generic argument
13+
|
14+
LL | field1: dyn Bar<'a, 'b, U,>,
15+
| +++
16+
17+
error[E0227]: ambiguous lifetime bound, explicit lifetime bound required
18+
--> $DIR/unable-fulfill-trait.rs:4:13
19+
|
20+
LL | field1: dyn Bar<'a, 'b,>,
21+
| ^^^^^^^^^^^^^^^^
22+
23+
error: aborting due to 2 previous errors
24+
25+
Some errors have detailed explanations: E0107, E0227.
26+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)