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
16 changes: 3 additions & 13 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use rustc_middle::util::Providers;
use rustc_session::Session;
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
use rustc_span::Symbol;
use rustc_target::spec::{RelocModel, TlsModel};

mod abi;
mod allocator;
Expand Down Expand Up @@ -244,16 +245,7 @@ impl CodegenBackend for LlvmCodegenBackend {
match req.kind {
PrintKind::RelocationModels => {
writeln!(out, "Available relocation models:").unwrap();
for name in &[
"static",
"pic",
"pie",
"dynamic-no-pic",
"ropi",
"rwpi",
"ropi-rwpi",
"default",
] {
for name in RelocModel::ALL.iter().map(RelocModel::desc).chain(["default"]) {
writeln!(out, " {name}").unwrap();
}
writeln!(out).unwrap();
Expand All @@ -267,9 +259,7 @@ impl CodegenBackend for LlvmCodegenBackend {
}
PrintKind::TlsModels => {
writeln!(out, "Available TLS models:").unwrap();
for name in
&["global-dynamic", "local-dynamic", "initial-exec", "local-exec", "emulated"]
{
for name in TlsModel::ALL.iter().map(TlsModel::desc) {
writeln!(out, " {name}").unwrap();
}
writeln!(out).unwrap();
Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Callbacks for TimePassesCallbacks {
// time because it will mess up the --print output. See #64339.
//
self.time_passes = (config.opts.prints.is_empty() && config.opts.unstable_opts.time_passes)
.then(|| config.opts.unstable_opts.time_passes_format);
.then_some(config.opts.unstable_opts.time_passes_format);
config.opts.trimmed_def_paths = true;
}
}
Expand Down Expand Up @@ -439,8 +439,9 @@ fn make_input(early_dcx: &EarlyDiagCtxt, free_matches: &[String]) -> Option<Inpu
"when UNSTABLE_RUSTDOC_TEST_PATH is set \
UNSTABLE_RUSTDOC_TEST_LINE also needs to be set",
);
let line = isize::from_str_radix(&line, 10)
.expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be an number");
let line = line
.parse::<isize>()
.expect("UNSTABLE_RUSTDOC_TEST_LINE needs to be a number");
FileName::doc_test_source_code(PathBuf::from(path), line)
}
Err(_) => FileName::anon_source_code(&input),
Expand Down Expand Up @@ -474,8 +475,7 @@ fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, col
let mut text = String::new();
// Slice off the leading newline and print.
for line in description.lines() {
let indent_level =
line.find(|c: char| !c.is_whitespace()).unwrap_or_else(|| line.len());
let indent_level = line.find(|c: char| !c.is_whitespace()).unwrap_or(line.len());
let dedented_line = &line[indent_level..];
if dedented_line.starts_with("```") {
is_in_code_block = !is_in_code_block;
Expand Down Expand Up @@ -547,7 +547,7 @@ fn show_md_content_with_pager(content: &str, color: ColorConfig) {

// The pager failed. Try to print pretty output to stdout.
if let Some((bufwtr, mdbuf)) = &pretty_data
&& bufwtr.print(&mdbuf).is_ok()
&& bufwtr.print(mdbuf).is_ok()
{
return;
}
Expand Down Expand Up @@ -598,8 +598,7 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {

fn list_metadata(sess: &Session, metadata_loader: &dyn MetadataLoader) {
match sess.io.input {
Input::File(ref ifile) => {
let path = &(*ifile);
Input::File(ref path) => {
let mut v = Vec::new();
locator::list_file_metadata(
&sess.target,
Expand Down Expand Up @@ -833,7 +832,7 @@ fn print_crate_info(
SupportedCrateTypes => {
let supported_crate_types = CRATE_TYPES
.iter()
.filter(|(_, crate_type)| !invalid_output_for_target(&sess, *crate_type))
.filter(|(_, crate_type)| !invalid_output_for_target(sess, *crate_type))
.filter(|(_, crate_type)| *crate_type != CrateType::Sdylib)
.map(|(crate_type_sym, _)| *crate_type_sym)
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -1434,7 +1433,7 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&DiagCtxt))
eprintln!();

if let Some(ice_path) = ice_path()
&& let Ok(mut out) = File::options().create(true).append(true).open(&ice_path)
&& let Ok(mut out) = File::options().create(true).append(true).open(ice_path)
{
// The current implementation always returns `Some`.
let location = info.location().unwrap();
Expand Down Expand Up @@ -1510,7 +1509,7 @@ fn report_ice(

let file = if let Some(path) = ice_path() {
// Create the ICE dump target file.
match crate::fs::File::options().create(true).append(true).open(&path) {
match crate::fs::File::options().create(true).append(true).open(path) {
Ok(mut file) => {
dcx.emit_note(session_diagnostics::IcePath { path: path.clone() });
if FIRST_PANIC.swap(false, Ordering::SeqCst) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_driver_impl/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ macro_rules! safe_println {
}

pub(crate) fn print(args: fmt::Arguments<'_>) {
if let Err(_) = io::stdout().write_fmt(args) {
if io::stdout().write_fmt(args).is_err() {
rustc_errors::FatalError.raise();
}
}
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fn typeck_with_inspect<'tcx>(
}

fcx.select_obligations_where_possible(|_| {});
if let None = fcx.infcx.tainted_by_errors() {
if fcx.infcx.tainted_by_errors().is_none() {
fcx.report_ambiguity_errors();
}

Expand Down Expand Up @@ -295,7 +295,7 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
} else if let Node::AnonConst(_) = node {
let id = tcx.local_def_id_to_hir_id(def_id);
match tcx.parent_hir_node(id) {
Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(ref anon_const), span, .. })
Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(anon_const), span, .. })
if anon_const.hir_id == id =>
{
Some(fcx.next_ty_var(span))
Expand Down
17 changes: 7 additions & 10 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Not all upvars are captured by ref, so use
// `apply_capture_kind_on_capture_ty` to ensure that we
// compute the right captured type.
return apply_capture_kind_on_capture_ty(
apply_capture_kind_on_capture_ty(
self.tcx,
upvar_ty,
capture,
Expand All @@ -430,7 +430,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
self.tcx.lifetimes.re_erased
},
);
)
},
),
);
Expand Down Expand Up @@ -529,11 +529,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// process any deferred resolutions.
let deferred_call_resolutions = self.remove_deferred_call_resolutions(closure_def_id);
for deferred_call_resolution in deferred_call_resolutions {
deferred_call_resolution.resolve(&mut FnCtxt::new(
self,
self.param_env,
closure_def_id,
));
deferred_call_resolution.resolve(&FnCtxt::new(self, self.param_env, closure_def_id));
}
}

Expand Down Expand Up @@ -1493,7 +1489,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Notation:
/// - Ty(place): Type of place
/// - `(a, b)`: Represents the function parameters `base_path_ty` and `captured_by_move_projs`
/// respectively.
/// respectively.
/// ```ignore (illustrative)
/// (Ty(w), [ &[p, x], &[c] ])
/// // |
Expand Down Expand Up @@ -2179,9 +2175,10 @@ fn restrict_precision_for_unsafe(
(place, curr_mode)
}

/// Truncate projections so that following rules are obeyed by the captured `place`:
/// Truncate projections so that the following rules are obeyed by the captured `place`:
/// - No Index projections are captured, since arrays are captured completely.
/// - No unsafe block is required to capture `place`
/// - No unsafe block is required to capture `place`.
///
/// Returns the truncated place and updated capture mode.
fn restrict_capture_precision(
place: Place<'_>,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
// to use builtin indexing because the index type is known to be
// usize-ish
fn fix_index_builtin_expr(&mut self, e: &hir::Expr<'_>) {
if let hir::ExprKind::Index(ref base, ref index, _) = e.kind {
if let hir::ExprKind::Index(base, index, _) = e.kind {
// All valid indexing looks like this; might encounter non-valid indexes at this point.
let base_ty = self.typeck_results.expr_ty_adjusted(base);
if let ty::Ref(_, base_ty_inner, _) = *base_ty.kind() {
Expand Down Expand Up @@ -583,7 +583,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
}

if let Err(err) = opaque_type_has_defining_use_args(
&self.fcx,
self.fcx,
opaque_type_key,
hidden_type.span,
DefiningScopeKind::HirTypeck,
Expand Down Expand Up @@ -792,7 +792,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {

fn visit_potentially_region_dependent_goals(&mut self) {
let obligations = self.fcx.take_hir_typeck_potentially_region_dependent_goals();
if let None = self.fcx.tainted_by_errors() {
if self.fcx.tainted_by_errors().is_none() {
for obligation in obligations {
let (predicate, mut cause) =
self.fcx.resolve_vars_if_possible((obligation.predicate, obligation.cause));
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn configure_and_expand(
unsafe {
env::set_var(
"PATH",
&env::join_paths(
env::join_paths(
new_path.iter().filter(|p| env::join_paths(iter::once(p)).is_ok()),
)
.unwrap(),
Expand Down Expand Up @@ -446,7 +446,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
let prev_source = sess.psess.source_map().span_to_prev_source(first_span);
let ferris_fix = prev_source
.map_or(FerrisFix::SnakeCase, |source| {
let mut source_before_ferris = source.trim_end().split_whitespace().rev();
let mut source_before_ferris = source.split_whitespace().rev();
match source_before_ferris.next() {
Some("struct" | "trait" | "mod" | "union" | "type" | "enum") => {
FerrisFix::PascalCase
Expand Down Expand Up @@ -500,7 +500,7 @@ fn env_var_os<'tcx>(tcx: TyCtxt<'tcx>, key: &'tcx OsStr) -> Option<&'tcx OsStr>
// properly change-tracked.
tcx.sess.psess.env_depinfo.borrow_mut().insert((
Symbol::intern(&key.to_string_lossy()),
value.as_ref().and_then(|value| value.to_str()).map(|value| Symbol::intern(&value)),
value.as_ref().and_then(|value| value.to_str()).map(|value| Symbol::intern(value)),
));

value_tcx
Expand Down Expand Up @@ -824,7 +824,7 @@ pub fn write_dep_info(tcx: TyCtxt<'_>) {

let outputs = tcx.output_filenames(());
let output_paths =
generated_output_paths(tcx, &outputs, sess.io.output_file.is_some(), crate_name);
generated_output_paths(tcx, outputs, sess.io.output_file.is_some(), crate_name);

// Ensure the source file isn't accidentally overwritten during compilation.
if let Some(input_path) = sess.io.input.opt_path() {
Expand All @@ -847,7 +847,7 @@ pub fn write_dep_info(tcx: TyCtxt<'_>) {
}
}

write_out_deps(tcx, &outputs, &output_paths);
write_out_deps(tcx, outputs, &output_paths);

let only_dep_info = sess.opts.output_types.contains_key(&OutputType::DepInfo)
&& sess.opts.output_types.len() == 1;
Expand Down Expand Up @@ -1303,7 +1303,7 @@ pub(crate) fn parse_crate_name(
let rustc_hir::Attribute::Parsed(AttributeKind::CrateName { name, name_span, .. }) =
AttributeParser::parse_limited_should_emit(
sess,
&attrs,
attrs,
sym::crate_name,
DUMMY_SP,
rustc_ast::node_id::CRATE_NODE_ID,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Linker {
&rlink_file,
&codegen_results,
&self.metadata,
&*self.output_filenames,
&self.output_filenames,
)
.unwrap_or_else(|error| {
sess.dcx().emit_fatal(FailedWritingFile { path: &rlink_file, error })
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
let query_map = rustc_span::set_session_globals_then(unsafe { &*(session_globals as *const SessionGlobals) }, || {
// Ensure there was no errors collecting all active jobs.
// We need the complete map to ensure we find a cycle to break.
QueryCtxt::new(tcx).collect_active_jobs().ok().expect("failed to collect active queries in deadlock handler")
QueryCtxt::new(tcx).collect_active_jobs().expect("failed to collect active queries in deadlock handler")
});
break_query_cycles(query_map, &registry);
})
Expand Down Expand Up @@ -561,7 +561,7 @@ pub fn build_output_filenames(attrs: &[ast::Attribute], sess: &Session) -> Outpu
}
Some(out_file.clone())
};
if sess.io.output_dir != None {
if sess.io.output_dir.is_some() {
sess.dcx().emit_warn(errors::IgnoringOutDir);
}

Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_session/src/config/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,13 @@ impl CheckCfg {

ins!(sym::overflow_checks, no_values);

ins!(sym::panic, empty_values).extend(&PanicStrategy::all());
ins!(sym::panic, empty_values)
.extend(PanicStrategy::ALL.iter().map(PanicStrategy::desc_symbol));

ins!(sym::proc_macro, no_values);

ins!(sym::relocation_model, empty_values).extend(RelocModel::all());
ins!(sym::relocation_model, empty_values)
.extend(RelocModel::ALL.iter().map(RelocModel::desc_symbol));

let sanitize_values = SanitizerSet::all()
.into_iter()
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_target/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,31 @@ fn find_relative_libdir(sysroot: &Path) -> std::borrow::Cow<'static, str> {
macro_rules! target_spec_enum {
(
$( #[$attr:meta] )*
pub enum $name:ident {
pub enum $Name:ident {
$(
$( #[$variant_attr:meta] )*
$variant:ident = $string:literal,
$Variant:ident = $string:literal,
)*
}
parse_error_type = $parse_error_type:literal;
) => {
$( #[$attr] )*
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
#[derive(schemars::JsonSchema)]
pub enum $name {
pub enum $Name {
$(
$( #[$variant_attr] )*
#[serde(rename = $string)] // for JSON schema generation only
$variant,
$Variant,
)*
}

impl FromStr for $name {
impl FromStr for $Name {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
$( $string => Self::$variant, )*
$( $string => Self::$Variant, )*
_ => {
let all = [$( concat!("'", $string, "'") ),*].join(", ");
return Err(format!("invalid {}: '{s}'. allowed values: {all}", $parse_error_type));
Expand All @@ -109,24 +109,25 @@ macro_rules! target_spec_enum {
}
}

impl $name {
impl $Name {
pub const ALL: &'static [$Name] = &[ $( $Name::$Variant, )* ];
pub fn desc(&self) -> &'static str {
match self {
$( Self::$variant => $string, )*
$( Self::$Variant => $string, )*
}
}
}

impl crate::json::ToJson for $name {
impl crate::json::ToJson for $Name {
fn to_json(&self) -> crate::json::Json {
self.desc().to_json()
}
}

crate::json::serde_deserialize_from_str!($name);
crate::json::serde_deserialize_from_str!($Name);


impl std::fmt::Display for $name {
impl std::fmt::Display for $Name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.desc())
}
Expand Down
Loading
Loading