Skip to content

Commit

Permalink
Auto merge of rust-lang#98781 - GuillaumeGomez:rollup-798kb8u, r=Guil…
Browse files Browse the repository at this point in the history
…laumeGomez

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
  • Loading branch information
bors committed Jul 1, 2022
2 parents 46b8c23 + 00d68a7 commit 9a6fa4f
Show file tree
Hide file tree
Showing 63 changed files with 366 additions and 371 deletions.
12 changes: 9 additions & 3 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub fn emit_inference_failure_err(
&self,
body_id: Option<hir::BodyId>,
span: Span,
failure_span: Span,
arg: GenericArg<'tcx>,
// FIXME(#94483): Either use this or remove it.
_impl_candidates: Vec<ty::TraitRef<'tcx>>,
error_code: TypeAnnotationNeeded,
should_label_span: bool,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let arg = self.resolve_vars_if_possible(arg);
let arg_data = self.extract_inference_diagnostics_data(arg, None);
Expand All @@ -326,7 +327,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// If we don't have any typeck results we're outside
// of a body, so we won't be able to get better info
// here.
return self.bad_inference_failure_err(span, arg_data, error_code);
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
};
let typeck_results = typeck_results.borrow();
let typeck_results = &typeck_results;
Expand All @@ -338,7 +339,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}

let Some(InferSource { span, kind }) = local_visitor.infer_source else {
return self.bad_inference_failure_err(span, arg_data, error_code)
return self.bad_inference_failure_err(failure_span, arg_data, error_code)
};

let error_code = error_code.into();
Expand All @@ -347,6 +348,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&format!("type annotations needed{}", kind.ty_msg(self)),
error_code,
);

if should_label_span && !failure_span.overlaps(span) {
err.span_label(failure_span, "type must be known at this point");
}

match kind {
InferSourceKind::LetBinding { insert_span, pattern_name, ty } => {
let suggestion_msg = if let Some(name) = pattern_name {
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,9 +914,17 @@ impl<'tcx> Term<'tcx> {
pub fn ty(&self) -> Option<Ty<'tcx>> {
if let Term::Ty(ty) = self { Some(*ty) } else { None }
}

pub fn ct(&self) -> Option<Const<'tcx>> {
if let Term::Const(c) = self { Some(*c) } else { None }
}

pub fn into_arg(self) -> GenericArg<'tcx> {
match self {
Term::Ty(ty) => ty.into(),
Term::Const(c) => c.into(),
}
}
}

/// This kind of predicate has no *direct* correspondent in the
Expand Down
99 changes: 59 additions & 40 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1958,26 +1958,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
if predicate.references_error() {
return;
}
// Typically, this ambiguity should only happen if
// there are unresolved type inference variables
// (otherwise it would suggest a coherence
// failure). But given #21974 that is not necessarily
// the case -- we can have multiple where clauses that
// are only distinguished by a region, which results
// in an ambiguity even when all types are fully
// known, since we don't dispatch based on region
// relationships.

// Pick the first substitution that still contains inference variables as the one
// we're going to emit an error for. If there are none (see above), fall back to
// the substitution for `Self`.
let subst = {
let substs = data.trait_ref.substs;
substs
.iter()
.find(|s| s.has_infer_types_or_consts())
.unwrap_or_else(|| substs[0])
};

// This is kind of a hack: it frequently happens that some earlier
// error prevents types from being fully inferred, and then we get
Expand All @@ -1999,27 +1979,54 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
self.emit_inference_failure_err(
body_id,
span,
subst,
trait_ref.self_ty().skip_binder().into(),
vec![],
ErrorCode::E0282,
false,
)
.emit();
}
return;
}

let impl_candidates = self
.find_similar_impl_candidates(trait_ref)
.into_iter()
.map(|candidate| candidate.trait_ref)
.collect();
let mut err = self.emit_inference_failure_err(
body_id,
span,
subst,
impl_candidates,
ErrorCode::E0283,
);
// Typically, this ambiguity should only happen if
// there are unresolved type inference variables
// (otherwise it would suggest a coherence
// failure). But given #21974 that is not necessarily
// the case -- we can have multiple where clauses that
// are only distinguished by a region, which results
// in an ambiguity even when all types are fully
// known, since we don't dispatch based on region
// relationships.

// Pick the first substitution that still contains inference variables as the one
// we're going to emit an error for. If there are none (see above), fall back to
// a more general error.
let subst = data.trait_ref.substs.iter().find(|s| s.has_infer_types_or_consts());

let mut err = if let Some(subst) = subst {
let impl_candidates = self
.find_similar_impl_candidates(trait_ref)
.into_iter()
.map(|candidate| candidate.trait_ref)
.collect();
self.emit_inference_failure_err(
body_id,
span,
subst,
impl_candidates,
ErrorCode::E0283,
true,
)
} else {
struct_span_err!(
self.tcx.sess,
span,
E0283,
"type annotations needed: cannot satisfy `{}`",
predicate,
)
};

let obligation = Obligation::new(
obligation.cause.clone(),
Expand Down Expand Up @@ -2110,7 +2117,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
return;
}

self.emit_inference_failure_err(body_id, span, arg, vec![], ErrorCode::E0282)
self.emit_inference_failure_err(body_id, span, arg, vec![], ErrorCode::E0282, false)
}

