Skip to content

Commit 213915b

Browse files
committed
migrate some rustc_borrowck diagnostic
1 parent 6c943ba commit 213915b

File tree

4 files changed

+50
-25
lines changed

4 files changed

+50
-25
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern crate tracing;
1818

1919
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2020
use rustc_data_structures::graph::dominators::Dominators;
21-
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
21+
use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
2222
use rustc_hir as hir;
2323
use rustc_hir::def_id::LocalDefId;
2424
use rustc_index::bit_set::ChunkedBitSet;
@@ -424,17 +424,12 @@ fn do_mir_borrowck<'a, 'tcx>(
424424
continue;
425425
}
426426

427-
tcx.struct_span_lint_hir(UNUSED_MUT, lint_root, span, |lint| {
428-
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
429-
lint.build("variable does not need to be mutable")
430-
.span_suggestion_short(
431-
mut_span,
432-
"remove this `mut`",
433-
"",
434-
Applicability::MachineApplicable,
435-
)
436-
.emit();
437-
})
427+
tcx.emit_spanned_lint(
428+
UNUSED_MUT,
429+
lint_root,
430+
span,
431+
session_diagnostics::VarBetterNotMut { span },
432+
)
438433
}
439434

440435
let tainted_by_errors = mbcx.emit_errors();

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use rustc_span::Span;
1616
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
1717
use rustc_trait_selection::traits::TraitEngineExt as _;
1818

19+
use crate::session_diagnostics::ConstNotUsedTraitAlias;
20+
1921
use super::RegionInferenceContext;
2022

2123
impl<'tcx> RegionInferenceContext<'tcx> {
@@ -639,17 +641,11 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
639641
Some(GenericArgKind::Const(c1)) => c1,
640642
Some(u) => panic!("const mapped to unexpected kind: {:?}", u),
641643
None => {
642-
self.tcx
643-
.sess
644-
.struct_span_err(
645-
self.span,
646-
&format!(
647-
"const parameter `{}` is part of concrete type but not \
648-
used in parameter list for the `impl Trait` type alias",
649-
ct
650-
),
651-
)
652-
.emit();
644+
//FIXME!
645+
self.tcx.sess.emit_err(ConstNotUsedTraitAlias {
646+
ct: ct.to_string(),
647+
span: self.span,
648+
});
653649

654650
self.tcx().const_error(ct.ty())
655651
}

compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
1+
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
22
use rustc_middle::ty::Ty;
33
use rustc_span::Span;
44

5+
#[derive(SessionDiagnostic)]
6+
#[error(borrowck::move_borrowed, code = "E0505")]
7+
pub(crate) struct MoveBorrowed<'cx> {
8+
#[primary_span]
9+
pub span: Span,
10+
pub desc: &'cx str,
11+
}
12+
513
#[derive(SessionDiagnostic)]
614
#[error(borrowck::move_unsized, code = "E0161")]
715
pub(crate) struct MoveUnsized<'tcx> {
@@ -42,3 +50,18 @@ pub(crate) struct GenericDoesNotLiveLongEnough {
4250
#[primary_span]
4351
pub span: Span,
4452
}
53+
54+
#[derive(LintDiagnostic)]
55+
#[lint(borrowck::var_better_not_mut)]
56+
pub(crate) struct VarBetterNotMut {
57+
#[suggestion_short(applicability = "machine-applicable", code = "")]
58+
pub span: Span,
59+
}
60+
61+
#[derive(SessionDiagnostic)]
62+
#[error(borrowck::const_not_used_in_type_alias)]
63+
pub(crate) struct ConstNotUsedTraitAlias {
64+
pub ct: String,
65+
#[primary_span]
66+
pub span: Span,
67+
}

compiler/rustc_error_messages/locales/en-US/borrowck.ftl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,15 @@ borrowck_higher_ranked_subtype_error =
1515
higher-ranked subtype error
1616
1717
generic_does_not_live_long_enough =
18-
`{$kind}` does not live long enough
18+
`{$kind}` does not live long enough
19+
20+
borrowck_move_borrowed =
21+
cannot move out of `{$desc}` beacause it is borrowed
22+
23+
borrowck_var_better_not_mut =
24+
variable does not need to be mutable
25+
.suggestion = remove this `mut`
26+
27+
borrowck_const_not_used_in_type_alias =
28+
const parameter `{$ct}` is part of concrete type but not \
29+
used in parameter list for the `impl Trait` type alias

0 commit comments

Comments
 (0)