Skip to content

Commit 9a6fa4f

Browse files
committed
Auto merge of rust-lang#98781 - GuillaumeGomez:rollup-798kb8u, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - rust-lang#97249 (`<details>`/`<summary>` UI fixes) - rust-lang#98418 (Allow macOS to build LLVM as shared library) - rust-lang#98460 (Use CSS variables to handle theming) - rust-lang#98497 (Improve some inference diagnostics) - rust-lang#98708 (rustdoc: fix 98690 Panic if invalid path for -Z persist-doctests) Failed merges: - rust-lang#98761 (more `need_type_info` improvements) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 46b8c23 + 00d68a7 commit 9a6fa4f

File tree

63 files changed

+366
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+366
-371
lines changed

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
313313
pub fn emit_inference_failure_err(
314314
&self,
315315
body_id: Option<hir::BodyId>,
316-
span: Span,
316+
failure_span: Span,
317317
arg: GenericArg<'tcx>,
318318
// FIXME(#94483): Either use this or remove it.
319319
_impl_candidates: Vec<ty::TraitRef<'tcx>>,
320320
error_code: TypeAnnotationNeeded,
321+
should_label_span: bool,
321322
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
322323
let arg = self.resolve_vars_if_possible(arg);
323324
let arg_data = self.extract_inference_diagnostics_data(arg, None);
@@ -326,7 +327,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
326327
// If we don't have any typeck results we're outside
327328
// of a body, so we won't be able to get better info
328329
// here.
329-
return self.bad_inference_failure_err(span, arg_data, error_code);
330+
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
330331
};
331332
let typeck_results = typeck_results.borrow();
332333
let typeck_results = &typeck_results;
@@ -338,7 +339,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
338339
}
339340

340341
let Some(InferSource { span, kind }) = local_visitor.infer_source else {
341-
return self.bad_inference_failure_err(span, arg_data, error_code)
342+
return self.bad_inference_failure_err(failure_span, arg_data, error_code)
342343
};
343344

344345
let error_code = error_code.into();
@@ -347,6 +348,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
347348
&format!("type annotations needed{}", kind.ty_msg(self)),
348349
error_code,
349350
);
351+
352+
if should_label_span && !failure_span.overlaps(span) {
353+
err.span_label(failure_span, "type must be known at this point");
354+
}
355+
350356
match kind {
351357
InferSourceKind::LetBinding { insert_span, pattern_name, ty } => {
352358
let suggestion_msg = if let Some(name) = pattern_name {

compiler/rustc_middle/src/ty/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -914,9 +914,17 @@ impl<'tcx> Term<'tcx> {
914914
pub fn ty(&self) -> Option<Ty<'tcx>> {
915915
if let Term::Ty(ty) = self { Some(*ty) } else { None }
916916
}
917+
917918
pub fn ct(&self) -> Option<Const<'tcx>> {
918919
if let Term::Const(c) = self { Some(*c) } else { None }
919920
}
921+
922+
pub fn into_arg(self) -> GenericArg<'tcx> {
923+
match self {
924+
Term::Ty(ty) => ty.into(),
925+
Term::Const(c) => c.into(),
926+
}
927+
}
920928
}
921929

922930
/// This kind of predicate has no *direct* correspondent in the

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+59-40
Original file line numberDiff line numberDiff line change
@@ -1958,26 +1958,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
19581958
if predicate.references_error() {
19591959
return;
19601960
}
1961-
// Typically, this ambiguity should only happen if
1962-
// there are unresolved type inference variables
1963-
// (otherwise it would suggest a coherence
1964-
// failure). But given #21974 that is not necessarily
1965-
// the case -- we can have multiple where clauses that
1966-
// are only distinguished by a region, which results
1967-
// in an ambiguity even when all types are fully
1968-
// known, since we don't dispatch based on region
1969-
// relationships.
1970-
1971-
// Pick the first substitution that still contains inference variables as the one
1972-
// we're going to emit an error for. If there are none (see above), fall back to
1973-
// the substitution for `Self`.
1974-
let subst = {
1975-
let substs = data.trait_ref.substs;
1976-
substs
1977-
.iter()
1978-
.find(|s| s.has_infer_types_or_consts())
1979-
.unwrap_or_else(|| substs[0])
1980-
};
19811961

