Skip to content

Commit 1ac98c8

Browse files
committed
make test more reliable, rename all_traits -> all_traits_including_private
1 parent 2f3d599 commit 1ac98c8

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
15881588
&infcx_
15891589
};
15901590

1591-
tcx.all_traits()
1591+
tcx.all_traits_including_private()
15921592
.filter(|trait_def_id| {
15931593
// Consider only traits with the associated type
15941594
tcx.associated_items(*trait_def_id)

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17251725
if unsatisfied_predicates.is_empty()
17261726
// ...or if we already suggested that name because of `rustc_confusable` annotation
17271727
&& Some(similar_candidate.name()) != confusable_suggested
1728-
// and if the we aren't in an expansion.
1728+
// and if we aren't in an expansion.
17291729
&& !span.from_expansion()
17301730
{
17311731
self.find_likely_intended_associated_item(
@@ -3480,7 +3480,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34803480
mut valid_out_of_scope_traits: Vec<DefId>,
34813481
explain: bool,
34823482
) -> bool {
3483-
valid_out_of_scope_traits.retain(|id| !self.tcx.is_private_dep(id.krate));
3483+
valid_out_of_scope_traits.retain(|id| self.tcx.is_user_visible_dep(id.krate));
34843484
if !valid_out_of_scope_traits.is_empty() {
34853485
let mut candidates = valid_out_of_scope_traits;
34863486
candidates.sort_by_key(|id| self.tcx.def_path_str(id));
@@ -4385,7 +4385,7 @@ pub(crate) struct TraitInfo {
43854385
/// Retrieves all traits in this crate and any dependent crates,
43864386
/// and wraps them into `TraitInfo` for custom sorting.
43874387
pub(crate) fn all_traits(tcx: TyCtxt<'_>) -> Vec<TraitInfo> {
4388-
tcx.all_traits().map(|def_id| TraitInfo { def_id }).collect()
4388+
tcx.all_traits_including_private().map(|def_id| TraitInfo { def_id }).collect()
43894389
}
43904390

43914391
fn print_disambiguation_help<'tcx>(

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2318,7 +2318,7 @@ impl<'tcx> TyCtxt<'tcx> {
23182318
}
23192319

23202320
/// All traits in the crate graph, including those not visible to the user.
2321-
pub fn all_traits(self) -> impl Iterator<Item = DefId> {
2321+
pub fn all_traits_including_private(self) -> impl Iterator<Item = DefId> {
23222322
iter::once(LOCAL_CRATE)
23232323
.chain(self.crates(()).iter().copied())
23242324
.flat_map(move |cnum| self.traits(cnum).iter().copied())

compiler/rustc_smir/src/rustc_smir/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ impl<'tcx> SmirCtxt<'tcx> {
130130

131131
pub fn all_trait_decls(&self) -> stable_mir::TraitDecls {
132132
let mut tables = self.0.borrow_mut();
133-
tables.tcx.all_traits().map(|trait_def_id| tables.trait_def(trait_def_id)).collect()
133+
tables
134+
.tcx
135+
.all_traits_including_private()
136+
.map(|trait_def_id| tables.trait_def(trait_def_id))
137+
.collect()
134138
}
135139

136140
pub fn trait_decls(&self, crate_num: CrateNum) -> stable_mir::TraitDecls {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18501850
let trait_def_id = trait_pred.def_id();
18511851
let trait_name = self.tcx.item_name(trait_def_id);
18521852
let crate_name = self.tcx.crate_name(trait_def_id.krate);
1853-
if let Some(other_trait_def_id) = self.tcx.all_traits().find(|def_id| {
1853+
if let Some(other_trait_def_id) = self.tcx.all_traits_including_private().find(|def_id| {
18541854
trait_name == self.tcx.item_name(trait_def_id)
18551855
&& trait_def_id.krate != def_id.krate
18561856
&& crate_name == self.tcx.crate_name(def_id.krate)

tests/ui/typeck/dont-suggest-private-dependencies.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
// Don't suggest importing a function from a private dependency.
2+
// Issues: #138191, #142676
3+
4+
// Avoid suggesting traits from std-private deps
5+
//@ forbid-output: compiler_builtins
6+
//@ forbid-output: object
27

38
struct VecReader(Vec<u8>);
49

tests/ui/typeck/dont-suggest-private-dependencies.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0599]: no method named `read` found for struct `Vec<u8>` in the current scope
2-
--> $DIR/dont-suggest-private-dependencies.rs:7:16
2+
--> $DIR/dont-suggest-private-dependencies.rs:12:16
33
|
44
LL | self.0.read(buf)
55
| ^^^^
@@ -10,7 +10,7 @@ LL | self.0.read_at(buf)
1010
| +++
1111

1212
error[E0599]: no function or associated item named `cast_from_lossy` found for type `u8` in the current scope
13-
--> $DIR/dont-suggest-private-dependencies.rs:13:17
13+
--> $DIR/dont-suggest-private-dependencies.rs:18:17
1414
|
1515
LL | let _ = u8::cast_from_lossy(9);
1616
| ^^^^^^^^^^^^^^^ function or associated item not found in `u8`

0 commit comments

Comments
 (0)