Skip to content

Commit 68f4a99

Browse files
authored
Rollup merge of #151887 - scottmcm:homogeneous-try-in-compiler, r=jackh726
Remove some unnecessary `try`-related type annotations I left a few, like ```rust let result: Result<_, ModError<'_>> = try { ``` where it felt like seeing it might still be useful for the reader. Feel free to push back on any of these changes if you think they should be left alone.
2 parents 55277ad + f7931c8 commit 68f4a99

12 files changed

Lines changed: 46 additions & 48 deletions

File tree

compiler/rustc_borrowck/src/nll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ pub(super) fn dump_nll_mir<'tcx>(
231231
dumper.dump_mir(body);
232232

233233
// Also dump the region constraint graph as a graphviz file.
234-
let _: io::Result<()> = try {
234+
let _ = try {
235235
let mut file = dumper.create_dump_file("regioncx.all.dot", body)?;
236236
regioncx.dump_graphviz_raw_constraints(tcx, &mut file)?;
237237
};
238238

239239
// Also dump the region constraint SCC graph as a graphviz file.
240-
let _: io::Result<()> = try {
240+
let _ = try {
241241
let mut file = dumper.create_dump_file("regioncx.scc.dot", body)?;
242242
regioncx.dump_graphviz_scc_constraints(tcx, &mut file)?;
243243
};

compiler/rustc_borrowck/src/polonius/dump.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn dump_polonius_mir<'tcx>(
5858

5959
let dumper = dumper.set_extra_data(extra_data).set_options(options);
6060

61-
let _: io::Result<()> = try {
61+
let _ = try {
6262
let mut file = dumper.create_dump_file("html", body)?;
6363
emit_polonius_dump(
6464
&dumper,

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ffi::{OsStr, OsString};
22
use std::fs::{self, File};
33
use std::io::prelude::*;
44
use std::path::{Path, PathBuf};
5-
use std::{env, io, iter, mem, str};
5+
use std::{env, iter, mem, str};
66

77
use find_msvc_tools;
88
use rustc_hir::attrs::WindowsSubsystemKind;
@@ -809,7 +809,7 @@ impl<'a> Linker for GccLinker<'a> {
809809

810810
if self.sess.target.is_like_darwin {
811811
// Write a plain, newline-separated list of symbols
812-
let res: io::Result<()> = try {
812+
let res = try {
813813
let mut f = File::create_buffered(&path)?;
814814
for (sym, _) in symbols {
815815
debug!(" _{sym}");
@@ -821,7 +821,7 @@ impl<'a> Linker for GccLinker<'a> {
821821
}
822822
self.link_arg("-exported_symbols_list").link_arg(path);
823823
} else if self.sess.target.is_like_windows {
824-
let res: io::Result<()> = try {
824+
let res = try {
825825
let mut f = File::create_buffered(&path)?;
826826

827827
// .def file similar to MSVC one but without LIBRARY section
@@ -845,7 +845,7 @@ impl<'a> Linker for GccLinker<'a> {
845845
self.link_arg("--export").link_arg(sym);
846846
}
847847
} else if crate_type == CrateType::Executable && !self.sess.target.is_like_solaris {
848-
let res: io::Result<()> = try {
848+
let res = try {
849849
let mut f = File::create_buffered(&path)?;
850850
writeln!(f, "{{")?;
851851
for (sym, _) in symbols {
@@ -860,7 +860,7 @@ impl<'a> Linker for GccLinker<'a> {
860860
self.link_arg("--dynamic-list").link_arg(path);
861861
} else {
862862
// Write an LD version script
863-
let res: io::Result<()> = try {
863+
let res = try {
864864
let mut f = File::create_buffered(&path)?;
865865
writeln!(f, "{{")?;
866866
if !symbols.is_empty() {
@@ -1139,7 +1139,7 @@ impl<'a> Linker for MsvcLinker<'a> {
11391139
}
11401140

11411141
let path = tmpdir.join("lib.def");
1142-
let res: io::Result<()> = try {
1142+
let res = try {
11431143
let mut f = File::create_buffered(&path)?;
11441144

11451145
// Start off with the standard module name header and then go
@@ -1735,7 +1735,7 @@ impl<'a> Linker for AixLinker<'a> {
17351735
symbols: &[(String, SymbolExportKind)],
17361736
) {
17371737
let path = tmpdir.join("list.exp");
1738-
let res: io::Result<()> = try {
1738+
let res = try {
17391739
let mut f = File::create_buffered(&path)?;
17401740
// FIXME: use llvm-nm to generate export list.
17411741
for (symbol, _) in symbols {
@@ -2135,7 +2135,7 @@ impl<'a> Linker for BpfLinker<'a> {
21352135
symbols: &[(String, SymbolExportKind)],
21362136
) {
21372137
let path = tmpdir.join("symbols");
2138-
let res: io::Result<()> = try {
2138+
let res = try {
21392139
let mut f = File::create_buffered(&path)?;
21402140
for (sym, _) in symbols {
21412141
writeln!(f, "{sym}")?;

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ fn show_md_content_with_pager(content: &str, color: ColorConfig) {
503503
};
504504

505505
// Try to print via the pager, pretty output if possible.
506-
let pager_res: Option<()> = try {
506+
let pager_res = try {
507507
let mut pager = cmd.stdin(Stdio::piped()).spawn().ok()?;
508508

509509
let pager_stdin = pager.stdin.as_mut()?;

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_ast::tokenstream::{self, DelimSpacing, Spacing, TokenStream};
77
use rustc_ast::util::literal::escape_byte_str_symbol;
88
use rustc_ast_pretty::pprust;
99
use rustc_data_structures::fx::FxHashMap;
10-
use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan, PResult};
10+
use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan};
1111
use rustc_parse::lexer::{StripTokens, nfc_normalize};
1212
use rustc_parse::parser::Parser;
1313
use rustc_parse::{exp, new_parser_from_source_str, source_str_to_stream, unwrap_or_emit_fatal};
@@ -591,7 +591,7 @@ impl server::Server for Rustc<'_, '_> {
591591

592592
fn ts_expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
593593
// Parse the expression from our tokenstream.
594-
let expr: PResult<'_, _> = try {
594+
let expr = try {
595595
let mut p = Parser::new(self.psess(), stream.clone(), Some("proc_macro expand expr"));
596596
let expr = p.parse_expr()?;
597597
if p.token != token::Eof {

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ fn compare_synthetic_generics<'tcx>(
18441844
// The case where the impl method uses `impl Trait` but the trait method uses
18451845
// explicit generics
18461846
err.span_label(impl_span, "expected generic parameter, found `impl Trait`");
1847-
let _: Option<_> = try {
1847+
try {
18481848
// try taking the name from the trait impl
18491849
// FIXME: this is obviously suboptimal since the name can already be used
18501850
// as another generic argument
@@ -1881,7 +1881,7 @@ fn compare_synthetic_generics<'tcx>(
18811881
// The case where the trait method uses `impl Trait`, but the impl method uses
18821882
// explicit generics.
18831883
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
1884-
let _: Option<_> = try {
1884+
try {
18851885
let impl_m = impl_m.def_id.as_local()?;
18861886
let impl_m = tcx.hir_expect_impl_item(impl_m);
18871887
let (sig, _) = impl_m.expect_fn();

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
582582
let deps_output = outputs.path(OutputType::DepInfo);
583583
let deps_filename = deps_output.as_path();
584584

585-
let result: io::Result<()> = try {
585+
let result = try {
586586
// Build a list of files used to compile the output and
587587
// write Makefile-compatible dependency rules
588588
let mut files: IndexMap<String, (u64, Option<SourceFileHash>)> = sess

compiler/rustc_lint/src/types.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -746,24 +746,23 @@ fn pat_ty_is_known_nonnull<'tcx>(
746746
typing_env: ty::TypingEnv<'tcx>,
747747
pat: ty::Pattern<'tcx>,
748748
) -> bool {
749-
Option::unwrap_or_default(
750-
try {
751-
match *pat {
752-
ty::PatternKind::Range { start, end } => {
753-
let start = start.try_to_value()?.try_to_bits(tcx, typing_env)?;
754-
let end = end.try_to_value()?.try_to_bits(tcx, typing_env)?;
755-
756-
// This also works for negative numbers, as we just need
757-
// to ensure we aren't wrapping over zero.
758-
start > 0 && end >= start
759-
}
760-
ty::PatternKind::NotNull => true,
761-
ty::PatternKind::Or(patterns) => {
762-
patterns.iter().all(|pat| pat_ty_is_known_nonnull(tcx, typing_env, pat))
763-
}
749+
try {
750+
match *pat {
751+
ty::PatternKind::Range { start, end } => {
752+
let start = start.try_to_value()?.try_to_bits(tcx, typing_env)?;
753+
let end = end.try_to_value()?.try_to_bits(tcx, typing_env)?;
754+
755+
// This also works for negative numbers, as we just need
756+
// to ensure we aren't wrapping over zero.
757+
start > 0 && end >= start
764758
}
765-
},
766-
)
759+
ty::PatternKind::NotNull => true,
760+
ty::PatternKind::Or(patterns) => {
761+
patterns.iter().all(|pat| pat_ty_is_known_nonnull(tcx, typing_env, pat))
762+
}
763+
}
764+
}
765+
.unwrap_or_default()
767766
}
768767

769768
/// Given a non-null scalar (or transparent) type `ty`, return the nullable version of that type.

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ impl<'dis, 'de, 'tcx> MirDumper<'dis, 'de, 'tcx> {
157157
/// - `foo & nll | bar & typeck` == match if `foo` and `nll` both appear in the name
158158
/// or `typeck` and `bar` both appear in the name.
159159
pub fn dump_mir(&self, body: &Body<'tcx>) {
160-
let _: io::Result<()> = try {
160+
let _ = try {
161161
let mut file = self.create_dump_file("mir", body)?;
162162
self.dump_mir_to_writer(body, &mut file)?;
163163
};
164164

165165
if self.tcx().sess.opts.unstable_opts.dump_mir_graphviz {
166-
let _: io::Result<()> = try {
166+
let _ = try {
167167
let mut file = self.create_dump_file("dot", body)?;
168168
write_mir_fn_graphviz(self.tcx(), body, false, &mut file)?;
169169
};

compiler/rustc_mir_build/src/builder/custom/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(super) fn build_custom_mir<'tcx>(
8585
block_map: FxHashMap::default(),
8686
};
8787

88-
let res: PResult<_> = try {
88+
let res = try {
8989
pctxt.parse_args(params)?;
9090
pctxt.parse_body(expr)?;
9191
};

0 commit comments

Comments
 (0)