aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorClemens Wasser <[email protected]>2021-06-07 12:59:01 +0100
committerClemens Wasser <[email protected]>2021-06-21 15:40:21 +0100
commit47747cd4120e260a144242aadd7732e11d133fe4 (patch)
treeba767d7da808c050e313446ac4cb90d810d0f4de /crates
parent4402f2b280f58896ed0696f4243d88a58fd970ca (diff)
Apply some clippy suggestions
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/lib.rs42
-rw-r--r--crates/hir_def/src/body/lower.rs7
-rw-r--r--crates/hir_def/src/body/tests.rs9
-rw-r--r--crates/hir_def/src/generics.rs5
-rw-r--r--crates/hir_def/src/item_scope.rs6
-rw-r--r--crates/hir_def/src/item_tree/pretty.rs6
-rw-r--r--crates/hir_def/src/nameres.rs5
-rw-r--r--crates/hir_def/src/nameres/path_resolution.rs2
-rw-r--r--crates/hir_def/src/path.rs2
-rw-r--r--crates/hir_def/src/resolver.rs12
-rw-r--r--crates/hir_expand/src/builtin_macro.rs7
-rw-r--r--crates/hir_expand/src/eager.rs6
-rw-r--r--crates/mbe/src/expander/matcher.rs8
-rw-r--r--crates/mbe/src/expander/transcriber.rs2
-rw-r--r--crates/mbe/src/lib.rs10
-rw-r--r--crates/mbe/src/subtree_source.rs2
-rw-r--r--crates/mbe/src/syntax_bridge.rs2
-rw-r--r--crates/mbe/src/tt_iter.rs9
-rw-r--r--crates/proc_macro_srv/src/rustc_server.rs4
19 files changed, 66 insertions, 80 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index b7eabaabb..88490fea9 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -219,8 +219,7 @@ impl Crate {
219 let doc_url = doc_attr_q.tt_values().map(|tt| { 219 let doc_url = doc_attr_q.tt_values().map(|tt| {
220 let name = tt.token_trees.iter() 220 let name = tt.token_trees.iter()
221 .skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident{text: ref ident, ..})) if ident == "html_root_url")) 221 .skip_while(|tt| !matches!(tt, TokenTree::Leaf(Leaf::Ident(Ident{text: ref ident, ..})) if ident == "html_root_url"))
222 .skip(2) 222 .nth(2);
223 .next();
224 223
225 match name { 224 match name {
226 Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text), 225 Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text),
@@ -1846,7 +1845,7 @@ impl TypeParam {
1846 1845
1847 pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> { 1846 pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> {
1848 db.generic_predicates_for_param(self.id) 1847 db.generic_predicates_for_param(self.id)
1849 .into_iter() 1848 .iter()
1850 .filter_map(|pred| match &pred.skip_binders().skip_binders() { 1849 .filter_map(|pred| match &pred.skip_binders().skip_binders() {
1851 hir_ty::WhereClause::Implemented(trait_ref) => { 1850 hir_ty::WhereClause::Implemented(trait_ref) => {
1852 Some(Trait::from(trait_ref.hir_trait_id())) 1851 Some(Trait::from(trait_ref.hir_trait_id()))
@@ -1951,7 +1950,7 @@ impl Impl {
1951 all.extend( 1950 all.extend(
1952 db.inherent_impls_in_crate(id) 1951 db.inherent_impls_in_crate(id)
1953 .for_self_ty(&ty) 1952 .for_self_ty(&ty)
1954 .into_iter() 1953 .iter()
1955 .cloned() 1954 .cloned()
1956 .map(Self::from) 1955 .map(Self::from)
1957 .filter(filter), 1956 .filter(filter),
@@ -2232,8 +2231,8 @@ impl Type {
2232 } 2231 }
2233 2232
2234 pub fn is_packed(&self, db: &dyn HirDatabase) -> bool { 2233 pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
2235 let adt_id = match self.ty.kind(&Interner) { 2234 let adt_id = match *self.ty.kind(&Interner) {
2236 &TyKind::Adt(hir_ty::AdtId(adt_id), ..) => adt_id, 2235 TyKind::Adt(hir_ty::AdtId(adt_id), ..) => adt_id,
2237 _ => return false, 2236 _ => return false,
2238 }; 2237 };
2239 2238
@@ -2287,9 +2286,9 @@ impl Type {
2287 } 2286 }
2288 2287
2289 pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> { 2288 pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
2290 let (variant_id, substs) = match self.ty.kind(&Interner) { 2289 let (variant_id, substs) = match *self.ty.kind(&Interner) {
2291 &TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), ref substs) => (s.into(), substs), 2290 TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), ref substs) => (s.into(), substs),
2292 &TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), ref substs) => (u.into(), substs), 2291 TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), ref substs) => (u.into(), substs),
2293 _ => return Vec::new(), 2292 _ => return Vec::new(),
2294 }; 2293 };
2295 2294
@@ -2488,20 +2487,17 @@ impl Type {
2488 cb: &mut impl FnMut(Type), 2487 cb: &mut impl FnMut(Type),
2489 ) { 2488 ) {
2490 for pred in bounds { 2489 for pred in bounds {
2491 match pred.skip_binders() { 2490 if let WhereClause::Implemented(trait_ref) = pred.skip_binders() {
2492 WhereClause::Implemented(trait_ref) => { 2491 cb(type_.clone());
2493 cb(type_.clone()); 2492 // skip the self type. it's likely the type we just got the bounds from
2494 // skip the self type. it's likely the type we just got the bounds from 2493 for ty in trait_ref
2495 for ty in trait_ref 2494 .substitution
2496 .substitution 2495 .iter(&Interner)
2497 .iter(&Interner) 2496 .skip(1)
2498 .skip(1) 2497 .filter_map(|a| a.ty(&Interner))
2499 .filter_map(|a| a.ty(&Interner)) 2498 {
2500 { 2499 walk_type(db, &type_.derived(ty.clone()), cb);
2501 walk_type(db, &type_.derived(ty.clone()), cb);
2502 }
2503 } 2500 }
2504 _ => (),
2505 } 2501 }
2506 } 2502 }
2507 } 2503 }
@@ -2514,7 +2510,7 @@ impl Type {
2514 walk_substs(db, type_, substs, cb); 2510 walk_substs(db, type_, substs, cb);
2515 } 2511 }
2516 TyKind::AssociatedType(_, substs) => { 2512 TyKind::AssociatedType(_, substs) => {
2517 if let Some(_) = ty.associated_type_parent_trait(db) { 2513 if ty.associated_type_parent_trait(db).is_some() {
2518 cb(type_.derived(ty.clone())); 2514 cb(type_.derived(ty.clone()));
2519 } 2515 }
2520 walk_substs(db, type_, substs, cb); 2516 walk_substs(db, type_, substs, cb);
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index bed4c4994..f6e6cdbe2 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -690,9 +690,7 @@ impl ExprCollector<'_> {
690 } 690 }
691 } 691 }
692 ast::Stmt::Item(item) => { 692 ast::Stmt::Item(item) => {
693 if self.check_cfg(&item).is_none() { 693 self.check_cfg(&item);
694 return;
695 }
696 } 694 }
697 } 695 }
698 } 696 }
@@ -717,7 +715,8 @@ impl ExprCollector<'_> {
717 block.statements().for_each(|s| self.collect_stmt(s)); 715 block.statements().for_each(|s| self.collect_stmt(s));
718 block.tail_expr().and_then(|e| { 716 block.tail_expr().and_then(|e| {
719 let expr = self.maybe_collect_expr(e)?; 717 let expr = self.maybe_collect_expr(e)?;
720 Some(self.statements_in_scope.push(Statement::Expr { expr, has_semi: false })) 718 self.statements_in_scope.push(Statement::Expr { expr, has_semi: false });
719 Some(())
721 }); 720 });
722 721
723 let mut tail = None; 722 let mut tail = None;
diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs
index 27d837d47..673a75386 100644
--- a/crates/hir_def/src/body/tests.rs
+++ b/crates/hir_def/src/body/tests.rs
@@ -15,12 +15,9 @@ fn lower(ra_fixture: &str) -> Arc<Body> {
15 let mut fn_def = None; 15 let mut fn_def = None;
16 'outer: for (_, module) in def_map.modules() { 16 'outer: for (_, module) in def_map.modules() {
17 for decl in module.scope.declarations() { 17 for decl in module.scope.declarations() {
18 match decl { 18 if let ModuleDefId::FunctionId(it) = decl {
19 ModuleDefId::FunctionId(it) => { 19 fn_def = Some(it);
20 fn_def = Some(it); 20 break 'outer;
21 break 'outer;
22 }
23 _ => {}
24 } 21 }
25 } 22 }
26 } 23 }
diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs
index 0f04b2bae..096ac7968 100644
--- a/crates/hir_def/src/generics.rs
+++ b/crates/hir_def/src/generics.rs
@@ -104,7 +104,7 @@ impl GenericParams {
104 ) -> Interned<GenericParams> { 104 ) -> Interned<GenericParams> {
105 let _p = profile::span("generic_params_query"); 105 let _p = profile::span("generic_params_query");
106 106
107 let generics = match def { 107 match def {
108 GenericDefId::FunctionId(id) => { 108 GenericDefId::FunctionId(id) => {
109 let id = id.lookup(db).id; 109 let id = id.lookup(db).id;
110 let tree = id.item_tree(db); 110 let tree = id.item_tree(db);
@@ -150,8 +150,7 @@ impl GenericParams {
150 GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => { 150 GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => {
151 Interned::new(GenericParams::default()) 151 Interned::new(GenericParams::default())
152 } 152 }
153 }; 153 }
154 generics
155 } 154 }
156 155
157 fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) { 156 fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) {
diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs
index 08407ebfa..567ae5660 100644
--- a/crates/hir_def/src/item_scope.rs
+++ b/crates/hir_def/src/item_scope.rs
@@ -241,10 +241,8 @@ impl ItemScope {
241 check_changed!(changed, (self / def).values, glob_imports[lookup], def_import_type); 241 check_changed!(changed, (self / def).values, glob_imports[lookup], def_import_type);
242 check_changed!(changed, (self / def).macros, glob_imports[lookup], def_import_type); 242 check_changed!(changed, (self / def).macros, glob_imports[lookup], def_import_type);
243 243
244 if def.is_none() { 244 if def.is_none() && self.unresolved.insert(lookup.1) {
245 if self.unresolved.insert(lookup.1) { 245 changed = true;
246 changed = true;
247 }
248 } 246 }
249 247
250 changed 248 changed
diff --git a/crates/hir_def/src/item_tree/pretty.rs b/crates/hir_def/src/item_tree/pretty.rs
index e63bc8232..8b12e5a67 100644
--- a/crates/hir_def/src/item_tree/pretty.rs
+++ b/crates/hir_def/src/item_tree/pretty.rs
@@ -30,16 +30,16 @@ pub(super) fn print_item_tree(tree: &ItemTree) -> String {
30 30
31macro_rules! w { 31macro_rules! w {
32 ($dst:expr, $($arg:tt)*) => { 32 ($dst:expr, $($arg:tt)*) => {
33 drop(write!($dst, $($arg)*)) 33 { let _ = write!($dst, $($arg)*); }
34 }; 34 };
35} 35}
36 36
37macro_rules! wln { 37macro_rules! wln {
38 ($dst:expr) => { 38 ($dst:expr) => {
39 drop(writeln!($dst)) 39 { let _ = writeln!($dst); }
40 }; 40 };
41 ($dst:expr, $($arg:tt)*) => { 41 ($dst:expr, $($arg:tt)*) => {
42 drop(writeln!($dst, $($arg)*)) 42 { let _ = writeln!($dst, $($arg)*); }
43 }; 43 };
44} 44}
45 45
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index ebfcc26c4..9e6aa9607 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -367,10 +367,7 @@ impl DefMap {
367 pub fn containing_module(&self, local_mod: LocalModuleId) -> Option<ModuleId> { 367 pub fn containing_module(&self, local_mod: LocalModuleId) -> Option<ModuleId> {
368 match &self[local_mod].parent { 368 match &self[local_mod].parent {
369 Some(parent) => Some(self.module_id(*parent)), 369 Some(parent) => Some(self.module_id(*parent)),
370 None => match &self.block { 370 None => self.block.as_ref().map(|block| block.parent),
371 Some(block) => Some(block.parent),
372 None => None,
373 },
374 } 371 }
375 } 372 }
376 373
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs
index 629bc7952..229f57d77 100644
--- a/crates/hir_def/src/nameres/path_resolution.rs
+++ b/crates/hir_def/src/nameres/path_resolution.rs
@@ -55,7 +55,7 @@ impl ResolvePathResult {
55 segment_index: Option<usize>, 55 segment_index: Option<usize>,
56 krate: Option<CrateId>, 56 krate: Option<CrateId>,
57 ) -> ResolvePathResult { 57 ) -> ResolvePathResult {
58 ResolvePathResult { resolved_def, reached_fixedpoint, segment_index, krate } 58 ResolvePathResult { resolved_def, segment_index, reached_fixedpoint, krate }
59 } 59 }
60} 60}
61 61
diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs
index 4cdb5913d..667092cd2 100644
--- a/crates/hir_def/src/path.rs
+++ b/crates/hir_def/src/path.rs
@@ -209,7 +209,7 @@ impl Path {
209 209
210 pub fn is_self_type(&self) -> bool { 210 pub fn is_self_type(&self) -> bool {
211 self.type_anchor.is_none() 211 self.type_anchor.is_none()
212 && self.generic_args == &[None] 212 && self.generic_args == [None]
213 && self.mod_path.as_ident() == Some(&name!(Self)) 213 && self.mod_path.as_ident() == Some(&name!(Self))
214 } 214 }
215} 215}
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs
index 49c573087..a11439c3b 100644
--- a/crates/hir_def/src/resolver.rs
+++ b/crates/hir_def/src/resolver.rs
@@ -388,9 +388,9 @@ impl Resolver {
388 self.module_scope().map(|t| t.0.krate()) 388 self.module_scope().map(|t| t.0.krate())
389 } 389 }
390 390
391 pub fn where_predicates_in_scope<'a>( 391 pub fn where_predicates_in_scope(
392 &'a self, 392 &self,
393 ) -> impl Iterator<Item = &'a crate::generics::WherePredicate> + 'a { 393 ) -> impl Iterator<Item = &crate::generics::WherePredicate> {
394 self.scopes 394 self.scopes
395 .iter() 395 .iter()
396 .rev() 396 .rev()
@@ -464,16 +464,16 @@ impl Scope {
464 &Scope::GenericParams { ref params, def: parent } => { 464 &Scope::GenericParams { ref params, def: parent } => {
465 for (local_id, param) in params.types.iter() { 465 for (local_id, param) in params.types.iter() {
466 if let Some(ref name) = param.name { 466 if let Some(ref name) = param.name {
467 let id = TypeParamId { local_id, parent }; 467 let id = TypeParamId { parent, local_id };
468 f(name.clone(), ScopeDef::GenericParam(id.into())) 468 f(name.clone(), ScopeDef::GenericParam(id.into()))
469 } 469 }
470 } 470 }
471 for (local_id, param) in params.consts.iter() { 471 for (local_id, param) in params.consts.iter() {
472 let id = ConstParamId { local_id, parent }; 472 let id = ConstParamId { parent, local_id };
473 f(param.name.clone(), ScopeDef::GenericParam(id.into())) 473 f(param.name.clone(), ScopeDef::GenericParam(id.into()))
474 } 474 }
475 for (local_id, param) in params.lifetimes.iter() { 475 for (local_id, param) in params.lifetimes.iter() {
476 let id = LifetimeParamId { local_id, parent }; 476 let id = LifetimeParamId { parent, local_id };
477 f(param.name.clone(), ScopeDef::GenericParam(id.into())) 477 f(param.name.clone(), ScopeDef::GenericParam(id.into()))
478 } 478 }
479 } 479 }
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index 4c83a2efe..f556bc751 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -420,7 +420,7 @@ fn parse_string(tt: &tt::Subtree) -> Result<String, mbe::ExpandError> {
420 tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => unquote_str(it), 420 tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => unquote_str(it),
421 _ => None, 421 _ => None,
422 }) 422 })
423 .ok_or_else(|| mbe::ExpandError::ConversionError) 423 .ok_or(mbe::ExpandError::ConversionError)
424} 424}
425 425
426fn include_expand( 426fn include_expand(
@@ -432,9 +432,8 @@ fn include_expand(
432 let path = parse_string(tt)?; 432 let path = parse_string(tt)?;
433 let file_id = relative_file(db, arg_id, &path, false)?; 433 let file_id = relative_file(db, arg_id, &path, false)?;
434 434
435 let subtree = parse_to_token_tree(&db.file_text(file_id)) 435 let subtree =
436 .ok_or_else(|| mbe::ExpandError::ConversionError)? 436 parse_to_token_tree(&db.file_text(file_id)).ok_or(mbe::ExpandError::ConversionError)?.0;
437 .0;
438 Ok((subtree, file_id)) 437 Ok((subtree, file_id))
439 })(); 438 })();
440 439
diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs
index 584ddcf9f..66601f4df 100644
--- a/crates/hir_expand/src/eager.rs
+++ b/crates/hir_expand/src/eager.rs
@@ -128,7 +128,7 @@ pub fn expand_eager_macro(
128 }), 128 }),
129 kind: MacroCallKind::FnLike { ast_id: call_id, fragment: FragmentKind::Expr }, 129 kind: MacroCallKind::FnLike { ast_id: call_id, fragment: FragmentKind::Expr },
130 }); 130 });
131 let arg_file_id: MacroCallId = arg_id; 131 let arg_file_id = arg_id;
132 132
133 let parsed_args = 133 let parsed_args =
134 diagnostic_sink.result(mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr))?.0; 134 diagnostic_sink.result(mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr))?.0;
@@ -177,7 +177,7 @@ fn lazy_expand(
177 let ast_id = db.ast_id_map(macro_call.file_id).ast_id(&macro_call.value); 177 let ast_id = db.ast_id_map(macro_call.file_id).ast_id(&macro_call.value);
178 178
179 let fragment = crate::to_fragment_kind(&macro_call.value); 179 let fragment = crate::to_fragment_kind(&macro_call.value);
180 let id: MacroCallId = def.as_lazy_macro( 180 let id = def.as_lazy_macro(
181 db, 181 db,
182 krate, 182 krate,
183 MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id), fragment }, 183 MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id), fragment },
@@ -207,7 +207,7 @@ fn eager_macro_recur(
207 .option_with(|| macro_resolver(child.path()?), || err("failed to resolve macro"))?; 207 .option_with(|| macro_resolver(child.path()?), || err("failed to resolve macro"))?;
208 let insert = match def.kind { 208 let insert = match def.kind {
209 MacroDefKind::BuiltInEager(..) => { 209 MacroDefKind::BuiltInEager(..) => {
210 let id: MacroCallId = expand_eager_macro( 210 let id = expand_eager_macro(
211 db, 211 db,
212 krate, 212 krate,
213 curr.with_value(child.clone()), 213 curr.with_value(child.clone()),
diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs
index b4f2fe9a4..0d694b1a7 100644
--- a/crates/mbe/src/expander/matcher.rs
+++ b/crates/mbe/src/expander/matcher.rs
@@ -645,7 +645,7 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
645 None if match_res.err.is_none() => { 645 None if match_res.err.is_none() => {
646 bindings_builder.push_optional(&mut item.bindings, name); 646 bindings_builder.push_optional(&mut item.bindings, name);
647 } 647 }
648 _ => {} 648 None => {}
649 } 649 }
650 if let Some(err) = match_res.err { 650 if let Some(err) = match_res.err {
651 res.add_err(err); 651 res.add_err(err);
@@ -756,7 +756,7 @@ impl<'a> TtIter<'a> {
756 let ok = match separator { 756 let ok = match separator {
757 Separator::Ident(lhs) if idx == 0 => match fork.expect_ident_or_underscore() { 757 Separator::Ident(lhs) if idx == 0 => match fork.expect_ident_or_underscore() {
758 Ok(rhs) => rhs.text == lhs.text, 758 Ok(rhs) => rhs.text == lhs.text,
759 _ => false, 759 Err(_) => false,
760 }, 760 },
761 Separator::Literal(lhs) if idx == 0 => match fork.expect_literal() { 761 Separator::Literal(lhs) if idx == 0 => match fork.expect_literal() {
762 Ok(rhs) => match rhs { 762 Ok(rhs) => match rhs {
@@ -764,11 +764,11 @@ impl<'a> TtIter<'a> {
764 tt::Leaf::Ident(rhs) => rhs.text == lhs.text, 764 tt::Leaf::Ident(rhs) => rhs.text == lhs.text,
765 tt::Leaf::Punct(_) => false, 765 tt::Leaf::Punct(_) => false,
766 }, 766 },
767 _ => false, 767 Err(_) => false,
768 }, 768 },
769 Separator::Puncts(lhss) if idx < lhss.len() => match fork.expect_punct() { 769 Separator::Puncts(lhss) if idx < lhss.len() => match fork.expect_punct() {
770 Ok(rhs) => rhs.char == lhss[idx].char, 770 Ok(rhs) => rhs.char == lhss[idx].char,
771 _ => false, 771 Err(_) => false,
772 }, 772 },
773 _ => false, 773 _ => false,
774 }; 774 };
diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs
index 49a137577..4894e2a0c 100644
--- a/crates/mbe/src/expander/transcriber.rs
+++ b/crates/mbe/src/expander/transcriber.rs
@@ -241,6 +241,6 @@ fn push_fragment(buf: &mut Vec<tt::TokenTree>, fragment: Fragment) {
241fn push_subtree(buf: &mut Vec<tt::TokenTree>, tt: tt::Subtree) { 241fn push_subtree(buf: &mut Vec<tt::TokenTree>, tt: tt::Subtree) {
242 match tt.delimiter { 242 match tt.delimiter {
243 None => buf.extend(tt.token_trees), 243 None => buf.extend(tt.token_trees),
244 _ => buf.push(tt.into()), 244 Some(_) => buf.push(tt.into()),
245 } 245 }
246} 246}
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs
index 8c8528aaf..fcc596756 100644
--- a/crates/mbe/src/lib.rs
+++ b/crates/mbe/src/lib.rs
@@ -135,7 +135,7 @@ impl Shift {
135 135
136 /// Shift given TokenTree token id 136 /// Shift given TokenTree token id
137 fn shift_all(self, tt: &mut tt::Subtree) { 137 fn shift_all(self, tt: &mut tt::Subtree) {
138 for t in tt.token_trees.iter_mut() { 138 for t in &mut tt.token_trees {
139 match t { 139 match t {
140 tt::TokenTree::Leaf(leaf) => match leaf { 140 tt::TokenTree::Leaf(leaf) => match leaf {
141 tt::Leaf::Ident(ident) => ident.id = self.shift(ident.id), 141 tt::Leaf::Ident(ident) => ident.id = self.shift(ident.id),
@@ -188,7 +188,7 @@ impl MacroRules {
188 } 188 }
189 } 189 }
190 190
191 for rule in rules.iter() { 191 for rule in &rules {
192 validate(&rule.lhs)?; 192 validate(&rule.lhs)?;
193 } 193 }
194 194
@@ -241,7 +241,7 @@ impl MacroDef {
241 } 241 }
242 rules.push(rule); 242 rules.push(rule);
243 } 243 }
244 for rule in rules.iter() { 244 for rule in &rules {
245 validate(&rule.lhs)?; 245 validate(&rule.lhs)?;
246 } 246 }
247 247
@@ -268,7 +268,7 @@ impl MacroDef {
268} 268}
269 269
270impl Rule { 270impl Rule {
271 fn parse(src: &mut TtIter, expect_arrow: bool) -> Result<Rule, ParseError> { 271 fn parse(src: &mut TtIter, expect_arrow: bool) -> Result<Self, ParseError> {
272 let lhs = src 272 let lhs = src
273 .expect_subtree() 273 .expect_subtree()
274 .map_err(|()| ParseError::Expected("expected subtree".to_string()))?; 274 .map_err(|()| ParseError::Expected("expected subtree".to_string()))?;
@@ -356,7 +356,7 @@ impl<T> ExpandResult<T> {
356 } 356 }
357 357
358 pub fn result(self) -> Result<T, ExpandError> { 358 pub fn result(self) -> Result<T, ExpandError> {
359 self.err.map(Err).unwrap_or(Ok(self.value)) 359 self.err.map_or(Ok(self.value), Err)
360 } 360 }
361} 361}
362 362
diff --git a/crates/mbe/src/subtree_source.rs b/crates/mbe/src/subtree_source.rs
index ee80807ad..ffc2a6017 100644
--- a/crates/mbe/src/subtree_source.rs
+++ b/crates/mbe/src/subtree_source.rs
@@ -115,7 +115,7 @@ impl<'a> TokenSource for SubtreeTokenSource {
115 fn is_keyword(&self, kw: &str) -> bool { 115 fn is_keyword(&self, kw: &str) -> bool {
116 match self.cached.get(self.curr.1) { 116 match self.cached.get(self.curr.1) {
117 Some(t) => t.text == *kw, 117 Some(t) => t.text == *kw,
118 _ => false, 118 None => false,
119 } 119 }
120 } 120 }
121} 121}
diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs
index cdc22425d..7526bd8e6 100644
--- a/crates/mbe/src/syntax_bridge.rs
+++ b/crates/mbe/src/syntax_bridge.rs
@@ -283,7 +283,7 @@ trait TokenConvertor {
283 let (id, idx) = self.id_alloc().open_delim(range); 283 let (id, idx) = self.id_alloc().open_delim(range);
284 subtree.delimiter = Some(tt::Delimiter { id, kind }); 284 subtree.delimiter = Some(tt::Delimiter { id, kind });
285 285
286 while self.peek().map(|it| it.kind() != closed).unwrap_or(false) { 286 while self.peek().map_or(false, |it| it.kind() != closed) {
287 self.collect_leaf(&mut subtree.token_trees); 287 self.collect_leaf(&mut subtree.token_trees);
288 } 288 }
289 let last_range = match self.bump() { 289 let last_range = match self.bump() {
diff --git a/crates/mbe/src/tt_iter.rs b/crates/mbe/src/tt_iter.rs
index 5a4eca7bf..65da83476 100644
--- a/crates/mbe/src/tt_iter.rs
+++ b/crates/mbe/src/tt_iter.rs
@@ -121,10 +121,11 @@ impl<'a> TtIter<'a> {
121 121
122 parser::parse_fragment(&mut src, &mut sink, fragment_kind); 122 parser::parse_fragment(&mut src, &mut sink, fragment_kind);
123 123
124 let mut err = None; 124 let mut err = if !sink.cursor.is_root() || sink.error {
125 if !sink.cursor.is_root() || sink.error { 125 Some(err!("expected {:?}", fragment_kind))
126 err = Some(err!("expected {:?}", fragment_kind)); 126 } else {
127 } 127 None
128 };
128 129
129 let mut curr = buffer.begin(); 130 let mut curr = buffer.begin();
130 let mut res = vec![]; 131 let mut res = vec![];
diff --git a/crates/proc_macro_srv/src/rustc_server.rs b/crates/proc_macro_srv/src/rustc_server.rs
index 65ca3eb6c..e252e89a5 100644
--- a/crates/proc_macro_srv/src/rustc_server.rs
+++ b/crates/proc_macro_srv/src/rustc_server.rs
@@ -248,7 +248,7 @@ pub mod token_stream {
248 token_trees: subtree 248 token_trees: subtree
249 .token_trees 249 .token_trees
250 .into_iter() 250 .into_iter()
251 .map(|t| token_tree_replace_token_ids_with_unspecified(t)) 251 .map(token_tree_replace_token_ids_with_unspecified)
252 .collect(), 252 .collect(),
253 } 253 }
254 } 254 }
@@ -457,7 +457,7 @@ impl server::Group for Rustc {
457 } 457 }
458 458
459 fn span(&mut self, group: &Self::Group) -> Self::Span { 459 fn span(&mut self, group: &Self::Group) -> Self::Span {
460 group.delimiter.map(|it| it.id).unwrap_or_else(|| tt::TokenId::unspecified()) 460 group.delimiter.map(|it| it.id).unwrap_or_else(tt::TokenId::unspecified)
461 } 461 }
462 462
463 fn set_span(&mut self, _group: &mut Self::Group, _span: Self::Span) { 463 fn set_span(&mut self, _group: &mut Self::Group, _span: Self::Span) {