Skip to content

Commit 1e79819

Browse files
committed
Remove redundant code and rename bindings for consistency
1 parent 003b911 commit 1e79819

File tree

6 files changed

+48
-62
lines changed

6 files changed

+48
-62
lines changed

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,11 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
13821382
&mut self.long_ty_path
13831383
}
13841384

1385+
pub fn with_long_ty_path(mut self, long_ty_path: Option<PathBuf>) -> Self {
1386+
self.long_ty_path = long_ty_path;
1387+
self
1388+
}
1389+
13851390
/// Most `emit_producing_guarantee` functions use this as a starting point.
13861391
fn emit_producing_nothing(mut self) {
13871392
let diag = self.take_diag();

compiler/rustc_trait_selection/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ trait_selection_fps_remove_ref = consider removing the reference
171171
trait_selection_fps_use_ref = consider using a reference
172172
trait_selection_fulfill_req_lifetime = the type `{$ty}` does not fulfill the required lifetime
173173
174-
trait_selection_full_type_written = the full type name has been written to '{$path}'
175-
176174
trait_selection_ignored_diagnostic_option = `{$option_name}` is ignored due to previous definition of `{$option_name}`
177175
.other_label = `{$option_name}` is first declared here
178176
.label = `{$option_name}` is already declared here

compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
436436
infer_subdiags,
437437
multi_suggestions,
438438
bad_label,
439-
was_written: false,
440-
path: Default::default(),
441439
}),
442440
TypeAnnotationNeeded::E0283 => self.dcx().create_err(AmbiguousImpl {
443441
span,
@@ -447,8 +445,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
447445
infer_subdiags,
448446
multi_suggestions,
449447
bad_label,
450-
was_written: false,
451-
path: Default::default(),
452448
}),
453449
TypeAnnotationNeeded::E0284 => self.dcx().create_err(AmbiguousReturn {
454450
span,
@@ -458,8 +454,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
458454
infer_subdiags,
459455
multi_suggestions,
460456
bad_label,
461-
was_written: false,
462-
path: Default::default(),
463457
}),
464458
}
465459
}
@@ -496,7 +490,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
496490
return self.bad_inference_failure_err(failure_span, arg_data, error_code);
497491
};
498492

499-
let (source_kind, name, path) = kind.ty_localized_msg(self);
493+
let (source_kind, name, long_ty_path) = kind.ty_localized_msg(self);
500494
let failure_span = if should_label_span && !failure_span.overlaps(span) {
501495
Some(failure_span)
502496
} else {
@@ -629,7 +623,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
629623
}
630624
}
631625
}
632-
match error_code {
626+
let mut err = match error_code {
633627
TypeAnnotationNeeded::E0282 => self.dcx().create_err(AnnotationRequired {
634628
span,
635629
source_kind,
@@ -638,8 +632,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
638632
infer_subdiags,
639633
multi_suggestions,
640634
bad_label: None,
641-
was_written: path.is_some(),
642-
path: path.unwrap_or_default(),
643635
}),
644636
TypeAnnotationNeeded::E0283 => self.dcx().create_err(AmbiguousImpl {
645637
span,
@@ -649,8 +641,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
649641
infer_subdiags,
650642
multi_suggestions,
651643
bad_label: None,
652-
was_written: path.is_some(),
653-
path: path.unwrap_or_default(),
654644
}),
655645
TypeAnnotationNeeded::E0284 => self.dcx().create_err(AmbiguousReturn {
656646
span,
@@ -660,10 +650,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
660650
infer_subdiags,
661651
multi_suggestions,
662652
bad_label: None,
663-
was_written: path.is_some(),
664-
path: path.unwrap_or_default(),
665653
}),
666-
}
654+
};
655+
*err.long_ty_path() = long_ty_path;
656+
err
667657
}
668658
}
669659

@@ -727,22 +717,24 @@ impl<'tcx> InferSource<'tcx> {
727717

728718
impl<'tcx> InferSourceKind<'tcx> {
729719
fn ty_localized_msg(&self, infcx: &InferCtxt<'tcx>) -> (&'static str, String, Option<PathBuf>) {
730-
let mut path = None;
720+
let mut long_ty_path = None;
731721
match *self {
732722
InferSourceKind::LetBinding { ty, .. }
733723
| InferSourceKind::ClosureArg { ty, .. }
734724
| InferSourceKind::ClosureReturn { ty, .. } => {
735725
if ty.is_closure() {
736-
("closure", closure_as_fn_str(infcx, ty), path)
726+
("closure", closure_as_fn_str(infcx, ty), long_ty_path)
737727
} else if !ty.is_ty_or_numeric_infer() {
738-
("normal", infcx.tcx.short_string(ty, &mut path), path)
728+
("normal", infcx.tcx.short_string(ty, &mut long_ty_path), long_ty_path)
739729
} else {
740-
("other", String::new(), path)
730+
("other", String::new(), long_ty_path)
741731
}
742732
}
743733
// FIXME: We should be able to add some additional info here.
744734
InferSourceKind::GenericArg { .. }
745-
| InferSourceKind::FullyQualifiedMethodCall { .. } => ("other", String::new(), path),
735+
| InferSourceKind::FullyQualifiedMethodCall { .. } => {
736+
("other", String::new(), long_ty_path)
737+
}
746738
}
747739
}
748740
}

compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
169169

170170
let predicate = self.resolve_vars_if_possible(obligation.predicate);
171171
let span = obligation.cause.span;
172-
let mut file = None;
172+
let mut long_ty_path = None;
173173

174174
debug!(?predicate, obligation.cause.code = ?obligation.cause.code());
175175

@@ -211,19 +211,18 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
211211
self.tcx.as_lang_item(trait_pred.def_id()),
212212
Some(LangItem::Sized | LangItem::MetaSized)
213213
) {
214-
match self.tainted_by_errors() {
215-
None => {
216-
let err = self.emit_inference_failure_err(
214+
return match self.tainted_by_errors() {
215+
None => self
216+
.emit_inference_failure_err(
217217
obligation.cause.body_id,
218218
span,
219219
trait_pred.self_ty().skip_binder().into(),
220220
TypeAnnotationNeeded::E0282,
221221
false,
222-
);
223-
return err.emit();
224-
}
225-
Some(e) => return e,
226-
}
222+
)
223+
.emit(),
224+
Some(e) => e,
225+
};
227226
}
228227

229228
// Typically, this ambiguity should only happen if
@@ -260,8 +259,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
260259
span,
261260
E0283,
262261
"type annotations needed: cannot satisfy `{}`",
263-
self.tcx.short_string(predicate, &mut file),
262+
self.tcx.short_string(predicate, &mut long_ty_path),
264263
)
264+
.with_long_ty_path(long_ty_path)
265265
};
266266

267267
let mut ambiguities = compute_applicable_impls_for_diagnostics(
@@ -307,7 +307,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
307307
err.cancel();
308308
return e;
309309
}
310-
let pred = self.tcx.short_string(predicate, &mut file);
310+
let pred = self.tcx.short_string(predicate, &mut err.long_ty_path());
311311
err.note(format!("cannot satisfy `{pred}`"));
312312
let impl_candidates =
313313
self.find_similar_impl_candidates(predicate.as_trait_clause().unwrap());
@@ -512,6 +512,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
512512
true,
513513
)
514514
}
515+
515516
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
516517
if let Err(e) = predicate.error_reported() {
517518
return e;
@@ -536,7 +537,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
536537
.filter_map(ty::GenericArg::as_term)
537538
.chain([data.term])
538539
.find(|g| g.has_non_region_infer());
539-
let predicate = self.tcx.short_string(predicate, &mut file);
540+
let predicate = self.tcx.short_string(predicate, &mut long_ty_path);
540541
if let Some(term) = term {
541542
self.emit_inference_failure_err(
542543
obligation.cause.body_id,
@@ -546,6 +547,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
546547
true,
547548
)
548549
.with_note(format!("cannot satisfy `{predicate}`"))
550+
.with_long_ty_path(long_ty_path)
549551
} else {
550552
// If we can't find a generic parameter, just print a generic error
551553
struct_span_code_err!(
@@ -555,6 +557,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
555557
"type annotations needed: cannot satisfy `{predicate}`",
556558
)
557559
.with_span_label(span, format!("cannot satisfy `{predicate}`"))
560+
.with_long_ty_path(long_ty_path)
558561
}
559562
}
560563

@@ -568,24 +571,24 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
568571
let term =
569572
data.walk().filter_map(ty::GenericArg::as_term).find(|term| term.is_infer());
570573
if let Some(term) = term {
571-
let err = self.emit_inference_failure_err(
574+
self.emit_inference_failure_err(
572575
obligation.cause.body_id,
573576
span,
574577
term,
575578
TypeAnnotationNeeded::E0284,
576579
true,
577-
);
578-
err
580+
)
579581
} else {
580582
// If we can't find a generic parameter, just print a generic error
581-
let predicate = self.tcx.short_string(predicate, &mut file);
583+
let predicate = self.tcx.short_string(predicate, &mut long_ty_path);
582584
struct_span_code_err!(
583585
self.dcx(),
584586
span,
585587
E0284,
586588
"type annotations needed: cannot satisfy `{predicate}`",
587589
)
588590
.with_span_label(span, format!("cannot satisfy `{predicate}`"))
591+
.with_long_ty_path(long_ty_path)
589592
}
590593
}
591594

