Skip to content

Commit 53f8635

Browse files
committed
Auto merge of #61819 - Centril:rollup-k2gprnz, r=Centril
Rollup of 5 pull requests Successful merges: - #61704 (Pass LLVM linker flags to librustc_llvm build) - #61792 (Add ui test for issue 51301) - #61803 (typeck: small refactoring, add 'fn write_resolution') - #61805 (typeck: Fix ICE for blocks in repeat expr count.) - #61818 (Issue #60709 test) Failed merges: r? @ghost
2 parents cdd7437 + 9b91bec commit 53f8635

File tree

10 files changed

+144
-19
lines changed

10 files changed

+144
-19
lines changed

src/bootstrap/compile.rs

+4
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,10 @@ pub fn build_codegen_backend(builder: &Builder<'_>,
775775
cargo.env("CFG_LLVM_ROOT", s);
776776
}
777777
}
778+
// Some LLVM linker flags (-L and -l) may be needed to link librustc_llvm.
779+
if let Some(ref s) = builder.config.llvm_ldflags {
780+
cargo.env("LLVM_LINKER_FLAGS", s);
781+
}
778782
// Building with a static libstdc++ is only supported on linux right now,
779783
// not for MSVC or macOS
780784
if builder.config.llvm_static_stdcpp &&

src/librustc_llvm/build.rs

+15
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,21 @@ fn main() {
234234
}
235235
}
236236

237+
// Some LLVM linker flags (-L and -l) may be needed even when linking
238+
// librustc_llvm, for example when using static libc++, we may need to
239+
// manually specify the library search path and -ldl -lpthread as link
240+
// dependencies.
241+
let llvm_linker_flags = env::var_os("LLVM_LINKER_FLAGS");
242+
if let Some(s) = llvm_linker_flags {
243+
for lib in s.into_string().unwrap().split_whitespace() {
244+
if lib.starts_with("-l") {
245+
println!("cargo:rustc-link-lib={}", &lib[2..]);
246+
} else if lib.starts_with("-L") {
247+
println!("cargo:rustc-link-search=native={}", &lib[2..]);
248+
}
249+
}
250+
}
251+
237252
let llvm_static_stdcpp = env::var_os("LLVM_STATIC_STDCPP");
238253
let llvm_use_libcxx = env::var_os("LLVM_USE_LIBCXX");
239254

src/librustc_typeck/astconv.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,14 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
21572157

21582158
/// Returns the `DefId` of the constant parameter that the provided expression is a path to.
21592159
pub fn const_param_def_id(&self, expr: &hir::Expr) -> Option<DefId> {
2160+
// Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
2161+
// currently have to be wrapped in curly brackets, so it's necessary to special-case.
2162+
let expr = match &expr.node {
2163+
ExprKind::Block(block, _) if block.stmts.is_empty() && block.expr.is_some() =>
2164+
block.expr.as_ref().unwrap(),
2165+
_ => expr,
2166+
};
2167+
21602168
match &expr.node {
21612169
ExprKind::Path(hir::QPath::Resolved(_, path)) => match path.res {
21622170
Res::Def(DefKind::ConstParam, did) => Some(did),
@@ -2184,18 +2192,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
21842192
ty,
21852193
};
21862194

2187-
let mut expr = &tcx.hir().body(ast_const.body).value;
2188-
2189-
// Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
2190-
// currently have to be wrapped in curly brackets, so it's necessary to special-case.
2191-
if let ExprKind::Block(block, _) = &expr.node {
2192-
if block.stmts.is_empty() {
2193-
if let Some(trailing) = &block.expr {
2194-
expr = &trailing;
2195-
}
2196-
}
2197-
}
2198-
2195+
let expr = &tcx.hir().body(ast_const.body).value;
21992196
if let Some(def_id) = self.const_param_def_id(expr) {
22002197
// Find the name and index of the const parameter by indexing the generics of the
22012198
// parent item and construct a `ParamConst`.

src/librustc_typeck/check/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2208,15 +2208,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
22082208
self.tables.borrow_mut().field_indices_mut().insert(hir_id, index);
22092209
}
22102210

2211+
fn write_resolution(&self, hir_id: hir::HirId, r: Result<(DefKind, DefId), ErrorReported>) {
2212+
self.tables.borrow_mut().type_dependent_defs_mut().insert(hir_id, r);
2213+
}
2214+
22112215
pub fn write_method_call(&self,
22122216
hir_id: hir::HirId,
22132217
method: MethodCallee<'tcx>) {
22142218
debug!("write_method_call(hir_id={:?}, method={:?})", hir_id, method);
2215-
self.tables
2216-
.borrow_mut()
2217-
.type_dependent_defs_mut()
2218-
.insert(hir_id, Ok((DefKind::Method, method.def_id)));
2219-
2219+
self.write_resolution(hir_id, Ok((DefKind::Method, method.def_id)));
22202220
self.write_substs(hir_id, method.substs);
22212221

22222222
// When the method is confirmed, the `method.substs` includes
@@ -4724,7 +4724,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
47244724
let result = result.map(|(_, kind, def_id)| (kind, def_id));
47254725

47264726
// Write back the new resolution.
4727-
self.tables.borrow_mut().type_dependent_defs_mut().insert(hir_id, result);
4727+
self.write_resolution(hir_id, result);
47284728

47294729
(result.map(|(kind, def_id)| Res::Def(kind, def_id)).unwrap_or(Res::Err), ty)
47304730
}
@@ -4777,7 +4777,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
47774777
});
47784778

