Rollup merge of #97312 - cjgillot:no-path-in-scope, r=compiler-errors
Compute lifetimes in scope at diagnostic time The set of available lifetimes is currently computed during lifetime resolution on HIR. It is only used for one diagnostic. In this PR, HIR lifetime resolution just reports whether elided lifetimes are well-defined at the place of use. The diagnostic code is responsible for building a list of lifetime names if elision is not allowed. This will allow to remove lifetime resolution on HIR eventually.
This commit is contained in:
commit
a736acc804
15 changed files with 127 additions and 206 deletions
|
@ -298,6 +298,7 @@ impl<'hir> Map<'hir> {
|
|||
Node::Stmt(_)
|
||||
| Node::PathSegment(_)
|
||||
| Node::Ty(_)
|
||||
| Node::TypeBinding(_)
|
||||
| Node::Infer(_)
|
||||
| Node::TraitRef(_)
|
||||
| Node::Pat(_)
|
||||
|
@ -323,7 +324,8 @@ impl<'hir> Map<'hir> {
|
|||
}
|
||||
|
||||
pub fn get_parent_node(self, hir_id: HirId) -> HirId {
|
||||
self.find_parent_node(hir_id).unwrap()
|
||||
self.find_parent_node(hir_id)
|
||||
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
|
||||
}
|
||||
|
||||
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
|
||||
|
@ -973,6 +975,7 @@ impl<'hir> Map<'hir> {
|
|||
.with_hi(seg.args.map_or_else(|| ident_span.hi(), |args| args.span_ext.hi()))
|
||||
}
|
||||
Node::Ty(ty) => ty.span,
|
||||
Node::TypeBinding(tb) => tb.span,
|
||||
Node::TraitRef(tr) => tr.path.span,
|
||||
Node::Binding(pat) => pat.span,
|
||||
Node::Pat(pat) => pat.span,
|
||||
|
@ -1205,6 +1208,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
|
|||
Some(Node::Stmt(_)) => node_str("stmt"),
|
||||
Some(Node::PathSegment(_)) => node_str("path segment"),
|
||||
Some(Node::Ty(_)) => node_str("type"),
|
||||
Some(Node::TypeBinding(_)) => node_str("type binding"),
|
||||
Some(Node::TraitRef(_)) => node_str("trait ref"),
|
||||
Some(Node::Binding(_)) => node_str("local"),
|
||||
Some(Node::Pat(_)) => node_str("pat"),
|
||||
|
|
|
@ -16,20 +16,6 @@ pub enum Region {
|
|||
Free(DefId, /* lifetime decl */ DefId),
|
||||
}
|
||||
|
||||
/// This is used in diagnostics to improve suggestions for missing generic arguments.
|
||||
/// It gives information on the type of lifetimes that are in scope for a particular `PathSegment`,
|
||||
/// so that we can e.g. suggest elided-lifetimes-in-paths of the form <'_, '_> e.g.
|
||||
#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
|
||||
pub enum LifetimeScopeForPath {
|
||||
/// Contains all lifetime names that are in scope and could possibly be used in generics
|
||||
/// arguments of path.
|
||||
NonElided(Vec<LocalDefId>),
|
||||
|
||||
/// Information that allows us to suggest args of the form `<'_>` in case
|
||||
/// no generic arguments were provided for a path.
|
||||
Elided,
|
||||
}
|
||||
|
||||
/// 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.
|
||||
|
|
|
@ -1599,11 +1599,6 @@ rustc_queries! {
|
|||
desc { "looking up late bound vars" }
|
||||
}
|
||||
|
||||
query lifetime_scope_map(_: LocalDefId) -> Option<FxHashMap<ItemLocalId, LifetimeScopeForPath>> {
|
||||
storage(ArenaCacheSelector<'tcx>)
|
||||
desc { "finds the lifetime scope for an HirId of a PathSegment" }
|
||||
}
|
||||
|
||||
query visibility(def_id: DefId) -> ty::Visibility {
|
||||
desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
|
||||
separate_provide_extern
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::hir::place::Place as HirPlace;
|
|||
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
|
||||
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
|
||||
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
|
||||
use crate::middle::resolve_lifetime::{self, LifetimeScopeForPath};
|
||||
use crate::middle::resolve_lifetime;
|
||||
use crate::middle::stability;
|
||||
use crate::mir::interpret::{self, Allocation, ConstAllocation, ConstValue, Scalar};
|
||||
use crate::mir::{
|
||||
|
@ -2821,10 +2821,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn lifetime_scope(self, id: HirId) -> Option<&'tcx LifetimeScopeForPath> {
|
||||
self.lifetime_scope_map(id.owner).as_ref().and_then(|map| map.get(&id.local_id))
|
||||
}
|
||||
|
||||
/// Whether the `def_id` counts as const fn in the current crate, considering all active
|
||||
/// feature gates
|
||||
pub fn is_const_fn(self, def_id: DefId) -> bool {
|
||||
|
|
|
@ -6,9 +6,7 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
|
|||
use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
|
||||
use crate::middle::lib_features::LibFeatures;
|
||||
use crate::middle::privacy::AccessLevels;
|
||||
use crate::middle::resolve_lifetime::{
|
||||
LifetimeScopeForPath, ObjectLifetimeDefault, Region, ResolveLifetimes,
|
||||
};
|
||||
use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes};
|
||||
use crate::middle::stability::{self, DeprecationEntry};
|
||||
use crate::mir;
|
||||
use crate::mir::interpret::GlobalId;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue