Auto merge of #132580 - compiler-errors:globs, r=Noratrieb
Remove unnecessary pub enum glob-imports from `rustc_middle::ty` We used to have an idiom in the compiler where we'd prefix or suffix all the variants of an enum, for example `BoundRegionKind`, with something like `Br`, and then *glob-import* that enum variant directly. `@noratrieb` brought this up, and I think that it's easier to read when we just use the normal style `EnumName::Variant`. This PR is a bit large, but it's just naming. The only somewhat opinionated change that this PR does is rename `BorrowKind::Imm` to `BorrowKind::Immutable` and same for the other variants. I think these enums are used sparingly enough that the extra length is fine. r? `@noratrieb` or reassign
This commit is contained in:
commit
d8a3fcc792
@ -80,7 +80,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
|
|||||||
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||||
|
|
||||||
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) {
|
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) {
|
||||||
if bk == ty::BorrowKind::MutBorrow {
|
if bk == ty::BorrowKind::Mutable {
|
||||||
if let PlaceBase::Local(id) = cmt.place.base {
|
if let PlaceBase::Local(id) = cmt.place.base {
|
||||||
if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
|
if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
|
||||||
self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id));
|
self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id));
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
use rustc_ast::ast;
|
use rustc_ast::ast;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
|
use rustc_middle::ty::AssocItemContainer;
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
use rustc_span::{Span, sym};
|
use rustc_span::{Span, sym};
|
||||||
|
|
||||||
@ -138,7 +139,6 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
|
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
|
||||||
use rustc_middle::ty::{ImplContainer, TraitContainer};
|
|
||||||
if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable_or_proc_macro(cx) {
|
if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable_or_proc_macro(cx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -156,8 +156,8 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
|
|||||||
let assoc_item = cx.tcx.associated_item(impl_item.owner_id);
|
let assoc_item = cx.tcx.associated_item(impl_item.owner_id);
|
||||||
let container_id = assoc_item.container_id(cx.tcx);
|
let container_id = assoc_item.container_id(cx.tcx);
|
||||||
let trait_def_id = match assoc_item.container {
|
let trait_def_id = match assoc_item.container {
|
||||||
TraitContainer => Some(container_id),
|
AssocItemContainer::Trait => Some(container_id),
|
||||||
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
|
AssocItemContainer::Impl => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(trait_def_id) = trait_def_id {
|
if let Some(trait_def_id) = trait_def_id {
|
||||||
|
@ -417,8 +417,8 @@ fn borrow(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, id: HirId, borrow: ty::Bor
|
|||||||
// a closure, it'll return this variant whereas if you have just an index access, it'll
|
// a closure, it'll return this variant whereas if you have just an index access, it'll
|
||||||
// return `ImmBorrow`. So if there is "Unique" and it's a mutable reference, we add it
|
// return `ImmBorrow`. So if there is "Unique" and it's a mutable reference, we add it
|
||||||
// to the mutably used variables set.
|
// to the mutably used variables set.
|
||||||
if borrow == ty::BorrowKind::MutBorrow
|
if borrow == ty::BorrowKind::Mutable
|
||||||
|| (borrow == ty::BorrowKind::UniqueImmBorrow && base_ty.ref_mutability() == Some(Mutability::Mut))
|
|| (borrow == ty::BorrowKind::UniqueImmutable && base_ty.ref_mutability() == Some(Mutability::Mut))
|
||||||
{
|
{
|
||||||
self.add_mutably_used_var(*vid);
|
self.add_mutably_used_var(*vid);
|
||||||
} else if self.is_in_unsafe_block(id) {
|
} else if self.is_in_unsafe_block(id) {
|
||||||
@ -426,7 +426,7 @@ fn borrow(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, id: HirId, borrow: ty::Bor
|
|||||||
// upon!
|
// upon!
|
||||||
self.add_mutably_used_var(*vid);
|
self.add_mutably_used_var(*vid);
|
||||||
}
|
}
|
||||||
} else if borrow == ty::ImmBorrow {
|
} else if borrow == ty::BorrowKind::Immutable {
|
||||||
// If there is an `async block`, it'll contain a call to a closure which we need to
|
// If there is an `async block`, it'll contain a call to a closure which we need to
|
||||||
// go into to ensure all "mutate" checks are found.
|
// go into to ensure all "mutate" checks are found.
|
||||||
if let Node::Expr(Expr {
|
if let Node::Expr(Expr {
|
||||||
|
@ -102,7 +102,7 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
|
|||||||
struct S(HirIdSet);
|
struct S(HirIdSet);
|
||||||
impl Delegate<'_> for S {
|
impl Delegate<'_> for S {
|
||||||
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
|
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
|
||||||
if matches!(kind, BorrowKind::ImmBorrow | BorrowKind::UniqueImmBorrow) {
|
if matches!(kind, BorrowKind::Immutable | BorrowKind::UniqueImmutable) {
|
||||||
self.0.insert(match place.place.base {
|
self.0.insert(match place.place.base {
|
||||||
PlaceBase::Local(id) => id,
|
PlaceBase::Local(id) => id,
|
||||||
PlaceBase::Upvar(id) => id.var_path.hir_id,
|
PlaceBase::Upvar(id) => id.var_path.hir_id,
|
||||||
@ -127,7 +127,7 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
|
|||||||
struct S(HirIdSet);
|
struct S(HirIdSet);
|
||||||
impl Delegate<'_> for S {
|
impl Delegate<'_> for S {
|
||||||
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
|
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
|
||||||
if matches!(kind, BorrowKind::MutBorrow) {
|
if matches!(kind, BorrowKind::Mutable) {
|
||||||
self.0.insert(match place.place.base {
|
self.0.insert(match place.place.base {
|
||||||
PlaceBase::Local(id) => id,
|
PlaceBase::Local(id) => id,
|
||||||
PlaceBase::Upvar(id) => id.var_path.hir_id,
|
PlaceBase::Upvar(id) => id.var_path.hir_id,
|
||||||
|
@ -217,7 +217,7 @@ fn is_option_as_mut_use(tcx: TyCtxt<'_>, expr_id: HirId) -> bool {
|
|||||||
|
|
||||||
impl<'tcx> Delegate<'tcx> for MutationVisitor<'tcx> {
|
impl<'tcx> Delegate<'tcx> for MutationVisitor<'tcx> {
|
||||||
fn borrow(&mut self, cat: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) {
|
fn borrow(&mut self, cat: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) {
|
||||||
if let ty::BorrowKind::MutBorrow = bk
|
if let ty::BorrowKind::Mutable = bk
|
||||||
&& is_potentially_local_place(self.local_id, &cat.place)
|
&& is_potentially_local_place(self.local_id, &cat.place)
|
||||||
&& !is_option_as_mut_use(self.tcx, diag_expr_id)
|
&& !is_option_as_mut_use(self.tcx, diag_expr_id)
|
||||||
{
|
{
|
||||||
|
@ -1209,8 +1209,8 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
|
|||||||
let capture = match capture.info.capture_kind {
|
let capture = match capture.info.capture_kind {
|
||||||
UpvarCapture::ByValue => CaptureKind::Value,
|
UpvarCapture::ByValue => CaptureKind::Value,
|
||||||
UpvarCapture::ByRef(kind) => match kind {
|
UpvarCapture::ByRef(kind) => match kind {
|
||||||
BorrowKind::ImmBorrow => CaptureKind::Ref(Mutability::Not),
|
BorrowKind::Immutable => CaptureKind::Ref(Mutability::Not),
|
||||||
BorrowKind::UniqueImmBorrow | BorrowKind::MutBorrow => {
|
BorrowKind::UniqueImmutable | BorrowKind::Mutable => {
|
||||||
CaptureKind::Ref(Mutability::Mut)
|
CaptureKind::Ref(Mutability::Mut)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3340,8 +3340,8 @@ pub fn get_path_from_caller_to_method_type<'tcx>(
|
|||||||
let assoc_item = tcx.associated_item(method);
|
let assoc_item = tcx.associated_item(method);
|
||||||
let def_id = assoc_item.container_id(tcx);
|
let def_id = assoc_item.container_id(tcx);
|
||||||
match assoc_item.container {
|
match assoc_item.container {
|
||||||
rustc_ty::TraitContainer => get_path_to_callee(tcx, from, def_id),
|
rustc_ty::AssocItemContainer::Trait => get_path_to_callee(tcx, from, def_id),
|
||||||
rustc_ty::ImplContainer => {
|
rustc_ty::AssocItemContainer::Impl => {
|
||||||
let ty = tcx.type_of(def_id).instantiate_identity();
|
let ty = tcx.type_of(def_id).instantiate_identity();
|
||||||
get_path_to_ty(tcx, from, ty, args)
|
get_path_to_ty(tcx, from, ty, args)
|
||||||
},
|
},
|
||||||
|
@ -67,7 +67,7 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
|
|||||||
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
|
||||||
|
|
||||||
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind) {
|
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind) {
|
||||||
if bk == ty::BorrowKind::MutBorrow {
|
if bk == ty::BorrowKind::Mutable {
|
||||||
self.update(cmt);
|
self.update(cmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user