From 2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:50 +0200 Subject: Merging upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- .../rustc_middle/src/middle/codegen_fn_attrs.rs | 3 +- compiler/rustc_middle/src/middle/mod.rs | 2 +- compiler/rustc_middle/src/middle/privacy.rs | 25 +++------- .../rustc_middle/src/middle/resolve_bound_vars.rs | 57 ++++++++++++++++++++++ .../rustc_middle/src/middle/resolve_lifetime.rs | 55 --------------------- compiler/rustc_middle/src/middle/stability.rs | 4 +- 6 files changed, 70 insertions(+), 76 deletions(-) create mode 100644 compiler/rustc_middle/src/middle/resolve_bound_vars.rs delete mode 100644 compiler/rustc_middle/src/middle/resolve_lifetime.rs (limited to 'compiler/rustc_middle/src/middle') diff --git a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs index bea884c85..c4601a1fb 100644 --- a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs +++ b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs @@ -91,7 +91,8 @@ bitflags! { /// the MIR `InstrumentCoverage` pass and not added to the coverage map /// during codegen. const NO_COVERAGE = 1 << 15; - /// `#[used(linker)]`: indicates that LLVM nor the linker can eliminate this function. + /// `#[used(linker)]`: + /// indicates that neither LLVM nor the linker will eliminate this function. const USED_LINKER = 1 << 16; /// `#[rustc_deallocator]`: a hint to LLVM that the function only deallocates memory. const DEALLOCATOR = 1 << 17; diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 8dc68b1f5..0b6774f1b 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -29,7 +29,7 @@ pub mod lib_features { pub mod limits; pub mod privacy; pub mod region; -pub mod resolve_lifetime; +pub mod resolve_bound_vars; pub mod stability; pub fn provide(providers: &mut crate::ty::query::Providers) { diff --git a/compiler/rustc_middle/src/middle/privacy.rs b/compiler/rustc_middle/src/middle/privacy.rs index 0e18ba73d..893bf54b8 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_middle/src/middle/privacy.rs @@ -194,11 +194,6 @@ impl EffectiveVisibilities { } } -pub trait IntoDefIdTree { - type Tree: DefIdTree; - fn tree(self) -> Self::Tree; -} - impl EffectiveVisibilities { pub fn iter(&self) -> impl Iterator { self.map.iter() @@ -217,25 +212,21 @@ impl EffectiveVisibilities { self.map.entry(id).or_insert_with(|| EffectiveVisibility::from_vis(lazy_private_vis())) } - pub fn update( + pub fn update( &mut self, id: Id, nominal_vis: Visibility, - lazy_private_vis: impl FnOnce(T) -> (Visibility, T), + lazy_private_vis: impl FnOnce() -> Visibility, inherited_effective_vis: EffectiveVisibility, level: Level, - mut into_tree: T, + tree: impl DefIdTree, ) -> bool { let mut changed = false; - let mut current_effective_vis = match self.map.get(&id).copied() { - Some(eff_vis) => eff_vis, - None => { - let private_vis; - (private_vis, into_tree) = lazy_private_vis(into_tree); - EffectiveVisibility::from_vis(private_vis) - } - }; - let tree = into_tree.tree(); + let mut current_effective_vis = self + .map + .get(&id) + .copied() + .unwrap_or_else(|| EffectiveVisibility::from_vis(lazy_private_vis())); let mut inherited_effective_vis_at_prev_level = *inherited_effective_vis.at_level(level); let mut calculated_effective_vis = inherited_effective_vis_at_prev_level; diff --git a/compiler/rustc_middle/src/middle/resolve_bound_vars.rs b/compiler/rustc_middle/src/middle/resolve_bound_vars.rs new file mode 100644 index 000000000..c59704fc0 --- /dev/null +++ b/compiler/rustc_middle/src/middle/resolve_bound_vars.rs @@ -0,0 +1,57 @@ +//! Name resolution for lifetimes and late-bound type and const variables: type declarations. + +use crate::ty; + +use rustc_data_structures::fx::FxHashMap; +use rustc_errors::ErrorGuaranteed; +use rustc_hir::def_id::DefId; +use rustc_hir::{ItemLocalId, OwnerId}; +use rustc_macros::HashStable; + +#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)] +pub enum ResolvedArg { + StaticLifetime, + EarlyBound(/* decl */ DefId), + LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* decl */ DefId), + Free(DefId, /* lifetime decl */ DefId), + Error(ErrorGuaranteed), +} + +/// A set containing, at most, one known element. +/// If two distinct values are inserted into a set, then it +/// becomes `Many`, which can be used to detect ambiguities. +#[derive(Copy, Clone, PartialEq, Eq, TyEncodable, TyDecodable, Debug, HashStable)] +pub enum Set1 { + Empty, + One(T), + Many, +} + +impl Set1 { + pub fn insert(&mut self, value: T) { + *self = match self { + Set1::Empty => Set1::One(value), + Set1::One(old) if *old == value => return, + _ => Set1::Many, + }; + } +} + +#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)] +pub enum ObjectLifetimeDefault { + Empty, + Static, + Ambiguous, + Param(DefId), +} + +/// Maps the id of each lifetime reference to the lifetime decl +/// that it corresponds to. +#[derive(Default, HashStable, Debug)] +pub struct ResolveBoundVars { + /// Maps from every use of a named (not anonymous) lifetime to a + /// `Region` describing how that region is bound + pub defs: FxHashMap>, + + pub late_bound_vars: FxHashMap>>, +} diff --git a/compiler/rustc_middle/src/middle/resolve_lifetime.rs b/compiler/rustc_middle/src/middle/resolve_lifetime.rs deleted file mode 100644 index c3bf1c717..000000000 --- a/compiler/rustc_middle/src/middle/resolve_lifetime.rs +++ /dev/null @@ -1,55 +0,0 @@ -//! Name resolution for lifetimes: type declarations. - -use crate::ty; - -use rustc_data_structures::fx::FxHashMap; -use rustc_hir::def_id::DefId; -use rustc_hir::{ItemLocalId, OwnerId}; -use rustc_macros::HashStable; - -#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)] -pub enum Region { - Static, - EarlyBound(/* lifetime decl */ DefId), - LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* lifetime decl */ DefId), - Free(DefId, /* lifetime decl */ DefId), -} - -/// A set containing, at most, one known element. -/// If two distinct values are inserted into a set, then it -/// becomes `Many`, which can be used to detect ambiguities. -#[derive(Copy, Clone, PartialEq, Eq, TyEncodable, TyDecodable, Debug, HashStable)] -pub enum Set1 { - Empty, - One(T), - Many, -} - -impl Set1 { - pub fn insert(&mut self, value: T) { - *self = match self { - Set1::Empty => Set1::One(value), - Set1::One(old) if *old == value => return, - _ => Set1::Many, - }; - } -} - -#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)] -pub enum ObjectLifetimeDefault { - Empty, - Static, - Ambiguous, - Param(DefId), -} - -/// Maps the id of each lifetime reference to the lifetime decl -/// that it corresponds to. -#[derive(Default, HashStable, Debug)] -pub struct ResolveLifetimes { - /// Maps from every use of a named (not anonymous) lifetime to a - /// `Region` describing how that region is bound - pub defs: FxHashMap>, - - pub late_bound_vars: FxHashMap>>, -} diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 0836f236e..354c84e22 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -255,7 +255,7 @@ fn late_report_deprecation( let method_span = method_span.unwrap_or(span); tcx.struct_span_lint_hir(lint, hir_id, method_span, message, |diag| { if let hir::Node::Expr(_) = tcx.hir().get(hir_id) { - let kind = tcx.def_kind(def_id).descr(def_id); + let kind = tcx.def_descr(def_id); deprecation_suggestion(diag, kind, suggestion, method_span); } diag @@ -392,7 +392,7 @@ impl<'tcx> TyCtxt<'tcx> { let lint = deprecation_lint(is_in_effect); if self.lint_level_at_node(lint, id).0 != Level::Allow { let def_path = with_no_trimmed_paths!(self.def_path_str(def_id)); - let def_kind = self.def_kind(def_id).descr(def_id); + let def_kind = self.def_descr(def_id); late_report_deprecation( self, -- cgit v1.2.3