Skip to content

Commit aa30011

Browse files
committed
Auto merge of #44908 - nikomatsakis:beta-20170928, r=alexcrichton
Beta 20170928 Backports of: - Allow unused extern crate again #44825 - macros: fix bug in collecting trait and impl items with derives. #44757 - `--cap-lints allow` switches off `can_emit_warnings` #44627 - Update the libc submodule #44116 - limit and clear cache obligations opportunistically #44269 - clear out projection subobligations after they are processed #43999 - fix logic error in #44269's `prune_cache_value_obligations` #45065 - REVERTS #43543: Cleanup some remains of `hr_lifetime_in_assoc_type` compatibility lint:
2 parents ab2bbf3 + a4923d9 commit aa30011

36 files changed

+653
-175
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ matrix:
9797
- env: IMAGE=dist-arm-linux DEPLOY=1
9898
- env: IMAGE=dist-armhf-linux DEPLOY=1
9999
- env: IMAGE=dist-armv7-linux DEPLOY=1
100-
- env: IMAGE=dist-fuchsia DEPLOY=1
101100
- env: IMAGE=dist-i586-gnu-i686-musl DEPLOY=1
102101
- env: IMAGE=dist-i686-freebsd DEPLOY=1
103102
- env: IMAGE=dist-i686-linux DEPLOY=1

src/bootstrap/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub const CFG_RELEASE_NUM: &str = "1.21.0";
2929
// An optional number to put after the label, e.g. '.2' -> '-beta.2'
3030
// Be sure to make this starts with a dot to conform to semver pre-release
3131
// versions (section 9)
32-
pub const CFG_PRERELEASE_VERSION: &str = ".3";
32+
pub const CFG_PRERELEASE_VERSION: &str = ".4";
3333

3434
pub struct GitInfo {
3535
inner: Option<Info>,

src/liblibc

Submodule liblibc updated 97 files

src/librustc/ich/impls_ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ for ty::RegionParameterDef {
374374
name,
375375
def_id,
376376
index,
377+
issue_32330: _,
377378
pure_wrt_drop
378379
} = *self;
379380

src/librustc/infer/error_reporting/mod.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ use hir::map as hir_map;
6666
use hir::def_id::DefId;
6767
use middle::region;
6868
use traits::{ObligationCause, ObligationCauseCode};
69-
use ty::{self, Region, TyCtxt, TypeFoldable};
69+
use ty::{self, TyCtxt, TypeFoldable};
70+
use ty::{Region, Issue32330};
7071
use ty::error::TypeError;
7172
use syntax::ast::DUMMY_NODE_ID;
7273
use syntax_pos::{Pos, Span};
@@ -714,6 +715,35 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
714715
self.tcx.note_and_explain_type_err(diag, terr, span);
715716
}
716717

