assign the correct DefId
in nominal_obligations
This commit is contained in:
parent
f8d3f401df
commit
b8402d6a6e
3 changed files with 19 additions and 7 deletions
|
@ -7,8 +7,9 @@ use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
|
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
|
||||||
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
|
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
|
use std::iter;
|
||||||
|
use std::rc::Rc;
|
||||||
/// Returns the set of obligations needed to make `arg` well-formed.
|
/// Returns the set of obligations needed to make `arg` well-formed.
|
||||||
/// If `arg` contains unresolved inference variables, this may include
|
/// If `arg` contains unresolved inference variables, this may include
|
||||||
/// further WF obligations. However, if `arg` IS an unresolved
|
/// further WF obligations. However, if `arg` IS an unresolved
|
||||||
|
@ -616,13 +617,24 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
substs: SubstsRef<'tcx>,
|
substs: SubstsRef<'tcx>,
|
||||||
) -> Vec<traits::PredicateObligation<'tcx>> {
|
) -> Vec<traits::PredicateObligation<'tcx>> {
|
||||||
let predicates = self.infcx.tcx.predicates_of(def_id).instantiate(self.infcx.tcx, substs);
|
let predicates = self.infcx.tcx.predicates_of(def_id);
|
||||||
|
let mut origins = vec![def_id; predicates.predicates.len()];
|
||||||
|
let mut head = predicates;
|
||||||
|
while let Some(parent) = head.parent {
|
||||||
|
head = self.infcx.tcx.predicates_of(parent);
|
||||||
|
origins.extend(iter::repeat(parent).take(head.predicates.len()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let predicates = predicates.instantiate(self.infcx.tcx, substs);
|
||||||
|
debug_assert_eq!(predicates.predicates.len(), origins.len());
|
||||||
|
|
||||||
predicates
|
predicates
|
||||||
.predicates
|
.predicates
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(predicates.spans.into_iter())
|
.zip(predicates.spans.into_iter())
|
||||||
.map(|(pred, span)| {
|
.zip(origins.into_iter().rev())
|
||||||
let cause = self.cause(traits::BindingObligation(def_id, span));
|
.map(|((pred, span), origin_def_id)| {
|
||||||
|
let cause = self.cause(traits::BindingObligation(origin_def_id, span));
|
||||||
traits::Obligation::new(cause, self.param_env, pred)
|
traits::Obligation::new(cause, self.param_env, pred)
|
||||||
})
|
})
|
||||||
.filter(|pred| !pred.has_escaping_bound_vars())
|
.filter(|pred| !pred.has_escaping_bound_vars())
|
||||||
|
|
|
@ -33,7 +33,7 @@ LL | let _ = const_evaluatable_lib::test1::<T>();
|
||||||
::: $DIR/auxiliary/const_evaluatable_lib.rs:6:10
|
::: $DIR/auxiliary/const_evaluatable_lib.rs:6:10
|
||||||
|
|
|
|
||||||
LL | [u8; std::mem::size_of::<T>() - 1]: Sized,
|
LL | [u8; std::mem::size_of::<T>() - 1]: Sized,
|
||||||
| ---------------------------- required by this bound in `test1::{{constant}}#1`
|
| ---------------------------- required by this bound in `test1`
|
||||||
|
|
|
|
||||||
= note: this may fail depending on what value the parameter takes
|
= note: this may fail depending on what value the parameter takes
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ LL | let _ = const_evaluatable_lib::test1::<T>();
|
||||||
::: $DIR/auxiliary/const_evaluatable_lib.rs:4:27
|
::: $DIR/auxiliary/const_evaluatable_lib.rs:4:27
|
||||||
|
|
|
|
||||||
LL | pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1]
|
LL | pub fn test1<T>() -> [u8; std::mem::size_of::<T>() - 1]
|
||||||
| ---------------------------- required by this bound in `test1::{{constant}}#1`
|
| ---------------------------- required by this bound in `test1`
|
||||||
|
|
|
|
||||||
= note: this may fail depending on what value the parameter takes
|
= note: this may fail depending on what value the parameter takes
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error: constant expression depends on a generic parameter
|
||||||
--> $DIR/let-bindings.rs:6:68
|
--> $DIR/let-bindings.rs:6:68
|
||||||
|
|
|
|
||||||
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
|
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `test::{{constant}}#0`
|
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `test`
|
||||||
|
|
|
|
||||||
= help: consider moving this anonymous constant into a `const` function
|
= help: consider moving this anonymous constant into a `const` function
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue