Skip to content

Commit c2bcced

Browse files
committed
Stop using hir_ty_to_ty in rustc_privacy
1 parent 1dceddf commit c2bcced

24 files changed

+117
-436
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4217,6 +4217,7 @@ dependencies = [
42174217
"rustc_middle",
42184218
"rustc_session",
42194219
"rustc_span",
4220+
"rustc_ty_utils",
42204221
"tracing",
42214222
]
42224223

compiler/rustc_privacy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ rustc_middle = { path = "../rustc_middle" }
1515
rustc_session = { path = "../rustc_session" }
1616
rustc_span = { path = "../rustc_span" }
1717
rustc_hir_analysis = { path = "../rustc_hir_analysis" }
18+
rustc_ty_utils = { path = "../rustc_ty_utils" }
1819
tracing = "0.1"

compiler/rustc_privacy/src/lib.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ where
176176
{
177177
type BreakTy = V::BreakTy;
178178

179+
fn visit_predicate(&mut self, p: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
180+
self.visit_clause(p.as_clause().unwrap())
181+
}
182+
179183
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<V::BreakTy> {
180184
let tcx = self.def_id_visitor.tcx();
181185
// GenericArgs are not visited here because they are visited below
@@ -1142,6 +1146,14 @@ impl<'tcx> TypePrivacyVisitor<'tcx> {
11421146
}
11431147
}
11441148

1149+
impl<'tcx> rustc_ty_utils::sig_types::Spanned<'tcx> for TypePrivacyVisitor<'tcx> {
1150+
type BreakTy = ();
1151+
fn visit(&mut self, span: Span, value: impl TypeVisitable<TyCtxt<'tcx>>) -> ControlFlow<()> {
1152+
self.span = span;
1153+
value.visit_with(&mut self.skeleton())
1154+
}
1155+
}
1156+
11451157
impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
11461158
type NestedFilter = nested_filter::All;
11471159

@@ -1183,7 +1195,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
11831195
// Types in signatures.
11841196
// FIXME: This is very ineffective. Ideally each HIR type should be converted
11851197
// into a semantic type only once and the result should be cached somehow.
1186-
if self.visit(rustc_hir_analysis::hir_ty_to_ty(self.tcx, hir_ty)).is_break() {
1198+
if self.visit(rustc_hir_analysis::hir_ty_to_ty(self.tcx(), hir_ty)).is_break() {
11871199
return;
11881200
}
11891201
}
@@ -1348,7 +1360,20 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
13481360
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
13491361
let orig_current_item = mem::replace(&mut self.current_item, item.owner_id.def_id);
13501362
let old_maybe_typeck_results = self.maybe_typeck_results.take();
1351-
intravisit::walk_item(self, item);
1363+
rustc_ty_utils::sig_types::walk_types(self.tcx(), item.owner_id.def_id, self);
1364+
match item.kind {
1365+
hir::ItemKind::Macro(_, _) => intravisit::walk_item(self, item),
1366+
hir::ItemKind::Static(_, _, body_id)
1367+
| hir::ItemKind::Const(_, body_id)
1368+
| hir::ItemKind::Fn(_, _, body_id) => self.visit_nested_body(body_id),
1369+
hir::ItemKind::Impl(hir::Impl { of_trait: Some(tr), .. }) => {
1370+
self.span = tr.path.span;
1371+
let trait_ref =
1372+
self.tcx().impl_trait_ref(item.owner_id.def_id).unwrap().instantiate_identity();
1373+
self.visit_def_id(trait_ref.def_id, "trait", &trait_ref.print_only_trait_path());
1374+
}
1375+
_ => {}
1376+
}
13521377
self.maybe_typeck_results = old_maybe_typeck_results;
13531378
self.current_item = orig_current_item;
13541379
}

tests/ui/dyn-keyword/dyn-2018-edition-lint.rs

