Skip to content

Commit cfa3471

Browse files
committed
simplify HR subtyping back to what we did before
A lot of the refactors, however, seem helpful, so leave those in, particularly since we may want to make this change in the future.
1 parent 2eca6d6 commit cfa3471

File tree

9 files changed

+14
-101
lines changed

9 files changed

+14
-101
lines changed

src/librustc/diagnostics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,5 @@ register_diagnostics! {
15791579
E0490, // a value of type `..` is borrowed for too long
15801580
E0491, // in type `..`, reference has a longer lifetime than the data it...
15811581
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
1582-
E0525, // expected a closure that implements `..` but this closure only implements `..`
1583-
E0526, // skolemization subtype
1582+
E0525 // expected a closure that implements `..` but this closure only implements `..`
15841583
}

src/librustc/infer/error_reporting.rs

-16
Original file line numberDiff line numberDiff line change
@@ -919,17 +919,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
919919
"");
920920
err
921921
}
922-
infer::SkolemizeSuccessor(span) => {
923-
let mut err =
924-
struct_span_err!(self.tcx.sess, span, E0526,
925-
"to satisfy higher-ranked bounds, \
926-
a static lifetime is required");
927-
self.tcx.note_and_explain_region(&mut err,
928-
"but the lifetime is only valid for ",
929-
sub,
930-
"");
931-
err
932-
}
933922
}
934923
}
935924

@@ -1817,11 +1806,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
18171806
"...so that references are valid when the destructor \
18181807
runs");
18191808
}
1820-
infer::SkolemizeSuccessor(span) => {
1821-
err.span_note(
1822-
span,
1823-
"...so that higher-ranked bounds are satisfied");
1824-
}
18251809
}
18261810
}
18271811
}

src/librustc/infer/higher_ranked/mod.rs

+2-68
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use super::{CombinedSnapshot,
1515
InferCtxt,
1616
LateBoundRegion,
1717
HigherRankedType,
18-
SubregionOrigin,
1918
SkolemizationMap};
2019
use super::combine::CombineFields;
2120
use super::region_inference::{TaintDirections};
@@ -527,7 +526,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
527526
// be itself or other new variables.
528527
let incoming_taints = self.tainted_regions(snapshot,
529528
skol,
530-
TaintDirections::incoming());
529+
TaintDirections::both());
531530
for &tainted_region in &incoming_taints {
532531
// Each skolemized should only be relatable to itself
533532
// or new variables:
@@ -568,71 +567,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
568567

569568
self.issue_32330_warnings(span, &warnings);
570569

571-
for (_, &skol) in skol_map {
572-
// The outputs from a skolemized variable must all be
573-
// equatable with `'static`.
574-
let outgoing_taints = self.tainted_regions(snapshot,
575-
skol,
576-
TaintDirections::outgoing());
577-
for &tainted_region in &outgoing_taints {
578-
match tainted_region {
579-
ty::ReVar(vid) if new_vars.contains(&vid) => {
580-
// There is a path from a skolemized variable
581-
// to some region variable that doesn't escape
582-
// this snapshot:
583-
//
584-
// [skol] -> [tainted_region]
585-
//
586-
// We can ignore this. The reasoning relies on
587-
// the fact that the preivous loop
588-
// completed. There are two possible cases
589-
// here.
590-
//
591-
// - `tainted_region` eventually reaches a
592-
// skolemized variable, which *must* be `skol`
593-
// (because otherwise we would have already
594-
// returned `Err`). In that case,
595-
// `tainted_region` could be inferred to `skol`.
596-
//
597-
// - `tainted_region` never reaches a
598-
// skolemized variable. In that case, we can
599-
// safely choose `'static` as an upper bound
600-
// incoming edges. This is a conservative
601-
// choice -- the LUB might be one of the
602-
// incoming skolemized variables, which we
603-
// might know by ambient bounds. We can
604-
// consider a more clever choice of upper
605-
// bound later (modulo some theoretical
606-
// breakage).
607-
//
608-
// We used to force such `tainted_region` to be
609-
// `'static`, but that leads to problems when
610-
// combined with `plug_leaks`. If you have a case
611-
// where `[skol] -> [tainted_region] -> [skol]`,
612-
// then `plug_leaks` concludes it should replace
613-
// `'static` with a late-bound region, which is
614-
// clearly wrong. (Well, what actually happens is
615-
// you get assertion failures because it WOULD
616-
// have to replace 'static with a late-bound
617-
// region.)
618-
}
619-
ty::ReSkolemized(..) => {
620-
// the only skolemized region we find in the
621-
// successors of X can be X; if there was another
622-
// region Y, then X would have been in the preds
623-
// of Y, and we would have aborted above
624-
assert_eq!(skol, tainted_region);
625-
}
626-
_ => {
627-
self.region_vars.make_subregion(
628-
SubregionOrigin::SkolemizeSuccessor(span),
629-
ty::ReStatic,
630-
tainted_region);
631-
}
632-
}
633-
}
634-
}
635-
636570
Ok(())
637571
}
638572

