Skip to content

Commit 90b3882

Browse files
committed
Auto merge of rust-lang#103739 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backport rollup * poll_fn and Unpin: fix pinning rust-lang#102737 * Support raw-dylib functions being used inside inlined functions rust-lang#102988 * Fix line numbers for MIR inlined code rust-lang#103071 * Add architectures to fn create_object_file rust-lang#103240 * Add eval hack in super_relate_consts back rust-lang#103279 * Mark std::os::wasi::io::AsFd etc. as stable. rust-lang#103308 * Truncate thread names on Linux and Apple targets rust-lang#103379 * Do not consider repeated lifetime params for elision. rust-lang#103450 * rustdoc: add missing URL redirect rust-lang#103588 * Remove commit_if_ok probe from NLL type relation rust-lang#103601 Also includes a copy of the release notes. r? `@ghost`
2 parents 636a78a + 108b32e commit 90b3882

File tree

38 files changed

+713
-81
lines changed

38 files changed

+713
-81
lines changed

RELEASES.md

+244
Large diffs are not rendered by default.

compiler/rustc_codegen_cranelift/src/archive.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
3838
_lib_name: &str,
3939
_dll_imports: &[rustc_session::cstore::DllImport],
4040
_tmpdir: &Path,
41+
_is_direct_dependency: bool,
4142
) -> PathBuf {
4243
bug!("creating dll imports is not supported");
4344
}

compiler/rustc_codegen_gcc/src/archive.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
4545
_lib_name: &str,
4646
_dll_imports: &[DllImport],
4747
_tmpdir: &Path,
48+
_is_direct_dependency: bool,
4849
) -> PathBuf {
4950
unimplemented!();
5051
}

