Skip to content

Commit 1d5fb06

Browse files
committedJan 13, 2017
Auto merge of #38890 - petrochenkov:noresolve, r=nrc
resolve: Do not use "resolve"/"resolution" in error messages Use less jargon-y wording instead. `cannot find <struct> <S> in <this scope>` and `cannot find <struct> <S> in <module a::b>` are used for base messages (this also harmonizes nicely with "you can import it into scope" suggestions) and `not found in <this scope>` and `not found in <a::b>` are used for short labels in fall-back case. I tweaked some other diagnostics to avoid using "resolve" (see, e.g., `librustc_resolve/macros.rs`), but haven't touched messages for imports. Closes #38750 r? @nrc
2 parents b0c52c5 + 2092682 commit 1d5fb06

File tree

93 files changed

+304
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+304
-294
lines changed
 

‎src/librustc_resolve/lib.rs

+22-11
Original file line numberDiff line numberDiff line change
@@ -2090,10 +2090,25 @@ impl<'a> Resolver<'a> {
20902090
let expected = source.descr_expected();
20912091
let path_str = names_to_string(path);
20922092
let code = source.error_code(def.is_some());
2093-
let base_msg = if let Some(def) = def {
2094-
format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str)
2093+
let (base_msg, fallback_label) = if let Some(def) = def {
2094+
(format!("expected {}, found {} `{}`", expected, def.kind_name(), path_str),
2095+
format!("not a {}", expected))
20952096
} else {
2096-
format!("unresolved {} `{}`", expected, path_str)
2097+
let item_str = path[path.len() - 1];
2098+
let (mod_prefix, mod_str) = if path.len() == 1 {
2099+
(format!(""), format!("this scope"))
2100+
} else if path.len() == 2 && path[0].name == keywords::CrateRoot.name() {
2101+
(format!(""), format!("the crate root"))
2102+
} else {
2103+
let mod_path = &path[..path.len() - 1];
2104+
let mod_prefix = match this.resolve_path(mod_path, Some(TypeNS), None) {
2105+
PathResult::Module(module) => module.def(),
2106+
_ => None,
2107+
}.map_or(format!(""), |def| format!("{} ", def.kind_name()));
2108+
(mod_prefix, format!("`{}`", names_to_string(mod_path)))
2109+
};
2110+
(format!("cannot find {} `{}` in {}{}", expected, item_str, mod_prefix, mod_str),
2111+
format!("not found in {}", mod_str))
20972112
};
20982113
let mut err = this.session.struct_span_err_with_code(span, &base_msg, code);
20992114

@@ -2183,12 +2198,8 @@ impl<'a> Resolver<'a> {
21832198
}
21842199
}
21852200

2186-
// Fallback labels.
2187-
if def.is_some() {
2188-
err.span_label(span, &format!("not a {}", expected));
2189-
} else {
2190-
err.span_label(span, &format!("no resolution found"));
2191-
}
2201+
// Fallback label.
2202+
err.span_label(span, &fallback_label);
21922203
err
21932204
};
21942205
let report_errors = |this: &mut Self, def: Option<Def>| {
@@ -2989,8 +3000,8 @@ impl<'a> Resolver<'a> {
29893000
let participle = |binding: &NameBinding| {
29903001
if binding.is_import() { "imported" } else { "defined" }
29913002
};
2992-
let msg1 = format!("`{}` could resolve to the name {} here", name, participle(b1));
2993-
let msg2 = format!("`{}` could also resolve to the name {} here", name, participle(b2));
3003+
let msg1 = format!("`{}` could refer to the name {} here", name, participle(b1));
3004+
let msg2 = format!("`{}` could also refer to the name {} here", name, participle(b2));
29943005
let note = if !lexical && b1.is_glob_import() {
29953006
format!("consider adding an explicit import of `{}` to disambiguate", name)
29963007
} else if let Def::Macro(..) = b1.def() {

‎src/librustc_resolve/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ impl<'a> Resolver<'a> {
380380
MacroBinding::Modern(binding) => (binding.span, "imported"),
381381
MacroBinding::Legacy(binding) => (binding.span, "defined"),
382382
};
383-
let msg1 = format!("`{}` could resolve to the macro {} here", ident, participle);
384-
let msg2 = format!("`{}` could also resolve to the macro imported here", ident);
383+
let msg1 = format!("`{}` could refer to the macro {} here", ident, participle);
384+
let msg2 = format!("`{}` could also refer to the macro imported here", ident);
385385
self.session.struct_span_err(span, &format!("`{}` is ambiguous", ident))
386386
.span_note(legacy_span, &msg1)
387387
.span_note(resolution.span, &msg2)

0 commit comments

Comments
 (0)