Skip to content

Commit d8a3fcc

Browse files
committed
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
2 parents 63d0ba9 + efeed55 commit d8a3fcc

7 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎clippy_lints/src/loops/mut_range_bound.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
8080
fnconsume(&mutself, _:&PlaceWithHirId<'tcx>, _:HirId){}
8181

8282
fnborrow(&mutself,cmt:&PlaceWithHirId<'tcx>,diag_expr_id:HirId,bk: ty::BorrowKind){
83-
if bk == ty::BorrowKind::MutBorrow{
83+
if bk == ty::BorrowKind::Mutable{
8484
ifletPlaceBase::Local(id) = cmt.place.base{
8585
ifSome(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id){
8686
self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id));

‎clippy_lints/src/missing_inline.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use clippy_utils::diagnostics::span_lint;
22
use rustc_ast::ast;
33
use rustc_hir as hir;
44
use rustc_lint::{LateContext,LateLintPass,LintContext};
5+
use rustc_middle::ty::AssocItemContainer;
56
use rustc_session::declare_lint_pass;
67
use rustc_span::{Span, sym};
78

@@ -138,7 +139,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
138139
}
139140

140141
fncheck_impl_item(&mutself,cx:&LateContext<'tcx>,impl_item:&'tcx hir::ImplItem<'_>){
141-
use rustc_middle::ty::{ImplContainer,TraitContainer};
142142
if rustc_middle::lint::in_external_macro(cx.sess(), impl_item.span) || is_executable_or_proc_macro(cx){
143143
return;
144144
}
@@ -156,8 +156,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
156156
let assoc_item = cx.tcx.associated_item(impl_item.owner_id);
157157
let container_id = assoc_item.container_id(cx.tcx);
158158
let trait_def_id = match assoc_item.container{
159-
TraitContainer => Some(container_id),
160-
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
159+
AssocItemContainer::Trait => Some(container_id),
160+
AssocItemContainer::Impl => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
161161
};
162162

163163
ifletSome(trait_def_id) = trait_def_id {

‎clippy_lints/src/needless_pass_by_ref_mut.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,16 @@ impl<'tcx> euv::Delegate<'tcx> for MutablyUsedVariablesCtxt<'tcx> {
417417
// a closure, it'll return this variant whereas if you have just an index access, it'll
418418
// return `ImmBorrow`. So if there is "Unique" and it's a mutable reference, we add it
419419
// to the mutably used variables set.
420-
if borrow == ty::BorrowKind::MutBorrow
421-
|| (borrow == ty::BorrowKind::UniqueImmBorrow && base_ty.ref_mutability() == Some(Mutability::Mut))
420+
if borrow == ty::BorrowKind::Mutable
421+
|| (borrow == ty::BorrowKind::UniqueImmutable && base_ty.ref_mutability() == Some(Mutability::Mut))
422422
{
423423
self.add_mutably_used_var(*vid);
424424
}elseifself.is_in_unsafe_block(id){
425425
// If we are in an unsafe block, any operation on this variable must not be warned
426426
// upon!
427427
self.add_mutably_used_var(*vid);
428428
}
429-
}elseif borrow == ty::ImmBorrow{
429+
}elseif borrow == ty::BorrowKind::Immutable{
430430
// If there is an `async block`, it'll contain a call to a closure which we need to
431431
// go into to ensure all "mutate" checks are found.
432432
ifletNode::Expr(Expr{

‎clippy_lints/src/operators/assign_op_pattern.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
102102
structS(HirIdSet);
103103
implDelegate<'_>forS{
104104
fnborrow(&mutself,place:&PlaceWithHirId<'_>, _:HirId,kind:BorrowKind){
105-
ifmatches!(kind,BorrowKind::ImmBorrow | BorrowKind::UniqueImmBorrow){
105+
ifmatches!(kind,BorrowKind::Immutable | BorrowKind::UniqueImmutable){
106106
self.0.insert(match place.place.base{
107107
PlaceBase::Local(id) => id,
108108
PlaceBase::Upvar(id) => id.var_path.hir_id,
@@ -127,7 +127,7 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
127127
structS(HirIdSet);
128128
implDelegate<'_>forS{
129129
fnborrow(&mutself,place:&PlaceWithHirId<'_>, _:HirId,kind:BorrowKind){
130-
ifmatches!(kind,BorrowKind::MutBorrow){
130+
ifmatches!(kind,BorrowKind::Mutable){
131131
self.0.insert(match place.place.base{
132132
PlaceBase::Local(id) => id,
133133
PlaceBase::Upvar(id) => id.var_path.hir_id,

‎clippy_lints/src/unwrap.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn is_option_as_mut_use(tcx: TyCtxt<'_>, expr_id: HirId) -> bool {
217217

218218
impl<'tcx>Delegate<'tcx>forMutationVisitor<'tcx>{
219219
fnborrow(&mutself,cat:&PlaceWithHirId<'tcx>,diag_expr_id:HirId,bk: ty::BorrowKind){
220-
iflet ty::BorrowKind::MutBorrow = bk
220+
iflet ty::BorrowKind::Mutable = bk
221221
&& is_potentially_local_place(self.local_id,&cat.place)
222222
&& !is_option_as_mut_use(self.tcx, diag_expr_id)
223223
{

‎clippy_utils/src/lib.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,8 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'
12091209
let capture = match capture.info.capture_kind{
12101210
UpvarCapture::ByValue => CaptureKind::Value,
12111211
UpvarCapture::ByRef(kind) => match kind {
1212-
BorrowKind::ImmBorrow => CaptureKind::Ref(Mutability::Not),
1213-
BorrowKind::UniqueImmBorrow | BorrowKind::MutBorrow => {
1212+
BorrowKind::Immutable => CaptureKind::Ref(Mutability::Not),
1213+
BorrowKind::UniqueImmutable | BorrowKind::Mutable => {
12141214
CaptureKind::Ref(Mutability::Mut)
12151215
},
12161216
},
@@ -3340,8 +3340,8 @@ pub fn get_path_from_caller_to_method_type<'tcx>(
33403340
let assoc_item = tcx.associated_item(method);
33413341
let def_id = assoc_item.container_id(tcx);
33423342
match assoc_item.container{
3343-
rustc_ty::TraitContainer => get_path_to_callee(tcx, from, def_id),
3344-
rustc_ty::ImplContainer => {
3343+
rustc_ty::AssocItemContainer::Trait => get_path_to_callee(tcx, from, def_id),
3344+
rustc_ty::AssocItemContainer::Impl => {
33453345
let ty = tcx.type_of(def_id).instantiate_identity();
33463346
get_path_to_ty(tcx, from, ty, args)
33473347
},

‎clippy_utils/src/usage.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
6767
fnconsume(&mutself, _:&PlaceWithHirId<'tcx>, _:HirId){}
6868

6969
fnborrow(&mutself,cmt:&PlaceWithHirId<'tcx>, _:HirId,bk: ty::BorrowKind){
70-
if bk == ty::BorrowKind::MutBorrow{
70+
if bk == ty::BorrowKind::Mutable{
7171
self.update(cmt);
7272
}
7373
}

0 commit comments

Comments
 (0)