Use if-let guards in the codebase
This commit is contained in:
parent
a992a11913
commit
fde1b76b4b
27 changed files with 242 additions and 254 deletions
|
@ -305,15 +305,14 @@ impl<'a> StripUnconfigured<'a> {
|
|||
Some((AttrAnnotatedTokenTree::Delimited(sp, delim, inner), *spacing))
|
||||
.into_iter()
|
||||
}
|
||||
AttrAnnotatedTokenTree::Token(ref token) if let TokenKind::Interpolated(ref nt) = token.kind => {
|
||||
panic!(
|
||||
"Nonterminal should have been flattened at {:?}: {:?}",
|
||||
token.span, nt
|
||||
);
|
||||
}
|
||||
AttrAnnotatedTokenTree::Token(token) => {
|
||||
if let TokenKind::Interpolated(nt) = token.kind {
|
||||
panic!(
|
||||
"Nonterminal should have been flattened at {:?}: {:?}",
|
||||
token.span, nt
|
||||
);
|
||||
} else {
|
||||
Some((AttrAnnotatedTokenTree::Token(token), *spacing)).into_iter()
|
||||
}
|
||||
Some((AttrAnnotatedTokenTree::Token(token), *spacing)).into_iter()
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
#![feature(decl_macro)]
|
||||
#![feature(destructuring_assignment)]
|
||||
#![feature(format_args_capture)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(iter_zip)]
|
||||
#![feature(proc_macro_diagnostic)]
|
||||
#![feature(proc_macro_internals)]
|
||||
#![feature(proc_macro_span)]
|
||||
#![feature(try_blocks)]
|
||||
#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
|
|
@ -86,13 +86,12 @@ crate fn mod_dir_path(
|
|||
inline: Inline,
|
||||
) -> (PathBuf, DirOwnership) {
|
||||
match inline {
|
||||
Inline::Yes if let Some(file_path) = mod_file_path_from_attr(sess, attrs, &module.dir_path) => {
|
||||
// For inline modules file path from `#[path]` is actually the directory path
|
||||
// for historical reasons, so we don't pop the last segment here.
|
||||
(file_path, DirOwnership::Owned { relative: None })
|
||||
}
|
||||
Inline::Yes => {
|
||||
if let Some(file_path) = mod_file_path_from_attr(sess, attrs, &module.dir_path) {
|
||||
// For inline modules file path from `#[path]` is actually the directory path
|
||||
// for historical reasons, so we don't pop the last segment here.
|
||||
return (file_path, DirOwnership::Owned { relative: None });
|
||||
}
|
||||
|
||||
// We have to push on the current module name in the case of relative
|
||||
// paths in order to ensure that any additional module paths from inline
|
||||
// `mod x { ... }` come after the relative extension.
|
||||
|
|
|
@ -178,18 +178,19 @@ impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_>)>
|
|||
tt!(Punct::new('#', false))
|
||||
}
|
||||
|
||||
Interpolated(nt)
|
||||
if let Some((name, is_raw)) = ident_name_compatibility_hack(&nt, span, rustc) =>
|
||||
{
|
||||
TokenTree::Ident(Ident::new(rustc.sess, name.name, is_raw, name.span))
|
||||
}
|
||||
Interpolated(nt) => {
|
||||
if let Some((name, is_raw)) = ident_name_compatibility_hack(&nt, span, rustc) {
|
||||
TokenTree::Ident(Ident::new(rustc.sess, name.name, is_raw, name.span))
|
||||
} else {
|
||||
let stream = nt_to_tokenstream(&nt, rustc.sess, CanSynthesizeMissingTokens::No);
|
||||
TokenTree::Group(Group {
|
||||
delimiter: Delimiter::None,
|
||||
stream,
|
||||
span: DelimSpan::from_single(span),
|
||||
flatten: crate::base::pretty_printing_compatibility_hack(&nt, rustc.sess),
|
||||
})
|
||||
}
|
||||
let stream = nt_to_tokenstream(&nt, rustc.sess, CanSynthesizeMissingTokens::No);
|
||||
TokenTree::Group(Group {
|
||||
delimiter: Delimiter::None,
|
||||
stream,
|
||||
span: DelimSpan::from_single(span),
|
||||
flatten: crate::base::pretty_printing_compatibility_hack(&nt, rustc.sess),
|
||||
})
|
||||
}
|
||||
|
||||
OpenDelim(..) | CloseDelim(..) => unreachable!(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue