Skip to content
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

Rollup of 7 pull requests #89702

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
853ffc7
stack overflow handler specific openbsd fix.
devnexen Jul 27, 2021
af83a96
std: Stabilize command_access
lf- Aug 28, 2021
4be574e
Add 'core::array::from_fn' and 'core::array::try_from_fn'
c410-f3r Sep 30, 2021
fdccc7d
Use reference instead of raw pointer
c410-f3r Sep 30, 2021
325025e
Improve previous commit
steffahn Sep 30, 2021
13bfcb7
Merge pull request #2 from steffahn/collect_into_array_fix_ub
c410-f3r Sep 30, 2021
355c7e9
Remove an unnecessary use of unwrap_unchecked
steffahn Sep 30, 2021
91ad91e
Skip platforms without unwinding support
c410-f3r Oct 3, 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
5e1941c
Apply suggestions from code review
yaahc Oct 5, 2021
e159d42
Redo #81358 in unicode-table-generator
cuviper Oct 6, 2021
6b0b417
Let unicode-table-generator fail gracefully for bitsets
cuviper Oct 7, 2021
459a7e3
Regenerate tables for Unicode 14.0.0
cuviper Oct 7, 2021
6a52fb7
Add documentation to boxed conversions
timClicks Oct 8, 2021
85c4a52
Also cfg flag auxiliar function
c410-f3r Oct 8, 2021
09d1774
Bless nll tests
oli-obk Oct 8, 2021
fa5a212
Simplify wording
timClicks Oct 9, 2021
020ec0a
Remove unnecessary hyphen
timClicks Oct 9, 2021
3214253
Fix invalid HTML generation for higher bounds
GuillaumeGomez Oct 8, 2021
1069985
Rollup merge of #75644 - c410-f3r:array, r=yaahc
GuillaumeGomez Oct 9, 2021
41babca
Rollup merge of #87528 - :stack_overflow_obsd, r=joshtriplett
GuillaumeGomez Oct 9, 2021
d8868d6
Rollup merge of #88436 - lf-:stabilize-command-access, r=yaahc
GuillaumeGomez Oct 9, 2021
3323ba1
Rollup merge of #89555 - oli-obk:nll_member_constraint_diag, r=estebank
GuillaumeGomez Oct 9, 2021
123f07f
Rollup merge of #89614 - cuviper:unicode-14, r=joshtriplett
GuillaumeGomez Oct 9, 2021
b243dcd
Rollup merge of #89664 - timClicks:51430-document-boxed-conversions, …
GuillaumeGomez Oct 9, 2021
4bbd3eb
Rollup merge of #89700 - GuillaumeGomez:fix-rustdoc-higher-bound-html…
GuillaumeGomez Oct 9, 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
3 changes: 1 addition & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
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
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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),
Expand All @@ -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), ..
Expand All @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading