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
9 changes: 5 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ dependencies = [

[[package]]
name = "clap"
version = "4.5.51"
version = "4.5.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c26d721170e0295f191a69bd9a1f93efcdb0aff38684b61ab5750468972e5f5"
checksum = "c6e6ff9dcd79cff5cd969a17a545d79e84ab086e444102a591e288a8aa3ce394"
dependencies = [
"clap_builder",
"clap_derive",
Expand All @@ -600,9 +600,9 @@ dependencies = [

[[package]]
name = "clap_builder"
version = "4.5.51"
version = "4.5.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75835f0c7bf681bfd05abe44e965760fea999a5286c6eb2d59883634fd02011a"
checksum = "fa42cf4d2b7a41bc8f663a7cab4031ebafa1bf3875705bfaf8466dc60ab52c00"
dependencies = [
"anstream",
"anstyle",
Expand Down Expand Up @@ -5623,6 +5623,7 @@ version = "0.1.0"
dependencies = [
"build_helper",
"cargo_metadata 0.21.0",
"clap",
"fluent-syntax",
"globset",
"ignore",
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0423.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ fn h1() -> i32 {
// did you mean `a::I`?
}
```

### Enum types used as values

Enums are types and cannot be used directly as values.

```compile_fail,E0423
fn main(){
let x = Option::<i32>;
//~^ ERROR expected value,found enum `Option`
}
```
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// the bad interactions of the given hack detailed in (note_1).
debug!("check_pat_ref: expected={:?}", expected);
match expected.maybe_pinned_ref() {
Some((r_ty, r_pinned, r_mutbl))
Some((r_ty, r_pinned, r_mutbl, _))
if ((ref_pat_matches_mut_ref && r_mutbl >= pat_mutbl)
|| r_mutbl == pat_mutbl)
&& pat_pinned == r_pinned =>
Expand Down
22 changes: 7 additions & 15 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,25 +1336,17 @@ impl<'tcx> Ty<'tcx> {
}
}

pub fn pinned_ref(self) -> Option<(Ty<'tcx>, ty::Mutability)> {
if let Adt(def, args) = self.kind()
&& def.is_pin()
&& let &ty::Ref(_, ty, mutbl) = args.type_at(0).kind()
{
return Some((ty, mutbl));
}
None
}

pub fn maybe_pinned_ref(self) -> Option<(Ty<'tcx>, ty::Pinnedness, ty::Mutability)> {
match *self.kind() {
pub fn maybe_pinned_ref(
self,
) -> Option<(Ty<'tcx>, ty::Pinnedness, ty::Mutability, Region<'tcx>)> {
match self.kind() {
Adt(def, args)
if def.is_pin()
&& let ty::Ref(_, ty, mutbl) = *args.type_at(0).kind() =>
&& let &ty::Ref(region, ty, mutbl) = args.type_at(0).kind() =>
{
Some((ty, ty::Pinnedness::Pinned, mutbl))
Some((ty, ty::Pinnedness::Pinned, mutbl, region))
}
ty::Ref(_, ty, mutbl) => Some((ty, ty::Pinnedness::Not, mutbl)),
&Ref(region, ty, mutbl) => Some((ty, ty::Pinnedness::Not, mutbl, region)),
_ => None,
}
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_pattern_analysis/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::iter::once;

use rustc_abi::{FIRST_VARIANT, FieldIdx, Integer, VariantIdx};
use rustc_arena::DroplessArena;
use rustc_hir::HirId;
use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir, HirId};
use rustc_index::{Idx, IndexVec};
use rustc_middle::middle::stability::EvalResult;
use rustc_middle::thir::{self, Pat, PatKind, PatRange, PatRangeBoundary};
Expand Down Expand Up @@ -471,9 +471,9 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
PatKind::Deref { pin, subpattern } => {
fields = vec![self.lower_pat(subpattern).at_index(0)];
arity = 1;
ctor = match pin {
hir::Pinnedness::Not if ty.is_ref() => Ref,
hir::Pinnedness::Pinned if let Some((inner_ty, _)) = ty.pinned_ref() => {
ctor = match (pin, ty.maybe_pinned_ref()) {
(ty::Pinnedness::Not, Some((_, ty::Pinnedness::Not, _, _))) => Ref,
(ty::Pinnedness::Pinned, Some((inner_ty, ty::Pinnedness::Pinned, _, _))) => {
self.internal_state.has_lowered_deref_pat.set(true);
DerefPattern(RevealedTy(inner_ty))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) fn target() -> Target {
max_atomic_width: Some(128),
// As documented in https://developer.android.com/ndk/guides/cpu-features.html
// the neon (ASIMD) and FP must exist on all android aarch64 targets.
features: "+v8a,+neon,+outline-atomics".into(),
features: "+v8a,+neon".into(),
// the AAPCS64 expects use of non-leaf frame pointers per
// https://github.com/ARM-software/abi-aa/blob/4492d1570eb70c8fd146623e0db65b2d241f12e7/aapcs64/aapcs64.rst#the-frame-pointer
// and we tend to encounter interesting bugs in AArch64 unwinding code if we do not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::spec::{Arch, Cc, FramePointer, LinkerFlavor, Lld, Target, TargetMetad
pub(crate) fn target() -> Target {
let mut base = base::windows_gnullvm::opts();
base.max_atomic_width = Some(128);
base.features = "+v8a,+neon,+outline-atomics".into();
base.features = "+v8a,+neon".into();
base.linker = Some("aarch64-w64-mingw32-clang".into());
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), &["-m", "arm64pe"]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::spec::{Arch, FramePointer, Target, TargetMetadata, base};
pub(crate) fn target() -> Target {
let mut base = base::windows_msvc::opts();
base.max_atomic_width = Some(128);
base.features = "+v8a,+neon,+outline-atomics".into();
base.features = "+v8a,+neon".into();

// Microsoft recommends enabling frame pointers on Arm64 Windows.
// From https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#integer-registers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) fn target() -> Target {
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
arch: Arch::AArch64,
options: TargetOptions {
features: "+v8a,+outline-atomics".into(),
features: "+v8a".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
supported_sanitizers: SanitizerSet::ADDRESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::spec::{
pub(crate) fn target() -> Target {
let mut base = base::fuchsia::opts();
base.cpu = "generic".into();
base.features = "+v8a,+crc,+aes,+sha2,+neon,+outline-atomics".into();
base.features = "+v8a,+crc,+aes,+sha2,+neon".into();
base.max_atomic_width = Some(128);
base.stack_probes = StackProbeType::Inline;
base.supported_sanitizers = SanitizerSet::ADDRESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) fn target() -> Target {
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
arch: Arch::AArch64,
options: TargetOptions {
features: "+v8a,+outline-atomics".into(),
features: "+v8a".into(),
max_atomic_width: Some(128),
stack_probes: StackProbeType::Inline,
..base::openbsd::opts()
Expand Down
12 changes: 6 additions & 6 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,19 +1299,19 @@ impl Step for Tidy {
/// for the `dev` or `nightly` channels.
fn run(self, builder: &Builder<'_>) {
let mut cmd = builder.tool_cmd(Tool::Tidy);
cmd.arg(&builder.src);
cmd.arg(&builder.initial_cargo);
cmd.arg(&builder.out);
cmd.arg(format!("--root-path={}", &builder.src.display()));
cmd.arg(format!("--cargo-path={}", &builder.initial_cargo.display()));
cmd.arg(format!("--output-dir={}", &builder.out.display()));
// Tidy is heavily IO constrained. Still respect `-j`, but use a higher limit if `jobs` hasn't been configured.
let jobs = builder.config.jobs.unwrap_or_else(|| {
8 * std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32
});
cmd.arg(jobs.to_string());
cmd.arg(format!("--concurrency={jobs}"));
// pass the path to the yarn command used for installing js deps.
if let Some(yarn) = &builder.config.yarn {
cmd.arg(yarn);
cmd.arg(format!("--npm-path={}", yarn.display()));
} else {
cmd.arg("yarn");
cmd.arg("--npm-path=yarn");
}
if builder.is_verbose() {
cmd.arg("--verbose");
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fluent-syntax = "0.12"
similar = "2.5.0"
toml = "0.7.8"
tempfile = "3.15.0"
clap = "4.5.54"

[features]
build-metrics = ["dep:serde"]
Expand Down
2 changes: 1 addition & 1 deletion src/tools/tidy/src/alphabetical/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn bless_test(before: &str, after: &str) {
let temp_path = tempfile::Builder::new().tempfile().unwrap().into_temp_path();
std::fs::write(&temp_path, before).unwrap();

let tidy_ctx = TidyCtx::new(Path::new("/"), false, TidyFlags::new(&["--bless".to_owned()]));
let tidy_ctx = TidyCtx::new(Path::new("/"), false, TidyFlags::new(true));

let mut check = tidy_ctx.start_check("alphabetical-test");
check_lines(&temp_path, before, &tidy_ctx, &mut check);
Expand Down
102 changes: 102 additions & 0 deletions src/tools/tidy/src/arg_parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use std::num::NonZeroUsize;
use std::path::PathBuf;

use clap::{Arg, ArgAction, ArgMatches, Command, value_parser};

#[cfg(test)]
mod tests;

#[derive(Debug, Clone)]
pub struct TidyArgParser {
pub root_path: PathBuf,
pub cargo: PathBuf,
pub output_directory: PathBuf,
pub concurrency: NonZeroUsize,
pub npm: PathBuf,
pub verbose: bool,
pub bless: bool,
pub extra_checks: Option<Vec<String>>,
pub pos_args: Vec<String>,
}

impl TidyArgParser {
fn command() -> Command {
Command::new("rust-tidy")
.arg(
Arg::new("root_path")
.help("path of the root directory")
.long("root-path")
.required(true)
.value_parser(value_parser!(PathBuf)),
)
.arg(
Arg::new("cargo")
.help("path of cargo")
.long("cargo-path")
.required(true)
.value_parser(value_parser!(PathBuf)),
)
.arg(
Arg::new("output_directory")
.help("path of output directory")
.long("output-dir")
.required(true)
.value_parser(value_parser!(PathBuf)),
)
.arg(
Arg::new("concurrency")
.help("number of threads working concurrently")
.long("concurrency")
.required(true)
.value_parser(value_parser!(NonZeroUsize)),
)
.arg(
Arg::new("npm")
.help("path of npm")
.long("npm-path")
.required(true)
.value_parser(value_parser!(PathBuf)),
)
.arg(Arg::new("verbose").help("verbose").long("verbose").action(ArgAction::SetTrue))
.arg(Arg::new("bless").help("target files are modified").long("bless").action(ArgAction::SetTrue))
.arg(
Arg::new("extra_checks")
.help("extra checks")
.long("extra-checks")
.value_delimiter(',')
.action(ArgAction::Append),
)
.arg(Arg::new("pos_args").help("for extra checks. you can specify configs and target files for external check tools").action(ArgAction::Append).last(true))
}

fn build(matches: ArgMatches) -> Self {
let mut tidy_flags = Self {
root_path: matches.get_one::<PathBuf>("root_path").unwrap().clone(),
cargo: matches.get_one::<PathBuf>("cargo").unwrap().clone(),
output_directory: matches.get_one::<PathBuf>("output_directory").unwrap().clone(),
concurrency: *matches.get_one::<NonZeroUsize>("concurrency").unwrap(),
npm: matches.get_one::<PathBuf>("npm").unwrap().clone(),
verbose: *matches.get_one::<bool>("verbose").unwrap(),
bless: *matches.get_one::<bool>("bless").unwrap(),
extra_checks: None,
pos_args: vec![],
};

if let Some(extra_checks) = matches.get_many::<String>("extra_checks") {
tidy_flags.extra_checks = Some(extra_checks.map(|s| s.to_string()).collect::<Vec<_>>());
}

tidy_flags.pos_args = matches
.get_many::<String>("pos_args")
.unwrap_or_default()
.map(|v| v.to_string())
.collect::<Vec<_>>();

tidy_flags
}

pub fn parse() -> Self {
let matches = Self::command().get_matches();
Self::build(matches)
}
}
Loading
Loading