Skip to content

Commit

Permalink
Use constraint span when lowering associated types
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Aug 19, 2019
1 parent f86521e commit 94ee54c
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 189 deletions.
6 changes: 3 additions & 3 deletions src/librustc/hir/lowering.rs
Expand Up @@ -72,7 +72,7 @@ use syntax::symbol::{kw, sym, Symbol};
use syntax::tokenstream::{TokenStream, TokenTree};
use syntax::parse::token::{self, Token};
use syntax::visit::{self, Visitor};
use syntax_pos::{DUMMY_SP, Span};
use syntax_pos::Span;

const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;

Expand Down Expand Up @@ -1094,15 +1094,15 @@ impl<'a> LoweringContext<'a> {
impl_trait_node_id,
DefPathData::ImplTrait,
ExpnId::root(),
DUMMY_SP
c.span,
);

self.with_dyn_type_scope(false, |this| {
let ty = this.lower_ty(
&Ty {
id: this.sess.next_node_id(),
node: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
span: DUMMY_SP,
span: c.span,
},
itctx,
);
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/infer/opaque_types/mod.rs
Expand Up @@ -127,8 +127,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
debug!(
"instantiate_opaque_types(value={:?}, parent_def_id={:?}, body_id={:?}, \
param_env={:?})",
value, parent_def_id, body_id, param_env,
param_env={:?}, value_span={:?})",
value, parent_def_id, body_id, param_env, value_span,
);
let mut instantiator = Instantiator {
infcx: self,
Expand Down Expand Up @@ -1111,6 +1111,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
return opaque_defn.concrete_ty;
}
let span = tcx.def_span(def_id);
debug!("fold_opaque_ty {:?} {:?}", self.value_span, span);
let ty_var = infcx
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span });

Expand Down
17 changes: 10 additions & 7 deletions src/librustc/traits/fulfill.rs
Expand Up @@ -248,10 +248,10 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
/// This is always inlined, despite its size, because it has a single
/// callsite and it is called *very* frequently.
#[inline(always)]
fn process_obligation(&mut self,
pending_obligation: &mut Self::Obligation)
-> ProcessResult<Self::Obligation, Self::Error>
{
fn process_obligation(
&mut self,
pending_obligation: &mut Self::Obligation,
) -> ProcessResult<Self::Obligation, Self::Error> {
// if we were stalled on some unresolved variables, first check
// whether any of them have been resolved; if not, don't bother
// doing more work yet
Expand All @@ -277,7 +277,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
self.selcx.infcx().resolve_vars_if_possible(&obligation.predicate);
}

debug!("process_obligation: obligation = {:?}", obligation);
debug!("process_obligation: obligation = {:?} cause = {:?}", obligation, obligation.cause);

match obligation.predicate {
ty::Predicate::Trait(ref data) => {
Expand Down Expand Up @@ -425,10 +425,13 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}

ty::Predicate::WellFormed(ty) => {
match ty::wf::obligations(self.selcx.infcx(),
match ty::wf::obligations(
self.selcx.infcx(),
obligation.param_env,
obligation.cause.body_id,
ty, obligation.cause.span) {
ty,
obligation.cause.span,
) {
None => {
pending_obligation.stalled_on = vec![ty];
ProcessResult::Unchanged
Expand Down
22 changes: 22 additions & 0 deletions src/test/ui/associated-item/associated-item-type-issue-63594.rs
@@ -0,0 +1,22 @@
#![feature(associated_type_bounds)]

fn main() {}

trait Bar { type Assoc; }

trait Thing {
type Out;
fn func() -> Self::Out;
}

struct AssocNoCopy;
impl Bar for AssocNoCopy { type Assoc = String; }

impl Thing for AssocNoCopy {
type Out = Box<dyn Bar<Assoc: Copy>>;
//~^ ERROR the trait bound `std::string::String: std::marker::Copy` is not satisfied

fn func() -> Self::Out {
Box::new(AssocNoCopy)
}
}
@@ -0,0 +1,11 @@
error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not satisfied
--> $DIR/associated-item-type-issue-63594.rs:16:28
|
LL | type Out = Box<dyn Bar<Assoc: Copy>>;
| ^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::string::String`
|
= note: the return type of a function must have a statically known size

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 94ee54c

Please sign in to comment.