Merge #9165
9165: Apply some clippy suggestions r=matklad a=clemenswasser Co-authored-by: Clemens Wasser <clemens.wasser@gmail.com>
This commit is contained in:
commit
56e61bdfea
@ -219,8 +219,7 @@ impl Crate {
|
|||||||
let doc_url = doc_attr_q.tt_values().map(|tt| {
|
let doc_url = doc_attr_q.tt_values().map(|tt| {
|
||||||
let name = tt.token_trees.iter()
|
let name = tt.token_trees.iter()
|
||||||
.skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident{text: ref ident, ..})) if ident == "html_root_url"))
|
.skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident{text: ref ident, ..})) if ident == "html_root_url"))
|
||||||
.skip(2)
|
.nth(2);
|
||||||
.next();
|
|
||||||
|
|
||||||
match name {
|
match name {
|
||||||
Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text),
|
Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text),
|
||||||
@ -1846,7 +1845,7 @@ impl TypeParam {
|
|||||||
|
|
||||||
pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> {
|
pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> {
|
||||||
db.generic_predicates_for_param(self.id)
|
db.generic_predicates_for_param(self.id)
|
||||||
.into_iter()
|
.iter()
|
||||||
.filter_map(|pred| match &pred.skip_binders().skip_binders() {
|
.filter_map(|pred| match &pred.skip_binders().skip_binders() {
|
||||||
hir_ty::WhereClause::Implemented(trait_ref) => {
|
hir_ty::WhereClause::Implemented(trait_ref) => {
|
||||||
Some(Trait::from(trait_ref.hir_trait_id()))
|
Some(Trait::from(trait_ref.hir_trait_id()))
|
||||||
@ -1951,7 +1950,7 @@ impl Impl {
|
|||||||
all.extend(
|
all.extend(
|
||||||
db.inherent_impls_in_crate(id)
|
db.inherent_impls_in_crate(id)
|
||||||
.for_self_ty(&ty)
|
.for_self_ty(&ty)
|
||||||
.into_iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(Self::from)
|
.map(Self::from)
|
||||||
.filter(filter),
|
.filter(filter),
|
||||||
@ -2232,8 +2231,8 @@ impl Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
|
pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
|
||||||
let adt_id = match self.ty.kind(&Interner) {
|
let adt_id = match *self.ty.kind(&Interner) {
|
||||||
&TyKind::Adt(hir_ty::AdtId(adt_id), ..) => adt_id,
|
TyKind::Adt(hir_ty::AdtId(adt_id), ..) => adt_id,
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2287,9 +2286,9 @@ impl Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
|
pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
|
||||||
let (variant_id, substs) = match self.ty.kind(&Interner) {
|
let (variant_id, substs) = match *self.ty.kind(&Interner) {
|
||||||
&TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), ref substs) => (s.into(), substs),
|
TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), ref substs) => (s.into(), substs),
|
||||||
&TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), ref substs) => (u.into(), substs),
|
TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), ref substs) => (u.into(), substs),
|
||||||
_ => return Vec::new(),
|
_ => return Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2488,20 +2487,17 @@ impl Type {
|
|||||||
cb: &mut impl FnMut(Type),
|
cb: &mut impl FnMut(Type),
|
||||||
) {
|
) {
|
||||||
for pred in bounds {
|
for pred in bounds {
|
||||||
match pred.skip_binders() {
|
if let WhereClause::Implemented(trait_ref) = pred.skip_binders() {
|
||||||
WhereClause::Implemented(trait_ref) => {
|
cb(type_.clone());
|
||||||
cb(type_.clone());
|
// skip the self type. it's likely the type we just got the bounds from
|
||||||
// skip the self type. it's likely the type we just got the bounds from
|
for ty in trait_ref
|
||||||
for ty in trait_ref
|
.substitution
|
||||||
.substitution
|
.iter(&Interner)
|
||||||
.iter(&Interner)
|
.skip(1)
|
||||||
.skip(1)
|
.filter_map(|a| a.ty(&Interner))
|
||||||
.filter_map(|a| a.ty(&Interner))
|
{
|
||||||
{
|
walk_type(db, &type_.derived(ty.clone()), cb);
|
||||||
walk_type(db, &type_.derived(ty.clone()), cb);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2514,7 +2510,7 @@ impl Type {
|
|||||||
walk_substs(db, type_, substs, cb);
|
walk_substs(db, type_, substs, cb);
|
||||||
}
|
}
|
||||||
TyKind::AssociatedType(_, substs) => {
|
TyKind::AssociatedType(_, substs) => {
|
||||||
if let Some(_) = ty.associated_type_parent_trait(db) {
|
if ty.associated_type_parent_trait(db).is_some() {
|
||||||
cb(type_.derived(ty.clone()));
|
cb(type_.derived(ty.clone()));
|
||||||
}
|
}
|
||||||
walk_substs(db, type_, substs, cb);
|
walk_substs(db, type_, substs, cb);
|
||||||
|
@ -690,9 +690,7 @@ impl ExprCollector<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::Stmt::Item(item) => {
|
ast::Stmt::Item(item) => {
|
||||||
if self.check_cfg(&item).is_none() {
|
self.check_cfg(&item);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -717,7 +715,8 @@ impl ExprCollector<'_> {
|
|||||||
block.statements().for_each(|s| self.collect_stmt(s));
|
block.statements().for_each(|s| self.collect_stmt(s));
|
||||||
block.tail_expr().and_then(|e| {
|
block.tail_expr().and_then(|e| {
|
||||||
let expr = self.maybe_collect_expr(e)?;
|
let expr = self.maybe_collect_expr(e)?;
|
||||||
Some(self.statements_in_scope.push(Statement::Expr { expr, has_semi: false }))
|
self.statements_in_scope.push(Statement::Expr { expr, has_semi: false });
|
||||||
|
Some(())
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut tail = None;
|
let mut tail = None;
|
||||||
|
@ -15,12 +15,9 @@ fn lower(ra_fixture: &str) -> Arc<Body> {
|
|||||||
let mut fn_def = None;
|
let mut fn_def = None;
|
||||||
'outer: for (_, module) in def_map.modules() {
|
'outer: for (_, module) in def_map.modules() {
|
||||||
for decl in module.scope.declarations() {
|
for decl in module.scope.declarations() {
|
||||||
match decl {
|
if let ModuleDefId::FunctionId(it) = decl {
|
||||||
ModuleDefId::FunctionId(it) => {
|
fn_def = Some(it);
|
||||||
fn_def = Some(it);
|
break 'outer;
|
||||||
break 'outer;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ impl GenericParams {
|
|||||||
) -> Interned<GenericParams> {
|
) -> Interned<GenericParams> {
|
||||||
let _p = profile::span("generic_params_query");
|
let _p = profile::span("generic_params_query");
|
||||||
|
|
||||||
let generics = match def {
|
match def {
|
||||||
GenericDefId::FunctionId(id) => {
|
GenericDefId::FunctionId(id) => {
|
||||||
let id = id.lookup(db).id;
|
let id = id.lookup(db).id;
|
||||||
let tree = id.item_tree(db);
|
let tree = id.item_tree(db);
|
||||||
@ -150,8 +150,7 @@ impl GenericParams {
|
|||||||
GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => {
|
GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => {
|
||||||
Interned::new(GenericParams::default())
|
Interned::new(GenericParams::default())
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
generics
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) {
|
fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) {
|
||||||
|
@ -241,10 +241,8 @@ impl ItemScope {
|
|||||||
check_changed!(changed, (self / def).values, glob_imports[lookup], def_import_type);
|
check_changed!(changed, (self / def).values, glob_imports[lookup], def_import_type);
|
||||||
check_changed!(changed, (self / def).macros, glob_imports[lookup], def_import_type);
|
check_changed!(changed, (self / def).macros, glob_imports[lookup], def_import_type);
|
||||||
|
|
||||||
if def.is_none() {
|
if def.is_none() && self.unresolved.insert(lookup.1) {
|
||||||
if self.unresolved.insert(lookup.1) {
|
changed = true;
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
changed
|
changed
|
||||||
|
@ -30,16 +30,16 @@ pub(super) fn print_item_tree(tree: &ItemTree) -> String {
|
|||||||
|
|
||||||
macro_rules! w {
|
macro_rules! w {
|
||||||
($dst:expr, $($arg:tt)*) => {
|
($dst:expr, $($arg:tt)*) => {
|
||||||
drop(write!($dst, $($arg)*))
|
{ let _ = write!($dst, $($arg)*); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! wln {
|
macro_rules! wln {
|
||||||
($dst:expr) => {
|
($dst:expr) => {
|
||||||
drop(writeln!($dst))
|
{ let _ = writeln!($dst); }
|
||||||
};
|
};
|
||||||
($dst:expr, $($arg:tt)*) => {
|
($dst:expr, $($arg:tt)*) => {
|
||||||
drop(writeln!($dst, $($arg)*))
|
{ let _ = writeln!($dst, $($arg)*); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,10 +367,7 @@ impl DefMap {
|
|||||||
pub fn containing_module(&self, local_mod: LocalModuleId) -> Option<ModuleId> {
|
pub fn containing_module(&self, local_mod: LocalModuleId) -> Option<ModuleId> {
|
||||||
match &self[local_mod].parent {
|
match &self[local_mod].parent {
|
||||||
Some(parent) => Some(self.module_id(*parent)),
|
Some(parent) => Some(self.module_id(*parent)),
|
||||||
None => match &self.block {
|
None => self.block.as_ref().map(|block| block.parent),
|
||||||
Some(block) => Some(block.parent),
|
|
||||||
None => None,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ impl ResolvePathResult {
|
|||||||
segment_index: Option<usize>,
|
segment_index: Option<usize>,
|
||||||
krate: Option<CrateId>,
|
krate: Option<CrateId>,
|
||||||
) -> ResolvePathResult {
|
) -> ResolvePathResult {
|
||||||
ResolvePathResult { resolved_def, reached_fixedpoint, segment_index, krate }
|
ResolvePathResult { resolved_def, segment_index, reached_fixedpoint, krate }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ impl Path {
|
|||||||
|
|
||||||
pub fn is_self_type(&self) -> bool {
|
pub fn is_self_type(&self) -> bool {
|
||||||
self.type_anchor.is_none()
|
self.type_anchor.is_none()
|
||||||
&& self.generic_args == &[None]
|
&& self.generic_args == [None]
|
||||||
&& self.mod_path.as_ident() == Some(&name!(Self))
|
&& self.mod_path.as_ident() == Some(&name!(Self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -388,9 +388,9 @@ impl Resolver {
|
|||||||
self.module_scope().map(|t| t.0.krate())
|
self.module_scope().map(|t| t.0.krate())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn where_predicates_in_scope<'a>(
|
pub fn where_predicates_in_scope(
|
||||||
&'a self,
|
&self,
|
||||||
) -> impl Iterator<Item = &'a crate::generics::WherePredicate> + 'a {
|
) -> impl Iterator<Item = &crate::generics::WherePredicate> {
|
||||||
self.scopes
|
self.scopes
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
@ -464,16 +464,16 @@ impl Scope {
|
|||||||
&Scope::GenericParams { ref params, def: parent } => {
|
&Scope::GenericParams { ref params, def: parent } => {
|
||||||
for (local_id, param) in params.types.iter() {
|
for (local_id, param) in params.types.iter() {
|
||||||
if let Some(ref name) = param.name {
|
if let Some(ref name) = param.name {
|
||||||
let id = TypeParamId { local_id, parent };
|
let id = TypeParamId { parent, local_id };
|
||||||
f(name.clone(), ScopeDef::GenericParam(id.into()))
|
f(name.clone(), ScopeDef::GenericParam(id.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (local_id, param) in params.consts.iter() {
|
for (local_id, param) in params.consts.iter() {
|
||||||
let id = ConstParamId { local_id, parent };
|
let id = ConstParamId { parent, local_id };
|
||||||
f(param.name.clone(), ScopeDef::GenericParam(id.into()))
|
f(param.name.clone(), ScopeDef::GenericParam(id.into()))
|
||||||
}
|
}
|
||||||
for (local_id, param) in params.lifetimes.iter() {
|
for (local_id, param) in params.lifetimes.iter() {
|
||||||
let id = LifetimeParamId { local_id, parent };
|
let id = LifetimeParamId { parent, local_id };
|
||||||
f(param.name.clone(), ScopeDef::GenericParam(id.into()))
|
f(param.name.clone(), ScopeDef::GenericParam(id.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,7 +420,7 @@ fn parse_string(tt: &tt::Subtree) -> Result<String, mbe::ExpandError> {
|
|||||||
tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => unquote_str(it),
|
tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => unquote_str(it),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.ok_or_else(|| mbe::ExpandError::ConversionError)
|
.ok_or(mbe::ExpandError::ConversionError)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn include_expand(
|
fn include_expand(
|
||||||
@ -432,9 +432,8 @@ fn include_expand(
|
|||||||
let path = parse_string(tt)?;
|
let path = parse_string(tt)?;
|
||||||
let file_id = relative_file(db, arg_id, &path, false)?;
|
let file_id = relative_file(db, arg_id, &path, false)?;
|
||||||
|
|
||||||
let subtree = parse_to_token_tree(&db.file_text(file_id))
|
let subtree =
|
||||||
.ok_or_else(|| mbe::ExpandError::ConversionError)?
|
parse_to_token_tree(&db.file_text(file_id)).ok_or(mbe::ExpandError::ConversionError)?.0;
|
||||||
.0;
|
|
||||||
Ok((subtree, file_id))
|
Ok((subtree, file_id))
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ pub fn expand_eager_macro(
|
|||||||
}),
|
}),
|
||||||
kind: MacroCallKind::FnLike { ast_id: call_id, fragment: FragmentKind::Expr },
|
kind: MacroCallKind::FnLike { ast_id: call_id, fragment: FragmentKind::Expr },
|
||||||
});
|
});
|
||||||
let arg_file_id: MacroCallId = arg_id;
|
let arg_file_id = arg_id;
|
||||||
|
|
||||||
let parsed_args =
|
let parsed_args =
|
||||||
diagnostic_sink.result(mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr))?.0;
|
diagnostic_sink.result(mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr))?.0;
|
||||||
@ -177,7 +177,7 @@ fn lazy_expand(
|
|||||||
let ast_id = db.ast_id_map(macro_call.file_id).ast_id(¯o_call.value);
|
let ast_id = db.ast_id_map(macro_call.file_id).ast_id(¯o_call.value);
|
||||||
|
|
||||||
let fragment = crate::to_fragment_kind(¯o_call.value);
|
let fragment = crate::to_fragment_kind(¯o_call.value);
|
||||||
let id: MacroCallId = def.as_lazy_macro(
|
let id = def.as_lazy_macro(
|
||||||
db,
|
db,
|
||||||
krate,
|
krate,
|
||||||
MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id), fragment },
|
MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id), fragment },
|
||||||
@ -207,7 +207,7 @@ fn eager_macro_recur(
|
|||||||
.option_with(|| macro_resolver(child.path()?), || err("failed to resolve macro"))?;
|
.option_with(|| macro_resolver(child.path()?), || err("failed to resolve macro"))?;
|
||||||
let insert = match def.kind {
|
let insert = match def.kind {
|
||||||
MacroDefKind::BuiltInEager(..) => {
|
MacroDefKind::BuiltInEager(..) => {
|
||||||
let id: MacroCallId = expand_eager_macro(
|
let id = expand_eager_macro(
|
||||||
db,
|
db,
|
||||||
krate,
|
krate,
|
||||||
curr.with_value(child.clone()),
|
curr.with_value(child.clone()),
|
||||||
|
@ -645,7 +645,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
|
|||||||
None if match_res.err.is_none() => {
|
None if match_res.err.is_none() => {
|
||||||
bindings_builder.push_optional(&mut item.bindings, name);
|
bindings_builder.push_optional(&mut item.bindings, name);
|
||||||
}
|
}
|
||||||
_ => {}
|
None => {}
|
||||||
}
|
}
|
||||||
if let Some(err) = match_res.err {
|
if let Some(err) = match_res.err {
|
||||||
res.add_err(err);
|
res.add_err(err);
|
||||||
@ -756,7 +756,7 @@ impl<'a> TtIter<'a> {
|
|||||||
let ok = match separator {
|
let ok = match separator {
|
||||||
Separator::Ident(lhs) if idx == 0 => match fork.expect_ident_or_underscore() {
|
Separator::Ident(lhs) if idx == 0 => match fork.expect_ident_or_underscore() {
|
||||||
Ok(rhs) => rhs.text == lhs.text,
|
Ok(rhs) => rhs.text == lhs.text,
|
||||||
_ => false,
|
Err(_) => false,
|
||||||
},
|
},
|
||||||
Separator::Literal(lhs) if idx == 0 => match fork.expect_literal() {
|
Separator::Literal(lhs) if idx == 0 => match fork.expect_literal() {
|
||||||
Ok(rhs) => match rhs {
|
Ok(rhs) => match rhs {
|
||||||
@ -764,11 +764,11 @@ impl<'a> TtIter<'a> {
|
|||||||
tt::Leaf::Ident(rhs) => rhs.text == lhs.text,
|
tt::Leaf::Ident(rhs) => rhs.text == lhs.text,
|
||||||
tt::Leaf::Punct(_) => false,
|
tt::Leaf::Punct(_) => false,
|
||||||
},
|
},
|
||||||
_ => false,
|
Err(_) => false,
|
||||||
},
|
},
|
||||||
Separator::Puncts(lhss) if idx < lhss.len() => match fork.expect_punct() {
|
Separator::Puncts(lhss) if idx < lhss.len() => match fork.expect_punct() {
|
||||||
Ok(rhs) => rhs.char == lhss[idx].char,
|
Ok(rhs) => rhs.char == lhss[idx].char,
|
||||||
_ => false,
|
Err(_) => false,
|
||||||
},
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
@ -241,6 +241,6 @@ fn push_fragment(buf: &mut Vec<tt::TokenTree>, fragment: Fragment) {
|
|||||||
fn push_subtree(buf: &mut Vec<tt::TokenTree>, tt: tt::Subtree) {
|
fn push_subtree(buf: &mut Vec<tt::TokenTree>, tt: tt::Subtree) {
|
||||||
match tt.delimiter {
|
match tt.delimiter {
|
||||||
None => buf.extend(tt.token_trees),
|
None => buf.extend(tt.token_trees),
|
||||||
_ => buf.push(tt.into()),
|
Some(_) => buf.push(tt.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ impl Shift {
|
|||||||
|
|
||||||
/// Shift given TokenTree token id
|
/// Shift given TokenTree token id
|
||||||
fn shift_all(self, tt: &mut tt::Subtree) {
|
fn shift_all(self, tt: &mut tt::Subtree) {
|
||||||
for t in tt.token_trees.iter_mut() {
|
for t in &mut tt.token_trees {
|
||||||
match t {
|
match t {
|
||||||
tt::TokenTree::Leaf(leaf) => match leaf {
|
tt::TokenTree::Leaf(leaf) => match leaf {
|
||||||
tt::Leaf::Ident(ident) => ident.id = self.shift(ident.id),
|
tt::Leaf::Ident(ident) => ident.id = self.shift(ident.id),
|
||||||
@ -188,7 +188,7 @@ impl MacroRules {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for rule in rules.iter() {
|
for rule in &rules {
|
||||||
validate(&rule.lhs)?;
|
validate(&rule.lhs)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ impl MacroDef {
|
|||||||
}
|
}
|
||||||
rules.push(rule);
|
rules.push(rule);
|
||||||
}
|
}
|
||||||
for rule in rules.iter() {
|
for rule in &rules {
|
||||||
validate(&rule.lhs)?;
|
validate(&rule.lhs)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ impl MacroDef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Rule {
|
impl Rule {
|
||||||
fn parse(src: &mut TtIter, expect_arrow: bool) -> Result<Rule, ParseError> {
|
fn parse(src: &mut TtIter, expect_arrow: bool) -> Result<Self, ParseError> {
|
||||||
let lhs = src
|
let lhs = src
|
||||||
.expect_subtree()
|
.expect_subtree()
|
||||||
.map_err(|()| ParseError::Expected("expected subtree".to_string()))?;
|
.map_err(|()| ParseError::Expected("expected subtree".to_string()))?;
|
||||||
@ -356,7 +356,7 @@ impl<T> ExpandResult<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn result(self) -> Result<T, ExpandError> {
|
pub fn result(self) -> Result<T, ExpandError> {
|
||||||
self.err.map(Err).unwrap_or(Ok(self.value))
|
self.err.map_or(Ok(self.value), Err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ impl<'a> TokenSource for SubtreeTokenSource {
|
|||||||
fn is_keyword(&self, kw: &str) -> bool {
|
fn is_keyword(&self, kw: &str) -> bool {
|
||||||
match self.cached.get(self.curr.1) {
|
match self.cached.get(self.curr.1) {
|
||||||
Some(t) => t.text == *kw,
|
Some(t) => t.text == *kw,
|
||||||
_ => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ trait TokenConvertor {
|
|||||||
let (id, idx) = self.id_alloc().open_delim(range);
|
let (id, idx) = self.id_alloc().open_delim(range);
|
||||||
subtree.delimiter = Some(tt::Delimiter { id, kind });
|
subtree.delimiter = Some(tt::Delimiter { id, kind });
|
||||||
|
|
||||||
while self.peek().map(|it| it.kind() != closed).unwrap_or(false) {
|
while self.peek().map_or(false, |it| it.kind() != closed) {
|
||||||
self.collect_leaf(&mut subtree.token_trees);
|
self.collect_leaf(&mut subtree.token_trees);
|
||||||
}
|
}
|
||||||
let last_range = match self.bump() {
|
let last_range = match self.bump() {
|
||||||
|
@ -121,10 +121,11 @@ impl<'a> TtIter<'a> {
|
|||||||
|
|
||||||
parser::parse_fragment(&mut src, &mut sink, fragment_kind);
|
parser::parse_fragment(&mut src, &mut sink, fragment_kind);
|
||||||
|
|
||||||
let mut err = None;
|
let mut err = if !sink.cursor.is_root() || sink.error {
|
||||||
if !sink.cursor.is_root() || sink.error {
|
Some(err!("expected {:?}", fragment_kind))
|
||||||
err = Some(err!("expected {:?}", fragment_kind));
|
} else {
|
||||||
}
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let mut curr = buffer.begin();
|
let mut curr = buffer.begin();
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
|
@ -248,7 +248,7 @@ pub mod token_stream {
|
|||||||
token_trees: subtree
|
token_trees: subtree
|
||||||
.token_trees
|
.token_trees
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|t| token_tree_replace_token_ids_with_unspecified(t))
|
.map(token_tree_replace_token_ids_with_unspecified)
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -457,7 +457,7 @@ impl server::Group for Rustc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn span(&mut self, group: &Self::Group) -> Self::Span {
|
fn span(&mut self, group: &Self::Group) -> Self::Span {
|
||||||
group.delimiter.map(|it| it.id).unwrap_or_else(|| tt::TokenId::unspecified())
|
group.delimiter.map(|it| it.id).unwrap_or_else(tt::TokenId::unspecified)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_span(&mut self, _group: &mut Self::Group, _span: Self::Span) {
|
fn set_span(&mut self, _group: &mut Self::Group, _span: Self::Span) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user