mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Shrink mbe::ExpandError
and mbe::ParseError
This commit is contained in:
parent
2310908df7
commit
2ad71f1350
8 changed files with 78 additions and 92 deletions
|
@ -368,7 +368,7 @@ fn compile_error_expand(
|
|||
let text = it.text.as_str();
|
||||
if text.starts_with('"') && text.ends_with('"') {
|
||||
// FIXME: does not handle raw strings
|
||||
mbe::ExpandError::Other(text[1..text.len() - 1].to_string())
|
||||
mbe::ExpandError::Other(text[1..text.len() - 1].into())
|
||||
} else {
|
||||
mbe::ExpandError::BindingError("`compile_error!` argument must be a string".into())
|
||||
}
|
||||
|
@ -451,12 +451,12 @@ fn relative_file(
|
|||
) -> Result<FileId, mbe::ExpandError> {
|
||||
let call_site = call_id.as_file().original_file(db);
|
||||
let path = AnchoredPath { anchor: call_site, path: path_str };
|
||||
let res = db
|
||||
.resolve_path(path)
|
||||
.ok_or_else(|| mbe::ExpandError::Other(format!("failed to load file `{}`", path_str)))?;
|
||||
let res = db.resolve_path(path).ok_or_else(|| {
|
||||
mbe::ExpandError::Other(format!("failed to load file `{path_str}`").into())
|
||||
})?;
|
||||
// Prevent include itself
|
||||
if res == call_site && !allow_recursion {
|
||||
Err(mbe::ExpandError::Other(format!("recursive inclusion of `{}`", path_str)))
|
||||
Err(mbe::ExpandError::Other(format!("recursive inclusion of `{path_str}`").into()))
|
||||
} else {
|
||||
Ok(res)
|
||||
}
|
||||
|
|
|
@ -390,7 +390,7 @@ fn macro_def(db: &dyn AstDatabase, id: MacroDefId) -> Result<Arc<TokenExpander>,
|
|||
MacroDefKind::BuiltInEager(..) => {
|
||||
// FIXME: Return a random error here just to make the types align.
|
||||
// This obviously should do something real instead.
|
||||
Err(mbe::ParseError::UnexpectedToken("unexpected eager macro".to_string()))
|
||||
Err(mbe::ParseError::UnexpectedToken("unexpected eager macro".into()))
|
||||
}
|
||||
MacroDefKind::ProcMacro(expander, ..) => Ok(Arc::new(TokenExpander::ProcMacro(expander))),
|
||||
}
|
||||
|
|
|
@ -51,12 +51,12 @@ impl ProcMacroExpander {
|
|||
{
|
||||
ExpandResult {
|
||||
value: tt.clone(),
|
||||
err: Some(mbe::ExpandError::Other(text)),
|
||||
err: Some(mbe::ExpandError::Other(text.into())),
|
||||
}
|
||||
}
|
||||
ProcMacroExpansionError::System(text)
|
||||
| ProcMacroExpansionError::Panic(text) => {
|
||||
ExpandResult::only_err(mbe::ExpandError::Other(text))
|
||||
ExpandResult::only_err(mbe::ExpandError::Other(text.into()))
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue