Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #88389

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9c7dbe8
Notify when an `I-prioritize` issue is closed
LeSeulArtichaut Dec 31, 2020
0ac601d
Mach-O (Macos/ios/...) LLD flavor is always LD64.
hkratz Aug 23, 2021
a519095
Include ld64 nexte to ld for use with -Z gcc-ld
hkratz Aug 23, 2021
0f7702e
Pass -fuse-ld=/path/to/ld64 if -Z gcc-ld and the lld_flavor for the t…
hkratz Aug 23, 2021
4b45bb9
Doctest persist full binaries when persisting
prconrad Aug 23, 2021
4d8d72f
Handle match with non axhaustive variants in closures
roxelo Aug 24, 2021
1335b4c
Add additional match test case
roxelo Aug 24, 2021
68b1bfc
Create a specific match folder for match tests
roxelo Aug 24, 2021
785309b
Add make tests for preserving test binaries
Aug 25, 2021
4fcae2c
Add const and static TAIT tests
spastorino Aug 25, 2021
bee13d1
add unsized coercion test
lcnr Aug 26, 2021
97bf80d
Treat types in unnormalized function signatures as well-formed
jackh726 Aug 25, 2021
e3cc51d
Rollup merge of #80543 - LeSeulArtichaut:notify-close, r=spastorino
Dylan-DPC Aug 27, 2021
056809f
Rollup merge of #88250 - rusticstuff:macos-lld, r=nagisa
Dylan-DPC Aug 27, 2021
671817a
Rollup merge of #88269 - prconrad:doctest-persist-binaries, r=jyn514
Dylan-DPC Aug 27, 2021
b33f35a
Rollup merge of #88280 - sexxi-goose:non-exhaustive, r=nikomatsakis
Dylan-DPC Aug 27, 2021
3830827
Rollup merge of #88312 - jackh726:issue-87748, r=nikomatsakis
Dylan-DPC Aug 27, 2021
45f5b4e
Rollup merge of #88349 - spastorino:const-static-types-tait-test, r=o…
Dylan-DPC Aug 27, 2021
e26afba
Rollup merge of #88357 - lcnr:stabilize-relaxed_struct_unsize, r=Mark…
Dylan-DPC Aug 27, 2021
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
47 changes: 33 additions & 14 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2482,20 +2482,39 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
if let LinkerFlavor::Gcc = flavor {
match ld_impl {
LdImpl::Lld => {
let tools_path =
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
let lld_path = tools_path
.into_iter()
.map(|p| p.join("gcc-ld"))
.find(|p| {
p.join(if sess.host.is_like_windows { "ld.exe" } else { "ld" }).exists()
})
.unwrap_or_else(|| sess.fatal("rust-lld (as ld) not found"));
cmd.cmd().arg({
let mut arg = OsString::from("-B");
arg.push(lld_path);
arg
});
if sess.target.lld_flavor == LldFlavor::Ld64 {
let tools_path =
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
let ld64_exe = tools_path
.into_iter()
.map(|p| p.join("gcc-ld"))
.map(|p| {
p.join(if sess.host.is_like_windows { "ld64.exe" } else { "ld64" })
})
.find(|p| p.exists())
.unwrap_or_else(|| sess.fatal("rust-lld (as ld64) not found"));
cmd.cmd().arg({
let mut arg = OsString::from("-fuse-ld=");
arg.push(ld64_exe);
arg
});
} else {
let tools_path =
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
let lld_path = tools_path
.into_iter()
.map(|p| p.join("gcc-ld"))
.find(|p| {
p.join(if sess.host.is_like_windows { "ld.exe" } else { "ld" })
.exists()
})
.unwrap_or_else(|| sess.fatal("rust-lld (as ld) not found"));
cmd.cmd().arg({
let mut arg = OsString::from("-B");
arg.push(lld_path);
arg
});
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
let constraint_sets: Vec<_> = unnormalized_input_output_tys
.flat_map(|ty| {
debug!("build: input_or_output={:?}", ty);
// We add implied bounds from both the unnormalized and normalized ty
// See issue #87748
let constraints_implied_1 = self.add_implied_bounds(ty);
let TypeOpOutput { output: ty, constraints: constraints1, .. } = self
.param_env
.and(type_op::normalize::Normalize::new(ty))
Expand All @@ -271,9 +274,21 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
canonicalized_query: None,
}
});
let constraints2 = self.add_implied_bounds(ty);
// Note: we need this in examples like
// ```
// trait Foo {
// type Bar;
// fn foo(&self) -> &Self::Bar;
// }
// impl Foo for () {
// type Bar = ();
// fn foo(&self) ->&() {}
// }
// ```
// Both &Self::Bar and &() are WF
let constraints_implied_2 = self.add_implied_bounds(ty);
normalized_inputs_and_output.push(ty);
constraints1.into_iter().chain(constraints2)
constraints1.into_iter().chain(constraints_implied_1).chain(constraints_implied_2)
})
.collect();

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_target/src/spec/apple_base.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;

use crate::spec::{FramePointer, SplitDebuginfo, TargetOptions};
use crate::spec::{FramePointer, LldFlavor, SplitDebuginfo, TargetOptions};

pub fn opts(os: &str) -> TargetOptions {
// ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6
Expand Down Expand Up @@ -35,6 +35,7 @@ pub fn opts(os: &str) -> TargetOptions {
abi_return_struct_as_int: true,
emit_debug_gdb_scripts: false,
eh_frame_header: false,
lld_flavor: LldFlavor::Ld64,

// The historical default for macOS targets is to run `dsymutil` which
// generates a packed version of debuginfo split from the main file.
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ fn compare_predicate_entailment<'tcx>(
// Compute placeholder form of impl and trait method tys.
let tcx = infcx.tcx;

let mut wf_tys = vec![];

let (impl_sig, _) = infcx.replace_bound_vars_with_fresh_vars(
impl_m_span,
infer::HigherRankedType,
Expand All @@ -260,10 +262,18 @@ fn compare_predicate_entailment<'tcx>(
let impl_fty = tcx.mk_fn_ptr(ty::Binder::dummy(impl_sig));
debug!("compare_impl_method: impl_fty={:?}", impl_fty);

// First liberate late bound regions and subst placeholders
let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(trait_m.def_id));
let trait_sig = trait_sig.subst(tcx, trait_to_placeholder_substs);
// Next, add all inputs and output as well-formed tys. Importantly,
// we have to do this before normalization, since the normalized ty may
// not contain the input parameters. See issue #87748.
wf_tys.extend(trait_sig.inputs_and_output.iter());
let trait_sig =
inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig);
// Also add the resulting inputs and output as well-formed.
// This probably isn't strictly necessary.
wf_tys.extend(trait_sig.inputs_and_output.iter());
let trait_fty = tcx.mk_fn_ptr(ty::Binder::dummy(trait_sig));

debug!("compare_impl_method: trait_fty={:?}", trait_fty);
Expand Down Expand Up @@ -388,7 +398,7 @@ fn compare_predicate_entailment<'tcx>(
// Finally, resolve all regions. This catches wily misuses of
// lifetime parameters.
let fcx = FnCtxt::new(&inh, param_env, impl_m_hir_id);
fcx.regionck_item(impl_m_hir_id, impl_m_span, trait_sig.inputs_and_output);
fcx.regionck_item(impl_m_hir_id, impl_m_span, &wf_tys);

Ok(())
})
Expand Down
16 changes: 12 additions & 4 deletions compiler/rustc_typeck/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ fn typeck_with_fallback<'tcx>(

