Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
5 changes: 1 addition & 4 deletions compiler/rustc_hir_typeck/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ pub(super) fn check_fn<'a, 'tcx>(
fcx.check_pat_top(&param.pat, param_ty, ty_span, None);

// Check that argument is Sized.
// The check for a non-trivial pattern is a hack to avoid duplicate warnings
// for simple cases like `fn foo(x: Trait)`,
// where we would error once on the parameter as a whole, and once on the binding `x`.
if param.pat.simple_ident().is_none() && !params_can_be_unsized {
if !params_can_be_unsized {
fcx.require_type_is_sized(
param_ty,
param.pat.span,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3464,7 +3464,8 @@ declare_lint! {
/// out an update in your own time.
pub LONG_RUNNING_CONST_EVAL,
Deny,
"detects long const eval operations"
"detects long const eval operations",
report_in_external_macro
}

declare_lint! {
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,13 @@ impl<'tcx> SizeSkeleton<'tcx> {
Ok(layout) => {
return Ok(SizeSkeleton::Known(layout.size));
}
Err(err) => err,
Err(err @ LayoutError::Unknown(_)) => err,
// We can't extract SizeSkeleton info from other layout errors
Err(
e @ LayoutError::Cycle
| e @ LayoutError::SizeOverflow(_)
| e @ LayoutError::NormalizationFailure(..),
) => return Err(e),
};

match *ty.kind() {
Expand Down
35 changes: 28 additions & 7 deletions compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,49 @@ fn layout_of_uncached<'tcx>(
return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr)));
}

let unsized_part = tcx.struct_tail_erasing_lifetimes(pointee, param_env);

let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type()
// Projection eagerly bails out when the pointee references errors,
// fall back to structurally deducing metadata.
&& !pointee.references_error()
{
let metadata_ty = tcx.normalize_erasing_regions(
let pointee_metadata = tcx.mk_projection(metadata_def_id, [pointee]);
let metadata_ty = match tcx.try_normalize_erasing_regions(
param_env,
tcx.mk_projection(metadata_def_id, [pointee]),
);
pointee_metadata,
) {
Ok(metadata_ty) => metadata_ty,
Err(mut err) => {
// Usually `<Ty as Pointee>::Metadata` can't be normalized because
// its struct tail cannot be normalized either, so try to get a
// more descriptive layout error here, which will lead to less confusing
// diagnostics.
match tcx.try_normalize_erasing_regions(
param_env,
tcx.struct_tail_without_normalization(pointee),
) {
Ok(_) => {},
Err(better_err) => {
err = better_err;
}
}
return Err(LayoutError::NormalizationFailure(pointee, err));
},
};

let metadata_layout = cx.layout_of(metadata_ty)?;
// If the metadata is a 1-zst, then the pointer is thin.
if metadata_layout.is_zst() && metadata_layout.align.abi.bytes() == 1 {
return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr)));
}

let Abi::Scalar(metadata) = metadata_layout.abi else {
return Err(LayoutError::Unknown(unsized_part));
return Err(LayoutError::Unknown(pointee));
};

