Skip to content

Commit

Permalink
Auto merge of #28393 - arielb1:required-because-it-appears, r=nikomat…
Browse files Browse the repository at this point in the history
…sakis

new error style:
```
path.rs:4:6: 4:7 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277]
path.rs:4 fn f(p: Path) {}
               ^
path.rs:4:6: 4:7 help: run `rustc --explain E0277` to see a detailed explanation
path.rs:4:6: 4:7 note: `[u8]` does not have a constant size known at compile-time
path.rs:4:6: 4:7 note: required because it appears within the type `std::sys::os_str::Slice`
path.rs:4:6: 4:7 note: required because it appears within the type `std::ffi::os_str::OsStr`
path.rs:4:6: 4:7 note: required because it appears within the type `std::path::Path`
path.rs:4:6: 4:7 note: all local variables must have a statically known size
path.rs:7:5: 7:36 error: the trait `core::marker::Send` is not implemented for the type `alloc::rc::Rc<()>` [E0277]
path.rs:7     foo::<BTreeMap<Rc<()>, Rc<()>>>();
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
path.rs:7:5: 7:36 help: run `rustc --explain E0277` to see a detailed explanation
path.rs:7:5: 7:36 note: `alloc::rc::Rc<()>` cannot be sent between threads safely
path.rs:7:5: 7:36 note: required because it appears within the type `collections::btree::node::Node<alloc::rc::Rc<()>, alloc::rc::Rc<()>>`
path.rs:7:5: 7:36 note: required because it appears within the type `collections::btree::map::BTreeMap<alloc::rc::Rc<()>, alloc::rc::Rc<()>>`
path.rs:7:5: 7:36 note: required by `foo`
error: aborting due to 2 previous errors
```

This improves the #21793/#23286 situation

r? @nikomatsakis
  • Loading branch information
