1
Fork 0

Simplify intra-crate qualifiers.

The following is a weird pattern for a file within `rustc_middle`:
```
use rustc_middle::aaa;
use crate::bbb;
```
More sensible and standard would be this:
```
use crate::{aaa, bbb};
```
I.e. we generally prefer using `crate::` to using a crate's own name.
(Exceptions are things like in macros where `crate::` doesn't work
because the macro is used in multiple crates.)

This commit fixes a bunch of these weird qualifiers.
This commit is contained in:
Nicholas Nethercote 2025-02-11 13:58:38 +11:00
parent 6171d944ae
commit af6020320d
20 changed files with 53 additions and 51 deletions

View file

@ -108,13 +108,13 @@ impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::ExistentialTrait
} }
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::UnevaluatedConst<I> { impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::UnevaluatedConst<I> {
fn into_diag_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
format!("{self:?}").into_diag_arg() format!("{self:?}").into_diag_arg()
} }
} }
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::FnSig<I> { impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::FnSig<I> {
fn into_diag_arg(self) -> rustc_errors::DiagArgValue { fn into_diag_arg(self) -> DiagArgValue {
format!("{self:?}").into_diag_arg() format!("{self:?}").into_diag_arg()
} }
} }

View file

@ -10,11 +10,10 @@ use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_hir::*; use rustc_hir::*;
use rustc_hir_pretty as pprust_hir; use rustc_hir_pretty as pprust_hir;
use rustc_middle::hir::nested_filter;
use rustc_span::def_id::StableCrateId; use rustc_span::def_id::StableCrateId;
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym, with_metavar_spans}; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym, with_metavar_spans};
use crate::hir::ModuleItems; use crate::hir::{ModuleItems, nested_filter};
use crate::middle::debugger_visualizer::DebuggerVisualizerFile; use crate::middle::debugger_visualizer::DebuggerVisualizerFile;
use crate::query::LocalCrate; use crate::query::LocalCrate;
use crate::ty::TyCtxt; use crate::ty::TyCtxt;

View file

