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 10 pull requests #54796

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fcda7b2
Add doc for impl From for Std Error
phungleson Sep 5, 2018
a7cc1fc
Examples for docs
phungleson Sep 25, 2018
0626afb
First stab at fixing #54505
pawroman Sep 29, 2018
53a4b39
handle outlives predicates in trait evaluation
arielb1 Sep 27, 2018
9d44e9e
enable using the evaluation cache on predicates with LBRs
arielb1 Sep 28, 2018
1069c0e
add a special case for literal `'static: 'a` where-clauses
arielb1 Sep 28, 2018
f7d35cc
Fix range borrowing suggestions logic
pawroman Oct 1, 2018
ec59188
Make spec_extend use for_each()
Lucretiel Oct 2, 2018
87bf9e2
Address review comments
pawroman Oct 2, 2018
84f75f0
Fix typo in CONTRIBUTING.md
Oct 2, 2018
30f2e96
Remove main() in examples
phungleson Oct 2, 2018
d686896
Update a FIXME in memory.rs
wesleywiser Oct 3, 2018
1081bbb
abolish ICE when pretty-printing async block
zackmdavis Oct 3, 2018
611e5c4
Address review comments
pawroman Oct 3, 2018
8327976
Remove duplicate predicates in `explicit_predicates_of`
scalexm Oct 3, 2018
f0de294
A handful of cleanups for rustc/mir
ljedrz Oct 3, 2018
608adfc
Introduce `TyKind::UnnormalizedProjection`
scalexm Oct 3, 2018
edb3f97
Fix `ty::UnnormalizedProjection` in rustdoc
scalexm Oct 3, 2018
d146804
Rollup merge of #53523 - phungleson:fix-impl-from-for-std-error, r=Gu…
pietroalbini Oct 3, 2018
4b267fa
Rollup merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
pietroalbini Oct 3, 2018
36e7d4d
Rollup merge of #54734 - pawroman:fix_range_borrowing_suggestion, r=v…
pietroalbini Oct 3, 2018
11ef111
Rollup merge of #54761 - Lucretiel:patch-1, r=cramertj
pietroalbini Oct 3, 2018
4a2ecc6
Rollup merge of #54769 - jacobherrington:patch-1, r=kennytm
pietroalbini Oct 3, 2018
723f662
Rollup merge of #54773 - rust-lang:wesleywiser-patch-1, r=oli-obk
pietroalbini Oct 3, 2018
bae5784
Rollup merge of #54777 - zackmdavis:async_pretty_ice, r=cramertj
pietroalbini Oct 3, 2018
009f32e
Rollup merge of #54780 - scalexm:dup-predicates, r=nikomatsakis
pietroalbini Oct 3, 2018
db548ea
Rollup merge of #54788 - ljedrz:cleanup_rustc_mir, r=oli-obk
pietroalbini Oct 3, 2018
2848e15
Rollup merge of #54789 - scalexm:unnormalized, r=nikomatsakis
pietroalbini Oct 3, 2018
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 CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ labels to triage issues:
to fix the issue.

* The dark blue **final-comment-period** label marks bugs that are using the
RFC signoff functionality of [rfcbot][rfcbot] and are currenty in the final
RFC signoff functionality of [rfcbot][rfcbot] and are currently in the final
comment period.

