Prepare for adding a TyCtxt
to Resolver
This commit is contained in:
parent
7e253a7fb2
commit
d191de63f0
9 changed files with 247 additions and 194 deletions
|
@ -133,8 +133,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
Some(self.new_module(
|
Some(self.new_module(
|
||||||
parent,
|
parent,
|
||||||
ModuleKind::Def(def_kind, def_id, name),
|
ModuleKind::Def(def_kind, def_id, name),
|
||||||
self.cstore().module_expansion_untracked(def_id, &self.session),
|
self.cstore().module_expansion_untracked(def_id, &self.tcx.sess),
|
||||||
self.cstore().get_span_untracked(def_id, &self.session),
|
self.cstore().get_span_untracked(def_id, &self.tcx.sess),
|
||||||
// FIXME: Account for `#[no_implicit_prelude]` attributes.
|
// FIXME: Account for `#[no_implicit_prelude]` attributes.
|
||||||
parent.map_or(false, |module| module.no_implicit_prelude),
|
parent.map_or(false, |module| module.no_implicit_prelude),
|
||||||
))
|
))
|
||||||
|
@ -179,7 +179,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
return macro_data.clone();
|
return macro_data.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
let (ext, macro_rules) = match self.cstore().load_macro_untracked(def_id, &self.session) {
|
let (ext, macro_rules) = match self.cstore().load_macro_untracked(def_id, &self.tcx.sess) {
|
||||||
LoadedMacro::MacroDef(item, edition) => (
|
LoadedMacro::MacroDef(item, edition) => (
|
||||||
Lrc::new(self.compile_macro(&item, edition).0),
|
Lrc::new(self.compile_macro(&item, edition).0),
|
||||||
matches!(item.kind, ItemKind::MacroDef(def) if def.macro_rules),
|
matches!(item.kind, ItemKind::MacroDef(def) if def.macro_rules),
|
||||||
|
@ -205,7 +205,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
|
pub(crate) fn build_reduced_graph_external(&mut self, module: Module<'a>) {
|
||||||
for child in
|
for child in
|
||||||
Vec::from_iter(self.cstore().module_children_untracked(module.def_id(), self.session))
|
Vec::from_iter(self.cstore().module_children_untracked(module.def_id(), self.tcx.sess))
|
||||||
{
|
{
|
||||||
let parent_scope = ParentScope::module(module, self);
|
let parent_scope = ParentScope::module(module, self);
|
||||||
BuildReducedGraphVisitor { r: self, parent_scope }
|
BuildReducedGraphVisitor { r: self, parent_scope }
|
||||||
|
@ -346,7 +346,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
|
|
||||||
fn insert_field_names_extern(&mut self, def_id: DefId) {
|
fn insert_field_names_extern(&mut self, def_id: DefId) {
|
||||||
let field_names =
|
let field_names =
|
||||||
self.r.cstore().struct_field_names_untracked(def_id, self.r.session).collect();
|
self.r.cstore().struct_field_names_untracked(def_id, self.r.tcx.sess).collect();
|
||||||
self.r.field_names.insert(def_id, field_names);
|
self.r.field_names.insert(def_id, field_names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -539,14 +539,15 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.r
|
self.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.struct_span_err(item.span, "`$crate` may not be imported")
|
.struct_span_err(item.span, "`$crate` may not be imported")
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ident.name == kw::Crate {
|
if ident.name == kw::Crate {
|
||||||
self.r.session.span_err(
|
self.r.tcx.sess.span_err(
|
||||||
ident.span,
|
ident.span,
|
||||||
"crate root imports need to be explicitly named: \
|
"crate root imports need to be explicitly named: \
|
||||||
`use crate as name;`",
|
`use crate as name;`",
|
||||||
|
@ -575,7 +576,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
ast::UseTreeKind::Glob => {
|
ast::UseTreeKind::Glob => {
|
||||||
let kind = ImportKind::Glob {
|
let kind = ImportKind::Glob {
|
||||||
is_prelude: self.r.session.contains_name(&item.attrs, sym::prelude_import),
|
is_prelude: self.r.tcx.sess.contains_name(&item.attrs, sym::prelude_import),
|
||||||
max_vis: Cell::new(None),
|
max_vis: Cell::new(None),
|
||||||
id,
|
id,
|
||||||
};
|
};
|
||||||
|
@ -690,7 +691,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
expansion.to_expn_id(),
|
expansion.to_expn_id(),
|
||||||
item.span,
|
item.span,
|
||||||
parent.no_implicit_prelude
|
parent.no_implicit_prelude
|
||||||
|| self.r.session.contains_name(&item.attrs, sym::no_implicit_prelude),
|
|| self.r.tcx.sess.contains_name(&item.attrs, sym::no_implicit_prelude),
|
||||||
);
|
);
|
||||||
self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion));
|
self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion));
|
||||||
|
|
||||||
|
@ -755,7 +756,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
// If the structure is marked as non_exhaustive then lower the visibility
|
// If the structure is marked as non_exhaustive then lower the visibility
|
||||||
// to within the crate.
|
// to within the crate.
|
||||||
let mut ctor_vis = if vis.is_public()
|
let mut ctor_vis = if vis.is_public()
|
||||||
&& self.r.session.contains_name(&item.attrs, sym::non_exhaustive)
|
&& self.r.tcx.sess.contains_name(&item.attrs, sym::non_exhaustive)
|
||||||
{
|
{
|
||||||
ty::Visibility::Restricted(CRATE_DEF_ID)
|
ty::Visibility::Restricted(CRATE_DEF_ID)
|
||||||
} else {
|
} else {
|
||||||
|
@ -837,7 +838,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
|
|
||||||
let (used, module, binding) = if orig_name.is_none() && ident.name == kw::SelfLower {
|
let (used, module, binding) = if orig_name.is_none() && ident.name == kw::SelfLower {
|
||||||
self.r
|
self.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.struct_span_err(item.span, "`extern crate self;` requires renaming")
|
.struct_span_err(item.span, "`extern crate self;` requires renaming")
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
item.span,
|
item.span,
|
||||||
|
@ -887,7 +889,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
{
|
{
|
||||||
let msg = "macro-expanded `extern crate` items cannot \
|
let msg = "macro-expanded `extern crate` items cannot \
|
||||||
shadow names passed with `--extern`";
|
shadow names passed with `--extern`";
|
||||||
self.r.session.span_err(item.span, msg);
|
self.r.tcx.sess.span_err(item.span, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let entry = self.r.extern_prelude.entry(ident.normalize_to_macros_2_0()).or_insert(
|
let entry = self.r.extern_prelude.entry(ident.normalize_to_macros_2_0()).or_insert(
|
||||||
|
@ -1014,7 +1016,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::Union, def_id) => self.insert_field_names_extern(def_id),
|
Res::Def(DefKind::Union, def_id) => self.insert_field_names_extern(def_id),
|
||||||
Res::Def(DefKind::AssocFn, def_id) => {
|
Res::Def(DefKind::AssocFn, def_id) => {
|
||||||
if cstore.fn_has_self_parameter_untracked(def_id, self.r.session) {
|
if cstore.fn_has_self_parameter_untracked(def_id, self.r.tcx.sess) {
|
||||||
self.r.has_self.insert(def_id);
|
self.r.has_self.insert(def_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1033,7 +1035,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
let msg = format!("`{}` is already in scope", name);
|
let msg = format!("`{}` is already in scope", name);
|
||||||
let note =
|
let note =
|
||||||
"macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)";
|
"macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)";
|
||||||
self.r.session.struct_span_err(span, &msg).note(note).emit();
|
self.r.tcx.sess.struct_span_err(span, &msg).note(note).emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1045,7 +1047,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
if attr.has_name(sym::macro_use) {
|
if attr.has_name(sym::macro_use) {
|
||||||
if self.parent_scope.module.parent.is_some() {
|
if self.parent_scope.module.parent.is_some() {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
item.span,
|
item.span,
|
||||||
E0468,
|
E0468,
|
||||||
"an `extern crate` loading macros must be at the crate root"
|
"an `extern crate` loading macros must be at the crate root"
|
||||||
|
@ -1055,7 +1057,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
if let ItemKind::ExternCrate(Some(orig_name)) = item.kind {
|
if let ItemKind::ExternCrate(Some(orig_name)) = item.kind {
|
||||||
if orig_name == kw::SelfLower {
|
if orig_name == kw::SelfLower {
|
||||||
self.r
|
self.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.struct_span_err(
|
.struct_span_err(
|
||||||
attr.span,
|
attr.span,
|
||||||
"`#[macro_use]` is not supported on `extern crate self`",
|
"`#[macro_use]` is not supported on `extern crate self`",
|
||||||
|
@ -1064,7 +1067,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let ill_formed = |span| {
|
let ill_formed = |span| {
|
||||||
struct_span_err!(self.r.session, span, E0466, "bad macro import").emit();
|
struct_span_err!(self.r.tcx.sess, span, E0466, "bad macro import").emit();
|
||||||
};
|
};
|
||||||
match attr.meta() {
|
match attr.meta() {
|
||||||
Some(meta) => match meta.kind {
|
Some(meta) => match meta.kind {
|
||||||
|
@ -1135,8 +1138,13 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
allow_shadowing,
|
allow_shadowing,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
struct_span_err!(self.r.session, ident.span, E0469, "imported macro not found")
|
struct_span_err!(
|
||||||
.emit();
|
self.r.tcx.sess,
|
||||||
|
ident.span,
|
||||||
|
E0469,
|
||||||
|
"imported macro not found"
|
||||||
|
)
|
||||||
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1148,7 +1156,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
if attr.has_name(sym::macro_escape) {
|
if attr.has_name(sym::macro_escape) {
|
||||||
let msg = "`#[macro_escape]` is a deprecated synonym for `#[macro_use]`";
|
let msg = "`#[macro_escape]` is a deprecated synonym for `#[macro_use]`";
|
||||||
let mut err = self.r.session.struct_span_warn(attr.span, msg);
|
let mut err = self.r.tcx.sess.struct_span_warn(attr.span, msg);
|
||||||
if let ast::AttrStyle::Inner = attr.style {
|
if let ast::AttrStyle::Inner = attr.style {
|
||||||
err.help("try an outer attribute: `#[macro_use]`").emit();
|
err.help("try an outer attribute: `#[macro_use]`").emit();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1159,7 +1167,10 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !attr.is_word() {
|
if !attr.is_word() {
|
||||||
self.r.session.span_err(attr.span, "arguments to `macro_use` are not allowed here");
|
self.r
|
||||||
|
.tcx
|
||||||
|
.sess
|
||||||
|
.span_err(attr.span, "arguments to `macro_use` are not allowed here");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1183,11 +1194,11 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn proc_macro_stub(&self, item: &ast::Item) -> Option<(MacroKind, Ident, Span)> {
|
fn proc_macro_stub(&self, item: &ast::Item) -> Option<(MacroKind, Ident, Span)> {
|
||||||
if self.r.session.contains_name(&item.attrs, sym::proc_macro) {
|
if self.r.tcx.sess.contains_name(&item.attrs, sym::proc_macro) {
|
||||||
return Some((MacroKind::Bang, item.ident, item.span));
|
return Some((MacroKind::Bang, item.ident, item.span));
|
||||||
} else if self.r.session.contains_name(&item.attrs, sym::proc_macro_attribute) {
|
} else if self.r.tcx.sess.contains_name(&item.attrs, sym::proc_macro_attribute) {
|
||||||
return Some((MacroKind::Attr, item.ident, item.span));
|
return Some((MacroKind::Attr, item.ident, item.span));
|
||||||
} else if let Some(attr) = self.r.session.find_by_name(&item.attrs, sym::proc_macro_derive)
|
} else if let Some(attr) = self.r.tcx.sess.find_by_name(&item.attrs, sym::proc_macro_derive)
|
||||||
{
|
{
|
||||||
if let Some(nested_meta) = attr.meta_item_list().and_then(|list| list.get(0).cloned()) {
|
if let Some(nested_meta) = attr.meta_item_list().and_then(|list| list.get(0).cloned()) {
|
||||||
if let Some(ident) = nested_meta.ident() {
|
if let Some(ident) = nested_meta.ident() {
|
||||||
|
@ -1222,7 +1233,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
let def_id = self.r.local_def_id(item.id);
|
let def_id = self.r.local_def_id(item.id);
|
||||||
let (ext, ident, span, macro_rules, rule_spans) = match &item.kind {
|
let (ext, ident, span, macro_rules, rule_spans) = match &item.kind {
|
||||||
ItemKind::MacroDef(def) => {
|
ItemKind::MacroDef(def) => {
|
||||||
let (ext, rule_spans) = self.r.compile_macro(item, self.r.session.edition());
|
let (ext, rule_spans) = self.r.compile_macro(item, self.r.tcx.sess.edition());
|
||||||
let ext = Lrc::new(ext);
|
let ext = Lrc::new(ext);
|
||||||
(ext, item.ident, item.span, def.macro_rules, rule_spans)
|
(ext, item.ident, item.span, def.macro_rules, rule_spans)
|
||||||
}
|
}
|
||||||
|
@ -1243,7 +1254,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
if macro_rules {
|
if macro_rules {
|
||||||
let ident = ident.normalize_to_macros_2_0();
|
let ident = ident.normalize_to_macros_2_0();
|
||||||
self.r.macro_names.insert(ident);
|
self.r.macro_names.insert(ident);
|
||||||
let is_macro_export = self.r.session.contains_name(&item.attrs, sym::macro_export);
|
let is_macro_export = self.r.tcx.sess.contains_name(&item.attrs, sym::macro_export);
|
||||||
let vis = if is_macro_export {
|
let vis = if is_macro_export {
|
||||||
ty::Visibility::Public
|
ty::Visibility::Public
|
||||||
} else {
|
} else {
|
||||||
|
@ -1507,7 +1518,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||||
|
|
||||||
// If the variant is marked as non_exhaustive then lower the visibility to within the crate.
|
// If the variant is marked as non_exhaustive then lower the visibility to within the crate.
|
||||||
let ctor_vis = if vis.is_public()
|
let ctor_vis = if vis.is_public()
|
||||||
&& self.r.session.contains_name(&variant.attrs, sym::non_exhaustive)
|
&& self.r.tcx.sess.contains_name(&variant.attrs, sym::non_exhaustive)
|
||||||
{
|
{
|
||||||
ty::Visibility::Restricted(CRATE_DEF_ID)
|
ty::Visibility::Restricted(CRATE_DEF_ID)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -290,7 +290,7 @@ impl Resolver<'_, '_> {
|
||||||
let ms = MultiSpan::from_spans(spans.clone());
|
let ms = MultiSpan::from_spans(spans.clone());
|
||||||
let mut span_snippets = spans
|
let mut span_snippets = spans
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|s| match visitor.r.session.source_map().span_to_snippet(*s) {
|
.filter_map(|s| match visitor.r.tcx.sess.source_map().span_to_snippet(*s) {
|
||||||
Ok(s) => Some(format!("`{}`", s)),
|
Ok(s) => Some(format!("`{}`", s)),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
|
@ -317,7 +317,7 @@ impl Resolver<'_, '_> {
|
||||||
// If we are in the `--test` mode, suppress a help that adds the `#[cfg(test)]`
|
// If we are in the `--test` mode, suppress a help that adds the `#[cfg(test)]`
|
||||||
// attribute; however, if not, suggest adding the attribute. There is no way to
|
// attribute; however, if not, suggest adding the attribute. There is no way to
|
||||||
// retrieve attributes here because we do not have a `TyCtxt` yet.
|
// retrieve attributes here because we do not have a `TyCtxt` yet.
|
||||||
let test_module_span = if visitor.r.session.opts.test {
|
let test_module_span = if visitor.r.tcx.sess.opts.test {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let parent_module = visitor.r.get_nearest_non_block_module(
|
let parent_module = visitor.r.get_nearest_non_block_module(
|
||||||
|
|
|
@ -154,7 +154,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
if !candidates.is_empty() {
|
if !candidates.is_empty() {
|
||||||
show_candidates(
|
show_candidates(
|
||||||
&self.session,
|
&self.tcx.sess,
|
||||||
&self.untracked.source_span,
|
&self.untracked.source_span,
|
||||||
&mut err,
|
&mut err,
|
||||||
span,
|
span,
|
||||||
|
@ -206,7 +206,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let (name, span) =
|
let (name, span) =
|
||||||
(ident.name, self.session.source_map().guess_head_span(new_binding.span));
|
(ident.name, self.tcx.sess.source_map().guess_head_span(new_binding.span));
|
||||||
|
|
||||||
if let Some(s) = self.name_already_seen.get(&name) {
|
if let Some(s) = self.name_already_seen.get(&name) {
|
||||||
if s == &span {
|
if s == &span {
|
||||||
|
@ -226,15 +226,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
let msg = format!("the name `{}` is defined multiple times", name);
|
let msg = format!("the name `{}` is defined multiple times", name);
|
||||||
|
|
||||||
let mut err = match (old_binding.is_extern_crate(), new_binding.is_extern_crate()) {
|
let mut err = match (old_binding.is_extern_crate(), new_binding.is_extern_crate()) {
|
||||||
(true, true) => struct_span_err!(self.session, span, E0259, "{}", msg),
|
(true, true) => struct_span_err!(self.tcx.sess, span, E0259, "{}", msg),
|
||||||
(true, _) | (_, true) => match new_binding.is_import() && old_binding.is_import() {
|
(true, _) | (_, true) => match new_binding.is_import() && old_binding.is_import() {
|
||||||
true => struct_span_err!(self.session, span, E0254, "{}", msg),
|
true => struct_span_err!(self.tcx.sess, span, E0254, "{}", msg),
|
||||||
false => struct_span_err!(self.session, span, E0260, "{}", msg),
|
false => struct_span_err!(self.tcx.sess, span, E0260, "{}", msg),
|
||||||
},
|
},
|
||||||
_ => match (old_binding.is_import_user_facing(), new_binding.is_import_user_facing()) {
|
_ => match (old_binding.is_import_user_facing(), new_binding.is_import_user_facing()) {
|
||||||
(false, false) => struct_span_err!(self.session, span, E0428, "{}", msg),
|
(false, false) => struct_span_err!(self.tcx.sess, span, E0428, "{}", msg),
|
||||||
(true, true) => struct_span_err!(self.session, span, E0252, "{}", msg),
|
(true, true) => struct_span_err!(self.tcx.sess, span, E0252, "{}", msg),
|
||||||
_ => struct_span_err!(self.session, span, E0255, "{}", msg),
|
_ => struct_span_err!(self.tcx.sess, span, E0255, "{}", msg),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
err.span_label(span, format!("`{}` re{} here", name, new_participle));
|
err.span_label(span, format!("`{}` re{} here", name, new_participle));
|
||||||
if !old_binding.span.is_dummy() && old_binding.span != span {
|
if !old_binding.span.is_dummy() && old_binding.span != span {
|
||||||
err.span_label(
|
err.span_label(
|
||||||
self.session.source_map().guess_head_span(old_binding.span),
|
self.tcx.sess.source_map().guess_head_span(old_binding.span),
|
||||||
format!("previous {} of the {} `{}` here", old_noun, old_kind, name),
|
format!("previous {} of the {} `{}` here", old_noun, old_kind, name),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
if let Some(pos) =
|
if let Some(pos) =
|
||||||
source.span.hi().0.checked_sub(binding_span.lo().0).map(|pos| pos as usize)
|
source.span.hi().0.checked_sub(binding_span.lo().0).map(|pos| pos as usize)
|
||||||
{
|
{
|
||||||
if let Ok(snippet) = self.session.source_map().span_to_snippet(binding_span) {
|
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(binding_span) {
|
||||||
if pos <= snippet.len() {
|
if pos <= snippet.len() {
|
||||||
suggestion = Some(format!(
|
suggestion = Some(format!(
|
||||||
"{} as {}{}",
|
"{} as {}{}",
|
||||||
|
@ -426,12 +426,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
// `a` and `import.use_span` is `issue_52891::{d, e, a};`.
|
// `a` and `import.use_span` is `issue_52891::{d, e, a};`.
|
||||||
|
|
||||||
let (found_closing_brace, span) =
|
let (found_closing_brace, span) =
|
||||||
find_span_of_binding_until_next_binding(self.session, binding_span, import.use_span);
|
find_span_of_binding_until_next_binding(self.tcx.sess, binding_span, import.use_span);
|
||||||
|
|
||||||
// If there was a closing brace then identify the span to remove any trailing commas from
|
// If there was a closing brace then identify the span to remove any trailing commas from
|
||||||
// previous imports.
|
// previous imports.
|
||||||
if found_closing_brace {
|
if found_closing_brace {
|
||||||
if let Some(span) = extend_span_to_previous_binding(self.session, span) {
|
if let Some(span) = extend_span_to_previous_binding(self.tcx.sess, span) {
|
||||||
err.tool_only_span_suggestion(span, message, "", Applicability::MaybeIncorrect);
|
err.tool_only_span_suggestion(span, message, "", Applicability::MaybeIncorrect);
|
||||||
} else {
|
} else {
|
||||||
// Remove the entire line if we cannot extend the span back, this indicates an
|
// Remove the entire line if we cannot extend the span back, this indicates an
|
||||||
|
@ -462,7 +462,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
let first_name = match path.get(0) {
|
let first_name = match path.get(0) {
|
||||||
// In the 2018 edition this lint is a hard error, so nothing to do
|
// In the 2018 edition this lint is a hard error, so nothing to do
|
||||||
Some(seg) if seg.ident.span.is_rust_2015() && self.session.is_rust_2015() => {
|
Some(seg) if seg.ident.span.is_rust_2015() && self.tcx.sess.is_rust_2015() => {
|
||||||
seg.ident.name
|
seg.ident.name
|
||||||
}
|
}
|
||||||
_ => return,
|
_ => return,
|
||||||
|
@ -541,14 +541,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
match resolution_error {
|
match resolution_error {
|
||||||
ResolutionError::GenericParamsFromOuterFunction(outer_res, has_generic_params) => {
|
ResolutionError::GenericParamsFromOuterFunction(outer_res, has_generic_params) => {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self.session,
|
self.tcx.sess,
|
||||||
span,
|
span,
|
||||||
E0401,
|
E0401,
|
||||||
"can't use generic parameters from outer function",
|
"can't use generic parameters from outer function",
|
||||||
);
|
);
|
||||||
err.span_label(span, "use of generic parameter from outer function");
|
err.span_label(span, "use of generic parameter from outer function");
|
||||||
|
|
||||||
let sm = self.session.source_map();
|
let sm = self.tcx.sess.source_map();
|
||||||
let def_id = match outer_res {
|
let def_id = match outer_res {
|
||||||
Res::SelfTyParam { .. } => {
|
Res::SelfTyParam { .. } => {
|
||||||
err.span_label(span, "can't use `Self` here");
|
err.span_label(span, "can't use `Self` here");
|
||||||
|
@ -605,10 +605,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
ResolutionError::NameAlreadyUsedInParameterList(name, first_use_span) => self
|
ResolutionError::NameAlreadyUsedInParameterList(name, first_use_span) => self
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.create_err(errs::NameAlreadyUsedInParameterList { span, first_use_span, name }),
|
.create_err(errs::NameAlreadyUsedInParameterList { span, first_use_span, name }),
|
||||||
ResolutionError::MethodNotMemberOfTrait(method, trait_, candidate) => {
|
ResolutionError::MethodNotMemberOfTrait(method, trait_, candidate) => {
|
||||||
self.session.create_err(errs::MethodNotMemberOfTrait {
|
self.tcx.sess.create_err(errs::MethodNotMemberOfTrait {
|
||||||
span,
|
span,
|
||||||
method,
|
method,
|
||||||
trait_,
|
trait_,
|
||||||
|
@ -619,7 +620,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ResolutionError::TypeNotMemberOfTrait(type_, trait_, candidate) => {
|
ResolutionError::TypeNotMemberOfTrait(type_, trait_, candidate) => {
|
||||||
self.session.create_err(errs::TypeNotMemberOfTrait {
|
self.tcx.sess.create_err(errs::TypeNotMemberOfTrait {
|
||||||
span,
|
span,
|
||||||
type_,
|
type_,
|
||||||
trait_,
|
trait_,
|
||||||
|
@ -630,7 +631,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ResolutionError::ConstNotMemberOfTrait(const_, trait_, candidate) => {
|
ResolutionError::ConstNotMemberOfTrait(const_, trait_, candidate) => {
|
||||||
self.session.create_err(errs::ConstNotMemberOfTrait {
|
self.tcx.sess.create_err(errs::ConstNotMemberOfTrait {
|
||||||
span,
|
span,
|
||||||
const_,
|
const_,
|
||||||
trait_,
|
trait_,
|
||||||
|
@ -648,7 +649,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
let msp = MultiSpan::from_spans(target_sp.clone());
|
let msp = MultiSpan::from_spans(target_sp.clone());
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self.session,
|
self.tcx.sess,
|
||||||
msp,
|
msp,
|
||||||
E0408,
|
E0408,
|
||||||
"variable `{}` is not bound in all patterns",
|
"variable `{}` is not bound in all patterns",
|
||||||
|
@ -686,7 +687,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
err.span_help(span, &help_msg);
|
err.span_help(span, &help_msg);
|
||||||
}
|
}
|
||||||
show_candidates(
|
show_candidates(
|
||||||
&self.session,
|
&self.tcx.sess,
|
||||||
&self.untracked.source_span,
|
&self.untracked.source_span,
|
||||||
&mut err,
|
&mut err,
|
||||||
Some(span),
|
Some(span),
|
||||||
|
@ -701,17 +702,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
ResolutionError::VariableBoundWithDifferentMode(variable_name, first_binding_span) => {
|
ResolutionError::VariableBoundWithDifferentMode(variable_name, first_binding_span) => {
|
||||||
self.session.create_err(errs::VariableBoundWithDifferentMode {
|
self.tcx.sess.create_err(errs::VariableBoundWithDifferentMode {
|
||||||
span,
|
span,
|
||||||
first_binding_span,
|
first_binding_span,
|
||||||
variable_name,
|
variable_name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => self
|
ResolutionError::IdentifierBoundMoreThanOnceInParameterList(identifier) => self
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.create_err(errs::IdentifierBoundMoreThanOnceInParameterList { span, identifier }),
|
.create_err(errs::IdentifierBoundMoreThanOnceInParameterList { span, identifier }),
|
||||||
ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => self
|
ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(identifier) => self
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.create_err(errs::IdentifierBoundMoreThanOnceInSamePattern { span, identifier }),
|
.create_err(errs::IdentifierBoundMoreThanOnceInSamePattern { span, identifier }),
|
||||||
ResolutionError::UndeclaredLabel { name, suggestion } => {
|
ResolutionError::UndeclaredLabel { name, suggestion } => {
|
||||||
let ((sub_reachable, sub_reachable_suggestion), sub_unreachable) = match suggestion
|
let ((sub_reachable, sub_reachable_suggestion), sub_unreachable) = match suggestion
|
||||||
|
@ -737,7 +740,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
// No similarly-named labels exist.
|
// No similarly-named labels exist.
|
||||||
None => ((None, None), None),
|
None => ((None, None), None),
|
||||||
};
|
};
|
||||||
self.session.create_err(errs::UndeclaredLabel {
|
self.tcx.sess.create_err(errs::UndeclaredLabel {
|
||||||
span,
|
span,
|
||||||
name,
|
name,
|
||||||
sub_reachable,
|
sub_reachable,
|
||||||
|
@ -762,21 +765,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
(Some(suggestion), Some(mpart_suggestion))
|
(Some(suggestion), Some(mpart_suggestion))
|
||||||
};
|
};
|
||||||
self.session.create_err(errs::SelfImportsOnlyAllowedWithin {
|
self.tcx.sess.create_err(errs::SelfImportsOnlyAllowedWithin {
|
||||||
span,
|
span,
|
||||||
suggestion,
|
suggestion,
|
||||||
mpart_suggestion,
|
mpart_suggestion,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ResolutionError::SelfImportCanOnlyAppearOnceInTheList => {
|
ResolutionError::SelfImportCanOnlyAppearOnceInTheList => {
|
||||||
self.session.create_err(errs::SelfImportCanOnlyAppearOnceInTheList { span })
|
self.tcx.sess.create_err(errs::SelfImportCanOnlyAppearOnceInTheList { span })
|
||||||
}
|
|
||||||
ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => {
|
|
||||||
self.session.create_err(errs::SelfImportOnlyInImportListWithNonEmptyPrefix { span })
|
|
||||||
}
|
}
|
||||||
|
ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => self
|
||||||
|
.tcx
|
||||||
|
.sess
|
||||||
|
.create_err(errs::SelfImportOnlyInImportListWithNonEmptyPrefix { span }),
|
||||||
ResolutionError::FailedToResolve { label, suggestion } => {
|
ResolutionError::FailedToResolve { label, suggestion } => {
|
||||||
let mut err =
|
let mut err =
|
||||||
struct_span_err!(self.session, span, E0433, "failed to resolve: {}", &label);
|
struct_span_err!(self.tcx.sess, span, E0433, "failed to resolve: {}", &label);
|
||||||
err.span_label(span, label);
|
err.span_label(span, label);
|
||||||
|
|
||||||
if let Some((suggestions, msg, applicability)) = suggestion {
|
if let Some((suggestions, msg, applicability)) = suggestion {
|
||||||
|
@ -790,7 +794,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => {
|
ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => {
|
||||||
self.session.create_err(errs::CannotCaptureDynamicEnvironmentInFnItem { span })
|
self.tcx.sess.create_err(errs::CannotCaptureDynamicEnvironmentInFnItem { span })
|
||||||
}
|
}
|
||||||
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, suggestion, current) => {
|
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, suggestion, current) => {
|
||||||
// let foo =...
|
// let foo =...
|
||||||
|
@ -802,12 +806,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
// the further the two are apart, the higher the chance of the suggestion being wrong
|
// the further the two are apart, the higher the chance of the suggestion being wrong
|
||||||
|
|
||||||
let sp = self
|
let sp = self
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.source_map()
|
.source_map()
|
||||||
.span_extend_to_prev_str(ident.span, current, true, false);
|
.span_extend_to_prev_str(ident.span, current, true, false);
|
||||||
|
|
||||||
let ((with, with_label), without) = match sp {
|
let ((with, with_label), without) = match sp {
|
||||||
Some(sp) if !self.session.source_map().is_multiline(sp) => {
|
Some(sp) if !self.tcx.sess.source_map().is_multiline(sp) => {
|
||||||
let sp = sp.with_lo(BytePos(sp.lo().0 - (current.len() as u32)));
|
let sp = sp.with_lo(BytePos(sp.lo().0 - (current.len() as u32)));
|
||||||
(
|
(
|
||||||
(Some(errs::AttemptToUseNonConstantValueInConstantWithSuggestion {
|
(Some(errs::AttemptToUseNonConstantValueInConstantWithSuggestion {
|
||||||
|
@ -828,7 +833,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.session.create_err(errs::AttemptToUseNonConstantValueInConstant {
|
self.tcx.sess.create_err(errs::AttemptToUseNonConstantValueInConstant {
|
||||||
span,
|
span,
|
||||||
with,
|
with,
|
||||||
with_label,
|
with_label,
|
||||||
|
@ -842,7 +847,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
article,
|
article,
|
||||||
shadowed_binding,
|
shadowed_binding,
|
||||||
shadowed_binding_span,
|
shadowed_binding_span,
|
||||||
} => self.session.create_err(errs::BindingShadowsSomethingUnacceptable {
|
} => self.tcx.sess.create_err(errs::BindingShadowsSomethingUnacceptable {
|
||||||
span,
|
span,
|
||||||
shadowing_binding,
|
shadowing_binding,
|
||||||
shadowed_binding,
|
shadowed_binding,
|
||||||
|
@ -859,13 +864,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
name,
|
name,
|
||||||
}),
|
}),
|
||||||
ResolutionError::ForwardDeclaredGenericParam => {
|
ResolutionError::ForwardDeclaredGenericParam => {
|
||||||
self.session.create_err(errs::ForwardDeclaredGenericParam { span })
|
self.tcx.sess.create_err(errs::ForwardDeclaredGenericParam { span })
|
||||||
}
|
}
|
||||||
ResolutionError::ParamInTyOfConstParam(name) => {
|
ResolutionError::ParamInTyOfConstParam(name) => {
|
||||||
self.session.create_err(errs::ParamInTyOfConstParam { span, name })
|
self.tcx.sess.create_err(errs::ParamInTyOfConstParam { span, name })
|
||||||
}
|
}
|
||||||
ResolutionError::ParamInNonTrivialAnonConst { name, is_type } => {
|
ResolutionError::ParamInNonTrivialAnonConst { name, is_type } => {
|
||||||
self.session.create_err(errs::ParamInNonTrivialAnonConst {
|
self.tcx.sess.create_err(errs::ParamInNonTrivialAnonConst {
|
||||||
span,
|
span,
|
||||||
name,
|
name,
|
||||||
sub_is_type: if is_type {
|
sub_is_type: if is_type {
|
||||||
|
@ -874,13 +879,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
errs::ParamInNonTrivialAnonConstIsType::NotAType { name }
|
errs::ParamInNonTrivialAnonConstIsType::NotAType { name }
|
||||||
},
|
},
|
||||||
help: self
|
help: self
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.is_nightly_build()
|
.is_nightly_build()
|
||||||
.then_some(errs::ParamInNonTrivialAnonConstHelp),
|
.then_some(errs::ParamInNonTrivialAnonConstHelp),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ResolutionError::SelfInGenericParamDefault => {
|
ResolutionError::SelfInGenericParamDefault => {
|
||||||
self.session.create_err(errs::SelfInGenericParamDefault { span })
|
self.tcx.sess.create_err(errs::SelfInGenericParamDefault { span })
|
||||||
}
|
}
|
||||||
ResolutionError::UnreachableLabel { name, definition_span, suggestion } => {
|
ResolutionError::UnreachableLabel { name, definition_span, suggestion } => {
|
||||||
let ((sub_suggestion_label, sub_suggestion), sub_unreachable_label) =
|
let ((sub_suggestion_label, sub_suggestion), sub_unreachable_label) =
|
||||||
|
@ -908,7 +914,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
// No similarly-named labels exist.
|
// No similarly-named labels exist.
|
||||||
None => ((None, None), None),
|
None => ((None, None), None),
|
||||||
};
|
};
|
||||||
self.session.create_err(errs::UnreachableLabel {
|
self.tcx.sess.create_err(errs::UnreachableLabel {
|
||||||
span,
|
span,
|
||||||
name,
|
name,
|
||||||
definition_span,
|
definition_span,
|
||||||
|
@ -924,7 +930,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
trait_item_span,
|
trait_item_span,
|
||||||
trait_path,
|
trait_path,
|
||||||
} => {
|
} => {
|
||||||
let mut err = self.session.struct_span_err_with_code(
|
let mut err = self.tcx.sess.struct_span_err_with_code(
|
||||||
span,
|
span,
|
||||||
&format!(
|
&format!(
|
||||||
"item `{}` is an associated {}, which doesn't match its trait `{}`",
|
"item `{}` is an associated {}, which doesn't match its trait `{}`",
|
||||||
|
@ -937,9 +943,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
ResolutionError::TraitImplDuplicate { name, trait_item_span, old_span } => self
|
ResolutionError::TraitImplDuplicate { name, trait_item_span, old_span } => self
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.create_err(errs::TraitImplDuplicate { span, name, trait_item_span, old_span }),
|
.create_err(errs::TraitImplDuplicate { span, name, trait_item_span, old_span }),
|
||||||
ResolutionError::InvalidAsmSym => self.session.create_err(errs::InvalidAsmSym { span }),
|
ResolutionError::InvalidAsmSym => {
|
||||||
|
self.tcx.sess.create_err(errs::InvalidAsmSym { span })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -949,7 +958,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
) -> ErrorGuaranteed {
|
) -> ErrorGuaranteed {
|
||||||
match vis_resolution_error {
|
match vis_resolution_error {
|
||||||
VisResolutionError::Relative2018(span, path) => {
|
VisResolutionError::Relative2018(span, path) => {
|
||||||
self.session.create_err(errs::Relative2018 {
|
self.tcx.sess.create_err(errs::Relative2018 {
|
||||||
span,
|
span,
|
||||||
path_span: path.span,
|
path_span: path.span,
|
||||||
// intentionally converting to String, as the text would also be used as
|
// intentionally converting to String, as the text would also be used as
|
||||||
|
@ -958,18 +967,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
VisResolutionError::AncestorOnly(span) => {
|
VisResolutionError::AncestorOnly(span) => {
|
||||||
self.session.create_err(errs::AncestorOnly(span))
|
self.tcx.sess.create_err(errs::AncestorOnly(span))
|
||||||
}
|
}
|
||||||
VisResolutionError::FailedToResolve(span, label, suggestion) => {
|
VisResolutionError::FailedToResolve(span, label, suggestion) => {
|
||||||
self.into_struct_error(span, ResolutionError::FailedToResolve { label, suggestion })
|
self.into_struct_error(span, ResolutionError::FailedToResolve { label, suggestion })
|
||||||
}
|
}
|
||||||
VisResolutionError::ExpectedFound(span, path_str, res) => {
|
VisResolutionError::ExpectedFound(span, path_str, res) => {
|
||||||
self.session.create_err(errs::ExpectedFound { span, res, path_str })
|
self.tcx.sess.create_err(errs::ExpectedFound { span, res, path_str })
|
||||||
}
|
}
|
||||||
VisResolutionError::Indeterminate(span) => {
|
VisResolutionError::Indeterminate(span) => {
|
||||||
self.session.create_err(errs::Indeterminate(span))
|
self.tcx.sess.create_err(errs::Indeterminate(span))
|
||||||
|
}
|
||||||
|
VisResolutionError::ModuleOnly(span) => {
|
||||||
|
self.tcx.sess.create_err(errs::ModuleOnly(span))
|
||||||
}
|
}
|
||||||
VisResolutionError::ModuleOnly(span) => self.session.create_err(errs::ModuleOnly(span)),
|
|
||||||
}
|
}
|
||||||
.emit()
|
.emit()
|
||||||
}
|
}
|
||||||
|
@ -1206,7 +1217,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
// a note about editions
|
// a note about editions
|
||||||
let note = if let Some(did) = did {
|
let note = if let Some(did) = did {
|
||||||
let requires_note = !did.is_local()
|
let requires_note = !did.is_local()
|
||||||
&& this.cstore().item_attrs_untracked(did, this.session).any(
|
&& this.cstore().item_attrs_untracked(did, this.tcx.sess).any(
|
||||||
|attr| {
|
|attr| {
|
||||||
if attr.has_name(sym::rustc_diagnostic_item) {
|
if attr.has_name(sym::rustc_diagnostic_item) {
|
||||||
[sym::TryInto, sym::TryFrom, sym::FromIterator]
|
[sym::TryInto, sym::TryFrom, sym::FromIterator]
|
||||||
|
@ -1341,7 +1352,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
let import_suggestions =
|
let import_suggestions =
|
||||||
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
|
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
|
||||||
show_candidates(
|
show_candidates(
|
||||||
&self.session,
|
&self.tcx.sess,
|
||||||
&self.untracked.source_span,
|
&self.untracked.source_span,
|
||||||
err,
|
err,
|
||||||
None,
|
None,
|
||||||
|
@ -1366,7 +1377,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
&& let ModuleKind::Def(DefKind::Enum, def_id, _) = parent_scope.module.kind
|
&& let ModuleKind::Def(DefKind::Enum, def_id, _) = parent_scope.module.kind
|
||||||
&& let Some(span) = self.opt_span(def_id)
|
&& let Some(span) = self.opt_span(def_id)
|
||||||
{
|
{
|
||||||
let source_map = self.session.source_map();
|
let source_map = self.tcx.sess.source_map();
|
||||||
let head_span = source_map.guess_head_span(span);
|
let head_span = source_map.guess_head_span(span);
|
||||||
if let Ok(head) = source_map.span_to_snippet(head_span) {
|
if let Ok(head) = source_map.span_to_snippet(head_span) {
|
||||||
err.span_suggestion(head_span, "consider adding a derive", format!("#[derive(Default)]\n{head}"), Applicability::MaybeIncorrect);
|
err.span_suggestion(head_span, "consider adding a derive", format!("#[derive(Default)]\n{head}"), Applicability::MaybeIncorrect);
|
||||||
|
@ -1443,7 +1454,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
let def_span = suggestion.res.opt_def_id().and_then(|def_id| match def_id.krate {
|
let def_span = suggestion.res.opt_def_id().and_then(|def_id| match def_id.krate {
|
||||||
LOCAL_CRATE => self.opt_span(def_id),
|
LOCAL_CRATE => self.opt_span(def_id),
|
||||||
_ => Some(self.cstore().get_span_untracked(def_id, self.session)),
|
_ => Some(self.cstore().get_span_untracked(def_id, self.tcx.sess)),
|
||||||
});
|
});
|
||||||
if let Some(def_span) = def_span {
|
if let Some(def_span) = def_span {
|
||||||
if span.overlaps(def_span) {
|
if span.overlaps(def_span) {
|
||||||
|
@ -1473,7 +1484,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
err.span_label(
|
err.span_label(
|
||||||
self.session.source_map().guess_head_span(def_span),
|
self.tcx.sess.source_map().guess_head_span(def_span),
|
||||||
&format!(
|
&format!(
|
||||||
"{}{} `{}` defined here",
|
"{}{} `{}` defined here",
|
||||||
prefix,
|
prefix,
|
||||||
|
@ -1498,7 +1509,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
fn binding_description(&self, b: &NameBinding<'_>, ident: Ident, from_prelude: bool) -> String {
|
fn binding_description(&self, b: &NameBinding<'_>, ident: Ident, from_prelude: bool) -> String {
|
||||||
let res = b.res();
|
let res = b.res();
|
||||||
if b.span.is_dummy() || !self.session.source_map().is_span_accessible(b.span) {
|
if b.span.is_dummy() || !self.tcx.sess.source_map().is_span_accessible(b.span) {
|
||||||
// These already contain the "built-in" prefix or look bad with it.
|
// These already contain the "built-in" prefix or look bad with it.
|
||||||
let add_built_in =
|
let add_built_in =
|
||||||
!matches!(b.res(), Res::NonMacroAttr(..) | Res::PrimTy(..) | Res::ToolMod);
|
!matches!(b.res(), Res::NonMacroAttr(..) | Res::PrimTy(..) | Res::ToolMod);
|
||||||
|
@ -1506,7 +1517,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
("", " from prelude")
|
("", " from prelude")
|
||||||
} else if b.is_extern_crate()
|
} else if b.is_extern_crate()
|
||||||
&& !b.is_import()
|
&& !b.is_import()
|
||||||
&& self.session.opts.externs.get(ident.as_str()).is_some()
|
&& self.tcx.sess.opts.externs.get(ident.as_str()).is_some()
|
||||||
{
|
{
|
||||||
("", " passed with `--extern`")
|
("", " passed with `--extern`")
|
||||||
} else if add_built_in {
|
} else if add_built_in {
|
||||||
|
@ -1532,7 +1543,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
(b1, b2, misc1, misc2, false)
|
(b1, b2, misc1, misc2, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut err = struct_span_err!(self.session, ident.span, E0659, "`{ident}` is ambiguous");
|
let mut err = struct_span_err!(self.tcx.sess, ident.span, E0659, "`{ident}` is ambiguous");
|
||||||
err.span_label(ident.span, "ambiguous name");
|
err.span_label(ident.span, "ambiguous name");
|
||||||
err.note(&format!("ambiguous because of {}", kind.descr()));
|
err.note(&format!("ambiguous because of {}", kind.descr()));
|
||||||
|
|
||||||
|
@ -1604,7 +1615,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
// Print the primary message.
|
// Print the primary message.
|
||||||
let descr = get_descr(binding);
|
let descr = get_descr(binding);
|
||||||
let mut err =
|
let mut err =
|
||||||
struct_span_err!(self.session, ident.span, E0603, "{} `{}` is private", descr, ident);
|
struct_span_err!(self.tcx.sess, ident.span, E0603, "{} `{}` is private", descr, ident);
|
||||||
err.span_label(ident.span, &format!("private {}", descr));
|
err.span_label(ident.span, &format!("private {}", descr));
|
||||||
if let Some(span) = ctor_fields_span {
|
if let Some(span) = ctor_fields_span {
|
||||||
err.span_label(span, "a constructor is private if any of the fields is private");
|
err.span_label(span, "a constructor is private if any of the fields is private");
|
||||||
|
@ -1650,7 +1661,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
which = if first { "" } else { " which" },
|
which = if first { "" } else { " which" },
|
||||||
dots = if next_binding.is_some() { "..." } else { "" },
|
dots = if next_binding.is_some() { "..." } else { "" },
|
||||||
);
|
);
|
||||||
let def_span = self.session.source_map().guess_head_span(binding.span);
|
let def_span = self.tcx.sess.source_map().guess_head_span(binding.span);
|
||||||
let mut note_span = MultiSpan::from_span(def_span);
|
let mut note_span = MultiSpan::from_span(def_span);
|
||||||
if !first && binding.vis.is_public() {
|
if !first && binding.vis.is_public() {
|
||||||
note_span.push_span_label(def_span, "consider importing it directly");
|
note_span.push_span_label(def_span, "consider importing it directly");
|
||||||
|
@ -1719,7 +1730,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
} else if self.session.is_rust_2015() {
|
} else if self.tcx.sess.is_rust_2015() {
|
||||||
(
|
(
|
||||||
format!("maybe a missing crate `{ident}`?"),
|
format!("maybe a missing crate `{ident}`?"),
|
||||||
Some((
|
Some((
|
||||||
|
@ -1738,7 +1749,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
let parent = match parent {
|
let parent = match parent {
|
||||||
// ::foo is mounted at the crate root for 2015, and is the extern
|
// ::foo is mounted at the crate root for 2015, and is the extern
|
||||||
// prelude for 2018+
|
// prelude for 2018+
|
||||||
kw::PathRoot if self.session.edition() > Edition::Edition2015 => {
|
kw::PathRoot if self.tcx.sess.edition() > Edition::Edition2015 => {
|
||||||
"the list of imported crates".to_owned()
|
"the list of imported crates".to_owned()
|
||||||
}
|
}
|
||||||
kw::PathRoot | kw::Crate => "the crate root".to_owned(),
|
kw::PathRoot | kw::Crate => "the crate root".to_owned(),
|
||||||
|
@ -2079,7 +2090,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
// ie. `use a::b::{c, d, e};`
|
// ie. `use a::b::{c, d, e};`
|
||||||
// ^^^
|
// ^^^
|
||||||
let (found_closing_brace, binding_span) = find_span_of_binding_until_next_binding(
|
let (found_closing_brace, binding_span) = find_span_of_binding_until_next_binding(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
import.span,
|
import.span,
|
||||||
import.use_span,
|
import.use_span,
|
||||||
);
|
);
|
||||||
|
@ -2098,7 +2109,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
// ie. `use a::b::{c, d};`
|
// ie. `use a::b::{c, d};`
|
||||||
// ^^^
|
// ^^^
|
||||||
if let Some(previous_span) =
|
if let Some(previous_span) =
|
||||||
extend_span_to_previous_binding(self.r.session, binding_span)
|
extend_span_to_previous_binding(self.r.tcx.sess, binding_span)
|
||||||
{
|
{
|
||||||
debug!("check_for_module_export_macro: previous_span={:?}", previous_span);
|
debug!("check_for_module_export_macro: previous_span={:?}", previous_span);
|
||||||
removal_span = removal_span.with_lo(previous_span.lo());
|
removal_span = removal_span.with_lo(previous_span.lo());
|
||||||
|
@ -2116,7 +2127,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
// or `use a::{b, c, d}};`
|
// or `use a::{b, c, d}};`
|
||||||
// ^^^^^^^^^^^
|
// ^^^^^^^^^^^
|
||||||
let (has_nested, after_crate_name) = find_span_immediately_after_crate_name(
|
let (has_nested, after_crate_name) = find_span_immediately_after_crate_name(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
module_name,
|
module_name,
|
||||||
import.use_span,
|
import.use_span,
|
||||||
);
|
);
|
||||||
|
@ -2125,7 +2136,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
has_nested, after_crate_name
|
has_nested, after_crate_name
|
||||||
);
|
);
|
||||||
|
|
||||||
let source_map = self.r.session.source_map();
|
let source_map = self.r.tcx.sess.source_map();
|
||||||
|
|
||||||
// Make sure this is actually crate-relative.
|
// Make sure this is actually crate-relative.
|
||||||
let is_definitely_crate = import
|
let is_definitely_crate = import
|
||||||
|
|
|
@ -1179,7 +1179,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstantItemRibKind(trivial, _) => {
|
ConstantItemRibKind(trivial, _) => {
|
||||||
let features = self.session.features_untracked();
|
let features = self.tcx.sess.features_untracked();
|
||||||
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
||||||
if !(trivial == ConstantHasGenerics::Yes
|
if !(trivial == ConstantHasGenerics::Yes
|
||||||
|| features.generic_const_exprs)
|
|| features.generic_const_exprs)
|
||||||
|
@ -1208,7 +1208,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
is_type: true,
|
is_type: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self.session.delay_span_bug(span, CG_BUG_STR);
|
self.tcx.sess.delay_span_bug(span, CG_BUG_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Res::Err;
|
return Res::Err;
|
||||||
|
@ -1255,7 +1255,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
| ForwardGenericParamBanRibKind => continue,
|
| ForwardGenericParamBanRibKind => continue,
|
||||||
|
|
||||||
ConstantItemRibKind(trivial, _) => {
|
ConstantItemRibKind(trivial, _) => {
|
||||||
let features = self.session.features_untracked();
|
let features = self.tcx.sess.features_untracked();
|
||||||
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
||||||
if !(trivial == ConstantHasGenerics::Yes
|
if !(trivial == ConstantHasGenerics::Yes
|
||||||
|| features.generic_const_exprs)
|
|| features.generic_const_exprs)
|
||||||
|
@ -1268,7 +1268,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
is_type: false,
|
is_type: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self.session.delay_span_bug(span, CG_BUG_STR);
|
self.tcx.sess.delay_span_bug(span, CG_BUG_STR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Res::Err;
|
return Res::Err;
|
||||||
|
@ -1397,7 +1397,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
module = Some(ModuleOrUniformRoot::ExternPrelude);
|
module = Some(ModuleOrUniformRoot::ExternPrelude);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if name == kw::PathRoot && ident.span.is_rust_2015() && self.session.rust_2018()
|
if name == kw::PathRoot
|
||||||
|
&& ident.span.is_rust_2015()
|
||||||
|
&& self.tcx.sess.rust_2018()
|
||||||
{
|
{
|
||||||
// `::a::b` from 2015 macro on 2018 global edition
|
// `::a::b` from 2015 macro on 2018 global edition
|
||||||
module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude);
|
module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude);
|
||||||
|
@ -1494,7 +1496,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
record_segment_res(self, res);
|
record_segment_res(self, res);
|
||||||
} else if res == Res::ToolMod && i + 1 != path.len() {
|
} else if res == Res::ToolMod && i + 1 != path.len() {
|
||||||
if binding.is_import() {
|
if binding.is_import() {
|
||||||
self.session
|
self.tcx
|
||||||
|
.sess
|
||||||
.struct_span_err(
|
.struct_span_err(
|
||||||
ident.span,
|
ident.span,
|
||||||
"cannot use a tool module through an import",
|
"cannot use a tool module through an import",
|
||||||
|
|
|
@ -526,7 +526,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let msg = format!("unresolved import{} {}", pluralize!(paths.len()), paths.join(", "),);
|
let msg = format!("unresolved import{} {}", pluralize!(paths.len()), paths.join(", "),);
|
||||||
|
|
||||||
let mut diag = struct_span_err!(self.r.session, span, E0432, "{}", &msg);
|
let mut diag = struct_span_err!(self.r.tcx.sess, span, E0432, "{}", &msg);
|
||||||
|
|
||||||
if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() {
|
if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() {
|
||||||
diag.note(note);
|
diag.note(note);
|
||||||
|
@ -548,7 +548,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
if let Some(candidates) = &err.candidates {
|
if let Some(candidates) = &err.candidates {
|
||||||
match &import.kind {
|
match &import.kind {
|
||||||
ImportKind::Single { nested: false, source, target, .. } => import_candidates(
|
ImportKind::Single { nested: false, source, target, .. } => import_candidates(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
&self.r.untracked.source_span,
|
&self.r.untracked.source_span,
|
||||||
&mut diag,
|
&mut diag,
|
||||||
Some(err.span),
|
Some(err.span),
|
||||||
|
@ -561,7 +561,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
),
|
),
|
||||||
ImportKind::Single { nested: true, source, target, .. } => {
|
ImportKind::Single { nested: true, source, target, .. } => {
|
||||||
import_candidates(
|
import_candidates(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
&self.r.untracked.source_span,
|
&self.r.untracked.source_span,
|
||||||
&mut diag,
|
&mut diag,
|
||||||
None,
|
None,
|
||||||
|
@ -658,7 +658,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
source_binding @ (Ok(..) | Err(Determined)) => {
|
source_binding @ (Ok(..) | Err(Determined)) => {
|
||||||
if source_binding.is_ok() {
|
if source_binding.is_ok() {
|
||||||
let msg = format!("`{}` is not directly importable", target);
|
let msg = format!("`{}` is not directly importable", target);
|
||||||
struct_span_err!(this.session, import.span, E0253, "{}", &msg)
|
struct_span_err!(this.tcx.sess, import.span, E0253, "{}", &msg)
|
||||||
.span_label(import.span, "cannot be imported directly")
|
.span_label(import.span, "cannot be imported directly")
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
|
@ -706,7 +706,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
} else if self.r.privacy_errors.is_empty() {
|
} else if self.r.privacy_errors.is_empty() {
|
||||||
let msg = "cannot determine resolution for the import";
|
let msg = "cannot determine resolution for the import";
|
||||||
let msg_note = "import resolution is stuck, try simplifying other imports";
|
let msg_note = "import resolution is stuck, try simplifying other imports";
|
||||||
self.r.session.struct_span_err(import.span, msg).note(msg_note).emit();
|
self.r.tcx.sess.struct_span_err(import.span, msg).note(msg_note).emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
module
|
module
|
||||||
|
@ -859,7 +859,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
let msg = "cannot determine resolution for the import";
|
let msg = "cannot determine resolution for the import";
|
||||||
let msg_note =
|
let msg_note =
|
||||||
"import resolution is stuck, try simplifying other imports";
|
"import resolution is stuck, try simplifying other imports";
|
||||||
this.session.struct_span_err(import.span, msg).note(msg_note).emit();
|
this.tcx.sess.struct_span_err(import.span, msg).note(msg_note).emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(..) => {
|
Err(..) => {
|
||||||
|
@ -1035,13 +1035,13 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
format!("re-export of private `{}`", ident)
|
format!("re-export of private `{}`", ident)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct_span_err!(self.r.session, import.span, E0365, "{}", error_msg)
|
struct_span_err!(self.r.tcx.sess, import.span, E0365, "{}", error_msg)
|
||||||
.span_label(import.span, label_msg)
|
.span_label(import.span, label_msg)
|
||||||
.note(&format!("consider declaring type or module `{}` with `pub`", ident))
|
.note(&format!("consider declaring type or module `{}` with `pub`", ident))
|
||||||
.emit();
|
.emit();
|
||||||
} else {
|
} else {
|
||||||
let mut err =
|
let mut err =
|
||||||
struct_span_err!(self.r.session, import.span, E0364, "{error_msg}");
|
struct_span_err!(self.r.tcx.sess, import.span, E0364, "{error_msg}");
|
||||||
match binding.kind {
|
match binding.kind {
|
||||||
NameBindingKind::Res(Res::Def(DefKind::Macro(_), def_id))
|
NameBindingKind::Res(Res::Def(DefKind::Macro(_), def_id))
|
||||||
// exclude decl_macro
|
// exclude decl_macro
|
||||||
|
@ -1164,12 +1164,12 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||||
let ImportKind::Glob { id, is_prelude, .. } = import.kind else { unreachable!() };
|
let ImportKind::Glob { id, is_prelude, .. } = import.kind else { unreachable!() };
|
||||||
|
|
||||||
let ModuleOrUniformRoot::Module(module) = import.imported_module.get().unwrap() else {
|
let ModuleOrUniformRoot::Module(module) = import.imported_module.get().unwrap() else {
|
||||||
self.r.session.span_err(import.span, "cannot glob-import all possible crates");
|
self.r.tcx.sess.span_err(import.span, "cannot glob-import all possible crates");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if module.is_trait() {
|
if module.is_trait() {
|
||||||
self.r.session.span_err(import.span, "items in traits are not importable");
|
self.r.tcx.sess.span_err(import.span, "items in traits are not importable");
|
||||||
return;
|
return;
|
||||||
} else if ptr::eq(module, import.parent_scope.module) {
|
} else if ptr::eq(module, import.parent_scope.module) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -682,7 +682,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
// Elided lifetime in reference: we resolve as if there was some lifetime `'_` with
|
// Elided lifetime in reference: we resolve as if there was some lifetime `'_` with
|
||||||
// NodeId `ty.id`.
|
// NodeId `ty.id`.
|
||||||
// This span will be used in case of elision failure.
|
// This span will be used in case of elision failure.
|
||||||
let span = self.r.session.source_map().start_point(ty.span);
|
let span = self.r.tcx.sess.source_map().start_point(ty.span);
|
||||||
self.resolve_elided_lifetime(ty.id, span);
|
self.resolve_elided_lifetime(ty.id, span);
|
||||||
visit::walk_ty(self, ty);
|
visit::walk_ty(self, ty);
|
||||||
}
|
}
|
||||||
|
@ -1571,7 +1571,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
("`'_` cannot be used here", "`'_` is a reserved lifetime name")
|
("`'_` cannot be used here", "`'_` is a reserved lifetime name")
|
||||||
};
|
};
|
||||||
let mut diag = rustc_errors::struct_span_err!(
|
let mut diag = rustc_errors::struct_span_err!(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
lifetime.ident.span,
|
lifetime.ident.span,
|
||||||
E0637,
|
E0637,
|
||||||
"{}",
|
"{}",
|
||||||
|
@ -1748,7 +1748,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
// impl Foo for std::cell::Ref<u32> // note lack of '_
|
// impl Foo for std::cell::Ref<u32> // note lack of '_
|
||||||
// async fn foo(_: std::cell::Ref<u32>) { ... }
|
// async fn foo(_: std::cell::Ref<u32>) { ... }
|
||||||
LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. } => {
|
LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. } => {
|
||||||
let sess = self.r.session;
|
let sess = self.r.tcx.sess;
|
||||||
let mut err = rustc_errors::struct_span_err!(
|
let mut err = rustc_errors::struct_span_err!(
|
||||||
sess,
|
sess,
|
||||||
path_span,
|
path_span,
|
||||||
|
@ -2194,7 +2194,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
let what = if ns == TypeNS { "type parameters" } else { "local variables" };
|
let what = if ns == TypeNS { "type parameters" } else { "local variables" };
|
||||||
if this.should_report_errs() {
|
if this.should_report_errs() {
|
||||||
this.r
|
this.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.span_err(ident.span, &format!("imports cannot refer to {}", what));
|
.span_err(ident.span, &format!("imports cannot refer to {}", what));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2438,7 +2439,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
if let GenericParamKind::Lifetime = param.kind
|
if let GenericParamKind::Lifetime = param.kind
|
||||||
&& let Some(&original) = seen_lifetimes.get(&ident)
|
&& let Some(&original) = seen_lifetimes.get(&ident)
|
||||||
{
|
{
|
||||||
diagnostics::signal_lifetime_shadowing(self.r.session, original, param.ident);
|
diagnostics::signal_lifetime_shadowing(self.r.tcx.sess, original, param.ident);
|
||||||
// Record lifetime res, so lowering knows there is something fishy.
|
// Record lifetime res, so lowering knows there is something fishy.
|
||||||
self.record_lifetime_param(param.id, LifetimeRes::Error);
|
self.record_lifetime_param(param.id, LifetimeRes::Error);
|
||||||
continue;
|
continue;
|
||||||
|
@ -2462,7 +2463,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
|
|
||||||
if param.ident.name == kw::UnderscoreLifetime {
|
if param.ident.name == kw::UnderscoreLifetime {
|
||||||
rustc_errors::struct_span_err!(
|
rustc_errors::struct_span_err!(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
param.ident.span,
|
param.ident.span,
|
||||||
E0637,
|
E0637,
|
||||||
"`'_` cannot be used here"
|
"`'_` cannot be used here"
|
||||||
|
@ -2476,7 +2477,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
|
|
||||||
if param.ident.name == kw::StaticLifetime {
|
if param.ident.name == kw::StaticLifetime {
|
||||||
rustc_errors::struct_span_err!(
|
rustc_errors::struct_span_err!(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
param.ident.span,
|
param.ident.span,
|
||||||
E0262,
|
E0262,
|
||||||
"invalid lifetime parameter name: `{}`",
|
"invalid lifetime parameter name: `{}`",
|
||||||
|
@ -2506,7 +2507,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
let res = match kind {
|
let res = match kind {
|
||||||
ItemRibKind(..) | AssocItemRibKind => Res::Def(def_kind, def_id.to_def_id()),
|
ItemRibKind(..) | AssocItemRibKind => Res::Def(def_kind, def_id.to_def_id()),
|
||||||
NormalRibKind => {
|
NormalRibKind => {
|
||||||
if self.r.session.features_untracked().non_lifetime_binders {
|
if self.r.tcx.sess.features_untracked().non_lifetime_binders {
|
||||||
Res::Def(def_kind, def_id.to_def_id())
|
Res::Def(def_kind, def_id.to_def_id())
|
||||||
} else {
|
} else {
|
||||||
Res::Err
|
Res::Err
|
||||||
|
@ -3384,7 +3385,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
Res::SelfCtor(_) => {
|
Res::SelfCtor(_) => {
|
||||||
// We resolve `Self` in pattern position as an ident sometimes during recovery,
|
// We resolve `Self` in pattern position as an ident sometimes during recovery,
|
||||||
// so delay a bug instead of ICEing.
|
// so delay a bug instead of ICEing.
|
||||||
self.r.session.delay_span_bug(
|
self.r.tcx.sess.delay_span_bug(
|
||||||
ident.span,
|
ident.span,
|
||||||
"unexpected `SelfCtor` in pattern, expected identifier"
|
"unexpected `SelfCtor` in pattern, expected identifier"
|
||||||
);
|
);
|
||||||
|
@ -3664,7 +3665,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
/// If we're actually rustdoc then avoid giving a name resolution error for `cfg()` items.
|
/// If we're actually rustdoc then avoid giving a name resolution error for `cfg()` items.
|
||||||
fn should_report_errs(&self) -> bool {
|
fn should_report_errs(&self) -> bool {
|
||||||
!(self.r.session.opts.actually_rustdoc && self.in_func_body)
|
!(self.r.tcx.sess.opts.actually_rustdoc && self.in_func_body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve in alternative namespaces if resolution in the primary namespace fails.
|
// Resolve in alternative namespaces if resolution in the primary namespace fails.
|
||||||
|
@ -3829,7 +3830,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok((_, orig_span)) = self.resolve_label(label.ident) {
|
if let Ok((_, orig_span)) = self.resolve_label(label.ident) {
|
||||||
diagnostics::signal_label_shadowing(self.r.session, orig_span, label.ident)
|
diagnostics::signal_label_shadowing(self.r.tcx.sess, orig_span, label.ident)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.with_label_rib(NormalRibKind, |this| {
|
self.with_label_rib(NormalRibKind, |this| {
|
||||||
|
@ -4211,8 +4212,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
if let Some(res) = res
|
if let Some(res) = res
|
||||||
&& let Some(def_id) = res.opt_def_id()
|
&& let Some(def_id) = res.opt_def_id()
|
||||||
&& !def_id.is_local()
|
&& !def_id.is_local()
|
||||||
&& self.r.session.crate_types().contains(&CrateType::ProcMacro)
|
&& self.r.tcx.sess.crate_types().contains(&CrateType::ProcMacro)
|
||||||
&& matches!(self.r.session.opts.resolve_doc_links, ResolveDocLinks::ExportedMetadata) {
|
&& matches!(self.r.tcx.sess.opts.resolve_doc_links, ResolveDocLinks::ExportedMetadata) {
|
||||||
// Encoding foreign def ids in proc macro crate metadata will ICE.
|
// Encoding foreign def ids in proc macro crate metadata will ICE.
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -4224,10 +4225,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_doc_links(&mut self, attrs: &[Attribute], maybe_exported: MaybeExported<'_>) {
|
fn resolve_doc_links(&mut self, attrs: &[Attribute], maybe_exported: MaybeExported<'_>) {
|
||||||
match self.r.session.opts.resolve_doc_links {
|
match self.r.tcx.sess.opts.resolve_doc_links {
|
||||||
ResolveDocLinks::None => return,
|
ResolveDocLinks::None => return,
|
||||||
ResolveDocLinks::ExportedMetadata
|
ResolveDocLinks::ExportedMetadata
|
||||||
if !self.r.session.crate_types().iter().copied().any(CrateType::has_metadata)
|
if !self.r.tcx.sess.crate_types().iter().copied().any(CrateType::has_metadata)
|
||||||
|| !maybe_exported.eval(self.r) =>
|
|| !maybe_exported.eval(self.r) =>
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -4281,9 +4282,9 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|tr| {
|
.filter_map(|tr| {
|
||||||
if !tr.def_id.is_local()
|
if !tr.def_id.is_local()
|
||||||
&& self.r.session.crate_types().contains(&CrateType::ProcMacro)
|
&& self.r.tcx.sess.crate_types().contains(&CrateType::ProcMacro)
|
||||||
&& matches!(
|
&& matches!(
|
||||||
self.r.session.opts.resolve_doc_links,
|
self.r.tcx.sess.opts.resolve_doc_links,
|
||||||
ResolveDocLinks::ExportedMetadata
|
ResolveDocLinks::ExportedMetadata
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
|
@ -170,7 +170,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
fn def_span(&self, def_id: DefId) -> Option<Span> {
|
fn def_span(&self, def_id: DefId) -> Option<Span> {
|
||||||
match def_id.krate {
|
match def_id.krate {
|
||||||
LOCAL_CRATE => self.r.opt_span(def_id),
|
LOCAL_CRATE => self.r.opt_span(def_id),
|
||||||
_ => Some(self.r.cstore().get_span_untracked(def_id, self.r.session)),
|
_ => Some(self.r.cstore().get_span_untracked(def_id, self.r.tcx.sess)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +200,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
Res::Def(DefKind::Fn, _) => {
|
Res::Def(DefKind::Fn, _) => {
|
||||||
// Verify whether this is a fn call or an Fn used as a type.
|
// Verify whether this is a fn call or an Fn used as a type.
|
||||||
self.r
|
self.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.source_map()
|
.source_map()
|
||||||
.span_to_snippet(span)
|
.span_to_snippet(span)
|
||||||
.map(|snippet| snippet.ends_with(')'))
|
.map(|snippet| snippet.ends_with(')'))
|
||||||
|
@ -255,7 +256,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
};
|
};
|
||||||
(String::new(), "this scope".to_string(), suggestion)
|
(String::new(), "this scope".to_string(), suggestion)
|
||||||
} else if path.len() == 2 && path[0].ident.name == kw::PathRoot {
|
} else if path.len() == 2 && path[0].ident.name == kw::PathRoot {
|
||||||
if self.r.session.edition() > Edition::Edition2015 {
|
if self.r.tcx.sess.edition() > Edition::Edition2015 {
|
||||||
// In edition 2018 onwards, the `::foo` syntax may only pull from the extern prelude
|
// In edition 2018 onwards, the `::foo` syntax may only pull from the extern prelude
|
||||||
// which overrides all other expectations of item type
|
// which overrides all other expectations of item type
|
||||||
expected = "crate";
|
expected = "crate";
|
||||||
|
@ -323,7 +324,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
let base_error = self.make_base_error(path, span, source, res);
|
let base_error = self.make_base_error(path, span, source, res);
|
||||||
let code = source.error_code(res.is_some());
|
let code = source.error_code(res.is_some());
|
||||||
let mut err =
|
let mut err =
|
||||||
self.r.session.struct_span_err_with_code(base_error.span, &base_error.msg, code);
|
self.r.tcx.sess.struct_span_err_with_code(base_error.span, &base_error.msg, code);
|
||||||
|
|
||||||
self.suggest_swapping_misplaced_self_ty_and_trait(&mut err, source, res, base_error.span);
|
self.suggest_swapping_misplaced_self_ty_and_trait(&mut err, source, res, base_error.span);
|
||||||
|
|
||||||
|
@ -432,7 +433,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
self.r
|
self.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.source_map()
|
.source_map()
|
||||||
.span_through_char(*fn_span, '(')
|
.span_through_char(*fn_span, '(')
|
||||||
.shrink_to_hi(),
|
.shrink_to_hi(),
|
||||||
|
@ -505,7 +507,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
{
|
{
|
||||||
if self
|
if self
|
||||||
.r
|
.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.parse_sess
|
.parse_sess
|
||||||
.type_ascription_path_suggestions
|
.type_ascription_path_suggestions
|
||||||
.borrow()
|
.borrow()
|
||||||
|
@ -596,7 +599,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
if let Some((call_span, args_span)) = self.call_has_self_arg(source) {
|
if let Some((call_span, args_span)) = self.call_has_self_arg(source) {
|
||||||
let mut args_snippet = String::new();
|
let mut args_snippet = String::new();
|
||||||
if let Some(args_span) = args_span {
|
if let Some(args_span) = args_span {
|
||||||
if let Ok(snippet) = self.r.session.source_map().span_to_snippet(args_span) {
|
if let Ok(snippet) = self.r.tcx.sess.source_map().span_to_snippet(args_span) {
|
||||||
args_snippet = snippet;
|
args_snippet = snippet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -732,7 +735,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
let ident_span = path.last().map_or(span, |ident| ident.ident.span);
|
let ident_span = path.last().map_or(span, |ident| ident.ident.span);
|
||||||
let typo_sugg = self.lookup_typo_candidate(path, source.namespace(), is_expected);
|
let typo_sugg = self.lookup_typo_candidate(path, source.namespace(), is_expected);
|
||||||
let is_in_same_file = &|sp1, sp2| {
|
let is_in_same_file = &|sp1, sp2| {
|
||||||
let source_map = self.r.session.source_map();
|
let source_map = self.r.tcx.sess.source_map();
|
||||||
let file1 = source_map.span_to_filename(sp1);
|
let file1 = source_map.span_to_filename(sp1);
|
||||||
let file2 = source_map.span_to_filename(sp2);
|
let file2 = source_map.span_to_filename(sp2);
|
||||||
file1 == file2
|
file1 == file2
|
||||||
|
@ -895,7 +898,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
.map_or(*span, |ident| span.with_lo(ident.span.hi()));
|
.map_or(*span, |ident| span.with_lo(ident.span.hi()));
|
||||||
(
|
(
|
||||||
self.r
|
self.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.source_map()
|
.source_map()
|
||||||
.span_through_char(span, '(')
|
.span_through_char(span, '(')
|
||||||
.shrink_to_hi(),
|
.shrink_to_hi(),
|
||||||
|
@ -949,9 +953,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
&& let PathSource::Trait(_) = source
|
&& let PathSource::Trait(_) = source
|
||||||
&& let Some(Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, _)) = res
|
&& let Some(Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, _)) = res
|
||||||
&& let Ok(self_ty_str) =
|
&& let Ok(self_ty_str) =
|
||||||
self.r.session.source_map().span_to_snippet(self_ty.span)
|
self.r.tcx.sess.source_map().span_to_snippet(self_ty.span)
|
||||||
&& let Ok(trait_ref_str) =
|
&& let Ok(trait_ref_str) =
|
||||||
self.r.session.source_map().span_to_snippet(trait_ref.path.span)
|
self.r.tcx.sess.source_map().span_to_snippet(trait_ref.path.span)
|
||||||
{
|
{
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
"`impl` items mention the trait being implemented first and the type it is being implemented for second",
|
"`impl` items mention the trait being implemented first and the type it is being implemented for second",
|
||||||
|
@ -1095,7 +1099,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
format!(
|
format!(
|
||||||
"{}: {}<{} = {}>",
|
"{}: {}<{} = {}>",
|
||||||
self.r
|
self.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.source_map()
|
.source_map()
|
||||||
.span_to_snippet(ty.span) // Account for `<&'a T as Foo>::Bar`.
|
.span_to_snippet(ty.span) // Account for `<&'a T as Foo>::Bar`.
|
||||||
.unwrap_or_else(|_| constrain_ident.to_string()),
|
.unwrap_or_else(|_| constrain_ident.to_string()),
|
||||||
|
@ -1164,7 +1169,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
// parser issue where a struct literal is being used on an expression
|
// parser issue where a struct literal is being used on an expression
|
||||||
// where a brace being opened means a block is being started. Look
|
// where a brace being opened means a block is being started. Look
|
||||||
// ahead for the next text to see if `span` is followed by a `{`.
|
// ahead for the next text to see if `span` is followed by a `{`.
|
||||||
let sm = self.r.session.source_map();
|
let sm = self.r.tcx.sess.source_map();
|
||||||
let sp = sm.span_look_ahead(span, None, Some(50));
|
let sp = sm.span_look_ahead(span, None, Some(50));
|
||||||
let followed_by_brace = matches!(sm.span_to_snippet(sp), Ok(ref snippet) if snippet == "{");
|
let followed_by_brace = matches!(sm.span_to_snippet(sp), Ok(ref snippet) if snippet == "{");
|
||||||
// In case this could be a struct literal that needs to be surrounded
|
// In case this could be a struct literal that needs to be surrounded
|
||||||
|
@ -1212,7 +1217,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
true
|
true
|
||||||
} else if kind == DefKind::Struct
|
} else if kind == DefKind::Struct
|
||||||
&& let Some(lhs_source_span) = lhs_span.find_ancestor_inside(expr.span)
|
&& let Some(lhs_source_span) = lhs_span.find_ancestor_inside(expr.span)
|
||||||
&& let Ok(snippet) = self.r.session.source_map().span_to_snippet(lhs_source_span)
|
&& let Ok(snippet) = self.r.tcx.sess.source_map().span_to_snippet(lhs_source_span)
|
||||||
{
|
{
|
||||||
// The LHS is a type that originates from a macro call.
|
// The LHS is a type that originates from a macro call.
|
||||||
// We have to add angle brackets around it.
|
// We have to add angle brackets around it.
|
||||||
|
@ -1352,11 +1357,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
}
|
}
|
||||||
(Res::Def(DefKind::TyAlias, def_id), PathSource::Trait(_)) => {
|
(Res::Def(DefKind::TyAlias, def_id), PathSource::Trait(_)) => {
|
||||||
err.span_label(span, "type aliases cannot be used as traits");
|
err.span_label(span, "type aliases cannot be used as traits");
|
||||||
if self.r.session.is_nightly_build() {
|
if self.r.tcx.sess.is_nightly_build() {
|
||||||
let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \
|
let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \
|
||||||
`type` alias";
|
`type` alias";
|
||||||
if let Some(span) = self.def_span(def_id) {
|
if let Some(span) = self.def_span(def_id) {
|
||||||
if let Ok(snip) = self.r.session.source_map().span_to_snippet(span) {
|
if let Ok(snip) = self.r.tcx.sess.source_map().span_to_snippet(span) {
|
||||||
// The span contains a type alias so we should be able to
|
// The span contains a type alias so we should be able to
|
||||||
// replace `type` with `trait`.
|
// replace `type` with `trait`.
|
||||||
let snip = snip.replacen("type", "trait", 1);
|
let snip = snip.replacen("type", "trait", 1);
|
||||||
|
@ -1387,7 +1392,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
.last()
|
.last()
|
||||||
.map(|sp| {
|
.map(|sp| {
|
||||||
self.r
|
self.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.parse_sess
|
.parse_sess
|
||||||
.type_ascription_path_suggestions
|
.type_ascription_path_suggestions
|
||||||
.borrow()
|
.borrow()
|
||||||
|
@ -1774,12 +1780,12 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
|
|
||||||
/// Only used in a specific case of type ascription suggestions
|
/// Only used in a specific case of type ascription suggestions
|
||||||
fn get_colon_suggestion_span(&self, start: Span) -> Span {
|
fn get_colon_suggestion_span(&self, start: Span) -> Span {
|
||||||
let sm = self.r.session.source_map();
|
let sm = self.r.tcx.sess.source_map();
|
||||||
start.to(sm.next_point(start))
|
start.to(sm.next_point(start))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_ascription_suggestion(&self, err: &mut Diagnostic, base_span: Span) -> bool {
|
fn type_ascription_suggestion(&self, err: &mut Diagnostic, base_span: Span) -> bool {
|
||||||
let sm = self.r.session.source_map();
|
let sm = self.r.tcx.sess.source_map();
|
||||||
let base_snippet = sm.span_to_snippet(base_span);
|
let base_snippet = sm.span_to_snippet(base_span);
|
||||||
if let Some(&sp) = self.diagnostic_metadata.current_type_ascription.last() {
|
if let Some(&sp) = self.diagnostic_metadata.current_type_ascription.last() {
|
||||||
if let Ok(snippet) = sm.span_to_snippet(sp) {
|
if let Ok(snippet) = sm.span_to_snippet(sp) {
|
||||||
|
@ -1809,7 +1815,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
show_label = false;
|
show_label = false;
|
||||||
if !self
|
if !self
|
||||||
.r
|
.r
|
||||||
.session
|
.tcx
|
||||||
|
.sess
|
||||||
.parse_sess
|
.parse_sess
|
||||||
.type_ascription_path_suggestions
|
.type_ascription_path_suggestions
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
@ -2272,7 +2279,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
debug_assert_ne!(lifetime_ref.ident.name, kw::UnderscoreLifetime);
|
debug_assert_ne!(lifetime_ref.ident.name, kw::UnderscoreLifetime);
|
||||||
let mut err = if let Some(outer) = outer_lifetime_ref {
|
let mut err = if let Some(outer) = outer_lifetime_ref {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
lifetime_ref.ident.span,
|
lifetime_ref.ident.span,
|
||||||
E0401,
|
E0401,
|
||||||
"can't use generic parameters from outer item",
|
"can't use generic parameters from outer item",
|
||||||
|
@ -2282,7 +2289,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
err
|
err
|
||||||
} else {
|
} else {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
lifetime_ref.ident.span,
|
lifetime_ref.ident.span,
|
||||||
E0261,
|
E0261,
|
||||||
"use of undeclared lifetime name `{}`",
|
"use of undeclared lifetime name `{}`",
|
||||||
|
@ -2340,8 +2347,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
);
|
);
|
||||||
(span, sugg)
|
(span, sugg)
|
||||||
} else {
|
} else {
|
||||||
let span =
|
let span = self
|
||||||
self.r.session.source_map().span_through_char(span, '<').shrink_to_hi();
|
.r
|
||||||
|
.tcx
|
||||||
|
.sess
|
||||||
|
.source_map()
|
||||||
|
.span_through_char(span, '<')
|
||||||
|
.shrink_to_hi();
|
||||||
let sugg = format!("{}, ", name.unwrap_or("'a"));
|
let sugg = format!("{}, ", name.unwrap_or("'a"));
|
||||||
(span, sugg)
|
(span, sugg)
|
||||||
};
|
};
|
||||||
|
@ -2375,7 +2387,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
|
|
||||||
pub(crate) fn emit_non_static_lt_in_const_generic_error(&self, lifetime_ref: &ast::Lifetime) {
|
pub(crate) fn emit_non_static_lt_in_const_generic_error(&self, lifetime_ref: &ast::Lifetime) {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
lifetime_ref.ident.span,
|
lifetime_ref.ident.span,
|
||||||
E0771,
|
E0771,
|
||||||
"use of non-static lifetime `{}` in const generic",
|
"use of non-static lifetime `{}` in const generic",
|
||||||
|
@ -2395,10 +2407,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
lifetime_ref: &ast::Lifetime,
|
lifetime_ref: &ast::Lifetime,
|
||||||
) {
|
) {
|
||||||
let feature_active = self.r.session.features_untracked().generic_const_exprs;
|
let feature_active = self.r.tcx.sess.features_untracked().generic_const_exprs;
|
||||||
if !feature_active {
|
if !feature_active {
|
||||||
feature_err(
|
feature_err(
|
||||||
&self.r.session.parse_sess,
|
&self.r.tcx.sess.parse_sess,
|
||||||
sym::generic_const_exprs,
|
sym::generic_const_exprs,
|
||||||
lifetime_ref.ident.span,
|
lifetime_ref.ident.span,
|
||||||
"a non-static lifetime is not allowed in a `const`",
|
"a non-static lifetime is not allowed in a `const`",
|
||||||
|
@ -2416,7 +2428,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
let spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
|
let spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
|
||||||
|
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self.r.session,
|
self.r.tcx.sess,
|
||||||
spans,
|
spans,
|
||||||
E0106,
|
E0106,
|
||||||
"missing lifetime specifier{}",
|
"missing lifetime specifier{}",
|
||||||
|
|
|
@ -861,11 +861,15 @@ struct MacroData {
|
||||||
macro_rules: bool,
|
macro_rules: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TyCtxt<'tcx> {
|
||||||
|
sess: &'tcx Session,
|
||||||
|
}
|
||||||
|
|
||||||
/// The main resolver class.
|
/// The main resolver class.
|
||||||
///
|
///
|
||||||
/// This is the visitor that walks the whole crate.
|
/// This is the visitor that walks the whole crate.
|
||||||
pub struct Resolver<'a, 'tcx> {
|
pub struct Resolver<'a, 'tcx> {
|
||||||
session: &'tcx Session,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
|
||||||
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
|
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
|
||||||
expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
|
expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
|
||||||
|
@ -1195,7 +1199,7 @@ impl<'tcx> Resolver<'_, 'tcx> {
|
||||||
if let Some(def_id) = def_id.as_local() {
|
if let Some(def_id) = def_id.as_local() {
|
||||||
self.item_generics_num_lifetimes[&def_id]
|
self.item_generics_num_lifetimes[&def_id]
|
||||||
} else {
|
} else {
|
||||||
self.cstore().item_generics_num_lifetimes(def_id, self.session)
|
self.cstore().item_generics_num_lifetimes(def_id, self.tcx.sess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1208,6 +1212,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
metadata_loader: Box<MetadataLoaderDyn>,
|
metadata_loader: Box<MetadataLoaderDyn>,
|
||||||
arenas: &'a ResolverArenas<'a>,
|
arenas: &'a ResolverArenas<'a>,
|
||||||
) -> Resolver<'a, 'tcx> {
|
) -> Resolver<'a, 'tcx> {
|
||||||
|
let tcx = TyCtxt { sess: session };
|
||||||
|
|
||||||
let root_def_id = CRATE_DEF_ID.to_def_id();
|
let root_def_id = CRATE_DEF_ID.to_def_id();
|
||||||
let mut module_map = FxHashMap::default();
|
let mut module_map = FxHashMap::default();
|
||||||
let graph_root = arenas.new_module(
|
let graph_root = arenas.new_module(
|
||||||
|
@ -1264,7 +1270,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
let features = session.features_untracked();
|
let features = session.features_untracked();
|
||||||
|
|
||||||
let mut resolver = Resolver {
|
let mut resolver = Resolver {
|
||||||
session,
|
tcx,
|
||||||
|
|
||||||
expn_that_defined: Default::default(),
|
expn_that_defined: Default::default(),
|
||||||
|
|
||||||
|
@ -1473,12 +1479,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
|
||||||
StableHashingContext::new(self.session, &self.untracked)
|
StableHashingContext::new(self.tcx.sess, &self.untracked)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crate_loader(&mut self) -> CrateLoader<'_> {
|
fn crate_loader(&mut self) -> CrateLoader<'_> {
|
||||||
CrateLoader::new(
|
CrateLoader::new(
|
||||||
&self.session,
|
&self.tcx.sess,
|
||||||
&*self.metadata_loader,
|
&*self.metadata_loader,
|
||||||
self.local_crate_name,
|
self.local_crate_name,
|
||||||
&mut *self.untracked.cstore.untracked_as_any().downcast_mut().unwrap(),
|
&mut *self.untracked.cstore.untracked_as_any().downcast_mut().unwrap(),
|
||||||
|
@ -1521,17 +1527,19 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
/// Entry point to crate resolution.
|
/// Entry point to crate resolution.
|
||||||
pub fn resolve_crate(&mut self, krate: &Crate) {
|
pub fn resolve_crate(&mut self, krate: &Crate) {
|
||||||
self.session.time("resolve_crate", || {
|
self.tcx.sess.time("resolve_crate", || {
|
||||||
self.session.time("finalize_imports", || ImportResolver { r: self }.finalize_imports());
|
self.tcx
|
||||||
self.session.time("compute_effective_visibilities", || {
|
.sess
|
||||||
|
.time("finalize_imports", || ImportResolver { r: self }.finalize_imports());
|
||||||
|
self.tcx.sess.time("compute_effective_visibilities", || {
|
||||||
EffectiveVisibilitiesVisitor::compute_effective_visibilities(self, krate)
|
EffectiveVisibilitiesVisitor::compute_effective_visibilities(self, krate)
|
||||||
});
|
});
|
||||||
self.session.time("finalize_macro_resolutions", || self.finalize_macro_resolutions());
|
self.tcx.sess.time("finalize_macro_resolutions", || self.finalize_macro_resolutions());
|
||||||
self.session.time("late_resolve_crate", || self.late_resolve_crate(krate));
|
self.tcx.sess.time("late_resolve_crate", || self.late_resolve_crate(krate));
|
||||||
self.session.time("resolve_main", || self.resolve_main());
|
self.tcx.sess.time("resolve_main", || self.resolve_main());
|
||||||
self.session.time("resolve_check_unused", || self.check_unused(krate));
|
self.tcx.sess.time("resolve_check_unused", || self.check_unused(krate));
|
||||||
self.session.time("resolve_report_errors", || self.report_errors(krate));
|
self.tcx.sess.time("resolve_report_errors", || self.report_errors(krate));
|
||||||
self.session.time("resolve_postprocess", || self.crate_loader().postprocess(krate));
|
self.tcx.sess.time("resolve_postprocess", || self.crate_loader().postprocess(krate));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1961,7 +1969,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
let attr = self
|
let attr = self
|
||||||
.cstore()
|
.cstore()
|
||||||
.item_attrs_untracked(def_id, self.session)
|
.item_attrs_untracked(def_id, self.tcx.sess)
|
||||||
.find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
|
.find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
|
||||||
let mut ret = Vec::new();
|
let mut ret = Vec::new();
|
||||||
for meta in attr.meta_item_list()? {
|
for meta in attr.meta_item_list()? {
|
||||||
|
|
|
@ -195,7 +195,8 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind) {
|
fn register_builtin_macro(&mut self, name: Symbol, ext: SyntaxExtensionKind) {
|
||||||
if self.builtin_macros.insert(name, BuiltinMacroState::NotYetSeen(ext)).is_some() {
|
if self.builtin_macros.insert(name, BuiltinMacroState::NotYetSeen(ext)).is_some() {
|
||||||
self.session
|
self.tcx
|
||||||
|
.sess
|
||||||
.diagnostic()
|
.diagnostic()
|
||||||
.bug(&format!("built-in macro `{}` was already registered", name));
|
.bug(&format!("built-in macro `{}` was already registered", name));
|
||||||
}
|
}
|
||||||
|
@ -216,7 +217,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
|
||||||
ExpnData::allow_unstable(
|
ExpnData::allow_unstable(
|
||||||
ExpnKind::AstPass(pass),
|
ExpnKind::AstPass(pass),
|
||||||
call_site,
|
call_site,
|
||||||
self.session.edition(),
|
self.tcx.sess.edition(),
|
||||||
features.into(),
|
features.into(),
|
||||||
None,
|
None,
|
||||||
parent_module,
|
parent_module,
|
||||||
|
@ -430,7 +431,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
|
||||||
PathResult::NonModule(..) |
|
PathResult::NonModule(..) |
|
||||||
// HACK(Urgau): This shouldn't be necessary
|
// HACK(Urgau): This shouldn't be necessary
|
||||||
PathResult::Failed { is_error_from_last_segment: false, .. } => {
|
PathResult::Failed { is_error_from_last_segment: false, .. } => {
|
||||||
self.session
|
self.tcx.sess
|
||||||
.struct_span_err(span, "not sure whether the path is accessible or not")
|
.struct_span_err(span, "not sure whether the path is accessible or not")
|
||||||
.note("the type may have associated items, but we are currently not checking them")
|
.note("the type may have associated items, but we are currently not checking them")
|
||||||
.emit();
|
.emit();
|
||||||
|
@ -455,7 +456,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_proc_macro_quoted_span(&self, krate: CrateNum, id: usize) -> Span {
|
fn get_proc_macro_quoted_span(&self, krate: CrateNum, id: usize) -> Span {
|
||||||
self.cstore().get_proc_macro_quoted_span_untracked(krate, id, self.session)
|
self.cstore().get_proc_macro_quoted_span_untracked(krate, id, self.tcx.sess)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn declare_proc_macro(&mut self, id: NodeId) {
|
fn declare_proc_macro(&mut self, id: NodeId) {
|
||||||
|
@ -493,10 +494,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
// Report errors for the resolved macro.
|
// Report errors for the resolved macro.
|
||||||
for segment in &path.segments {
|
for segment in &path.segments {
|
||||||
if let Some(args) = &segment.args {
|
if let Some(args) = &segment.args {
|
||||||
self.session.span_err(args.span(), "generic arguments in macro path");
|
self.tcx.sess.span_err(args.span(), "generic arguments in macro path");
|
||||||
}
|
}
|
||||||
if kind == MacroKind::Attr && segment.ident.as_str().starts_with("rustc") {
|
if kind == MacroKind::Attr && segment.ident.as_str().starts_with("rustc") {
|
||||||
self.session.span_err(
|
self.tcx.sess.span_err(
|
||||||
segment.ident.span,
|
segment.ident.span,
|
||||||
"attributes starting with `rustc` are reserved for use by the `rustc` compiler",
|
"attributes starting with `rustc` are reserved for use by the `rustc` compiler",
|
||||||
);
|
);
|
||||||
|
@ -508,7 +509,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
if let Some(def_id) = def_id.as_local() {
|
if let Some(def_id) = def_id.as_local() {
|
||||||
self.unused_macros.remove(&def_id);
|
self.unused_macros.remove(&def_id);
|
||||||
if self.proc_macro_stubs.contains(&def_id) {
|
if self.proc_macro_stubs.contains(&def_id) {
|
||||||
self.session.span_err(
|
self.tcx.sess.span_err(
|
||||||
path.span,
|
path.span,
|
||||||
"can't use a procedural macro from the same crate that defines it",
|
"can't use a procedural macro from the same crate that defines it",
|
||||||
);
|
);
|
||||||
|
@ -540,7 +541,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
if let Some((article, expected)) = unexpected_res {
|
if let Some((article, expected)) = unexpected_res {
|
||||||
let path_str = pprust::path_to_string(path);
|
let path_str = pprust::path_to_string(path);
|
||||||
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path_str);
|
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path_str);
|
||||||
self.session
|
self.tcx
|
||||||
|
.sess
|
||||||
.struct_span_err(path.span, &msg)
|
.struct_span_err(path.span, &msg)
|
||||||
.span_label(path.span, format!("not {} {}", article, expected))
|
.span_label(path.span, format!("not {} {}", article, expected))
|
||||||
.emit();
|
.emit();
|
||||||
|
@ -550,7 +552,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
// We are trying to avoid reporting this error if other related errors were reported.
|
// We are trying to avoid reporting this error if other related errors were reported.
|
||||||
if res != Res::Err
|
if res != Res::Err
|
||||||
&& inner_attr
|
&& inner_attr
|
||||||
&& !self.session.features_untracked().custom_inner_attributes
|
&& !self.tcx.sess.features_untracked().custom_inner_attributes
|
||||||
{
|
{
|
||||||
let msg = match res {
|
let msg = match res {
|
||||||
Res::Def(..) => "inner macro attributes are unstable",
|
Res::Def(..) => "inner macro attributes are unstable",
|
||||||
|
@ -558,10 +560,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
if soft_custom_inner_attributes_gate {
|
if soft_custom_inner_attributes_gate {
|
||||||
self.session.parse_sess.buffer_lint(SOFT_UNSTABLE, path.span, node_id, msg);
|
self.tcx.sess.parse_sess.buffer_lint(SOFT_UNSTABLE, path.span, node_id, msg);
|
||||||
} else {
|
} else {
|
||||||
feature_err(&self.session.parse_sess, sym::custom_inner_attributes, path.span, msg)
|
feature_err(
|
||||||
.emit();
|
&self.tcx.sess.parse_sess,
|
||||||
|
sym::custom_inner_attributes,
|
||||||
|
path.span,
|
||||||
|
msg,
|
||||||
|
)
|
||||||
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,7 +662,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
// Make sure compilation does not succeed if preferred macro resolution
|
// Make sure compilation does not succeed if preferred macro resolution
|
||||||
// has changed after the macro had been expanded. In theory all such
|
// has changed after the macro had been expanded. In theory all such
|
||||||
// situations should be reported as errors, so this is a bug.
|
// situations should be reported as errors, so this is a bug.
|
||||||
this.session.delay_span_bug(span, "inconsistent resolution for a macro");
|
this.tcx.sess.delay_span_bug(span, "inconsistent resolution for a macro");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// It's possible that the macro was unresolved (indeterminate) and silently
|
// It's possible that the macro was unresolved (indeterminate) and silently
|
||||||
|
@ -672,7 +679,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
Segment::names_to_string(path)
|
Segment::names_to_string(path)
|
||||||
);
|
);
|
||||||
let msg_note = "import resolution is stuck, try simplifying macro imports";
|
let msg_note = "import resolution is stuck, try simplifying macro imports";
|
||||||
this.session.struct_span_err(span, &msg).note(msg_note).emit();
|
this.tcx.sess.struct_span_err(span, &msg).note(msg_note).emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -699,7 +706,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
// try to suggest if it's not a macro, maybe a function
|
// try to suggest if it's not a macro, maybe a function
|
||||||
if let PathResult::NonModule(partial_res) = self.maybe_resolve_path(&path, Some(ValueNS), &parent_scope)
|
if let PathResult::NonModule(partial_res) = self.maybe_resolve_path(&path, Some(ValueNS), &parent_scope)
|
||||||
&& partial_res.unresolved_segments() == 0 {
|
&& partial_res.unresolved_segments() == 0 {
|
||||||
let sm = self.session.source_map();
|
let sm = self.tcx.sess.source_map();
|
||||||
let exclamation_span = sm.next_point(span);
|
let exclamation_span = sm.next_point(span);
|
||||||
suggestion = Some((
|
suggestion = Some((
|
||||||
vec![(exclamation_span, "".to_string())],
|
vec![(exclamation_span, "".to_string())],
|
||||||
|
@ -762,7 +769,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
Err(..) => {
|
Err(..) => {
|
||||||
let expected = kind.descr_expected();
|
let expected = kind.descr_expected();
|
||||||
let msg = format!("cannot find {} `{}` in this scope", expected, ident);
|
let msg = format!("cannot find {} `{}` in this scope", expected, ident);
|
||||||
let mut err = self.session.struct_span_err(ident.span, &msg);
|
let mut err = self.tcx.sess.struct_span_err(ident.span, &msg);
|
||||||
self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident);
|
self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident);
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
@ -804,7 +811,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
let soft_handler =
|
let soft_handler =
|
||||||
|lint, span, msg: &_| lint_buffer.buffer_lint(lint, node_id, span, msg);
|
|lint, span, msg: &_| lint_buffer.buffer_lint(lint, node_id, span, msg);
|
||||||
stability::report_unstable(
|
stability::report_unstable(
|
||||||
self.session,
|
self.tcx.sess,
|
||||||
feature,
|
feature,
|
||||||
reason.to_opt_reason(),
|
reason.to_opt_reason(),
|
||||||
issue,
|
issue,
|
||||||
|
@ -840,7 +847,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
if kind != NonMacroAttrKind::Tool && binding.map_or(true, |b| b.is_import()) {
|
if kind != NonMacroAttrKind::Tool && binding.map_or(true, |b| b.is_import()) {
|
||||||
let msg =
|
let msg =
|
||||||
format!("cannot use {} {} through an import", kind.article(), kind.descr());
|
format!("cannot use {} {} through an import", kind.article(), kind.descr());
|
||||||
let mut err = self.session.struct_span_err(span, &msg);
|
let mut err = self.tcx.sess.struct_span_err(span, &msg);
|
||||||
if let Some(binding) = binding {
|
if let Some(binding) = binding {
|
||||||
err.span_note(binding.span, &format!("the {} imported here", kind.descr()));
|
err.span_note(binding.span, &format!("the {} imported here", kind.descr()));
|
||||||
}
|
}
|
||||||
|
@ -855,7 +862,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
if ident.name == sym::cfg || ident.name == sym::cfg_attr {
|
if ident.name == sym::cfg || ident.name == sym::cfg_attr {
|
||||||
let macro_kind = self.get_macro(res).map(|macro_data| macro_data.ext.macro_kind());
|
let macro_kind = self.get_macro(res).map(|macro_data| macro_data.ext.macro_kind());
|
||||||
if macro_kind.is_some() && sub_namespace_match(macro_kind, Some(MacroKind::Attr)) {
|
if macro_kind.is_some() && sub_namespace_match(macro_kind, Some(MacroKind::Attr)) {
|
||||||
self.session.span_err(
|
self.tcx.sess.span_err(
|
||||||
ident.span,
|
ident.span,
|
||||||
&format!("name `{}` is reserved in attribute namespace", ident),
|
&format!("name `{}` is reserved in attribute namespace", ident),
|
||||||
);
|
);
|
||||||
|
@ -872,8 +879,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
) -> (SyntaxExtension, Vec<(usize, Span)>) {
|
) -> (SyntaxExtension, Vec<(usize, Span)>) {
|
||||||
let (mut result, mut rule_spans) = compile_declarative_macro(
|
let (mut result, mut rule_spans) = compile_declarative_macro(
|
||||||
&self.session,
|
&self.tcx.sess,
|
||||||
self.session.features_untracked(),
|
self.tcx.sess.features_untracked(),
|
||||||
item,
|
item,
|
||||||
edition,
|
edition,
|
||||||
);
|
);
|
||||||
|
@ -895,7 +902,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
BuiltinMacroState::AlreadySeen(span) => {
|
BuiltinMacroState::AlreadySeen(span) => {
|
||||||
struct_span_err!(
|
struct_span_err!(
|
||||||
self.session,
|
self.tcx.sess,
|
||||||
item.span,
|
item.span,
|
||||||
E0773,
|
E0773,
|
||||||
"attempted to define built-in macro more than once"
|
"attempted to define built-in macro more than once"
|
||||||
|
@ -906,7 +913,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let msg = format!("cannot find a built-in macro with name `{}`", item.ident);
|
let msg = format!("cannot find a built-in macro with name `{}`", item.ident);
|
||||||
self.session.span_err(item.span, &msg);
|
self.tcx.sess.span_err(item.span, &msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue