Skip to content

Commit 6d154af

Browse files
committed
Auto merge of #28393 - arielb1:required-because-it-appears, r=nikomatsakis
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 ``` Fixes #21793 Fixes #23286 r? @nikomatsakis
2 parents 8320345 + 38f76db commit 6d154af

File tree

2 files changed

+46
-41
lines changed

2 files changed

+46
-41
lines changed

src/librustc/middle/traits/error_reporting.rs

+46-40
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
207207
let custom_note = report_on_unimplemented(infcx, &trait_ref.0,
208208
obligation.cause.span);
209209
if let Some(s) = custom_note {
210-
infcx.tcx.sess.span_note(obligation.cause.span, &s);
210+
infcx.tcx.sess.fileline_note(obligation.cause.span, &s);
211211
}
212212
note_obligation_cause(infcx, obligation);
213213
}
@@ -305,29 +305,29 @@ pub fn report_object_safety_error<'tcx>(tcx: &ty::ctxt<'tcx>,
305305
for violation in object_safety_violations(tcx, trait_def_id) {
306306
match violation {
307307
ObjectSafetyViolation::SizedSelf => {
308-
tcx.sess.span_note(
308+
tcx.sess.fileline_note(
309309
span,
310310
"the trait cannot require that `Self : Sized`");
311311
}
312312

313313
ObjectSafetyViolation::SupertraitSelf => {
314-
tcx.sess.span_note(
314+
tcx.sess.fileline_note(
315315
span,
316316
"the trait cannot use `Self` as a type parameter \
317317
in the supertrait listing");
318318
}
319319

320320
ObjectSafetyViolation::Method(method,
321321
MethodViolationCode::StaticMethod) => {
322-
tcx.sess.span_note(
322+
tcx.sess.fileline_note(
323323
span,
324324
&format!("method `{}` has no receiver",
325325
method.name));
326326
}
327327

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

337337
ObjectSafetyViolation::Method(method,
338338
MethodViolationCode::Generic) => {
339-
tcx.sess.span_note(
339+
tcx.sess.fileline_note(
340340
span,
341341
&format!("method `{}` has generic type parameters",
342342
method.name));
@@ -458,111 +458,117 @@ fn note_obligation_cause_code<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
458458
note_obligation_cause_code(infcx, predicate, cause_span, subcode);
459459
}
460460
ObligationCauseCode::SliceOrArrayElem => {
461-
tcx.sess.span_note(
461+
tcx.sess.fileline_note(
462462
cause_span,
463463
&format!("slice and array elements must have `Sized` type"));
464464
}
465465
ObligationCauseCode::ProjectionWf(data) => {
466-
tcx.sess.span_note(
466+
tcx.sess.fileline_note(
467467
cause_span,
468468
&format!("required so that the projection `{}` is well-formed",
469469
data));
470470
}
471471
ObligationCauseCode::ReferenceOutlivesReferent(ref_ty) => {
472-
tcx.sess.span_note(
472+
tcx.sess.fileline_note(
473473
cause_span,
474474
&format!("required so that reference `{}` does not outlive its referent",
475475
ref_ty));
476476
}
477477
ObligationCauseCode::ItemObligation(item_def_id) => {
478478
let item_name = tcx.item_path_str(item_def_id);
479-
tcx.sess.span_note(
479+
tcx.sess.fileline_note(
480480
cause_span,
481481
&format!("required by `{}`", item_name));
482482
}
483483
ObligationCauseCode::ObjectCastObligation(object_ty) => {
484-
tcx.sess.span_note(
484+
tcx.sess.fileline_note(
485485
cause_span,
486486
&format!(
487487
"required for the cast to the object type `{}`",
488488
infcx.ty_to_string(object_ty)));
489489
}
490490
ObligationCauseCode::RepeatVec => {
491-
tcx.sess.span_note(
491+
tcx.sess.fileline_note(
492492
cause_span,
493493
"the `Copy` trait is required because the \
494494
repeated element will be copied");
495495
}
496496
ObligationCauseCode::VariableType(_) => {
497-
tcx.sess.span_note(
497+
tcx.sess.fileline_note(
498498
cause_span,
499499
"all local variables must have a statically known size");
500500
}
501501
ObligationCauseCode::ReturnType => {
502-
tcx.sess.span_note(
502+
tcx.sess.fileline_note(
503503
cause_span,
504504
"the return type of a function must have a \
505505
statically known size");
506506
}
507507
ObligationCauseCode::AssignmentLhsSized => {
508-
tcx.sess.span_note(
508+
tcx.sess.fileline_note(
509509
cause_span,
510510
"the left-hand-side of an assignment must have a statically known size");
511511
}
512512
ObligationCauseCode::StructInitializerSized => {
513-
tcx.sess.span_note(
513+
tcx.sess.fileline_note(
514514
cause_span,
515515
"structs must have a statically known size to be initialized");
516516
}
517-
ObligationCauseCode::ClosureCapture(var_id, closure_span, builtin_bound) => {
517+
ObligationCauseCode::ClosureCapture(var_id, _, builtin_bound) => {
518518
let def_id = tcx.lang_items.from_builtin_kind(builtin_bound).unwrap();
519519
let trait_name = tcx.item_path_str(def_id);
520520
let name = tcx.local_var_name_str(var_id);
521-
span_note!(tcx.sess, closure_span,
522-
"the closure that captures `{}` requires that all captured variables \
523-
implement the trait `{}`",
524-
name,
525-
trait_name);
521+
tcx.sess.fileline_note(
522+
cause_span,
523+
&format!("the closure that captures `{}` requires that all captured variables \
524+
implement the trait `{}`",
525+
name,
526+
trait_name));
526527
}
527528
ObligationCauseCode::FieldSized => {
528-
span_note!(tcx.sess, cause_span,
529-
"only the last field of a struct or enum variant \
530-
may have a dynamically sized type")
529+
tcx.sess.fileline_note(
530+
cause_span,
531+
"only the last field of a struct or enum variant \
532+
may have a dynamically sized type");
531533
}
532534
ObligationCauseCode::SharedStatic => {
533-
span_note!(tcx.sess, cause_span,
534-
"shared static variables must have a type that implements `Sync`");
535+
tcx.sess.fileline_note(
536+
cause_span,
537+
"shared static variables must have a type that implements `Sync`");
535538
}
536539
ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
537540
let parent_trait_ref = infcx.resolve_type_vars_if_possible(&data.parent_trait_ref);
538-
span_note!(tcx.sess, cause_span,
539-
"required because it appears within the type `{}`",
540-
parent_trait_ref.0.self_ty());
541+
tcx.sess.fileline_note(
542+
cause_span,
543+
&format!("required because it appears within the type `{}`",
544+
parent_trait_ref.0.self_ty()));
541545
let parent_predicate = parent_trait_ref.to_predicate();
542546
note_obligation_cause_code(infcx, &parent_predicate, cause_span, &*data.parent_code);
543547
}
544548
ObligationCauseCode::ImplDerivedObligation(ref data) => {
545549
let parent_trait_ref = infcx.resolve_type_vars_if_possible(&data.parent_trait_ref);
546-
span_note!(tcx.sess, cause_span,
547-
"required because of the requirements on the impl of `{}` for `{}`",
548-
parent_trait_ref,
549-
parent_trait_ref.0.self_ty());
550+
tcx.sess.fileline_note(
551+
cause_span,
552+
&format!("required because of the requirements on the impl of `{}` for `{}`",
553+
parent_trait_ref,
554+
parent_trait_ref.0.self_ty()));
550555
let parent_predicate = parent_trait_ref.to_predicate();
551556
note_obligation_cause_code(infcx, &parent_predicate, cause_span, &*data.parent_code);
552557
}
553558
ObligationCauseCode::CompareImplMethodObligation => {
554-
span_note!(tcx.sess, cause_span,
555-
"the requirement `{}` appears on the impl method \
556-
but not on the corresponding trait method",
557-
predicate);
559+
tcx.sess.fileline_note(
560+
cause_span,
561+
&format!("the requirement `{}` appears on the impl method \
562+
but not on the corresponding trait method",
563+
predicate));
558564
}
559565
}
560566
}
561567

562-
pub fn suggest_new_overflow_limit(tcx: &ty::ctxt, span: Span) {
568+
fn suggest_new_overflow_limit(tcx: &ty::ctxt, span: Span) {
563569
let current_limit = tcx.sess.recursion_limit.get();
564570
let suggested_limit = current_limit * 2;
565-
tcx.sess.span_note(
571+
tcx.sess.fileline_note(
566572
span,
567573
&format!(
568574
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",

src/librustc/middle/traits/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub use self::error_reporting::report_fulfillment_errors;
2929
pub use self::error_reporting::report_overflow_error;
3030
pub use self::error_reporting::report_selection_error;
3131
pub use self::error_reporting::report_object_safety_error;
32-
pub use self::error_reporting::suggest_new_overflow_limit;
3332
pub use self::coherence::orphan_check;
3433
pub use self::coherence::overlapping_impls;
3534
pub use self::coherence::OrphanCheckErr;

0 commit comments

Comments
 (0)