718+
pub fn note_issue_32330(&self,
719+
diag: &mut DiagnosticBuilder<'tcx>,
720+
terr: &TypeError<'tcx>)
721+
{
722+
debug!("note_issue_32330: terr={:?}", terr);
723+
match *terr {
724+
TypeError::RegionsInsufficientlyPolymorphic(_, _, Some(box Issue32330 {
725+
fn_def_id, region_name
726+
})) |
727+
TypeError::RegionsOverlyPolymorphic(_, _, Some(box Issue32330 {
728+
fn_def_id, region_name
729+
})) => {
730+
diag.note(
731+
&format!("lifetime parameter `{0}` declared on fn `{1}` \
732+
appears only in the return type, \
733+
but here is required to be higher-ranked, \
734+
which means that `{0}` must appear in both \
735+
argument and return types",
736+
region_name,
737+
self.tcx.item_path_str(fn_def_id)));
738+
diag.note(
739+
&format!("this error is the result of a recent bug fix; \
740+
for more information, see issue #33685 \
741+
<https://github.com/rust-lang/rust/issues/33685>"));
742+
}
743+
_ => {}
744+
}
745+
}
746+
717747
pub fn report_and_explain_type_error(&self,
718748
trace: TypeTrace<'tcx>,
719749
terr: &TypeError<'tcx>)
@@ -733,6 +763,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
733763
}
734764
};
735765
self.note_type_err(&mut diag, &trace.cause, None, Some(trace.values), terr);
766+
self.note_issue_32330(&mut diag, terr);
736767
diag
737768
}
738769

@@ -905,7 +936,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
905936
format!(" for lifetime parameter {}in trait containing associated type `{}`",
906937
br_string(br), self.tcx.associated_item(def_id).name)
907938
}
908-
infer::EarlyBoundRegion(_, name) => {
939+
infer::EarlyBoundRegion(_, name, _) => {
909940
format!(" for lifetime parameter `{}`",
910941
name)
911942
}

src/librustc/infer/higher_ranked/mod.rs

+49-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
1414
use super::{CombinedSnapshot,
1515
InferCtxt,
16+
LateBoundRegion,
1617
HigherRankedType,
18+
RegionVariableOrigin,
1719
SubregionOrigin,
1820
SkolemizationMap};
1921
use super::combine::CombineFields;
@@ -27,6 +29,15 @@ use util::nodemap::{FxHashMap, FxHashSet};
2729

2830
pub struct HrMatchResult<U> {
2931
pub value: U,
32+
33+
/// Normally, when we do a higher-ranked match operation, we
34+
/// expect all higher-ranked regions to be constrained as part of
35+
/// the match operation. However, in the transition period for
36+
/// #32330, it can happen that we sometimes have unconstrained
37+
/// regions that get instantiated with fresh variables. In that
38+
/// case, we collect the set of unconstrained bound regions here
39+
/// and replace them with fresh variables.
40+
pub unconstrained_regions: Vec<ty::BoundRegion>,
3041
}
3142

3243
impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
@@ -97,6 +108,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
97108
/// that do not appear in `T`. If that happens, those regions are
98109
/// unconstrained, and this routine replaces them with `'static`.
99110
pub fn higher_ranked_match<T, U>(&mut self,
111+
span: Span,
100112
a_pair: &Binder<(T, U)>,
101113
b_match: &T,
102114
a_is_expected: bool)
@@ -146,16 +158,28 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
146158
// be any region from the sets above, except for other members of
147159
// `skol_map`. There should always be a representative if things
148160
// are properly well-formed.
161+
let mut unconstrained_regions = vec![];
149162
let skol_representatives: FxHashMap<_, _> =
150163
skol_resolution_map
151164
.iter()
152-
.map(|(&skol, &(_, ref regions))| {
165+
.map(|(&skol, &(br, ref regions))| {
153166
let representative =
154167
regions.iter()
155168
.filter(|&&r| !skol_resolution_map.contains_key(r))
156169
.cloned()
157170
.next()
158-
.expect("no representative region");
171+
.unwrap_or_else(|| { // [1]
172+
unconstrained_regions.push(br);
173+
self.infcx.next_region_var(
174+
LateBoundRegion(span, br, HigherRankedType))
175+
});
176+
177+
// [1] There should always be a representative,
178+
// unless the higher-ranked region did not appear
179+
// in the values being matched. We should reject
180+
// as ill-formed cases that can lead to this, but
181+
// right now we sometimes issue warnings (see
182+
// #32330).
159183

160184
(skol, representative)
161185
})
@@ -192,7 +216,10 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
192216
// We are now done with these skolemized variables.
193217
self.infcx.pop_skolemized(skol_map, snapshot);
194218

195-
Ok(HrMatchResult { value: a_value })
219+
Ok(HrMatchResult {
220+
value: a_value,
221+
unconstrained_regions,
222+
})
196223
});
197224
}
198225

@@ -630,13 +657,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
630657
skol_br,
631658
tainted_region);
632659

633-
return Err(if overly_polymorphic {
660+
let issue_32330 = if let &ty::ReVar(vid) = tainted_region {
661+
match self.region_vars.var_origin(vid) {
662+
RegionVariableOrigin::EarlyBoundRegion(_, _, issue_32330) => {
663+
issue_32330.map(Box::new)
664+
}
665+
_ => None
666+
}
667+
} else {
668+
None
669+
};
670+
671+
if overly_polymorphic {
634672
debug!("Overly polymorphic!");
635-
TypeError::RegionsOverlyPolymorphic(skol_br, tainted_region)
673+
return Err(TypeError::RegionsOverlyPolymorphic(skol_br,
674+
tainted_region,
675+
issue_32330));
636676
} else {
637677
debug!("Not as polymorphic!");
638-
TypeError::RegionsInsufficientlyPolymorphic(skol_br, tainted_region)
639-
})
678+
return Err(TypeError::RegionsInsufficientlyPolymorphic(skol_br,
679+
tainted_region,
680+
issue_32330));
681+
}
640682
}
641683
}
642684

