1
Fork 0

change the type of note field to Option<String>

This commit is contained in:
Takayuki Maeda 2022-07-28 18:17:55 +09:00
parent ada80a13b9
commit 089471b129
2 changed files with 21 additions and 26 deletions

View file

@ -2023,7 +2023,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
span: Span, span: Span,
mut path: Vec<Segment>, mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>, parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> { ) -> Option<(Vec<Segment>, Option<String>)> {
debug!("make_path_suggestion: span={:?} path={:?}", span, path); debug!("make_path_suggestion: span={:?} path={:?}", span, path);
match (path.get(0), path.get(1)) { match (path.get(0), path.get(1)) {
@ -2058,12 +2058,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
&mut self, &mut self,
mut path: Vec<Segment>, mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>, parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> { ) -> Option<(Vec<Segment>, Option<String>)> {
// Replace first ident with `self` and check if that is valid. // Replace first ident with `self` and check if that is valid.
path[0].ident.name = kw::SelfLower; path[0].ident.name = kw::SelfLower;
let result = self.r.maybe_resolve_path(&path, None, parent_scope); let result = self.r.maybe_resolve_path(&path, None, parent_scope);
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result); debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None } if let PathResult::Module(..) = result { Some((path, None)) } else { None }
} }
/// Suggests a missing `crate::` if that resolves to an correct module. /// Suggests a missing `crate::` if that resolves to an correct module.
@ -2077,7 +2077,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
&mut self, &mut self,
mut path: Vec<Segment>, mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>, parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> { ) -> Option<(Vec<Segment>, Option<String>)> {
// Replace first ident with `crate` and check if that is valid. // Replace first ident with `crate` and check if that is valid.
path[0].ident.name = kw::Crate; path[0].ident.name = kw::Crate;
let result = self.r.maybe_resolve_path(&path, None, parent_scope); let result = self.r.maybe_resolve_path(&path, None, parent_scope);
@ -2085,12 +2085,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
if let PathResult::Module(..) = result { if let PathResult::Module(..) = result {
Some(( Some((
path, path,
vec![ Some(
"`use` statements changed in Rust 2018; read more at \ "`use` statements changed in Rust 2018; read more at \
<https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-\ <https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-\
clarity.html>" clarity.html>"
.to_string(), .to_string(),
], ),
)) ))
} else { } else {
None None
@ -2108,12 +2108,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
&mut self, &mut self,
mut path: Vec<Segment>, mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>, parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> { ) -> Option<(Vec<Segment>, Option<String>)> {
// Replace first ident with `crate` and check if that is valid. // Replace first ident with `crate` and check if that is valid.
path[0].ident.name = kw::Super; path[0].ident.name = kw::Super;
let result = self.r.maybe_resolve_path(&path, None, parent_scope); let result = self.r.maybe_resolve_path(&path, None, parent_scope);
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result); debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None } if let PathResult::Module(..) = result { Some((path, None)) } else { None }
} }
/// Suggests a missing external crate name if that resolves to an correct module. /// Suggests a missing external crate name if that resolves to an correct module.
@ -2130,7 +2130,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
&mut self, &mut self,
mut path: Vec<Segment>, mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>, parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> { ) -> Option<(Vec<Segment>, Option<String>)> {
if path[1].ident.span.rust_2015() { if path[1].ident.span.rust_2015() {
return None; return None;
} }
@ -2151,7 +2151,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
name, path, result name, path, result
); );
if let PathResult::Module(..) = result { if let PathResult::Module(..) = result {
return Some((path, Vec::new())); return Some((path, None));
} }
} }
@ -2175,7 +2175,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
import: &'b Import<'b>, import: &'b Import<'b>,
module: ModuleOrUniformRoot<'b>, module: ModuleOrUniformRoot<'b>,
ident: Ident, ident: Ident,
) -> Option<(Option<Suggestion>, Vec<String>)> { ) -> Option<(Option<Suggestion>, Option<String>)> {
let ModuleOrUniformRoot::Module(mut crate_module) = module else { let ModuleOrUniformRoot::Module(mut crate_module) = module else {
return None; return None;
}; };
@ -2287,12 +2287,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
String::from("a macro with this name exists at the root of the crate"), String::from("a macro with this name exists at the root of the crate"),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
)); ));
let note = vec![ Some((suggestion, Some("this could be because a macro annotated with `#[macro_export]` will be exported \
"this could be because a macro annotated with `#[macro_export]` will be exported \
at the root of the crate instead of the module where it is defined" at the root of the crate instead of the module where it is defined"
.to_string(), .to_string())))
];
Some((suggestion, note))
} else { } else {
None None
} }

View file

@ -336,7 +336,7 @@ impl<'a> Resolver<'a> {
struct UnresolvedImportError { struct UnresolvedImportError {
span: Span, span: Span,
label: Option<String>, label: Option<String>,
note: Vec<String>, note: Option<String>,
suggestion: Option<Suggestion>, suggestion: Option<Suggestion>,
} }
@ -427,7 +427,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
let err = UnresolvedImportError { let err = UnresolvedImportError {
span: import.span, span: import.span,
label: None, label: None,
note: Vec::new(), note: None,
suggestion: None, suggestion: None,
}; };
if path.contains("::") { if path.contains("::") {
@ -463,10 +463,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
let mut diag = struct_span_err!(self.r.session, span, E0432, "{}", &msg); let mut diag = struct_span_err!(self.r.session, span, E0432, "{}", &msg);
if let Some((_, UnresolvedImportError { note, .. })) = errors.iter().last() { if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() {
for message in note { diag.note(note);
diag.note(message);
}
} }
for (_, err) in errors.into_iter().take(MAX_LABEL_COUNT) { for (_, err) in errors.into_iter().take(MAX_LABEL_COUNT) {
@ -644,7 +642,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
None => UnresolvedImportError { None => UnresolvedImportError {
span, span,
label: Some(label), label: Some(label),
note: Vec::new(), note: None,
suggestion, suggestion,
}, },
}; };
@ -686,7 +684,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
return Some(UnresolvedImportError { return Some(UnresolvedImportError {
span: import.span, span: import.span,
label: Some(String::from("cannot glob-import a module into itself")), label: Some(String::from("cannot glob-import a module into itself")),
note: Vec::new(), note: None,
suggestion: None, suggestion: None,
}); });
} }
@ -830,7 +828,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
let (suggestion, note) = let (suggestion, note) =
match self.check_for_module_export_macro(import, module, ident) { match self.check_for_module_export_macro(import, module, ident) {
Some((suggestion, note)) => (suggestion.or(lev_suggestion), note), Some((suggestion, note)) => (suggestion.or(lev_suggestion), note),
_ => (lev_suggestion, Vec::new()), _ => (lev_suggestion, None),
}; };
let label = match module { let label = match module {