Skip to content

Commit 0b7e900

Browse files
authored
Rollup merge of #149185 - Jules-Bertholet:fix-149092, r=chenyukang
Handle cycles when checking impl candidates for `doc(hidden)` Fixes #149092
2 parents 8f5ae74 + f580357 commit 0b7e900

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// ignore-tidy-filelength
22
use core::ops::ControlFlow;
33
use std::borrow::Cow;
4+
use std::collections::hash_set;
45
use std::path::PathBuf;
56

67
use rustc_abi::ExternAbi;
78
use rustc_ast::ast::LitKind;
89
use rustc_ast::{LitIntType, TraitObjectSyntax};
9-
use rustc_data_structures::fx::FxHashMap;
10+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1011
use rustc_data_structures::unord::UnordSet;
1112
use rustc_errors::codes::*;
1213
use rustc_errors::{
@@ -1952,11 +1953,17 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19521953
if self.tcx.visibility(did).is_accessible_from(body_def_id, self.tcx) {
19531954
// don't suggest foreign `#[doc(hidden)]` types
19541955
if !did.is_local() {
1955-
while let Some(parent) = parent_map.get(&did) {
1956+
let mut previously_seen_dids: FxHashSet<DefId> = Default::default();
1957+
previously_seen_dids.insert(did);
1958+
while let Some(&parent) = parent_map.get(&did)
1959+
&& let hash_set::Entry::Vacant(v) =
1960+
previously_seen_dids.entry(parent)
1961+
{
19561962
if self.tcx.is_doc_hidden(did) {
19571963
return false;
19581964
}
1959-
did = *parent;
1965+
v.insert();
1966+
did = parent;
19601967
}
19611968
}
19621969
true

compiler/rustc_trait_selection/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#![feature(associated_type_defaults)]
1818
#![feature(box_patterns)]
1919
#![feature(default_field_values)]
20+
#![feature(hash_set_entry)]
2021
#![feature(if_let_guard)]
2122
#![feature(iter_intersperse)]
2223
#![feature(iterator_try_reduce)]

tests/ui/suggestions/auxiliary/hidden-struct.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ impl Marker for hidden::Foo {}
3333
impl Marker for hidden1::Bar {}
3434
impl Marker for Baz {}
3535
impl Marker for Quux {}
36+
37+
38+
pub use crate as library;

tests/ui/suggestions/dont-suggest-foreign-doc-hidden.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ pub fn test4(_: Quux) {}
2121

2222
fn test5<T: hidden_struct::Marker>() {}
2323

24+
fn test6<T: hidden_struct::library::Marker>() {}
25+
2426
fn main() {
2527
test5::<i32>();
2628
//~^ ERROR [E0277]
29+
30+
test6::<i32>();
31+
//~^ ERROR [E0277]
2732
}

tests/ui/suggestions/dont-suggest-foreign-doc-hidden.stderr

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ LL + use hidden_struct::Quux;
3838
|
3939

4040
error[E0277]: the trait bound `i32: Marker` is not satisfied
41-
--> $DIR/dont-suggest-foreign-doc-hidden.rs:25:13
41+
--> $DIR/dont-suggest-foreign-doc-hidden.rs:27:13
4242
|
4343
LL | test5::<i32>();
4444
| ^^^ the trait `Marker` is not implemented for `i32`
@@ -59,7 +59,29 @@ note: required by a bound in `test5`
5959
LL | fn test5<T: hidden_struct::Marker>() {}
6060
| ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `test5`
6161

62-
error: aborting due to 5 previous errors
62+
error[E0277]: the trait bound `i32: Marker` is not satisfied
63+
--> $DIR/dont-suggest-foreign-doc-hidden.rs:30:13
64+
|
65+
LL | test6::<i32>();
66+
| ^^^ the trait `Marker` is not implemented for `i32`
67+
|
68+
help: the following other types implement trait `Marker`
69+
--> $DIR/auxiliary/hidden-struct.rs:31:1
70+
|
71+
LL | impl Marker for Option<u32> {}
72+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Option<u32>`
73+
...
74+
LL | impl Marker for Baz {}
75+
| ^^^^^^^^^^^^^^^^^^^ `Baz`
76+
LL | impl Marker for Quux {}
77+
| ^^^^^^^^^^^^^^^^^^^^ `Quux`
78+
note: required by a bound in `test6`
79+
--> $DIR/dont-suggest-foreign-doc-hidden.rs:24:13
80+
|
81+
LL | fn test6<T: hidden_struct::library::Marker>() {}
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `test6`
83+
84+
error: aborting due to 6 previous errors
6385

6486
Some errors have detailed explanations: E0277, E0412.
6587
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)