compiler/rustc_codegen_llvm/src/back/archive.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,12 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
104104
lib_name: &str,
105105
dll_imports: &[DllImport],
106106
tmpdir: &Path,
107+
is_direct_dependency: bool,
107108
) -> PathBuf {
109+
let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
108110
let output_path = {
109111
let mut output_path: PathBuf = tmpdir.to_path_buf();
110-
output_path.push(format!("{}_imports", lib_name));
112+
output_path.push(format!("{}{}", lib_name, name_suffix));
111113
output_path.with_extension("lib")
112114
};
113115

@@ -134,7 +136,8 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
134136
// that loaded but crashed with an AV upon calling one of the imported
135137
// functions. Therefore, use binutils to create the import library instead,
136138
// by writing a .DEF file to the temp dir and calling binutils's dlltool.
137-
let def_file_path = tmpdir.join(format!("{}_imports", lib_name)).with_extension("def");
139+
let def_file_path =
140+
tmpdir.join(format!("{}{}", lib_name, name_suffix)).with_extension("def");
138141

139142
let def_file_content = format!(
140143
"EXPORTS\n{}",

compiler/rustc_codegen_ssa/src/back/archive.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub trait ArchiveBuilderBuilder {
2525
lib_name: &str,
2626
dll_imports: &[DllImport],
2727
tmpdir: &Path,
28+
is_direct_dependency: bool,
2829
) -> PathBuf;
2930

3031
fn extract_bundled_libs(

compiler/rustc_codegen_ssa/src/back/link.rs

+36-5
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,14 @@ fn link_rlib<'a>(
376376
}
377377

378378
for (raw_dylib_name, raw_dylib_imports) in
379-
collate_raw_dylibs(sess, &codegen_results.crate_info.used_libraries)?
379+
collate_raw_dylibs(sess, codegen_results.crate_info.used_libraries.iter())?
380380
{
381381
let output_path = archive_builder_builder.create_dll_import_lib(
382382
sess,
383383
&raw_dylib_name,
384384
&raw_dylib_imports,
385385
tmpdir.as_ref(),
386+
true,
386387
);
387388

388389
ab.add_archive(&output_path, Box::new(|_| false)).unwrap_or_else(|e| {
@@ -434,9 +435,9 @@ fn link_rlib<'a>(
434435
/// then the CodegenResults value contains one NativeLib instance for each block. However, the
435436
/// linker appears to expect only a single import library for each library used, so we need to
436437
/// collate the symbols together by library name before generating the import libraries.
437-
fn collate_raw_dylibs(
438-
sess: &Session,
439-
used_libraries: &[NativeLib],
438+
fn collate_raw_dylibs<'a, 'b>(
439+
sess: &'a Session,
440+
used_libraries: impl IntoIterator<Item = &'b NativeLib>,
440441
) -> Result<Vec<(String, Vec<DllImport>)>, ErrorGuaranteed> {
441442
// Use index maps to preserve original order of imports and libraries.
442443
let mut dylib_table = FxIndexMap::<String, FxIndexMap<Symbol, &DllImport>>::default();
@@ -2028,13 +2029,43 @@ fn linker_with_args<'a>(
20282029

20292030
// Link with the import library generated for any raw-dylib functions.
20302031
for (raw_dylib_name, raw_dylib_imports) in
2031-
collate_raw_dylibs(sess, &codegen_results.crate_info.used_libraries)?
2032+
collate_raw_dylibs(sess, codegen_results.crate_info.used_libraries.iter())?
2033+
{
2034+
cmd.add_object(&archive_builder_builder.create_dll_import_lib(
2035+
sess,
2036+
&raw_dylib_name,
2037+
&raw_dylib_imports,
2038+
tmpdir,
2039+
true,
2040+
));
2041+
}
2042+
// As with add_upstream_native_libraries, we need to add the upstream raw-dylib symbols in case
2043+
// they are used within inlined functions or instantiated generic functions. We do this *after*
2044+
// handling the raw-dylib symbols in the current crate to make sure that those are chosen first
2045+
// by the linker.
2046+
let (_, dependency_linkage) = codegen_results
2047+
.crate_info
2048+
.dependency_formats
2049+
.iter()
2050+
.find(|(ty, _)| *ty == crate_type)
2051+
.expect("failed to find crate type in dependency format list");
2052+
let native_libraries_from_nonstatics = codegen_results
2053+
.crate_info
2054+
.native_libraries
2055+
.iter()
2056+
.filter_map(|(cnum, libraries)| {
2057+
(dependency_linkage[cnum.as_usize() - 1] != Linkage::Static).then(|| libraries)
2058+
})
2059+
.flatten();
2060+
for (raw_dylib_name, raw_dylib_imports) in
2061+
collate_raw_dylibs(sess, native_libraries_from_nonstatics)?
20322062
{
20332063
cmd.add_object(&archive_builder_builder.create_dll_import_lib(
20342064
sess,
20352065
&raw_dylib_name,
20362066
&raw_dylib_imports,
20372067
tmpdir,
2068+
false,
20382069
));
20392070
}
20402071

compiler/rustc_codegen_ssa/src/back/metadata.rs

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
117117
"riscv32" => Architecture::Riscv32,
118118
"riscv64" => Architecture::Riscv64,
119119
"sparc64" => Architecture::Sparc64,
120+
"avr" => Architecture::Avr,
121+
"msp430" => Architecture::Msp430,
122+
"hexagon" => Architecture::Hexagon,
123+
"bpf" => Architecture::Bpf,
120124
// Unsupported architecture.
121125
_ => return None,
122126
};

compiler/rustc_const_eval/src/interpret/operand.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
591591
val: &mir::ConstantKind<'tcx>,
592592
layout: Option<TyAndLayout<'tcx>>,
593593
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
594+
// FIXME(const_prop): normalization needed b/c const prop lint in
595+
// `mir_drops_elaborated_and_const_checked`, which happens before
596+
// optimized MIR. Only after optimizing the MIR can we guarantee
597+
// that the `RevealAll` pass has happened and that the body's consts
598+
// are normalized, so any call to resolve before that needs to be
599+
// manually normalized.
600+
let val = self.tcx.normalize_erasing_regions(self.param_env, *val);
594601
match val {
595-
mir::ConstantKind::Ty(ct) => self.const_to_op(*ct, layout),
596-
mir::ConstantKind::Val(val, ty) => self.const_val_to_op(*val, *ty, layout),
602+
mir::ConstantKind::Ty(ct) => self.const_to_op(ct, layout),
603+
mir::ConstantKind::Val(val, ty) => self.const_val_to_op(val, ty, layout),
597604
mir::ConstantKind::Unevaluated(uv, _) => {
598605
let instance = self.resolve(uv.def, uv.substs)?;
599606
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into())

compiler/rustc_infer/src/infer/nll_relate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ where
596596
(&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)),
597597

598598
(&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => {
599-
infcx.commit_if_ok(|_| infcx.super_combine_tys(self, a, b)).or_else(|err| {
599+
infcx.super_combine_tys(self, a, b).or_else(|err| {
600600
self.tcx().sess.delay_span_bug(
601601
self.delegate.span(),
602602
"failure to relate an opaque to itself should result in an error later on",

compiler/rustc_middle/src/ty/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2489,7 +2489,9 @@ impl<'tcx> TyCtxt<'tcx> {
24892489
&& if self.features().collapse_debuginfo {
24902490
span.in_macro_expansion_with_collapse_debuginfo()
24912491
} else {
2492-
span.from_expansion()
2492+
// Inlined spans should not be collapsed as that leads to all of the
2493+
// inlined code being attributed to the inline callsite.
2494+
span.from_expansion() && !span.is_inlined()
24932495
}
24942496
}
24952497

compiler/rustc_middle/src/ty/relate.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
574574
/// it.
575575
pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
576576
relation: &mut R,
577-
a: ty::Const<'tcx>,
578-
b: ty::Const<'tcx>,
577+
mut a: ty::Const<'tcx>,
578+
mut b: ty::Const<'tcx>,
579579
) -> RelateResult<'tcx, ty::Const<'tcx>> {
580580
debug!("{}.super_relate_consts(a = {:?}, b = {:?})", relation.tag(), a, b);
581581
let tcx = relation.tcx();
@@ -596,6 +596,17 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
596596
);
597597
}
598598

599+
// HACK(const_generics): We still need to eagerly evaluate consts when
600+
// relating them because during `normalize_param_env_or_error`,
601+
// we may relate an evaluated constant in a obligation against
602+
// an unnormalized (i.e. unevaluated) const in the param-env.
603+
// FIXME(generic_const_exprs): Once we always lazily unify unevaluated constants
604+
// these `eval` calls can be removed.
605+
if !relation.tcx().features().generic_const_exprs {
606+
a = a.eval(tcx, relation.param_env());
607+
b = b.eval(tcx, relation.param_env());
608+
}
609+
599610
// Currently, the values that can be unified are primitive types,
600611
// and those that derive both `PartialEq` and `Eq`, corresponding
601612
// to structural-match types.

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
481481
// Use `Reveal::All` here because patterns are always monomorphic even if their function
482482
// isn't.
483483
let param_env_reveal_all = self.param_env.with_reveal_all_normalized(self.tcx);
484-
let substs = self.typeck_results.node_substs(id);
484+
// N.B. There is no guarantee that substs collected in typeck results are fully normalized,
485+
// so they need to be normalized in order to pass to `Instance::resolve`, which will ICE
486+
// if given unnormalized types.
487+
let substs = self
488+
.tcx
489+
.normalize_erasing_regions(param_env_reveal_all, self.typeck_results.node_substs(id));
485490
let instance = match ty::Instance::resolve(self.tcx, param_env_reveal_all, def_id, substs) {
486491
Ok(Some(i)) => i,
487492
Ok(None) => {

compiler/rustc_resolve/src/late.rs

+69-34
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use rustc_span::{BytePos, Span};
3030
use smallvec::{smallvec, SmallVec};
3131

3232
use rustc_span::source_map::{respan, Spanned};
33+
use std::assert_matches::debug_assert_matches;
3334
use std::collections::{hash_map::Entry, BTreeSet};
3435
use std::mem::{replace, take};
3536

@@ -557,7 +558,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast> {
557558
/// They will be used to determine the correct lifetime for the fn return type.
558559
/// The `LifetimeElisionCandidate` is used for diagnostics, to suggest introducing named
559560
/// lifetimes.
560-
lifetime_elision_candidates: Option<FxIndexMap<LifetimeRes, LifetimeElisionCandidate>>,
561+
lifetime_elision_candidates: Option<Vec<(LifetimeRes, LifetimeElisionCandidate)>>,
561562

562563
/// The trait that the current context can refer to.
563564
current_trait_ref: Option<(Module<'a>, TraitRef)>,
@@ -1819,7 +1820,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
18191820
match res {
18201821
LifetimeRes::Param { .. } | LifetimeRes::Fresh { .. } | LifetimeRes::Static => {
18211822
if let Some(ref mut candidates) = self.lifetime_elision_candidates {
1822-
candidates.insert(res, candidate);
1823+
candidates.push((res, candidate));
18231824
}
18241825
}
18251826
LifetimeRes::Infer | LifetimeRes::Error | LifetimeRes::ElidedAnchor { .. } => {}
@@ -1872,74 +1873,108 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
18721873
has_self: bool,
18731874
inputs: impl Iterator<Item = (Option<&'ast Pat>, &'ast Ty)>,
18741875
) -> Result<LifetimeRes, (Vec<MissingLifetime>, Vec<ElisionFnParameter>)> {
1875-
let outer_candidates =
1876-
replace(&mut self.lifetime_elision_candidates, Some(Default::default()));
1876+
enum Elision {
1877+
/// We have not found any candidate.
1878+
None,
1879+
/// We have a candidate bound to `self`.
1880+
Self_(LifetimeRes),
1881+
/// We have a candidate bound to a parameter.
1882+
Param(LifetimeRes),
1883+
/// We failed elision.
1884+
Err,
1885+
}
18771886

1878-
let mut elision_lifetime = None;
1879-
let mut lifetime_count = 0;
1887+
// Save elision state to reinstate it later.
1888+
let outer_candidates = self.lifetime_elision_candidates.take();
1889+
1890+
// Result of elision.
1891+
let mut elision_lifetime = Elision::None;
1892+
// Information for diagnostics.
18801893
let mut parameter_info = Vec::new();
1894+
let mut all_candidates = Vec::new();
18811895

18821896
let mut bindings = smallvec![(PatBoundCtx::Product, Default::default())];
18831897
for (index, (pat, ty)) in inputs.enumerate() {
18841898
debug!(?pat, ?ty);
18851899
if let Some(pat) = pat {
18861900
self.resolve_pattern(pat, PatternSource::FnParam, &mut bindings);
18871901
}
1902+
1903+
// Record elision candidates only for this parameter.
1904+
debug_assert_matches!(self.lifetime_elision_candidates, None);
1905+
self.lifetime_elision_candidates = Some(Default::default());
18881906
self.visit_ty(ty);
1907+
let local_candidates = self.lifetime_elision_candidates.take();
18891908

1890-
if let Some(ref candidates) = self.lifetime_elision_candidates {
1891-
let new_count = candidates.len();
1892-
let local_count = new_count - lifetime_count;
1893-
if local_count != 0 {
1909+
if let Some(candidates) = local_candidates {
1910+
let distinct: FxHashSet<_> = candidates.iter().map(|(res, _)| *res).collect();
1911+
let lifetime_count = distinct.len();
1912+
if lifetime_count != 0 {
18941913
parameter_info.push(ElisionFnParameter {
18951914
index,
18961915
ident: if let Some(pat) = pat && let PatKind::Ident(_, ident, _) = pat.kind {
18971916
Some(ident)
18981917
} else {
18991918
None
19001919
},
1901-
lifetime_count: local_count,
1920+
lifetime_count,
19021921
span: ty.span,
19031922
});
1923+
all_candidates.extend(candidates.into_iter().filter_map(|(_, candidate)| {
1924+
match candidate {
1925+
LifetimeElisionCandidate::Ignore | LifetimeElisionCandidate::Named => {
1926+
None
1927+
}
1928+
LifetimeElisionCandidate::Missing(missing) => Some(missing),
1929+
}
1930+
}));
1931+
}
1932+
let mut distinct_iter = distinct.into_iter();
1933+
if let Some(res) = distinct_iter.next() {
1934+
match elision_lifetime {
1935+
// We are the first parameter to bind lifetimes.
1936+
Elision::None => {
1937+
if distinct_iter.next().is_none() {
1938+
// We have a single lifetime => success.
1939+
elision_lifetime = Elision::Param(res)
1940+
} else {
1941+
// We have have multiple lifetimes => error.
1942+
elision_lifetime = Elision::Err;
1943+
}
1944+
}
1945+
// We have 2 parameters that bind lifetimes => error.
1946+
Elision::Param(_) => elision_lifetime = Elision::Err,
1947+
// `self` elision takes precedence over everything else.
1948+
Elision::Self_(_) | Elision::Err => {}
1949+
}
19041950
}
1905-
lifetime_count = new_count;
19061951
}
19071952

19081953
// Handle `self` specially.
19091954
if index == 0 && has_self {
19101955
let self_lifetime = self.find_lifetime_for_self(ty);
19111956
if let Set1::One(lifetime) = self_lifetime {
1912-
elision_lifetime = Some(lifetime);
1913-
self.lifetime_elision_candidates = None;
1957+
// We found `self` elision.
1958+
elision_lifetime = Elision::Self_(lifetime);
19141959
} else {
1915-
self.lifetime_elision_candidates = Some(Default::default());
1916-
lifetime_count = 0;
1960+
// We do not have `self` elision: disregard the `Elision::Param` that we may
1961+
// have found.
1962+
elision_lifetime = Elision::None;
19171963
}
19181964
}
19191965
debug!("(resolving function / closure) recorded parameter");
19201966
}
19211967

1922-
let all_candidates = replace(&mut self.lifetime_elision_candidates, outer_candidates);
1923-
debug!(?all_candidates);
1968+
// Reinstate elision state.
1969+
debug_assert_matches!(self.lifetime_elision_candidates, None);
1970+
self.lifetime_elision_candidates = outer_candidates;
19241971

1925-
if let Some(res) = elision_lifetime {
1972+
if let Elision::Param(res) | Elision::Self_(res) = elision_lifetime {
19261973
return Ok(res);
19271974
}
19281975

1929-
// We do not have a `self` candidate, look at the full list.
1930-
let all_candidates = all_candidates.unwrap();
1931-
if all_candidates.len() == 1 {
1932-
Ok(*all_candidates.first().unwrap().0)
1933-
} else {
1934-
let all_candidates = all_candidates
1935-
.into_iter()
1936-
.filter_map(|(_, candidate)| match candidate {
1937-
LifetimeElisionCandidate::Ignore | LifetimeElisionCandidate::Named => None,
1938-
LifetimeElisionCandidate::Missing(missing) => Some(missing),
1939-
})
1940-
.collect();
1941-
Err((all_candidates, parameter_info))
1942-
}
1976+
// We do not have a candidate.
1977+
Err((all_candidates, parameter_info))
19431978
}
19441979

19451980
/// List all the lifetimes that appear in the provided type.
@@ -2411,7 +2446,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
24112446
// Do not account for the parameters we just bound for function lifetime elision.
24122447
if let Some(ref mut candidates) = self.lifetime_elision_candidates {
24132448
for (_, res) in function_lifetime_rib.bindings.values() {
2414-
candidates.remove(res);
2449+
candidates.retain(|(r, _)| r != res);
24152450
}
24162451
}
24172452

compiler/rustc_resolve/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! Type-relative name resolution (methods, fields, associated items) happens in `rustc_typeck`.
88
99
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
10+
#![feature(assert_matches)]
1011
#![feature(box_patterns)]
1112
#![feature(drain_filter)]
1213
#![feature(if_let_guard)]

0 commit comments

Comments
 (0)