Skip to content

Commit

Permalink
Auto merge of rust-lang#125131 - jieyouxu:rollup-oqprchr, r=jieyouxu
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#124746 (`rustc --explain E0582` additional example)
 - rust-lang#124975 (Use an helper to move the files)
 - rust-lang#125027 (Migrate `run-make/c-link-to-rust-staticlib` to `rmake`)
 - rust-lang#125084 (`rustc_hir_typeck`: Account for `skipped_ref_pats` in `expr_use_visitor`)
 - rust-lang#125104 (Migrate `run-make/no-cdylib-as-rdylib` to `rmake`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 14, 2024
2 parents 8387315 + 49d9c1e commit 7cd7f2d
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 42 deletions.
34 changes: 34 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0582.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@ fn bar<F, G>(t: F, u: G)
fn main() { }
```

This error also includes the use of associated types with lifetime parameters.
```compile_fail,E0582
trait Foo {
type Assoc<'a>;
}
struct Bar<X, F>
where
X: Foo,
F: for<'a> Fn(X::Assoc<'a>) -> &'a i32
{
x: X,
f: F
}
```
This is as `Foo::Assoc<'a>` could be implemented by a type that does not use
the `'a` parameter, so there is no guarentee that `X::Assoc<'a>` actually uses
`'a`.

To fix this we can pass a dummy parameter:
```
# trait Foo {
# type Assoc<'a>;
# }
struct Bar<X, F>
where
X: Foo,
F: for<'a> Fn(X::Assoc<'a>, /* dummy */ &'a ()) -> &'a i32
{
x: X,
f: F
}
```

Note: The examples above used to be (erroneously) accepted by the
compiler, but this was since corrected. See [issue #33685] for more
details.
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_hir_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorOf, Res};
use rustc_hir::def_id::LocalDefId;
use rustc_hir::{HirId, PatKind};
use rustc_middle::{bug, span_bug};
use rustc_middle::hir::place::ProjectionKind;
use rustc_middle::mir::FakeReadCause;
use rustc_middle::ty::{
self, adjustment, AdtKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt as _,
};
use rustc_middle::{bug, span_bug};
use rustc_span::{ErrorGuaranteed, Span};
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
use rustc_trait_selection::infer::InferCtxtExt;
Expand Down Expand Up @@ -1181,6 +1181,10 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
debug!("pat_ty(pat={:?}) found adjusted ty `{:?}`", pat, first_ty);
return Ok(*first_ty);
}
} else if let PatKind::Ref(subpat, _) = pat.kind
&& self.cx.typeck_results().skipped_ref_pats().contains(pat.hir_id)
{
return self.pat_ty_adjusted(subpat);
}

self.pat_ty_unadjusted(pat)
Expand Down Expand Up @@ -1712,6 +1716,12 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
self.cat_pattern(place_with_id, subpat, op)?;
}

PatKind::Ref(subpat, _)
if self.cx.typeck_results().skipped_ref_pats().contains(pat.hir_id) =>
{
self.cat_pattern(place_with_id, subpat, op)?;
}

PatKind::Box(subpat) | PatKind::Ref(subpat, _) => {
// box p1, &p1, &mut p1. we can ignore the mutability of
// PatKind::Ref since that information is already contained
Expand Down
6 changes: 4 additions & 2 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use crate::core::build_steps::tool::{self, Tool};
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::core::config::TargetSelection;
use crate::utils::channel::{self, Info};
use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit};
use crate::utils::helpers::{
exe, is_dylib, move_file, output, t, target_supports_cranelift_backend, timeit,
};
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};

Expand Down Expand Up @@ -2024,7 +2026,7 @@ impl Step for Extended {
builder.run(&mut cmd);

if !builder.config.dry_run() {
t!(fs::rename(exe.join(&filename), distdir(builder).join(&filename)));
t!(move_file(exe.join(&filename), distdir(builder).join(&filename)));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use build_helper::ci::CiEnv;
use build_helper::stage0_parser::VersionMetadata;
use xz2::bufread::XzDecoder;

use crate::utils::helpers::{check_run, exe, program_out_of_date};
use crate::utils::helpers::{check_run, exe, move_file, program_out_of_date};
use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode};
use crate::{t, Config};

Expand Down Expand Up @@ -209,7 +209,7 @@ impl Config {
None => panic!("no protocol in {url}"),
}
t!(
std::fs::rename(&tempfile, dest_path),
move_file(&tempfile, dest_path),
format!("failed to rename {tempfile:?} to {dest_path:?}")
);
}
Expand Down Expand Up @@ -313,7 +313,7 @@ impl Config {
if src_path.is_dir() && dst_path.exists() {
continue;
}
t!(fs::rename(src_path, dst_path));
t!(move_file(src_path, dst_path));
}
let dst_dir = dst.join(directory_prefix);
if dst_dir.exists() {
Expand Down
15 changes: 15 additions & 0 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ pub fn symlink_dir(config: &Config, original: &Path, link: &Path) -> io::Result<
}
}

