2019-08-12 23:46:42 +00:00
|
|
|
|
//! This crate is responsible for the part of name resolution that doesn't require type checker.
|
|
|
|
|
//!
|
|
|
|
|
//! Module structure of the crate is built here.
|
|
|
|
|
//! Paths in macros, imports, expressions, types, patterns are resolved here.
|
2020-01-12 10:29:00 +00:00
|
|
|
|
//! Label and lifetime names are resolved here as well.
|
2019-08-12 23:46:42 +00:00
|
|
|
|
//!
|
2021-04-07 19:47:01 +00:00
|
|
|
|
//! Type-relative name resolution (methods, fields, associated items) happens in `rustc_typeck`.
|
2014-12-18 22:46:26 +00:00
|
|
|
|
|
2020-09-23 19:51:56 +00:00
|
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
2021-01-29 07:31:08 +00:00
|
|
|
|
#![feature(box_patterns)]
|
2021-09-25 02:33:53 +00:00
|
|
|
|
#![feature(drain_filter)]
|
2019-10-08 00:14:42 +00:00
|
|
|
|
#![feature(bool_to_option)]
|
2018-05-22 15:10:17 +00:00
|
|
|
|
#![feature(crate_visibility_modifier)]
|
2022-03-06 11:02:13 +00:00
|
|
|
|
#![feature(if_let_guard)]
|
2022-03-23 21:32:00 +00:00
|
|
|
|
#![feature(let_chains)]
|
2021-10-16 01:45:14 +00:00
|
|
|
|
#![feature(let_else)]
|
2021-09-05 20:37:15 +00:00
|
|
|
|
#![feature(never_type)]
|
2019-02-10 07:13:30 +00:00
|
|
|
|
#![feature(nll)]
|
2019-12-24 22:38:22 +00:00
|
|
|
|
#![recursion_limit = "256"]
|
2021-04-04 20:23:08 +00:00
|
|
|
|
#![allow(rustdoc::private_intra_doc_links)]
|
2022-02-23 13:06:22 +00:00
|
|
|
|
#![allow(rustc::potential_query_instability)]
|
2018-12-13 15:57:25 +00:00
|
|
|
|
|
2021-08-20 13:36:04 +00:00
|
|
|
|
#[macro_use]
|
|
|
|
|
extern crate tracing;
|
|
|
|
|
|
2020-01-05 01:37:57 +00:00
|
|
|
|
pub use rustc_hir::def::{Namespace, PerNS};
|
2018-06-13 16:44:06 +00:00
|
|
|
|
|
2020-10-20 08:37:56 +00:00
|
|
|
|
use rustc_arena::{DroplessArena, TypedArena};
|
2020-05-24 22:39:39 +00:00
|
|
|
|
use rustc_ast::node_id::NodeMap;
|
2022-04-08 20:52:18 +00:00
|
|
|
|
use rustc_ast::{self as ast, NodeId, CRATE_NODE_ID};
|
2022-03-10 22:12:35 +00:00
|
|
|
|
use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArgs, LitKind, Path};
|
2022-04-07 18:54:13 +00:00
|
|
|
|
use rustc_ast_lowering::{LifetimeRes, ResolverAstLowering};
|
2019-12-24 04:02:53 +00:00
|
|
|
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
2022-02-04 03:26:29 +00:00
|
|
|
|
use rustc_data_structures::intern::Interned;
|
2019-12-24 04:02:53 +00:00
|
|
|
|
use rustc_data_structures::sync::Lrc;
|
2022-04-08 20:52:18 +00:00
|
|
|
|
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
2021-03-08 12:05:03 +00:00
|
|
|
|
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
|
2020-01-05 01:37:57 +00:00
|
|
|
|
use rustc_hir::def::Namespace::*;
|
2022-03-26 19:59:09 +00:00
|
|
|
|
use rustc_hir::def::{self, CtorOf, DefKind, PartialRes};
|
2021-09-13 21:13:14 +00:00
|
|
|
|
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefPathHash, LocalDefId};
|
2022-04-15 17:27:53 +00:00
|
|
|
|
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE};
|
2020-06-20 18:59:29 +00:00
|
|
|
|
use rustc_hir::definitions::{DefKey, DefPathData, Definitions};
|
2021-03-13 19:23:18 +00:00
|
|
|
|
use rustc_hir::TraitCandidate;
|
2020-06-20 18:59:29 +00:00
|
|
|
|
use rustc_index::vec::IndexVec;
|
2019-12-24 04:02:53 +00:00
|
|
|
|
use rustc_metadata::creader::{CStore, CrateLoader};
|
2021-12-21 03:24:43 +00:00
|
|
|
|
use rustc_middle::metadata::ModChild;
|
2021-07-26 03:38:16 +00:00
|
|
|
|
use rustc_middle::middle::privacy::AccessLevels;
|
2022-03-26 19:59:09 +00:00
|
|
|
|
use rustc_middle::span_bug;
|
2020-03-29 15:19:48 +00:00
|
|
|
|
use rustc_middle::ty::query::Providers;
|
2021-09-28 22:17:54 +00:00
|
|
|
|
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, ResolverOutputs};
|
2021-09-19 20:17:50 +00:00
|
|
|
|
use rustc_query_system::ich::StableHashingContext;
|
2020-11-14 02:02:03 +00:00
|
|
|
|
use rustc_session::cstore::{CrateStore, MetadataLoaderDyn};
|
2022-04-08 20:52:18 +00:00
|
|
|
|
use rustc_session::lint::LintBuffer;
|
2020-01-05 08:40:16 +00:00
|
|
|
|
use rustc_session::Session;
|
2022-03-26 19:59:09 +00:00
|
|
|
|
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
|
2021-09-19 20:17:50 +00:00
|
|
|
|
use rustc_span::source_map::Spanned;
|
2020-04-19 11:00:18 +00:00
|
|
|
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
2019-12-31 17:15:40 +00:00
|
|
|
|
use rustc_span::{Span, DUMMY_SP};
|
2016-06-21 22:08:13 +00:00
|
|
|
|
|
2020-08-08 17:06:45 +00:00
|
|
|
|
use smallvec::{smallvec, SmallVec};
|
2019-12-24 22:38:22 +00:00
|
|
|
|
use std::cell::{Cell, RefCell};
|
2022-01-25 23:40:10 +00:00
|
|
|
|
use std::collections::BTreeSet;
|
2022-03-23 21:03:12 +00:00
|
|
|
|
use std::{cmp, fmt, mem, ptr};
|
2020-08-14 06:05:01 +00:00
|
|
|
|
use tracing::debug;
|
2012-05-22 17:54:12 +00:00
|
|
|
|
|
2020-06-25 14:16:38 +00:00
|
|
|
|
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
|
2020-03-07 15:49:13 +00:00
|
|
|
|
use imports::{Import, ImportKind, ImportResolver, NameResolution};
|
2022-03-26 19:59:09 +00:00
|
|
|
|
use late::{HasGenericParams, PathSource};
|
2020-11-06 13:11:21 +00:00
|
|
|
|
use macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
|
2015-03-15 21:44:19 +00:00
|
|
|
|
|
2021-07-26 03:38:16 +00:00
|
|
|
|
use crate::access_levels::AccessLevelsVisitor;
|
|
|
|
|
|
2019-04-20 16:36:05 +00:00
|
|
|
|
type Res = def::Res<NodeId>;
|
2019-04-03 07:07:45 +00:00
|
|
|
|
|
2021-07-26 03:38:16 +00:00
|
|
|
|
mod access_levels;
|
2019-12-24 22:38:22 +00:00
|
|
|
|
mod build_reduced_graph;
|
|
|
|
|
mod check_unused;
|
2019-11-23 15:19:57 +00:00
|
|
|
|
mod def_collector;
|
2016-03-17 01:05:29 +00:00
|
|
|
|
mod diagnostics;
|
2022-03-26 19:59:09 +00:00
|
|
|
|
mod ident;
|
2019-12-29 16:42:23 +00:00
|
|
|
|
mod imports;
|
2019-08-07 23:39:02 +00:00
|
|
|
|
mod late;
|
2016-09-07 23:21:59 +00:00
|
|
|
|
mod macros;
|
2014-12-19 07:13:54 +00:00
|
|
|
|
|
2018-11-17 17:13:25 +00:00
|
|
|
|
enum Weak {
|
|
|
|
|
Yes,
|
|
|
|
|
No,
|
2018-11-08 22:29:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 08:44:57 +00:00
|
|
|
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
|
|
|
|
pub enum Determinacy {
|
|
|
|
|
Determined,
|
|
|
|
|
Undetermined,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Determinacy {
|
|
|
|
|
fn determined(determined: bool) -> Determinacy {
|
|
|
|
|
if determined { Determinacy::Determined } else { Determinacy::Undetermined }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 18:45:43 +00:00
|
|
|
|
/// A specific scope in which a name can be looked up.
|
|
|
|
|
/// This enum is currently used only for early resolution (imports and macros),
|
|
|
|
|
/// but not for late resolution yet.
|
2019-07-11 20:05:35 +00:00
|
|
|
|
#[derive(Clone, Copy)]
|
2019-07-11 18:45:43 +00:00
|
|
|
|
enum Scope<'a> {
|
2021-06-25 18:43:04 +00:00
|
|
|
|
DeriveHelpers(LocalExpnId),
|
2019-10-03 22:44:57 +00:00
|
|
|
|
DeriveHelpersCompat,
|
2020-11-06 13:11:21 +00:00
|
|
|
|
MacroRules(MacroRulesScopeRef<'a>),
|
2019-07-11 18:45:43 +00:00
|
|
|
|
CrateRoot,
|
2021-03-13 19:23:18 +00:00
|
|
|
|
// The node ID is for reporting the `PROC_MACRO_DERIVE_RESOLUTION_FALLBACK`
|
|
|
|
|
// lint if it should be reported.
|
|
|
|
|
Module(Module<'a>, Option<NodeId>),
|
2019-11-03 17:28:20 +00:00
|
|
|
|
RegisteredAttrs,
|
2019-07-11 18:45:43 +00:00
|
|
|
|
MacroUsePrelude,
|
|
|
|
|
BuiltinAttrs,
|
|
|
|
|
ExternPrelude,
|
|
|
|
|
ToolPrelude,
|
|
|
|
|
StdLibPrelude,
|
|
|
|
|
BuiltinTypes,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Names from different contexts may want to visit different subsets of all specific scopes
|
|
|
|
|
/// with different restrictions when looking up the resolution.
|
|
|
|
|
/// This enum is currently used only for early resolution (imports and macros),
|
|
|
|
|
/// but not for late resolution yet.
|
2021-03-13 19:23:18 +00:00
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
|
enum ScopeSet<'a> {
|
2019-08-09 22:40:05 +00:00
|
|
|
|
/// All scopes with the given namespace.
|
|
|
|
|
All(Namespace, /*is_import*/ bool),
|
|
|
|
|
/// Crate root, then extern prelude (used for mixed 2015-2018 mode in macros).
|
2018-11-24 21:25:03 +00:00
|
|
|
|
AbsolutePath(Namespace),
|
2019-08-09 22:40:05 +00:00
|
|
|
|
/// All scopes with macro namespace and the given macro kind restriction.
|
2018-11-24 16:14:05 +00:00
|
|
|
|
Macro(MacroKind),
|
2021-03-13 19:23:18 +00:00
|
|
|
|
/// All scopes with the given namespace, used for partially performing late resolution.
|
|
|
|
|
/// The node id enables lints and is used for reporting them.
|
|
|
|
|
Late(Namespace, Module<'a>, Option<NodeId>),
|
2018-11-24 16:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 18:45:43 +00:00
|
|
|
|
/// Everything you need to know about a name's location to resolve it.
|
|
|
|
|
/// Serves as a starting point for the scope visitor.
|
|
|
|
|
/// This struct is currently used only for early resolution (imports and macros),
|
|
|
|
|
/// but not for late resolution yet.
|
2019-08-12 22:39:10 +00:00
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
2019-07-11 18:45:43 +00:00
|
|
|
|
pub struct ParentScope<'a> {
|
|
|
|
|
module: Module<'a>,
|
2021-06-25 18:43:04 +00:00
|
|
|
|
expansion: LocalExpnId,
|
2020-11-06 13:11:21 +00:00
|
|
|
|
macro_rules: MacroRulesScopeRef<'a>,
|
2019-08-12 22:39:10 +00:00
|
|
|
|
derives: &'a [ast::Path],
|
2019-07-11 18:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-12 20:19:36 +00:00
|
|
|
|
impl<'a> ParentScope<'a> {
|
2019-08-15 17:47:15 +00:00
|
|
|
|
/// Creates a parent scope with the passed argument used as the module scope component,
|
|
|
|
|
/// and other scope components set to default empty values.
|
2020-11-06 13:11:21 +00:00
|
|
|
|
pub fn module(module: Module<'a>, resolver: &Resolver<'a>) -> ParentScope<'a> {
|
2020-03-13 22:06:36 +00:00
|
|
|
|
ParentScope {
|
|
|
|
|
module,
|
2021-06-25 18:43:04 +00:00
|
|
|
|
expansion: LocalExpnId::ROOT,
|
2020-11-06 13:11:21 +00:00
|
|
|
|
macro_rules: resolver.arenas.alloc_macro_rules_scope(MacroRulesScope::Empty),
|
2020-03-13 22:06:36 +00:00
|
|
|
|
derives: &[],
|
|
|
|
|
}
|
2019-08-12 20:19:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-13 19:41:02 +00:00
|
|
|
|
#[derive(Copy, Debug, Clone)]
|
|
|
|
|
enum ImplTraitContext {
|
|
|
|
|
Existential,
|
|
|
|
|
Universal(LocalDefId),
|
|
|
|
|
}
|
|
|
|
|
|
Clean up "pattern doesn't bind x" messages
Group "missing variable bind" spans in `or` matches and clarify wording
for the two possible cases: when a variable from the first pattern is
not in any of the subsequent patterns, and when a variable in any of the
other patterns is not in the first one.
Before:
```
error[E0408]: variable `a` from pattern #1 is not bound in pattern #2
--> file.rs:10:23
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^^^^ pattern doesn't bind `a`
error[E0408]: variable `b` from pattern #2 is not bound in pattern #1
--> file.rs:10:32
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^ pattern doesn't bind `b`
error[E0408]: variable `a` from pattern #1 is not bound in pattern #3
--> file.rs:10:37
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^ pattern doesn't bind `a`
error[E0408]: variable `d` from pattern #1 is not bound in pattern #3
--> file.rs:10:37
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^ pattern doesn't bind `d`
error[E0408]: variable `c` from pattern #3 is not bound in pattern #1
--> file.rs:10:43
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^ pattern doesn't bind `c`
error[E0408]: variable `d` from pattern #1 is not bound in pattern #4
--> file.rs:10:48
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^ pattern doesn't bind `d`
error: aborting due to 6 previous errors
```
After:
```
error[E0408]: variable `a` is not bound in all patterns
--> file.rs:20:37
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| - ^^^^^^^^^^^ ^^^^^^^^ - variable
t in all patterns
| | | |
| | | pattern doesn't bind `a`
| | pattern doesn't bind `a`
| variable not in all patterns
error[E0408]: variable `d` is not bound in all patterns
--> file.rs:20:37
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| - - ^^^^^^^^ ^^^^^^^^ pattern
esn't bind `d`
| | | |
| | | pattern doesn't bind `d`
| | variable not in all patterns
| variable not in all patterns
error[E0408]: variable `b` is not bound in all patterns
--> file.rs:20:37
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| ^^^^^^^^^^^ - ^^^^^^^^ ^^^^^^^^ pattern
esn't bind `b`
| | | |
| | | pattern doesn't bind `b`
| | variable not in all patterns
| pattern doesn't bind `b`
error[E0408]: variable `c` is not bound in all patterns
--> file.rs:20:48
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| ^^^^^^^^^^^ ^^^^^^^^^^^ - ^^^^^^^^ pattern
esn't bind `c`
| | | |
| | | variable not in all
tterns
| | pattern doesn't bind `c`
| pattern doesn't bind `c`
error: aborting due to 4 previous errors
```
* Have only one presentation for binding consistency errors
* Point to same binding in multiple patterns when possible
* Check inconsistent bindings in all arms
* Simplify wording of diagnostic message
* Sort emition and spans of binding errors for deterministic output
2017-02-10 01:54:56 +00:00
|
|
|
|
#[derive(Eq)]
|
|
|
|
|
struct BindingError {
|
2020-04-19 11:00:18 +00:00
|
|
|
|
name: Symbol,
|
2017-03-05 23:19:05 +00:00
|
|
|
|
origin: BTreeSet<Span>,
|
|
|
|
|
target: BTreeSet<Span>,
|
2019-12-24 22:38:22 +00:00
|
|
|
|
could_be_path: bool,
|
Clean up "pattern doesn't bind x" messages
Group "missing variable bind" spans in `or` matches and clarify wording
for the two possible cases: when a variable from the first pattern is
not in any of the subsequent patterns, and when a variable in any of the
other patterns is not in the first one.
Before:
```
error[E0408]: variable `a` from pattern #1 is not bound in pattern #2
--> file.rs:10:23
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^^^^ pattern doesn't bind `a`
error[E0408]: variable `b` from pattern #2 is not bound in pattern #1
--> file.rs:10:32
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^ pattern doesn't bind `b`
error[E0408]: variable `a` from pattern #1 is not bound in pattern #3
--> file.rs:10:37
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^ pattern doesn't bind `a`
error[E0408]: variable `d` from pattern #1 is not bound in pattern #3
--> file.rs:10:37
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^ pattern doesn't bind `d`
error[E0408]: variable `c` from pattern #3 is not bound in pattern #1
--> file.rs:10:43
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^ pattern doesn't bind `c`
error[E0408]: variable `d` from pattern #1 is not bound in pattern #4
--> file.rs:10:48
|
10 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
| ^^^^^^^^ pattern doesn't bind `d`
error: aborting due to 6 previous errors
```
After:
```
error[E0408]: variable `a` is not bound in all patterns
--> file.rs:20:37
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| - ^^^^^^^^^^^ ^^^^^^^^ - variable
t in all patterns
| | | |
| | | pattern doesn't bind `a`
| | pattern doesn't bind `a`
| variable not in all patterns
error[E0408]: variable `d` is not bound in all patterns
--> file.rs:20:37
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| - - ^^^^^^^^ ^^^^^^^^ pattern
esn't bind `d`
| | | |
| | | pattern doesn't bind `d`
| | variable not in all patterns
| variable not in all patterns
error[E0408]: variable `b` is not bound in all patterns
--> file.rs:20:37
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| ^^^^^^^^^^^ - ^^^^^^^^ ^^^^^^^^ pattern
esn't bind `b`
| | | |
| | | pattern doesn't bind `b`
| | variable not in all patterns
| pattern doesn't bind `b`
error[E0408]: variable `c` is not bound in all patterns
--> file.rs:20:48
|
20 | T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
| ^^^^^^^^^^^ ^^^^^^^^^^^ - ^^^^^^^^ pattern
esn't bind `c`
| | | |
| | | variable not in all
tterns
| | pattern doesn't bind `c`
| pattern doesn't bind `c`
error: aborting due to 4 previous errors
```
* Have only one presentation for binding consistency errors
* Point to same binding in multiple patterns when possible
* Check inconsistent bindings in all arms
* Simplify wording of diagnostic message
* Sort emition and spans of binding errors for deterministic output
2017-02-10 01:54:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl PartialOrd for BindingError {
|
|
|
|
|
fn partial_cmp(&self, other: &BindingError) -> Option<cmp::Ordering> {
|
|
|
|
|
Some(self.cmp(other))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl PartialEq for BindingError {
|
|
|
|
|
fn eq(&self, other: &BindingError) -> bool {
|
|
|
|
|
self.name == other.name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Ord for BindingError {
|
|
|
|
|
fn cmp(&self, other: &BindingError) -> cmp::Ordering {
|
|
|
|
|
self.name.cmp(&other.name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-17 01:05:29 +00:00
|
|
|
|
enum ResolutionError<'a> {
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0401: can't use type or const parameters from outer function.
|
2019-10-05 15:55:58 +00:00
|
|
|
|
GenericParamsFromOuterFunction(Res, HasGenericParams),
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0403: the name is already used for a type or const parameter in this generic
|
|
|
|
|
/// parameter list.
|
2020-04-19 11:00:18 +00:00
|
|
|
|
NameAlreadyUsedInParameterList(Symbol, Span),
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0407: method is not a member of trait.
|
2021-11-17 19:37:46 +00:00
|
|
|
|
MethodNotMemberOfTrait(Ident, String, Option<Symbol>),
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0437: type is not a member of trait.
|
2021-11-17 19:37:46 +00:00
|
|
|
|
TypeNotMemberOfTrait(Ident, String, Option<Symbol>),
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0438: const is not a member of trait.
|
2021-11-17 19:37:46 +00:00
|
|
|
|
ConstNotMemberOfTrait(Ident, String, Option<Symbol>),
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0408: variable `{}` is not bound in all patterns.
|
2021-11-17 19:37:46 +00:00
|
|
|
|
VariableNotBoundInPattern(BindingError, ParentScope<'a>),
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0409: variable `{}` is bound in inconsistent ways within the same match arm.
|
2020-04-19 11:00:18 +00:00
|
|
|
|
VariableBoundWithDifferentMode(Symbol, Span),
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0415: identifier is bound more than once in this parameter list.
|
2020-07-08 10:03:37 +00:00
|
|
|
|
IdentifierBoundMoreThanOnceInParameterList(Symbol),
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0416: identifier is bound more than once in the same pattern.
|
2020-07-08 10:03:37 +00:00
|
|
|
|
IdentifierBoundMoreThanOnceInSamePattern(Symbol),
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0426: use of undeclared label.
|
2020-07-08 10:03:37 +00:00
|
|
|
|
UndeclaredLabel { name: Symbol, suggestion: Option<LabelSuggestion> },
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0429: `self` imports are only allowed within a `{ }` list.
|
2020-05-03 16:54:21 +00:00
|
|
|
|
SelfImportsOnlyAllowedWithin { root: bool, span_with_rename: Span },
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0430: `self` import can only appear once in the list.
|
2015-07-14 14:32:43 +00:00
|
|
|
|
SelfImportCanOnlyAppearOnceInTheList,
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0431: `self` import can only appear in an import list with a non-empty prefix.
|
2015-07-14 14:32:43 +00:00
|
|
|
|
SelfImportOnlyInImportListWithNonEmptyPrefix,
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0433: failed to resolve.
|
2019-01-16 20:30:41 +00:00
|
|
|
|
FailedToResolve { label: String, suggestion: Option<Suggestion> },
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0434: can't capture dynamic environment in a fn item.
|
2015-07-14 14:32:43 +00:00
|
|
|
|
CannotCaptureDynamicEnvironmentInFnItem,
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0435: attempt to use a non-constant value in a constant.
|
2021-01-08 00:44:08 +00:00
|
|
|
|
AttemptToUseNonConstantValueInConstant(
|
|
|
|
|
Ident,
|
|
|
|
|
/* suggestion */ &'static str,
|
|
|
|
|
/* current */ &'static str,
|
|
|
|
|
),
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Error E0530: `X` bindings cannot shadow `Y`s.
|
2021-05-19 16:51:42 +00:00
|
|
|
|
BindingShadowsSomethingUnacceptable {
|
|
|
|
|
shadowing_binding_descr: &'static str,
|
|
|
|
|
name: Symbol,
|
|
|
|
|
participle: &'static str,
|
|
|
|
|
article: &'static str,
|
|
|
|
|
shadowed_binding_descr: &'static str,
|
|
|
|
|
shadowed_binding_span: Span,
|
|
|
|
|
},
|
2021-03-01 11:50:09 +00:00
|
|
|
|
/// Error E0128: generic parameters with a default cannot use forward-declared identifiers.
|
2021-06-01 16:44:49 +00:00
|
|
|
|
ForwardDeclaredGenericParam,
|
2020-07-08 20:16:18 +00:00
|
|
|
|
/// ERROR E0770: the type of const parameters must not depend on other generic parameters.
|
2020-07-18 20:35:50 +00:00
|
|
|
|
ParamInTyOfConstParam(Symbol),
|
2020-10-11 15:47:45 +00:00
|
|
|
|
/// generic parameters must not be used inside const evaluations.
|
2020-07-28 13:55:42 +00:00
|
|
|
|
///
|
|
|
|
|
/// This error is only emitted when using `min_const_generics`.
|
2020-09-14 21:39:43 +00:00
|
|
|
|
ParamInNonTrivialAnonConst { name: Symbol, is_type: bool },
|
2021-03-01 11:50:09 +00:00
|
|
|
|
/// Error E0735: generic parameters with a default cannot use `Self`
|
2021-07-14 18:22:32 +00:00
|
|
|
|
SelfInGenericParamDefault,
|
2020-06-25 14:16:38 +00:00
|
|
|
|
/// Error E0767: use of unreachable label
|
2020-07-08 10:03:37 +00:00
|
|
|
|
UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option<LabelSuggestion> },
|
2022-01-08 13:49:38 +00:00
|
|
|
|
/// Error E0323, E0324, E0325: mismatch between trait item and impl item.
|
|
|
|
|
TraitImplMismatch {
|
|
|
|
|
name: Symbol,
|
|
|
|
|
kind: &'static str,
|
|
|
|
|
trait_path: String,
|
|
|
|
|
trait_item_span: Span,
|
|
|
|
|
code: rustc_errors::DiagnosticId,
|
|
|
|
|
},
|
2022-03-01 00:50:56 +00:00
|
|
|
|
/// Inline asm `sym` operand must refer to a `fn` or `static`.
|
|
|
|
|
InvalidAsmSym,
|
2015-12-10 23:00:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-06 22:49:21 +00:00
|
|
|
|
enum VisResolutionError<'a> {
|
|
|
|
|
Relative2018(Span, &'a ast::Path),
|
|
|
|
|
AncestorOnly(Span),
|
|
|
|
|
FailedToResolve(Span, String, Option<Suggestion>),
|
|
|
|
|
ExpectedFound(Span, String, Res),
|
|
|
|
|
Indeterminate(Span),
|
|
|
|
|
ModuleOnly(Span),
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-13 18:12:29 +00:00
|
|
|
|
/// A minimal representation of a path segment. We use this in resolve because we synthesize 'path
|
|
|
|
|
/// segments' which don't have the rest of an AST or HIR `PathSegment`.
|
2018-09-12 03:21:50 +00:00
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
|
pub struct Segment {
|
|
|
|
|
ident: Ident,
|
|
|
|
|
id: Option<NodeId>,
|
2020-06-13 18:12:29 +00:00
|
|
|
|
/// Signals whether this `PathSegment` has generic arguments. Used to avoid providing
|
|
|
|
|
/// nonsensical suggestions.
|
2020-06-17 23:29:03 +00:00
|
|
|
|
has_generic_args: bool,
|
2022-03-10 22:12:35 +00:00
|
|
|
|
/// Signals whether this `PathSegment` has lifetime arguments.
|
|
|
|
|
has_lifetime_args: bool,
|
|
|
|
|
args_span: Span,
|
2018-09-12 03:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Segment {
|
|
|
|
|
fn from_path(path: &Path) -> Vec<Segment> {
|
|
|
|
|
path.segments.iter().map(|s| s.into()).collect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn from_ident(ident: Ident) -> Segment {
|
2022-03-10 22:12:35 +00:00
|
|
|
|
Segment {
|
|
|
|
|
ident,
|
|
|
|
|
id: None,
|
|
|
|
|
has_generic_args: false,
|
|
|
|
|
has_lifetime_args: false,
|
|
|
|
|
args_span: DUMMY_SP,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn from_ident_and_id(ident: Ident, id: NodeId) -> Segment {
|
|
|
|
|
Segment {
|
|
|
|
|
ident,
|
|
|
|
|
id: Some(id),
|
|
|
|
|
has_generic_args: false,
|
|
|
|
|
has_lifetime_args: false,
|
|
|
|
|
args_span: DUMMY_SP,
|
|
|
|
|
}
|
2018-09-12 03:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn names_to_string(segments: &[Segment]) -> String {
|
2019-12-24 22:38:22 +00:00
|
|
|
|
names_to_string(&segments.iter().map(|seg| seg.ident.name).collect::<Vec<_>>())
|
2018-09-12 03:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> From<&'a ast::PathSegment> for Segment {
|
|
|
|
|
fn from(seg: &'a ast::PathSegment) -> Segment {
|
2022-03-10 22:12:35 +00:00
|
|
|
|
let has_generic_args = seg.args.is_some();
|
|
|
|
|
let (args_span, has_lifetime_args) = if let Some(args) = seg.args.as_deref() {
|
|
|
|
|
match args {
|
|
|
|
|
GenericArgs::AngleBracketed(args) => {
|
|
|
|
|
let found_lifetimes = args
|
|
|
|
|
.args
|
|
|
|
|
.iter()
|
|
|
|
|
.any(|arg| matches!(arg, AngleBracketedArg::Arg(GenericArg::Lifetime(_))));
|
|
|
|
|
(args.span, found_lifetimes)
|
|
|
|
|
}
|
|
|
|
|
GenericArgs::Parenthesized(args) => (args.span, true),
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
(DUMMY_SP, false)
|
|
|
|
|
};
|
|
|
|
|
Segment {
|
|
|
|
|
ident: seg.ident,
|
|
|
|
|
id: Some(seg.id),
|
|
|
|
|
has_generic_args,
|
|
|
|
|
has_lifetime_args,
|
|
|
|
|
args_span,
|
|
|
|
|
}
|
2018-09-12 03:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 13:09:24 +00:00
|
|
|
|
/// An intermediate resolution result.
|
|
|
|
|
///
|
|
|
|
|
/// This refers to the thing referred by a name. The difference between `Res` and `Item` is that
|
|
|
|
|
/// items are visible in their whole block, while `Res`es only from the place they are defined
|
|
|
|
|
/// forward.
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
enum LexicalScopeBinding<'a> {
|
|
|
|
|
Item(&'a NameBinding<'a>),
|
|
|
|
|
Res(Res),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> LexicalScopeBinding<'a> {
|
|
|
|
|
fn res(self) -> Res {
|
|
|
|
|
match self {
|
|
|
|
|
LexicalScopeBinding::Item(binding) => binding.res(),
|
|
|
|
|
LexicalScopeBinding::Res(res) => res,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 13:29:22 +00:00
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
2018-11-08 22:29:07 +00:00
|
|
|
|
enum ModuleOrUniformRoot<'a> {
|
2018-08-09 13:29:22 +00:00
|
|
|
|
/// Regular module.
|
|
|
|
|
Module(Module<'a>),
|
|
|
|
|
|
2018-11-24 21:25:03 +00:00
|
|
|
|
/// Virtual module that denotes resolution in crate root with fallback to extern prelude.
|
|
|
|
|
CrateRootAndExternPrelude,
|
|
|
|
|
|
2018-11-24 16:14:05 +00:00
|
|
|
|
/// Virtual module that denotes resolution in extern prelude.
|
2019-01-13 13:18:00 +00:00
|
|
|
|
/// Used for paths starting with `::` on 2018 edition.
|
2018-11-24 16:14:05 +00:00
|
|
|
|
ExternPrelude,
|
|
|
|
|
|
|
|
|
|
/// Virtual module that denotes resolution in current scope.
|
|
|
|
|
/// Used only for resolving single-segment imports. The reason it exists is that import paths
|
|
|
|
|
/// are always split into two parts, the first of which should be some kind of module.
|
|
|
|
|
CurrentScope,
|
2018-08-09 13:29:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-28 21:15:19 +00:00
|
|
|
|
impl ModuleOrUniformRoot<'_> {
|
|
|
|
|
fn same_def(lhs: Self, rhs: Self) -> bool {
|
|
|
|
|
match (lhs, rhs) {
|
2019-12-24 22:38:22 +00:00
|
|
|
|
(ModuleOrUniformRoot::Module(lhs), ModuleOrUniformRoot::Module(rhs)) => {
|
2021-09-26 16:29:53 +00:00
|
|
|
|
ptr::eq(lhs, rhs)
|
2019-12-24 22:38:22 +00:00
|
|
|
|
}
|
|
|
|
|
(
|
|
|
|
|
ModuleOrUniformRoot::CrateRootAndExternPrelude,
|
|
|
|
|
ModuleOrUniformRoot::CrateRootAndExternPrelude,
|
|
|
|
|
)
|
|
|
|
|
| (ModuleOrUniformRoot::ExternPrelude, ModuleOrUniformRoot::ExternPrelude)
|
|
|
|
|
| (ModuleOrUniformRoot::CurrentScope, ModuleOrUniformRoot::CurrentScope) => true,
|
2018-11-10 15:58:37 +00:00
|
|
|
|
_ => false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 05:21:11 +00:00
|
|
|
|
#[derive(Clone, Debug)]
|
2016-11-25 06:07:21 +00:00
|
|
|
|
enum PathResult<'a> {
|
2018-08-09 13:29:22 +00:00
|
|
|
|
Module(ModuleOrUniformRoot<'a>),
|
2019-05-04 12:18:58 +00:00
|
|
|
|
NonModule(PartialRes),
|
2016-11-25 06:07:21 +00:00
|
|
|
|
Indeterminate,
|
2019-01-16 20:30:41 +00:00
|
|
|
|
Failed {
|
|
|
|
|
span: Span,
|
|
|
|
|
label: String,
|
|
|
|
|
suggestion: Option<Suggestion>,
|
|
|
|
|
is_error_from_last_segment: bool,
|
|
|
|
|
},
|
2016-11-25 06:07:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 19:47:19 +00:00
|
|
|
|
impl<'a> PathResult<'a> {
|
|
|
|
|
fn failed(
|
|
|
|
|
span: Span,
|
|
|
|
|
is_error_from_last_segment: bool,
|
2022-03-23 23:55:22 +00:00
|
|
|
|
finalize: bool,
|
2022-03-23 19:47:19 +00:00
|
|
|
|
label_and_suggestion: impl FnOnce() -> (String, Option<Suggestion>),
|
|
|
|
|
) -> PathResult<'a> {
|
|
|
|
|
let (label, suggestion) =
|
2022-03-23 23:55:22 +00:00
|
|
|
|
if finalize { label_and_suggestion() } else { (String::new(), None) };
|
2022-03-23 19:47:19 +00:00
|
|
|
|
PathResult::Failed { span, label, suggestion, is_error_from_last_segment }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 03:52:51 +00:00
|
|
|
|
#[derive(Debug)]
|
2016-09-18 09:45:06 +00:00
|
|
|
|
enum ModuleKind {
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// An anonymous module; e.g., just a block.
|
2018-03-24 16:07:58 +00:00
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// fn main() {
|
|
|
|
|
/// fn f() {} // (1)
|
|
|
|
|
/// { // This is an anonymous module
|
|
|
|
|
/// f(); // This resolves to (2) as we are inside the block.
|
|
|
|
|
/// fn f() {} // (2)
|
|
|
|
|
/// }
|
|
|
|
|
/// f(); // Resolves to (1)
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2016-09-18 09:45:06 +00:00
|
|
|
|
Block(NodeId),
|
2018-03-24 16:07:58 +00:00
|
|
|
|
/// Any module with a name.
|
|
|
|
|
///
|
|
|
|
|
/// This could be:
|
2018-02-18 17:01:33 +00:00
|
|
|
|
///
|
2020-12-28 00:54:47 +00:00
|
|
|
|
/// * A normal module – either `mod from_file;` or `mod from_block { }` –
|
|
|
|
|
/// or the crate root (which is conceptually a top-level module).
|
|
|
|
|
/// Note that the crate root's [name][Self::name] will be [`kw::Empty`].
|
2018-03-24 16:07:58 +00:00
|
|
|
|
/// * A trait or an enum (it implicitly contains associated types, methods and variant
|
|
|
|
|
/// constructors).
|
2020-04-19 11:00:18 +00:00
|
|
|
|
Def(DefKind, DefId, Symbol),
|
2012-05-22 17:54:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-07 17:56:41 +00:00
|
|
|
|
impl ModuleKind {
|
|
|
|
|
/// Get name of the module.
|
2020-04-19 11:00:18 +00:00
|
|
|
|
pub fn name(&self) -> Option<Symbol> {
|
2019-04-07 17:56:41 +00:00
|
|
|
|
match self {
|
|
|
|
|
ModuleKind::Block(..) => None,
|
2019-04-20 16:46:19 +00:00
|
|
|
|
ModuleKind::Def(.., name) => Some(*name),
|
2019-04-07 17:56:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 20:04:26 +00:00
|
|
|
|
/// A key that identifies a binding in a given `Module`.
|
|
|
|
|
///
|
|
|
|
|
/// Multiple bindings in the same module can have the same key (in a valid
|
|
|
|
|
/// program) if all but one of them come from glob imports.
|
2020-03-17 15:45:02 +00:00
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
2019-09-09 20:04:26 +00:00
|
|
|
|
struct BindingKey {
|
2022-03-30 19:14:15 +00:00
|
|
|
|
/// The identifier for the binding, always the `normalize_to_macros_2_0` version of the
|
2019-09-09 20:04:26 +00:00
|
|
|
|
/// identifier.
|
|
|
|
|
ident: Ident,
|
|
|
|
|
ns: Namespace,
|
|
|
|
|
/// 0 if ident is not `_`, otherwise a value that's unique to the specific
|
|
|
|
|
/// `_` in the expanded AST that introduced this binding.
|
|
|
|
|
disambiguator: u32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Resolutions<'a> = RefCell<FxIndexMap<BindingKey, &'a RefCell<NameResolution<'a>>>>;
|
2019-07-29 18:19:50 +00:00
|
|
|
|
|
2012-07-04 21:53:12 +00:00
|
|
|
|
/// One node in the tree of modules.
|
2020-12-28 00:53:57 +00:00
|
|
|
|
///
|
2020-12-28 00:54:47 +00:00
|
|
|
|
/// Note that a "module" in resolve is broader than a `mod` that you declare in Rust code. It may be one of these:
|
|
|
|
|
///
|
|
|
|
|
/// * `mod`
|
|
|
|
|
/// * crate root (aka, top-level anonymous module)
|
|
|
|
|
/// * `enum`
|
|
|
|
|
/// * `trait`
|
|
|
|
|
/// * curly-braced block with statements
|
|
|
|
|
///
|
|
|
|
|
/// You can use [`ModuleData::kind`] to determine the kind of module this is.
|
2016-11-26 12:47:52 +00:00
|
|
|
|
pub struct ModuleData<'a> {
|
2020-12-28 00:53:57 +00:00
|
|
|
|
/// The direct parent module (it may not be a `mod`, however).
|
2016-09-18 09:45:06 +00:00
|
|
|
|
parent: Option<Module<'a>>,
|
2020-12-28 00:53:57 +00:00
|
|
|
|
/// What kind of module this is, because this may not be a `mod`.
|
2016-09-18 09:45:06 +00:00
|
|
|
|
kind: ModuleKind,
|
2016-02-02 20:21:24 +00:00
|
|
|
|
|
2020-12-28 00:53:57 +00:00
|
|
|
|
/// Mapping between names and their (possibly in-progress) resolutions in this module.
|
|
|
|
|
/// Resolutions in modules from other crates are not populated until accessed.
|
2019-07-29 18:19:50 +00:00
|
|
|
|
lazy_resolutions: Resolutions<'a>,
|
2020-12-28 00:53:57 +00:00
|
|
|
|
/// True if this is a module from other crate that needs to be populated on access.
|
2019-07-29 18:19:50 +00:00
|
|
|
|
populate_on_access: Cell<bool>,
|
2012-05-22 17:54:12 +00:00
|
|
|
|
|
2020-12-28 00:53:57 +00:00
|
|
|
|
/// Macro invocations that can expand into items in this module.
|
2021-06-25 18:43:04 +00:00
|
|
|
|
unexpanded_invocations: RefCell<FxHashSet<LocalExpnId>>,
|
2016-11-11 10:51:15 +00:00
|
|
|
|
|
2020-12-28 00:53:57 +00:00
|
|
|
|
/// Whether `#[no_implicit_prelude]` is active.
|
2016-09-19 05:25:17 +00:00
|
|
|
|
no_implicit_prelude: bool,
|
2016-02-06 23:43:04 +00:00
|
|
|
|
|
2020-03-07 15:49:13 +00:00
|
|
|
|
glob_importers: RefCell<Vec<&'a Import<'a>>>,
|
|
|
|
|
globs: RefCell<Vec<&'a Import<'a>>>,
|
2015-08-05 19:47:01 +00:00
|
|
|
|
|
2020-12-28 00:53:57 +00:00
|
|
|
|
/// Used to memoize the traits in this module for faster searches through all traits in scope.
|
2016-11-29 02:07:12 +00:00
|
|
|
|
traits: RefCell<Option<Box<[(Ident, &'a NameBinding<'a>)]>>>,
|
2016-04-18 00:00:18 +00:00
|
|
|
|
|
2017-05-10 11:19:29 +00:00
|
|
|
|
/// Span of the module itself. Used for error reporting.
|
|
|
|
|
span: Span,
|
2017-03-22 08:39:51 +00:00
|
|
|
|
|
2019-07-15 22:04:05 +00:00
|
|
|
|
expansion: ExpnId,
|
2012-05-22 17:54:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-19 00:09:55 +00:00
|
|
|
|
type Module<'a> = &'a ModuleData<'a>;
|
2016-01-11 21:19:29 +00:00
|
|
|
|
|
2016-11-26 12:47:52 +00:00
|
|
|
|
impl<'a> ModuleData<'a> {
|
2021-09-11 13:37:34 +00:00
|
|
|
|
fn new(
|
|
|
|
|
parent: Option<Module<'a>>,
|
|
|
|
|
kind: ModuleKind,
|
|
|
|
|
expansion: ExpnId,
|
|
|
|
|
span: Span,
|
|
|
|
|
no_implicit_prelude: bool,
|
|
|
|
|
) -> Self {
|
2021-09-13 21:13:14 +00:00
|
|
|
|
let is_foreign = match kind {
|
|
|
|
|
ModuleKind::Def(_, def_id, _) => !def_id.is_local(),
|
|
|
|
|
ModuleKind::Block(_) => false,
|
|
|
|
|
};
|
2016-11-26 12:47:52 +00:00
|
|
|
|
ModuleData {
|
2017-08-07 05:54:09 +00:00
|
|
|
|
parent,
|
|
|
|
|
kind,
|
2019-07-29 18:19:50 +00:00
|
|
|
|
lazy_resolutions: Default::default(),
|
2021-09-13 21:13:14 +00:00
|
|
|
|
populate_on_access: Cell::new(is_foreign),
|
2019-08-17 17:49:00 +00:00
|
|
|
|
unexpanded_invocations: Default::default(),
|
2021-09-11 13:37:34 +00:00
|
|
|
|
no_implicit_prelude,
|
2016-02-16 03:54:14 +00:00
|
|
|
|
glob_importers: RefCell::new(Vec::new()),
|
2017-12-24 03:28:33 +00:00
|
|
|
|
globs: RefCell::new(Vec::new()),
|
2016-04-18 00:00:18 +00:00
|
|
|
|
traits: RefCell::new(None),
|
2017-08-07 05:54:09 +00:00
|
|
|
|
span,
|
|
|
|
|
expansion,
|
2016-01-11 21:19:29 +00:00
|
|
|
|
}
|
2012-09-05 22:58:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 18:19:50 +00:00
|
|
|
|
fn for_each_child<R, F>(&'a self, resolver: &mut R, mut f: F)
|
2019-12-24 22:38:22 +00:00
|
|
|
|
where
|
|
|
|
|
R: AsMut<Resolver<'a>>,
|
|
|
|
|
F: FnMut(&mut R, Ident, Namespace, &'a NameBinding<'a>),
|
2019-07-29 18:19:50 +00:00
|
|
|
|
{
|
2019-09-09 20:04:26 +00:00
|
|
|
|
for (key, name_resolution) in resolver.as_mut().resolutions(self).borrow().iter() {
|
2020-04-24 20:58:41 +00:00
|
|
|
|
if let Some(binding) = name_resolution.borrow().binding {
|
|
|
|
|
f(resolver, key.ident, key.ns, binding);
|
|
|
|
|
}
|
2016-02-07 23:58:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 17:21:19 +00:00
|
|
|
|
/// This modifies `self` in place. The traits will be stored in `self.traits`.
|
|
|
|
|
fn ensure_traits<R>(&'a self, resolver: &mut R)
|
|
|
|
|
where
|
|
|
|
|
R: AsMut<Resolver<'a>>,
|
|
|
|
|
{
|
|
|
|
|
let mut traits = self.traits.borrow_mut();
|
|
|
|
|
if traits.is_none() {
|
|
|
|
|
let mut collected_traits = Vec::new();
|
|
|
|
|
self.for_each_child(resolver, |_, name, ns, binding| {
|
|
|
|
|
if ns != TypeNS {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-18 16:33:37 +00:00
|
|
|
|
if let Res::Def(DefKind::Trait | DefKind::TraitAlias, _) = binding.res() {
|
|
|
|
|
collected_traits.push((name, binding))
|
2020-08-08 17:21:19 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
*traits = Some(collected_traits.into_boxed_slice());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-20 16:36:05 +00:00
|
|
|
|
fn res(&self) -> Option<Res> {
|
2016-09-18 09:45:06 +00:00
|
|
|
|
match self.kind {
|
2019-04-20 16:36:05 +00:00
|
|
|
|
ModuleKind::Def(kind, def_id, _) => Some(Res::Def(kind, def_id)),
|
2019-04-20 16:46:19 +00:00
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-29 18:41:46 +00:00
|
|
|
|
// Public for rustdoc.
|
|
|
|
|
pub fn def_id(&self) -> DefId {
|
2021-09-26 16:29:53 +00:00
|
|
|
|
self.opt_def_id().expect("`ModuleData::def_id` is called on a block module")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn opt_def_id(&self) -> Option<DefId> {
|
2019-04-20 16:46:19 +00:00
|
|
|
|
match self.kind {
|
|
|
|
|
ModuleKind::Def(_, def_id, _) => Some(def_id),
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
2015-11-16 07:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-09 23:19:53 +00:00
|
|
|
|
// `self` resolves to the first module ancestor that `is_normal`.
|
2015-11-16 07:59:50 +00:00
|
|
|
|
fn is_normal(&self) -> bool {
|
2020-10-27 01:02:48 +00:00
|
|
|
|
matches!(self.kind, ModuleKind::Def(DefKind::Mod, _, _))
|
2015-11-16 07:59:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_trait(&self) -> bool {
|
2020-10-27 01:02:48 +00:00
|
|
|
|
matches!(self.kind, ModuleKind::Def(DefKind::Trait, _, _))
|
2012-09-05 22:58:43 +00:00
|
|
|
|
}
|
2016-10-22 22:08:08 +00:00
|
|
|
|
|
2017-03-27 05:22:18 +00:00
|
|
|
|
fn nearest_item_scope(&'a self) -> Module<'a> {
|
2019-09-05 15:04:58 +00:00
|
|
|
|
match self.kind {
|
2020-04-17 00:38:52 +00:00
|
|
|
|
ModuleKind::Def(DefKind::Enum | DefKind::Trait, ..) => {
|
2019-12-24 22:38:22 +00:00
|
|
|
|
self.parent.expect("enum or trait module without a parent")
|
|
|
|
|
}
|
2019-09-05 15:04:58 +00:00
|
|
|
|
_ => self,
|
|
|
|
|
}
|
2017-03-27 05:22:18 +00:00
|
|
|
|
}
|
2018-09-27 01:49:40 +00:00
|
|
|
|
|
2021-09-13 21:13:14 +00:00
|
|
|
|
/// The [`DefId`] of the nearest `mod` item ancestor (which may be this module).
|
|
|
|
|
/// This may be the crate root.
|
|
|
|
|
fn nearest_parent_mod(&self) -> DefId {
|
|
|
|
|
match self.kind {
|
|
|
|
|
ModuleKind::Def(DefKind::Mod, def_id, _) => def_id,
|
|
|
|
|
_ => self.parent.expect("non-root module without parent").nearest_parent_mod(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 01:49:40 +00:00
|
|
|
|
fn is_ancestor_of(&self, mut other: &Self) -> bool {
|
|
|
|
|
while !ptr::eq(self, other) {
|
|
|
|
|
if let Some(parent) = other.parent {
|
|
|
|
|
other = parent;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
true
|
|
|
|
|
}
|
2015-08-06 10:47:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-26 12:47:52 +00:00
|
|
|
|
impl<'a> fmt::Debug for ModuleData<'a> {
|
2019-02-06 17:15:23 +00:00
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2019-04-20 16:36:05 +00:00
|
|
|
|
write!(f, "{:?}", self.res())
|
2014-11-28 02:41:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-14 01:05:01 +00:00
|
|
|
|
/// Records a possibly-private value, type, or module definition.
|
2016-02-15 05:18:55 +00:00
|
|
|
|
#[derive(Clone, Debug)]
|
2016-01-14 01:42:45 +00:00
|
|
|
|
pub struct NameBinding<'a> {
|
2016-02-07 21:34:23 +00:00
|
|
|
|
kind: NameBindingKind<'a>,
|
2018-12-29 15:15:29 +00:00
|
|
|
|
ambiguity: Option<(&'a NameBinding<'a>, AmbiguityKind)>,
|
2021-06-25 18:43:04 +00:00
|
|
|
|
expansion: LocalExpnId,
|
2016-04-27 01:13:15 +00:00
|
|
|
|
span: Span,
|
2016-04-09 23:19:53 +00:00
|
|
|
|
vis: ty::Visibility,
|
2012-08-18 00:55:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-28 02:34:01 +00:00
|
|
|
|
pub trait ToNameBinding<'a> {
|
2016-11-29 02:53:00 +00:00
|
|
|
|
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a>;
|
2016-07-28 02:34:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-29 02:53:00 +00:00
|
|
|
|
impl<'a> ToNameBinding<'a> for &'a NameBinding<'a> {
|
|
|
|
|
fn to_name_binding(self, _: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
|
2016-07-28 02:34:01 +00:00
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 05:18:55 +00:00
|
|
|
|
#[derive(Clone, Debug)]
|
2016-02-07 21:34:23 +00:00
|
|
|
|
enum NameBindingKind<'a> {
|
2019-04-20 16:36:05 +00:00
|
|
|
|
Res(Res, /* is_macro_export */ bool),
|
2016-01-11 21:19:29 +00:00
|
|
|
|
Module(Module<'a>),
|
2020-03-07 16:02:32 +00:00
|
|
|
|
Import { binding: &'a NameBinding<'a>, import: &'a Import<'a>, used: Cell<bool> },
|
2012-09-08 02:04:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 12:34:40 +00:00
|
|
|
|
impl<'a> NameBindingKind<'a> {
|
2021-08-22 12:46:15 +00:00
|
|
|
|
/// Is this a name binding of an import?
|
2019-01-29 12:34:40 +00:00
|
|
|
|
fn is_import(&self) -> bool {
|
2020-10-27 01:02:48 +00:00
|
|
|
|
matches!(*self, NameBindingKind::Import { .. })
|
2019-01-29 12:34:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-12 10:29:00 +00:00
|
|
|
|
struct PrivacyError<'a> {
|
|
|
|
|
ident: Ident,
|
|
|
|
|
binding: &'a NameBinding<'a>,
|
|
|
|
|
dedup_span: Span,
|
|
|
|
|
}
|
2016-02-25 04:40:46 +00:00
|
|
|
|
|
2017-08-17 09:03:59 +00:00
|
|
|
|
struct UseError<'a> {
|
2022-01-23 18:34:26 +00:00
|
|
|
|
err: DiagnosticBuilder<'a, ErrorGuaranteed>,
|
2020-06-02 18:16:23 +00:00
|
|
|
|
/// Candidates which user could `use` to access the missing type.
|
2017-08-17 09:03:59 +00:00
|
|
|
|
candidates: Vec<ImportSuggestion>,
|
2020-06-02 18:16:23 +00:00
|
|
|
|
/// The `DefId` of the module to place the use-statements in.
|
2020-05-24 22:39:39 +00:00
|
|
|
|
def_id: DefId,
|
2020-06-02 18:16:23 +00:00
|
|
|
|
/// Whether the diagnostic should say "instead" (as in `consider importing ... instead`).
|
|
|
|
|
instead: bool,
|
|
|
|
|
/// Extra free-form suggestion.
|
2020-01-22 07:01:21 +00:00
|
|
|
|
suggestion: Option<(Span, &'static str, String, Applicability)>,
|
2017-08-17 09:03:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-04 22:11:59 +00:00
|
|
|
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
|
|
|
|
enum AmbiguityKind {
|
|
|
|
|
Import,
|
|
|
|
|
BuiltinAttr,
|
|
|
|
|
DeriveHelper,
|
2020-03-13 22:23:24 +00:00
|
|
|
|
MacroRulesVsModularized,
|
2018-11-04 22:11:59 +00:00
|
|
|
|
GlobVsOuter,
|
|
|
|
|
GlobVsGlob,
|
|
|
|
|
GlobVsExpanded,
|
|
|
|
|
MoreExpandedVsOuter,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AmbiguityKind {
|
|
|
|
|
fn descr(self) -> &'static str {
|
|
|
|
|
match self {
|
2021-10-20 13:56:10 +00:00
|
|
|
|
AmbiguityKind::Import => "multiple potential import sources",
|
|
|
|
|
AmbiguityKind::BuiltinAttr => "a name conflict with a builtin attribute",
|
|
|
|
|
AmbiguityKind::DeriveHelper => "a name conflict with a derive helper attribute",
|
2020-03-13 22:23:24 +00:00
|
|
|
|
AmbiguityKind::MacroRulesVsModularized => {
|
2021-10-20 13:56:10 +00:00
|
|
|
|
"a conflict between a `macro_rules` name and a non-`macro_rules` name from another module"
|
2020-03-13 22:23:24 +00:00
|
|
|
|
}
|
2019-12-24 22:38:22 +00:00
|
|
|
|
AmbiguityKind::GlobVsOuter => {
|
2021-10-20 13:56:10 +00:00
|
|
|
|
"a conflict between a name from a glob import and an outer scope during import or macro resolution"
|
2019-12-24 22:38:22 +00:00
|
|
|
|
}
|
2021-10-20 13:56:10 +00:00
|
|
|
|
AmbiguityKind::GlobVsGlob => "multiple glob imports of a name in the same module",
|
2019-12-24 22:38:22 +00:00
|
|
|
|
AmbiguityKind::GlobVsExpanded => {
|
2021-10-20 13:56:10 +00:00
|
|
|
|
"a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution"
|
2019-12-24 22:38:22 +00:00
|
|
|
|
}
|
|
|
|
|
AmbiguityKind::MoreExpandedVsOuter => {
|
2021-10-20 13:56:10 +00:00
|
|
|
|
"a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution"
|
2019-12-24 22:38:22 +00:00
|
|
|
|
}
|
2018-11-04 22:11:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Miscellaneous bits of metadata for better ambiguity error reporting.
|
|
|
|
|
#[derive(Clone, Copy, PartialEq)]
|
|
|
|
|
enum AmbiguityErrorMisc {
|
2018-11-25 13:08:43 +00:00
|
|
|
|
SuggestCrate,
|
2018-11-04 22:11:59 +00:00
|
|
|
|
SuggestSelf,
|
|
|
|
|
FromPrelude,
|
|
|
|
|
None,
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-06 03:47:11 +00:00
|
|
|
|
struct AmbiguityError<'a> {
|
2018-11-04 22:11:59 +00:00
|
|
|
|
kind: AmbiguityKind,
|
2018-09-07 23:51:20 +00:00
|
|
|
|
ident: Ident,
|
2016-09-06 03:47:11 +00:00
|
|
|
|
b1: &'a NameBinding<'a>,
|
|
|
|
|
b2: &'a NameBinding<'a>,
|
2018-11-04 22:11:59 +00:00
|
|
|
|
misc1: AmbiguityErrorMisc,
|
|
|
|
|
misc2: AmbiguityErrorMisc,
|
2016-09-06 03:47:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-14 01:42:45 +00:00
|
|
|
|
impl<'a> NameBinding<'a> {
|
2016-11-27 00:23:54 +00:00
|
|
|
|
fn module(&self) -> Option<Module<'a>> {
|
2016-02-07 21:34:23 +00:00
|
|
|
|
match self.kind {
|
2016-11-27 00:23:54 +00:00
|
|
|
|
NameBindingKind::Module(module) => Some(module),
|
2016-02-07 21:34:23 +00:00
|
|
|
|
NameBindingKind::Import { binding, .. } => binding.module(),
|
2016-11-27 00:23:54 +00:00
|
|
|
|
_ => None,
|
2013-05-13 23:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-20 16:36:05 +00:00
|
|
|
|
fn res(&self) -> Res {
|
2016-02-07 21:34:23 +00:00
|
|
|
|
match self.kind {
|
2019-04-20 16:36:05 +00:00
|
|
|
|
NameBindingKind::Res(res, _) => res,
|
|
|
|
|
NameBindingKind::Module(module) => module.res().unwrap(),
|
|
|
|
|
NameBindingKind::Import { binding, .. } => binding.res(),
|
2012-10-16 01:04:15 +00:00
|
|
|
|
}
|
2012-05-22 17:54:12 +00:00
|
|
|
|
}
|
2012-10-15 21:56:42 +00:00
|
|
|
|
|
2018-12-29 15:15:29 +00:00
|
|
|
|
fn is_ambiguity(&self) -> bool {
|
2019-12-24 22:38:22 +00:00
|
|
|
|
self.ambiguity.is_some()
|
|
|
|
|
|| match self.kind {
|
|
|
|
|
NameBindingKind::Import { binding, .. } => binding.is_ambiguity(),
|
|
|
|
|
_ => false,
|
|
|
|
|
}
|
2016-11-27 10:27:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 16:31:49 +00:00
|
|
|
|
fn is_possibly_imported_variant(&self) -> bool {
|
|
|
|
|
match self.kind {
|
|
|
|
|
NameBindingKind::Import { binding, .. } => binding.is_possibly_imported_variant(),
|
2021-01-07 12:23:25 +00:00
|
|
|
|
NameBindingKind::Res(
|
2020-04-17 00:38:52 +00:00
|
|
|
|
Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Variant, ..), _),
|
|
|
|
|
_,
|
2021-01-06 15:07:47 +00:00
|
|
|
|
) => true,
|
|
|
|
|
NameBindingKind::Res(..) | NameBindingKind::Module(..) => false,
|
|
|
|
|
}
|
2015-11-16 02:10:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-29 22:21:36 +00:00
|
|
|
|
fn is_extern_crate(&self) -> bool {
|
2016-10-28 03:40:58 +00:00
|
|
|
|
match self.kind {
|
|
|
|
|
NameBindingKind::Import {
|
2020-03-07 16:02:32 +00:00
|
|
|
|
import: &Import { kind: ImportKind::ExternCrate { .. }, .. },
|
2019-12-24 22:38:22 +00:00
|
|
|
|
..
|
2016-10-28 03:40:58 +00:00
|
|
|
|
} => true,
|
2019-12-24 22:38:22 +00:00
|
|
|
|
NameBindingKind::Module(&ModuleData {
|
|
|
|
|
kind: ModuleKind::Def(DefKind::Mod, def_id, _),
|
|
|
|
|
..
|
2022-04-15 17:27:53 +00:00
|
|
|
|
}) => def_id.is_crate_root(),
|
2016-10-28 03:40:58 +00:00
|
|
|
|
_ => false,
|
|
|
|
|
}
|
2016-01-29 22:21:36 +00:00
|
|
|
|
}
|
2016-02-07 21:34:23 +00:00
|
|
|
|
|
|
|
|
|
fn is_import(&self) -> bool {
|
2020-10-27 01:02:48 +00:00
|
|
|
|
matches!(self.kind, NameBindingKind::Import { .. })
|
2016-02-07 21:34:23 +00:00
|
|
|
|
}
|
2016-04-17 01:57:09 +00:00
|
|
|
|
|
|
|
|
|
fn is_glob_import(&self) -> bool {
|
|
|
|
|
match self.kind {
|
2020-03-07 16:02:32 +00:00
|
|
|
|
NameBindingKind::Import { import, .. } => import.is_glob(),
|
2016-04-17 01:57:09 +00:00
|
|
|
|
_ => false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_importable(&self) -> bool {
|
2020-10-27 01:02:48 +00:00
|
|
|
|
!matches!(
|
|
|
|
|
self.res(),
|
|
|
|
|
Res::Def(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, _)
|
|
|
|
|
)
|
2016-04-17 01:57:09 +00:00
|
|
|
|
}
|
2017-03-18 01:55:51 +00:00
|
|
|
|
|
2018-09-03 22:14:58 +00:00
|
|
|
|
fn macro_kind(&self) -> Option<MacroKind> {
|
2019-07-11 23:29:28 +00:00
|
|
|
|
self.res().macro_kind()
|
2018-09-03 22:14:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-02 01:57:56 +00:00
|
|
|
|
// Suppose that we resolved macro invocation with `invoc_parent_expansion` to binding `binding`
|
|
|
|
|
// at some expansion round `max(invoc, binding)` when they both emerged from macros.
|
2018-08-28 01:07:31 +00:00
|
|
|
|
// Then this function returns `true` if `self` may emerge from a macro *after* that
|
|
|
|
|
// in some later round and screw up our previously found resolution.
|
2018-09-07 23:50:57 +00:00
|
|
|
|
// See more detailed explanation in
|
|
|
|
|
// https://github.com/rust-lang/rust/pull/53778#issuecomment-419224049
|
2021-06-25 18:43:04 +00:00
|
|
|
|
fn may_appear_after(
|
|
|
|
|
&self,
|
|
|
|
|
invoc_parent_expansion: LocalExpnId,
|
|
|
|
|
binding: &NameBinding<'_>,
|
|
|
|
|
) -> bool {
|
2018-09-02 01:57:56 +00:00
|
|
|
|
// self > max(invoc, binding) => !(self <= invoc || self <= binding)
|
2018-08-29 00:23:28 +00:00
|
|
|
|
// Expansions are partially ordered, so "may appear after" is an inversion of
|
|
|
|
|
// "certainly appears before or simultaneously" and includes unordered cases.
|
|
|
|
|
let self_parent_expansion = self.expansion;
|
|
|
|
|
let other_parent_expansion = binding.expansion;
|
|
|
|
|
let certainly_before_other_or_simultaneously =
|
|
|
|
|
other_parent_expansion.is_descendant_of(self_parent_expansion);
|
|
|
|
|
let certainly_before_invoc_or_simultaneously =
|
|
|
|
|
invoc_parent_expansion.is_descendant_of(self_parent_expansion);
|
|
|
|
|
!(certainly_before_other_or_simultaneously || certainly_before_invoc_or_simultaneously)
|
2018-08-28 01:07:31 +00:00
|
|
|
|
}
|
2012-08-18 00:55:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-09 19:11:00 +00:00
|
|
|
|
#[derive(Debug, Default, Clone)]
|
2018-09-28 22:31:54 +00:00
|
|
|
|
pub struct ExternPreludeEntry<'a> {
|
|
|
|
|
extern_crate_item: Option<&'a NameBinding<'a>>,
|
|
|
|
|
pub introduced_by_item: bool,
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 04:04:01 +00:00
|
|
|
|
/// Used for better errors for E0773
|
|
|
|
|
enum BuiltinMacroState {
|
2021-01-10 11:36:30 +00:00
|
|
|
|
NotYetSeen(SyntaxExtensionKind),
|
2020-08-31 04:04:01 +00:00
|
|
|
|
AlreadySeen(Span),
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 12:05:03 +00:00
|
|
|
|
struct DeriveData {
|
|
|
|
|
resolutions: DeriveResolutions,
|
2021-04-04 14:51:31 +00:00
|
|
|
|
helper_attrs: Vec<(usize, Ident)>,
|
2021-03-08 12:05:03 +00:00
|
|
|
|
has_derive_copy: bool,
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-04 21:53:12 +00:00
|
|
|
|
/// The main resolver class.
|
2018-02-18 17:01:33 +00:00
|
|
|
|
///
|
|
|
|
|
/// This is the visitor that walks the whole crate.
|
2018-12-10 04:37:10 +00:00
|
|
|
|
pub struct Resolver<'a> {
|
2014-03-05 14:36:01 +00:00
|
|
|
|
session: &'a Session,
|
2012-05-22 17:54:12 +00:00
|
|
|
|
|
2019-10-19 23:55:39 +00:00
|
|
|
|
definitions: Definitions,
|
2014-11-23 09:29:41 +00:00
|
|
|
|
|
2019-10-19 23:55:39 +00:00
|
|
|
|
graph_root: Module<'a>,
|
2012-05-22 17:54:12 +00:00
|
|
|
|
|
2016-06-05 09:56:05 +00:00
|
|
|
|
prelude: Option<Module<'a>>,
|
2019-10-19 23:55:39 +00:00
|
|
|
|
extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'a>>,
|
2016-06-05 09:56:05 +00:00
|
|
|
|
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// N.B., this is used only for better diagnostics, not name resolution itself.
|
2017-03-18 02:10:13 +00:00
|
|
|
|
has_self: FxHashSet<DefId>,
|
2014-05-06 23:37:32 +00:00
|
|
|
|
|
2018-04-14 01:05:01 +00:00
|
|
|
|
/// Names of fields of an item `DefId` accessible with dot syntax.
|
|
|
|
|
/// Used for hints during error reporting.
|
2020-04-19 11:00:18 +00:00
|
|
|
|
field_names: FxHashMap<DefId, Vec<Spanned<Symbol>>>,
|
2012-07-11 22:00:40 +00:00
|
|
|
|
|
2018-04-14 01:05:01 +00:00
|
|
|
|
/// All imports known to succeed or fail.
|
2020-03-07 15:49:13 +00:00
|
|
|
|
determined_imports: Vec<&'a Import<'a>>,
|
2016-08-15 08:19:09 +00:00
|
|
|
|
|
2018-04-14 01:05:01 +00:00
|
|
|
|
/// All non-determined imports.
|
2020-03-07 15:49:13 +00:00
|
|
|
|
indeterminate_imports: Vec<&'a Import<'a>>,
|
2012-05-22 17:54:12 +00:00
|
|
|
|
|
2021-10-21 13:09:24 +00:00
|
|
|
|
// Spans for local variables found during pattern resolution.
|
|
|
|
|
// Used for suggestions during error reporting.
|
|
|
|
|
pat_span_map: NodeMap<Span>,
|
|
|
|
|
|
2019-05-04 12:18:58 +00:00
|
|
|
|
/// Resolutions for nodes that have a single resolution.
|
|
|
|
|
partial_res_map: NodeMap<PartialRes>,
|
|
|
|
|
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
|
|
|
|
|
import_res_map: NodeMap<PerNS<Option<Res>>>,
|
2019-05-04 14:22:00 +00:00
|
|
|
|
/// Resolutions for labels (node IDs of their corresponding blocks or loops).
|
|
|
|
|
label_res_map: NodeMap<NodeId>,
|
2022-04-07 18:54:13 +00:00
|
|
|
|
/// Resolutions for lifetimes.
|
|
|
|
|
lifetimes_res_map: NodeMap<LifetimeRes>,
|
2022-04-24 13:49:00 +00:00
|
|
|
|
/// Lifetime parameters that lowering will have to introduce.
|
|
|
|
|
extra_lifetime_params_map: NodeMap<Vec<(Ident, NodeId, LifetimeRes)>>,
|
2019-05-04 12:18:58 +00:00
|
|
|
|
|
2019-10-13 22:08:13 +00:00
|
|
|
|
/// `CrateNum` resolutions of `extern crate` items.
|
2020-05-24 11:18:22 +00:00
|
|
|
|
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
|
2021-12-21 03:24:43 +00:00
|
|
|
|
reexport_map: FxHashMap<LocalDefId, Vec<ModChild>>,
|
2021-07-16 12:42:26 +00:00
|
|
|
|
trait_map: NodeMap<Vec<TraitCandidate>>,
|
2013-04-30 05:15:17 +00:00
|
|
|
|
|
2018-04-14 01:05:01 +00:00
|
|
|
|
/// A map from nodes to anonymous modules.
|
|
|
|
|
/// Anonymous modules are pseudo-modules that are implicitly created around items
|
|
|
|
|
/// contained within blocks.
|
|
|
|
|
///
|
|
|
|
|
/// For example, if we have this:
|
|
|
|
|
///
|
|
|
|
|
/// fn f() {
|
|
|
|
|
/// fn g() {
|
|
|
|
|
/// ...
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// There will be an anonymous module created around `g` with the ID of the
|
|
|
|
|
/// entry block for `f`.
|
2016-12-20 08:32:15 +00:00
|
|
|
|
block_map: NodeMap<Module<'a>>,
|
2019-08-25 19:58:03 +00:00
|
|
|
|
/// A fake module that contains no definition and no prelude. Used so that
|
|
|
|
|
/// some AST passes can generate identifiers that only resolve to local or
|
|
|
|
|
/// language items.
|
|
|
|
|
empty_module: Module<'a>,
|
2021-09-11 22:59:05 +00:00
|
|
|
|
module_map: FxHashMap<DefId, Module<'a>>,
|
2022-02-04 03:26:29 +00:00
|
|
|
|
binding_parent_modules: FxHashMap<Interned<'a, NameBinding<'a>>, Module<'a>>,
|
2019-09-09 20:04:26 +00:00
|
|
|
|
underscore_disambiguator: u32,
|
2016-04-17 20:41:57 +00:00
|
|
|
|
|
2019-01-06 00:22:52 +00:00
|
|
|
|
/// Maps glob imports to the names of items actually imported.
|
2020-05-24 11:18:22 +00:00
|
|
|
|
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
|
2020-10-16 23:28:11 +00:00
|
|
|
|
/// Visibilities in "lowered" form, for all entities that have them.
|
|
|
|
|
visibilities: FxHashMap<LocalDefId, ty::Visibility>,
|
2022-04-18 13:35:40 +00:00
|
|
|
|
has_pub_restricted: bool,
|
2021-08-22 14:50:59 +00:00
|
|
|
|
used_imports: FxHashSet<NodeId>,
|
2020-05-24 11:18:22 +00:00
|
|
|
|
maybe_unused_trait_imports: FxHashSet<LocalDefId>,
|
|
|
|
|
maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
|
2015-05-14 11:40:16 +00:00
|
|
|
|
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Privacy errors are delayed until the end in order to deduplicate them.
|
2016-02-25 04:40:46 +00:00
|
|
|
|
privacy_errors: Vec<PrivacyError<'a>>,
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Ambiguity errors are delayed for deduplication.
|
2016-09-06 03:47:11 +00:00
|
|
|
|
ambiguity_errors: Vec<AmbiguityError<'a>>,
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// `use` injections are delayed for better placement and deduplication.
|
2017-08-17 09:03:59 +00:00
|
|
|
|
use_injections: Vec<UseError<'a>>,
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Crate-local macro expanded `macro_export` referred to by a module-relative path.
|
2018-08-11 11:33:43 +00:00
|
|
|
|
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>,
|
2016-01-11 21:19:29 +00:00
|
|
|
|
|
|
|
|
|
arenas: &'a ResolverArenas<'a>,
|
2016-08-22 04:05:49 +00:00
|
|
|
|
dummy_binding: &'a NameBinding<'a>,
|
2016-09-05 03:46:05 +00:00
|
|
|
|
|
2019-10-20 00:28:36 +00:00
|
|
|
|
crate_loader: CrateLoader<'a>,
|
2017-03-22 08:39:51 +00:00
|
|
|
|
macro_names: FxHashSet<Ident>,
|
2020-08-31 04:04:01 +00:00
|
|
|
|
builtin_macros: FxHashMap<Symbol, BuiltinMacroState>,
|
2021-12-11 11:52:23 +00:00
|
|
|
|
/// A small map keeping true kinds of built-in macros that appear to be fn-like on
|
|
|
|
|
/// the surface (`macro` items in libcore), but are actually attributes or derives.
|
|
|
|
|
builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
|
2019-11-03 17:28:20 +00:00
|
|
|
|
registered_attrs: FxHashSet<Ident>,
|
2021-09-28 22:17:54 +00:00
|
|
|
|
registered_tools: RegisteredTools,
|
2020-04-19 11:00:18 +00:00
|
|
|
|
macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>,
|
2022-04-05 20:46:44 +00:00
|
|
|
|
/// FIXME: The only user of this is a doc link resolution hack for rustdoc.
|
|
|
|
|
all_macro_rules: FxHashMap<Symbol, Res>,
|
2018-02-27 16:11:14 +00:00
|
|
|
|
macro_map: FxHashMap<DefId, Lrc<SyntaxExtension>>,
|
2019-07-02 22:44:04 +00:00
|
|
|
|
dummy_ext_bang: Lrc<SyntaxExtension>,
|
|
|
|
|
dummy_ext_derive: Lrc<SyntaxExtension>,
|
2021-08-05 22:58:59 +00:00
|
|
|
|
non_macro_attr: Lrc<SyntaxExtension>,
|
2020-05-24 11:18:22 +00:00
|
|
|
|
local_macro_def_scopes: FxHashMap<LocalDefId, Module<'a>>,
|
2021-06-25 18:43:04 +00:00
|
|
|
|
ast_transform_scopes: FxHashMap<LocalExpnId, Module<'a>>,
|
2021-11-10 11:00:46 +00:00
|
|
|
|
unused_macros: FxHashMap<LocalDefId, (NodeId, Ident)>,
|
2020-05-24 22:39:39 +00:00
|
|
|
|
proc_macro_stubs: FxHashSet<LocalDefId>,
|
2019-08-12 18:52:37 +00:00
|
|
|
|
/// Traces collected during macro resolution and validated when it's complete.
|
2019-12-24 22:38:22 +00:00
|
|
|
|
single_segment_macro_resolutions:
|
|
|
|
|
Vec<(Ident, MacroKind, ParentScope<'a>, Option<&'a NameBinding<'a>>)>,
|
|
|
|
|
multi_segment_macro_resolutions:
|
|
|
|
|
Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'a>, Option<Res>)>,
|
2019-08-12 18:52:37 +00:00
|
|
|
|
builtin_attrs: Vec<(Ident, ParentScope<'a>)>,
|
2019-10-30 10:13:00 +00:00
|
|
|
|
/// `derive(Copy)` marks items they are applied to so they are treated specially later.
|
2019-08-03 01:22:44 +00:00
|
|
|
|
/// Derive macros cannot modify the item themselves and have to store the markers in the global
|
|
|
|
|
/// context, so they attach the markers to derive container IDs using this resolver table.
|
2021-06-25 18:43:04 +00:00
|
|
|
|
containers_deriving_copy: FxHashSet<LocalExpnId>,
|
2019-08-12 20:39:49 +00:00
|
|
|
|
/// Parent scopes in which the macros were invoked.
|
|
|
|
|
/// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere.
|
2021-06-25 18:43:04 +00:00
|
|
|
|
invocation_parent_scopes: FxHashMap<LocalExpnId, ParentScope<'a>>,
|
2020-03-13 22:06:36 +00:00
|
|
|
|
/// `macro_rules` scopes *produced* by expanding the macro invocations,
|
2019-08-12 20:39:49 +00:00
|
|
|
|
/// include all the `macro_rules` items and other invocations generated by them.
|
2021-06-25 18:43:04 +00:00
|
|
|
|
output_macro_rules_scopes: FxHashMap<LocalExpnId, MacroRulesScopeRef<'a>>,
|
2019-10-03 22:53:20 +00:00
|
|
|
|
/// Helper attributes that are in scope for the given expansion.
|
2021-06-25 18:43:04 +00:00
|
|
|
|
helper_attrs: FxHashMap<LocalExpnId, Vec<Ident>>,
|
2021-03-08 12:05:03 +00:00
|
|
|
|
/// Ready or in-progress results of resolving paths inside the `#[derive(...)]` attribute
|
|
|
|
|
/// with the given `ExpnId`.
|
2021-06-25 18:43:04 +00:00
|
|
|
|
derive_data: FxHashMap<LocalExpnId, DeriveData>,
|
2016-10-28 07:30:23 +00:00
|
|
|
|
|
2018-04-14 01:05:01 +00:00
|
|
|
|
/// Avoid duplicated errors for "name already defined".
|
2020-04-19 11:00:18 +00:00
|
|
|
|
name_already_seen: FxHashMap<Symbol, Span>,
|
2017-01-09 09:31:14 +00:00
|
|
|
|
|
2020-03-07 15:49:13 +00:00
|
|
|
|
potentially_unused_imports: Vec<&'a Import<'a>>,
|
2017-01-20 15:53:49 +00:00
|
|
|
|
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Table for mapping struct IDs into struct constructor IDs,
|
2018-04-14 01:05:01 +00:00
|
|
|
|
/// it's not used during normal resolution, only for better error reporting.
|
2020-09-08 22:14:09 +00:00
|
|
|
|
/// Also includes of list of each fields visibility
|
|
|
|
|
struct_constructors: DefIdMap<(Res, ty::Visibility, Vec<ty::Visibility>)>,
|
2017-07-18 18:41:21 +00:00
|
|
|
|
|
2019-06-22 13:18:05 +00:00
|
|
|
|
/// Features enabled for this crate.
|
2020-04-19 11:00:18 +00:00
|
|
|
|
active_features: FxHashSet<Symbol>,
|
2019-09-09 12:26:25 +00:00
|
|
|
|
|
2020-01-05 08:40:16 +00:00
|
|
|
|
lint_buffer: LintBuffer,
|
2019-11-03 22:38:02 +00:00
|
|
|
|
|
|
|
|
|
next_node_id: NodeId,
|
2020-06-20 18:59:29 +00:00
|
|
|
|
|
|
|
|
|
node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
|
|
|
|
|
def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
|
|
|
|
|
|
|
|
|
|
/// Indices of unnamed struct or variant fields with unresolved attributes.
|
|
|
|
|
placeholder_field_indices: FxHashMap<NodeId, usize>,
|
|
|
|
|
/// When collecting definitions from an AST fragment produced by a macro invocation `ExpnId`
|
2021-02-13 19:41:02 +00:00
|
|
|
|
/// we know what parent node that fragment should be attached to thanks to this table,
|
|
|
|
|
/// and how the `impl Trait` fragments were introduced.
|
2021-06-25 18:43:04 +00:00
|
|
|
|
invocation_parents: FxHashMap<LocalExpnId, (LocalDefId, ImplTraitContext)>,
|
2020-06-21 22:49:06 +00:00
|
|
|
|
|
2020-10-16 23:28:11 +00:00
|
|
|
|
/// Some way to know that we are in a *trait* impl in `visit_assoc_item`.
|
|
|
|
|
/// FIXME: Replace with a more general AST map (together with some other fields).
|
|
|
|
|
trait_impl_items: FxHashSet<LocalDefId>,
|
2021-02-25 00:37:56 +00:00
|
|
|
|
|
|
|
|
|
legacy_const_generic_args: FxHashMap<DefId, Option<Vec<usize>>>,
|
2021-07-14 16:04:56 +00:00
|
|
|
|
/// Amount of lifetime parameters for each item in the crate.
|
|
|
|
|
item_generics_num_lifetimes: FxHashMap<LocalDefId, usize>,
|
2021-04-25 17:09:35 +00:00
|
|
|
|
|
|
|
|
|
main_def: Option<MainDefinition>,
|
2022-01-25 23:40:10 +00:00
|
|
|
|
trait_impls: FxIndexMap<DefId, Vec<LocalDefId>>,
|
2021-07-16 20:22:08 +00:00
|
|
|
|
/// A list of proc macro LocalDefIds, written out in the order in which
|
|
|
|
|
/// they are declared in the static array generated by proc_macro_harness.
|
|
|
|
|
proc_macros: Vec<NodeId>,
|
2021-09-06 16:20:59 +00:00
|
|
|
|
confused_type_with_std_module: FxHashMap<Span, Span>,
|
2021-07-26 03:38:16 +00:00
|
|
|
|
|
|
|
|
|
access_levels: AccessLevels,
|
2016-01-11 21:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 13:53:55 +00:00
|
|
|
|
/// Nothing really interesting here; it just provides memory for the rest of the crate.
|
2018-10-16 14:57:53 +00:00
|
|
|
|
#[derive(Default)]
|
2016-06-22 01:54:34 +00:00
|
|
|
|
pub struct ResolverArenas<'a> {
|
2020-06-02 17:19:49 +00:00
|
|
|
|
modules: TypedArena<ModuleData<'a>>,
|
2016-04-17 20:23:10 +00:00
|
|
|
|
local_modules: RefCell<Vec<Module<'a>>>,
|
2020-06-02 17:19:49 +00:00
|
|
|
|
imports: TypedArena<Import<'a>>,
|
|
|
|
|
name_resolutions: TypedArena<RefCell<NameResolution<'a>>>,
|
|
|
|
|
ast_paths: TypedArena<ast::Path>,
|
2020-10-20 08:37:56 +00:00
|
|
|
|
dropless: DroplessArena,
|
2016-02-15 02:22:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> ResolverArenas<'a> {
|
2021-09-11 13:37:34 +00:00
|
|
|
|
fn new_module(
|
|
|
|
|
&'a self,
|
|
|
|
|
parent: Option<Module<'a>>,
|
|
|
|
|
kind: ModuleKind,
|
|
|
|
|
expn_id: ExpnId,
|
|
|
|
|
span: Span,
|
|
|
|
|
no_implicit_prelude: bool,
|
2021-09-24 23:27:00 +00:00
|
|
|
|
module_map: &mut FxHashMap<DefId, Module<'a>>,
|
2021-09-11 13:37:34 +00:00
|
|
|
|
) -> Module<'a> {
|
|
|
|
|
let module =
|
|
|
|
|
self.modules.alloc(ModuleData::new(parent, kind, expn_id, span, no_implicit_prelude));
|
2021-09-26 16:29:53 +00:00
|
|
|
|
let def_id = module.opt_def_id();
|
2021-09-24 23:27:00 +00:00
|
|
|
|
if def_id.map_or(true, |def_id| def_id.is_local()) {
|
2016-04-17 20:23:10 +00:00
|
|
|
|
self.local_modules.borrow_mut().push(module);
|
|
|
|
|
}
|
2021-09-24 23:27:00 +00:00
|
|
|
|
if let Some(def_id) = def_id {
|
|
|
|
|
module_map.insert(def_id, module);
|
|
|
|
|
}
|
2016-04-17 20:23:10 +00:00
|
|
|
|
module
|
|
|
|
|
}
|
2019-02-06 17:15:23 +00:00
|
|
|
|
fn local_modules(&'a self) -> std::cell::Ref<'a, Vec<Module<'a>>> {
|
2016-04-17 20:23:10 +00:00
|
|
|
|
self.local_modules.borrow()
|
2016-02-15 05:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
fn alloc_name_binding(&'a self, name_binding: NameBinding<'a>) -> &'a NameBinding<'a> {
|
2020-10-20 08:37:56 +00:00
|
|
|
|
self.dropless.alloc(name_binding)
|
2016-02-15 05:18:55 +00:00
|
|
|
|
}
|
2020-03-07 16:02:32 +00:00
|
|
|
|
fn alloc_import(&'a self, import: Import<'a>) -> &'a Import<'_> {
|
|
|
|
|
self.imports.alloc(import)
|
2016-02-15 02:22:59 +00:00
|
|
|
|
}
|
2016-03-30 22:21:56 +00:00
|
|
|
|
fn alloc_name_resolution(&'a self) -> &'a RefCell<NameResolution<'a>> {
|
|
|
|
|
self.name_resolutions.alloc(Default::default())
|
|
|
|
|
}
|
2020-11-06 13:11:21 +00:00
|
|
|
|
fn alloc_macro_rules_scope(&'a self, scope: MacroRulesScope<'a>) -> MacroRulesScopeRef<'a> {
|
2022-02-04 03:26:29 +00:00
|
|
|
|
Interned::new_unchecked(self.dropless.alloc(Cell::new(scope)))
|
2020-11-06 13:11:21 +00:00
|
|
|
|
}
|
2020-03-13 22:06:36 +00:00
|
|
|
|
fn alloc_macro_rules_binding(
|
|
|
|
|
&'a self,
|
|
|
|
|
binding: MacroRulesBinding<'a>,
|
|
|
|
|
) -> &'a MacroRulesBinding<'a> {
|
2020-10-20 08:37:56 +00:00
|
|
|
|
self.dropless.alloc(binding)
|
2016-10-06 08:04:30 +00:00
|
|
|
|
}
|
2019-08-12 22:39:10 +00:00
|
|
|
|
fn alloc_ast_paths(&'a self, paths: &[ast::Path]) -> &'a [ast::Path] {
|
|
|
|
|
self.ast_paths.alloc_from_iter(paths.iter().cloned())
|
|
|
|
|
}
|
2020-09-08 22:14:09 +00:00
|
|
|
|
fn alloc_pattern_spans(&'a self, spans: impl Iterator<Item = Span>) -> &'a [Span] {
|
2020-10-20 08:37:56 +00:00
|
|
|
|
self.dropless.alloc_from_iter(spans)
|
2020-09-08 22:14:09 +00:00
|
|
|
|
}
|
2012-09-08 02:04:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 18:19:50 +00:00
|
|
|
|
impl<'a> AsMut<Resolver<'a>> for Resolver<'a> {
|
2019-12-24 22:38:22 +00:00
|
|
|
|
fn as_mut(&mut self) -> &mut Resolver<'a> {
|
|
|
|
|
self
|
|
|
|
|
}
|
2019-07-29 18:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 14:37:48 +00:00
|
|
|
|
impl<'a, 'b> DefIdTree for &'a Resolver<'b> {
|
2016-12-20 08:32:15 +00:00
|
|
|
|
fn parent(self, id: DefId) -> Option<DefId> {
|
2019-11-03 12:36:59 +00:00
|
|
|
|
match id.as_local() {
|
|
|
|
|
Some(id) => self.definitions.def_key(id).parent,
|
|
|
|
|
None => self.cstore().def_key(id).parent,
|
2019-12-24 22:38:22 +00:00
|
|
|
|
}
|
|
|
|
|
.map(|index| DefId { index, ..id })
|
2016-04-27 02:29:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-24 16:07:58 +00:00
|
|
|
|
/// This interface is used through the AST→HIR step, to embed full paths into the HIR. After that
|
|
|
|
|
/// the resolver is no longer needed as all the relevant information is inline.
|
2020-06-20 18:59:29 +00:00
|
|
|
|
impl ResolverAstLowering for Resolver<'_> {
|
2021-04-01 17:05:14 +00:00
|
|
|
|
fn def_key(&self, id: DefId) -> DefKey {
|
2019-11-03 12:36:59 +00:00
|
|
|
|
if let Some(id) = id.as_local() {
|
2021-04-01 17:05:14 +00:00
|
|
|
|
self.definitions.def_key(id)
|
2019-11-03 12:36:59 +00:00
|
|
|
|
} else {
|
|
|
|
|
self.cstore().def_key(id)
|
|
|
|
|
}
|
2020-01-06 06:34:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 12:27:28 +00:00
|
|
|
|
#[inline]
|
|
|
|
|
fn def_span(&self, id: LocalDefId) -> Span {
|
|
|
|
|
self.definitions.def_span(id)
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-14 16:04:56 +00:00
|
|
|
|
fn item_generics_num_lifetimes(&self, def_id: DefId) -> usize {
|
|
|
|
|
if let Some(def_id) = def_id.as_local() {
|
|
|
|
|
self.item_generics_num_lifetimes[&def_id]
|
|
|
|
|
} else {
|
|
|
|
|
self.cstore().item_generics_num_lifetimes(def_id, self.session)
|
|
|
|
|
}
|
2019-10-20 00:28:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 00:37:56 +00:00
|
|
|
|
fn legacy_const_generic_args(&mut self, expr: &Expr) -> Option<Vec<usize>> {
|
2021-02-25 00:09:33 +00:00
|
|
|
|
self.legacy_const_generic_args(expr)
|
2021-02-23 15:12:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 21:15:28 +00:00
|
|
|
|
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
|
2019-05-04 12:18:58 +00:00
|
|
|
|
self.partial_res_map.get(&id).cloned()
|
2018-01-01 07:31:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 17:05:14 +00:00
|
|
|
|
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res>> {
|
2019-05-04 12:18:58 +00:00
|
|
|
|
self.import_res_map.get(&id).cloned().unwrap_or_default()
|
2018-01-01 07:31:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 17:05:14 +00:00
|
|
|
|
fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
|
2019-05-04 14:22:00 +00:00
|
|
|
|
self.label_res_map.get(&id).cloned()
|
2018-06-13 16:44:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-07 18:54:13 +00:00
|
|
|
|
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
|
|
|
|
|
self.lifetimes_res_map.get(&id).copied()
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-24 13:49:00 +00:00
|
|
|
|
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)> {
|
|
|
|
|
self.extra_lifetime_params_map.remove(&id).unwrap_or_default()
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-19 20:17:50 +00:00
|
|
|
|
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
|
|
|
|
StableHashingContext::new(self.session, &self.definitions, self.crate_loader.cstore())
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 17:05:14 +00:00
|
|
|
|
fn definitions(&self) -> &Definitions {
|
|
|
|
|
&self.definitions
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-03 22:38:02 +00:00
|
|
|
|
fn next_node_id(&mut self) -> NodeId {
|
|
|
|
|
self.next_node_id()
|
|
|
|
|
}
|
2020-06-12 17:13:10 +00:00
|
|
|
|
|
2021-07-16 12:42:26 +00:00
|
|
|
|
fn take_trait_map(&mut self, node: NodeId) -> Option<Vec<TraitCandidate>> {
|
|
|
|
|
self.trait_map.remove(&node)
|
2020-06-12 17:13:10 +00:00
|
|
|
|
}
|
2020-06-20 18:59:29 +00:00
|
|
|
|
|
|
|
|
|
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
|
|
|
|
|
self.node_id_to_def_id.get(&node).copied()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn local_def_id(&self, node: NodeId) -> LocalDefId {
|
|
|
|
|
self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{:?}`", node))
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 17:20:25 +00:00
|
|
|
|
fn def_path_hash(&self, def_id: DefId) -> DefPathHash {
|
|
|
|
|
match def_id.as_local() {
|
|
|
|
|
Some(def_id) => self.definitions.def_path_hash(def_id),
|
|
|
|
|
None => self.cstore().def_path_hash(def_id),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-20 18:59:29 +00:00
|
|
|
|
/// Adds a definition with a parent definition.
|
2020-06-21 14:49:38 +00:00
|
|
|
|
fn create_def(
|
2020-06-20 18:59:29 +00:00
|
|
|
|
&mut self,
|
|
|
|
|
parent: LocalDefId,
|
|
|
|
|
node_id: ast::NodeId,
|
|
|
|
|
data: DefPathData,
|
|
|
|
|
expn_id: ExpnId,
|
|
|
|
|
span: Span,
|
|
|
|
|
) -> LocalDefId {
|
|
|
|
|
assert!(
|
|
|
|
|
!self.node_id_to_def_id.contains_key(&node_id),
|
|
|
|
|
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
|
|
|
|
|
node_id,
|
|
|
|
|
data,
|
|
|
|
|
self.definitions.def_key(self.node_id_to_def_id[&node_id]),
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-02 14:47:08 +00:00
|
|
|
|
let def_id = self.definitions.create_def(parent, data, expn_id, span);
|
2020-06-20 18:59:29 +00:00
|
|
|
|
|
|
|
|
|
// Some things for which we allocate `LocalDefId`s don't correspond to
|
|
|
|
|
// anything in the AST, so they don't have a `NodeId`. For these cases
|
|
|
|
|
// we don't need a mapping from `NodeId` to `LocalDefId`.
|
|
|
|
|
if node_id != ast::DUMMY_NODE_ID {
|
2020-06-21 14:49:38 +00:00
|
|
|
|
debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
|
2020-06-20 18:59:29 +00:00
|
|
|
|
self.node_id_to_def_id.insert(node_id, def_id);
|
|
|
|
|
}
|
|
|
|
|
assert_eq!(self.def_id_to_node_id.push(node_id), def_id);
|
|
|
|
|
|
|
|
|
|
def_id
|
|
|
|
|
}
|
2021-12-11 11:52:23 +00:00
|
|
|
|
|
|
|
|
|
fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind {
|
|
|
|
|
self.builtin_macro_kinds.get(&def_id).copied().unwrap_or(MacroKind::Bang)
|
|
|
|
|
}
|
2018-01-01 07:31:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-10 04:37:10 +00:00
|
|
|
|
impl<'a> Resolver<'a> {
|
2019-12-24 22:38:22 +00:00
|
|
|
|
pub fn new(
|
|
|
|
|
session: &'a Session,
|
|
|
|
|
krate: &Crate,
|
|
|
|
|
crate_name: &str,
|
2021-05-31 15:36:53 +00:00
|
|
|
|
metadata_loader: Box<MetadataLoaderDyn>,
|
2019-12-24 22:38:22 +00:00
|
|
|
|
arenas: &'a ResolverArenas<'a>,
|
|
|
|
|
) -> Resolver<'a> {
|
2021-09-11 13:37:34 +00:00
|
|
|
|
let root_def_id = CRATE_DEF_ID.to_def_id();
|
2021-09-24 23:27:00 +00:00
|
|
|
|
let mut module_map = FxHashMap::default();
|
2021-09-11 13:37:34 +00:00
|
|
|
|
let graph_root = arenas.new_module(
|
|
|
|
|
None,
|
|
|
|
|
ModuleKind::Def(DefKind::Mod, root_def_id, kw::Empty),
|
|
|
|
|
ExpnId::root(),
|
2022-03-03 23:45:25 +00:00
|
|
|
|
krate.spans.inner_span,
|
2021-09-11 13:37:34 +00:00
|
|
|
|
session.contains_name(&krate.attrs, sym::no_implicit_prelude),
|
2021-09-24 23:27:00 +00:00
|
|
|
|
&mut module_map,
|
2021-09-11 13:37:34 +00:00
|
|
|
|
);
|
|
|
|
|
let empty_module = arenas.new_module(
|
|
|
|
|
None,
|
|
|
|
|
ModuleKind::Def(DefKind::Mod, root_def_id, kw::Empty),
|
|
|
|
|
ExpnId::root(),
|
|
|
|
|
DUMMY_SP,
|
|
|
|
|
true,
|
2021-09-24 23:27:00 +00:00
|
|
|
|
&mut FxHashMap::default(),
|
2021-09-11 13:37:34 +00:00
|
|
|
|
);
|
2014-05-28 19:36:05 +00:00
|
|
|
|
|
2022-03-03 23:45:25 +00:00
|
|
|
|
let definitions = Definitions::new(session.local_stable_crate_id(), krate.spans.inner_span);
|
2020-06-20 18:59:29 +00:00
|
|
|
|
|
2020-10-16 23:28:11 +00:00
|
|
|
|
let mut visibilities = FxHashMap::default();
|
2021-09-11 13:37:34 +00:00
|
|
|
|
visibilities.insert(CRATE_DEF_ID, ty::Visibility::Public);
|
2020-10-16 23:28:11 +00:00
|
|
|
|
|
2020-06-20 18:59:29 +00:00
|
|
|
|
let mut def_id_to_node_id = IndexVec::default();
|
2022-04-15 17:27:53 +00:00
|
|
|
|
assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), CRATE_DEF_ID);
|
2020-06-20 18:59:29 +00:00
|
|
|
|
let mut node_id_to_def_id = FxHashMap::default();
|
2022-04-15 17:27:53 +00:00
|
|
|
|
node_id_to_def_id.insert(CRATE_NODE_ID, CRATE_DEF_ID);
|
2020-06-20 18:59:29 +00:00
|
|
|
|
|
|
|
|
|
let mut invocation_parents = FxHashMap::default();
|
2022-04-15 17:27:53 +00:00
|
|
|
|
invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential));
|
2016-09-14 09:55:20 +00:00
|
|
|
|
|
2019-12-24 22:38:22 +00:00
|
|
|
|
let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> = session
|
|
|
|
|
.opts
|
|
|
|
|
.externs
|
|
|
|
|
.iter()
|
|
|
|
|
.filter(|(_, entry)| entry.add_prelude)
|
|
|
|
|
.map(|(name, _)| (Ident::from_str(name), Default::default()))
|
|
|
|
|
.collect();
|
2018-10-13 16:07:17 +00:00
|
|
|
|
|
2020-07-30 01:27:50 +00:00
|
|
|
|
if !session.contains_name(&krate.attrs, sym::no_core) {
|
2019-08-10 23:20:18 +00:00
|
|
|
|
extern_prelude.insert(Ident::with_dummy_span(sym::core), Default::default());
|
2020-07-30 01:27:50 +00:00
|
|
|
|
if !session.contains_name(&krate.attrs, sym::no_std) {
|
2019-08-10 23:20:18 +00:00
|
|
|
|
extern_prelude.insert(Ident::with_dummy_span(sym::std), Default::default());
|
2018-10-13 18:24:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-13 16:07:17 +00:00
|
|
|
|
|
2019-11-03 17:28:20 +00:00
|
|
|
|
let (registered_attrs, registered_tools) =
|
|
|
|
|
macros::registered_attrs_and_tools(session, &krate.attrs);
|
|
|
|
|
|
2019-06-22 13:18:05 +00:00
|
|
|
|
let features = session.features_untracked();
|
2019-06-17 09:29:56 +00:00
|
|
|
|
|
2020-11-06 13:11:21 +00:00
|
|
|
|
let mut resolver = Resolver {
|
2017-08-07 05:54:09 +00:00
|
|
|
|
session,
|
2014-05-28 19:36:05 +00:00
|
|
|
|
|
2017-08-07 05:54:09 +00:00
|
|
|
|
definitions,
|
2014-11-23 09:29:41 +00:00
|
|
|
|
|
2014-05-28 19:36:05 +00:00
|
|
|
|
// The outermost module has def ID 0; this is not reflected in the
|
|
|
|
|
// AST.
|
2017-08-07 05:54:09 +00:00
|
|
|
|
graph_root,
|
2016-06-05 09:56:05 +00:00
|
|
|
|
prelude: None,
|
2018-10-13 16:07:17 +00:00
|
|
|
|
extern_prelude,
|
2014-05-28 19:36:05 +00:00
|
|
|
|
|
2018-10-16 08:44:26 +00:00
|
|
|
|
has_self: FxHashSet::default(),
|
|
|
|
|
field_names: FxHashMap::default(),
|
2014-05-28 19:36:05 +00:00
|
|
|
|
|
2016-08-15 08:19:09 +00:00
|
|
|
|
determined_imports: Vec::new(),
|
2016-08-17 00:52:18 +00:00
|
|
|
|
indeterminate_imports: Vec::new(),
|
2014-05-28 19:36:05 +00:00
|
|
|
|
|
2021-10-21 13:09:24 +00:00
|
|
|
|
pat_span_map: Default::default(),
|
2019-05-04 12:18:58 +00:00
|
|
|
|
partial_res_map: Default::default(),
|
|
|
|
|
import_res_map: Default::default(),
|
2019-05-04 14:22:00 +00:00
|
|
|
|
label_res_map: Default::default(),
|
2022-04-07 18:54:13 +00:00
|
|
|
|
lifetimes_res_map: Default::default(),
|
2022-04-24 13:49:00 +00:00
|
|
|
|
extra_lifetime_params_map: Default::default(),
|
2019-10-13 22:08:13 +00:00
|
|
|
|
extern_crate_map: Default::default(),
|
2021-12-21 03:24:43 +00:00
|
|
|
|
reexport_map: FxHashMap::default(),
|
2021-07-16 12:42:26 +00:00
|
|
|
|
trait_map: NodeMap::default(),
|
2019-09-09 20:04:26 +00:00
|
|
|
|
underscore_disambiguator: 0,
|
2019-08-25 19:58:03 +00:00
|
|
|
|
empty_module,
|
2017-08-07 05:54:09 +00:00
|
|
|
|
module_map,
|
2018-07-21 19:15:11 +00:00
|
|
|
|
block_map: Default::default(),
|
2018-10-16 08:44:26 +00:00
|
|
|
|
binding_parent_modules: FxHashMap::default(),
|
2019-08-25 19:58:03 +00:00
|
|
|
|
ast_transform_scopes: FxHashMap::default(),
|
2014-05-28 19:36:05 +00:00
|
|
|
|
|
2018-07-21 19:15:11 +00:00
|
|
|
|
glob_map: Default::default(),
|
2020-10-16 23:28:11 +00:00
|
|
|
|
visibilities,
|
2022-04-18 13:35:40 +00:00
|
|
|
|
has_pub_restricted: false,
|
2018-10-16 08:44:26 +00:00
|
|
|
|
used_imports: FxHashSet::default(),
|
2018-07-21 19:15:11 +00:00
|
|
|
|
maybe_unused_trait_imports: Default::default(),
|
2017-06-24 08:48:27 +00:00
|
|
|
|
maybe_unused_extern_crates: Vec::new(),
|
2016-04-19 13:43:10 +00:00
|
|
|
|
|
2016-02-25 04:40:46 +00:00
|
|
|
|
privacy_errors: Vec::new(),
|
2016-08-22 08:30:07 +00:00
|
|
|
|
ambiguity_errors: Vec::new(),
|
2017-08-17 09:03:59 +00:00
|
|
|
|
use_injections: Vec::new(),
|
2018-08-11 11:33:43 +00:00
|
|
|
|
macro_expanded_macro_export_errors: BTreeSet::new(),
|
2016-01-11 21:19:29 +00:00
|
|
|
|
|
2017-08-07 05:54:09 +00:00
|
|
|
|
arenas,
|
2021-10-21 13:09:24 +00:00
|
|
|
|
dummy_binding: arenas.alloc_name_binding(NameBinding {
|
|
|
|
|
kind: NameBindingKind::Res(Res::Err, false),
|
|
|
|
|
ambiguity: None,
|
|
|
|
|
expansion: LocalExpnId::ROOT,
|
|
|
|
|
span: DUMMY_SP,
|
|
|
|
|
vis: ty::Visibility::Public,
|
|
|
|
|
}),
|
2017-01-09 09:31:14 +00:00
|
|
|
|
|
2019-10-20 00:28:36 +00:00
|
|
|
|
crate_loader: CrateLoader::new(session, metadata_loader, crate_name),
|
2018-10-16 08:44:26 +00:00
|
|
|
|
macro_names: FxHashSet::default(),
|
2019-06-20 08:52:31 +00:00
|
|
|
|
builtin_macros: Default::default(),
|
2021-12-11 11:52:23 +00:00
|
|
|
|
builtin_macro_kinds: Default::default(),
|
2019-11-03 17:28:20 +00:00
|
|
|
|
registered_attrs,
|
|
|
|
|
registered_tools,
|
2018-10-16 08:44:26 +00:00
|
|
|
|
macro_use_prelude: FxHashMap::default(),
|
2022-04-05 20:46:44 +00:00
|
|
|
|
all_macro_rules: Default::default(),
|
2018-10-16 08:44:26 +00:00
|
|
|
|
macro_map: FxHashMap::default(),
|
2019-07-02 22:44:04 +00:00
|
|
|
|
dummy_ext_bang: Lrc::new(SyntaxExtension::dummy_bang(session.edition())),
|
|
|
|
|
dummy_ext_derive: Lrc::new(SyntaxExtension::dummy_derive(session.edition())),
|
2021-08-05 22:58:59 +00:00
|
|
|
|
non_macro_attr: Lrc::new(SyntaxExtension::non_macro_attr(session.edition())),
|
2020-11-06 13:11:21 +00:00
|
|
|
|
invocation_parent_scopes: Default::default(),
|
2020-03-13 22:06:36 +00:00
|
|
|
|
output_macro_rules_scopes: Default::default(),
|
2019-10-03 22:53:20 +00:00
|
|
|
|
helper_attrs: Default::default(),
|
2021-03-08 12:05:03 +00:00
|
|
|
|
derive_data: Default::default(),
|
2018-10-16 08:44:26 +00:00
|
|
|
|
local_macro_def_scopes: FxHashMap::default(),
|
|
|
|
|
name_already_seen: FxHashMap::default(),
|
2017-01-14 07:35:54 +00:00
|
|
|
|
potentially_unused_imports: Vec::new(),
|
2018-07-21 19:15:11 +00:00
|
|
|
|
struct_constructors: Default::default(),
|
2019-06-20 08:52:31 +00:00
|
|
|
|
unused_macros: Default::default(),
|
2019-07-02 22:44:04 +00:00
|
|
|
|
proc_macro_stubs: Default::default(),
|
2019-08-12 18:52:37 +00:00
|
|
|
|
single_segment_macro_resolutions: Default::default(),
|
|
|
|
|
multi_segment_macro_resolutions: Default::default(),
|
|
|
|
|
builtin_attrs: Default::default(),
|
2019-11-04 09:09:58 +00:00
|
|
|
|
containers_deriving_copy: Default::default(),
|
2019-12-24 22:38:22 +00:00
|
|
|
|
active_features: features
|
|
|
|
|
.declared_lib_features
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|(feat, ..)| *feat)
|
|
|
|
|
.chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
|
|
|
|
|
.collect(),
|
2020-01-05 08:40:16 +00:00
|
|
|
|
lint_buffer: LintBuffer::default(),
|
2022-01-05 08:09:55 +00:00
|
|
|
|
next_node_id: CRATE_NODE_ID,
|
2020-06-20 18:59:29 +00:00
|
|
|
|
node_id_to_def_id,
|
|
|
|
|
def_id_to_node_id,
|
|
|
|
|
placeholder_field_indices: Default::default(),
|
|
|
|
|
invocation_parents,
|
2020-10-16 23:28:11 +00:00
|
|
|
|
trait_impl_items: Default::default(),
|
2021-02-25 00:37:56 +00:00
|
|
|
|
legacy_const_generic_args: Default::default(),
|
2021-07-14 16:04:56 +00:00
|
|
|
|
item_generics_num_lifetimes: Default::default(),
|
2021-04-25 17:09:35 +00:00
|
|
|
|
main_def: Default::default(),
|
2021-07-16 19:55:10 +00:00
|
|
|
|
trait_impls: Default::default(),
|
2021-07-16 20:22:08 +00:00
|
|
|
|
proc_macros: Default::default(),
|
2021-09-06 16:20:59 +00:00
|
|
|
|
confused_type_with_std_module: Default::default(),
|
2021-07-26 03:38:16 +00:00
|
|
|
|
access_levels: Default::default(),
|
2020-11-06 13:11:21 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let root_parent_scope = ParentScope::module(graph_root, &resolver);
|
2021-06-25 18:43:04 +00:00
|
|
|
|
resolver.invocation_parent_scopes.insert(LocalExpnId::ROOT, root_parent_scope);
|
2020-11-06 13:11:21 +00:00
|
|
|
|
|
|
|
|
|
resolver
|
2019-11-03 22:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-24 23:27:00 +00:00
|
|
|
|
fn new_module(
|
|
|
|
|
&mut self,
|
|
|
|
|
parent: Option<Module<'a>>,
|
|
|
|
|
kind: ModuleKind,
|
|
|
|
|
expn_id: ExpnId,
|
|
|
|
|
span: Span,
|
|
|
|
|
no_implicit_prelude: bool,
|
|
|
|
|
) -> Module<'a> {
|
|
|
|
|
let module_map = &mut self.module_map;
|
|
|
|
|
self.arenas.new_module(parent, kind, expn_id, span, no_implicit_prelude, module_map)
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-03 22:38:02 +00:00
|
|
|
|
pub fn next_node_id(&mut self) -> NodeId {
|
2022-03-06 11:02:13 +00:00
|
|
|
|
let start = self.next_node_id;
|
|
|
|
|
let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
|
|
|
|
|
self.next_node_id = ast::NodeId::from_u32(next);
|
|
|
|
|
start
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn next_node_ids(&mut self, count: usize) -> std::ops::Range<NodeId> {
|
|
|
|
|
let start = self.next_node_id;
|
|
|
|
|
let end = start.as_usize().checked_add(count).expect("input too large; ran out of NodeIds");
|
|
|
|
|
self.next_node_id = ast::NodeId::from_usize(end);
|
|
|
|
|
start..self.next_node_id
|
2016-01-11 21:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-05 08:40:16 +00:00
|
|
|
|
pub fn lint_buffer(&mut self) -> &mut LintBuffer {
|
2019-10-25 17:41:51 +00:00
|
|
|
|
&mut self.lint_buffer
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-22 01:54:34 +00:00
|
|
|
|
pub fn arenas() -> ResolverArenas<'a> {
|
2018-10-16 14:57:53 +00:00
|
|
|
|
Default::default()
|
2014-05-28 19:36:05 +00:00
|
|
|
|
}
|
2012-05-22 17:54:12 +00:00
|
|
|
|
|
2019-10-20 00:19:12 +00:00
|
|
|
|
pub fn into_outputs(self) -> ResolverOutputs {
|
2021-07-16 20:22:08 +00:00
|
|
|
|
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
|
2020-05-20 20:52:30 +00:00
|
|
|
|
let definitions = self.definitions;
|
2020-10-16 23:28:11 +00:00
|
|
|
|
let visibilities = self.visibilities;
|
2022-04-18 13:35:40 +00:00
|
|
|
|
let has_pub_restricted = self.has_pub_restricted;
|
2020-05-24 11:18:22 +00:00
|
|
|
|
let extern_crate_map = self.extern_crate_map;
|
2021-12-21 03:24:43 +00:00
|
|
|
|
let reexport_map = self.reexport_map;
|
2020-05-24 11:18:22 +00:00
|
|
|
|
let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
|
|
|
|
|
let maybe_unused_extern_crates = self.maybe_unused_extern_crates;
|
|
|
|
|
let glob_map = self.glob_map;
|
2021-04-25 17:09:35 +00:00
|
|
|
|
let main_def = self.main_def;
|
2021-09-06 16:20:59 +00:00
|
|
|
|
let confused_type_with_std_module = self.confused_type_with_std_module;
|
2021-07-26 03:38:16 +00:00
|
|
|
|
let access_levels = self.access_levels;
|
2019-10-20 00:19:12 +00:00
|
|
|
|
ResolverOutputs {
|
2020-10-27 01:02:48 +00:00
|
|
|
|
definitions,
|
2019-10-20 00:28:36 +00:00
|
|
|
|
cstore: Box::new(self.crate_loader.into_cstore()),
|
2020-10-16 23:28:11 +00:00
|
|
|
|
visibilities,
|
2022-04-18 13:35:40 +00:00
|
|
|
|
has_pub_restricted,
|
2021-07-26 03:38:16 +00:00
|
|
|
|
access_levels,
|
2020-05-20 23:08:49 +00:00
|
|
|
|
extern_crate_map,
|
2021-12-21 03:24:43 +00:00
|
|
|
|
reexport_map,
|
2020-05-20 22:18:45 +00:00
|
|
|
|
glob_map,
|
2020-05-20 22:01:48 +00:00
|
|
|
|
maybe_unused_trait_imports,
|
2020-05-20 22:11:56 +00:00
|
|
|
|
maybe_unused_extern_crates,
|
2019-12-24 22:38:22 +00:00
|
|
|
|
extern_prelude: self
|
|
|
|
|
.extern_prelude
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|(ident, entry)| (ident.name, entry.introduced_by_item))
|
|
|
|
|
.collect(),
|
2021-04-25 17:09:35 +00:00
|
|
|
|
main_def,
|
2021-07-16 19:55:10 +00:00
|
|
|
|
trait_impls: self.trait_impls,
|
2021-07-16 20:22:08 +00:00
|
|
|
|
proc_macros,
|
2021-09-06 16:20:59 +00:00
|
|
|
|
confused_type_with_std_module,
|
2021-09-28 22:17:54 +00:00
|
|
|
|
registered_tools: self.registered_tools,
|
2019-10-20 00:19:12 +00:00
|
|
|
|
}
|
2019-10-19 23:55:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 00:19:12 +00:00
|
|
|
|
pub fn clone_outputs(&self) -> ResolverOutputs {
|
2021-07-16 20:22:08 +00:00
|
|
|
|
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
|
2019-10-20 00:19:12 +00:00
|
|
|
|
ResolverOutputs {
|
|
|
|
|
definitions: self.definitions.clone(),
|
2021-07-26 03:38:16 +00:00
|
|
|
|
access_levels: self.access_levels.clone(),
|
2019-10-20 00:28:36 +00:00
|
|
|
|
cstore: Box::new(self.cstore().clone()),
|
2020-10-16 23:28:11 +00:00
|
|
|
|
visibilities: self.visibilities.clone(),
|
2022-04-18 13:35:40 +00:00
|
|
|
|
has_pub_restricted: self.has_pub_restricted,
|
2020-05-24 11:18:22 +00:00
|
|
|
|
extern_crate_map: self.extern_crate_map.clone(),
|
2021-12-21 03:24:43 +00:00
|
|
|
|
reexport_map: self.reexport_map.clone(),
|
2020-05-24 11:18:22 +00:00
|
|
|
|
glob_map: self.glob_map.clone(),
|
|
|
|
|
maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(),
|
|
|
|
|
maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(),
|
2019-12-24 22:38:22 +00:00
|
|
|
|
extern_prelude: self
|
|
|
|
|
.extern_prelude
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|(ident, entry)| (ident.name, entry.introduced_by_item))
|
|
|
|
|
.collect(),
|
2021-09-11 08:18:56 +00:00
|
|
|
|
main_def: self.main_def,
|
2021-07-16 19:55:10 +00:00
|
|
|
|
trait_impls: self.trait_impls.clone(),
|
2021-07-16 20:22:08 +00:00
|
|
|
|
proc_macros,
|
2021-09-06 16:20:59 +00:00
|
|
|
|
confused_type_with_std_module: self.confused_type_with_std_module.clone(),
|
2021-09-28 22:17:54 +00:00
|
|
|
|
registered_tools: self.registered_tools.clone(),
|
2019-10-20 00:19:12 +00:00
|
|
|
|
}
|
2019-10-19 23:55:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 00:28:36 +00:00
|
|
|
|
pub fn cstore(&self) -> &CStore {
|
|
|
|
|
self.crate_loader.cstore()
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-02 22:44:04 +00:00
|
|
|
|
fn dummy_ext(&self, macro_kind: MacroKind) -> Lrc<SyntaxExtension> {
|
|
|
|
|
match macro_kind {
|
|
|
|
|
MacroKind::Bang => self.dummy_ext_bang.clone(),
|
|
|
|
|
MacroKind::Derive => self.dummy_ext_derive.clone(),
|
2021-08-05 22:58:59 +00:00
|
|
|
|
MacroKind::Attr => self.non_macro_attr.clone(),
|
2019-07-02 22:44:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-18 17:01:33 +00:00
|
|
|
|
/// Runs the function on each namespace.
|
2018-04-29 23:20:14 +00:00
|
|
|
|
fn per_ns<F: FnMut(&mut Self, Namespace)>(&mut self, mut f: F) {
|
|
|
|
|
f(self, TypeNS);
|
|
|
|
|
f(self, ValueNS);
|
2018-05-14 00:22:52 +00:00
|
|
|
|
f(self, MacroNS);
|
2016-11-10 06:19:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-12 23:13:36 +00:00
|
|
|
|
fn is_builtin_macro(&mut self, res: Res) -> bool {
|
2021-01-09 15:48:58 +00:00
|
|
|
|
self.get_macro(res).map_or(false, |ext| ext.builtin_name.is_some())
|
2019-06-20 08:52:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-28 07:07:44 +00:00
|
|
|
|
fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId {
|
|
|
|
|
loop {
|
2021-03-02 19:01:29 +00:00
|
|
|
|
match ctxt.outer_expn_data().macro_def_id {
|
2020-05-22 20:57:25 +00:00
|
|
|
|
Some(def_id) => return def_id,
|
2017-11-28 07:07:44 +00:00
|
|
|
|
None => ctxt.remove_mark(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-22 01:54:34 +00:00
|
|
|
|
/// Entry point to crate resolution.
|
|
|
|
|
pub fn resolve_crate(&mut self, krate: &Crate) {
|
2021-01-21 22:57:46 +00:00
|
|
|
|
self.session.time("resolve_crate", || {
|
|
|
|
|
self.session.time("finalize_imports", || ImportResolver { r: self }.finalize_imports());
|
2021-07-26 03:38:16 +00:00
|
|
|
|
self.session.time("resolve_access_levels", || {
|
|
|
|
|
AccessLevelsVisitor::compute_access_levels(self, krate)
|
|
|
|
|
});
|
2021-01-21 22:57:46 +00:00
|
|
|
|
self.session.time("finalize_macro_resolutions", || self.finalize_macro_resolutions());
|
|
|
|
|
self.session.time("late_resolve_crate", || self.late_resolve_crate(krate));
|
2021-04-25 17:09:35 +00:00
|
|
|
|
self.session.time("resolve_main", || self.resolve_main());
|
2021-01-21 22:57:46 +00:00
|
|
|
|
self.session.time("resolve_check_unused", || self.check_unused(krate));
|
|
|
|
|
self.session.time("resolve_report_errors", || self.report_errors(krate));
|
|
|
|
|
self.session.time("resolve_postprocess", || self.crate_loader.postprocess(krate));
|
|
|
|
|
});
|
2016-06-22 01:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-06 20:50:02 +00:00
|
|
|
|
pub fn traits_in_scope(
|
|
|
|
|
&mut self,
|
|
|
|
|
current_trait: Option<Module<'a>>,
|
|
|
|
|
parent_scope: &ParentScope<'a>,
|
|
|
|
|
ctxt: SyntaxContext,
|
|
|
|
|
assoc_item: Option<(Symbol, Namespace)>,
|
|
|
|
|
) -> Vec<TraitCandidate> {
|
|
|
|
|
let mut found_traits = Vec::new();
|
|
|
|
|
|
|
|
|
|
if let Some(module) = current_trait {
|
|
|
|
|
if self.trait_may_have_item(Some(module), assoc_item) {
|
2021-09-26 16:29:53 +00:00
|
|
|
|
let def_id = module.def_id();
|
2021-01-06 20:50:02 +00:00
|
|
|
|
found_traits.push(TraitCandidate { def_id, import_ids: smallvec![] });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.visit_scopes(ScopeSet::All(TypeNS, false), parent_scope, ctxt, |this, scope, _, _| {
|
|
|
|
|
match scope {
|
2021-03-13 19:23:18 +00:00
|
|
|
|
Scope::Module(module, _) => {
|
2021-01-06 20:50:02 +00:00
|
|
|
|
this.traits_in_module(module, assoc_item, &mut found_traits);
|
|
|
|
|
}
|
|
|
|
|
Scope::StdLibPrelude => {
|
|
|
|
|
if let Some(module) = this.prelude {
|
|
|
|
|
this.traits_in_module(module, assoc_item, &mut found_traits);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Scope::ExternPrelude | Scope::ToolPrelude | Scope::BuiltinTypes => {}
|
|
|
|
|
_ => unreachable!(),
|
|
|
|
|
}
|
|
|
|
|
None::<()>
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
found_traits
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn traits_in_module(
|
2020-08-08 17:06:45 +00:00
|
|
|
|
&mut self,
|
|
|
|
|
module: Module<'a>,
|
2021-01-06 20:50:02 +00:00
|
|
|
|
assoc_item: Option<(Symbol, Namespace)>,
|
2020-08-08 17:06:45 +00:00
|
|
|
|
found_traits: &mut Vec<TraitCandidate>,
|
|
|
|
|
) {
|
2020-08-08 17:21:19 +00:00
|
|
|
|
module.ensure_traits(self);
|
|
|
|
|
let traits = module.traits.borrow();
|
2021-01-06 20:50:02 +00:00
|
|
|
|
for (trait_name, trait_binding) in traits.as_ref().unwrap().iter() {
|
|
|
|
|
if self.trait_may_have_item(trait_binding.module(), assoc_item) {
|
|
|
|
|
let def_id = trait_binding.res().def_id();
|
|
|
|
|
let import_ids = self.find_transitive_imports(&trait_binding.kind, *trait_name);
|
|
|
|
|
found_traits.push(TraitCandidate { def_id, import_ids });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-08 17:06:45 +00:00
|
|
|
|
|
2021-01-06 20:50:02 +00:00
|
|
|
|
// List of traits in scope is pruned on best effort basis. We reject traits not having an
|
|
|
|
|
// associated item with the given name and namespace (if specified). This is a conservative
|
|
|
|
|
// optimization, proper hygienic type-based resolution of associated items is done in typeck.
|
|
|
|
|
// We don't reject trait aliases (`trait_module == None`) because we don't have access to their
|
|
|
|
|
// associated items.
|
|
|
|
|
fn trait_may_have_item(
|
|
|
|
|
&mut self,
|
|
|
|
|
trait_module: Option<Module<'a>>,
|
|
|
|
|
assoc_item: Option<(Symbol, Namespace)>,
|
|
|
|
|
) -> bool {
|
|
|
|
|
match (trait_module, assoc_item) {
|
|
|
|
|
(Some(trait_module), Some((name, ns))) => {
|
|
|
|
|
self.resolutions(trait_module).borrow().iter().any(|resolution| {
|
|
|
|
|
let (&BindingKey { ident: assoc_ident, ns: assoc_ns, .. }, _) = resolution;
|
|
|
|
|
assoc_ns == ns && assoc_ident.name == name
|
|
|
|
|
})
|
2020-08-08 17:06:45 +00:00
|
|
|
|
}
|
2021-01-06 20:50:02 +00:00
|
|
|
|
_ => true,
|
2020-08-08 17:06:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn find_transitive_imports(
|
|
|
|
|
&mut self,
|
|
|
|
|
mut kind: &NameBindingKind<'_>,
|
|
|
|
|
trait_name: Ident,
|
|
|
|
|
) -> SmallVec<[LocalDefId; 1]> {
|
|
|
|
|
let mut import_ids = smallvec![];
|
|
|
|
|
while let NameBindingKind::Import { import, binding, .. } = kind {
|
|
|
|
|
let id = self.local_def_id(import.id);
|
|
|
|
|
self.maybe_unused_trait_imports.insert(id);
|
|
|
|
|
self.add_to_glob_map(&import, trait_name);
|
|
|
|
|
import_ids.push(id);
|
|
|
|
|
kind = &binding.kind;
|
|
|
|
|
}
|
|
|
|
|
import_ids
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 20:04:26 +00:00
|
|
|
|
fn new_key(&mut self, ident: Ident, ns: Namespace) -> BindingKey {
|
2020-03-13 22:36:46 +00:00
|
|
|
|
let ident = ident.normalize_to_macros_2_0();
|
2019-09-09 20:04:26 +00:00
|
|
|
|
let disambiguator = if ident.name == kw::Underscore {
|
|
|
|
|
self.underscore_disambiguator += 1;
|
|
|
|
|
self.underscore_disambiguator
|
|
|
|
|
} else {
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
BindingKey { ident, ns, disambiguator }
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-15 22:18:14 +00:00
|
|
|
|
fn resolutions(&mut self, module: Module<'a>) -> &'a Resolutions<'a> {
|
|
|
|
|
if module.populate_on_access.get() {
|
|
|
|
|
module.populate_on_access.set(false);
|
2019-08-16 18:19:43 +00:00
|
|
|
|
self.build_reduced_graph_external(module);
|
2019-08-15 22:18:14 +00:00
|
|
|
|
}
|
|
|
|
|
&module.lazy_resolutions
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-24 22:38:22 +00:00
|
|
|
|
fn resolution(
|
|
|
|
|
&mut self,
|
|
|
|
|
module: Module<'a>,
|
|
|
|
|
key: BindingKey,
|
|
|
|
|
) -> &'a RefCell<NameResolution<'a>> {
|
|
|
|
|
*self
|
|
|
|
|
.resolutions(module)
|
|
|
|
|
.borrow_mut()
|
|
|
|
|
.entry(key)
|
|
|
|
|
.or_insert_with(|| self.arenas.alloc_name_resolution())
|
2019-08-15 22:18:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-24 22:38:22 +00:00
|
|
|
|
fn record_use(
|
|
|
|
|
&mut self,
|
|
|
|
|
ident: Ident,
|
|
|
|
|
used_binding: &'a NameBinding<'a>,
|
|
|
|
|
is_lexical_scope: bool,
|
|
|
|
|
) {
|
2018-12-29 15:15:29 +00:00
|
|
|
|
if let Some((b2, kind)) = used_binding.ambiguity {
|
|
|
|
|
self.ambiguity_errors.push(AmbiguityError {
|
2019-12-24 22:38:22 +00:00
|
|
|
|
kind,
|
|
|
|
|
ident,
|
|
|
|
|
b1: used_binding,
|
|
|
|
|
b2,
|
2018-12-29 15:15:29 +00:00
|
|
|
|
misc1: AmbiguityErrorMisc::None,
|
|
|
|
|
misc2: AmbiguityErrorMisc::None,
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-03-07 16:02:32 +00:00
|
|
|
|
if let NameBindingKind::Import { import, binding, ref used } = used_binding.kind {
|
2018-12-29 15:15:29 +00:00
|
|
|
|
// Avoid marking `extern crate` items that refer to a name from extern prelude,
|
|
|
|
|
// but not introduce it, as used if they are accessed from lexical scope.
|
|
|
|
|
if is_lexical_scope {
|
2020-03-13 22:36:46 +00:00
|
|
|
|
if let Some(entry) = self.extern_prelude.get(&ident.normalize_to_macros_2_0()) {
|
2018-12-29 15:15:29 +00:00
|
|
|
|
if let Some(crate_item) = entry.extern_crate_item {
|
|
|
|
|
if ptr::eq(used_binding, crate_item) && !entry.introduced_by_item {
|
|
|
|
|
return;
|
2018-11-13 23:17:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-05 05:27:58 +00:00
|
|
|
|
}
|
2018-12-29 15:15:29 +00:00
|
|
|
|
used.set(true);
|
2020-03-07 16:02:32 +00:00
|
|
|
|
import.used.set(true);
|
2021-08-22 14:50:59 +00:00
|
|
|
|
self.used_imports.insert(import.id);
|
2020-03-07 16:02:32 +00:00
|
|
|
|
self.add_to_glob_map(&import, ident);
|
2021-08-22 14:50:59 +00:00
|
|
|
|
self.record_use(ident, binding, false);
|
2016-09-05 04:55:12 +00:00
|
|
|
|
}
|
2016-07-29 16:04:45 +00:00
|
|
|
|
}
|
2014-11-23 09:29:41 +00:00
|
|
|
|
|
2019-01-06 00:22:52 +00:00
|
|
|
|
#[inline]
|
2020-03-07 16:02:32 +00:00
|
|
|
|
fn add_to_glob_map(&mut self, import: &Import<'_>, ident: Ident) {
|
|
|
|
|
if import.is_glob() {
|
2020-06-20 18:59:29 +00:00
|
|
|
|
let def_id = self.local_def_id(import.id);
|
2020-05-24 11:18:22 +00:00
|
|
|
|
self.glob_map.entry(def_id).or_default().insert(ident.name);
|
2016-07-29 16:04:45 +00:00
|
|
|
|
}
|
2014-11-23 09:29:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-24 16:12:00 +00:00
|
|
|
|
fn resolve_crate_root(&mut self, ident: Ident) -> Module<'a> {
|
2020-03-17 15:45:02 +00:00
|
|
|
|
debug!("resolve_crate_root({:?})", ident);
|
2018-06-24 16:12:00 +00:00
|
|
|
|
let mut ctxt = ident.span.ctxt();
|
2019-05-11 14:41:37 +00:00
|
|
|
|
let mark = if ident.name == kw::DollarCrate {
|
2017-11-29 09:05:31 +00:00
|
|
|
|
// When resolving `$crate` from a `macro_rules!` invoked in a `macro`,
|
|
|
|
|
// we don't want to pretend that the `macro_rules!` definition is in the `macro`
|
2020-03-13 22:36:46 +00:00
|
|
|
|
// as described in `SyntaxContext::apply_mark`, so we ignore prepended opaque marks.
|
2018-06-29 00:45:47 +00:00
|
|
|
|
// FIXME: This is only a guess and it doesn't work correctly for `macro_rules!`
|
|
|
|
|
// definitions actually produced by `macro` and `macro` definitions produced by
|
|
|
|
|
// `macro_rules!`, but at least such configurations are not stable yet.
|
2020-03-13 22:36:46 +00:00
|
|
|
|
ctxt = ctxt.normalize_to_macro_rules();
|
2020-03-17 15:45:02 +00:00
|
|
|
|
debug!(
|
|
|
|
|
"resolve_crate_root: marks={:?}",
|
|
|
|
|
ctxt.marks().into_iter().map(|(i, t)| (i.expn_data(), t)).collect::<Vec<_>>()
|
|
|
|
|
);
|
2018-06-29 00:45:47 +00:00
|
|
|
|
let mut iter = ctxt.marks().into_iter().rev().peekable();
|
|
|
|
|
let mut result = None;
|
2020-03-13 22:36:46 +00:00
|
|
|
|
// Find the last opaque mark from the end if it exists.
|
2018-06-30 16:53:46 +00:00
|
|
|
|
while let Some(&(mark, transparency)) = iter.peek() {
|
|
|
|
|
if transparency == Transparency::Opaque {
|
2018-06-29 00:45:47 +00:00
|
|
|
|
result = Some(mark);
|
|
|
|
|
iter.next();
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-17 15:45:02 +00:00
|
|
|
|
debug!(
|
|
|
|
|
"resolve_crate_root: found opaque mark {:?} {:?}",
|
|
|
|
|
result,
|
|
|
|
|
result.map(|r| r.expn_data())
|
|
|
|
|
);
|
2020-03-13 22:23:24 +00:00
|
|
|
|
// Then find the last semi-transparent mark from the end if it exists.
|
2018-06-30 16:53:46 +00:00
|
|
|
|
for (mark, transparency) in iter {
|
|
|
|
|
if transparency == Transparency::SemiTransparent {
|
2018-06-29 00:45:47 +00:00
|
|
|
|
result = Some(mark);
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-17 15:45:02 +00:00
|
|
|
|
debug!(
|
|
|
|
|
"resolve_crate_root: found semi-transparent mark {:?} {:?}",
|
|
|
|
|
result,
|
|
|
|
|
result.map(|r| r.expn_data())
|
|
|
|
|
);
|
2018-06-29 00:45:47 +00:00
|
|
|
|
result
|
2017-11-29 09:05:31 +00:00
|
|
|
|
} else {
|
2020-03-17 15:45:02 +00:00
|
|
|
|
debug!("resolve_crate_root: not DollarCrate");
|
2020-03-13 22:36:46 +00:00
|
|
|
|
ctxt = ctxt.normalize_to_macros_2_0();
|
2019-07-15 22:04:05 +00:00
|
|
|
|
ctxt.adjust(ExpnId::root())
|
2017-11-29 09:05:31 +00:00
|
|
|
|
};
|
|
|
|
|
let module = match mark {
|
2021-09-11 22:47:46 +00:00
|
|
|
|
Some(def) => self.expn_def_scope(def),
|
2020-03-17 15:45:02 +00:00
|
|
|
|
None => {
|
|
|
|
|
debug!(
|
|
|
|
|
"resolve_crate_root({:?}): found no mark (ident.span = {:?})",
|
|
|
|
|
ident, ident.span
|
|
|
|
|
);
|
|
|
|
|
return self.graph_root;
|
|
|
|
|
}
|
2017-03-22 08:39:51 +00:00
|
|
|
|
};
|
2021-09-26 16:29:53 +00:00
|
|
|
|
let module = self.expect_module(
|
|
|
|
|
module.opt_def_id().map_or(LOCAL_CRATE, |def_id| def_id.krate).as_def_id(),
|
|
|
|
|
);
|
2020-03-17 15:45:02 +00:00
|
|
|
|
debug!(
|
|
|
|
|
"resolve_crate_root({:?}): got module {:?} ({:?}) (ident.span = {:?})",
|
|
|
|
|
ident,
|
|
|
|
|
module,
|
|
|
|
|
module.kind.name(),
|
|
|
|
|
ident.span
|
|
|
|
|
);
|
|
|
|
|
module
|
2017-03-22 08:39:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn resolve_self(&mut self, ctxt: &mut SyntaxContext, module: Module<'a>) -> Module<'a> {
|
2021-09-11 23:06:27 +00:00
|
|
|
|
let mut module = self.expect_module(module.nearest_parent_mod());
|
2020-03-13 22:36:46 +00:00
|
|
|
|
while module.span.ctxt().normalize_to_macros_2_0() != *ctxt {
|
2021-09-11 22:47:46 +00:00
|
|
|
|
let parent = module.parent.unwrap_or_else(|| self.expn_def_scope(ctxt.remove_mark()));
|
2021-09-11 23:06:27 +00:00
|
|
|
|
module = self.expect_module(parent.nearest_parent_mod());
|
2016-10-23 02:44:36 +00:00
|
|
|
|
}
|
2017-03-22 08:39:51 +00:00
|
|
|
|
module
|
2016-10-23 02:44:36 +00:00
|
|
|
|
}
|
2019-08-05 18:18:50 +00:00
|
|
|
|
|
2019-05-04 12:18:58 +00:00
|
|
|
|
fn record_partial_res(&mut self, node_id: NodeId, resolution: PartialRes) {
|
2019-04-20 16:36:05 +00:00
|
|
|
|
debug!("(recording res) recording {:?} for {}", resolution, node_id);
|
2019-05-04 12:18:58 +00:00
|
|
|
|
if let Some(prev_res) = self.partial_res_map.insert(node_id, resolution) {
|
2016-04-24 03:26:10 +00:00
|
|
|
|
panic!("path resolved multiple times ({:?} before, {:?} now)", prev_res, resolution);
|
2014-09-18 21:05:52 +00:00
|
|
|
|
}
|
2012-05-22 17:54:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 13:09:24 +00:00
|
|
|
|
fn record_pat_span(&mut self, node: NodeId, span: Span) {
|
|
|
|
|
debug!("(recording pat) recording {:?} for {:?}", node, span);
|
|
|
|
|
self.pat_span_map.insert(node, span);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-20 00:33:06 +00:00
|
|
|
|
fn is_accessible_from(&self, vis: ty::Visibility, module: Module<'a>) -> bool {
|
2021-09-13 21:13:14 +00:00
|
|
|
|
vis.is_accessible_from(module.nearest_parent_mod(), self)
|
2016-08-20 00:33:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 01:49:40 +00:00
|
|
|
|
fn set_binding_parent_module(&mut self, binding: &'a NameBinding<'a>, module: Module<'a>) {
|
2022-02-04 03:26:29 +00:00
|
|
|
|
if let Some(old_module) =
|
|
|
|
|
self.binding_parent_modules.insert(Interned::new_unchecked(binding), module)
|
|
|
|
|
{
|
2018-09-27 01:49:40 +00:00
|
|
|
|
if !ptr::eq(module, old_module) {
|
|
|
|
|
span_bug!(binding.span, "parent module is reset for binding");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-13 22:23:24 +00:00
|
|
|
|
fn disambiguate_macro_rules_vs_modularized(
|
2018-09-27 01:49:40 +00:00
|
|
|
|
&self,
|
2020-03-13 22:23:24 +00:00
|
|
|
|
macro_rules: &'a NameBinding<'a>,
|
|
|
|
|
modularized: &'a NameBinding<'a>,
|
2018-09-27 01:49:40 +00:00
|
|
|
|
) -> bool {
|
2020-03-13 22:36:46 +00:00
|
|
|
|
// Some non-controversial subset of ambiguities "modularized macro name" vs "macro_rules"
|
2018-09-27 01:49:40 +00:00
|
|
|
|
// is disambiguated to mitigate regressions from macro modularization.
|
|
|
|
|
// Scoping for `macro_rules` behaves like scoping for `let` at module level, in general.
|
2019-12-24 22:38:22 +00:00
|
|
|
|
match (
|
2022-02-04 03:26:29 +00:00
|
|
|
|
self.binding_parent_modules.get(&Interned::new_unchecked(macro_rules)),
|
|
|
|
|
self.binding_parent_modules.get(&Interned::new_unchecked(modularized)),
|
2019-12-24 22:38:22 +00:00
|
|
|
|
) {
|
2020-03-13 22:23:24 +00:00
|
|
|
|
(Some(macro_rules), Some(modularized)) => {
|
2021-09-13 21:13:14 +00:00
|
|
|
|
macro_rules.nearest_parent_mod() == modularized.nearest_parent_mod()
|
2020-03-13 22:23:24 +00:00
|
|
|
|
&& modularized.is_ancestor_of(macro_rules)
|
2019-12-24 22:38:22 +00:00
|
|
|
|
}
|
2018-09-27 01:49:40 +00:00
|
|
|
|
_ => false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 23:55:22 +00:00
|
|
|
|
fn extern_prelude_get(&mut self, ident: Ident, finalize: bool) -> Option<&'a NameBinding<'a>> {
|
2018-11-08 22:29:07 +00:00
|
|
|
|
if ident.is_path_segment_keyword() {
|
|
|
|
|
// Make sure `self`, `super` etc produce an error when passed to here.
|
|
|
|
|
return None;
|
|
|
|
|
}
|
2020-03-13 22:36:46 +00:00
|
|
|
|
self.extern_prelude.get(&ident.normalize_to_macros_2_0()).cloned().and_then(|entry| {
|
2018-09-28 22:31:54 +00:00
|
|
|
|
if let Some(binding) = entry.extern_crate_item {
|
2022-03-23 23:55:22 +00:00
|
|
|
|
if finalize && entry.introduced_by_item {
|
2021-08-22 14:50:59 +00:00
|
|
|
|
self.record_use(ident, binding, false);
|
2019-01-12 21:58:45 +00:00
|
|
|
|
}
|
2018-09-28 22:31:54 +00:00
|
|
|
|
Some(binding)
|
|
|
|
|
} else {
|
2022-03-23 23:55:22 +00:00
|
|
|
|
let crate_id = if finalize {
|
2021-11-26 21:39:44 +00:00
|
|
|
|
let Some(crate_id) =
|
|
|
|
|
self.crate_loader.process_path_extern(ident.name, ident.span) else { return Some(self.dummy_binding); };
|
|
|
|
|
crate_id
|
2018-09-28 22:31:54 +00:00
|
|
|
|
} else {
|
2020-07-05 07:39:15 +00:00
|
|
|
|
self.crate_loader.maybe_process_path_extern(ident.name)?
|
2018-09-28 22:31:54 +00:00
|
|
|
|
};
|
2021-09-11 23:06:27 +00:00
|
|
|
|
let crate_root = self.expect_module(crate_id.as_def_id());
|
2019-12-24 22:38:22 +00:00
|
|
|
|
Some(
|
2021-06-25 18:43:04 +00:00
|
|
|
|
(crate_root, ty::Visibility::Public, DUMMY_SP, LocalExpnId::ROOT)
|
2019-12-24 22:38:22 +00:00
|
|
|
|
.to_name_binding(self.arenas),
|
|
|
|
|
)
|
2018-09-28 22:31:54 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2015-03-15 21:44:19 +00:00
|
|
|
|
|
2022-03-23 21:03:12 +00:00
|
|
|
|
/// Rustdoc uses this to resolve doc link paths in a recoverable way. `PathResult<'a>`
|
2019-08-07 23:39:02 +00:00
|
|
|
|
/// isn't something that can be returned because it can't be made to live that long,
|
|
|
|
|
/// and also it's a private type. Fortunately rustdoc doesn't need to know the error,
|
|
|
|
|
/// just that an error occurred.
|
2022-03-23 21:03:12 +00:00
|
|
|
|
pub fn resolve_rustdoc_path(
|
2019-12-24 22:38:22 +00:00
|
|
|
|
&mut self,
|
|
|
|
|
path_str: &str,
|
|
|
|
|
ns: Namespace,
|
2022-03-25 23:50:00 +00:00
|
|
|
|
mut module_id: DefId,
|
2022-03-23 21:03:12 +00:00
|
|
|
|
) -> Option<Res> {
|
|
|
|
|
let mut segments =
|
|
|
|
|
Vec::from_iter(path_str.split("::").map(Ident::from_str).map(Segment::from_ident));
|
2022-03-25 23:50:00 +00:00
|
|
|
|
if let Some(segment) = segments.first_mut() {
|
|
|
|
|
if segment.ident.name == kw::Crate {
|
|
|
|
|
// FIXME: `resolve_path` always resolves `crate` to the current crate root, but
|
|
|
|
|
// rustdoc wants it to resolve to the `module_id`'s crate root. This trick of
|
|
|
|
|
// replacing `crate` with `self` and changing the current module should achieve
|
|
|
|
|
// the same effect.
|
|
|
|
|
segment.ident.name = kw::SelfLower;
|
|
|
|
|
module_id = module_id.krate.as_def_id();
|
|
|
|
|
} else if segment.ident.name == kw::Empty {
|
|
|
|
|
segment.ident.name = kw::PathRoot;
|
|
|
|
|
}
|
2022-03-23 21:03:12 +00:00
|
|
|
|
}
|
2016-11-30 22:35:25 +00:00
|
|
|
|
|
2022-03-23 21:03:12 +00:00
|
|
|
|
let module = self.expect_module(module_id);
|
2022-04-08 20:50:56 +00:00
|
|
|
|
match self.maybe_resolve_path(&segments, Some(ns), &ParentScope::module(module, self)) {
|
2022-03-23 21:03:12 +00:00
|
|
|
|
PathResult::Module(ModuleOrUniformRoot::Module(module)) => Some(module.res().unwrap()),
|
2019-12-24 22:38:22 +00:00
|
|
|
|
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => {
|
2022-03-23 21:03:12 +00:00
|
|
|
|
Some(path_res.base_res())
|
2019-12-24 22:38:22 +00:00
|
|
|
|
}
|
2022-04-05 12:38:18 +00:00
|
|
|
|
PathResult::Module(ModuleOrUniformRoot::ExternPrelude)
|
|
|
|
|
| PathResult::NonModule(..)
|
|
|
|
|
| PathResult::Failed { .. } => None,
|
2019-08-07 23:39:02 +00:00
|
|
|
|
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-19 23:55:39 +00:00
|
|
|
|
// For rustdoc.
|
|
|
|
|
pub fn graph_root(&self) -> Module<'a> {
|
|
|
|
|
self.graph_root
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For rustdoc.
|
2022-04-05 20:46:44 +00:00
|
|
|
|
pub fn take_all_macro_rules(&mut self) -> FxHashMap<Symbol, Res> {
|
|
|
|
|
mem::take(&mut self.all_macro_rules)
|
2019-10-19 23:55:39 +00:00
|
|
|
|
}
|
2020-06-20 18:59:29 +00:00
|
|
|
|
|
2021-08-29 18:41:46 +00:00
|
|
|
|
/// For rustdoc.
|
|
|
|
|
/// For local modules returns only reexports, for external modules returns all children.
|
|
|
|
|
pub fn module_children_or_reexports(&self, def_id: DefId) -> Vec<ModChild> {
|
|
|
|
|
if let Some(def_id) = def_id.as_local() {
|
|
|
|
|
self.reexport_map.get(&def_id).cloned().unwrap_or_default()
|
|
|
|
|
} else {
|
|
|
|
|
self.cstore().module_children_untracked(def_id, self.session)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-20 18:59:29 +00:00
|
|
|
|
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {
|
2021-04-04 14:04:38 +00:00
|
|
|
|
def_id.as_local().map(|def_id| self.definitions.def_span(def_id))
|
2020-06-20 18:59:29 +00:00
|
|
|
|
}
|
2021-02-25 00:09:33 +00:00
|
|
|
|
|
|
|
|
|
/// Checks if an expression refers to a function marked with
|
|
|
|
|
/// `#[rustc_legacy_const_generics]` and returns the argument index list
|
|
|
|
|
/// from the attribute.
|
2021-02-25 00:37:56 +00:00
|
|
|
|
pub fn legacy_const_generic_args(&mut self, expr: &Expr) -> Option<Vec<usize>> {
|
2021-02-25 00:09:33 +00:00
|
|
|
|
if let ExprKind::Path(None, path) = &expr.kind {
|
|
|
|
|
// Don't perform legacy const generics rewriting if the path already
|
|
|
|
|
// has generic arguments.
|
|
|
|
|
if path.segments.last().unwrap().args.is_some() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let partial_res = self.partial_res_map.get(&expr.id)?;
|
|
|
|
|
if partial_res.unresolved_segments() != 0 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Res::Def(def::DefKind::Fn, def_id) = partial_res.base_res() {
|
|
|
|
|
// We only support cross-crate argument rewriting. Uses
|
|
|
|
|
// within the same crate should be updated to use the new
|
|
|
|
|
// const generics style.
|
|
|
|
|
if def_id.is_local() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 00:37:56 +00:00
|
|
|
|
if let Some(v) = self.legacy_const_generic_args.get(&def_id) {
|
|
|
|
|
return v.clone();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 12:11:36 +00:00
|
|
|
|
let attr = self
|
|
|
|
|
.cstore()
|
2022-01-06 04:13:41 +00:00
|
|
|
|
.item_attrs_untracked(def_id, self.session)
|
2021-12-21 12:11:36 +00:00
|
|
|
|
.find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
|
|
|
|
|
let mut ret = Vec::new();
|
|
|
|
|
for meta in attr.meta_item_list()? {
|
|
|
|
|
match meta.literal()?.kind {
|
|
|
|
|
LitKind::Int(a, _) => ret.push(a as usize),
|
|
|
|
|
_ => panic!("invalid arg index"),
|
2021-02-25 00:09:33 +00:00
|
|
|
|
}
|
2021-12-21 12:11:36 +00:00
|
|
|
|
}
|
|
|
|
|
// Cache the lookup to avoid parsing attributes for an iterm multiple times.
|
|
|
|
|
self.legacy_const_generic_args.insert(def_id, Some(ret.clone()));
|
|
|
|
|
return Some(ret);
|
2021-02-25 00:09:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
None
|
|
|
|
|
}
|
2021-04-25 17:09:35 +00:00
|
|
|
|
|
|
|
|
|
fn resolve_main(&mut self) {
|
|
|
|
|
let module = self.graph_root;
|
|
|
|
|
let ident = Ident::with_dummy_span(sym::main);
|
|
|
|
|
let parent_scope = &ParentScope::module(module, self);
|
|
|
|
|
|
2022-04-08 20:50:56 +00:00
|
|
|
|
let Ok(name_binding) = self.maybe_resolve_ident_in_module(
|
2021-04-25 17:09:35 +00:00
|
|
|
|
ModuleOrUniformRoot::Module(module),
|
|
|
|
|
ident,
|
|
|
|
|
ValueNS,
|
|
|
|
|
parent_scope,
|
2022-02-18 23:48:49 +00:00
|
|
|
|
) else {
|
|
|
|
|
return;
|
2021-04-25 17:09:35 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let res = name_binding.res();
|
|
|
|
|
let is_import = name_binding.is_import();
|
|
|
|
|
let span = name_binding.span;
|
|
|
|
|
if let Res::Def(DefKind::Fn, _) = res {
|
2021-08-22 14:50:59 +00:00
|
|
|
|
self.record_use(ident, name_binding, false);
|
2021-04-25 17:09:35 +00:00
|
|
|
|
}
|
|
|
|
|
self.main_def = Some(MainDefinition { res, is_import, span });
|
|
|
|
|
}
|
2016-11-30 22:35:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-19 11:00:18 +00:00
|
|
|
|
fn names_to_string(names: &[Symbol]) -> String {
|
2015-03-15 21:44:19 +00:00
|
|
|
|
let mut result = String::new();
|
2019-12-24 22:38:22 +00:00
|
|
|
|
for (i, name) in names.iter().filter(|name| **name != kw::PathRoot).enumerate() {
|
2016-12-05 03:51:11 +00:00
|
|
|
|
if i > 0 {
|
|
|
|
|
result.push_str("::");
|
|
|
|
|
}
|
2019-11-24 01:08:04 +00:00
|
|
|
|
if Ident::with_dummy_span(*name).is_raw_guess() {
|
2019-11-20 22:50:13 +00:00
|
|
|
|
result.push_str("r#");
|
|
|
|
|
}
|
2021-12-15 03:39:23 +00:00
|
|
|
|
result.push_str(name.as_str());
|
2015-10-26 19:31:11 +00:00
|
|
|
|
}
|
2015-03-15 21:44:19 +00:00
|
|
|
|
result
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 22:35:25 +00:00
|
|
|
|
fn path_names_to_string(path: &Path) -> String {
|
2019-11-20 22:50:13 +00:00
|
|
|
|
names_to_string(&path.segments.iter().map(|seg| seg.ident.name).collect::<Vec<_>>())
|
2015-03-15 21:44:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A somewhat inefficient routine to obtain the name of a module.
|
2019-02-06 17:15:23 +00:00
|
|
|
|
fn module_to_string(module: Module<'_>) -> Option<String> {
|
2015-03-15 21:44:19 +00:00
|
|
|
|
let mut names = Vec::new();
|
|
|
|
|
|
2020-04-19 11:00:18 +00:00
|
|
|
|
fn collect_mod(names: &mut Vec<Symbol>, module: Module<'_>) {
|
2019-04-20 16:46:19 +00:00
|
|
|
|
if let ModuleKind::Def(.., name) = module.kind {
|
2016-09-18 09:45:06 +00:00
|
|
|
|
if let Some(parent) = module.parent {
|
2019-09-14 20:10:12 +00:00
|
|
|
|
names.push(name);
|
2016-09-18 09:45:06 +00:00
|
|
|
|
collect_mod(names, parent);
|
2015-03-15 21:44:19 +00:00
|
|
|
|
}
|
2016-09-18 09:45:06 +00:00
|
|
|
|
} else {
|
2020-04-19 11:00:18 +00:00
|
|
|
|
names.push(Symbol::intern("<opaque>"));
|
2016-10-01 07:38:47 +00:00
|
|
|
|
collect_mod(names, module.parent.unwrap());
|
2015-03-15 21:44:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
collect_mod(&mut names, module);
|
|
|
|
|
|
2015-03-24 23:53:34 +00:00
|
|
|
|
if names.is_empty() {
|
2018-01-16 19:47:14 +00:00
|
|
|
|
return None;
|
2015-03-15 21:44:19 +00:00
|
|
|
|
}
|
2019-09-14 20:10:12 +00:00
|
|
|
|
names.reverse();
|
|
|
|
|
Some(names_to_string(&names))
|
2015-03-15 21:44:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 23:55:22 +00:00
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
2022-04-30 13:26:36 +00:00
|
|
|
|
struct Finalize {
|
|
|
|
|
/// Node ID for linting.
|
|
|
|
|
node_id: NodeId,
|
|
|
|
|
/// Span of the whole path or some its characteristic fragment.
|
|
|
|
|
/// E.g. span of `b` in `foo::{a, b, c}`, or full span for regular paths.
|
|
|
|
|
path_span: Span,
|
|
|
|
|
/// Span of the path start, suitable for prepending something to to it.
|
|
|
|
|
/// E.g. span of `foo` in `foo::{a, b, c}`, or full span for regular paths.
|
|
|
|
|
root_span: Span,
|
2018-05-22 15:10:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 23:55:22 +00:00
|
|
|
|
impl Finalize {
|
2022-04-30 13:26:36 +00:00
|
|
|
|
fn new(node_id: NodeId, path_span: Span) -> Finalize {
|
|
|
|
|
Finalize { node_id, path_span, root_span: path_span }
|
2022-03-23 21:32:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 13:26:36 +00:00
|
|
|
|
fn with_root_span(node_id: NodeId, path_span: Span, root_span: Span) -> Finalize {
|
|
|
|
|
Finalize { node_id, path_span, root_span }
|
2022-03-23 21:32:00 +00:00
|
|
|
|
}
|
2018-07-21 18:14:22 +00:00
|
|
|
|
}
|
2019-12-29 09:48:52 +00:00
|
|
|
|
|
2020-07-05 20:00:14 +00:00
|
|
|
|
pub fn provide(providers: &mut Providers) {
|
2020-02-24 18:44:55 +00:00
|
|
|
|
late::lifetimes::provide(providers);
|
2019-12-29 09:48:52 +00:00
|
|
|
|
}
|