Skip to content

Commit

Permalink
Stop using hir_ty_to_ty in rustc_privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 5, 2023
1 parent 1dceddf commit c2bcced
Show file tree
Hide file tree
Showing 24 changed files with 117 additions and 436 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4217,6 +4217,7 @@ dependencies = [
"rustc_middle",
"rustc_session",
"rustc_span",
"rustc_ty_utils",
"tracing",
]

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_privacy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ rustc_middle = { path = "../rustc_middle" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_hir_analysis = { path = "../rustc_hir_analysis" }
rustc_ty_utils = { path = "../rustc_ty_utils" }
tracing = "0.1"
29 changes: 27 additions & 2 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ where
{
type BreakTy = V::BreakTy;

fn visit_predicate(&mut self, p: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
self.visit_clause(p.as_clause().unwrap())
}

fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<V::BreakTy> {
let tcx = self.def_id_visitor.tcx();
// GenericArgs are not visited here because they are visited below
Expand Down Expand Up @@ -1142,6 +1146,14 @@ impl<'tcx> TypePrivacyVisitor<'tcx> {
}
}

impl<'tcx> rustc_ty_utils::sig_types::Spanned<'tcx> for TypePrivacyVisitor<'tcx> {
type BreakTy = ();
fn visit(&mut self, span: Span, value: impl TypeVisitable<TyCtxt<'tcx>>) -> ControlFlow<()> {
self.span = span;
value.visit_with(&mut self.skeleton())
}
}

impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
type NestedFilter = nested_filter::All;

Expand Down Expand Up @@ -1183,7 +1195,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
// Types in signatures.
// FIXME: This is very ineffective. Ideally each HIR type should be converted
// into a semantic type only once and the result should be cached somehow.
if self.visit(rustc_hir_analysis::hir_ty_to_ty(self.tcx, hir_ty)).is_break() {
if self.visit(rustc_hir_analysis::hir_ty_to_ty(self.tcx(), hir_ty)).is_break() {
return;
}
}
Expand Down Expand Up @@ -1348,7 +1360,20 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let orig_current_item = mem::replace(&mut self.current_item, item.owner_id.def_id);
let old_maybe_typeck_results = self.maybe_typeck_results.take();
intravisit::walk_item(self, item);
rustc_ty_utils::sig_types::walk_types(self.tcx(), item.owner_id.def_id, self);
match item.kind {
hir::ItemKind::Macro(_, _) => intravisit::walk_item(self, item),
hir::ItemKind::Static(_, _, body_id)
| hir::ItemKind::Const(_, body_id)
| hir::ItemKind::Fn(_, _, body_id) => self.visit_nested_body(body_id),
hir::ItemKind::Impl(hir::Impl { of_trait: Some(tr), .. }) => {
self.span = tr.path.span;
let trait_ref =
self.tcx().impl_trait_ref(item.owner_id.def_id).unwrap().instantiate_identity();
self.visit_def_id(trait_ref.def_id, "trait", &trait_ref.print_only_trait_path());
}
_ => {}
}
self.maybe_typeck_results = old_maybe_typeck_results;
self.current_item = orig_current_item;
}
Expand Down
8 changes: 0 additions & 8 deletions tests/ui/dyn-keyword/dyn-2018-edition-lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ fn function(x: &SomeTrait, y: Box<SomeTrait>) {
//~| WARN this is accepted in the current edition
//~| ERROR trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| ERROR trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| ERROR trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| ERROR trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| ERROR trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
let _x: &SomeTrait = todo!();
//~^ ERROR trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
Expand Down
56 changes: 2 additions & 54 deletions tests/ui/dyn-keyword/dyn-2018-edition-lint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
| +++

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

error: trait objects without an explicit `dyn` are deprecated
--> $DIR/dyn-2018-edition-lint.rs:4:17
|
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
| +++

error: trait objects without an explicit `dyn` are deprecated
--> $DIR/dyn-2018-edition-lint.rs:4:17
|
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
| +++

error: trait objects without an explicit `dyn` are deprecated
--> $DIR/dyn-2018-edition-lint.rs:4:35
|
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
| +++

error: trait objects without an explicit `dyn` are deprecated
--> $DIR/dyn-2018-edition-lint.rs:4:35
|
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
| +++

error: aborting due to 7 previous errors
error: aborting due to 3 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ pub trait SomeTrait {}
pub fn function(_x: Box<SomeTrait>) {}
//~^ WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,5 @@ help: use `dyn`
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/allowed-group-warn-by-default-lint.rs:10:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/allowed-group-warn-by-default-lint.rs:10:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: 3 warnings emitted
warning: 1 warning emitted

4 changes: 0 additions & 4 deletions tests/ui/lint/force-warn/cap-lints-allow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ pub trait SomeTrait {}
pub fn function(_x: Box<SomeTrait>) {}
//~^ WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition

fn main() {}
28 changes: 1 addition & 27 deletions tests/ui/lint/force-warn/cap-lints-allow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,5 @@ help: use `dyn`
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/cap-lints-allow.rs:8:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/cap-lints-allow.rs:8:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: 3 warnings emitted
warning: 1 warning emitted

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ pub trait SomeTrait {}
pub fn function(_x: Box<SomeTrait>) {}
//~^ WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,5 @@ help: use `dyn`
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/lint-group-allowed-cli-warn-by-default-lint.rs:8:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/lint-group-allowed-cli-warn-by-default-lint.rs:8:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: 3 warnings emitted
warning: 1 warning emitted

4 changes: 0 additions & 4 deletions tests/ui/lint/force-warn/lint-group-allowed-lint-group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ pub trait SomeTrait {}
pub fn function(_x: Box<SomeTrait>) {}
//~^ WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition

fn main() {}
28 changes: 1 addition & 27 deletions tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,5 @@ help: use `dyn`
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/lint-group-allowed-lint-group.rs:10:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/lint-group-allowed-lint-group.rs:10:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: 3 warnings emitted
warning: 1 warning emitted

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,5 @@ pub trait SomeTrait {}
pub fn function(_x: Box<SomeTrait>) {}
//~^ WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,5 @@ help: use `dyn`
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/lint-group-allowed-warn-by-default-lint.rs:10:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/lint-group-allowed-warn-by-default-lint.rs:10:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
| +++

warning: 3 warnings emitted
warning: 1 warning emitted

3 changes: 0 additions & 3 deletions tests/ui/lint/lint-stability-deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,10 @@ mod cross_crate {
struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
//~^ WARN use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`: text
//~| WARN use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`: text
type A = dyn TraitWithAssociatedTypes<
TypeUnstable = u8,
TypeDeprecated = u16,
//~^ WARN use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`
//~| WARN use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`
//~| WARN use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`
>;

let _ = DeprecatedStruct { //~ WARN use of deprecated struct `lint_stability::DeprecatedStruct`
Expand Down
Loading

0 comments on commit c2bcced

Please sign in to comment.