* Red, **I**-prefixed labels indicate the **importance** of the issue. The
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1822,12 +1822,12 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
unsafe {
let mut ptr = self.as_mut_ptr().add(self.len());
let mut local_len = SetLenOnDrop::new(&mut self.len);
for element in iterator {
iterator.for_each(move |element| {
ptr::write(ptr, element);
ptr = ptr.offset(1);
// NB can't overflow since we would have had to alloc the address space
local_len.increment_len(1);
}
});
}
} else {
self.extend_desugared(iterator)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ for ty::TyKind<'gcx>
Tuple(inner_tys) => {
inner_tys.hash_stable(hcx, hasher);
}
Projection(ref projection_ty) => {
projection_ty.hash_stable(hcx, hasher);
Projection(ref data) | UnnormalizedProjection(ref data) => {
data.hash_stable(hcx, hasher);
}
Opaque(def_id, substs) => {
def_id.hash_stable(hcx, hasher);
Expand Down
1 change: 1 addition & 0 deletions src/librustc/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
| ty::Never
| ty::Tuple(..)
| ty::Projection(..)
| ty::UnnormalizedProjection(..)
| ty::Foreign(..)
| ty::Param(..)
| ty::Opaque(..) => {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
ty::Never |
ty::Tuple(..) |
ty::Projection(..) |
ty::UnnormalizedProjection(..) |
ty::Foreign(..) |
ty::Param(..) |
ty::Closure(..) |
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl<'tcx> Scalar {
pub fn from_uint(i: impl Into<u128>, size: Size) -> Self {
let i = i.into();
debug_assert_eq!(truncate(i, size), i,
"Unsigned value {} does not fit in {} bits", i, size.bits());
"Unsigned value {} does not fit in {} bits", i, size.bits());
Scalar::Bits { bits: i, size: size.bytes() as u8 }
}

Expand All @@ -181,7 +181,7 @@ impl<'tcx> Scalar {
// `into` performed sign extension, we have to truncate
let truncated = truncate(i as u128, size);
debug_assert_eq!(sign_extend(truncated, size) as i128, i,
"Signed value {} does not fit in {} bits", i, size.bits());
"Signed value {} does not fit in {} bits", i, size.bits());
Scalar::Bits { bits: truncated, size: size.bytes() as u8 }
}

Expand Down
31 changes: 13 additions & 18 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//!
//! [rustc guide]: https://rust-lang-nursery.github.io/rustc-guide/mir/index.html

use graphviz::IntoCow;
use hir::def::CtorKind;
use hir::def_id::DefId;
use hir::{self, HirId, InlineAsm};
Expand Down Expand Up @@ -327,22 +326,20 @@ impl<'tcx> Mir<'tcx> {
if idx < stmts.len() {
&stmts[idx].source_info
} else {
assert!(idx == stmts.len());
assert_eq!(idx, stmts.len());
&block.terminator().source_info
}
}

/// Check if `sub` is a sub scope of `sup`
pub fn is_sub_scope(&self, mut sub: SourceScope, sup: SourceScope) -> bool {
loop {
if sub == sup {
return true;
}
while sub != sup {
match self.source_scopes[sub].parent_scope {
None => return false,
Some(p) => sub = p,
}
}
true
}

/// Return the return type, it always return first element from `local_decls` array
Expand Down Expand Up @@ -526,9 +523,7 @@ impl BorrowKind {
pub fn allows_two_phase_borrow(&self) -> bool {
match *self {
BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => false,
BorrowKind::Mut {
allow_two_phase_borrow,
} => allow_two_phase_borrow,
BorrowKind::Mut { allow_two_phase_borrow } => allow_two_phase_borrow,
}
}
}
Expand Down Expand Up @@ -1574,42 +1569,42 @@ impl<'tcx> TerminatorKind<'tcx> {
};
fmt_const_val(&mut s, &c).unwrap();
s.into()
}).chain(iter::once(String::from("otherwise").into()))
}).chain(iter::once("otherwise".into()))
.collect()
}
Call {
destination: Some(_),
cleanup: Some(_),
..
} => vec!["return".into_cow(), "unwind".into_cow()],
} => vec!["return".into(), "unwind".into()],
Call {
destination: Some(_),
cleanup: None,
..
} => vec!["return".into_cow()],
} => vec!["return".into()],
Call {
destination: None,
cleanup: Some(_),
..
} => vec!["unwind".into_cow()],
} => vec!["unwind".into()],
Call {
destination: None,
cleanup: None,
..
} => vec![],
Yield { drop: Some(_), .. } => vec!["resume".into_cow(), "drop".into_cow()],
Yield { drop: None, .. } => vec!["resume".into_cow()],
Yield { drop: Some(_), .. } => vec!["resume".into(), "drop".into()],
Yield { drop: None, .. } => vec!["resume".into()],
DropAndReplace { unwind: None, .. } | Drop { unwind: None, .. } => {
vec!["return".into_cow()]
vec!["return".into()]
}
DropAndReplace {
unwind: Some(_), ..
}
| Drop {
unwind: Some(_), ..
} => vec!["return".into_cow(), "unwind".into_cow()],
} => vec!["return".into(), "unwind".into()],
Assert { cleanup: None, .. } => vec!["".into()],
Assert { .. } => vec!["success".into_cow(), "unwind".into_cow()],
Assert { .. } => vec!["success".into(), "unwind".into()],
FalseEdges {
ref imaginary_targets,
..
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> CodegenUnitNameBuilder<'a, 'gcx, 'tcx> {
String::new()
};

