Skip to content

Commit fd2c811

Browse files
committedSep 16, 2024
Auto merge of #130439 - matthiaskrgr:rollup-1lkzo74, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #123436 (linker: Allow MSVC to use import libraries following the Meson/MinGW convention) - #130410 (Don't ICE when generating `Fn` shim for async closure with borrowck error) - #130412 (Don't ICE when RPITIT captures more method args than trait definition) - #130436 (Ignore reduce-fadd-unordered on SGX platform) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3a22be3 + 1807fda commit fd2c811

File tree

12 files changed

+161
-26
lines changed

12 files changed

+161
-26
lines changed
 

‎compiler/rustc_codegen_ssa/src/back/linker.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use std::{env, iter, mem, str};
77

88
use cc::windows_registry;
99
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
10-
use rustc_metadata::{find_native_static_library, try_find_native_static_library};
10+
use rustc_metadata::{
11+
find_native_static_library, try_find_native_dynamic_library, try_find_native_static_library,
12+
};
1113
use rustc_middle::bug;
1214
use rustc_middle::middle::dependency_format::Linkage;
1315
use rustc_middle::middle::exported_symbols;
@@ -876,7 +878,13 @@ impl<'a> Linker for MsvcLinker<'a> {
876878
}
877879

878880
fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, _as_needed: bool) {
879-
self.link_arg(format!("{}{}", name, if verbatim { "" } else { ".lib" }));
881+
// On MSVC-like targets rustc supports import libraries using alternative naming
882+
// scheme (`libfoo.a`) unsupported by linker, search for such libraries manually.
883+
if let Some(path) = try_find_native_dynamic_library(self.sess, name, verbatim) {
884+
self.link_arg(path);
885+
} else {
886+
self.link_arg(format!("{}{}", name, if verbatim { "" } else { ".lib" }));
887+
}
880888
}
881889

882890
fn link_dylib_by_path(&mut self, path: &Path, _as_needed: bool) {

‎compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
726726
num_trait_args,
727727
num_impl_args,
728728
def_id,
729-
impl_def_id: impl_m.container_id(tcx),
729+
impl_m_def_id: impl_m.def_id,
730730
ty,
731731
return_span,
732732
}) {
@@ -844,12 +844,18 @@ where
844844

845845
struct RemapHiddenTyRegions<'tcx> {
846846
tcx: TyCtxt<'tcx>,
847+
/// Map from early/late params of the impl to identity regions of the RPITIT (GAT)
848+
/// in the trait.
847849
map: FxIndexMap<ty::Region<'tcx>, ty::Region<'tcx>>,
848850
num_trait_args: usize,
849851
num_impl_args: usize,
852+
/// Def id of the RPITIT (GAT) in the *trait*.
850853
def_id: DefId,
851-
impl_def_id: DefId,
854+
/// Def id of the impl method which owns the opaque hidden type we're remapping.
855+
impl_m_def_id: DefId,
856+
/// The hidden type we're remapping. Useful for diagnostics.
852857
ty: Ty<'tcx>,
858+
/// Span of the return type. Useful for diagnostics.
853859
return_span: Span,
854860
}
855861

@@ -885,8 +891,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
885891
ty::ReLateParam(_) => {}
886892
// Remap early-bound regions as long as they don't come from the `impl` itself,
887893
// in which case we don't really need to renumber them.
888-
ty::ReEarlyParam(ebr)
889-
if ebr.index >= self.tcx.generics_of(self.impl_def_id).count() as u32 => {}
894+
ty::ReEarlyParam(ebr) if ebr.index as usize >= self.num_impl_args => {}
890895
_ => return Ok(region),
891896
}
892897