metadata
} else {
let unsized_part = tcx.struct_tail_erasing_lifetimes(pointee, param_env);

match unsized_part.kind() {
ty::Foreign(..) => {
return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr)));
Expand All @@ -178,7 +199,7 @@ fn layout_of_uncached<'tcx>(
vtable
}
_ => {
return Err(LayoutError::Unknown(unsized_part));
return Err(LayoutError::Unknown(pointee));
}
}
};
Expand Down
22 changes: 12 additions & 10 deletions src/bootstrap/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ impl Config {
/// Runs a command, printing out nice contextual information if it fails.
/// Exits if the command failed to execute at all, otherwise returns its
/// `status.success()`.
pub(crate) fn try_run(&self, cmd: &mut Command) -> bool {
pub(crate) fn try_run(&self, cmd: &mut Command) -> Result<(), ()> {
if self.dry_run() {
return true;
return Ok(());
}
self.verbose(&format!("running: {:?}", cmd));
try_run(cmd, self.is_verbose())
Expand Down Expand Up @@ -156,12 +156,14 @@ impl Config {
];
}
";
nix_build_succeeded = self.try_run(Command::new("nix-build").args(&[
Path::new("-E"),
Path::new(NIX_EXPR),
Path::new("-o"),
&nix_deps_dir,
]));
nix_build_succeeded = self
.try_run(Command::new("nix-build").args(&[
Path::new("-E"),
Path::new(NIX_EXPR),
Path::new("-o"),
&nix_deps_dir,
]))
.is_ok();
nix_deps_dir
});
if !nix_build_succeeded {
Expand All @@ -186,7 +188,7 @@ impl Config {
patchelf.args(&["--set-interpreter", dynamic_linker.trim_end()]);
}

self.try_run(patchelf.arg(fname));
self.try_run(patchelf.arg(fname)).unwrap();
}

fn download_file(&self, url: &str, dest_path: &Path, help_on_error: &str) {
Expand Down Expand Up @@ -237,7 +239,7 @@ impl Config {
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')",
url, tempfile.to_str().expect("invalid UTF-8 not supported with powershell downloads"),
),
])) {
])).is_err() {
return;
}
eprintln!("\nspurious failure, trying again");
Expand Down
14 changes: 8 additions & 6 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ forward! {
create(path: &Path, s: &str),
remove(f: &Path),
tempdir() -> PathBuf,
try_run(cmd: &mut Command) -> bool,
try_run(cmd: &mut Command) -> Result<(), ()>,
llvm_link_shared() -> bool,
download_rustc() -> bool,
initial_rustfmt() -> Option<PathBuf>,
Expand Down Expand Up @@ -614,11 +614,13 @@ impl Build {
}

// Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error).
let has_local_modifications = !self.try_run(
Command::new("git")
.args(&["diff-index", "--quiet", "HEAD"])
.current_dir(&absolute_path),
);
let has_local_modifications = self
.try_run(
Command::new("git")
.args(&["diff-index", "--quiet", "HEAD"])
.current_dir(&absolute_path),
)
.is_err();
if has_local_modifications {
self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path));
}
Expand Down
11 changes: 6 additions & 5 deletions src/bootstrap/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ impl Step for ExpandYamlAnchors {
try_run(
builder,
&mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("generate").arg(&builder.src),
);
)
.unwrap();
}

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand All @@ -39,17 +40,17 @@ impl Step for ExpandYamlAnchors {
}
}

fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> Result<(), ()> {
if !builder.fail_fast {
if !builder.try_run(cmd) {
if let Err(e) = builder.try_run(cmd) {
let mut failures = builder.delayed_failures.borrow_mut();
failures.push(format!("{:?}", cmd));
return false;
return Err(e);
}
} else {
builder.run(cmd);
}
true
Ok(())
}

#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
Expand Down
38 changes: 21 additions & 17 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ const MIR_OPT_BLESS_TARGET_MAPPING: &[(&str, &str)] = &[
// build for, so there is no entry for "aarch64-apple-darwin" here.
];

fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> Result<(), ()> {
if !builder.fail_fast {
if !builder.try_run(cmd) {
if let Err(e) = builder.try_run(cmd) {
let mut failures = builder.delayed_failures.borrow_mut();
failures.push(format!("{:?}", cmd));
return false;
return Err(e);
}
} else {
builder.run(cmd);
}
true
Ok(())
}

fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
Expand Down Expand Up @@ -187,7 +187,8 @@ You can skip linkcheck with --exclude src/tools/linkchecker"
try_run(
builder,
builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host.triple).join("doc")),
);
)
.unwrap();
}

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand Down Expand Up @@ -240,7 +241,8 @@ impl Step for HtmlCheck {
builder.default_doc(&[]);
builder.ensure(crate::doc::Rustc::new(builder.top_stage, self.target, builder));

try_run(builder, builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)));
try_run(builder, builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)))
.unwrap();
}
}

