summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_resolve/src/late.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_resolve/src/late.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_resolve/src/late.rs')
-rw-r--r--compiler/rustc_resolve/src/late.rs87
1 files changed, 48 insertions, 39 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs
index 15ec727e4..3be962dab 100644
--- a/compiler/rustc_resolve/src/late.rs
+++ b/compiler/rustc_resolve/src/late.rs
@@ -41,9 +41,6 @@ type Res = def::Res<NodeId>;
type IdentMap<T> = FxHashMap<Ident, T>;
-/// Map from the name in a pattern to its binding mode.
-type BindingMap = IdentMap<BindingInfo>;
-
use diagnostics::{
ElisionFnParameter, LifetimeElisionCandidate, MissingLifetime, MissingLifetimeKind,
};
@@ -180,8 +177,8 @@ pub(crate) enum RibKind<'a> {
/// upvars).
AssocItem,
- /// We passed through a closure. Disallow labels.
- ClosureOrAsync,
+ /// We passed through a function, closure or coroutine signature. Disallow labels.
+ FnOrCoroutine,
/// We passed through an item scope. Disallow upvars.
Item(HasGenericParams),
@@ -218,7 +215,7 @@ impl RibKind<'_> {
pub(crate) fn contains_params(&self) -> bool {
match self {
RibKind::Normal
- | RibKind::ClosureOrAsync
+ | RibKind::FnOrCoroutine
| RibKind::ConstantItem(..)
| RibKind::Module(_)
| RibKind::MacroDefinition(_)
@@ -234,7 +231,7 @@ impl RibKind<'_> {
RibKind::Normal | RibKind::MacroDefinition(..) => false,
RibKind::AssocItem
- | RibKind::ClosureOrAsync
+ | RibKind::FnOrCoroutine
| RibKind::Item(..)
| RibKind::ConstantItem(..)
| RibKind::Module(..)
@@ -739,7 +736,8 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
// Check whether we should interpret this as a bare trait object.
if qself.is_none()
&& let Some(partial_res) = self.r.partial_res_map.get(&ty.id)
- && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
+ && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) =
+ partial_res.full_res()
{
// This path is actually a bare trait object. In case of a bare `Fn`-trait
// object with anonymous lifetimes, we need this rib to correctly place the
@@ -926,9 +924,9 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
debug!("(resolving function) entering function");
// Create a value rib for the function.
- self.with_rib(ValueNS, RibKind::ClosureOrAsync, |this| {
+ self.with_rib(ValueNS, RibKind::FnOrCoroutine, |this| {
// Create a label rib for the function.
- this.with_label_rib(RibKind::ClosureOrAsync, |this| {
+ this.with_label_rib(RibKind::FnOrCoroutine, |this| {
match fn_kind {
FnKind::Fn(_, _, sig, _, generics, body) => {
this.visit_generics(generics);
@@ -2049,7 +2047,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
if lifetime_count != 0 {
parameter_info.push(ElisionFnParameter {
index,
- ident: if let Some(pat) = pat && let PatKind::Ident(_, ident, _) = pat.kind {
+ ident: if let Some(pat) = pat
+ && let PatKind::Ident(_, ident, _) = pat.kind
+ {
Some(ident)
} else {
None
@@ -2143,7 +2143,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
impl<'a> Visitor<'a> for SelfVisitor<'_, '_, '_> {
fn visit_ty(&mut self, ty: &'a Ty) {
trace!("SelfVisitor considering ty={:?}", ty);
- if let TyKind::Ref(lt, ref mt) = ty.kind && self.is_self_ty(&mt.ty) {
+ if let TyKind::Ref(lt, ref mt) = ty.kind
+ && self.is_self_ty(&mt.ty)
+ {
let lt_id = if let Some(lt) = lt {
lt.id
} else {
@@ -3164,8 +3166,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
/// this is done hygienically. This could arise for a macro
/// that expands into an or-pattern where one 'x' was from the
/// user and one 'x' came from the macro.
- fn binding_mode_map(&mut self, pat: &Pat) -> BindingMap {
- let mut binding_map = FxHashMap::default();
+ fn binding_mode_map(&mut self, pat: &Pat) -> FxIndexMap<Ident, BindingInfo> {
+ let mut binding_map = FxIndexMap::default();
pat.walk(&mut |pat| {
match pat.kind {
@@ -3200,22 +3202,28 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
/// Checks that all of the arms in an or-pattern have exactly the
/// same set of bindings, with the same binding modes for each.
- fn check_consistent_bindings(&mut self, pats: &[P<Pat>]) -> Vec<BindingMap> {
- let mut missing_vars = FxHashMap::default();
- let mut inconsistent_vars = FxHashMap::default();
+ fn check_consistent_bindings(
+ &mut self,
+ pats: &[P<Pat>],
+ ) -> Vec<FxIndexMap<Ident, BindingInfo>> {
+ // pats is consistent.
+ let mut missing_vars = FxIndexMap::default();
+ let mut inconsistent_vars = FxIndexMap::default();
// 1) Compute the binding maps of all arms.
let maps = pats.iter().map(|pat| self.binding_mode_map(pat)).collect::<Vec<_>>();
// 2) Record any missing bindings or binding mode inconsistencies.
- for (map_outer, pat_outer) in pats.iter().enumerate().map(|(idx, pat)| (&maps[idx], pat)) {
+ for (map_outer, pat_outer) in maps.iter().zip(pats.iter()) {
// Check against all arms except for the same pattern which is always self-consistent.
- let inners = pats
+ let inners = maps
.iter()
- .enumerate()
+ .zip(pats.iter())
.filter(|(_, pat)| pat.id != pat_outer.id)
- .flat_map(|(idx, _)| maps[idx].iter())
- .map(|(key, binding)| (key.name, map_outer.get(&key), binding));
+ .flat_map(|(map, _)| map)
+ .map(|(key, binding)| (key.name, map_outer.get(key), binding));
+
+ let inners = inners.collect::<Vec<_>>();
for (name, info, &binding_inner) in inners {
match info {
@@ -3244,10 +3252,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}
// 3) Report all missing variables we found.
- let mut missing_vars = missing_vars.into_iter().collect::<Vec<_>>();
- missing_vars.sort_by_key(|&(sym, ref _err)| sym);
-
- for (name, mut v) in missing_vars.into_iter() {
+ for (name, mut v) in missing_vars {
if inconsistent_vars.contains_key(&name) {
v.could_be_path = false;
}
@@ -3258,10 +3263,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}
// 4) Report all inconsistencies in binding modes we found.
- let mut inconsistent_vars = inconsistent_vars.iter().collect::<Vec<_>>();
- inconsistent_vars.sort();
for (name, v) in inconsistent_vars {
- self.report_error(v.0, ResolutionError::VariableBoundWithDifferentMode(*name, v.1));
+ self.report_error(v.0, ResolutionError::VariableBoundWithDifferentMode(name, v.1));
}
// 5) Finally bubble up all the binding maps.
@@ -3604,7 +3607,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
sugg.to_string(),
Applicability::MaybeIncorrect,
))
- } else if res.is_none() && let PathSource::Type | PathSource::Expr(_) = source {
+ } else if res.is_none()
+ && let PathSource::Type | PathSource::Expr(_) = source
+ {
this.suggest_adding_generic_parameter(path, source)
} else {
None
@@ -4006,7 +4011,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
"unnecessary qualification",
lint::BuiltinLintDiagnostics::UnusedQualifications {
removal_span: finalize.path_span.until(last_segment.ident.span),
- }
+ },
)
}
}
@@ -4059,13 +4064,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
(block.could_be_bare_literal, &block.stmts[..])
&& let ExprKind::Type(..) = expr.kind
{
- self.diagnostic_metadata.current_block_could_be_bare_struct_literal =
- Some(block.span);
+ self.diagnostic_metadata.current_block_could_be_bare_struct_literal = Some(block.span);
}
// Descend into the block.
for stmt in &block.stmts {
if let StmtKind::Item(ref item) = stmt.kind
- && let ItemKind::MacroDef(..) = item.kind {
+ && let ItemKind::MacroDef(..) = item.kind
+ {
num_macro_definition_ribs += 1;
let res = self.r.local_def_id(item.id).to_def_id();
self.ribs[ValueNS].push(Rib::new(RibKind::MacroDefinition(res)));
@@ -4282,7 +4287,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
..
}) => {
self.with_rib(ValueNS, RibKind::Normal, |this| {
- this.with_label_rib(RibKind::ClosureOrAsync, |this| {
+ this.with_label_rib(RibKind::FnOrCoroutine, |this| {
// Resolve arguments:
this.resolve_params(&fn_decl.inputs);
// No need to resolve return type --
@@ -4299,7 +4304,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
})
});
}
- // For closures, ClosureOrAsyncRibKind is added in visit_fn
+ // For closures, RibKind::FnOrCoroutine is added in visit_fn
ExprKind::Closure(box ast::Closure {
binder: ClosureBinder::For { ref generic_params, span },
..
@@ -4316,8 +4321,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
);
}
ExprKind::Closure(..) => visit::walk_expr(self, expr),
- ExprKind::Async(..) => {
- self.with_label_rib(RibKind::ClosureOrAsync, |this| visit::walk_expr(this, expr));
+ ExprKind::Gen(..) => {
+ self.with_label_rib(RibKind::FnOrCoroutine, |this| visit::walk_expr(this, expr));
}
ExprKind::Repeat(ref elem, ref ct) => {
self.visit_expr(elem);
@@ -4421,7 +4426,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
&& let Some(def_id) = res.opt_def_id()
&& !def_id.is_local()
&& self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
- && matches!(self.r.tcx.sess.opts.resolve_doc_links, ResolveDocLinks::ExportedMetadata) {
+ && matches!(
+ self.r.tcx.sess.opts.resolve_doc_links,
+ ResolveDocLinks::ExportedMetadata
+ )
+ {
// Encoding foreign def ids in proc macro crate metadata will ICE.
return None;
}