-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ fn function(x: &SomeTrait, y: Box<SomeTrait>) {
66
//~| WARN this is accepted in the current edition
77
//~| ERROR trait objects without an explicit `dyn` are deprecated
88
//~| WARN this is accepted in the current edition
9-
//~| ERROR trait objects without an explicit `dyn` are deprecated
10-
//~| WARN this is accepted in the current edition
11-
//~| ERROR trait objects without an explicit `dyn` are deprecated
12-
//~| WARN this is accepted in the current edition
13-
//~| ERROR trait objects without an explicit `dyn` are deprecated
14-
//~| WARN this is accepted in the current edition
15-
//~| ERROR trait objects without an explicit `dyn` are deprecated
16-
//~| WARN this is accepted in the current edition
179
let _x: &SomeTrait = todo!();
1810
//~^ ERROR trait objects without an explicit `dyn` are deprecated
1911
//~| WARN this is accepted in the current edition

tests/ui/dyn-keyword/dyn-2018-edition-lint.stderr

+2-54
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
3030
| +++
3131

3232
error: trait objects without an explicit `dyn` are deprecated
33-
--> $DIR/dyn-2018-edition-lint.rs:17:14
33+
--> $DIR/dyn-2018-edition-lint.rs:9:14
3434
|
3535
LL | let _x: &SomeTrait = todo!();
3636
| ^^^^^^^^^
@@ -42,57 +42,5 @@ help: use `dyn`
4242
LL | let _x: &dyn SomeTrait = todo!();
4343
| +++
4444

45-
error: trait objects without an explicit `dyn` are deprecated
46-
--> $DIR/dyn-2018-edition-lint.rs:4:17
47-
|
48-
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
49-
| ^^^^^^^^^
50-
|
51-
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
52-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
53-
help: use `dyn`
54-
|
55-
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
56-
| +++
57-
58-
error: trait objects without an explicit `dyn` are deprecated
59-
--> $DIR/dyn-2018-edition-lint.rs:4:17
60-
|
61-
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
62-
| ^^^^^^^^^
63-
|
64-
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
65-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
66-
help: use `dyn`
67-
|
68-
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
69-
| +++
70-
71-
error: trait objects without an explicit `dyn` are deprecated
72-
--> $DIR/dyn-2018-edition-lint.rs:4:35
73-
|
74-
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
75-
| ^^^^^^^^^
76-
|
77-
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
78-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
79-
help: use `dyn`
80-
|
81-
LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
82-
| +++
83-
84-
error: trait objects without an explicit `dyn` are deprecated
85-
--> $DIR/dyn-2018-edition-lint.rs:4:35
86-
|
87-
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
88-
| ^^^^^^^^^
89-
|
90-
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
91-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
92-
help: use `dyn`
93-
|
94-
LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
95-
| +++
96-
97-
error: aborting due to 7 previous errors
45+
error: aborting due to 3 previous errors
9846

tests/ui/lint/force-warn/allowed-group-warn-by-default-lint.rs

-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,5 @@ pub trait SomeTrait {}
1010
pub fn function(_x: Box<SomeTrait>) {}
1111
//~^ WARN trait objects without an explicit `dyn` are deprecated
1212
//~| WARN this is accepted in the current edition
13-
//~| WARN trait objects without an explicit `dyn` are deprecated
14-
//~| WARN this is accepted in the current edition
15-
//~| WARN trait objects without an explicit `dyn` are deprecated
16-
//~| WARN this is accepted in the current edition
1713

1814
fn main() {}

tests/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr

+1-27
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,5 @@ help: use `dyn`
1212
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
1313
| +++
1414

15-
warning: trait objects without an explicit `dyn` are deprecated
16-
--> $DIR/allowed-group-warn-by-default-lint.rs:10:25
17-
|
18-
LL | pub fn function(_x: Box<SomeTrait>) {}
19-
| ^^^^^^^^^
20-
|
21-
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
22-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
23-
help: use `dyn`
24-
|
25-
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
26-
| +++
27-
28-
warning: trait objects without an explicit `dyn` are deprecated
29-
--> $DIR/allowed-group-warn-by-default-lint.rs:10:25
30-
|
31-
LL | pub fn function(_x: Box<SomeTrait>) {}
32-
| ^^^^^^^^^
33-
|
34-
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
35-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
36-
help: use `dyn`
37-
|
38-
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
39-
| +++
40-
41-
warning: 3 warnings emitted
15+
warning: 1 warning emitted
4216

tests/ui/lint/force-warn/cap-lints-allow.rs

-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@ pub trait SomeTrait {}
88
pub fn function(_x: Box<SomeTrait>) {}
99
//~^ WARN trait objects without an explicit `dyn` are deprecated
1010
//~| WARN this is accepted in the current edition
11-
//~| WARN trait objects without an explicit `dyn` are deprecated
12-
//~| WARN this is accepted in the current edition
13-
//~| WARN trait objects without an explicit `dyn` are deprecated
14-
//~| WARN this is accepted in the current edition
1511

1612
fn main() {}

tests/ui/lint/force-warn/cap-lints-allow.stderr

+1-27
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,5 @@ help: use `dyn`
1212
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
1313
| +++
1414

15-
warning: trait objects without an explicit `dyn` are deprecated
16-
--> $DIR/cap-lints-allow.rs:8:25
17-
|
18-
LL | pub fn function(_x: Box<SomeTrait>) {}
19-
| ^^^^^^^^^
20-
|
21-
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
22-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
23-
help: use `dyn`
24-
|
25-
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
26-
| +++
27-
28-
warning: trait objects without an explicit `dyn` are deprecated
29-
--> $DIR/cap-lints-allow.rs:8:25
30-
|
31-
LL | pub fn function(_x: Box<SomeTrait>) {}
32-
| ^^^^^^^^^
33-
|
34-
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
35-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
36-
help: use `dyn`
37-
|
38-
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
39-
| +++
40-
41-
warning: 3 warnings emitted
15+
warning: 1 warning emitted
4216

tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.rs

-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,5 @@ pub trait SomeTrait {}
88
pub fn function(_x: Box<SomeTrait>) {}
99
//~^ WARN trait objects without an explicit `dyn` are deprecated
1010
//~| WARN this is accepted in the current edition
11-
//~| WARN trait objects without an explicit `dyn` are deprecated
12-
//~| WARN this is accepted in the current edition
13-
//~| WARN trait objects without an explicit `dyn` are deprecated
14-
//~| WARN this is accepted in the current edition
1511

1612
fn main() {}

tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr

+1-27
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,5 @@ help: use `dyn`
1313
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
1414
| +++
1515

16-
warning: trait objects without an explicit `dyn` are deprecated
17-
--> $DIR/lint-group-allowed-cli-warn-by-default-lint.rs:8:25
18-
|
19-
LL | pub fn function(_x: Box<SomeTrait>) {}
20-
| ^^^^^^^^^
21-
|
22-
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
23-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
24-
help: use `dyn`
25-
|
26-
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
27-
| +++
28-
29-
warning: trait objects without an explicit `dyn` are deprecated
30-
--> $DIR/lint-group-allowed-cli-warn-by-default-lint.rs:8:25
31-
|
32-
LL | pub fn function(_x: Box<SomeTrait>) {}
33-
| ^^^^^^^^^
34-
|
35-
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
36-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
37-
help: use `dyn`
38-
|
39-
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
40-
| +++
41-
42-
warning: 3 warnings emitted
16+
warning: 1 warning emitted
4317

tests/ui/lint/force-warn/lint-group-allowed-lint-group.rs

-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,5 @@ pub trait SomeTrait {}
1010
pub fn function(_x: Box<SomeTrait>) {}
1111
//~^ WARN trait objects without an explicit `dyn` are deprecated
1212
//~| WARN this is accepted in the current edition
13-
//~| WARN trait objects without an explicit `dyn` are deprecated
14-
//~| WARN this is accepted in the current edition
15-
//~| WARN trait objects without an explicit `dyn` are deprecated
16-
//~| WARN this is accepted in the current edition
1713

1814
fn main() {}

tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr

+1-27
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,5 @@ help: use `dyn`
1313
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
1414
| +++
1515

16-
warning: trait objects without an explicit `dyn` are deprecated
17-
--> $DIR/lint-group-allowed-lint-group.rs:10:25
18-
|
19-
LL | pub fn function(_x: Box<SomeTrait>) {}
20-
| ^^^^^^^^^
21-
|
22-
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
23-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
24-
help: use `dyn`
25-
|
26-
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
27-
| +++
28-
29-
warning: trait objects without an explicit `dyn` are deprecated
30-
--> $DIR/lint-group-allowed-lint-group.rs:10:25
31-
|
32-
LL | pub fn function(_x: Box<SomeTrait>) {}
33-
| ^^^^^^^^^
34-
|
35-
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
36-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
37-
help: use `dyn`
38-
|
39-
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
40-
| +++
41-
42-
warning: 3 warnings emitted
16+
warning: 1 warning emitted
4317

tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.rs

-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,5 @@ pub trait SomeTrait {}
1010
pub fn function(_x: Box<SomeTrait>) {}
1111
//~^ WARN trait objects without an explicit `dyn` are deprecated
1212
//~| WARN this is accepted in the current edition
13-
//~| WARN trait objects without an explicit `dyn` are deprecated
14-
//~| WARN this is accepted in the current edition
15-
//~| WARN trait objects without an explicit `dyn` are deprecated
16-
//~| WARN this is accepted in the current edition
1713

1814
fn main() {}

tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr

+1-27
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,5 @@ help: use `dyn`
1313
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
1414
| +++
1515

16-
warning: trait objects without an explicit `dyn` are deprecated
17-
--> $DIR/lint-group-allowed-warn-by-default-lint.rs:10:25
18-
|
19-
LL | pub fn function(_x: Box<SomeTrait>) {}
20-
| ^^^^^^^^^
21-
|
22-
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
23-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
24-
help: use `dyn`
25-
|
26-
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
27-
| +++
28-
29-
warning: trait objects without an explicit `dyn` are deprecated
30-
--> $DIR/lint-group-allowed-warn-by-default-lint.rs:10:25
31-
|
32-
LL | pub fn function(_x: Box<SomeTrait>) {}
33-
| ^^^^^^^^^
34-
|
35-
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
36-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
37-
help: use `dyn`
38-
|
39-
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
40-
| +++
41-
42-
warning: 3 warnings emitted
16+
warning: 1 warning emitted
4317

tests/ui/lint/lint-stability-deprecated.rs

-3
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,10 @@ mod cross_crate {
9696
struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
9797
struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
9898
//~^ WARN use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`: text
99-
//~| WARN use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`: text
10099
type A = dyn TraitWithAssociatedTypes<
101100
TypeUnstable = u8,
102101
TypeDeprecated = u16,
103102
//~^ WARN use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`
104-
//~| WARN use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`
105-
//~| WARN use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`
106103
>;
107104

108105
let _ = DeprecatedStruct { //~ WARN use of deprecated struct `lint_stability::DeprecatedStruct`

0 commit comments

Comments
 (0)