Skip to content

Commit 5c13041

Browse files
committed
review comments
1 parent ef09db0 commit 5c13041

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

src/librustc/traits/error_reporting.rs

+24-10
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
457457
err
458458
}
459459

460+
461+
/// Get the parent trait chain start
462+
fn get_parent_trait_ref(&self, code: &ObligationCauseCode<'tcx>) -> Option<String> {
463+
match code {
464+
&ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
465+
let parent_trait_ref = self.resolve_type_vars_if_possible(
466+
&data.parent_trait_ref);
467+
match self.get_parent_trait_ref(&data.parent_code) {
468+
Some(t) => Some(t),
469+
None => Some(format!("{}", parent_trait_ref.0.self_ty())),
470+
}
471+
}
472+
_ => None,
473+
}
474+
}
475+
460476
pub fn report_selection_error(&self,
461477
obligation: &PredicateObligation<'tcx>,
462478
error: &SelectionError<'tcx>)
463479
{
464480
let span = obligation.cause.span;
481+
465482
let mut err = match *error {
466483
SelectionError::Unimplemented => {
467484
if let ObligationCauseCode::CompareImplMethodObligation {
@@ -486,16 +503,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
486503
return;
487504
} else {
488505
let trait_ref = trait_predicate.to_poly_trait_ref();
489-
490-
let (post_message, pre_message) =
491-
if let ObligationCauseCode::BuiltinDerivedObligation(ref data)
492-
= obligation.cause.code {
493-
let parent_trait_ref = self.resolve_type_vars_if_possible(
494-
&data.parent_trait_ref);
495-
(format!(" in `{}`", parent_trait_ref.0.self_ty()),
496-
format!("within `{}`, ", parent_trait_ref.0.self_ty()))
497-
} else {
498-
(String::new(), String::new())
506+
let (post_message, pre_message) = match self.get_parent_trait_ref(
507+
&obligation.cause.code)
508+
{
509+
Some(t) => {
510+
(format!(" in `{}`", t), format!("within `{}`, ", t))
511+
}
512+
None => (String::new(), String::new()),
499513
};
500514
let mut err = struct_span_err!(
501515
self.tcx.sess,

src/test/compile-fail/E0277-2.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo {
12+
bar: Bar
13+
}
14+
15+
struct Bar {
16+
baz: Baz
17+
}
18+
19+
struct Baz {
20+
x: *const u8
21+
}
22+
23+
fn is_send<T: Send>() { }
24+
25+
fn main() {
26+
is_send::<Foo>();
27+
//~^ ERROR the trait bound `*const u8: std::marker::Send` is not satisfied in `Foo`
28+
//~| NOTE within `Foo`, the trait `std::marker::Send` is not implemented for `*const u8`
29+
//~| NOTE: `*const u8` cannot be sent between threads safely
30+
//~| NOTE: required because it appears within the type `Baz`
31+
//~| NOTE: required because it appears within the type `Bar`
32+
//~| NOTE: required because it appears within the type `Foo`
33+
//~| NOTE: required by `is_send`
34+
}

0 commit comments

Comments
 (0)