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 6 pull requests #72490

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0ef565e
Add missing ASM arena declaration to librustc_middle
Aaron1011 May 20, 2020
5728c53
Use `HirId` as key for `ResolverOutputs::trait_map` instead of `NodeId`
marmeladema May 20, 2020
3c5dba7
Use `HirId` in value of `ResolverOutputs::trait_map` instead of `NodeId`
marmeladema May 20, 2020
52359f7
Use `HirId` in `ResolverOutputs::export_map` instead of `NodeId`
marmeladema May 20, 2020
13c86f2
Use `LocalDefId` in `ResolverOutputs::maybe_unused_trait_imports` ins…
marmeladema May 20, 2020
25f575b
Use `DefId` in `ResolverOutputs::maybe_unused_extern_crates` instead …
marmeladema May 20, 2020
21f65ae
Use `DefId` in `ResolverOutputs::glob_map` instead of `NodeId`
marmeladema May 20, 2020
8ff6ffd
Use `DefId` in `ResolverOutputs::extern_crate_map` instead of `NodeId`
marmeladema May 20, 2020
4c4cb46
Use `collect()` instead of manually inserting elements into maps
marmeladema May 21, 2020
f31e076
Replace unecessary calls to `.clone()` by argument binding pattern fo…
marmeladema May 21, 2020
407958a
Replace obligation construction with deref_steps()
ldm0 May 17, 2020
52bb09a
Rewrite `Parser::collect_tokens`
Aaron1011 May 19, 2020
33f90f2
Check for upper bound universe errors more carefully
matthewjasper May 19, 2020
187bfb3
Improve the error when an opaque type captures ReEmtpty
matthewjasper May 19, 2020
c102312
Remove the parts of regionck referencing ReScope
matthewjasper May 19, 2020
7d73e4c
Remove ReScope
matthewjasper May 19, 2020
52d628f
Remove unused error reporting code
matthewjasper May 19, 2020
3d8a073
Remove dead ScopeTree code
matthewjasper May 19, 2020
f9f3063
Update tests
matthewjasper May 20, 2020
9754b3f
Document `collect_bounding_regions`
matthewjasper May 21, 2020
730c6f3
Preserve substitutions when trying to prove trait obligation
ecstatic-morse Apr 27, 2020
8ea828b
Add regression test for #71394
ecstatic-morse Apr 27, 2020
4d9e9c6
Bless other example of #71394
ecstatic-morse Apr 27, 2020
d2bacb1
Ensure that `new_self_ty` has no escaping bound vars
ecstatic-morse Apr 28, 2020
7278e29
Document invariants of `mk_trait_obligation_with_new_self_ty`
ecstatic-morse May 18, 2020
f99519b
Bail out if `output_ty` has bound variables
ecstatic-morse May 18, 2020
1fad3b7
Use `mk_trait_obligation_with_new_self_ty` for new suggestion
ecstatic-morse May 18, 2020
a630767
Rollup merge of #71618 - ecstatic-morse:issue-71394, r=nikomatsakis
RalfJung May 23, 2020
6b9b044
Rollup merge of #72292 - ldm0:derefsteps, r=estebank
RalfJung May 23, 2020
533b6ce
Rollup merge of #72362 - matthewjasper:remove-rescope, r=nikomatsakis
RalfJung May 23, 2020
8e98d8d
Rollup merge of #72393 - Aaron1011:feature/rewrite-collect-tokens, r=…
RalfJung May 23, 2020
f1f3e52
Rollup merge of #72400 - Aaron1011:fix/asm-incr-ice, r=Amanieu
RalfJung May 23, 2020
88e2815
Rollup merge of #72402 - marmeladema:resolver-outputs-def-id, r=ecsta…
RalfJung May 23, 2020
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
4 changes: 3 additions & 1 deletion src/librustc_hir/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ impl Definitions {

#[inline]
pub fn local_def_id(&self, node: ast::NodeId) -> LocalDefId {
self.opt_local_def_id(node).unwrap()
self.opt_local_def_id(node).unwrap_or_else(|| {
panic!("no entry for node id: `{:?}` / `{:?}`", node, self.opt_node_id_to_hir_id(node))
})
}

#[inline]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_infer/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
ty::ReStatic
| ty::ReEarlyBound(..)
| ty::ReFree(_)
| ty::ReScope(_)
| ty::ReEmpty(_)
| ty::RePlaceholder(..)
| ty::ReErased => self.canonicalize_region_mode.canonicalize_free_region(self, r),
Expand Down
1 change: 0 additions & 1 deletion src/librustc_infer/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
| ty::ReVar(..)
| ty::ReEmpty(_)
| ty::ReStatic
| ty::ReScope(..)
| ty::ReEarlyBound(..)
| ty::ReFree(..) => {
// see common code below
Expand Down
199 changes: 52 additions & 147 deletions src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::Node;
use rustc_middle::middle::region;
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::{
self,
Expand All @@ -81,58 +80,12 @@ pub mod nice_region_error;

pub(super) fn note_and_explain_region(
tcx: TyCtxt<'tcx>,
region_scope_tree: &region::ScopeTree,
err: &mut DiagnosticBuilder<'_>,
prefix: &str,
region: ty::Region<'tcx>,
suffix: &str,
) {
let (description, span) = match *region {
ty::ReScope(scope) => {
let new_string;
let unknown_scope =
|| format!("{}unknown scope: {:?}{}. Please report a bug.", prefix, scope, suffix);
let span = scope.span(tcx, region_scope_tree);
let hir_id = scope.hir_id(region_scope_tree);
let tag = match hir_id.and_then(|hir_id| tcx.hir().find(hir_id)) {
Some(Node::Block(_)) => "block",
Some(Node::Expr(expr)) => match expr.kind {
hir::ExprKind::Call(..) => "call",
hir::ExprKind::MethodCall(..) => "method call",
hir::ExprKind::Match(.., hir::MatchSource::IfLetDesugar { .. }) => "if let",
hir::ExprKind::Match(.., hir::MatchSource::WhileLetDesugar) => "while let",
hir::ExprKind::Match(.., hir::MatchSource::ForLoopDesugar) => "for",
hir::ExprKind::Match(..) => "match",
_ => "expression",
},
Some(Node::Stmt(_)) => "statement",
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(_) | None => {
err.span_note(span, &unknown_scope());
return;
}
};
let scope_decorated_tag = match scope.data {
region::ScopeData::Node => tag,
region::ScopeData::CallSite => "scope of call-site for function",
region::ScopeData::Arguments => "scope of function body",
region::ScopeData::Destruction => {
new_string = format!("destruction scope surrounding {}", tag);
&new_string[..]
}
region::ScopeData::Remainder(first_statement_index) => {
new_string = format!(
"block suffix following statement {}",
first_statement_index.index()
);
&new_string[..]
}
};
explain_span(tcx, scope_decorated_tag, span)
}

ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => {
msg_span_from_free_region(tcx, region)
}
Expand Down Expand Up @@ -284,7 +237,6 @@ fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option

pub fn unexpected_hidden_region_diagnostic(
tcx: TyCtxt<'tcx>,
region_scope_tree: Option<&region::ScopeTree>,
span: Span,
hidden_ty: Ty<'tcx>,
hidden_region: ty::Region<'tcx>,
Expand All @@ -297,64 +249,56 @@ pub fn unexpected_hidden_region_diagnostic(
);

// Explain the region we are capturing.
if let ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic | ty::ReEmpty(_) = hidden_region {
// Assuming regionck succeeded (*), we ought to always be
// capturing *some* region from the fn header, and hence it
// ought to be free. So under normal circumstances, we will go
// down this path which gives a decent human readable
// explanation.
//
// (*) 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(
tcx,
&mut err,
&format!("hidden type `{}` captures ", hidden_ty),
hidden_region,
"",
);
} else {
// Ugh. This is a painful case: the hidden region is not one
// that we can easily summarize or explain. This can happen
// in a case like
// `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
//
// ```
// fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
// if condition() { a } else { b }
// }
// ```
//
// Here the captured lifetime is the intersection of `'a` and
// `'b`, which we can't quite express.

if let Some(region_scope_tree) = region_scope_tree {
// If the `region_scope_tree` is available, this is being
// invoked from the "region inferencer error". We can at
// least report a really cryptic error for now.
note_and_explain_region(
match hidden_region {
ty::ReEmpty(ty::UniverseIndex::ROOT) => {
// All lifetimes shorter than the function body are `empty` in
// lexical region resolution. The default explanation of "an empty
// lifetime" isn't really accurate here.
let message = format!(
"hidden type `{}` captures lifetime smaller than the function body",
hidden_ty
);
err.span_note(span, &message);
}
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic | ty::ReEmpty(_) => {
// Assuming regionck succeeded (*), we ought to always be
// capturing *some* region from the fn header, and hence it
// ought to be free. So under normal circumstances, we will go
// down this path which gives a decent human readable
// explanation.
//
// (*) 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(
tcx,
region_scope_tree,
&mut err,
&format!("hidden type `{}` captures ", hidden_ty),
hidden_region,
"",
);
} else {
// If the `region_scope_tree` is *unavailable*, this is
// being invoked by the code that comes *after* region
// inferencing. This is a bug, as the region inferencer
// ought to have noticed the failed constraint and invoked
// error reporting, which in turn should have prevented us
// from getting trying to infer the hidden type
// completely.
tcx.sess.delay_span_bug(
span,
&format!(
"hidden type captures unexpected lifetime `{:?}` \
but no region inference failure",
hidden_region,
),
}
_ => {
// Ugh. This is a painful case: the hidden region is not one
// that we can easily summarize or explain. This can happen
// in a case like
// `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
//
// ```
// fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
// if condition() { a } else { b }
// }
// ```
//
// Here the captured lifetime is the intersection of `'a` and
// `'b`, which we can't quite express.

// We can at least report a really cryptic error for now.
note_and_explain_region(
tcx,
&mut err,
&format!("hidden type `{}` captures ", hidden_ty),
hidden_region,
"",
);
}
}
Expand All @@ -363,11 +307,7 @@ pub fn unexpected_hidden_region_diagnostic(
}

impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub fn report_region_errors(
&self,
region_scope_tree: &region::ScopeTree,
errors: &Vec<RegionResolutionError<'tcx>>,
) {
pub fn report_region_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>) {
debug!("report_region_errors(): {} errors to start", errors.len());

// try to pre-process the errors, which will group some of them
Expand All @@ -390,17 +330,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// general bit of code that displays the error information
RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
if sub.is_placeholder() || sup.is_placeholder() {
self.report_placeholder_failure(region_scope_tree, origin, sub, sup)
.emit();
self.report_placeholder_failure(origin, sub, sup).emit();
} else {
self.report_concrete_failure(region_scope_tree, origin, sub, sup)
.emit();
self.report_concrete_failure(origin, sub, sup).emit();
}
}

RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => {
self.report_generic_bound_failure(
region_scope_tree,
origin.span(),
Some(origin),
param_ty,
Expand All @@ -417,29 +354,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
sup_r,
) => {
if sub_r.is_placeholder() {
self.report_placeholder_failure(
region_scope_tree,
sub_origin,
sub_r,
sup_r,
)
.emit();
self.report_placeholder_failure(sub_origin, sub_r, sup_r).emit();
} else if sup_r.is_placeholder() {
self.report_placeholder_failure(
region_scope_tree,
sup_origin,
sub_r,
sup_r,
)
.emit();
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
} else {
self.report_sub_sup_conflict(
region_scope_tree,
var_origin,
sub_origin,
sub_r,
sup_origin,
sup_r,
var_origin, sub_origin, sub_r, sup_origin, sup_r,
);
}
}
Expand All @@ -460,13 +380,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// value.
let sub_r = self.tcx.mk_region(ty::ReEmpty(var_universe));

self.report_placeholder_failure(
region_scope_tree,
sup_origin,
sub_r,
sup_r,
)
.emit();
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
}

RegionResolutionError::MemberConstraintFailure {
Expand All @@ -477,7 +391,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let hidden_ty = self.resolve_vars_if_possible(&hidden_ty);
unexpected_hidden_region_diagnostic(
self.tcx,
Some(region_scope_tree),
span,
hidden_ty,
member_region,
Expand Down Expand Up @@ -1754,19 +1667,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

pub fn report_generic_bound_failure(
&self,
region_scope_tree: &region::ScopeTree,
span: Span,
origin: Option<SubregionOrigin<'tcx>>,
bound_kind: GenericKind<'tcx>,
sub: Region<'tcx>,
) {
self.construct_generic_bound_failure(region_scope_tree, span, origin, bound_kind, sub)
.emit();
self.construct_generic_bound_failure(span, origin, bound_kind, sub).emit();
}

pub fn construct_generic_bound_failure(
&self,
region_scope_tree: &region::ScopeTree,
span: Span,
origin: Option<SubregionOrigin<'tcx>>,
bound_kind: GenericKind<'tcx>,
Expand Down Expand Up @@ -1918,7 +1828,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
));
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
&format!("{} must be valid for ", labeled_user_string),
sub,
Expand All @@ -1936,7 +1845,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

fn report_sub_sup_conflict(
&self,
region_scope_tree: &region::ScopeTree,
var_origin: RegionVariableOrigin,
sub_origin: SubregionOrigin<'tcx>,
sub_region: Region<'tcx>,
Expand All @@ -1947,7 +1855,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"first, the lifetime cannot outlive ",
sup_region,
Expand All @@ -1973,7 +1880,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if sub_expected == sup_expected && sub_found == sup_found {
note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"...but the lifetime must also be valid for ",
sub_region,
Expand All @@ -1995,7 +1901,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

note_and_explain_region(
self.tcx,
region_scope_tree,
&mut err,
"but, the lifetime must be valid for ",
sub_region,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use rustc_span::source_map::Span;
mod different_lifetimes;
mod find_anon_type;
mod named_anon_conflict;
mod outlives_closure;
mod placeholder_error;
mod static_impl_trait;
mod trait_impl_difference;
Expand Down Expand Up @@ -57,7 +56,6 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> {
ErrorReported
})
.or_else(|| self.try_report_anon_anon_conflict())
.or_else(|| self.try_report_outlives_closure())
.or_else(|| self.try_report_static_impl_trait())
.or_else(|| self.try_report_impl_not_conforming_to_trait())
}
Expand Down
Loading