Skip to content

Remove in_band_lifetimes from rustc_middle #91984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_macros/src/type_foldable.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use quote::quote;
use syn::parse_quote;

pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
if let syn::Data::Union(_) = s.ast().data {
panic!("cannot derive on union")
}

if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
s.add_impl_generic(parse_quote! { 'tcx });
}

s.add_bounds(synstructure::AddBounds::Generics);
let body_visit = s.each(|bind| {
quote! {
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
@@ -201,7 +201,7 @@ crate fn make_compile_codegen_unit(tcx: TyCtxt<'_>, name: Symbol) -> DepNode {

// WARNING: `construct` is generic and does not know that `CompileMonoItem` takes `MonoItem`s as keys.
// Be very careful changing this type signature!
crate fn make_compile_mono_item(tcx: TyCtxt<'tcx>, mono_item: &MonoItem<'tcx>) -> DepNode {
crate fn make_compile_mono_item<'tcx>(tcx: TyCtxt<'tcx>, mono_item: &MonoItem<'tcx>) -> DepNode {
DepNode::construct(tcx, DepKind::CompileMonoItem, mono_item)
}

@@ -264,7 +264,7 @@ impl DepNodeExt for DepNode {
/// DepNode. Condition (2) might not be fulfilled if a DepNode
/// refers to something from the previous compilation session that
/// has been removed.
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
fn extract_def_id<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
if self.kind.fingerprint_style(tcx) == FingerprintStyle::DefPathHash {
Some(tcx.def_path_hash_to_def_id(DefPathHash(self.hash.into())))
} else {
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/infer/canonical.rs
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ pub struct OriginalQueryValues<'tcx> {
pub var_values: SmallVec<[GenericArg<'tcx>; 8]>,
}

impl Default for OriginalQueryValues<'tcx> {
impl<'tcx> Default for OriginalQueryValues<'tcx> {
fn default() -> Self {
let mut universe_map = SmallVec::default();
universe_map.push(ty::UniverseIndex::ROOT);
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/infer/unify_key.rs
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {

impl<'tcx> EqUnifyValue for &'tcx ty::Const<'tcx> {}

pub fn replace_if_possible<V, L>(
pub fn replace_if_possible<'tcx, V, L>(
table: &mut UnificationTable<InPlace<ty::ConstVid<'tcx>, V, L>>,
c: &'tcx ty::Const<'tcx>,
) -> &'tcx ty::Const<'tcx>
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@
#![feature(let_else)]
#![feature(min_specialization)]
#![feature(trusted_len)]
#![feature(in_band_lifetimes)]
#![feature(crate_visibility_modifier)]
#![feature(associated_type_bounds)]
#![feature(rustc_attrs)]
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
@@ -212,7 +212,7 @@ pub fn struct_lint_level<'s, 'd>(
) {
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
// the "real" work.
fn struct_lint_level_impl(
fn struct_lint_level_impl<'s, 'd>(
sess: &'s Session,
lint: &'static Lint,
level: Level,
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
@@ -229,7 +229,7 @@ pub fn deprecation_message_and_lint(
)
}

pub fn early_report_deprecation(
pub fn early_report_deprecation<'a>(
lint_buffer: &'a mut LintBuffer,
message: &str,
suggestion: Option<Symbol>,
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ impl fmt::Display for InterpErrorInfo<'_> {
}
}

impl InterpErrorInfo<'tcx> {
impl<'tcx> InterpErrorInfo<'tcx> {
pub fn print_backtrace(&self) {
if let Some(backtrace) = self.0.backtrace.as_ref() {
print_backtrace(backtrace);
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ pub struct GlobalId<'tcx> {
pub promoted: Option<mir::Promoted>,
}

impl GlobalId<'tcx> {
impl<'tcx> GlobalId<'tcx> {
pub fn display(self, tcx: TyCtxt<'tcx>) -> String {
let instance_name = with_no_trimmed_paths(|| tcx.def_path_str(self.instance.def.def_id()));
if let Some(promoted) = self.promoted {
@@ -273,7 +273,7 @@ pub struct AllocDecodingSession<'s> {

impl<'s> AllocDecodingSession<'s> {
/// Decodes an `AllocId` in a thread-safe way.
pub fn decode_alloc_id<D>(&self, decoder: &mut D) -> Result<AllocId, D::Error>
pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> Result<AllocId, D::Error>
where
D: TyDecoder<'tcx>,
{
@@ -390,7 +390,7 @@ pub enum GlobalAlloc<'tcx> {
Memory(&'tcx Allocation),
}

impl GlobalAlloc<'tcx> {
impl<'tcx> GlobalAlloc<'tcx> {
/// Panics if the `GlobalAlloc` does not refer to an `GlobalAlloc::Memory`
#[track_caller]
#[inline]
16 changes: 8 additions & 8 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -2033,7 +2033,7 @@ impl SourceScope {
/// Finds the original HirId this MIR item came from.
/// This is necessary after MIR optimizations, as otherwise we get a HirId
/// from the function that was inlined instead of the function call site.
pub fn lint_root(
pub fn lint_root<'tcx>(
self,
source_scopes: &IndexVec<SourceScope, SourceScopeData<'tcx>>,
) -> Option<HirId> {
@@ -2543,7 +2543,7 @@ pub enum ConstantKind<'tcx> {
Val(interpret::ConstValue<'tcx>, Ty<'tcx>),
}

impl Constant<'tcx> {
impl<'tcx> Constant<'tcx> {
pub fn check_static_ptr(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
match self.literal.const_for_ty()?.val.try_to_scalar() {
Some(Scalar::Ptr(ptr, _size)) => match tcx.global_alloc(ptr.provenance) {
@@ -2562,14 +2562,14 @@ impl Constant<'tcx> {
}
}

impl From<&'tcx ty::Const<'tcx>> for ConstantKind<'tcx> {
impl<'tcx> From<&'tcx ty::Const<'tcx>> for ConstantKind<'tcx> {
#[inline]
fn from(ct: &'tcx ty::Const<'tcx>) -> Self {
Self::Ty(ct)
}
}

impl ConstantKind<'tcx> {
impl<'tcx> ConstantKind<'tcx> {
/// Returns `None` if the constant is not trivially safe for use in the type system.
pub fn const_for_ty(&self) -> Option<&'tcx ty::Const<'tcx>> {
match self {
@@ -2851,7 +2851,7 @@ impl<'tcx> Display for ConstantKind<'tcx> {
}
}

fn pretty_print_const(
fn pretty_print_const<'tcx>(
c: &ty::Const<'tcx>,
fmt: &mut Formatter<'_>,
print_types: bool,
@@ -2866,7 +2866,7 @@ fn pretty_print_const(
})
}

fn pretty_print_const_value(
fn pretty_print_const_value<'tcx>(
val: interpret::ConstValue<'tcx>,
ty: Ty<'tcx>,
fmt: &mut Formatter<'_>,
@@ -2913,12 +2913,12 @@ impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> {
type Iter = iter::Cloned<Successors<'b>>;
}

impl graph::GraphPredecessors<'graph> for Body<'tcx> {
impl<'tcx, 'graph> graph::GraphPredecessors<'graph> for Body<'tcx> {
type Item = BasicBlock;
type Iter = std::iter::Copied<std::slice::Iter<'graph, BasicBlock>>;
}

impl graph::WithPredecessors for Body<'tcx> {
impl<'tcx> graph::WithPredecessors for Body<'tcx> {
#[inline]
fn predecessors(&self, node: Self::Node) -> <Self as graph::GraphPredecessors<'_>>::Iter {
self.predecessors()[node].iter().copied()
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
@@ -431,7 +431,7 @@ pub struct CodegenUnitNameBuilder<'tcx> {
cache: FxHashMap<CrateNum, String>,
}

impl CodegenUnitNameBuilder<'tcx> {
impl<'tcx> CodegenUnitNameBuilder<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
CodegenUnitNameBuilder { tcx, cache: Default::default() }
}
22 changes: 12 additions & 10 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
@@ -167,8 +167,8 @@ fn dump_matched_mir_node<'tcx, F>(

/// Returns the file basename portion (without extension) of a filename path
/// where we should dump a MIR representation output files.
fn dump_file_basename(
tcx: TyCtxt<'_>,
fn dump_file_basename<'tcx>(
tcx: TyCtxt<'tcx>,
pass_num: Option<&dyn Display>,
pass_name: &str,
disambiguator: &dyn Display,
@@ -251,8 +251,8 @@ fn create_dump_file_with_basename(
/// bit of MIR-related data. Used by `mir-dump`, but also by other
/// bits of code (e.g., NLL inference) that dump graphviz data or
/// other things, and hence takes the extension as an argument.
pub fn create_dump_file(
tcx: TyCtxt<'_>,
pub fn create_dump_file<'tcx>(
tcx: TyCtxt<'tcx>,
extension: &str,
pass_num: Option<&dyn Display>,
pass_name: &str,
@@ -419,15 +419,15 @@ struct ExtraComments<'tcx> {
comments: Vec<String>,
}

impl ExtraComments<'tcx> {
impl<'tcx> ExtraComments<'tcx> {
fn push(&mut self, lines: &str) {
for line in lines.split('\n') {
self.comments.push(line.to_string());
}
}
}

fn use_verbose(ty: &&TyS<'tcx>, fn_def: bool) -> bool {
fn use_verbose<'tcx>(ty: &&TyS<'tcx>, fn_def: bool) -> bool {
match ty.kind() {
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => false,
// Unit type
@@ -439,7 +439,7 @@ fn use_verbose(ty: &&TyS<'tcx>, fn_def: bool) -> bool {
}
}

impl Visitor<'tcx> for ExtraComments<'tcx> {
impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
self.super_constant(constant, location);
let Constant { span, user_ty, literal } = constant;
@@ -762,7 +762,7 @@ pub fn write_allocations<'tcx>(
/// After the hex dump, an ascii dump follows, replacing all unprintable characters (control
/// characters or characters whose value is larger than 127) with a `.`
/// This also prints relocations adequately.
pub fn display_allocation<Tag, Extra>(
pub fn display_allocation<'a, 'tcx, Tag, Extra>(
tcx: TyCtxt<'tcx>,
alloc: &'a Allocation<Tag, Extra>,
) -> RenderAllocation<'a, 'tcx, Tag, Extra> {
@@ -775,7 +775,9 @@ pub struct RenderAllocation<'a, 'tcx, Tag, Extra> {
alloc: &'a Allocation<Tag, Extra>,
}

impl<Tag: Provenance, Extra> std::fmt::Display for RenderAllocation<'a, 'tcx, Tag, Extra> {
impl<'a, 'tcx, Tag: Provenance, Extra> std::fmt::Display
for RenderAllocation<'a, 'tcx, Tag, Extra>
{
fn fmt(&self, w: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let RenderAllocation { tcx, alloc } = *self;
write!(w, "size: {}, align: {})", alloc.size().bytes(), alloc.align.bytes())?;
@@ -818,7 +820,7 @@ fn write_allocation_newline(
/// The `prefix` argument allows callers to add an arbitrary prefix before each line (even if there
/// is only one line). Note that your prefix should contain a trailing space as the lines are
/// printed directly after it.
fn write_allocation_bytes<Tag: Provenance, Extra>(
fn write_allocation_bytes<'tcx, Tag: Provenance, Extra>(
tcx: TyCtxt<'tcx>,
alloc: &Allocation<Tag, Extra>,
w: &mut dyn std::fmt::Write,
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/traversal.rs
Original file line number Diff line number Diff line change
@@ -300,7 +300,7 @@ pub fn reachable<'a, 'tcx>(
}

/// Returns a `BitSet` containing all basic blocks reachable from the `START_BLOCK`.
pub fn reachable_as_bitset(body: &Body<'tcx>) -> BitSet<BasicBlock> {
pub fn reachable_as_bitset<'tcx>(body: &Body<'tcx>) -> BitSet<BasicBlock> {
let mut iter = preorder(body);
(&mut iter).for_each(drop);
iter.visited
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
@@ -965,7 +965,7 @@ macro_rules! visit_place_fns {
}
}

fn process_projection(
fn process_projection<'a>(
&mut self,
projection: &'a [PlaceElem<'tcx>],
location: Location,
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ impl<'tcx> fmt::Debug for ObligationCause<'tcx> {
}
}

impl Deref for ObligationCause<'tcx> {
impl<'tcx> Deref for ObligationCause<'tcx> {
type Target = ObligationCauseData<'tcx>;

#[inline(always)]
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/specialization_graph.rs
Original file line number Diff line number Diff line change
@@ -216,7 +216,7 @@ impl<'tcx> Ancestors<'tcx> {
///
/// Returns `Err` if an error was reported while building the specialization
/// graph.
pub fn ancestors(
pub fn ancestors<'tcx>(
tcx: TyCtxt<'tcx>,
trait_def_id: DefId,
start_from_impl: DefId,
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/structural_impls.rs
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceBuiltinData<N> {
}
}

impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitUpcastingData<'tcx, N> {
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitUpcastingData<'tcx, N> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/_match.rs
Original file line number Diff line number Diff line change
@@ -23,13 +23,13 @@ pub struct Match<'tcx> {
param_env: ty::ParamEnv<'tcx>,
}

impl Match<'tcx> {
impl<'tcx> Match<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Match<'tcx> {
Match { tcx, param_env }
}
}

impl TypeRelation<'tcx> for Match<'tcx> {
impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
fn tag(&self) -> &'static str {
"Match"
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/adjustment.rs
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ pub struct Adjustment<'tcx> {
pub target: Ty<'tcx>,
}

impl Adjustment<'tcx> {
impl<'tcx> Adjustment<'tcx> {
pub fn is_region_borrow(&self) -> bool {
matches!(self.kind, Adjust::Borrow(AutoBorrow::Ref(..)))
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/assoc.rs
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ impl<'tcx> AssocItems<'tcx> {
/// Multiple items may have the same name if they are in different `Namespace`s. For example,
/// an associated type can have the same name as a method. Use one of the `find_by_name_and_*`
/// methods below if you know which item you are looking for.
pub fn filter_by_name(
pub fn filter_by_name<'a>(
&'a self,
tcx: TyCtxt<'a>,
ident: Ident,
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/closure.rs
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ pub struct CapturedPlace<'tcx> {
pub mutability: hir::Mutability,
}

impl CapturedPlace<'tcx> {
impl<'tcx> CapturedPlace<'tcx> {
pub fn to_string(&self, tcx: TyCtxt<'tcx>) -> String {
place_to_string_for_capture(tcx, &self.place)
}
@@ -328,7 +328,7 @@ pub struct CaptureInfo<'tcx> {
pub capture_kind: UpvarCapture<'tcx>,
}

pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) -> String {
pub fn place_to_string_for_capture<'tcx>(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) -> String {
let mut curr_string: String = match place.base {
HirPlaceBase::Upvar(upvar_id) => tcx.hir().name(upvar_id.var_path.hir_id).to_string(),
_ => bug!("Capture_information should only contain upvars"),
6 changes: 5 additions & 1 deletion compiler/rustc_middle/src/ty/codec.rs
Original file line number Diff line number Diff line change
@@ -76,7 +76,11 @@ pub trait RefDecodable<'tcx, D: TyDecoder<'tcx>> {
}

/// Encode the given value or a previously cached shorthand.
pub fn encode_with_shorthand<E, T, M>(encoder: &mut E, value: &T, cache: M) -> Result<(), E::Error>
pub fn encode_with_shorthand<'tcx, E, T, M>(
encoder: &mut E,
value: &T,
cache: M,
) -> Result<(), E::Error>
where
E: TyEncoder<'tcx>,
M: for<'b> Fn(&'b mut E) -> &'b mut FxHashMap<T, usize>,
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/consts/int.rs
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@ impl ScalarInt {
}

#[inline]
pub fn try_to_machine_usize(&self, tcx: TyCtxt<'tcx>) -> Result<u64, Size> {
pub fn try_to_machine_usize<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Result<u64, Size> {
Ok(self.to_bits(tcx.data_layout.pointer_size)? as u64)
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/consts/valtree.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ pub enum ValTree<'tcx> {
Branch(&'tcx [ValTree<'tcx>]),
}

impl ValTree<'tcx> {
impl<'tcx> ValTree<'tcx> {
pub fn zst() -> Self {
Self::Branch(&[])
}
Loading