19821962
// This is kind of a hack: it frequently happens that some earlier
19831963
// error prevents types from being fully inferred, and then we get
@@ -1999,27 +1979,54 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
19991979
self.emit_inference_failure_err(
20001980
body_id,
20011981
span,
2002-
subst,
1982+
trait_ref.self_ty().skip_binder().into(),
20031983
vec![],
20041984
ErrorCode::E0282,
1985+
false,
20051986
)
20061987
.emit();
20071988
}
20081989
return;
20091990
}
20101991

2011-
let impl_candidates = self
2012-
.find_similar_impl_candidates(trait_ref)
2013-
.into_iter()
2014-
.map(|candidate| candidate.trait_ref)
2015-
.collect();
2016-
let mut err = self.emit_inference_failure_err(
2017-
body_id,
2018-
span,
2019-
subst,
2020-
impl_candidates,
2021-
ErrorCode::E0283,
2022-
);
1992+
// Typically, this ambiguity should only happen if
1993+
// there are unresolved type inference variables
1994+
// (otherwise it would suggest a coherence
1995+
// failure). But given #21974 that is not necessarily
1996+
// the case -- we can have multiple where clauses that
1997+
// are only distinguished by a region, which results
1998+
// in an ambiguity even when all types are fully
1999+
// known, since we don't dispatch based on region
2000+
// relationships.
2001+
2002+
// Pick the first substitution that still contains inference variables as the one
2003+
// we're going to emit an error for. If there are none (see above), fall back to
2004+
// a more general error.
2005+
let subst = data.trait_ref.substs.iter().find(|s| s.has_infer_types_or_consts());
2006+
2007+
let mut err = if let Some(subst) = subst {
2008+
let impl_candidates = self
2009+
.find_similar_impl_candidates(trait_ref)
2010+
.into_iter()
2011+
.map(|candidate| candidate.trait_ref)
2012+
.collect();
2013+
self.emit_inference_failure_err(
2014+
body_id,
2015+
span,
2016+
subst,
2017+
impl_candidates,
2018+
ErrorCode::E0283,
2019+
true,
2020+
)
2021+
} else {
2022+
struct_span_err!(
2023+
self.tcx.sess,
2024+
span,
2025+
E0283,
2026+
"type annotations needed: cannot satisfy `{}`",
2027+
predicate,
2028+
)
2029+
};
20232030

20242031
let obligation = Obligation::new(
20252032
obligation.cause.clone(),
@@ -2110,7 +2117,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
21102117
return;
21112118
}
21122119

2113-
self.emit_inference_failure_err(body_id, span, arg, vec![], ErrorCode::E0282)
2120+
self.emit_inference_failure_err(body_id, span, arg, vec![], ErrorCode::E0282, false)
21142121
}
21152122

