Skip to content

Rollup of 6 pull requests #89671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
853ffc7
stack overflow handler specific openbsd fix.
devnexen Jul 27, 2021
10f7769
Remove textual span from diagnostic string
oli-obk Oct 5, 2021
64c794c
Use a label instead of a note for member constraint errors
oli-obk Oct 5, 2021
7df32f4
Remove a feature attribute for an accepted feature
oli-obk Oct 5, 2021
b7191b3
Remove explicit -Zborrowck=mir which does not affect test anymore
oli-obk Oct 5, 2021
d3871f5
Re-use logic for adding a suggestion when a lifetime bound is missing…
oli-obk Oct 5, 2021
6189d0a
Fix stabilization version for `bindings_after_at`
camelid Oct 6, 2021
cbf9153
dont normalize return type during candidate assembly in method probing
b-naber Oct 7, 2021
3215403
tests
b-naber Oct 7, 2021
4593d78
Default to disabling the new pass manager for the s390x targets.
hkratz Oct 8, 2021
31b2eb1
Cfg hide more conditions for core
Urgau Oct 8, 2021
0a03ec4
Cfg hide more conditions for alloc
Urgau Oct 8, 2021
9d1dc71
Rollup merge of #86506 - b-naber:gen_trait_impl_inconsistent, r=jackh726
GuillaumeGomez Oct 8, 2021
bc70f7d
Rollup merge of #87528 - :stack_overflow_obsd, r=joshtriplett
GuillaumeGomez Oct 8, 2021
57b9602
Rollup merge of #89555 - oli-obk:nll_member_constraint_diag, r=estebank
GuillaumeGomez Oct 8, 2021
c52602f
Rollup merge of #89605 - camelid:fix-version, r=nagisa
GuillaumeGomez Oct 8, 2021
d7bb8a7
Rollup merge of #89666 - rusticstuff:disable_new_llvm_pass_manager_on…
GuillaumeGomez Oct 8, 2021
66f5f12
Rollup merge of #89668 - Urgau:core-cfg-hide, r=GuillaumeGomez
GuillaumeGomez Oct 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
@@ -596,7 +596,7 @@ pub(crate) fn run_pass_manager(
// tools/lto/LTOCodeGenerator.cpp
debug!("running the pass manager");
unsafe {
if write::should_use_new_llvm_pass_manager(config) {
if write::should_use_new_llvm_pass_manager(cgcx, config) {
let opt_stage = if thin { llvm::OptStage::ThinLTO } else { llvm::OptStage::FatLTO };
let opt_level = config.opt_level.unwrap_or(config::OptLevel::No);
write::optimize_with_new_llvm_pass_manager(
15 changes: 12 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
@@ -377,10 +377,19 @@ fn get_pgo_sample_use_path(config: &ModuleConfig) -> Option<CString> {
.map(|path_buf| CString::new(path_buf.to_string_lossy().as_bytes()).unwrap())
}

pub(crate) fn should_use_new_llvm_pass_manager(config: &ModuleConfig) -> bool {
pub(crate) fn should_use_new_llvm_pass_manager(
cgcx: &CodegenContext<LlvmCodegenBackend>,
config: &ModuleConfig,
) -> bool {
// The new pass manager is enabled by default for LLVM >= 13.
// This matches Clang, which also enables it since Clang 13.
config.new_llvm_pass_manager.unwrap_or_else(|| llvm_util::get_version() >= (13, 0, 0))

// FIXME: There are some perf issues with the new pass manager
// when targeting s390x, so it is temporarily disabled for that
// arch, see https://github.com/rust-lang/rust/issues/89609
config
.new_llvm_pass_manager
.unwrap_or_else(|| cgcx.target_arch != "s390x" && llvm_util::get_version() >= (13, 0, 0))
}

pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
@@ -482,7 +491,7 @@ pub(crate) unsafe fn optimize(
}

if let Some(opt_level) = config.opt_level {
if should_use_new_llvm_pass_manager(config) {
if should_use_new_llvm_pass_manager(cgcx, config) {
let opt_stage = match cgcx.lto {
Lto::Fat => llvm::OptStage::PreLinkFatLTO,
Lto::Thin | Lto::ThinLocal => llvm::OptStage::PreLinkThinLTO,
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
@@ -288,7 +288,7 @@ declare_features! (
(accepted, member_constraints, "1.54.0", Some(61997), None),
/// Allows bindings in the subpattern of a binding pattern.
/// For example, you can write `x @ Some(y)`.
(accepted, bindings_after_at, "1.54.0", Some(65490), None),
(accepted, bindings_after_at, "1.56.0", Some(65490), None),
/// Allows calling `transmute` in const fn
(accepted, const_fn_transmute, "1.56.0", Some(53605), None),
/// Allows accessing fields of unions inside `const` functions.
3 changes: 1 addition & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
@@ -2235,8 +2235,7 @@ pub enum TyKind<'hir> {
///
/// Type parameters may be stored in each `PathSegment`.
Path(QPath<'hir>),
/// An opaque type definition itself. This is currently only used for the
/// `opaque type Foo: Trait` item that `impl Trait` in desugars to.
/// An opaque type definition itself. This is only used for `impl Trait`.
///
/// The generic argument list contains the lifetimes (and in the future
/// possibly parameters) that are actually bound on the `impl Trait`.
93 changes: 37 additions & 56 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ pub(super) fn note_and_explain_region(
emit_msg_span(err, prefix, description, span, suffix);
}

pub(super) fn note_and_explain_free_region(
fn explain_free_region(
tcx: TyCtxt<'tcx>,
err: &mut DiagnosticBuilder<'_>,
prefix: &str,
@@ -125,7 +125,7 @@ pub(super) fn note_and_explain_free_region(
) {
let (description, span) = msg_span_from_free_region(tcx, region, None);

emit_msg_span(err, prefix, description, span, suffix);
label_msg_span(err, prefix, description, span, suffix);
}

fn msg_span_from_free_region(
@@ -135,7 +135,8 @@ fn msg_span_from_free_region(
) -> (String, Option<Span>) {
match *region {
ty::ReEarlyBound(_) | ty::ReFree(_) => {
msg_span_from_early_bound_and_free_regions(tcx, region)
let (msg, span) = msg_span_from_early_bound_and_free_regions(tcx, region);
(msg, Some(span))
}
ty::ReStatic => ("the static lifetime".to_owned(), alt_span),
ty::ReEmpty(ty::UniverseIndex::ROOT) => ("an empty lifetime".to_owned(), alt_span),
@@ -147,28 +148,20 @@ fn msg_span_from_free_region(
fn msg_span_from_early_bound_and_free_regions(
tcx: TyCtxt<'tcx>,
region: ty::Region<'tcx>,
) -> (String, Option<Span>) {
) -> (String, Span) {
let sm = tcx.sess.source_map();

let scope = region.free_region_binding_scope(tcx);
let node = tcx.hir().local_def_id_to_hir_id(scope.expect_local());
let tag = match tcx.hir().find(node) {
Some(Node::Block(_) | Node::Expr(_)) => "body",
Some(Node::Item(it)) => item_scope_tag(&it),
Some(Node::TraitItem(it)) => trait_item_scope_tag(&it),
Some(Node::ImplItem(it)) => impl_item_scope_tag(&it),
Some(Node::ForeignItem(it)) => foreign_item_scope_tag(&it),
_ => unreachable!(),
};
let (prefix, span) = match *region {
match *region {
ty::ReEarlyBound(ref br) => {
let mut sp = sm.guess_head_span(tcx.hir().span(node));
if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
{
sp = param.span;
}
(format!("the lifetime `{}` as defined on", br.name), sp)
(format!("the lifetime `{}` as defined here", br.name), sp)
}
ty::ReFree(ty::FreeRegion {
bound_region: ty::BoundRegionKind::BrNamed(_, name), ..
@@ -179,28 +172,26 @@ fn msg_span_from_early_bound_and_free_regions(
{
sp = param.span;
}
(format!("the lifetime `{}` as defined on", name), sp)
(format!("the lifetime `{}` as defined here", name), sp)
}
ty::ReFree(ref fr) => match fr.bound_region {
ty::BrAnon(idx) => {
if let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region) {
("the anonymous lifetime defined on".to_string(), ty.span)
("the anonymous lifetime defined here".to_string(), ty.span)
} else {
(
format!("the anonymous lifetime #{} defined on", idx + 1),
format!("the anonymous lifetime #{} defined here", idx + 1),
tcx.hir().span(node),
)
}
}
_ => (
format!("the lifetime `{}` as defined on", region),
format!("the lifetime `{}` as defined here", region),
sm.guess_head_span(tcx.hir().span(node)),
),
},
_ => bug!(),
};
let (msg, opt_span) = explain_span(tcx, tag, span);
(format!("{} {}", prefix, msg), opt_span)
}
}

fn emit_msg_span(
@@ -219,44 +210,22 @@ fn emit_msg_span(
}
}

fn item_scope_tag(item: &hir::Item<'_>) -> &'static str {
match item.kind {
hir::ItemKind::Impl { .. } => "impl",
hir::ItemKind::Struct(..) => "struct",
hir::ItemKind::Union(..) => "union",
hir::ItemKind::Enum(..) => "enum",
hir::ItemKind::Trait(..) => "trait",
hir::ItemKind::Fn(..) => "function body",
_ => "item",
}
}

fn trait_item_scope_tag(item: &hir::TraitItem<'_>) -> &'static str {
match item.kind {
hir::TraitItemKind::Fn(..) => "method body",
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => "associated item",
}
}

fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str {
match item.kind {
hir::ImplItemKind::Fn(..) => "method body",
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(..) => "associated item",
}
}
fn label_msg_span(
err: &mut DiagnosticBuilder<'_>,
prefix: &str,
description: String,
span: Option<Span>,
suffix: &str,
) {
let message = format!("{}{}{}", prefix, description, suffix);

fn foreign_item_scope_tag(item: &hir::ForeignItem<'_>) -> &'static str {
match item.kind {
hir::ForeignItemKind::Fn(..) => "method body",
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => "associated item",
if let Some(span) = span {
err.span_label(span, &message);
} else {
err.note(&message);
}
}

fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option<Span>) {
let lo = tcx.sess.source_map().lookup_char_pos(span.lo());
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize() + 1), Some(span))
}

pub fn unexpected_hidden_region_diagnostic(
tcx: TyCtxt<'tcx>,
span: Span,
@@ -291,13 +260,25 @@ pub fn unexpected_hidden_region_diagnostic(
//
// (*) if not, the `tainted_by_errors` field would be set to
// `Some(ErrorReported)` in any case, so we wouldn't be here at all.
note_and_explain_free_region(
explain_free_region(
tcx,
&mut err,
&format!("hidden type `{}` captures ", hidden_ty),
hidden_region,
"",
);
if let Some(reg_info) = tcx.is_suitable_region(hidden_region) {
let fn_returns = tcx.return_type_impl_or_dyn_traits(reg_info.def_id);
nice_region_error::suggest_new_region_bound(
tcx,
&mut err,
fn_returns,
hidden_region.to_string(),
None,
format!("captures {}", hidden_region),
None,
)
}
}
_ => {
// Ugh. This is a painful case: the hidden region is not one
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ mod static_impl_trait;
mod trait_impl_difference;
mod util;

pub use static_impl_trait::suggest_new_region_bound;

impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
pub fn try_report_nice_region_error(&self, error: &RegionResolutionError<'tcx>) -> bool {
NiceRegionError::new(self, error.clone()).try_report().is_some()
Loading