@@ -682,7 +616,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
682616
skol_map
683617
.iter()
684618
.flat_map(|(&skol_br, &skol)| {
685-
self.tainted_regions(snapshot, skol, TaintDirections::incoming())
619+
self.tainted_regions(snapshot, skol, TaintDirections::both())
686620
.into_iter()
687621
.map(move |tainted_region| (tainted_region, skol_br))
688622
})

src/librustc/infer/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,6 @@ pub enum SubregionOrigin<'tcx> {
335335

336336
// Region constraint arriving from destructor safety
337337
SafeDestructor(Span),
338-
339-
// When doing a higher-ranked comparison, this region was a
340-
// successor from a skolemized region, which means that it must be
341-
// `'static` to be sound.
342-
SkolemizeSuccessor(Span),
343338
}
344339

345340
/// Places that type/region parameters can appear.
@@ -1775,7 +1770,6 @@ impl<'tcx> SubregionOrigin<'tcx> {
17751770
AddrOf(a) => a,
17761771
AutoBorrow(a) => a,
17771772
SafeDestructor(a) => a,
1778-
SkolemizeSuccessor(a) => a,
17791773
}
17801774
}
17811775
}

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
16991699
lint::builtin::HR_LIFETIME_IN_ASSOC_TYPE,
17001700
ast_ty.id,
17011701
ast_ty.span,
1702-
format!("fn type references lifetime `{}`, \
1702+
format!("return type references lifetime `{}`, \
17031703
which does not appear in the trait input types",
17041704
br_name));
17051705
}

src/libsyntax/ext/quote.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ pub fn expand_quote_expr<'cx>(cx: &'cx mut ExtCtxt,
422422
base::MacEager::expr(expanded)
423423
}
424424

425-
pub fn expand_quote_item<'cx>(cx: &mut ExtCtxt,
425+
pub fn expand_quote_item<'cx>(cx: &'cx mut ExtCtxt,
426426
sp: Span,
427427
tts: &[TokenTree])
428428
-> Box<base::MacResult+'cx> {

src/libsyntax_ext/concat_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use syntax::parse::token;
1717
use syntax::parse::token::str_to_ident;
1818
use syntax::ptr::P;
1919

20-
pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
20+
pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[TokenTree])
2121
-> Box<base::MacResult+'cx> {
2222
if !cx.ecfg.enable_concat_idents() {
2323
feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic,

src/test/compile-fail/hr-subtype.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ macro_rules! check {
5252
//[bound_inv_a_b_vs_bound_inv_a]~^^^ ERROR mismatched types
5353
//[bound_a_b_ret_a_vs_bound_a_ret_a]~^^^^ ERROR mismatched types
5454
//[free_inv_x_vs_free_inv_y]~^^^^^ ERROR mismatched types
55+
//[bound_a_b_vs_bound_a]~^^^^^^ ERROR mismatched types
56+
//[bound_co_a_b_vs_bound_co_a]~^^^^^^^ ERROR mismatched types
57+
//[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^ ERROR mismatched types
58+
//[bound_co_a_co_b_ret_contra_a]~^^^^^^^^^ ERROR mismatched types
5559
}
5660
}
5761
}
@@ -87,6 +91,9 @@ check! { free_inv_x_vs_free_inv_y: (fn(Inv<'x>),
8791
// - if we are covariant, then 'a and 'b can be set to the call-site
8892
// intersection;
8993
// - if we are contravariant, then 'a can be inferred to 'static.
94+
//
95+
// FIXME(#32330) this is true, but we are not currently impl'ing this
96+
// full semantics
9097
check! { bound_a_b_vs_bound_a: (for<'a,'b> fn(&'a u32, &'b u32),
9198
for<'a> fn(&'a u32, &'a u32)) }
9299
check! { bound_co_a_b_vs_bound_co_a: (for<'a,'b> fn(Co<'a>, Co<'b>),
@@ -109,8 +116,4 @@ fn main() {
109116
//[bound_inv_a_vs_bound_inv_b]~^^^ ERROR compilation successful
110117
//[bound_co_a_vs_bound_co_b]~^^^^ ERROR compilation successful
111118
//[free_x_vs_free_x]~^^^^^ ERROR compilation successful
112-
//[bound_a_b_vs_bound_a]~^^^^^^ ERROR compilation successful
113-
//[bound_co_a_b_vs_bound_co_a]~^^^^^^^ ERROR compilation successful
114-
//[bound_contra_a_contra_b_ret_co_a]~^^^^^^^^ ERROR compilation successful
115-
//[bound_co_a_co_b_ret_contra_a]~^^^^^^^^^ ERROR compilation successful
116119
}

src/test/compile-fail/regions-trait-1.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ impl<'a> get_ctxt for has_ctxt<'a> {
2424
// Here an error occurs because we used `&self` but
2525
// the definition used `&`:
2626
fn get_ctxt(&self) -> &'a ctxt {
27-
//~^ ERROR E0308
28-
//~| ERROR E0526
27+
//~^ ERROR E0053
2928
self.c
3029
}
3130

0 commit comments

Comments
 (0)