ty::PredicateKind::Subtype(data) => {
Expand All @@ -2124,26 +2131,38 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
let SubtypePredicate { a_is_expected: _, a, b } = data;
// both must be type variables, or the other would've been instantiated
assert!(a.is_ty_var() && b.is_ty_var());
self.emit_inference_failure_err(body_id, span, a.into(), vec![], ErrorCode::E0282)
self.emit_inference_failure_err(
body_id,
span,
a.into(),
vec![],
ErrorCode::E0282,
true,
)
}
ty::PredicateKind::Projection(data) => {
let self_ty = data.projection_ty.self_ty();
let term = data.term;
if predicate.references_error() || self.is_tainted_by_errors() {
return;
}
if self_ty.needs_infer() && term.needs_infer() {
// We do this for the `foo.collect()?` case to produce a suggestion.
let subst = data
.projection_ty
.substs
.iter()
.chain(Some(data.term.into_arg()))
.find(|g| g.has_infer_types_or_consts());
if let Some(subst) = subst {
let mut err = self.emit_inference_failure_err(
body_id,
span,
self_ty.into(),
subst,
vec![],
ErrorCode::E0284,
true,
);
err.note(&format!("cannot satisfy `{}`", predicate));
err
} else {
// If we can't find a substitution, just print a generic error
let mut err = struct_span_err!(
self.tcx.sess,
span,
Expand Down
12 changes: 9 additions & 3 deletions compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,9 +1538,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty
} else {
if !self.is_tainted_by_errors() {
self.emit_inference_failure_err((**self).body_id, sp, ty.into(), vec![], E0282)
.note("type must be known at this point")
.emit();
self.emit_inference_failure_err(
(**self).body_id,
sp,
ty.into(),
vec![],
E0282,
true,
)
.emit();
}
let err = self.tcx.ty_error();
self.demand_suptype(sp, err, ty);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_typeck/src/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
t.into(),
vec![],
E0282,
false,
)
.emit();
}
Expand All @@ -708,6 +709,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
c.into(),
vec![],
E0282,
false,
)
.emit();
}
Expand Down
16 changes: 10 additions & 6 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,11 @@ use std::cell::{Cell, RefCell};
use std::collections::{HashMap, HashSet};
use std::env;
use std::fs::{self, File};
use std::io;
use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::str;

#[cfg(unix)]
use std::os::unix::fs::symlink as symlink_file;
#[cfg(windows)]
use std::os::windows::fs::symlink_file;

use filetime::FileTime;
use once_cell::sync::OnceCell;

Expand Down Expand Up @@ -1460,7 +1456,7 @@ impl Build {
src = t!(fs::canonicalize(src));
} else {
let link = t!(fs::read_link(src));
t!(symlink_file(link, dst));
t!(self.symlink_file(link, dst));
return;
}
}
Expand Down Expand Up @@ -1585,6 +1581,14 @@ impl Build {
iter.map(|e| t!(e)).collect::<Vec<_>>().into_iter()
}

fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(&self, src: P, link: Q) -> io::Result<()> {
#[cfg(unix)]
use std::os::unix::fs::symlink as symlink_file;
#[cfg(windows)]
use std::os::windows::fs::symlink_file;
if !self.config.dry_run { symlink_file(src.as_ref(), link.as_ref()) } else { Ok(()) }
}

fn remove(&self, f: &Path) {
if self.config.dry_run {
return;
Expand Down
41 changes: 31 additions & 10 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ impl Step for Llvm {
};

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

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

Expand Down Expand Up @@ -438,18 +438,18 @@ impl Step for Llvm {
);
}

if let Some(ref suffix) = builder.config.llvm_version_suffix {
let llvm_version_suffix = if let Some(ref suffix) = builder.config.llvm_version_suffix {
// Allow version-suffix="" to not define a version suffix at all.
if !suffix.is_empty() {
cfg.define("LLVM_VERSION_SUFFIX", suffix);
}
if !suffix.is_empty() { Some(suffix.to_string()) } else { None }
} else if builder.config.channel == "dev" {
// Changes to a version suffix require a complete rebuild of the LLVM.
// To avoid rebuilds during a time of version bump, don't include rustc
// release number on the dev channel.
cfg.define("LLVM_VERSION_SUFFIX", "-rust-dev");
Some("-rust-dev".to_string())
} else {
let suffix = format!("-rust-{}-{}", builder.version, builder.config.channel);
Some(format!("-rust-{}-{}", builder.version, builder.config.channel))
};
if let Some(ref suffix) = llvm_version_suffix {
cfg.define("LLVM_VERSION_SUFFIX", suffix);
}

Expand Down Expand Up @@ -478,6 +478,27 @@ impl Step for Llvm {

cfg.build();

// When building LLVM with LLVM_LINK_LLVM_DYLIB for macOS, an unversioned
// libLLVM.dylib will be built. However, llvm-config will still look
// for a versioned path like libLLVM-14.dylib. Manually create a symbolic
// link to make llvm-config happy.
if llvm_link_shared && target.contains("apple-darwin") {
let mut cmd = Command::new(&build_llvm_config);
let version = output(cmd.arg("--version"));
let major = version.split('.').next().unwrap();
let lib_name = match llvm_version_suffix {
Some(s) => format!("lib/libLLVM-{}{}.dylib", major, s),
None => format!("lib/libLLVM-{}.dylib", major),
};

// The reason why we build the library path from llvm-config is because
// the output of llvm-config depends on its location in the file system.
// Make sure we create the symlink exactly where it's needed.
let llvm_base = build_llvm_config.parent().unwrap().parent().unwrap();
let lib_llvm = llvm_base.join(lib_name);
t!(builder.symlink_file("libLLVM.dylib", &lib_llvm));
}

t!(stamp.write());

build_llvm_config
Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,10 @@ impl Tester for Collector {
let outdir = if let Some(mut path) = rustdoc_options.persist_doctests.clone() {
path.push(&test_id);

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

DirState::Perm(path)
} else {
Expand Down
Loading

0 comments on commit 9a6fa4f

Please sign in to comment.