let crate_disambiguator = format!("{}", tcx.crate_disambiguator(cnum));
let crate_disambiguator = tcx.crate_disambiguator(cnum).to_string();
// Using a shortened disambiguator of about 40 bits
format!("{}.{}{}",
tcx.crate_name(cnum),
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
assert!(index < adt_def.variants.len());
assert_eq!(adt_def, adt_def1);
PlaceTy::Downcast { adt_def,
substs,
variant_index: index }
substs,
variant_index: index }
}
_ => {
bug!("cannot downcast non-ADT type: `{:?}`", self)
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'tcx> Place<'tcx> {
}
},
_ => None,
}
}
_ => None,
}
}
Expand Down Expand Up @@ -255,9 +255,9 @@ impl<'tcx> Operand<'tcx> {

impl<'tcx> BinOp {
pub fn ty<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
lhs_ty: Ty<'tcx>,
rhs_ty: Ty<'tcx>)
-> Ty<'tcx> {
lhs_ty: Ty<'tcx>,
rhs_ty: Ty<'tcx>)
-> Ty<'tcx> {
// FIXME: handle SIMD correctly
match self {
&BinOp::Add | &BinOp::Sub | &BinOp::Mul | &BinOp::Div | &BinOp::Rem |
Expand Down
1 change: 1 addition & 0 deletions src/librustc/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ fn ty_is_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> bool {

ty::Error => true,

ty::UnnormalizedProjection(..) |
ty::Closure(..) |
ty::Generator(..) |
ty::GeneratorWitness(..) |
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
ty::Generator(..) => Some(18),
ty::Foreign(..) => Some(19),
ty::GeneratorWitness(..) => Some(20),
ty::Infer(..) | ty::Error => None
ty::Infer(..) | ty::Error => None,
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
ty::Predicate::Trait(ref data) => {
let trait_obligation = obligation.with(data.clone());

if data.is_global() && !data.has_late_bound_regions() {
if data.is_global() {
// no type variables present, can use evaluation for better caching.
// FIXME: consider caching errors too.
if self.selcx.infcx().predicate_must_hold(&obligation) {
Expand Down Expand Up @@ -362,6 +362,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
match binder.no_late_bound_regions() {
// If so, this obligation is an error (for now). Eventually we should be
// able to support additional cases here, like `for<'a> &'a str: 'a`.
// NOTE: this is duplicate-implemented between here and fulfillment.
None => {
ProcessResult::Error(CodeSelectionError(Unimplemented))
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/traits/query/dropck_outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'_, '_, 'tcx>, ty: Ty<'tcx>) ->
| ty::Opaque(..)
| ty::Infer(_)
| ty::Generator(..) => false,

ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
}
}
94 changes: 90 additions & 4 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,92 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
}
}

ty::Predicate::TypeOutlives(..) | ty::Predicate::RegionOutlives(..) => {
// we do not consider region relationships when
// evaluating trait matches
Ok(EvaluatedToOk)
ty::Predicate::TypeOutlives(ref binder) => {
assert!(!binder.has_escaping_regions());
// Check if the type has higher-ranked regions.
if binder.skip_binder().0.has_escaping_regions() {
// If so, this obligation is an error (for now). Eventually we should be
// able to support additional cases here, like `for<'a> &'a str: 'a`.

// NOTE: this hack is implemented in both trait fulfillment and
// evaluation. If you fix it in one place, make sure you fix it
// in the other.

// We don't want to allow this sort of reasoning in intercrate
// mode, for backwards-compatibility reasons.
if self.intercrate.is_some() {
Ok(EvaluatedToAmbig)
} else {
Ok(EvaluatedToErr)
}
} else {
// If the type has no late bound regions, then if we assign all
// the inference variables in it to be 'static, then the type
// will be 'static itself.
//
// Therefore, `staticize(T): 'a` holds for any `'a`, so this
// obligation is fulfilled. Because evaluation works with
// staticized types (yes I know this is involved with #21974),
// we are 100% OK here.
Ok(EvaluatedToOk)
}
}

ty::Predicate::RegionOutlives(ref binder) => {
let ty::OutlivesPredicate(r_a, r_b) = binder.skip_binder();

if r_a == r_b {
// for<'a> 'a: 'a. OK
Ok(EvaluatedToOk)
} else if **r_a == ty::ReStatic {
// 'static: 'x always holds.
//
// This special case is handled somewhat inconsistently - if we
// have an inference variable that is supposed to be equal to
// `'static`, then we don't allow it to be equated to an LBR,
// but if we have a literal `'static`, then we *do*.
//
// This is actually consistent with how our region inference works.
//
// It would appear that this sort of inconsistency would
// cause "instability" problems with evaluation caching. However,
// evaluation caching is only for trait predicates, and when
// trait predicates create nested obligations, they contain
// inference variables for all the regions in the trait - the
// only way this codepath can be reached from trait predicate
// evaluation is when the user typed an explicit `where 'static: 'a`
// lifetime bound (in which case we want to return EvaluatedToOk).
//
// If we ever want to handle inference variables that might be
// equatable with ReStatic, we need to make sure we are not confused by
// technically-allowed-by-RFC-447-but-probably-should-not-be
// impls such as
// ```Rust
// impl<'a, 's, T> X<'s> for T where T: Debug + 'a, 'a: 's
// ```
Ok(EvaluatedToOk)
} else if r_a.is_late_bound() || r_b.is_late_bound() {
// There is no current way to prove `for<'a> 'a: 'x`
// unless `'a = 'x`, because there are no bounds involving
// lifetimes.

// It might be possible to prove `for<'a> 'x: 'a` by forcing `'x`
// to be `'static`. However, this is not currently done by type
// inference unless `'x` is literally ReStatic. See the comment
// above.

// We don't want to allow this sort of reasoning in intercrate
// mode, for backwards-compatibility reasons.
if self.intercrate.is_some() {
Ok(EvaluatedToAmbig)
} else {
Ok(EvaluatedToErr)
}
} else {
// Relating 2 inference variable regions. These will
// always hold if our query is "staticized".
Ok(EvaluatedToOk)
}
}

ty::Predicate::ObjectSafe(trait_def_id) => {
Expand Down Expand Up @@ -900,6 +982,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
{
debug!("evaluate_stack({:?}) --> recursive",
stack.fresh_trait_ref);

let cycle = stack.iter().skip(1).take(rec_index + 1);
let cycle = cycle.map(|stack| ty::Predicate::Trait(stack.obligation.predicate));
if self.coinductive_match(cycle) {
Expand Down Expand Up @@ -2200,6 +2283,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => None,
ty::Infer(ty::TyVar(_)) => Ambiguous,

ty::UnnormalizedProjection(..) |
ty::Infer(ty::CanonicalTy(_)) |
ty::Infer(ty::FreshTy(_)) |
ty::Infer(ty::FreshIntTy(_)) |
Expand Down Expand Up @@ -2272,6 +2356,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
Ambiguous
}

ty::UnnormalizedProjection(..) |
ty::Infer(ty::CanonicalTy(_)) |
ty::Infer(ty::FreshTy(_)) |
ty::Infer(ty::FreshIntTy(_)) |
Expand Down Expand Up @@ -2310,6 +2395,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
Vec::new()
}

ty::UnnormalizedProjection(..) |
ty::Dynamic(..) |
ty::Param(..) |
ty::Foreign(..) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
self,
Adt, Array, Slice, RawPtr, Ref, FnDef, FnPtr,
Generator, GeneratorWitness, Dynamic, Closure, Tuple,
Param, Infer, Projection, Opaque, Foreign);
Param, Infer, UnnormalizedProjection, Projection, Opaque, Foreign);

println!("Substs interner: #{}", self.interners.substs.borrow().len());
println!("Region interner: #{}", self.interners.region.borrow().len());
Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
ty::Infer(ty::FreshIntTy(_)) => "skolemized integral type".to_string(),
ty::Infer(ty::FreshFloatTy(_)) => "skolemized floating-point type".to_string(),
ty::Projection(_) => "associated type".to_string(),
ty::UnnormalizedProjection(_) => "non-normalized associated type".to_string(),
ty::Param(ref p) => {
if p.is_self() {
"Self".to_string()
Expand Down
Loading