47794779
// Write back the new resolution.
4780-
self.tables.borrow_mut().type_dependent_defs_mut().insert(hir_id, result);
4780+
self.write_resolution(hir_id, result);
47814781
(
47824782
result.map(|(kind, def_id)| Res::Def(kind, def_id)).unwrap_or(Res::Err),
47834783
Some(ty),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This used to compile the future down to ud2, due to uninhabited types being
2+
// handled incorrectly in generators.
3+
// compile-flags: -Copt-level=z -Cdebuginfo=2 --edition=2018
4+
5+
#![feature(async_await, await_macro)]
6+
#![allow(unused)]
7+
8+
use std::future::Future;
9+
use std::task::Poll;
10+
use std::task::Context;
11+
use std::pin::Pin;
12+
use std::rc::Rc;
13+
14+
struct Never();
15+
impl Future for Never {
16+
type Output = ();
17+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
18+
Poll::Pending
19+
}
20+
}
21+
22+
fn main() {
23+
let fut = async {
24+
let _rc = Rc::new(()); // Also crashes with Arc
25+
await!(Never());
26+
};
27+
let _bla = fut; // Moving the future is required.
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(const_generics)]
2+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
4+
fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
5+
[x; {N}]
6+
}
7+
8+
fn g<T, const N: usize>(x: T) -> [T; N] {
9+
[x; {N}]
10+
//~^ ERROR the trait bound `T: std::marker::Copy` is not satisfied [E0277]
11+
}
12+
13+
fn main() {
14+
let x: [u32; 5] = f::<u32, 5>(3);
15+
assert_eq!(x, [3u32; 5]);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/issue-61336-2.rs:1:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
7+
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
8+
--> $DIR/issue-61336-2.rs:9:5
9+
|
10+
LL | [x; {N}]
11+
| ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
12+
|
13+
= help: consider adding a `where T: std::marker::Copy` bound
14+
= note: the `Copy` trait is required because the repeated element will be copied
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/issues/issue-51301.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::any::TypeId;
2+
use std::collections::HashMap;
3+
use std::hash::Hash;
4+
5+
trait State {
6+
type EventType;
7+
fn get_type_id_of_state(&self) -> TypeId;
8+
}
9+
10+
struct StateMachine<EventType: Hash + Eq> {
11+
current_state: Box<dyn State<EventType = EventType>>,
12+
transition_table:
13+
HashMap<TypeId, HashMap<EventType, fn() -> Box<dyn State<EventType = EventType>>>>,
14+
}
15+
16+
impl<EventType: Hash + Eq> StateMachine<EventType> {
17+
fn inner_process_event(&mut self, event: EventType) -> Result<(), i8> {
18+
let new_state_creation_function = self
19+
.transition_table
20+
.iter()
21+
.find(|(&event_typeid, _)| event_typeid == self.current_state.get_type_id_of_state())
22+
.ok_or(1)?
23+
.1
24+
.iter()
25+
.find(|(&event_type, _)| event == event_type)
26+
//~^ ERROR cannot move out of a shared reference
27+
.ok_or(2)?
28+
.1;
29+
30+
self.current_state = new_state_creation_function();
31+
Ok(())
32+
}
33+
}
34+
35+
fn main() {}

src/test/ui/issues/issue-51301.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0507]: cannot move out of a shared reference
2+
--> $DIR/issue-51301.rs:25:20
3+
|
4+
LL | .find(|(&event_type, _)| event == event_type)
5+
| ^^----------^^^^
6+
| |
7+
| data moved here
8+
| move occurs because `event_type` has type `EventType`, which does not implement the `Copy` trait
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0507`.

0 commit comments

Comments
 (0)