@@ -899,7 +904,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
899904
);
900905
}
901906
} else {
902-
let guar = match region.opt_param_def_id(self.tcx, self.tcx.parent(self.def_id)) {
907+
let guar = match region.opt_param_def_id(self.tcx, self.impl_m_def_id) {
903908
Some(def_id) => {
904909
let return_span = if let ty::Alias(ty::Opaque, opaque_ty) = self.ty.kind() {
905910
self.tcx.def_span(opaque_ty.def_id)

‎compiler/rustc_metadata/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ pub mod locator;
3737
pub use creader::{load_symbol_from_dylib, DylibError};
3838
pub use fs::{emit_wrapper_file, METADATA_FILENAME};
3939
pub use native_libs::{
40-
find_native_static_library, try_find_native_static_library, walk_native_lib_search_dirs,
40+
find_native_static_library, try_find_native_dynamic_library, try_find_native_static_library,
41+
walk_native_lib_search_dirs,
4142
};
4243
pub use rmeta::{encode_metadata, rendered_const, EncodedMetadata, METADATA_HEADER};
4344

‎compiler/rustc_metadata/src/native_libs.rs

+38
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,44 @@ pub fn try_find_native_static_library(
109109
.break_value()
110110
}
111111

112+
pub fn try_find_native_dynamic_library(
113+
sess: &Session,
114+
name: &str,
115+
verbatim: bool,
116+
) -> Option<PathBuf> {
117+
let formats = if verbatim {
118+
vec![("".into(), "".into())]
119+
} else {
120+
// While the official naming convention for MSVC import libraries
121+
// is foo.lib...
122+
let os = (sess.target.staticlib_prefix.clone(), sess.target.staticlib_suffix.clone());
123+
// ... Meson follows the libfoo.dll.a convention to
124+
// disambiguate .a for static libraries
125+
let meson = ("lib".into(), ".dll.a".into());
126+
// and MinGW uses .a altogether
127+
let mingw = ("lib".into(), ".a".into());
128+
vec![os, meson, mingw]
129+
};
130+
131+
walk_native_lib_search_dirs(
132+
sess,
133+
LinkSelfContainedComponents::empty(),
134+
None,
135+
|dir, is_framework| {
136+
if !is_framework {
137+
for (prefix, suffix) in &formats {
138+
let test = dir.join(format!("{prefix}{name}{suffix}"));
139+
if test.exists() {
140+
return ControlFlow::Break(test);
141+
}
142+
}
143+
}
144+
ControlFlow::Continue(())
145+
},
146+
)
147+
.break_value()
148+
}
149+
112150
pub fn find_native_static_library(name: &str, verbatim: bool, sess: &Session) -> PathBuf {
113151
try_find_native_static_library(sess, name, verbatim)
114152
.unwrap_or_else(|| sess.dcx().emit_fatal(errors::MissingNativeLibrary::new(name, verbatim)))

‎compiler/rustc_middle/src/ty/generics.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ impl<'tcx> Generics {
255255
let param = self.param_at(param.index as usize, tcx);
256256
match param.kind {
257257
GenericParamDefKind::Lifetime => param,
258-
_ => bug!("expected lifetime parameter, but found another generic parameter"),
258+
_ => {
259+
bug!("expected lifetime parameter, but found another generic parameter: {param:#?}")
260+
}
259261
}
260262
}
261263

@@ -264,7 +266,7 @@ impl<'tcx> Generics {
264266
let param = self.param_at(param.index as usize, tcx);
265267
match param.kind {
266268
GenericParamDefKind::Type { .. } => param,
267-
_ => bug!("expected type parameter, but found another generic parameter"),
269+
_ => bug!("expected type parameter, but found another generic parameter: {param:#?}"),
268270
}
269271
}
270272

@@ -273,7 +275,7 @@ impl<'tcx> Generics {
273275
let param = self.param_at(param.index as usize, tcx);
274276
match param.kind {
275277
GenericParamDefKind::Const { .. } => param,
276-
_ => bug!("expected const parameter, but found another generic parameter"),
278+
_ => bug!("expected const parameter, but found another generic parameter: {param:#?}"),
277279
}
278280
}
279281

‎compiler/rustc_mir_transform/src/shim.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -1070,19 +1070,26 @@ fn build_construct_coroutine_by_move_shim<'tcx>(
10701070
let locals = local_decls_for_sig(&sig, span);
10711071

10721072
let mut fields = vec![];
1073+
1074+
// Move all of the closure args.
10731075
for idx in 1..sig.inputs().len() {
10741076
fields.push(Operand::Move(Local::from_usize(idx + 1).into()));
10751077
}
1078+
10761079
for (idx, ty) in args.as_coroutine_closure().upvar_tys().iter().enumerate() {
10771080
if receiver_by_ref {
10781081
// The only situation where it's possible is when we capture immuatable references,
10791082
// since those don't need to be reborrowed with the closure's env lifetime. Since
10801083
// references are always `Copy`, just emit a copy.
1081-
assert_matches!(
1082-
ty.kind(),
1083-
ty::Ref(_, _, hir::Mutability::Not),
1084-
"field should be captured by immutable ref if we have an `Fn` instance"
1085-
);
1084+
if !matches!(ty.kind(), ty::Ref(_, _, hir::Mutability::Not)) {
1085+
// This copy is only sound if it's a `&T`. This may be
1086+
// reachable e.g. when eagerly computing the `Fn` instance
1087+
// of an async closure that doesn't borrowck.
1088+
tcx.dcx().delayed_bug(format!(
1089+
"field should be captured by immutable ref if we have \
1090+
an `Fn` instance, but it was: {ty}"
1091+
));
1092+
}
10861093
fields.push(Operand::Copy(tcx.mk_place_field(
10871094
self_local,
10881095
FieldIdx::from_usize(idx),

‎tests/assembly/simd/reduce-fadd-unordered.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//@[aarch64] only-aarch64
55
//@[x86_64] only-x86_64
66
//@[x86_64] compile-flags: -Ctarget-feature=+sse3
7+
//@ ignore-sgx Test incompatible with LVI mitigations
78
#![feature(portable_simd)]
89
#![feature(core_intrinsics)]
910
use std::intrinsics::simd as intrinsics;

‎tests/crashes/129850.rs

-9
This file was deleted.

‎tests/crashes/129262.rs ‎tests/ui/async-await/async-closures/closure-shim-borrowck-error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ known-bug: rust-lang/rust#129262
21
//@ compile-flags: -Zvalidate-mir --edition=2018 --crate-type=lib -Copt-level=3
32

43
#![feature(async_closure)]
@@ -11,6 +10,7 @@ fn needs_fn_mut<T>(mut x: impl FnMut() -> T) {
1110

1211
fn hello(x: Ty) {
1312
needs_fn_mut(async || {
13+
//~^ ERROR cannot move out of `x`
1414
x.hello();
1515
});
1616
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0507]: cannot move out of `x` which is behind a mutable reference
2+
--> $DIR/closure-shim-borrowck-error.rs:12:18
3+
|
4+
LL | needs_fn_mut(async || {
5+
| ^^^^^^^^ `x` is moved here
6+
LL |
7+
LL | x.hello();
8+
| -
9+
| |
10+
| variable moved due to use in coroutine
11+
| move occurs because `x` has type `Ty`, which does not implement the `Copy` trait
12+
|
13+
note: if `Ty` implemented `Clone`, you could clone the value
14+
--> $DIR/closure-shim-borrowck-error.rs:18:1
15+
|
16+
LL | x.hello();
17+
| - you could clone this value
18+
...
19+
LL | struct Ty;
20+
| ^^^^^^^^^ consider implementing `Clone` for this type
21+
22+
error: aborting due to 1 previous error
23+
24+
For more information about this error, try `rustc --explain E0507`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Make sure we don't ICE when an RPITIT captures more method args than the
2+
// trait definition, which is not allowed. Due to the default lifetime capture
3+
// rules of RPITITs, this is only doable if we use precise capturing.
4+
5+
pub trait Foo {
6+
fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>;
7+
//~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
8+
}
9+
10+
impl Foo for () {
11+
fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {}
12+
//~^ ERROR return type captures more lifetimes than trait definition
13+
//~| WARN impl trait in impl method signature does not match trait method signature
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
2+
--> $DIR/rpitit-captures-more-method-lifetimes.rs:6:53
3+
|
4+
LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>;
5+
| ^^^^^^^^^
6+
|
7+
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
8+
9+
error: return type captures more lifetimes than trait definition
10+
--> $DIR/rpitit-captures-more-method-lifetimes.rs:11:40
11+
|
12+
LL | fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {}
13+
| --- ^^^^^^^^^^^^^^^^
14+
| |
15+
| this lifetime was captured
16+
|
17+
note: hidden type must only reference lifetimes captured by this impl trait
18+
--> $DIR/rpitit-captures-more-method-lifetimes.rs:6:40
19+
|
20+
LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>;
21+
| ^^^^^^^^^^^^^^^^^^^^^^
22+
= note: hidden type inferred to be `impl Sized + 'im`
23+
24+
warning: impl trait in impl method signature does not match trait method signature
25+
--> $DIR/rpitit-captures-more-method-lifetimes.rs:11:40
26+
|
27+
LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>;
28+
| ---------------------- return type from trait method defined here
29+
...
30+
LL | fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {}
31+
| ^^^^^^^^^^^^^^^^
32+
|
33+
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
34+
= note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
35+
= note: `#[warn(refining_impl_trait_reachable)]` on by default
36+
help: replace the return type so that it matches the trait
37+
|
38+
LL | fn bar<'im: 'im>(&'im mut self) -> impl Sized {}
39+
| ~~~~~~~~~~
40+
41+
error: aborting due to 2 previous errors; 1 warning emitted
42+

0 commit comments

Comments
 (0)
Please sign in to comment.