let typeck_results = Inherited::build(tcx, def_id).enter(|inh| {
let param_env = tcx.param_env(def_id);
let fcx = if let Some(hir::FnSig { header, decl, .. }) = fn_sig {
let (fcx, wf_tys) = if let Some(hir::FnSig { header, decl, .. }) = fn_sig {
let fn_sig = if crate::collect::get_infer_ret_ty(&decl.output).is_some() {
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
<dyn AstConv<'_>>::ty_of_fn(
Expand All @@ -383,17 +383,25 @@ fn typeck_with_fallback<'tcx>(

check_abi(tcx, id, span, fn_sig.abi());

// When normalizing the function signature, we assume all types are
// well-formed. So, we don't need to worry about the obligations
// from normalization. We could just discard these, but to align with
// compare_method and elsewhere, we just add implied bounds for
// these types.
let mut wf_tys = vec![];
// Compute the fty from point of view of inside the fn.
let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
wf_tys.extend(fn_sig.inputs_and_output.iter());
let fn_sig = inh.normalize_associated_types_in(
body.value.span,
body_id.hir_id,
param_env,
fn_sig,
);
wf_tys.extend(fn_sig.inputs_and_output.iter());

let fcx = check_fn(&inh, param_env, fn_sig, decl, id, body, None, true).0;
fcx
(fcx, wf_tys)
} else {
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
let expected_type = body_ty
Expand Down Expand Up @@ -443,7 +451,7 @@ fn typeck_with_fallback<'tcx>(

fcx.write_ty(id, expected_type);

fcx
(fcx, vec![])
};

let fallback_has_occurred = fcx.type_inference_fallback();
Expand All @@ -467,7 +475,7 @@ fn typeck_with_fallback<'tcx>(
fcx.select_all_obligations_or_error();

if fn_sig.is_some() {
fcx.regionck_fn(id, body);
fcx.regionck_fn(id, body, span, &wf_tys);
} else {
fcx.regionck_expr(body);
}
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_typeck/src/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// rest of type check and because sometimes we need type
/// inference to have completed before we can determine which
/// constraints to add.
pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'tcx hir::Body<'tcx>) {
pub(crate) fn regionck_fn(
&self,
fn_id: hir::HirId,
body: &'tcx hir::Body<'tcx>,
span: Span,
wf_tys: &[Ty<'tcx>],
) {
debug!("regionck_fn(id={})", fn_id);
let subject = self.tcx.hir().body_owner_def_id(body.id());
let hir_id = body.value.hir_id;
let mut rcx = RegionCtxt::new(self, hir_id, Subject(subject), self.param_env);
// We need to add the implied bounds from the function signature
rcx.outlives_environment.add_implied_bounds(self, wf_tys, fn_id, span);
rcx.outlives_environment.save_implied_bounds(fn_id);

if !self.errors_reported_since_creation() {
// regionck assumes typeck succeeded
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_typeck/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ fn check_where_clauses<'tcx, 'fcx>(
}
}

#[tracing::instrument(level = "debug", skip(fcx, span, hir_decl))]
fn check_fn_or_method<'fcx, 'tcx>(
fcx: &FnCtxt<'fcx, 'tcx>,
span: Span,
Expand All @@ -921,6 +922,11 @@ fn check_fn_or_method<'fcx, 'tcx>(
) {
let sig = fcx.tcx.liberate_late_bound_regions(def_id, sig);

// Unnormalized types in signature are WF too
implied_bounds.extend(sig.inputs());
// FIXME(#27579) return types should not be implied bounds
implied_bounds.push(sig.output());

// Normalize the input and output types one at a time, using a different
// `WellFormedLoc` for each. We cannot call `normalize_associated_types`
// on the entire `FnSig`, since this would use the same `WellFormedLoc`
Expand Down Expand Up @@ -970,9 +976,11 @@ fn check_fn_or_method<'fcx, 'tcx>(
ObligationCauseCode::ReturnType,
);

// FIXME(#25759) return types should not be implied bounds
// FIXME(#27579) return types should not be implied bounds
implied_bounds.push(sig.output());

debug!(?implied_bounds);

check_where_clauses(fcx, span, def_id, Some((sig.output(), hir_decl.output.span())));
}

Expand Down Expand Up @@ -1117,6 +1125,7 @@ const HELP_FOR_SELF_TYPE: &str = "consider changing to `self`, `&self`, `&mut se
`self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one \
of the previous types except `Self`)";

#[tracing::instrument(level = "debug", skip(fcx))]
fn check_method_receiver<'fcx, 'tcx>(
fcx: &FnCtxt<'fcx, 'tcx>,
fn_sig: &hir::FnSig<'_>,
Expand Down
17 changes: 15 additions & 2 deletions compiler/rustc_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_index::vec::Idx;
use rustc_infer::infer::InferCtxt;
use rustc_middle::hir::place::ProjectionKind;
use rustc_middle::mir::FakeReadCause;
use rustc_middle::ty::{self, adjustment, TyCtxt};
use rustc_middle::ty::{self, adjustment, AdtKind, TyCtxt};
use rustc_target::abi::VariantIdx;
use std::iter;

Expand Down Expand Up @@ -265,7 +265,20 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
let place_ty = place.place.ty();

if let ty::Adt(def, _) = place_ty.kind() {
if def.variants.len() > 1 {
// Note that if a non-exhaustive SingleVariant is defined in another crate, we need
// to assume that more cases will be added to the variant in the future. This mean
// that we should handle non-exhaustive SingleVariant the same way we would handle
// a MultiVariant.
// If the variant is not local it must be defined in another crate.
let is_non_exhaustive = match def.adt_kind() {
AdtKind::Struct | AdtKind::Union => {
def.non_enum_variant().is_field_list_non_exhaustive()
}
AdtKind::Enum => def.is_variant_list_non_exhaustive(),
};
if def.variants.len() > 1
|| (!def.did.is_local() && is_non_exhaustive)
{
needs_to_be_read = true;
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,10 @@ impl Step for Assemble {
&lld_install.join("bin").join(&src_exe),
&gcc_ld_dir.join(exe("ld", target_compiler.host)),
);
builder.copy(
&lld_install.join("bin").join(&src_exe),
&gcc_ld_dir.join(exe("ld64", target_compiler.host)),
);
}

// Similarly, copy `llvm-dwp` into libdir for Split DWARF. Only copy it when the LLVM
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ impl Step for Rustc {
let gcc_lld_dir = dst_dir.join("gcc-ld");
t!(fs::create_dir(&gcc_lld_dir));
builder.copy(&src_dir.join(&rust_lld), &gcc_lld_dir.join(exe("ld", compiler.host)));
builder
.copy(&src_dir.join(&rust_lld), &gcc_lld_dir.join(exe("ld64", compiler.host)));
}

// Copy over llvm-dwp if it's there
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn run_test(
for debugging_option_str in &options.debugging_opts_strs {
compiler.arg("-Z").arg(&debugging_option_str);
}
if no_run && !compile_fail {
if no_run && !compile_fail && options.persist_doctests.is_none() {
compiler.arg("--emit=metadata");
}
compiler.arg("--target").arg(match target {
Expand Down
21 changes: 21 additions & 0 deletions src/test/run-make/doctests-keep-binaries/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include ../../run-make-fulldeps/tools.mk

# Check that valid binaries are persisted by running them, regardless of whether the --run or --no-run option is used.

all: run no_run

run:
mkdir -p $(TMPDIR)/doctests
$(RUSTC) --crate-type rlib t.rs
$(RUSTDOC) -Zunstable-options --test --persist-doctests $(TMPDIR)/doctests --extern t=$(TMPDIR)/libt.rlib t.rs
$(TMPDIR)/doctests/t_rs_2_0/rust_out
$(TMPDIR)/doctests/t_rs_8_0/rust_out
rm -rf $(TMPDIR)/doctests

no_run:
mkdir -p $(TMPDIR)/doctests
$(RUSTC) --crate-type rlib t.rs
$(RUSTDOC) -Zunstable-options --test --persist-doctests $(TMPDIR)/doctests --extern t=$(TMPDIR)/libt.rlib t.rs --no-run
$(TMPDIR)/doctests/t_rs_2_0/rust_out
$(TMPDIR)/doctests/t_rs_8_0/rust_out
rm -rf $(TMPDIR)/doctests
11 changes: 11 additions & 0 deletions src/test/run-make/doctests-keep-binaries/t.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// Fungle the foople.
/// ```
/// t::foople();
/// ```
pub fn foople() {}

/// Flomble the florp
/// ```
/// t::florp();
/// ```
pub fn florp() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[non_exhaustive]
pub enum E1 {}

#[non_exhaustive]
pub enum E2 { A, B }

#[non_exhaustive]
pub enum E3 { C }

pub enum E4 { D }
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// edition:2021

enum SingleVariant {
A
}

struct TestStruct {
x: i32,
y: i32,
z: i32,
}

fn main() {
let sv = SingleVariant::A;
let condition = true;
// sv should not be captured as it is a SingleVariant
let _a = || {
match sv {
SingleVariant::A if condition => (),
_ => ()
}
};
let mut mut_sv = sv;
_a();

// ts should be captured
let ts = TestStruct { x: 1, y: 1, z: 1 };
let _b = || { match ts {
TestStruct{ x: 1, .. } => (),
_ => ()
}};
let mut mut_ts = ts;
//~^ ERROR: cannot move out of `ts` because it is borrowed
_b();
}
Loading