Skip to content

Commit b2c51ca

Browse files
committed
Smoe more minor optimizations
Really just one batched allocation, and the rest are style changes
1 parent e5eef19 commit b2c51ca

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

compiler/rustc_expand/src/base.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -1071,26 +1071,25 @@ impl<'a> ExtCtxt<'a> {
10711071
) -> Result<PathBuf, DiagnosticBuilder<'a>> {
10721072
let path = path.into();
10731073

1074+
if path.is_absolute() {
1075+
return Ok(path);
1076+
}
10741077
// Relative paths are resolved relative to the file in which they are found
10751078
// after macro expansion (that is, they are unhygienic).
1076-
if !path.is_absolute() {
1077-
let callsite = span.source_callsite();
1078-
let mut result = match self.source_map().span_to_unmapped_path(callsite) {
1079-
FileName::Real(name) => name.into_local_path(),
1080-
FileName::DocTest(path, _) => path,
1081-
other => {
1082-
return Err(self.struct_span_err(
1083-
span,
1084-
&format!("cannot resolve relative path in non-file source `{}`", other),
1085-
));
1086-
}
1087-
};
1088-
result.pop();
1089-
result.push(path);
1090-
Ok(result)
1091-
} else {
1092-
Ok(path)
1093-
}
1079+
let callsite = span.source_callsite();
1080+
let mut result = match self.source_map().span_to_unmapped_path(callsite) {
1081+
FileName::Real(name) => name.into_local_path(),
1082+
FileName::DocTest(path, _) => path,
1083+
other => {
1084+
return Err(self.struct_span_err(
1085+
span,
1086+
&format!("cannot resolve relative path in non-file source `{}`", other),
1087+
));
1088+
}
1089+
};
1090+
result.pop();
1091+
result.push(path);
1092+
Ok(result)
10941093
}
10951094
}
10961095

compiler/rustc_resolve/src/macros.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,10 @@ impl<'a> ResolverExpand for Resolver<'a> {
263263
// than by individual derives.
264264
// - Derives in the container need to know whether one of them is a built-in `Copy`.
265265
// FIXME: Try to avoid repeated resolutions for derives here and in expansion.
266-
let mut exts = Vec::new();
267266
let mut helper_attrs = Vec::new();
268-
for path in derives {
269-
exts.push(
267+
let exts = derives
268+
.iter()
269+
.map(|path| {
270270
match self.resolve_macro_path(
271271
path,
272272
Some(MacroKind::Derive),
@@ -288,15 +288,15 @@ impl<'a> ResolverExpand for Resolver<'a> {
288288
if ext.is_derive_copy {
289289
self.containers_deriving_copy.insert(invoc_id);
290290
}
291-
ext
291+
Ok(ext)
292292
}
293293
Ok(_) | Err(Determinacy::Determined) => {
294-
self.dummy_ext(MacroKind::Derive)
294+
Ok(self.dummy_ext(MacroKind::Derive))
295295
}
296-
Err(Determinacy::Undetermined) => return Err(Indeterminate),
297-
},
298-
)
299-
}
296+
Err(Determinacy::Undetermined) => Err(Indeterminate),
297+
}
298+
})
299+
.collect::<Result<Vec<_>, _>>()?;
300300
self.helper_attrs.insert(invoc_id, helper_attrs);
301301
return Ok(InvocationRes::DeriveContainer(exts));
302302
}

compiler/rustc_typeck/src/astconv/generics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
347347
seg: &hir::PathSegment<'_>,
348348
is_method_call: bool,
349349
) -> GenericArgCountResult {
350-
let empty_args = hir::GenericArgs::none();
351350
let suppress_mismatch = Self::check_impl_trait(tcx, seg, &def);
352351
Self::check_generic_arg_count(
353352
tcx,
354353
span,
355354
def,
356-
if let Some(ref args) = seg.args { args } else { &empty_args },
355+
seg.args.unwrap_or(&hir::GenericArgs::none()),
357356
if is_method_call { GenericArgPosition::MethodCall } else { GenericArgPosition::Value },
358357
def.parent.is_none() && def.has_self, // `has_self`
359358
seg.infer_args || suppress_mismatch, // `infer_args`

0 commit comments

Comments
 (0)