Skip to content

Commit e4dadd6

Browse files
authored
Rollup merge of #108265 - lcnr:cg-error-msg, r=BoxyUwU
"`const` generic" -> "const parameter"
2 parents 133afeb + 2cbe583 commit e4dadd6

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

compiler/rustc_hir_analysis/src/astconv/generics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::astconv::{
66
use crate::errors::AssocTypeBindingNotAllowed;
77
use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
88
use rustc_ast::ast::ParamKindOrd;
9-
use rustc_errors::{struct_span_err, Applicability, Diagnostic, MultiSpan};
9+
use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan};
1010
use rustc_hir as hir;
1111
use rustc_hir::def::{DefKind, Res};
1212
use rustc_hir::def_id::DefId;
@@ -26,7 +26,7 @@ fn generic_arg_mismatch_err(
2626
param: &GenericParamDef,
2727
possible_ordering_error: bool,
2828
help: Option<&str>,
29-
) {
29+
) -> ErrorGuaranteed {
3030
let sess = tcx.sess;
3131
let mut err = struct_span_err!(
3232
sess,
@@ -70,9 +70,9 @@ fn generic_arg_mismatch_err(
7070
) => match path.res {
7171
Res::Err => {
7272
add_braces_suggestion(arg, &mut err);
73-
err.set_primary_message("unresolved item provided when a constant was expected")
73+
return err
74+
.set_primary_message("unresolved item provided when a constant was expected")
7475
.emit();
75-
return;
7676
}
7777
Res::Def(DefKind::TyParam, src_def_id) => {
7878
if let Some(param_local_id) = param.def_id.as_local() {
@@ -81,7 +81,7 @@ fn generic_arg_mismatch_err(
8181
if param_type.is_suggestable(tcx, false) {
8282
err.span_suggestion(
8383
tcx.def_span(src_def_id),
84-
"consider changing this type parameter to be a `const` generic",
84+
"consider changing this type parameter to a const parameter",
8585
format!("const {}: {}", param_name, param_type),
8686
Applicability::MaybeIncorrect,
8787
);
@@ -137,7 +137,7 @@ fn generic_arg_mismatch_err(
137137
}
138138
}
139139

140-
err.emit();
140+
err.emit()
141141
}
142142

143143
/// Creates the relevant generic argument substitutions

tests/ui/const-generics/early/invalid-const-arguments.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@ error[E0747]: type provided when a constant was expected
4949
--> $DIR/invalid-const-arguments.rs:10:19
5050
|
5151
LL | impl<N> Foo for B<N> {}
52-
| ^
53-
|
54-
help: consider changing this type parameter to be a `const` generic
55-
|
56-
LL | impl<const N: u8> Foo for B<N> {}
57-
| ~~~~~~~~~~~
52+
| - ^
53+
| |
54+
| help: consider changing this type parameter to a const parameter: `const N: u8`
5855

5956
error[E0747]: unresolved item provided when a constant was expected
6057
--> $DIR/invalid-const-arguments.rs:14:32

0 commit comments

Comments
 (0)