@@ -597,61 +600,59 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
597600
TypeAnnotationNeeded::E0284,
598601
true,
599602
),
603+
600604
ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })
601605
if term.is_infer() =>
602606
{
603607
if let Some(e) = self.tainted_by_errors() {
604608
return e;
605609
}
606-
let alias = self.tcx.short_string(alias, &mut file);
610+
let alias = self.tcx.short_string(alias, &mut long_ty_path);
607611
struct_span_code_err!(
608612
self.dcx(),
609613
span,
610614
E0284,
611615
"type annotations needed: cannot normalize `{alias}`",
612616
)
613617
.with_span_label(span, format!("cannot normalize `{alias}`"))
618+
.with_long_ty_path(long_ty_path)
614619
}
620+
615621
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(sym)) => {
616622
if let Some(e) = self.tainted_by_errors() {
617623
return e;
618624
}
619625

620-
let mut err;
621-
622626
if self.tcx.features().staged_api() {
623-
err = self.dcx().struct_span_err(
627+
self.dcx().struct_span_err(
624628
span,
625629
format!("unstable feature `{sym}` is used without being enabled."),
626-
);
627-
628-
err.help(format!("The feature can be enabled by marking the current item with `#[unstable_feature_bound({sym})]`"));
630+
).with_help(format!("The feature can be enabled by marking the current item with `#[unstable_feature_bound({sym})]`"))
629631
} else {
630-
err = feature_err_unstable_feature_bound(
632+
feature_err_unstable_feature_bound(
631633
&self.tcx.sess,
632634
sym,
633635
span,
634636
format!("use of unstable library feature `{sym}`"),
635-
);
637+
)
636638
}
637-
err
638639
}
639640

640641
_ => {
641642
if let Some(e) = self.tainted_by_errors() {
642643
return e;
643644
}
644-
let predicate = self.tcx.short_string(predicate, &mut file);
645+
let predicate = self.tcx.short_string(predicate, &mut long_ty_path);
645646
struct_span_code_err!(
646647
self.dcx(),
647648
span,
648649
E0284,
649650
"type annotations needed: cannot satisfy `{predicate}`",
650651
)
651652
.with_span_label(span, format!("cannot satisfy `{predicate}`"))
653+
.with_long_ty_path(long_ty_path)
652654
}
653655
};
654-
*err.long_ty_path() = file;
655656
self.note_obligation_cause(&mut err, obligation);
656657
err.emit()
657658
}

compiler/rustc_trait_selection/src/errors.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::path::PathBuf;
2-
31
use rustc_ast::Path;
42
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
53
use rustc_errors::codes::*;
@@ -224,9 +222,6 @@ pub struct AnnotationRequired<'a> {
224222
pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
225223
#[subdiagnostic]
226224
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
227-
#[note(trait_selection_full_type_written)]
228-
pub was_written: bool,
229-
pub path: PathBuf,
230225
}
231226

232227
// Copy of `AnnotationRequired` for E0283
@@ -245,9 +240,6 @@ pub struct AmbiguousImpl<'a> {
245240
pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
246241
#[subdiagnostic]
247242
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
248-
#[note(trait_selection_full_type_written)]
249-
pub was_written: bool,
250-
pub path: PathBuf,
251243
}
252244

253245
// Copy of `AnnotationRequired` for E0284
@@ -266,9 +258,6 @@ pub struct AmbiguousReturn<'a> {
266258
pub infer_subdiags: Vec<SourceKindSubdiag<'a>>,
267259
#[subdiagnostic]
268260
pub multi_suggestions: Vec<SourceKindMultiSuggestion<'a>>,
269-
#[note(trait_selection_full_type_written)]
270-
pub was_written: bool,
271-
pub path: PathBuf,
272261
}
273262

274263
// Used when a better one isn't available

tests/ui/inference/really-long-type-in-let-binding-without-sufficient-type-info.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error[E0282]: type annotations needed for `Result<_, (((..., ..., ..., ...), ...
44
LL | let y = Err(x);
55
| ^ ------ type must be known at this point
66
|
7-
= note: the full type name has been written to '$TEST_BUILD_DIR/really-long-type-in-let-binding-without-sufficient-type-info.long-type-$LONG_TYPE_HASH.txt'
7+
= note: the full name for the type has been written to '$TEST_BUILD_DIR/really-long-type-in-let-binding-without-sufficient-type-info.long-type-$LONG_TYPE_HASH.txt'
8+
= note: consider using `--verbose` to print the full type name to the console
89
help: consider giving `y` an explicit type, where the type for type parameter `T` is specified
910
|
1011
LL | let y: Result<T, _> = Err(x);

0 commit comments

Comments
 (0)