bors committed Sep 15, 2015
2 parents f3e6d31 + 38f76db commit 310ed91
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 41 deletions.
86 changes: 46 additions & 40 deletions src/librustc/middle/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
let custom_note = report_on_unimplemented(infcx, &trait_ref.0,
obligation.cause.span);
if let Some(s) = custom_note {
infcx.tcx.sess.span_note(obligation.cause.span, &s);
infcx.tcx.sess.fileline_note(obligation.cause.span, &s);
}
note_obligation_cause(infcx, obligation);
}
Expand Down Expand Up @@ -305,29 +305,29 @@ pub fn report_object_safety_error<'tcx>(tcx: &ty::ctxt<'tcx>,
for violation in object_safety_violations(tcx, trait_def_id) {
match violation {
ObjectSafetyViolation::SizedSelf => {
tcx.sess.span_note(
tcx.sess.fileline_note(
span,
"the trait cannot require that `Self : Sized`");
}

ObjectSafetyViolation::SupertraitSelf => {
tcx.sess.span_note(
tcx.sess.fileline_note(
span,
"the trait cannot use `Self` as a type parameter \
in the supertrait listing");
}

ObjectSafetyViolation::Method(method,
MethodViolationCode::StaticMethod) => {
tcx.sess.span_note(
tcx.sess.fileline_note(
span,
&format!("method `{}` has no receiver",
method.name));
}

ObjectSafetyViolation::Method(method,
MethodViolationCode::ReferencesSelf) => {
tcx.sess.span_note(
tcx.sess.fileline_note(
span,
&format!("method `{}` references the `Self` type \
in its arguments or return type",
Expand All @@ -336,7 +336,7 @@ pub fn report_object_safety_error<'tcx>(tcx: &ty::ctxt<'tcx>,

ObjectSafetyViolation::Method(method,
MethodViolationCode::Generic) => {
tcx.sess.span_note(
tcx.sess.fileline_note(
span,
&format!("method `{}` has generic type parameters",
method.name));
Expand Down Expand Up @@ -458,111 +458,117 @@ fn note_obligation_cause_code<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
note_obligation_cause_code(infcx, predicate, cause_span, subcode);
}
ObligationCauseCode::SliceOrArrayElem => {
tcx.sess.span_note(
tcx.sess.fileline_note(
cause_span,
&format!("slice and array elements must have `Sized` type"));
}
ObligationCauseCode::ProjectionWf(data) => {
tcx.sess.span_note(
tcx.sess.fileline_note(
cause_span,
&format!("required so that the projection `{}` is well-formed",
data));
}
ObligationCauseCode::ReferenceOutlivesReferent(ref_ty) => {
tcx.sess.span_note(
tcx.sess.fileline_note(
cause_span,
&format!("required so that reference `{}` does not outlive its referent",
ref_ty));
}
ObligationCauseCode::ItemObligation(item_def_id) => {
let item_name = tcx.item_path_str(item_def_id);
tcx.sess.span_note(
tcx.sess.fileline_note(
cause_span,
&format!("required by `{}`", item_name));
}
ObligationCauseCode::ObjectCastObligation(object_ty) => {
tcx.sess.span_note(
tcx.sess.fileline_note(
cause_span,
&format!(
"required for the cast to the object type `{}`",
infcx.ty_to_string(object_ty)));
}
ObligationCauseCode::RepeatVec => {
tcx.sess.span_note(
tcx.sess.fileline_note(
cause_span,
"the `Copy` trait is required because the \
repeated element will be copied");
}
ObligationCauseCode::VariableType(_) => {
tcx.sess.span_note(
tcx.sess.fileline_note(
cause_span,
"all local variables must have a statically known size");
}
ObligationCauseCode::ReturnType => {
tcx.sess.span_note(
tcx.sess.fileline_note(
cause_span,
"the return type of a function must have a \
statically known size");
}
ObligationCauseCode::AssignmentLhsSized => {
tcx.sess.span_note(
tcx.sess.fileline_note(
cause_span,
"the left-hand-side of an assignment must have a statically known size");
}
ObligationCauseCode::StructInitializerSized => {
tcx.sess.span_note(
tcx.sess.fileline_note(
cause_span,
"structs must have a statically known size to be initialized");
}
ObligationCauseCode::ClosureCapture(var_id, closure_span, builtin_bound) => {
ObligationCauseCode::ClosureCapture(var_id, _, builtin_bound) => {
let def_id = tcx.lang_items.from_builtin_kind(builtin_bound).unwrap();
let trait_name = tcx.item_path_str(def_id);
let name = tcx.local_var_name_str(var_id);
span_note!(tcx.sess, closure_span,
"the closure that captures `{}` requires that all captured variables \
implement the trait `{}`",
name,
trait_name);
tcx.sess.fileline_note(
cause_span,
&format!("the closure that captures `{}` requires that all captured variables \
implement the trait `{}`",
name,
trait_name));
}
ObligationCauseCode::FieldSized => {
span_note!(tcx.sess, cause_span,
"only the last field of a struct or enum variant \
may have a dynamically sized type")
tcx.sess.fileline_note(
cause_span,
"only the last field of a struct or enum variant \
may have a dynamically sized type");
}
ObligationCauseCode::SharedStatic => {
span_note!(tcx.sess, cause_span,
"shared static variables must have a type that implements `Sync`");
tcx.sess.fileline_note(
cause_span,
"shared static variables must have a type that implements `Sync`");
}
ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
let parent_trait_ref = infcx.resolve_type_vars_if_possible(&data.parent_trait_ref);
span_note!(tcx.sess, cause_span,
"required because it appears within the type `{}`",
parent_trait_ref.0.self_ty());
tcx.sess.fileline_note(
cause_span,
&format!("required because it appears within the type `{}`",
parent_trait_ref.0.self_ty()));
let parent_predicate = parent_trait_ref.to_predicate();
note_obligation_cause_code(infcx, &parent_predicate, cause_span, &*data.parent_code);
}
ObligationCauseCode::ImplDerivedObligation(ref data) => {
let parent_trait_ref = infcx.resolve_type_vars_if_possible(&data.parent_trait_ref);
span_note!(tcx.sess, cause_span,
"required because of the requirements on the impl of `{}` for `{}`",
parent_trait_ref,
parent_trait_ref.0.self_ty());
tcx.sess.fileline_note(
cause_span,
&format!("required because of the requirements on the impl of `{}` for `{}`",
parent_trait_ref,
parent_trait_ref.0.self_ty()));
let parent_predicate = parent_trait_ref.to_predicate();
note_obligation_cause_code(infcx, &parent_predicate, cause_span, &*data.parent_code);
}
ObligationCauseCode::CompareImplMethodObligation => {
span_note!(tcx.sess, cause_span,
"the requirement `{}` appears on the impl method \
but not on the corresponding trait method",
predicate);
tcx.sess.fileline_note(
cause_span,
&format!("the requirement `{}` appears on the impl method \
but not on the corresponding trait method",
predicate));
}
}
}

pub fn suggest_new_overflow_limit(tcx: &ty::ctxt, span: Span) {
fn suggest_new_overflow_limit(tcx: &ty::ctxt, span: Span) {
let current_limit = tcx.sess.recursion_limit.get();
let suggested_limit = current_limit * 2;
tcx.sess.span_note(
tcx.sess.fileline_note(
span,
&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub use self::error_reporting::report_fulfillment_errors;
pub use self::error_reporting::report_overflow_error;
pub use self::error_reporting::report_selection_error;
pub use self::error_reporting::report_object_safety_error;
pub use self::error_reporting::suggest_new_overflow_limit;
pub use self::coherence::orphan_check;
pub use self::coherence::overlapping_impls;
pub use self::coherence::OrphanCheckErr;
Expand Down

0 comments on commit 310ed91

Please sign in to comment.