src/librustc/infer/mod.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pub enum RegionVariableOrigin {
299299
Coercion(Span),
300300

301301
// Region variables created as the values for early-bound regions
302-
EarlyBoundRegion(Span, ast::Name),
302+
EarlyBoundRegion(Span, ast::Name, Option<ty::Issue32330>),
303303

304304
// Region variables created for bound regions
305305
// in a function or method that is called
@@ -989,7 +989,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
989989
span: Span,
990990
def: &ty::RegionParameterDef)
991991
-> ty::Region<'tcx> {
992-
self.next_region_var(EarlyBoundRegion(span, def.name))
992+
self.next_region_var(EarlyBoundRegion(span, def.name, def.issue_32330))
993993
}
994994

995995
/// Create a type inference variable for the given
@@ -1160,6 +1160,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11601160
value.fold_with(&mut r)
11611161
}
11621162

1163+
/// Returns true if `T` contains unresolved type variables. In the
1164+
/// process of visiting `T`, this will resolve (where possible)
1165+
/// type variables in `T`, but it never constructs the final,
1166+
/// resolved type, so it's more efficient than
1167+
/// `resolve_type_vars_if_possible()`.
1168+
pub fn any_unresolved_type_vars<T>(&self, value: &T) -> bool
1169+
where T: TypeFoldable<'tcx>
1170+
{
1171+
let mut r = resolve::UnresolvedTypeFinder::new(self);
1172+
value.visit_with(&mut r)
1173+
}
1174+
11631175
pub fn resolve_type_and_region_vars_if_possible<T>(&self, value: &T) -> T
11641176
where T: TypeFoldable<'tcx>
11651177
{
@@ -1278,13 +1290,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12781290
-> InferResult<'tcx, HrMatchResult<Ty<'tcx>>>
12791291
{
12801292
let match_pair = match_a.map_bound(|p| (p.projection_ty.trait_ref(self.tcx), p.ty));
1293+
let span = cause.span;
12811294
let trace = TypeTrace {
12821295
cause,
12831296
values: TraitRefs(ExpectedFound::new(true, match_pair.skip_binder().0, match_b))
12841297
};
12851298

12861299
let mut combine = self.combine_fields(trace, param_env);
1287-
let result = combine.higher_ranked_match(&match_pair, &match_b, true)?;
1300+
let result = combine.higher_ranked_match(span, &match_pair, &match_b, true)?;
12881301
Ok(InferOk { value: result, obligations: combine.obligations })
12891302
}
12901303

src/librustc/infer/resolve.rs

+38-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use super::{InferCtxt, FixupError, FixupResult};
1212
use ty::{self, Ty, TyCtxt, TypeFoldable};
13-
use ty::fold::TypeFolder;
13+
use ty::fold::{TypeFolder, TypeVisitor};
1414

1515
///////////////////////////////////////////////////////////////////////////
1616
// OPPORTUNISTIC TYPE RESOLVER
@@ -80,6 +80,43 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticTypeAndRegionResolv
8080
}
8181
}
8282

83+
///////////////////////////////////////////////////////////////////////////
84+
// UNRESOLVED TYPE FINDER
85+
86+
/// The unresolved type **finder** walks your type and searches for
87+
/// type variables that don't yet have a value. They get pushed into a
88+
/// vector. It does not construct the fully resolved type (which might
89+
/// involve some hashing and so forth).
90+
pub struct UnresolvedTypeFinder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
91+
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
92+
}
93+
94+
impl<'a, 'gcx, 'tcx> UnresolvedTypeFinder<'a, 'gcx, 'tcx> {
95+
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>) -> Self {
96+
UnresolvedTypeFinder { infcx }
97+
}
98+
}
99+
100+
impl<'a, 'gcx, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'gcx, 'tcx> {
101+
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
102+
let t = self.infcx.shallow_resolve(t);
103+
if t.has_infer_types() {
104+
if let ty::TyInfer(_) = t.sty {
105+
// Since we called `shallow_resolve` above, this must
106+
// be an (as yet...) unresolved inference variable.
107+
true
108+
} else {
109+
// Otherwise, visit its contents.
110+
t.super_visit_with(self)
111+
}
112+
} else {
113+
// Micro-optimize: no inference types at all Can't have unresolved type
114+
// variables, no need to visit the contents.
115+
false
116+
}
117+
}
118+
}
119+
83120
///////////////////////////////////////////////////////////////////////////
84121
// FULL TYPE RESOLUTION
85122

src/librustc/lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ declare_lint! {
3030

3131
declare_lint! {
3232
pub UNUSED_EXTERN_CRATES,
33-
Warn,
33+
Allow,
3434
"extern crates that are never used"
3535
}
3636

0 commit comments

Comments
 (0)