21162123
ty::PredicateKind::Subtype(data) => {
@@ -2124,26 +2131,38 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
21242131
let SubtypePredicate { a_is_expected: _, a, b } = data;
21252132
// both must be type variables, or the other would've been instantiated
21262133
assert!(a.is_ty_var() && b.is_ty_var());
2127-
self.emit_inference_failure_err(body_id, span, a.into(), vec![], ErrorCode::E0282)
2134+
self.emit_inference_failure_err(
2135+
body_id,
2136+
span,
2137+
a.into(),
2138+
vec![],
2139+
ErrorCode::E0282,
2140+
true,
2141+
)
21282142
}
21292143
ty::PredicateKind::Projection(data) => {
2130-
let self_ty = data.projection_ty.self_ty();
2131-
let term = data.term;
21322144
if predicate.references_error() || self.is_tainted_by_errors() {
21332145
return;
21342146
}
2135-
if self_ty.needs_infer() && term.needs_infer() {
2136-
// We do this for the `foo.collect()?` case to produce a suggestion.
2147+
let subst = data
2148+
.projection_ty
2149+
.substs
2150+
.iter()
2151+
.chain(Some(data.term.into_arg()))
2152+
.find(|g| g.has_infer_types_or_consts());
2153+
if let Some(subst) = subst {
21372154
let mut err = self.emit_inference_failure_err(
21382155
body_id,
21392156
span,
2140-
self_ty.into(),
2157+
subst,
21412158
vec![],
21422159
ErrorCode::E0284,
2160+
true,
21432161
);
21442162
err.note(&format!("cannot satisfy `{}`", predicate));
21452163
err
21462164
} else {
2165+
// If we can't find a substitution, just print a generic error
21472166
let mut err = struct_span_err!(
21482167
self.tcx.sess,
21492168
span,

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -1538,9 +1538,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15381538
ty
15391539
} else {
15401540
if !self.is_tainted_by_errors() {
1541-
self.emit_inference_failure_err((**self).body_id, sp, ty.into(), vec![], E0282)
1542-
.note("type must be known at this point")
1543-
.emit();
1541+
self.emit_inference_failure_err(
1542+
(**self).body_id,
1543+
sp,
1544+
ty.into(),
1545+
vec![],
1546+
E0282,
1547+
true,
1548+
)
1549+
.emit();
15441550
}
15451551
let err = self.tcx.ty_error();
15461552
self.demand_suptype(sp, err, ty);

compiler/rustc_typeck/src/check/writeback.rs

+2
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
694694
t.into(),
695695
vec![],
696696
E0282,
697+
false,
697698
)
698699
.emit();
699700
}
@@ -708,6 +709,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
708709
c.into(),
709710
vec![],
710711
E0282,
712+
false,
711713
)
712714
.emit();
713715
}

src/bootstrap/lib.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,11 @@ use std::cell::{Cell, RefCell};
107107
use std::collections::{HashMap, HashSet};
108108
use std::env;
109109
use std::fs::{self, File};
110+
use std::io;
110111
use std::path::{Path, PathBuf};
111112
use std::process::{self, Command};
112113
use std::str;
113114

114-
#[cfg(unix)]
115-
use std::os::unix::fs::symlink as symlink_file;
116-
#[cfg(windows)]
117-
use std::os::windows::fs::symlink_file;
118-
119115
use filetime::FileTime;
120116
use once_cell::sync::OnceCell;
121117

@@ -1460,7 +1456,7 @@ impl Build {
14601456
src = t!(fs::canonicalize(src));
14611457
} else {
14621458
let link = t!(fs::read_link(src));
1463-
t!(symlink_file(link, dst));
1459+
t!(self.symlink_file(link, dst));
14641460
return;
14651461
}
14661462
}
@@ -1585,6 +1581,14 @@ impl Build {
15851581
iter.map(|e| t!(e)).collect::<Vec<_>>().into_iter()
15861582
}
15871583