@ -13,7 +13,6 @@ use rustc_feature::GateIssue;
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap}; use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap};
use rustc_hir::{self as hir, HirId}; use rustc_hir::{self as hir, HirId};
use rustc_macros::{Decodable, Encodable, HashStable, Subdiagnostic}; use rustc_macros::{Decodable, Encodable, HashStable, Subdiagnostic};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_session::Session; use rustc_session::Session;
use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE}; use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE};
use rustc_session::lint::{BuiltinLintDiag, DeprecatedSinceKind, Level, Lint, LintBuffer}; use rustc_session::lint::{BuiltinLintDiag, DeprecatedSinceKind, Level, Lint, LintBuffer};
@ -23,6 +22,7 @@ use tracing::debug;
pub use self::StabilityLevel::*; pub use self::StabilityLevel::*;
use crate::ty::TyCtxt; use crate::ty::TyCtxt;
use crate::ty::print::with_no_trimmed_paths;
#[derive(PartialEq, Clone, Copy, Debug)] #[derive(PartialEq, Clone, Copy, Debug)]
pub enum StabilityLevel { pub enum StabilityLevel {

View file

@ -1,5 +1,6 @@
use gsgdt::{Edge, Graph, Node, NodeStyle}; use gsgdt::{Edge, Graph, Node, NodeStyle};
use rustc_middle::mir::*;
use crate::mir::*;
/// Convert an MIR function into a gsgdt Graph /// Convert an MIR function into a gsgdt Graph
pub(crate) fn mir_fn_to_generic_graph<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Graph { pub(crate) fn mir_fn_to_generic_graph<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Graph {

View file

@ -2,7 +2,8 @@ use std::io::{self, Write};
use rustc_data_structures::graph::{self, iterate}; use rustc_data_structures::graph::{self, iterate};
use rustc_graphviz as dot; use rustc_graphviz as dot;
use rustc_middle::ty::TyCtxt;
use crate::ty::TyCtxt;
pub struct GraphvizWriter< pub struct GraphvizWriter<
'a, 'a,

View file

@ -2,10 +2,10 @@ use std::io::{self, Write};
use gsgdt::GraphvizSettings; use gsgdt::GraphvizSettings;
use rustc_graphviz as dot; use rustc_graphviz as dot;
use rustc_middle::mir::*;
use super::generic_graph::mir_fn_to_generic_graph; use super::generic_graph::mir_fn_to_generic_graph;
use super::pretty::dump_mir_def_ids; use super::pretty::dump_mir_def_ids;
use crate::mir::*;
/// Write a graphviz DOT graph of a list of MIRs. /// Write a graphviz DOT graph of a list of MIRs.
pub fn write_mir_graphviz<W>(tcx: TyCtxt<'_>, single: Option<DefId>, w: &mut W) -> io::Result<()> pub fn write_mir_graphviz<W>(tcx: TyCtxt<'_>, single: Option<DefId>, w: &mut W) -> io::Result<()>

View file

@ -20,7 +20,6 @@ use rustc_data_structures::sync::{AtomicU64, Lock};
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Encodable};
use tracing::{debug, trace}; use tracing::{debug, trace};
// Also make the error macros available from this module. // Also make the error macros available from this module.
@ -46,6 +45,7 @@ pub use self::pointer::{CtfeProvenance, Pointer, PointerArithmetic, Provenance};
pub use self::value::Scalar; pub use self::value::Scalar;
use crate::mir; use crate::mir;
use crate::ty::codec::{TyDecoder, TyEncoder}; use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::print::with_no_trimmed_paths;
use crate::ty::{self, Instance, Ty, TyCtxt}; use crate::ty::{self, Instance, Ty, TyCtxt};
/// Uniquely identifies one of the following: /// Uniquely identifies one of the following:

View file

@ -1,6 +1,7 @@
use rustc_middle::mir::*;
use tracing::debug; use tracing::debug;
use crate::mir::*;
/// This struct represents a patch to MIR, which can add /// This struct represents a patch to MIR, which can add
/// new statements and basic blocks and patch over block /// new statements and basic blocks and patch over block
/// terminators. /// terminators.

View file

@ -5,17 +5,16 @@ use std::{fs, io};
use rustc_abi::Size; use rustc_abi::Size;
use rustc_ast::InlineAsmTemplatePiece; use rustc_ast::InlineAsmTemplatePiece;
use rustc_middle::mir::interpret::{
AllocBytes, AllocId, Allocation, GlobalAlloc, Pointer, Provenance, alloc_range,
read_target_uint,
};
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*;
use tracing::trace; use tracing::trace;
use ty::print::PrettyPrinter; use ty::print::PrettyPrinter;
use super::graphviz::write_mir_fn_graphviz; use super::graphviz::write_mir_fn_graphviz;
use crate::mir::interpret::ConstAllocation; use crate::mir::interpret::{
AllocBytes, AllocId, Allocation, ConstAllocation, GlobalAlloc, Pointer, Provenance,
alloc_range, read_target_uint,
};
use crate::mir::visit::Visitor;
use crate::mir::*;
const INDENT: &str = " "; const INDENT: &str = " ";
/// Alignment for lining up comments following MIR statements /// Alignment for lining up comments following MIR statements

View file

@ -101,9 +101,9 @@ impl<T> EraseType for Result<&'_ T, &'_ ty::layout::FnAbiError<'_>> {
type Result = [u8; size_of::<Result<&'static (), &'static ty::layout::FnAbiError<'static>>>()]; type Result = [u8; size_of::<Result<&'static (), &'static ty::layout::FnAbiError<'static>>>()];
} }
impl<T> EraseType for Result<(&'_ T, rustc_middle::thir::ExprId), rustc_errors::ErrorGuaranteed> { impl<T> EraseType for Result<(&'_ T, crate::thir::ExprId), rustc_errors::ErrorGuaranteed> {
type Result = [u8; size_of::< type Result = [u8; size_of::<
Result<(&'static (), rustc_middle::thir::ExprId), rustc_errors::ErrorGuaranteed>, Result<(&'static (), crate::thir::ExprId), rustc_errors::ErrorGuaranteed>,
>()]; >()];
} }

View file

@ -11,12 +11,6 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE, LocalDefId, Stab
use rustc_hir::definitions::DefPathHash; use rustc_hir::definitions::DefPathHash;
use rustc_index::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
use rustc_macros::{Decodable, Encodable}; use rustc_macros::{Decodable, Encodable};
use rustc_middle::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::mir::{self, interpret};
use rustc_middle::ty::codec::{RefDecodable, TyDecoder, TyEncoder};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_query_system::query::QuerySideEffects; use rustc_query_system::query::QuerySideEffects;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder}; use rustc_serialize::opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
@ -30,6 +24,13 @@ use rustc_span::{
SpanDecoder, SpanEncoder, StableSourceFileId, Symbol, SpanDecoder, SpanEncoder, StableSourceFileId, Symbol,
}; };
use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
use crate::mir::interpret::{AllocDecodingSession, AllocDecodingState};
use crate::mir::mono::MonoItem;
use crate::mir::{self, interpret};
use crate::ty::codec::{RefDecodable, TyDecoder, TyEncoder};
use crate::ty::{self, Ty, TyCtxt};
const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE; const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
// A normal span encoded with both location information and a `SyntaxContext` // A normal span encoded with both location information and a `SyntaxContext`
@ -563,7 +564,7 @@ impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> {
} }
} }
rustc_middle::implement_ty_decoder!(CacheDecoder<'a, 'tcx>); crate::implement_ty_decoder!(CacheDecoder<'a, 'tcx>);
// This ensures that the `Decodable<opaque::Decoder>::decode` specialization for `Vec<u8>` is used // This ensures that the `Decodable<opaque::Decoder>::decode` specialization for `Vec<u8>` is used
// when a `CacheDecoder` is passed to `Decodable::decode`. Unfortunately, we have to manually opt // when a `CacheDecoder` is passed to `Decodable::decode`. Unfortunately, we have to manually opt