/// Rename a file if from and to are in the same filesystem or
/// copy and remove the file otherwise
pub fn move_file<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {
match fs::rename(&from, &to) {
// FIXME: Once `ErrorKind::CrossesDevices` is stabilized use
// if e.kind() == io::ErrorKind::CrossesDevices {
#[cfg(unix)]
Err(e) if e.raw_os_error() == Some(libc::EXDEV) => {
std::fs::copy(&from, &to)?;
std::fs::remove_file(&from)
}
r => r,
}
}

pub fn forcing_clang_based_tests() -> bool {
if let Some(var) = env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS") {
match &var.to_string_lossy().to_lowercase()[..] {
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/utils/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
use crate::core::builder::Builder;
use crate::core::{build_steps::dist::distdir, builder::Kind};
use crate::utils::channel;
use crate::utils::helpers::t;
use crate::utils::helpers::{move_file, t};

#[derive(Copy, Clone)]
pub(crate) enum OverlayKind {
Expand Down Expand Up @@ -284,7 +284,7 @@ impl<'a> Tarball<'a> {
// name, not "image". We rename the image directory just before passing
// into rust-installer.
let dest = self.temp_dir.join(self.package_name());
t!(std::fs::rename(&self.image_dir, &dest));
t!(move_file(&self.image_dir, &dest));

self.run(|this, cmd| {
let distdir = distdir(this.builder);
Expand Down
2 changes: 0 additions & 2 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ run-make/branch-protection-check-IBT/Makefile
run-make/c-dynamic-dylib/Makefile
run-make/c-dynamic-rlib/Makefile
run-make/c-link-to-rust-dylib/Makefile
run-make/c-link-to-rust-staticlib/Makefile
run-make/c-static-dylib/Makefile
run-make/c-static-rlib/Makefile
run-make/c-unwind-abi-catch-lib-panic/Makefile
Expand Down Expand Up @@ -180,7 +179,6 @@ run-make/native-link-modifier-whole-archive/Makefile
run-make/no-alloc-shim/Makefile
run-make/no-builtins-attribute/Makefile
run-make/no-builtins-lto/Makefile
run-make/no-cdylib-as-rdylib/Makefile
run-make/no-duplicate-libs/Makefile
run-make/no-intermediate-extras/Makefile
run-make/obey-crate-type-flag/Makefile
Expand Down
16 changes: 0 additions & 16 deletions tests/run-make/c-link-to-rust-staticlib/Makefile

This file was deleted.

19 changes: 19 additions & 0 deletions tests/run-make/c-link-to-rust-staticlib/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This test checks that C linking with Rust does not encounter any errors, with a static library.
// See https://github.com/rust-lang/rust/issues/10434

//@ ignore-cross-compile

use run_make_support::{cc, extra_c_flags, run, rustc, static_lib};
use std::fs;

Check failure on line 8 in tests/run-make/c-link-to-rust-staticlib/rmake.rs

View workflow job for this annotation

GitHub Actions / auto - aarch64-apple

Diff in /Users/runner/work/rust/rust/tests/run-make/c-link-to-rust-staticlib/rmake.rs
fn main() {
rustc().input("foo.rs").run();
cc().input("bar.c")
.input(static_lib("foo"))
.out_exe("bar")
.args(&extra_c_flags())
.run();
run("bar");
fs::remove_file(static_lib("foo"));
run("bar");
}
16 changes: 0 additions & 16 deletions tests/run-make/no-cdylib-as-rdylib/Makefile

This file was deleted.

16 changes: 16 additions & 0 deletions tests/run-make/no-cdylib-as-rdylib/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This test produces an rlib and a cdylib from bar.rs.
// Then, foo.rs attempts to link to the bar library.
// If the test passes, that means rustc favored the rlib and ignored the cdylib.
// If the test fails, that is because the cdylib was picked, which does not export
// any Rust symbols.
// See https://github.com/rust-lang/rust/pull/113695

//@ ignore-cross-compile

use run_make_support::{run, rustc};

fn main() {
rustc().input("bar.rs").crate_type("rlib").crate_type("cdylib").run();
rustc().input("foo.rs").arg("-Cprefer-dynamic").run();
run("foo");
}
18 changes: 18 additions & 0 deletions tests/ui/pattern/skipped-ref-pats-issue-125058.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ run-pass
//@ edition: 2024
//@ compile-flags: -Zunstable-options

#![allow(incomplete_features)]
#![feature(ref_pat_eat_one_layer_2024)]

struct Foo;
//~^ WARN struct `Foo` is never constructed

fn main() {
|| {
//~^ WARN unused closure that must be used
if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
let _: u32 = x;
}
};
}
24 changes: 24 additions & 0 deletions tests/ui/pattern/skipped-ref-pats-issue-125058.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
warning: struct `Foo` is never constructed
--> $DIR/skipped-ref-pats-issue-125058.rs:8:8
|
LL | struct Foo;
| ^^^
|
= note: `#[warn(dead_code)]` on by default

warning: unused closure that must be used
--> $DIR/skipped-ref-pats-issue-125058.rs:12:5
|
LL | / || {
LL | |
LL | | if let Some(Some(&mut x)) = &mut Some(&mut Some(0)) {
LL | | let _: u32 = x;
LL | | }
LL | | };
| |_____^
|
= note: closures are lazy and do nothing unless called
= note: `#[warn(unused_must_use)]` on by default

warning: 2 warnings emitted

0 comments on commit 7cd7f2d

Please sign in to comment.