1584+
fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(&self, src: P, link: Q) -> io::Result<()> {
1585+
#[cfg(unix)]
1586+
use std::os::unix::fs::symlink as symlink_file;
1587+
#[cfg(windows)]
1588+
use std::os::windows::fs::symlink_file;
1589+
if !self.config.dry_run { symlink_file(src.as_ref(), link.as_ref()) } else { Ok(()) }
1590+
}
1591+
15881592
fn remove(&self, f: &Path) {
15891593
if self.config.dry_run {
15901594
return;

src/bootstrap/native.rs

+31-10
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ impl Step for Llvm {
251251
};
252252

253253
builder.update_submodule(&Path::new("src").join("llvm-project"));
254-
if builder.llvm_link_shared()
255-
&& (target.contains("windows") || target.contains("apple-darwin"))
256-
{
254+
if builder.llvm_link_shared() && target.contains("windows") {
257255
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
258256
}
259257

@@ -359,7 +357,9 @@ impl Step for Llvm {
359357
//
360358
// If we're not linking rustc to a dynamic LLVM, though, then don't link
361359
// tools to it.
362-
if builder.llvm_link_tools_dynamically(target) && builder.llvm_link_shared() {
360+
let llvm_link_shared =
361+
builder.llvm_link_tools_dynamically(target) && builder.llvm_link_shared();
362+
if llvm_link_shared {
363363
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
364364
}
365365

@@ -438,18 +438,18 @@ impl Step for Llvm {
438438
);
439439
}
440440

441-
if let Some(ref suffix) = builder.config.llvm_version_suffix {
441+
let llvm_version_suffix = if let Some(ref suffix) = builder.config.llvm_version_suffix {
442442
// Allow version-suffix="" to not define a version suffix at all.
443-
if !suffix.is_empty() {
444-
cfg.define("LLVM_VERSION_SUFFIX", suffix);
445-
}
443+
if !suffix.is_empty() { Some(suffix.to_string()) } else { None }
446444
} else if builder.config.channel == "dev" {
447445
// Changes to a version suffix require a complete rebuild of the LLVM.
448446
// To avoid rebuilds during a time of version bump, don't include rustc
449447
// release number on the dev channel.
450-
cfg.define("LLVM_VERSION_SUFFIX", "-rust-dev");
448+
Some("-rust-dev".to_string())
451449
} else {
452-
let suffix = format!("-rust-{}-{}", builder.version, builder.config.channel);
450+
Some(format!("-rust-{}-{}", builder.version, builder.config.channel))
451+
};
452+
if let Some(ref suffix) = llvm_version_suffix {
453453
cfg.define("LLVM_VERSION_SUFFIX", suffix);
454454
}
455455

@@ -478,6 +478,27 @@ impl Step for Llvm {
478478

479479
cfg.build();
480480

481+
// When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
482+
// libLLVM.dylib will be built. However, llvm-config will still look
483+
// for a versioned path like libLLVM-14.dylib. Manually create a symbolic
484+
// link to make llvm-config happy.
485+
if llvm_link_shared && target.contains("apple-darwin") {
486+
let mut cmd = Command::new(&build_llvm_config);
487+
let version = output(cmd.arg("--version"));
488+
let major = version.split('.').next().unwrap();
489+
let lib_name = match llvm_version_suffix {
490+
Some(s) => format!("lib/libLLVM-{}{}.dylib", major, s),
491+
None => format!("lib/libLLVM-{}.dylib", major),
492+
};
493+
494+
// The reason why we build the library path from llvm-config is because
495+
// the output of llvm-config depends on its location in the file system.
496+
// Make sure we create the symlink exactly where it's needed.
497+
let llvm_base = build_llvm_config.parent().unwrap().parent().unwrap();
498+
let lib_llvm = llvm_base.join(lib_name);
499+
t!(builder.symlink_file("libLLVM.dylib", &lib_llvm));
500+
}
501+
481502
t!(stamp.write());
482503

483504
build_llvm_config

src/librustdoc/doctest.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1003,8 +1003,10 @@ impl Tester for Collector {
10031003
let outdir = if let Some(mut path) = rustdoc_options.persist_doctests.clone() {
10041004
path.push(&test_id);
10051005

1006-
std::fs::create_dir_all(&path)
1007-
.expect("Couldn't create directory for doctest executables");
1006+
if let Err(err) = std::fs::create_dir_all(&path) {
1007+
eprintln!("Couldn't create directory for doctest executables: {}", err);
1008+
panic::resume_unwind(box ());
1009+
}
10081010

10091011
DirState::Perm(path)
10101012
} else {

0 commit comments

Comments
 (0)