Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ pub(super) fn dump_nll_mir<'tcx>(
dumper.dump_mir(body);

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

// Also dump the region constraint SCC graph as a graphviz file.
let _: io::Result<()> = try {
let _ = try {
let mut file = dumper.create_dump_file("regioncx.scc.dot", body)?;
regioncx.dump_graphviz_scc_constraints(tcx, &mut file)?;
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/polonius/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) fn dump_polonius_mir<'tcx>(

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

let _: io::Result<()> = try {
let _ = try {
let mut file = dumper.create_dump_file("html", body)?;
emit_polonius_dump(
&dumper,
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ffi::{OsStr, OsString};
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::{env, io, iter, mem, str};
use std::{env, iter, mem, str};

use find_msvc_tools;
use rustc_hir::attrs::WindowsSubsystemKind;
Expand Down Expand Up @@ -809,7 +809,7 @@ impl<'a> Linker for GccLinker<'a> {

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

// .def file similar to MSVC one but without LIBRARY section
Expand All @@ -845,7 +845,7 @@ impl<'a> Linker for GccLinker<'a> {
self.link_arg("--export").link_arg(sym);
}
} else if crate_type == CrateType::Executable && !self.sess.target.is_like_solaris {
let res: io::Result<()> = try {
let res = try {
let mut f = File::create_buffered(&path)?;
writeln!(f, "{{")?;
for (sym, _) in symbols {
Expand All @@ -860,7 +860,7 @@ impl<'a> Linker for GccLinker<'a> {
self.link_arg("--dynamic-list").link_arg(path);
} else {
// Write an LD version script
let res: io::Result<()> = try {
let res = try {
let mut f = File::create_buffered(&path)?;
writeln!(f, "{{")?;
if !symbols.is_empty() {
Expand Down Expand Up @@ -1139,7 +1139,7 @@ impl<'a> Linker for MsvcLinker<'a> {
}

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

// Start off with the standard module name header and then go
Expand Down Expand Up @@ -1735,7 +1735,7 @@ impl<'a> Linker for AixLinker<'a> {
symbols: &[(String, SymbolExportKind)],
) {
let path = tmpdir.join("list.exp");
let res: io::Result<()> = try {
let res = try {
let mut f = File::create_buffered(&path)?;
// FIXME: use llvm-nm to generate export list.
for (symbol, _) in symbols {
Expand Down Expand Up @@ -2135,7 +2135,7 @@ impl<'a> Linker for BpfLinker<'a> {
symbols: &[(String, SymbolExportKind)],
) {
let path = tmpdir.join("symbols");
let res: io::Result<()> = try {
let res = try {
let mut f = File::create_buffered(&path)?;
for (sym, _) in symbols {
writeln!(f, "{sym}")?;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ fn show_md_content_with_pager(content: &str, color: ColorConfig) {
};

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

let pager_stdin = pager.stdin.as_mut()?;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_ast::tokenstream::{self, DelimSpacing, Spacing, TokenStream};
use rustc_ast::util::literal::escape_byte_str_symbol;
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan, PResult};
use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan};
use rustc_parse::lexer::{StripTokens, nfc_normalize};
use rustc_parse::parser::Parser;
use rustc_parse::{exp, new_parser_from_source_str, source_str_to_stream, unwrap_or_emit_fatal};
Expand Down Expand Up @@ -591,7 +591,7 @@ impl server::Server for Rustc<'_, '_> {

fn ts_expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
// Parse the expression from our tokenstream.
let expr: PResult<'_, _> = try {
let expr = try {
let mut p = Parser::new(self.psess(), stream.clone(), Some("proc_macro expand expr"));
let expr = p.parse_expr()?;
if p.token != token::Eof {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@ fn compare_synthetic_generics<'tcx>(
// The case where the impl method uses `impl Trait` but the trait method uses
// explicit generics
err.span_label(impl_span, "expected generic parameter, found `impl Trait`");
let _: Option<_> = try {
try {
// try taking the name from the trait impl
// FIXME: this is obviously suboptimal since the name can already be used
// as another generic argument
Expand Down Expand Up @@ -1882,7 +1882,7 @@ fn compare_synthetic_generics<'tcx>(
// The case where the trait method uses `impl Trait`, but the impl method uses
// explicit generics.
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
let _: Option<_> = try {
try {
let impl_m = impl_m.def_id.as_local()?;
let impl_m = tcx.hir_expect_impl_item(impl_m);
let (sig, _) = impl_m.expect_fn();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
let deps_output = outputs.path(OutputType::DepInfo);
let deps_filename = deps_output.as_path();

let result: io::Result<()> = try {
let result = try {
// Build a list of files used to compile the output and
// write Makefile-compatible dependency rules
let mut files: IndexMap<String, (u64, Option<SourceFileHash>)> = sess
Expand Down
33 changes: 16 additions & 17 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,24 +746,23 @@ fn pat_ty_is_known_nonnull<'tcx>(
typing_env: ty::TypingEnv<'tcx>,
pat: ty::Pattern<'tcx>,
) -> bool {
Option::unwrap_or_default(
try {
match *pat {
ty::PatternKind::Range { start, end } => {
let start = start.try_to_value()?.try_to_bits(tcx, typing_env)?;
let end = end.try_to_value()?.try_to_bits(tcx, typing_env)?;

// This also works for negative numbers, as we just need
// to ensure we aren't wrapping over zero.
start > 0 && end >= start
}
ty::PatternKind::NotNull => true,
ty::PatternKind::Or(patterns) => {
patterns.iter().all(|pat| pat_ty_is_known_nonnull(tcx, typing_env, pat))
}
try {
match *pat {
ty::PatternKind::Range { start, end } => {
let start = start.try_to_value()?.try_to_bits(tcx, typing_env)?;
let end = end.try_to_value()?.try_to_bits(tcx, typing_env)?;

// This also works for negative numbers, as we just need
// to ensure we aren't wrapping over zero.
start > 0 && end >= start
}
},
)
ty::PatternKind::NotNull => true,
ty::PatternKind::Or(patterns) => {
patterns.iter().all(|pat| pat_ty_is_known_nonnull(tcx, typing_env, pat))
}
}
}
.unwrap_or_default()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annot: the whitespace changed here, so you might want the ignore whitespace diff for this function.

}

/// Given a non-null scalar (or transparent) type `ty`, return the nullable version of that type.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ impl<'dis, 'de, 'tcx> MirDumper<'dis, 'de, 'tcx> {
/// - `foo & nll | bar & typeck` == match if `foo` and `nll` both appear in the name
/// or `typeck` and `bar` both appear in the name.
pub fn dump_mir(&self, body: &Body<'tcx>) {
let _: io::Result<()> = try {
let _ = try {
let mut file = self.create_dump_file("mir", body)?;
self.dump_mir_to_writer(body, &mut file)?;
};

if self.tcx().sess.opts.unstable_opts.dump_mir_graphviz {
let _: io::Result<()> = try {
let _ = try {
let mut file = self.create_dump_file("dot", body)?;
write_mir_fn_graphviz(self.tcx(), body, false, &mut file)?;
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/builder/custom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub(super) fn build_custom_mir<'tcx>(
block_map: FxHashMap::default(),
};

let res: PResult<_> = try {
let res = try {
pctxt.parse_args(params)?;
pctxt.parse_body(expr)?;
};
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,14 +1159,14 @@ impl<'tcx> TypePrivacyVisitor<'tcx> {
let typeck_results = self
.maybe_typeck_results
.unwrap_or_else(|| span_bug!(span, "`hir::Expr` or `hir::Pat` outside of a body"));
let result: ControlFlow<()> = try {
try {
self.visit(typeck_results.node_type(id))?;
self.visit(typeck_results.node_args(id))?;
if let Some(adjustments) = typeck_results.adjustments().get(id) {
adjustments.iter().try_for_each(|adjustment| self.visit(adjustment.target))?;
}
};
result.is_break()
}
.is_break()
}

fn check_def_id(&self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
hir::ExprKind::MethodCall(segment, ..) => {
if let Some(def_id) = self.typeck_results.type_dependent_def_id(expr.hir_id) {
let generics = tcx.generics_of(def_id);
let insertable: Option<_> = try {
let insertable = try {
if generics.has_impl_trait() {
None?
}
Expand Down Expand Up @@ -1061,7 +1061,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
//
// FIXME: We deal with that one separately for now,
// would be good to remove this special case.
let last_segment_using_path_data: Option<_> = try {
let last_segment_using_path_data = try {
let generics_def_id = tcx.res_generics_def_id(path.res)?;
let generics = tcx.generics_of(generics_def_id);
if generics.has_impl_trait() {
Expand Down Expand Up @@ -1117,19 +1117,18 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
};

let generics = tcx.generics_of(def_id);
let segment: Option<_> = try {
if !segment.infer_args || generics.has_impl_trait() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old code seems simpler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this one didn't have any ? inside the try, my instinct was that just using None instead of do yeet; was more direct.

do yeet ();
}
let segment = if !segment.infer_args || generics.has_impl_trait() {
None
} else {
let span = tcx.hir_span(segment.hir_id);
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
InsertableGenericArgs {
Some(InsertableGenericArgs {
insert_span,
args,
generics_def_id: def_id,
def_id,
have_turbofish: false,
}
})
};

let parent_def_id = generics.parent.unwrap();
Expand Down
Loading