Skip to content

Commit 94ee54c

Browse files
committed
Use constraint span when lowering associated types
1 parent f86521e commit 94ee54c

File tree

9 files changed

+354
-189
lines changed

9 files changed

+354
-189
lines changed

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use syntax::symbol::{kw, sym, Symbol};
7272
use syntax::tokenstream::{TokenStream, TokenTree};
7373
use syntax::parse::token::{self, Token};
7474
use syntax::visit::{self, Visitor};
75-
use syntax_pos::{DUMMY_SP, Span};
75+
use syntax_pos::Span;
7676

7777
const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
7878

@@ -1094,15 +1094,15 @@ impl<'a> LoweringContext<'a> {
10941094
impl_trait_node_id,
10951095
DefPathData::ImplTrait,
10961096
ExpnId::root(),
1097-
DUMMY_SP
1097+
c.span,
10981098
);
10991099

11001100
self.with_dyn_type_scope(false, |this| {
11011101
let ty = this.lower_ty(
11021102
&Ty {
11031103
id: this.sess.next_node_id(),
11041104
node: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
1105-
span: DUMMY_SP,
1105+
span: c.span,
11061106
},
11071107
itctx,
11081108
);

src/librustc/infer/opaque_types/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
127127
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
128128
debug!(
129129
"instantiate_opaque_types(value={:?}, parent_def_id={:?}, body_id={:?}, \
130-
param_env={:?})",
131-
value, parent_def_id, body_id, param_env,
130+
param_env={:?}, value_span={:?})",
131+
value, parent_def_id, body_id, param_env, value_span,
132132
);
133133
let mut instantiator = Instantiator {
134134
infcx: self,
@@ -1111,6 +1111,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
11111111
return opaque_defn.concrete_ty;
11121112
}
11131113
let span = tcx.def_span(def_id);
1114+
debug!("fold_opaque_ty {:?} {:?}", self.value_span, span);
11141115
let ty_var = infcx
11151116
.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span });
11161117

src/librustc/traits/fulfill.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
248248
/// This is always inlined, despite its size, because it has a single
249249
/// callsite and it is called *very* frequently.
250250
#[inline(always)]
251-
fn process_obligation(&mut self,
252-
pending_obligation: &mut Self::Obligation)
253-
-> ProcessResult<Self::Obligation, Self::Error>
254-
{
251+
fn process_obligation(
252+
&mut self,
253+
pending_obligation: &mut Self::Obligation,
254+
) -> ProcessResult<Self::Obligation, Self::Error> {
255255
// if we were stalled on some unresolved variables, first check
256256
// whether any of them have been resolved; if not, don't bother
257257
// doing more work yet
@@ -277,7 +277,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
277277
self.selcx.infcx().resolve_vars_if_possible(&obligation.predicate);
278278
}
279279

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

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

427427
ty::Predicate::WellFormed(ty) => {
428-
match ty::wf::obligations(self.selcx.infcx(),
428+
match ty::wf::obligations(
429+
self.selcx.infcx(),
429430
obligation.param_env,
430431
obligation.cause.body_id,
431-
ty, obligation.cause.span) {
432+
ty,
433+
obligation.cause.span,
434+
) {
432435
None => {
433436
pending_obligation.stalled_on = vec![ty];
434437
ProcessResult::Unchanged
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(associated_type_bounds)]
2+
3+
fn main() {}
4+
5+
trait Bar { type Assoc; }
6+
7+
trait Thing {
8+
type Out;
9+
fn func() -> Self::Out;
10+
}
11+
12+
struct AssocNoCopy;
13+
impl Bar for AssocNoCopy { type Assoc = String; }
14+
15+
impl Thing for AssocNoCopy {
16+
type Out = Box<dyn Bar<Assoc: Copy>>;
17+
//~^ ERROR the trait bound `std::string::String: std::marker::Copy` is not satisfied
18+
19+
fn func() -> Self::Out {
20+
Box::new(AssocNoCopy)
21+
}
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not satisfied
2+
--> $DIR/associated-item-type-issue-63594.rs:16:28
3+
|
4+
LL | type Out = Box<dyn Bar<Assoc: Copy>>;
5+
| ^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::string::String`
6+
|
7+
= note: the return type of a function must have a statically known size
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)