Expand Down Expand Up @@ -286,7 +288,8 @@ impl Step for Cargotest {
.args(builder.config.test_args())
.env("RUSTC", builder.rustc(compiler))
.env("RUSTDOC", builder.rustdoc(compiler)),
);
)
.unwrap();
}
}

Expand Down Expand Up @@ -785,7 +788,7 @@ impl Step for Clippy {
cargo.add_rustc_lib_path(builder, compiler);
let mut cargo = prepare_cargo_test(cargo, &[], &[], "clippy", compiler, host, builder);

if builder.try_run(&mut cargo) {
if builder.try_run(&mut cargo).is_ok() {
// The tests succeeded; nothing to do.
return;
}
Expand Down Expand Up @@ -858,7 +861,7 @@ impl Step for RustdocTheme {
util::lld_flag_no_threads(self.compiler.host.contains("windows")),
);
}
try_run(builder, &mut cmd);
try_run(builder, &mut cmd).unwrap();
}
}

Expand Down Expand Up @@ -1109,7 +1112,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
}

builder.info("tidy check");
try_run(builder, &mut cmd);
try_run(builder, &mut cmd).unwrap();

builder.ensure(ExpandYamlAnchors);

Expand Down Expand Up @@ -1157,7 +1160,8 @@ impl Step for ExpandYamlAnchors {
try_run(
builder,
&mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
);
)
.unwrap();
}

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand Down Expand Up @@ -1936,7 +1940,7 @@ impl BookTest {
compiler.host,
);
let _time = util::timeit(&builder);
let toolstate = if try_run(builder, &mut rustbook_cmd) {
let toolstate = if try_run(builder, &mut rustbook_cmd).is_ok() {
ToolState::TestPass
} else {
ToolState::TestFail
Expand Down Expand Up @@ -2094,7 +2098,7 @@ fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) ->
cmd.arg("--test-args").arg(test_args);

if builder.config.verbose_tests {
try_run(builder, &mut cmd)
try_run(builder, &mut cmd).is_ok()
} else {
try_run_quiet(builder, &mut cmd)
}
Expand Down Expand Up @@ -2122,7 +2126,7 @@ impl Step for RustcGuide {

let src = builder.src.join(relative_path);
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)).is_ok() {
ToolState::TestPass
} else {
ToolState::TestFail
Expand Down Expand Up @@ -2661,7 +2665,7 @@ impl Step for Bootstrap {
fn run(self, builder: &Builder<'_>) {
let mut check_bootstrap = Command::new(&builder.python());
check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
try_run(builder, &mut check_bootstrap);
try_run(builder, &mut check_bootstrap).unwrap();

let host = builder.config.build;
let compiler = builder.compiler(0, host);
Expand Down Expand Up @@ -2733,7 +2737,7 @@ impl Step for TierCheck {
}

builder.info("platform support check");
try_run(builder, &mut cargo.into());
try_run(builder, &mut cargo.into()).unwrap();
}
}

Expand Down Expand Up @@ -2813,7 +2817,7 @@ impl Step for RustInstaller {
cmd.env("CARGO", &builder.initial_cargo);
cmd.env("RUSTC", &builder.initial_rustc);
cmd.env("TMP_DIR", &tmpdir);
try_run(builder, &mut cmd);
try_run(builder, &mut cmd).unwrap();
}

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Step for ToolBuild {
);

let mut cargo = Command::from(cargo);
let is_expected = builder.try_run(&mut cargo);
let is_expected = builder.try_run(&mut cargo).is_ok();

builder.save_toolstate(
tool,
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
}

pub fn run(cmd: &mut Command, print_cmd_on_fail: bool) {
if !try_run(cmd, print_cmd_on_fail) {
if try_run(cmd, print_cmd_on_fail).is_err() {
crate::detail_exit_macro!(1);
}
}
Expand Down
Loading