mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 19:43:24 +00:00
hygiene: modern
-> normalize_to_macros_2_0
`modern_and_legacy` -> `normalize_to_macro_rules`
This commit is contained in:
parent
8c9a38f679
commit
db638bd123
@ -3083,7 +3083,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool {
|
||||
// We could use `Ident::eq` here, but we deliberately don't. The name
|
||||
// comparison fails frequently, and we want to avoid the expensive
|
||||
// `modern()` calls required for the span comparison whenever possible.
|
||||
// `normalize_to_macros_2_0()` calls required for the span comparison whenever possible.
|
||||
use_name.name == def_name.name
|
||||
&& use_name
|
||||
.span
|
||||
@ -3099,7 +3099,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
|
||||
pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
|
||||
ident.span.modernize_and_adjust(self.expansion_that_defined(scope));
|
||||
ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope));
|
||||
ident
|
||||
}
|
||||
|
||||
@ -3109,7 +3109,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
scope: DefId,
|
||||
block: hir::HirId,
|
||||
) -> (Ident, DefId) {
|
||||
let scope = match ident.span.modernize_and_adjust(self.expansion_that_defined(scope)) {
|
||||
let scope =
|
||||
match ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope))
|
||||
{
|
||||
Some(actual_expansion) => {
|
||||
self.hir().definitions().parent_module_of_macro_def(actual_expansion)
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
_ => &[],
|
||||
};
|
||||
let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind {
|
||||
hir::GenericParamKind::Lifetime { .. } => Some(param.name.modern()),
|
||||
hir::GenericParamKind::Lifetime { .. } => Some(param.name.normalize_to_macros_2_0()),
|
||||
_ => None,
|
||||
});
|
||||
self.in_scope_lifetimes.extend(lt_def_names);
|
||||
|
@ -153,7 +153,7 @@ struct LoweringContext<'a, 'hir: 'a> {
|
||||
/// against this list to see if it is already in-scope, or if a definition
|
||||
/// needs to be created for it.
|
||||
///
|
||||
/// We always store a `modern()` version of the param-name in this
|
||||
/// We always store a `normalize_to_macros_2_0()` version of the param-name in this
|
||||
/// vector.
|
||||
in_scope_lifetimes: Vec<ParamName>,
|
||||
|
||||
@ -805,14 +805,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.modern())) {
|
||||
if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.normalize_to_macros_2_0())) {
|
||||
return;
|
||||
}
|
||||
|
||||
let hir_name = ParamName::Plain(ident);
|
||||
|
||||
if self.lifetimes_to_define.iter().any(|(_, lt_name)| lt_name.modern() == hir_name.modern())
|
||||
{
|
||||
if self.lifetimes_to_define.iter().any(|(_, lt_name)| {
|
||||
lt_name.normalize_to_macros_2_0() == hir_name.normalize_to_macros_2_0()
|
||||
}) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -840,7 +841,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
) -> T {
|
||||
let old_len = self.in_scope_lifetimes.len();
|
||||
let lt_def_names = params.iter().filter_map(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => Some(ParamName::Plain(param.ident.modern())),
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
Some(ParamName::Plain(param.ident.normalize_to_macros_2_0()))
|
||||
}
|
||||
_ => None,
|
||||
});
|
||||
self.in_scope_lifetimes.extend(lt_def_names);
|
||||
|
@ -79,9 +79,9 @@ impl ParamName {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn modern(&self) -> ParamName {
|
||||
pub fn normalize_to_macros_2_0(&self) -> ParamName {
|
||||
match *self {
|
||||
ParamName::Plain(ident) => ParamName::Plain(ident.modern()),
|
||||
ParamName::Plain(ident) => ParamName::Plain(ident.normalize_to_macros_2_0()),
|
||||
param_name => param_name,
|
||||
}
|
||||
}
|
||||
@ -151,9 +151,11 @@ impl LifetimeName {
|
||||
self == &LifetimeName::Static
|
||||
}
|
||||
|
||||
pub fn modern(&self) -> LifetimeName {
|
||||
pub fn normalize_to_macros_2_0(&self) -> LifetimeName {
|
||||
match *self {
|
||||
LifetimeName::Param(param_name) => LifetimeName::Param(param_name.modern()),
|
||||
LifetimeName::Param(param_name) => {
|
||||
LifetimeName::Param(param_name.normalize_to_macros_2_0())
|
||||
}
|
||||
lifetime_name => lifetime_name,
|
||||
}
|
||||
}
|
||||
|
@ -1088,9 +1088,9 @@ fn create_mono_items_for_default_impls<'tcx>(
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
|
||||
let overridden_methods: FxHashSet<_> =
|
||||
items.iter().map(|iiref| iiref.ident.modern()).collect();
|
||||
items.iter().map(|iiref| iiref.ident.normalize_to_macros_2_0()).collect();
|
||||
for method in tcx.provided_trait_methods(trait_ref.def_id) {
|
||||
if overridden_methods.contains(&method.ident.modern()) {
|
||||
if overridden_methods.contains(&method.ident.normalize_to_macros_2_0()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -645,7 +645,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
self.r.potentially_unused_imports.push(import);
|
||||
let imported_binding = self.r.import(binding, import);
|
||||
if ptr::eq(parent, self.r.graph_root) {
|
||||
if let Some(entry) = self.r.extern_prelude.get(&ident.modern()) {
|
||||
if let Some(entry) = self.r.extern_prelude.get(&ident.normalize_to_macros_2_0())
|
||||
{
|
||||
if expansion != ExpnId::root()
|
||||
&& orig_name.is_some()
|
||||
&& entry.extern_crate_item.is_none()
|
||||
@ -656,10 +657,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
}
|
||||
}
|
||||
let entry =
|
||||
self.r.extern_prelude.entry(ident.modern()).or_insert(ExternPreludeEntry {
|
||||
self.r.extern_prelude.entry(ident.normalize_to_macros_2_0()).or_insert(
|
||||
ExternPreludeEntry {
|
||||
extern_crate_item: None,
|
||||
introduced_by_item: true,
|
||||
});
|
||||
},
|
||||
);
|
||||
entry.extern_crate_item = Some(imported_binding);
|
||||
if orig_name.is_some() {
|
||||
entry.introduced_by_item = true;
|
||||
@ -1119,7 +1122,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
self.r.local_macro_def_scopes.insert(item.id, parent_scope.module);
|
||||
|
||||
if macro_rules {
|
||||
let ident = ident.modern();
|
||||
let ident = ident.normalize_to_macros_2_0();
|
||||
self.r.macro_names.insert(ident);
|
||||
let is_macro_export = attr::contains_name(&item.attrs, sym::macro_export);
|
||||
let vis = if is_macro_export {
|
||||
|
@ -758,7 +758,7 @@ impl<'a> Resolver<'a> {
|
||||
let msg = format!("unsafe traits like `{}` should be implemented explicitly", ident);
|
||||
err.span_note(ident.span, &msg);
|
||||
}
|
||||
if self.macro_names.contains(&ident.modern()) {
|
||||
if self.macro_names.contains(&ident.normalize_to_macros_2_0()) {
|
||||
err.help("have you added the `#[macro_use]` on the module/import?");
|
||||
}
|
||||
}
|
||||
|
@ -416,7 +416,8 @@ impl<'a> Resolver<'a> {
|
||||
None => return Err((Undetermined, Weak::Yes)),
|
||||
};
|
||||
let tmp_parent_scope;
|
||||
let (mut adjusted_parent_scope, mut ident) = (parent_scope, ident.modern());
|
||||
let (mut adjusted_parent_scope, mut ident) =
|
||||
(parent_scope, ident.normalize_to_macros_2_0());
|
||||
match ident.span.glob_adjust(module.expansion, glob_import.span) {
|
||||
Some(Some(def)) => {
|
||||
tmp_parent_scope =
|
||||
|
@ -935,7 +935,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let ident = param.ident.modern();
|
||||
let ident = param.ident.normalize_to_macros_2_0();
|
||||
debug!("with_generic_param_rib: {}", param.id);
|
||||
|
||||
if seen_bindings.contains_key(&ident) {
|
||||
@ -1464,7 +1464,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
// Add the binding to the local ribs, if it doesn't already exist in the bindings map.
|
||||
// (We must not add it if it's in the bindings map because that breaks the assumptions
|
||||
// later passes make about or-patterns.)
|
||||
let ident = ident.modern_and_legacy();
|
||||
let ident = ident.normalize_to_macro_rules();
|
||||
|
||||
let mut bound_iter = bindings.iter().filter(|(_, set)| set.contains(&ident));
|
||||
// Already bound in a product pattern? e.g. `(a, a)` which is not allowed.
|
||||
@ -1873,7 +1873,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
self.diagnostic_metadata.unused_labels.insert(id, label.ident.span);
|
||||
}
|
||||
self.with_label_rib(NormalRibKind, |this| {
|
||||
let ident = label.ident.modern_and_legacy();
|
||||
let ident = label.ident.normalize_to_macro_rules();
|
||||
this.label_ribs.last_mut().unwrap().bindings.insert(ident, id);
|
||||
f(this);
|
||||
});
|
||||
@ -1949,7 +1949,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
|
||||
ExprKind::Break(Some(label), _) | ExprKind::Continue(Some(label)) => {
|
||||
let node_id = self.search_label(label.ident, |rib, ident| {
|
||||
rib.bindings.get(&ident.modern_and_legacy()).cloned()
|
||||
rib.bindings.get(&ident.normalize_to_macro_rules()).cloned()
|
||||
});
|
||||
match node_id {
|
||||
None => {
|
||||
@ -2115,7 +2115,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
}
|
||||
}
|
||||
|
||||
ident.span = ident.span.modern();
|
||||
ident.span = ident.span.normalize_to_macros_2_0();
|
||||
let mut search_module = self.parent_scope.module;
|
||||
loop {
|
||||
self.get_traits_in_module_containing_item(ident, ns, search_module, &mut found_traits);
|
||||
|
@ -62,7 +62,7 @@ impl RegionExt for Region {
|
||||
let def_id = hir_map.local_def_id(param.hir_id);
|
||||
let origin = LifetimeDefOrigin::from_param(param);
|
||||
debug!("Region::early: index={} def_id={:?}", i, def_id);
|
||||
(param.name.modern(), Region::EarlyBound(i, def_id, origin))
|
||||
(param.name.normalize_to_macros_2_0(), Region::EarlyBound(i, def_id, origin))
|
||||
}
|
||||
|
||||
fn late(hir_map: &Map<'_>, param: &GenericParam<'_>) -> (ParamName, Region) {
|
||||
@ -73,7 +73,7 @@ impl RegionExt for Region {
|
||||
"Region::late: param={:?} depth={:?} def_id={:?} origin={:?}",
|
||||
param, depth, def_id, origin,
|
||||
);
|
||||
(param.name.modern(), Region::LateBound(depth, def_id, origin))
|
||||
(param.name.normalize_to_macros_2_0(), Region::LateBound(depth, def_id, origin))
|
||||
}
|
||||
|
||||
fn late_anon(index: &Cell<u32>) -> Region {
|
||||
@ -1174,7 +1174,9 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
|
||||
|
||||
Scope::Binder { ref lifetimes, s, .. } => {
|
||||
// FIXME (#24278): non-hygienic comparison
|
||||
if let Some(def) = lifetimes.get(&hir::ParamName::Plain(label.modern())) {
|
||||
if let Some(def) =
|
||||
lifetimes.get(&hir::ParamName::Plain(label.normalize_to_macros_2_0()))
|
||||
{
|
||||
let hir_id = tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap();
|
||||
|
||||
signal_shadowing_problem(
|
||||
@ -1253,7 +1255,7 @@ fn object_lifetime_defaults_for_item(
|
||||
fn add_bounds(set: &mut Set1<hir::LifetimeName>, bounds: &[hir::GenericBound<'_>]) {
|
||||
for bound in bounds {
|
||||
if let hir::GenericBound::Outlives(ref lifetime) = *bound {
|
||||
set.insert(lifetime.name.modern());
|
||||
set.insert(lifetime.name.normalize_to_macros_2_0());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1791,7 +1793,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
Scope::Binder { ref lifetimes, s, .. } => {
|
||||
match lifetime_ref.name {
|
||||
LifetimeName::Param(param_name) => {
|
||||
if let Some(&def) = lifetimes.get(¶m_name.modern()) {
|
||||
if let Some(&def) = lifetimes.get(¶m_name.normalize_to_macros_2_0())
|
||||
{
|
||||
break Some(def.shifted(late_depth));
|
||||
}
|
||||
}
|
||||
@ -2544,7 +2547,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
let lifetimes: Vec<_> = params
|
||||
.iter()
|
||||
.filter_map(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => Some((param, param.name.modern())),
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
Some((param, param.name.normalize_to_macros_2_0()))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
@ -2661,7 +2666,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
}
|
||||
|
||||
Scope::Binder { ref lifetimes, s, .. } => {
|
||||
if let Some(&def) = lifetimes.get(¶m.name.modern()) {
|
||||
if let Some(&def) = lifetimes.get(¶m.name.normalize_to_macros_2_0()) {
|
||||
let hir_id = self.tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap();
|
||||
|
||||
signal_shadowing_problem(
|
||||
@ -2799,7 +2804,7 @@ fn insert_late_bound_lifetimes(
|
||||
// `'a: 'b` means both `'a` and `'b` are referenced
|
||||
appears_in_where_clause
|
||||
.regions
|
||||
.insert(hir::LifetimeName::Param(param.name.modern()));
|
||||
.insert(hir::LifetimeName::Param(param.name.normalize_to_macros_2_0()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2821,7 +2826,7 @@ fn insert_late_bound_lifetimes(
|
||||
hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => continue,
|
||||
}
|
||||
|
||||
let lt_name = hir::LifetimeName::Param(param.name.modern());
|
||||
let lt_name = hir::LifetimeName::Param(param.name.normalize_to_macros_2_0());
|
||||
// appears in the where clauses? early-bound.
|
||||
if appears_in_where_clause.regions.contains(<_name) {
|
||||
continue;
|
||||
@ -2885,7 +2890,7 @@ fn insert_late_bound_lifetimes(
|
||||
}
|
||||
|
||||
fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
|
||||
self.regions.insert(lifetime_ref.name.modern());
|
||||
self.regions.insert(lifetime_ref.name.normalize_to_macros_2_0());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2902,7 +2907,7 @@ fn insert_late_bound_lifetimes(
|
||||
}
|
||||
|
||||
fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
|
||||
self.regions.insert(lifetime_ref.name.modern());
|
||||
self.regions.insert(lifetime_ref.name.normalize_to_macros_2_0());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ impl ModuleKind {
|
||||
/// program) if all but one of them come from glob imports.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
struct BindingKey {
|
||||
/// The identifier for the binding, aways the `modern` version of the
|
||||
/// The identifier for the binding, aways the `normalize_to_macros_2_0` version of the
|
||||
/// identifier.
|
||||
ident: Ident,
|
||||
ns: Namespace,
|
||||
@ -1362,7 +1362,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
|
||||
fn new_key(&mut self, ident: Ident, ns: Namespace) -> BindingKey {
|
||||
let ident = ident.modern();
|
||||
let ident = ident.normalize_to_macros_2_0();
|
||||
let disambiguator = if ident.name == kw::Underscore {
|
||||
self.underscore_disambiguator += 1;
|
||||
self.underscore_disambiguator
|
||||
@ -1413,7 +1413,7 @@ impl<'a> Resolver<'a> {
|
||||
// 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 {
|
||||
if let Some(entry) = self.extern_prelude.get(&ident.modern()) {
|
||||
if let Some(entry) = self.extern_prelude.get(&ident.normalize_to_macros_2_0()) {
|
||||
if let Some(crate_item) = entry.extern_crate_item {
|
||||
if ptr::eq(used_binding, crate_item) && !entry.introduced_by_item {
|
||||
return;
|
||||
@ -1500,7 +1500,7 @@ impl<'a> Resolver<'a> {
|
||||
TypeNS | ValueNS => Scope::Module(module),
|
||||
MacroNS => Scope::DeriveHelpers(parent_scope.expansion),
|
||||
};
|
||||
let mut ident = ident.modern();
|
||||
let mut ident = ident.normalize_to_macros_2_0();
|
||||
let mut use_prelude = !module.no_implicit_prelude;
|
||||
|
||||
loop {
|
||||
@ -1622,18 +1622,18 @@ impl<'a> Resolver<'a> {
|
||||
if ident.name == kw::Invalid {
|
||||
return Some(LexicalScopeBinding::Res(Res::Err));
|
||||
}
|
||||
let (general_span, modern_span) = if ident.name == kw::SelfUpper {
|
||||
let (general_span, normalized_span) = if ident.name == kw::SelfUpper {
|
||||
// FIXME(jseyfried) improve `Self` hygiene
|
||||
let empty_span = ident.span.with_ctxt(SyntaxContext::root());
|
||||
(empty_span, empty_span)
|
||||
} else if ns == TypeNS {
|
||||
let modern_span = ident.span.modern();
|
||||
(modern_span, modern_span)
|
||||
let normalized_span = ident.span.normalize_to_macros_2_0();
|
||||
(normalized_span, normalized_span)
|
||||
} else {
|
||||
(ident.span.modern_and_legacy(), ident.span.modern())
|
||||
(ident.span.normalize_to_macro_rules(), ident.span.normalize_to_macros_2_0())
|
||||
};
|
||||
ident.span = general_span;
|
||||
let modern_ident = Ident { span: modern_span, ..ident };
|
||||
let normalized_ident = Ident { span: normalized_span, ..ident };
|
||||
|
||||
// Walk backwards up the ribs in scope.
|
||||
let record_used = record_used_id.is_some();
|
||||
@ -1641,8 +1641,8 @@ impl<'a> Resolver<'a> {
|
||||
for i in (0..ribs.len()).rev() {
|
||||
debug!("walk rib\n{:?}", ribs[i].bindings);
|
||||
// Use the rib kind to determine whether we are resolving parameters
|
||||
// (modern hygiene) or local variables (`macro_rules` hygiene).
|
||||
let rib_ident = if ribs[i].kind.contains_params() { modern_ident } else { ident };
|
||||
// (macro 2.0 hygiene) or local variables (`macro_rules` hygiene).
|
||||
let rib_ident = if ribs[i].kind.contains_params() { normalized_ident } else { ident };
|
||||
if let Some(res) = ribs[i].bindings.get(&rib_ident).cloned() {
|
||||
// The ident resolves to a type parameter or local variable.
|
||||
return Some(LexicalScopeBinding::Res(self.validate_res_from_ribs(
|
||||
@ -1685,7 +1685,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
ident = modern_ident;
|
||||
ident = normalized_ident;
|
||||
let mut poisoned = None;
|
||||
loop {
|
||||
let opt_module = if let Some(node_id) = record_used_id {
|
||||
@ -1854,14 +1854,14 @@ impl<'a> Resolver<'a> {
|
||||
let mut adjusted_parent_scope = parent_scope;
|
||||
match module {
|
||||
ModuleOrUniformRoot::Module(m) => {
|
||||
if let Some(def) = ident.span.modernize_and_adjust(m.expansion) {
|
||||
if let Some(def) = ident.span.normalize_to_macros_2_0_and_adjust(m.expansion) {
|
||||
tmp_parent_scope =
|
||||
ParentScope { module: self.macro_def_scope(def), ..*parent_scope };
|
||||
adjusted_parent_scope = &tmp_parent_scope;
|
||||
}
|
||||
}
|
||||
ModuleOrUniformRoot::ExternPrelude => {
|
||||
ident.span.modernize_and_adjust(ExpnId::root());
|
||||
ident.span.normalize_to_macros_2_0_and_adjust(ExpnId::root());
|
||||
}
|
||||
ModuleOrUniformRoot::CrateRootAndExternPrelude | ModuleOrUniformRoot::CurrentScope => {
|
||||
// No adjustments
|
||||
@ -1884,14 +1884,14 @@ impl<'a> Resolver<'a> {
|
||||
let mark = if ident.name == kw::DollarCrate {
|
||||
// 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`
|
||||
// as described in `SyntaxContext::apply_mark`, so we ignore prepended modern marks.
|
||||
// as described in `SyntaxContext::apply_mark`, so we ignore prepended opaque marks.
|
||||
// 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.
|
||||
ctxt = ctxt.modern_and_legacy();
|
||||
ctxt = ctxt.normalize_to_macro_rules();
|
||||
let mut iter = ctxt.marks().into_iter().rev().peekable();
|
||||
let mut result = None;
|
||||
// Find the last modern mark from the end if it exists.
|
||||
// Find the last opaque mark from the end if it exists.
|
||||
while let Some(&(mark, transparency)) = iter.peek() {
|
||||
if transparency == Transparency::Opaque {
|
||||
result = Some(mark);
|
||||
@ -1910,7 +1910,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
result
|
||||
} else {
|
||||
ctxt = ctxt.modern();
|
||||
ctxt = ctxt.normalize_to_macros_2_0();
|
||||
ctxt.adjust(ExpnId::root())
|
||||
};
|
||||
let module = match mark {
|
||||
@ -1922,7 +1922,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
fn resolve_self(&mut self, ctxt: &mut SyntaxContext, module: Module<'a>) -> Module<'a> {
|
||||
let mut module = self.get_module(module.normal_ancestor_id);
|
||||
while module.span.ctxt().modern() != *ctxt {
|
||||
while module.span.ctxt().normalize_to_macros_2_0() != *ctxt {
|
||||
let parent = module.parent.unwrap_or_else(|| self.macro_def_scope(ctxt.remove_mark()));
|
||||
module = self.get_module(parent.normal_ancestor_id);
|
||||
}
|
||||
@ -1990,7 +1990,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
if ns == TypeNS {
|
||||
if allow_super && name == kw::Super {
|
||||
let mut ctxt = ident.span.ctxt().modern();
|
||||
let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
|
||||
let self_module = match i {
|
||||
0 => Some(self.resolve_self(&mut ctxt, parent_scope.module)),
|
||||
_ => match module {
|
||||
@ -2016,7 +2016,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
if i == 0 {
|
||||
if name == kw::SelfLower {
|
||||
let mut ctxt = ident.span.ctxt().modern();
|
||||
let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
|
||||
module = Some(ModuleOrUniformRoot::Module(
|
||||
self.resolve_self(&mut ctxt, parent_scope.module),
|
||||
));
|
||||
@ -2430,7 +2430,7 @@ impl<'a> Resolver<'a> {
|
||||
macro_rules: &'a NameBinding<'a>,
|
||||
modularized: &'a NameBinding<'a>,
|
||||
) -> bool {
|
||||
// Some non-controversial subset of ambiguities "modern macro name" vs "macro_rules"
|
||||
// Some non-controversial subset of ambiguities "modularized macro name" vs "macro_rules"
|
||||
// is disambiguated to mitigate regressions from macro modularization.
|
||||
// Scoping for `macro_rules` behaves like scoping for `let` at module level, in general.
|
||||
match (
|
||||
@ -2769,7 +2769,7 @@ impl<'a> Resolver<'a> {
|
||||
// Make sure `self`, `super` etc produce an error when passed to here.
|
||||
return None;
|
||||
}
|
||||
self.extern_prelude.get(&ident.modern()).cloned().and_then(|entry| {
|
||||
self.extern_prelude.get(&ident.normalize_to_macros_2_0()).cloned().and_then(|entry| {
|
||||
if let Some(binding) = entry.extern_crate_item {
|
||||
if !speculative && entry.introduced_by_item {
|
||||
self.record_use(ident, TypeNS, binding, false);
|
||||
|
@ -258,7 +258,13 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||
force,
|
||||
) {
|
||||
Ok((Some(ext), _)) => {
|
||||
let span = path.segments.last().unwrap().ident.span.modern();
|
||||
let span = path
|
||||
.segments
|
||||
.last()
|
||||
.unwrap()
|
||||
.ident
|
||||
.span
|
||||
.normalize_to_macros_2_0();
|
||||
helper_attrs.extend(
|
||||
ext.helper_attrs.iter().map(|name| Ident::new(*name, span)),
|
||||
);
|
||||
|
@ -201,11 +201,11 @@ impl HygieneData {
|
||||
true
|
||||
}
|
||||
|
||||
fn modern(&self, ctxt: SyntaxContext) -> SyntaxContext {
|
||||
fn normalize_to_macros_2_0(&self, ctxt: SyntaxContext) -> SyntaxContext {
|
||||
self.syntax_context_data[ctxt.0 as usize].opaque
|
||||
}
|
||||
|
||||
fn modern_and_legacy(&self, ctxt: SyntaxContext) -> SyntaxContext {
|
||||
fn normalize_to_macro_rules(&self, ctxt: SyntaxContext) -> SyntaxContext {
|
||||
self.syntax_context_data[ctxt.0 as usize].opaque_and_semitransparent
|
||||
}
|
||||
|
||||
@ -266,9 +266,9 @@ impl HygieneData {
|
||||
|
||||
let call_site_ctxt = self.expn_data(expn_id).call_site.ctxt();
|
||||
let mut call_site_ctxt = if transparency == Transparency::SemiTransparent {
|
||||
self.modern(call_site_ctxt)
|
||||
self.normalize_to_macros_2_0(call_site_ctxt)
|
||||
} else {
|
||||
self.modern_and_legacy(call_site_ctxt)
|
||||
self.normalize_to_macro_rules(call_site_ctxt)
|
||||
};
|
||||
|
||||
if call_site_ctxt == SyntaxContext::root() {
|
||||
@ -491,10 +491,10 @@ impl SyntaxContext {
|
||||
HygieneData::with(|data| data.adjust(self, expn_id))
|
||||
}
|
||||
|
||||
/// Like `SyntaxContext::adjust`, but also modernizes `self`.
|
||||
pub fn modernize_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
|
||||
/// Like `SyntaxContext::adjust`, but also normalizes `self` to macros 2.0.
|
||||
pub fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
|
||||
HygieneData::with(|data| {
|
||||
*self = data.modern(*self);
|
||||
*self = data.normalize_to_macros_2_0(*self);
|
||||
data.adjust(self, expn_id)
|
||||
})
|
||||
}
|
||||
@ -527,7 +527,7 @@ impl SyntaxContext {
|
||||
pub fn glob_adjust(&mut self, expn_id: ExpnId, glob_span: Span) -> Option<Option<ExpnId>> {
|
||||
HygieneData::with(|data| {
|
||||
let mut scope = None;
|
||||
let mut glob_ctxt = data.modern(glob_span.ctxt());
|
||||
let mut glob_ctxt = data.normalize_to_macros_2_0(glob_span.ctxt());
|
||||
while !data.is_descendant_of(expn_id, data.outer_expn(glob_ctxt)) {
|
||||
scope = Some(data.remove_mark(&mut glob_ctxt).0);
|
||||
if data.remove_mark(self).0 != scope.unwrap() {
|
||||
@ -558,7 +558,7 @@ impl SyntaxContext {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut glob_ctxt = data.modern(glob_span.ctxt());
|
||||
let mut glob_ctxt = data.normalize_to_macros_2_0(glob_span.ctxt());
|
||||
let mut marks = Vec::new();
|
||||
while !data.is_descendant_of(expn_id, data.outer_expn(glob_ctxt)) {
|
||||
marks.push(data.remove_mark(&mut glob_ctxt));
|
||||
@ -574,20 +574,20 @@ impl SyntaxContext {
|
||||
|
||||
pub fn hygienic_eq(self, other: SyntaxContext, expn_id: ExpnId) -> bool {
|
||||
HygieneData::with(|data| {
|
||||
let mut self_modern = data.modern(self);
|
||||
data.adjust(&mut self_modern, expn_id);
|
||||
self_modern == data.modern(other)
|
||||
let mut self_normalized = data.normalize_to_macros_2_0(self);
|
||||
data.adjust(&mut self_normalized, expn_id);
|
||||
self_normalized == data.normalize_to_macros_2_0(other)
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn modern(self) -> SyntaxContext {
|
||||
HygieneData::with(|data| data.modern(self))
|
||||
pub fn normalize_to_macros_2_0(self) -> SyntaxContext {
|
||||
HygieneData::with(|data| data.normalize_to_macros_2_0(self))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn modern_and_legacy(self) -> SyntaxContext {
|
||||
HygieneData::with(|data| data.modern_and_legacy(self))
|
||||
pub fn normalize_to_macro_rules(self) -> SyntaxContext {
|
||||
HygieneData::with(|data| data.normalize_to_macro_rules(self))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -548,9 +548,9 @@ impl Span {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn modernize_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
|
||||
pub fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
|
||||
let mut span = self.data();
|
||||
let mark = span.ctxt.modernize_and_adjust(expn_id);
|
||||
let mark = span.ctxt.normalize_to_macros_2_0_and_adjust(expn_id);
|
||||
*self = Span::new(span.lo, span.hi, span.ctxt);
|
||||
mark
|
||||
}
|
||||
@ -576,15 +576,15 @@ impl Span {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn modern(self) -> Span {
|
||||
pub fn normalize_to_macros_2_0(self) -> Span {
|
||||
let span = self.data();
|
||||
span.with_ctxt(span.ctxt.modern())
|
||||
span.with_ctxt(span.ctxt.normalize_to_macros_2_0())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn modern_and_legacy(self) -> Span {
|
||||
pub fn normalize_to_macro_rules(self) -> Span {
|
||||
let span = self.data();
|
||||
span.with_ctxt(span.ctxt.modern_and_legacy())
|
||||
span.with_ctxt(span.ctxt.normalize_to_macro_rules())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -853,12 +853,12 @@ impl Ident {
|
||||
}
|
||||
|
||||
/// "Normalize" ident for use in comparisons using "item hygiene".
|
||||
/// Identifiers with same string value become same if they came from the same "modern" macro
|
||||
/// Identifiers with same string value become same if they came from the same macro 2.0 macro
|
||||
/// (e.g., `macro` item, but not `macro_rules` item) and stay different if they came from
|
||||
/// different "modern" macros.
|
||||
/// different macro 2.0 macros.
|
||||
/// Technically, this operation strips all non-opaque marks from ident's syntactic context.
|
||||
pub fn modern(self) -> Ident {
|
||||
Ident::new(self.name, self.span.modern())
|
||||
pub fn normalize_to_macros_2_0(self) -> Ident {
|
||||
Ident::new(self.name, self.span.normalize_to_macros_2_0())
|
||||
}
|
||||
|
||||
/// "Normalize" ident for use in comparisons using "local variable hygiene".
|
||||
@ -866,8 +866,8 @@ impl Ident {
|
||||
/// macro (e.g., `macro` or `macro_rules!` items) and stay different if they came from different
|
||||
/// non-transparent macros.
|
||||
/// Technically, this operation strips all transparent marks from ident's syntactic context.
|
||||
pub fn modern_and_legacy(self) -> Ident {
|
||||
Ident::new(self.name, self.span.modern_and_legacy())
|
||||
pub fn normalize_to_macro_rules(self) -> Ident {
|
||||
Ident::new(self.name, self.span.normalize_to_macro_rules())
|
||||
}
|
||||
|
||||
/// Convert the name to a `SymbolStr`. This is a slowish operation because
|
||||
|
@ -1441,12 +1441,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
let (assoc_ident, def_scope) =
|
||||
tcx.adjust_ident_and_get_scope(binding.item_name, candidate.def_id(), hir_ref_id);
|
||||
|
||||
// We have already adjusted the item name above, so compare with `ident.modern()` instead
|
||||
// We have already adjusted the item name above, so compare with `ident.normalize_to_macros_2_0()` instead
|
||||
// of calling `filter_by_name_and_kind`.
|
||||
let assoc_ty = tcx
|
||||
.associated_items(candidate.def_id())
|
||||
.filter_by_name_unhygienic(assoc_ident.name)
|
||||
.find(|i| i.kind == ty::AssocKind::Type && i.ident.modern() == assoc_ident)
|
||||
.find(|i| {
|
||||
i.kind == ty::AssocKind::Type && i.ident.normalize_to_macros_2_0() == assoc_ident
|
||||
})
|
||||
.expect("missing associated type");
|
||||
|
||||
if !assoc_ty.vis.is_accessible_from(def_scope, tcx) {
|
||||
@ -2298,12 +2300,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
let (assoc_ident, def_scope) =
|
||||
tcx.adjust_ident_and_get_scope(assoc_ident, trait_did, hir_ref_id);
|
||||
|
||||
// We have already adjusted the item name above, so compare with `ident.modern()` instead
|
||||
// We have already adjusted the item name above, so compare with `ident.normalize_to_macros_2_0()` instead
|
||||
// of calling `filter_by_name_and_kind`.
|
||||
let item = tcx
|
||||
.associated_items(trait_did)
|
||||
.in_definition_order()
|
||||
.find(|i| i.kind.namespace() == Namespace::TypeNS && i.ident.modern() == assoc_ident)
|
||||
.find(|i| {
|
||||
i.kind.namespace() == Namespace::TypeNS
|
||||
&& i.ident.normalize_to_macros_2_0() == assoc_ident
|
||||
})
|
||||
.expect("missing associated type");
|
||||
|
||||
let ty = self.projected_ty_from_poly_trait_ref(span, item.def_id, assoc_segment, bound);
|
||||
|
@ -1203,7 +1203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
.fields
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, field)| (field.ident.modern(), (i, field)))
|
||||
.map(|(i, field)| (field.ident.normalize_to_macros_2_0(), (i, field)))
|
||||
.collect::<FxHashMap<_, _>>();
|
||||
|
||||
let mut seen_fields = FxHashMap::default();
|
||||
@ -1469,7 +1469,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let (ident, def_scope) =
|
||||
self.tcx.adjust_ident_and_get_scope(field, base_def.did, self.body_id);
|
||||
let fields = &base_def.non_enum_variant().fields;
|
||||
if let Some(index) = fields.iter().position(|f| f.ident.modern() == ident) {
|
||||
if let Some(index) =
|
||||
fields.iter().position(|f| f.ident.normalize_to_macros_2_0() == ident)
|
||||
{
|
||||
let field = &fields[index];
|
||||
let field_ty = self.field_ty(expr.span, field, substs);
|
||||
// Save the index of all fields regardless of their visibility in case
|
||||
|
@ -1023,7 +1023,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
.fields
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, field)| (field.ident.modern(), (i, field)))
|
||||
.map(|(i, field)| (field.ident.normalize_to_macros_2_0(), (i, field)))
|
||||
.collect::<FxHashMap<_, _>>();
|
||||
|
||||
// Keep track of which fields have already appeared in the pattern.
|
||||
@ -1064,7 +1064,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let mut unmentioned_fields = variant
|
||||
.fields
|
||||
.iter()
|
||||
.map(|field| field.ident.modern())
|
||||
.map(|field| field.ident.normalize_to_macros_2_0())
|
||||
.filter(|ident| !used_fields.contains_key(&ident))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -26,7 +26,8 @@ impl InherentOverlapChecker<'tcx> {
|
||||
let collision = impl_items2.filter_by_name_unhygienic(item1.ident.name).any(|item2| {
|
||||
// Symbols and namespace match, compare hygienically.
|
||||
item1.kind.namespace() == item2.kind.namespace()
|
||||
&& item1.ident.modern() == item2.ident.modern()
|
||||
&& item1.ident.normalize_to_macros_2_0()
|
||||
== item2.ident.normalize_to_macros_2_0()
|
||||
});
|
||||
|
||||
if collision {
|
||||
@ -50,11 +51,12 @@ impl InherentOverlapChecker<'tcx> {
|
||||
let collision = impl_items2.filter_by_name_unhygienic(item1.ident.name).find(|item2| {
|
||||
// Symbols and namespace match, compare hygienically.
|
||||
item1.kind.namespace() == item2.kind.namespace()
|
||||
&& item1.ident.modern() == item2.ident.modern()
|
||||
&& item1.ident.normalize_to_macros_2_0()
|
||||
== item2.ident.normalize_to_macros_2_0()
|
||||
});
|
||||
|
||||
if let Some(item2) = collision {
|
||||
let name = item1.ident.modern();
|
||||
let name = item1.ident.normalize_to_macros_2_0();
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
self.tcx.span_of_impl(item1.def_id).unwrap(),
|
||||
|
@ -828,7 +828,7 @@ fn convert_variant(
|
||||
.iter()
|
||||
.map(|f| {
|
||||
let fid = tcx.hir().local_def_id(f.hir_id);
|
||||
let dup_span = seen_fields.get(&f.ident.modern()).cloned();
|
||||
let dup_span = seen_fields.get(&f.ident.normalize_to_macros_2_0()).cloned();
|
||||
if let Some(prev_span) = dup_span {
|
||||
struct_span_err!(
|
||||
tcx.sess,
|
||||
@ -841,7 +841,7 @@ fn convert_variant(
|
||||
.span_label(prev_span, format!("`{}` first declared here", f.ident))
|
||||
.emit();
|
||||
} else {
|
||||
seen_fields.insert(f.ident.modern(), f.span);
|
||||
seen_fields.insert(f.ident.normalize_to_macros_2_0(), f.span);
|
||||
}
|
||||
|
||||
ty::FieldDef {
|
||||
|
@ -227,7 +227,7 @@ fn enforce_impl_items_are_distinct(tcx: TyCtxt<'_>, impl_item_refs: &[hir::ImplI
|
||||
hir::ImplItemKind::TyAlias(_) => &mut seen_type_items,
|
||||
_ => &mut seen_value_items,
|
||||
};
|
||||
match seen_items.entry(impl_item.ident.modern()) {
|
||||
match seen_items.entry(impl_item.ident.normalize_to_macros_2_0()) {
|
||||
Occupied(entry) => {
|
||||
let mut err = struct_span_err!(
|
||||
tcx.sess,
|
||||
|
Loading…
Reference in New Issue
Block a user