Skip to content

Commit 08ef1b9

Browse files
majaharami3l
authored andcommitted
Pull match statement out in OverrideCfg::from_file()
1 parent 5e90849 commit 08ef1b9

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

src/config.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -165,39 +165,41 @@ struct OverrideCfg {
165165

166166
impl OverrideCfg {
167167
fn from_file(cfg: &Cfg, file: OverrideFile) -> Result<Self> {
168-
Ok(Self {
169-
toolchain: match (file.toolchain.channel, file.toolchain.path) {
170-
(Some(name), None) => Some(
171-
(&ResolvableToolchainName::try_from(name)?
172-
.resolve(&cfg.get_default_host_triple()?)?)
173-
.into(),
174-
),
175-
(None, Some(path)) => {
176-
if file.toolchain.targets.is_some()
177-
|| file.toolchain.components.is_some()
178-
|| file.toolchain.profile.is_some()
179-
{
180-
bail!(
181-
"toolchain options are ignored for path toolchain ({})",
182-
path.display()
183-
)
184-
}
185-
// We -do not- support relative paths, they permit trivial
186-
// completely arbitrary code execution in a directory.
187-
// Longer term we'll not support path based toolchains at
188-
// all, because they also permit arbitrary code execution,
189-
// though with more challenges to exploit.
190-
Some((&PathBasedToolchainName::try_from(&path as &Path)?).into())
191-
}
192-
(Some(channel), Some(path)) => {
168+
let toolchain_name = match (file.toolchain.channel, file.toolchain.path) {
169+
(Some(name), None) => Some(
170+
(&ResolvableToolchainName::try_from(name)?
171+
.resolve(&cfg.get_default_host_triple()?)?)
172+
.into(),
173+
),
174+
(None, Some(path)) => {
175+
if file.toolchain.targets.is_some()
176+
|| file.toolchain.components.is_some()
177+
|| file.toolchain.profile.is_some()
178+
{
193179
bail!(
194-
"cannot specify both channel ({}) and path ({}) simultaneously",
195-
channel,
180+
"toolchain options are ignored for path toolchain ({})",
196181
path.display()
197182
)
198183
}
199-
(None, None) => None,
200-
},
184+
// We -do not- support relative paths, they permit trivial
185+
// completely arbitrary code execution in a directory.
186+
// Longer term we'll not support path based toolchains at
187+
// all, because they also permit arbitrary code execution,
188+
// though with more challenges to exploit.
189+
Some((&PathBasedToolchainName::try_from(&path as &Path)?).into())
190+
}
191+
(Some(channel), Some(path)) => {
192+
bail!(
193+
"cannot specify both channel ({}) and path ({}) simultaneously",
194+
channel,
195+
path.display()
196+
)
197+
}
198+
(None, None) => None,
199+
};
200+
201+
Ok(Self {
202+
toolchain: toolchain_name,
201203
components: file.toolchain.components.unwrap_or_default(),
202204
targets: file.toolchain.targets.unwrap_or_default(),
203205
profile: file

0 commit comments

Comments
 (0)