View file

@ -20,20 +20,21 @@ use rustc_hir::def_id::DefId;
use rustc_hir::{BindingMode, ByRef, HirId, MatchSource, RangeEnd}; use rustc_hir::{BindingMode, ByRef, HirId, MatchSource, RangeEnd};
use rustc_index::{IndexVec, newtype_index}; use rustc_index::{IndexVec, newtype_index};
use rustc_macros::{HashStable, TypeVisitable}; use rustc_macros::{HashStable, TypeVisitable};
use rustc_middle::middle::region;
use rustc_middle::mir::interpret::AllocId;
use rustc_middle::mir::{self, BinOp, BorrowKind, FakeReadCause, UnOp};
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::IntegerExt;
use rustc_middle::ty::{
self, AdtDef, CanonicalUserType, CanonicalUserTypeAnnotation, FnSig, GenericArgsRef, List, Ty,
TyCtxt, UpvarArgs,
};
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
use rustc_span::{ErrorGuaranteed, Span, Symbol}; use rustc_span::{ErrorGuaranteed, Span, Symbol};
use rustc_target::asm::InlineAsmRegOrRegClass; use rustc_target::asm::InlineAsmRegOrRegClass;
use tracing::instrument; use tracing::instrument;
use crate::middle::region;
use crate::mir::interpret::AllocId;
use crate::mir::{self, BinOp, BorrowKind, FakeReadCause, UnOp};
use crate::ty::adjustment::PointerCoercion;
use crate::ty::layout::IntegerExt;
use crate::ty::{
self, AdtDef, CanonicalUserType, CanonicalUserTypeAnnotation, FnSig, GenericArgsRef, List, Ty,
TyCtxt, UpvarArgs,
};
pub mod visit; pub mod visit;
macro_rules! thir_with_elements { macro_rules! thir_with_elements {

View file

@ -2,8 +2,8 @@
// typeck and codegen. // typeck and codegen.
use rustc_macros::{HashStable, TyDecodable, TyEncodable}; use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_middle::mir;
use crate::mir;
use crate::ty::{self, Ty}; use crate::ty::{self, Ty};
/// Types that are represented as ints. /// Types that are represented as ints.

View file

@ -13,8 +13,6 @@ use std::marker::DiscriminantKind;
use rustc_abi::{FieldIdx, VariantIdx}; use rustc_abi::{FieldIdx, VariantIdx};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::ty::TyCtxt;
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Encodable};
use rustc_span::Span; use rustc_span::Span;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
@ -23,9 +21,10 @@ pub use rustc_type_ir::{TyDecoder, TyEncoder};
use crate::arena::ArenaAllocatable; use crate::arena::ArenaAllocatable;
use crate::infer::canonical::{CanonicalVarInfo, CanonicalVarInfos}; use crate::infer::canonical::{CanonicalVarInfo, CanonicalVarInfos};
use crate::mir::interpret::{AllocId, ConstAllocation, CtfeProvenance}; use crate::mir::interpret::{AllocId, ConstAllocation, CtfeProvenance};
use crate::mir::mono::MonoItem;
use crate::mir::{self}; use crate::mir::{self};
use crate::traits; use crate::traits;
use crate::ty::{self, AdtDef, GenericArgsRef, Ty}; use crate::ty::{self, AdtDef, GenericArgsRef, Ty, TyCtxt};
/// The shorthand encoding uses an enum's variant index `usize` /// The shorthand encoding uses an enum's variant index `usize`
/// and is offset by this value so it never matches a real variant. /// and is offset by this value so it never matches a real variant.

View file

@ -10,13 +10,13 @@ use rustc_hir::def_id::{CrateNum, DefId};
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::FiniteBitSet; use rustc_index::bit_set::FiniteBitSet;
use rustc_macros::{Decodable, Encodable, HashStable, Lift, TyDecodable, TyEncodable}; use rustc_macros::{Decodable, Encodable, HashStable, Lift, TyDecodable, TyEncodable};
use rustc_middle::ty::normalize_erasing_regions::NormalizationError;
use rustc_span::def_id::LOCAL_CRATE; use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::{DUMMY_SP, Span, Symbol}; use rustc_span::{DUMMY_SP, Span, Symbol};
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use crate::error; use crate::error;
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::ty::normalize_erasing_regions::NormalizationError;
use crate::ty::print::{FmtPrinter, Printer, shrunk_instance_name}; use crate::ty::print::{FmtPrinter, Printer, shrunk_instance_name};
use crate::ty::{ use crate::ty::{
self, EarlyBinder, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, self, EarlyBinder, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,

View file

@ -1512,7 +1512,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
ty::ExprKind::Binop(op) => { ty::ExprKind::Binop(op) => {
let (_, _, c1, c2) = expr.binop_args(); let (_, _, c1, c2) = expr.binop_args();
let precedence = |binop: rustc_middle::mir::BinOp| { let precedence = |binop: crate::mir::BinOp| {
use rustc_ast::util::parser::AssocOp; use rustc_ast::util::parser::AssocOp;
AssocOp::from_ast_binop(binop.to_hir_binop()).precedence() AssocOp::from_ast_binop(binop.to_hir_binop()).precedence()
}; };
@ -1558,7 +1558,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
ty::ExprKind::UnOp(op) => { ty::ExprKind::UnOp(op) => {
let (_, ct) = expr.unop_args(); let (_, ct) = expr.unop_args();
use rustc_middle::mir::UnOp; use crate::mir::UnOp;
let formatted_op = match op { let formatted_op = match op {
UnOp::Not => "!", UnOp::Not => "!",
UnOp::Neg => "-", UnOp::Neg => "-",

View file

@ -14,13 +14,13 @@ use rustc_hir::{
}; };
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_middle::mir::FakeReadCause;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::Span; use rustc_span::Span;
use super::RvalueScopes; use super::RvalueScopes;
use crate::hir::place::Place as HirPlace; use crate::hir::place::Place as HirPlace;
use crate::infer::canonical::Canonical; use crate::infer::canonical::Canonical;
use crate::mir::FakeReadCause;
use crate::traits::ObligationCause; use crate::traits::ObligationCause;
use crate::ty::{ use crate::ty::{
self, BoundVar, CanonicalPolyFnSig, ClosureSizeProfileData, GenericArgKind, GenericArgs, self, BoundVar, CanonicalPolyFnSig, ClosureSizeProfileData, GenericArgKind, GenericArgs,

View file

@ -2,9 +2,9 @@ pub mod bug;
#[derive(Default, Copy, Clone)] #[derive(Default, Copy, Clone)]
pub struct Providers { pub struct Providers {
pub queries: rustc_middle::query::Providers, pub queries: crate::query::Providers,
pub extern_queries: rustc_middle::query::ExternProviders, pub extern_queries: crate::query::ExternProviders,
pub hooks: rustc_middle::hooks::Providers, pub hooks: crate::hooks::Providers,
} }
/// Backwards compatibility hack to keep the diff small. This /// Backwards compatibility hack to keep the diff small. This
@ -17,7 +17,7 @@ impl std::ops::DerefMut for Providers {
} }
impl std::ops::Deref for Providers { impl std::ops::Deref for Providers {
type Target = rustc_middle::query::Providers; type Target = crate::query::Providers;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.queries &self.queries

View file

@ -7,7 +7,6 @@ use rustc_errors::codes::*;
use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err}; use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_middle::ty::{self, Representability, Ty, TyCtxt};
use rustc_query_system::Value; use rustc_query_system::Value;
use rustc_query_system::query::{CycleError, report_cycle}; use rustc_query_system::query::{CycleError, report_cycle};
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
@ -15,6 +14,7 @@ use rustc_span::{ErrorGuaranteed, Span};
use crate::dep_graph::dep_kinds; use crate::dep_graph::dep_kinds;
use crate::query::plumbing::CyclePlaceholder; use crate::query::plumbing::CyclePlaceholder;
use crate::ty::{self, Representability, Ty, TyCtxt};
impl<'tcx> Value<TyCtxt<'tcx>> for Ty<'_> { impl<'tcx> Value<TyCtxt<'tcx>> for Ty<'_> {
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &CycleError, guar: ErrorGuaranteed) -> Self { fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &CycleError, guar: ErrorGuaranteed) -> Self {

View file

@ -1,10 +1,10 @@
pub use rustc_type_ir::relate::*;
use rustc_type_ir::solve::Goal;
use rustc_type_ir::{self as ty, InferCtxtLike, Interner};
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use self::combine::{PredicateEmittingRelation, super_combine_consts, super_combine_tys}; use self::combine::{PredicateEmittingRelation, super_combine_consts, super_combine_tys};
use crate::data_structures::DelayedSet; use crate::data_structures::DelayedSet;
pub use crate::relate::*;
use crate::solve::Goal;
use crate::{self as ty, InferCtxtLike, Interner};
pub trait RelateExt: InferCtxtLike { pub trait RelateExt: InferCtxtLike {
fn relate<T: Relate<Self::Interner>>( fn relate<T: Relate<Self::Interner>>(