diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index c7fa8e788b57..576267e6948f 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -775,6 +775,10 @@ pub fn build_codegen_backend(builder: &Builder<'_>, cargo.env("CFG_LLVM_ROOT", s); } } + // Some LLVM linker flags (-L and -l) may be needed to link librustc_llvm. + if let Some(ref s) = builder.config.llvm_ldflags { + cargo.env("LLVM_LINKER_FLAGS", s); + } // Building with a static libstdc++ is only supported on linux right now, // not for MSVC or macOS if builder.config.llvm_static_stdcpp && diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index 7fa83dd97795..21fa872c8dad 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -234,6 +234,21 @@ fn main() { } } + // Some LLVM linker flags (-L and -l) may be needed even when linking + // librustc_llvm, for example when using static libc++, we may need to + // manually specify the library search path and -ldl -lpthread as link + // dependencies. + let llvm_linker_flags = env::var_os("LLVM_LINKER_FLAGS"); + if let Some(s) = llvm_linker_flags { + for lib in s.into_string().unwrap().split_whitespace() { + if lib.starts_with("-l") { + println!("cargo:rustc-link-lib={}", &lib[2..]); + } else if lib.starts_with("-L") { + println!("cargo:rustc-link-search=native={}", &lib[2..]); + } + } + } + let llvm_static_stdcpp = env::var_os("LLVM_STATIC_STDCPP"); let llvm_use_libcxx = env::var_os("LLVM_USE_LIBCXX"); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 2c9309a1696c..2f8b45bbcad3 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2157,6 +2157,14 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { /// Returns the `DefId` of the constant parameter that the provided expression is a path to. pub fn const_param_def_id(&self, expr: &hir::Expr) -> Option { + // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments + // currently have to be wrapped in curly brackets, so it's necessary to special-case. + let expr = match &expr.node { + ExprKind::Block(block, _) if block.stmts.is_empty() && block.expr.is_some() => + block.expr.as_ref().unwrap(), + _ => expr, + }; + match &expr.node { ExprKind::Path(hir::QPath::Resolved(_, path)) => match path.res { Res::Def(DefKind::ConstParam, did) => Some(did), @@ -2184,18 +2192,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { ty, }; - let mut expr = &tcx.hir().body(ast_const.body).value; - - // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments - // currently have to be wrapped in curly brackets, so it's necessary to special-case. - if let ExprKind::Block(block, _) = &expr.node { - if block.stmts.is_empty() { - if let Some(trailing) = &block.expr { - expr = &trailing; - } - } - } - + let expr = &tcx.hir().body(ast_const.body).value; if let Some(def_id) = self.const_param_def_id(expr) { // Find the name and index of the const parameter by indexing the generics of the // parent item and construct a `ParamConst`. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d62536ccb466..966ed58a4125 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2208,15 +2208,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.tables.borrow_mut().field_indices_mut().insert(hir_id, index); } + fn write_resolution(&self, hir_id: hir::HirId, r: Result<(DefKind, DefId), ErrorReported>) { + self.tables.borrow_mut().type_dependent_defs_mut().insert(hir_id, r); + } + pub fn write_method_call(&self, hir_id: hir::HirId, method: MethodCallee<'tcx>) { debug!("write_method_call(hir_id={:?}, method={:?})", hir_id, method); - self.tables - .borrow_mut() - .type_dependent_defs_mut() - .insert(hir_id, Ok((DefKind::Method, method.def_id))); - + self.write_resolution(hir_id, Ok((DefKind::Method, method.def_id))); self.write_substs(hir_id, method.substs); // When the method is confirmed, the `method.substs` includes @@ -4724,7 +4724,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let result = result.map(|(_, kind, def_id)| (kind, def_id)); // Write back the new resolution. - self.tables.borrow_mut().type_dependent_defs_mut().insert(hir_id, result); + self.write_resolution(hir_id, result); (result.map(|(kind, def_id)| Res::Def(kind, def_id)).unwrap_or(Res::Err), ty) } @@ -4777,7 +4777,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }); // Write back the new resolution. - self.tables.borrow_mut().type_dependent_defs_mut().insert(hir_id, result); + self.write_resolution(hir_id, result); ( result.map(|(kind, def_id)| Res::Def(kind, def_id)).unwrap_or(Res::Err), Some(ty), diff --git a/src/test/run-pass/async-fn-size.rs b/src/test/run-pass/async-await/async-fn-size.rs similarity index 100% rename from src/test/run-pass/async-fn-size.rs rename to src/test/run-pass/async-await/async-fn-size.rs diff --git a/src/test/run-pass/async-await/issue-60709.rs b/src/test/run-pass/async-await/issue-60709.rs new file mode 100644 index 000000000000..778d3ee0c708 --- /dev/null +++ b/src/test/run-pass/async-await/issue-60709.rs @@ -0,0 +1,28 @@ +// This used to compile the future down to ud2, due to uninhabited types being +// handled incorrectly in generators. +// compile-flags: -Copt-level=z -Cdebuginfo=2 --edition=2018 + +#![feature(async_await, await_macro)] +#![allow(unused)] + +use std::future::Future; +use std::task::Poll; +use std::task::Context; +use std::pin::Pin; +use std::rc::Rc; + +struct Never(); +impl Future for Never { + type Output = (); + fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll { + Poll::Pending + } +} + +fn main() { + let fut = async { + let _rc = Rc::new(()); // Also crashes with Arc + await!(Never()); + }; + let _bla = fut; // Moving the future is required. +} diff --git a/src/test/ui/const-generics/issue-61336-2.rs b/src/test/ui/const-generics/issue-61336-2.rs new file mode 100644 index 000000000000..604c14ee120a --- /dev/null +++ b/src/test/ui/const-generics/issue-61336-2.rs @@ -0,0 +1,16 @@ +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +fn f(x: T) -> [T; N] { + [x; {N}] +} + +fn g(x: T) -> [T; N] { + [x; {N}] + //~^ ERROR the trait bound `T: std::marker::Copy` is not satisfied [E0277] +} + +fn main() { + let x: [u32; 5] = f::(3); + assert_eq!(x, [3u32; 5]); +} diff --git a/src/test/ui/const-generics/issue-61336-2.stderr b/src/test/ui/const-generics/issue-61336-2.stderr new file mode 100644 index 000000000000..a7135b62f8cf --- /dev/null +++ b/src/test/ui/const-generics/issue-61336-2.stderr @@ -0,0 +1,18 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/issue-61336-2.rs:1:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied + --> $DIR/issue-61336-2.rs:9:5 + | +LL | [x; {N}] + | ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T` + | + = help: consider adding a `where T: std::marker::Copy` bound + = note: the `Copy` trait is required because the repeated element will be copied + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/issues/issue-51301.rs b/src/test/ui/issues/issue-51301.rs new file mode 100644 index 000000000000..7e0a5190fcd8 --- /dev/null +++ b/src/test/ui/issues/issue-51301.rs @@ -0,0 +1,35 @@ +use std::any::TypeId; +use std::collections::HashMap; +use std::hash::Hash; + +trait State { + type EventType; + fn get_type_id_of_state(&self) -> TypeId; +} + +struct StateMachine { + current_state: Box>, + transition_table: + HashMap Box>>>, +} + +impl StateMachine { + fn inner_process_event(&mut self, event: EventType) -> Result<(), i8> { + let new_state_creation_function = self + .transition_table + .iter() + .find(|(&event_typeid, _)| event_typeid == self.current_state.get_type_id_of_state()) + .ok_or(1)? + .1 + .iter() + .find(|(&event_type, _)| event == event_type) + //~^ ERROR cannot move out of a shared reference + .ok_or(2)? + .1; + + self.current_state = new_state_creation_function(); + Ok(()) + } +} + +fn main() {} diff --git a/src/test/ui/issues/issue-51301.stderr b/src/test/ui/issues/issue-51301.stderr new file mode 100644 index 000000000000..f3decf7a9913 --- /dev/null +++ b/src/test/ui/issues/issue-51301.stderr @@ -0,0 +1,12 @@ +error[E0507]: cannot move out of a shared reference + --> $DIR/issue-51301.rs:25:20 + | +LL | .find(|(&event_type, _)| event == event_type) + | ^^----------^^^^ + | | + | data moved here + | move occurs because `event_type` has type `EventType`, which does not implement the `Copy` trait + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0507`.