Skip to content

Commit 99f967e

Browse files
committedMar 14, 2022
Auto merge of rust-lang#94933 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backports * Update LLVM submodule rust-lang#94764 * Statically compile libstdc++ everywhere if asked rust-lang#94719 * Downgrade #[test] on macro call to warning rust-lang#94624 * Delay bug in expr adjustment when check_expr is called multiple times rust-lang#94596 * bootstrap: correct reading of flags for llvm rust-lang#94466 * Check method input expressions once rust-lang#94438 * remove feature gate in control_flow examples rust-lang#94283 r? `@Mark-Simulacrum`
2 parents e5effbd + 12cae30 commit 99f967e

27 files changed

+207
-104
lines changed
 

‎compiler/rustc_builtin_macros/src/test.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,15 @@ pub fn expand_test_or_bench(
105105

106106
// Note: non-associated fn items are already handled by `expand_test_or_bench`
107107
if !matches!(item.kind, ast::ItemKind::Fn(_)) {
108-
cx.sess
109-
.parse_sess
110-
.span_diagnostic
111-
.struct_span_err(
112-
attr_sp,
113-
"the `#[test]` attribute may only be used on a non-associated function",
114-
)
115-
.note("the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions")
108+
let diag = &cx.sess.parse_sess.span_diagnostic;
109+
let msg = "the `#[test]` attribute may only be used on a non-associated function";
110+
let mut err = match item.kind {
111+
// These were a warning before #92959 and need to continue being that to avoid breaking
112+
// stable user code (#94508).
113+
ast::ItemKind::MacCall(_) => diag.struct_span_warn(attr_sp, msg),
114+
_ => diag.struct_span_err(attr_sp, msg),
115+
};
116+
err.span_label(attr_sp, "the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions")
116117
.span_label(item.span, format!("expected a non-associated function, found {} {}", item.kind.article(), item.kind.descr()))
117118
.span_suggestion(attr_sp, "replace with conditional compilation to make the item only exist when tests are being run", String::from("#[cfg(test)]"), Applicability::MaybeIncorrect)
118119
.emit();

‎compiler/rustc_codegen_llvm/src/llvm_util.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ pub(crate) fn should_use_new_llvm_pass_manager(user_opt: &Option<bool>, target_a
475475
// The new pass manager is enabled by default for LLVM >= 13.
476476
// This matches Clang, which also enables it since Clang 13.
477477

478-
// FIXME: There are some perf issues with the new pass manager
479-
// when targeting s390x, so it is temporarily disabled for that
480-
// arch, see https://github.com/rust-lang/rust/issues/89609
481-
user_opt.unwrap_or_else(|| target_arch != "s390x" && llvm_util::get_version() >= (13, 0, 0))
478+
// There are some perf issues with the new pass manager when targeting
479+
// s390x with LLVM 13, so enable the new pass manager only with LLVM 14.
480+
// See https://github.com/rust-lang/rust/issues/89609.
481+
let min_version = if target_arch == "s390x" { 14 } else { 13 };
482+
user_opt.unwrap_or_else(|| llvm_util::get_version() >= (min_version, 0, 0))
482483
}

‎compiler/rustc_typeck/src/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
475475
_ => return None,
476476
};
477477

478-
let self_ty = self.typeck_results.borrow().node_type(method_expr[0].hir_id);
478+
let self_ty = self.typeck_results.borrow().expr_ty(&method_expr[0]);
479479
let self_ty = format!("{:?}", self_ty);
480480
let name = method_path.ident.name;
481481
let is_as_ref_able = (self_ty.starts_with("&std::option::Option")

‎compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15071507
}
15081508
} else {
15091509
self.check_expr_has_type_or_error(base_expr, adt_ty, |_| {
1510-
let base_ty = self.typeck_results.borrow().node_type(base_expr.hir_id);
1510+
let base_ty = self.typeck_results.borrow().expr_ty(*base_expr);
15111511
let same_adt = match (adt_ty.kind(), base_ty.kind()) {
15121512
(ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt => true,
15131513
_ => false,

‎compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
315315
}
316316
// FIXME: currently we never try to compose autoderefs
317317
// and ReifyFnPointer/UnsafeFnPointer, but we could.
318-
_ => bug!(
319-
"while adjusting {:?}, can't compose {:?} and {:?}",
320-
expr,
321-
entry.get(),
322-
adj
318+
_ => self.tcx.sess.delay_span_bug(
319+
expr.span,
320+
&format!(
321+
"while adjusting {:?}, can't compose {:?} and {:?}",
322+
expr,
323+
entry.get(),
324+
adj
325+
),
323326
),
324327
};
325328
*entry.get_mut() = adj;

‎compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
133133
let expected_arg_count = formal_input_tys.len();
134134

135135
// expected_count, arg_count, error_code, sugg_unit, sugg_tuple_wrap_args
136-
let mut error: Option<(usize, usize, &str, bool, Option<FnArgsAsTuple<'_>>)> = None;
136+
let mut arg_count_error: Option<(usize, usize, &str, bool, Option<FnArgsAsTuple<'_>>)> =
137+
None;
137138

138139
// If the arguments should be wrapped in a tuple (ex: closures), unwrap them here
139140
let (formal_input_tys, expected_input_tys) = if tuple_arguments == TupleArguments {
@@ -143,7 +144,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
143144
ty::Tuple(arg_types) => {
144145
// Argument length differs
145146
if arg_types.len() != provided_args.len() {
146-
error = Some((arg_types.len(), provided_args.len(), "E0057", false, None));
147+
arg_count_error =
148+
Some((arg_types.len(), provided_args.len(), "E0057", false, None));
147149
}
148150
let expected_input_tys = match expected_input_tys.get(0) {
149151
Some(&ty) => match ty.kind() {
@@ -174,7 +176,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
174176
if supplied_arg_count >= expected_arg_count {
175177
(formal_input_tys.to_vec(), expected_input_tys)
176178
} else {
177-
error = Some((expected_arg_count, supplied_arg_count, "E0060", false, None));
179+
arg_count_error =
180+
Some((expected_arg_count, supplied_arg_count, "E0060", false, None));
178181
(self.err_args(supplied_arg_count), vec![])
179182
}
180183
} else {
@@ -198,7 +201,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
198201

199202
let sugg_tuple_wrap_args = self.suggested_tuple_wrap(expected_input_tys, provided_args);
200203

201-
error = Some((
204+
arg_count_error = Some((
202205
expected_arg_count,
203206
supplied_arg_count,
204207
"E0061",
@@ -231,6 +234,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
231234
// This is more complicated than just checking type equality, as arguments could be coerced
232235
// This version writes those types back so further type checking uses the narrowed types
233236
let demand_compatible = |idx, final_arg_types: &mut Vec<Option<(Ty<'tcx>, Ty<'tcx>)>>| {
237+
// Do not check argument compatibility if the number of args do not match
238+
if arg_count_error.is_some() {
239+
return;
240+
}
241+
234242
let formal_input_ty: Ty<'tcx> = formal_input_tys[idx];
235243
let expected_input_ty: Ty<'tcx> = expected_input_tys[idx];
236244
let provided_arg = &provided_args[idx];
@@ -328,7 +336,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
328336
}
329337

330338
// If there was an error in parameter count, emit that here
331-
if let Some((expected_count, arg_count, err_code, sugg_unit, sugg_tuple_wrap_args)) = error
339+
if let Some((expected_count, arg_count, err_code, sugg_unit, sugg_tuple_wrap_args)) =
340+
arg_count_error
332341
{
333342
let (span, start_span, args, ctor_of) = match &call_expr.kind {
334343
hir::ExprKind::Call(

‎library/core/src/ops/control_flow.rs

-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ impl<B, C> ControlFlow<B, C> {
134134
/// # Examples
135135
///
136136
/// ```
137-
/// #![feature(control_flow_enum)]
138137
/// use std::ops::ControlFlow;
139138
///
140139
/// assert!(ControlFlow::<i32, String>::Break(3).is_break());
@@ -151,7 +150,6 @@ impl<B, C> ControlFlow<B, C> {
151150
/// # Examples
152151
///
153152
/// ```
154-
/// #![feature(control_flow_enum)]
155153
/// use std::ops::ControlFlow;
156154
///
157155
/// assert!(!ControlFlow::<i32, String>::Break(3).is_continue());

‎src/bootstrap/builder.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::run;
2626
use crate::test;
2727
use crate::tool::{self, SourceType};
2828
use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir};
29-
use crate::{Build, DocTests, GitRepo, Mode};
29+
use crate::{Build, CLang, DocTests, GitRepo, Mode};
3030

3131
pub use crate::Compiler;
3232
// FIXME: replace with std::lazy after it gets stabilized and reaches beta
@@ -1511,7 +1511,7 @@ impl<'a> Builder<'a> {
15111511
let cc = ccacheify(&self.cc(target));
15121512
cargo.env(format!("CC_{}", target.triple), &cc);
15131513

1514-
let cflags = self.cflags(target, GitRepo::Rustc).join(" ");
1514+
let cflags = self.cflags(target, GitRepo::Rustc, CLang::C).join(" ");
15151515
cargo.env(format!("CFLAGS_{}", target.triple), &cflags);
15161516

15171517
if let Some(ar) = self.ar(target) {
@@ -1523,9 +1523,10 @@ impl<'a> Builder<'a> {
15231523

15241524
if let Ok(cxx) = self.cxx(target) {
15251525
let cxx = ccacheify(&cxx);
1526+
let cxxflags = self.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" ");
15261527
cargo
15271528
.env(format!("CXX_{}", target.triple), &cxx)
1528-
.env(format!("CXXFLAGS_{}", target.triple), cflags);
1529+
.env(format!("CXXFLAGS_{}", target.triple), cxxflags);
15291530
}
15301531
}
15311532

‎src/bootstrap/cc_detect.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::{env, iter};
2929
use build_helper::output;
3030

3131
use crate::config::{Target, TargetSelection};
32-
use crate::{Build, GitRepo};
32+
use crate::{Build, CLang, GitRepo};
3333

3434
// The `cc` crate doesn't provide a way to obtain a path to the detected archiver,
3535
// so use some simplified logic here. First we respect the environment variable `AR`, then
@@ -109,7 +109,7 @@ pub fn find(build: &mut Build) {
109109
};
110110

111111
build.cc.insert(target, compiler.clone());
112-
let cflags = build.cflags(target, GitRepo::Rustc);
112+
let cflags = build.cflags(target, GitRepo::Rustc, CLang::C);
113113

114114
// If we use llvm-libunwind, we will need a C++ compiler as well for all targets
115115
// We'll need one anyways if the target triple is also a host triple
@@ -142,8 +142,9 @@ pub fn find(build: &mut Build) {
142142
build.verbose(&format!("CC_{} = {:?}", &target.triple, build.cc(target)));
143143
build.verbose(&format!("CFLAGS_{} = {:?}", &target.triple, cflags));
144144
if let Ok(cxx) = build.cxx(target) {
145+
let cxxflags = build.cflags(target, GitRepo::Rustc, CLang::Cxx);
145146
build.verbose(&format!("CXX_{} = {:?}", &target.triple, cxx));
146-
build.verbose(&format!("CXXFLAGS_{} = {:?}", &target.triple, cflags));
147+
build.verbose(&format!("CXXFLAGS_{} = {:?}", &target.triple, cxxflags));
147148
}
148149
if let Some(ar) = ar {
149150
build.verbose(&format!("AR_{} = {:?}", &target.triple, ar));

‎src/bootstrap/compile.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::native;
2929
use crate::tool::SourceType;
3030
use crate::util::{exe, is_debug_info, is_dylib, symlink_dir};
3131
use crate::LLVM_TOOLS;
32-
use crate::{Compiler, DependencyType, GitRepo, Mode};
32+
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode};
3333

3434
#[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)]
3535
pub struct Std {
@@ -250,7 +250,7 @@ fn copy_self_contained_objects(
250250
}
251251
} else if target.contains("windows-gnu") {
252252
for obj in ["crt2.o", "dllcrt2.o"].iter() {
253-
let src = compiler_file(builder, builder.cc(target), target, obj);
253+
let src = compiler_file(builder, builder.cc(target), target, CLang::C, obj);
254254
let target = libdir_self_contained.join(obj);
255255
builder.copy(&src, &target);
256256
target_deps.push((target, DependencyType::TargetSelfContained));
@@ -724,7 +724,13 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
724724
&& !target.contains("msvc")
725725
&& !target.contains("apple")
726726
{
727-
let file = compiler_file(builder, builder.cxx(target).unwrap(), target, "libstdc++.a");
727+
let file = compiler_file(
728+
builder,
729+
builder.cxx(target).unwrap(),
730+
target,
731+
CLang::Cxx,
732+
"libstdc++.a",
733+
);
728734
cargo.env("LLVM_STATIC_STDCPP", file);
729735
}
730736
if builder.config.llvm_link_shared {
@@ -945,10 +951,11 @@ pub fn compiler_file(
945951
builder: &Builder<'_>,
946952
compiler: &Path,
947953
target: TargetSelection,
954+
c: CLang,
948955
file: &str,
949956
) -> PathBuf {
950957
let mut cmd = Command::new(compiler);
951-
cmd.args(builder.cflags(target, GitRepo::Rustc));
958+
cmd.args(builder.cflags(target, GitRepo::Rustc, c));
952959
cmd.arg(format!("-print-file-name={}", file));
953960
let out = output(&mut cmd);
954961
PathBuf::from(out.trim())

‎src/bootstrap/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ impl Mode {
338338
}
339339
}
340340

341+
pub enum CLang {
342+
C,
343+
Cxx,
344+
}
345+
341346
impl Build {
342347
/// Creates a new set of build configuration from the `flags` on the command
343348
/// line and the filesystem `config`.
@@ -940,10 +945,15 @@ impl Build {
940945

941946
/// Returns a list of flags to pass to the C compiler for the target
942947
/// specified.
943-
fn cflags(&self, target: TargetSelection, which: GitRepo) -> Vec<String> {
948+
fn cflags(&self, target: TargetSelection, which: GitRepo, c: CLang) -> Vec<String> {
949+
let base = match c {
950+
CLang::C => &self.cc[&target],
951+
CLang::Cxx => &self.cxx[&target],
952+
};
953+
944954
// Filter out -O and /O (the optimization flags) that we picked up from
945955
// cc-rs because the build scripts will determine that for themselves.
946-
let mut base = self.cc[&target]
956+
let mut base = base
947957
.args()
948958
.iter()
949959
.map(|s| s.to_string_lossy().into_owned())

‎src/bootstrap/native.rs

+26-24
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use build_helper::{output, t};
2121
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
2222
use crate::config::TargetSelection;
2323
use crate::util::{self, exe};
24-
use crate::GitRepo;
24+
use crate::{CLang, GitRepo};
2525
use build_helper::up_to_date;
2626

2727
pub struct Meta {
@@ -262,18 +262,6 @@ impl Step for Llvm {
262262
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
263263
}
264264

265-
// For distribution we want the LLVM tools to be *statically* linked to libstdc++.
266-
// We also do this if the user explicitly requested static libstdc++.
267-
if builder.config.llvm_tools_enabled || builder.config.llvm_static_stdcpp {
268-
if !target.contains("msvc") && !target.contains("netbsd") {
269-
if target.contains("apple") {
270-
ldflags.push_all("-static-libstdc++");
271-
} else {
272-
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
273-
}
274-
}
275-
}
276-
277265
if target.starts_with("riscv") && !target.contains("freebsd") {
278266
// RISC-V GCC erroneously requires linking against
279267
// `libatomic` when using 1-byte and 2-byte C++
@@ -529,7 +517,7 @@ fn configure_cmake(
529517
}
530518

531519
cfg.build_arg("-j").build_arg(builder.jobs().to_string());
532-
let mut cflags: OsString = builder.cflags(target, GitRepo::Llvm).join(" ").into();
520+
let mut cflags: OsString = builder.cflags(target, GitRepo::Llvm, CLang::C).join(" ").into();
533521
if let Some(ref s) = builder.config.llvm_cflags {
534522
cflags.push(" ");
535523
cflags.push(s);
@@ -545,23 +533,15 @@ fn configure_cmake(
545533
if builder.config.llvm_clang_cl.is_some() {
546534
cflags.push(&format!(" --target={}", target));
547535
}
548-
if let Some(flags) = env::var_os("CFLAGS") {
549-
cflags.push(" ");
550-
cflags.push(flags);
551-
}
552536
cfg.define("CMAKE_C_FLAGS", cflags);
553-
let mut cxxflags: OsString = builder.cflags(target, GitRepo::Llvm).join(" ").into();
537+
let mut cxxflags: OsString = builder.cflags(target, GitRepo::Llvm, CLang::Cxx).join(" ").into();
554538
if let Some(ref s) = builder.config.llvm_cxxflags {
555539
cxxflags.push(" ");
556540
cxxflags.push(s);
557541
}
558542
if builder.config.llvm_clang_cl.is_some() {
559543
cxxflags.push(&format!(" --target={}", target));
560544
}
561-
if let Some(flags) = env::var_os("CXXFLAGS") {
562-
cxxflags.push(" ");
563-
cxxflags.push(flags);
564-
}
565545
cfg.define("CMAKE_CXX_FLAGS", cxxflags);
566546
if let Some(ar) = builder.ar(target) {
567547
if ar.is_absolute() {
@@ -583,10 +563,22 @@ fn configure_cmake(
583563
ldflags.push_all(flags);
584564
}
585565

586-
if let Some(flags) = env::var_os("LDFLAGS") {
566+
if let Some(flags) = get_var("LDFLAGS", &builder.config.build.triple, &target.triple) {
587567
ldflags.push_all(&flags);
588568
}
589569

570+
// For distribution we want the LLVM tools to be *statically* linked to libstdc++.
571+
// We also do this if the user explicitly requested static libstdc++.
572+
if builder.config.llvm_tools_enabled || builder.config.llvm_static_stdcpp {
573+
if !target.contains("msvc") && !target.contains("netbsd") {
574+
if target.contains("apple") {
575+
ldflags.push_all("-static-libstdc++");
576+
} else {
577+
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
578+
}
579+
}
580+
}
581+
590582
cfg.define("CMAKE_SHARED_LINKER_FLAGS", &ldflags.shared);
591583
cfg.define("CMAKE_MODULE_LINKER_FLAGS", &ldflags.module);
592584
cfg.define("CMAKE_EXE_LINKER_FLAGS", &ldflags.exe);
@@ -596,6 +588,16 @@ fn configure_cmake(
596588
}
597589
}
598590

591+
// Adapted from https://github.com/alexcrichton/cc-rs/blob/fba7feded71ee4f63cfe885673ead6d7b4f2f454/src/lib.rs#L2347-L2365
592+
fn get_var(var_base: &str, host: &str, target: &str) -> Option<OsString> {
593+
let kind = if host == target { "HOST" } else { "TARGET" };
594+
let target_u = target.replace("-", "_");
595+
env::var_os(&format!("{}_{}", var_base, target))
596+
.or_else(|| env::var_os(&format!("{}_{}", var_base, target_u)))
597+
.or_else(|| env::var_os(&format!("{}_{}", kind, var_base)))
598+
.or_else(|| env::var_os(var_base))
599+
}
600+
599601
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
600602
pub struct Lld {
601603
pub target: TargetSelection,

0 commit comments

Comments
 (0)