Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4bf6116

Browse files
committedFeb 22, 2020
Add to_stringified_ident_guess to Symbol and suggest correct raw identifier in notes and help messages
1 parent 477dac3 commit 4bf6116

File tree

14 files changed

+144
-72
lines changed

14 files changed

+144
-72
lines changed
 

‎src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_hir::def::{DefKind, Namespace};
99
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1010
use rustc_hir::{Body, Expr, ExprKind, FunctionRetTy, HirId, Local, Pat};
1111
use rustc_span::source_map::DesugaringKind;
12-
use rustc_span::symbol::kw;
1312
use rustc_span::Span;
13+
use rustc_span::{symbol::kw, Symbol};
1414
use std::borrow::Cow;
1515

1616
struct FindLocalByTypeVisitor<'a, 'tcx> {
@@ -108,7 +108,7 @@ fn closure_return_type_suggestion(
108108
output: &FunctionRetTy<'_>,
109109
body: &Body<'_>,
110110
descr: &str,
111-
name: &str,
111+
name: Symbol,
112112
ret: &str,
113113
parent_name: Option<String>,
114114
parent_descr: Option<&str>,
@@ -129,7 +129,7 @@ fn closure_return_type_suggestion(
129129
suggestion,
130130
Applicability::HasPlaceholders,
131131
);
132-
err.span_label(span, InferCtxt::missing_type_msg(&name, &descr, parent_name, parent_descr));
132+
err.span_label(span, InferCtxt::missing_type_msg(name, &descr, parent_name, parent_descr));
133133
}
134134

135135
/// Given a closure signature, return a `String` containing a list of all its argument types.
@@ -320,7 +320,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
320320
&decl.output,
321321
&body,
322322
&descr,
323-
&name,
323+
Symbol::intern(&name),
324324
&ret,
325325
parent_name,
326326
parent_descr,
@@ -444,7 +444,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
444444
// Avoid multiple labels pointing at `span`.
445445
err.span_label(
446446
span,
447-
InferCtxt::missing_type_msg(&name, &descr, parent_name, parent_descr),
447+
InferCtxt::missing_type_msg(
448+
Symbol::intern(&name),
449+
&descr,
450+
parent_name,
451+
parent_descr,
452+
),
448453
);
449454
}
450455

@@ -518,17 +523,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
518523
"type inside {} must be known in this context",
519524
kind,
520525
);
521-
err.span_label(span, InferCtxt::missing_type_msg(&name, &descr, parent_name, parent_descr));
526+
err.span_label(
527+
span,
528+
InferCtxt::missing_type_msg(Symbol::intern(&name), &descr, parent_name, parent_descr),
529+
);
522530
err
523531
}
524532

525533
fn missing_type_msg(
526-
type_name: &str,
534+
type_name: Symbol,
527535
descr: &str,
528536
parent_name: Option<String>,
529537
parent_descr: Option<&str>,
530538
) -> Cow<'static, str> {
531-
if type_name == "_" {
539+
if type_name == kw::Underscore {
532540
"cannot infer type".into()
533541
} else {
534542
let parent_desc = if let Some(parent_name) = parent_name {

‎src/librustc/infer/error_reporting/note.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
3636
}
3737
infer::ReborrowUpvar(span, ref upvar_id) => {
3838
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
39-
err.span_note(span, &format!("...so that closure can access `{}`", var_name));
39+
err.span_note(
40+
span,
41+
&format!(
42+
"...so that closure can access `{}`",
43+
var_name.to_stringified_ident_guess()
44+
),
45+
);
4046
}
4147
infer::InfStackClosure(span) => {
4248
err.span_note(span, "...so that closure does not outlive its stack frame");
@@ -53,7 +59,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
5359
&format!(
5460
"...so that captured variable `{}` does not outlive the \
5561
enclosing closure",
56-
self.tcx.hir().name(id)
62+
self.tcx.hir().name(id).to_stringified_ident_guess()
5763
),
5864
);
5965
}

‎src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn deprecation_suggestion(
161161
diag.span_suggestion(
162162
span,
163163
"replace the use of the deprecated item",
164-
suggestion.to_string(),
164+
suggestion.to_stringified_ident_guess(),
165165
Applicability::MachineApplicable,
166166
);
167167
}

‎src/librustc/traits/error_reporting/suggestions.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_hir::def_id::DefId;
1717
use rustc_hir::intravisit::Visitor;
1818
use rustc_hir::Node;
1919
use rustc_span::source_map::SourceMap;
20-
use rustc_span::symbol::{kw, sym};
20+
use rustc_span::symbol::{kw, sym, Symbol};
2121
use rustc_span::{MultiSpan, Span, DUMMY_SP};
2222
use std::fmt;
2323

@@ -143,12 +143,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
143143
{
144144
// Missing generic type parameter bound.
145145
let param_name = self_ty.to_string();
146+
let param = Symbol::intern(&param_name);
146147
let constraint = trait_ref.print_only_trait_path().to_string();
147148
if suggest_constraining_type_param(
148149
self.tcx,
149150
generics,
150151
&mut err,
151-
&param_name,
152+
param,
152153
&constraint,
153154
self.tcx.sess.source_map(),
154155
*span,
@@ -1657,30 +1658,30 @@ pub fn suggest_constraining_type_param(
16571658
tcx: TyCtxt<'_>,
16581659
generics: &hir::Generics<'_>,
16591660
err: &mut DiagnosticBuilder<'_>,
1660-
param_name: &str,
1661+
param_name: Symbol,
16611662
constraint: &str,
16621663
source_map: &SourceMap,
16631664
span: Span,
16641665
def_id: Option<DefId>,
16651666
) -> bool {
16661667
let restrict_msg = "consider further restricting this bound";
16671668
if let Some(param) =
1668-
generics.params.iter().filter(|p| p.name.ident().as_str() == param_name).next()
1669+
generics.params.iter().filter(|p| p.name.ident().as_str() == param_name.as_str()).next()
16691670
{
16701671
if def_id == tcx.lang_items().sized_trait() {
16711672
// Type parameters are already `Sized` by default.
16721673
err.span_label(
16731674
param.span,
16741675
&format!("this type parameter needs to be `{}`", constraint),
16751676
);
1676-
} else if param_name.starts_with("impl ") {
1677+
} else if param_name.as_str().starts_with("impl ") {
16771678
// `impl Trait` in argument:
16781679
// `fn foo(x: impl Trait) {}` → `fn foo(t: impl Trait + Trait2) {}`
16791680
err.span_suggestion(
16801681
param.span,
16811682
restrict_msg,
16821683
// `impl CurrentTrait + MissingTrait`
1683-
format!("{} + {}", param_name, constraint),
1684+
format!("{} + {}", param_name.to_stringified_ident_guess(), constraint),
16841685
Applicability::MachineApplicable,
16851686
);
16861687
} else if generics.where_clause.predicates.is_empty() && param.bounds.is_empty() {
@@ -1690,7 +1691,7 @@ pub fn suggest_constraining_type_param(
16901691
err.span_suggestion(
16911692
param.span,
16921693
"consider restricting this bound",
1693-
format!("{}: {}", param_name, constraint),
1694+
format!("{}: {}", param_name.to_stringified_ident_guess(), constraint),
16941695
Applicability::MachineApplicable,
16951696
);
16961697
} else if !generics.where_clause.predicates.is_empty() {
@@ -1699,8 +1700,11 @@ pub fn suggest_constraining_type_param(
16991700
// `fn foo<T>(t: T) where T: Debug, T: Trait {}`
17001701
err.span_suggestion(
17011702
generics.where_clause.span().unwrap().shrink_to_hi(),
1702-
&format!("consider further restricting type parameter `{}`", param_name),
1703-
format!(", {}: {}", param_name, constraint),
1703+
&format!(
1704+
"consider further restricting type parameter `{}`",
1705+
param_name.to_stringified_ident_guess()
1706+
),
1707+
format!(", {}: {}", param_name.to_stringified_ident_guess(), constraint),
17041708
Applicability::MachineApplicable,
17051709
);
17061710
} else {
@@ -1716,13 +1720,17 @@ pub fn suggest_constraining_type_param(
17161720
err.span_suggestion(
17171721
span,
17181722
restrict_msg,
1719-
format!("{}: {} + ", param_name, constraint),
1723+
format!("{}: {} + ", param_name.to_stringified_ident_guess(), constraint),
17201724
Applicability::MachineApplicable,
17211725
);
17221726
} else {
17231727
err.span_label(
17241728
param.span,
1725-
&format!("consider adding a `where {}: {}` bound", param_name, constraint),
1729+
&format!(
1730+
"consider adding a `where {}: {}` bound",
1731+
param_name.to_stringified_ident_guess(),
1732+
constraint
1733+
),
17261734
);
17271735
}
17281736
}

‎src/librustc_lint/nonstandard_style.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ impl NonCamelCaseTypes {
107107
let name = &ident.name.as_str();
108108

109109
if !is_camel_case(name) {
110-
let msg = format!("{} `{}` should have an upper camel case name", sort, name);
110+
let msg =
111+
format!("{} `{}` should have an upper camel case name", sort, name.to_string());
111112
cx.struct_span_lint(NON_CAMEL_CASE_TYPES, ident.span, &msg)
112113
.span_suggestion(
113114
ident.span,

‎src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
220220
tcx,
221221
generics,
222222
&mut err,
223-
&param.name.as_str(),
223+
param.name,
224224
"Copy",
225225
tcx.sess.source_map(),
226226
span,

‎src/librustc_mir/borrow_check/diagnostics/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
107107
&format!(
108108
"closure cannot be invoked more than once because it moves the \
109109
variable `{}` out of its environment",
110-
name,
110+
name.to_stringified_ident_guess(),
111111
),
112112
);
113113
return;
@@ -129,7 +129,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
129129
&format!(
130130
"closure cannot be moved more than once as it is not `Copy` due to \
131131
moving the variable `{}` out of its environment",
132-
name
132+
name.to_stringified_ident_guess()
133133
),
134134
);
135135
}

‎src/librustc_parse/parser/module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{new_sub_parser_from_file, DirectoryOwnership};
66

77
use rustc_errors::PResult;
88
use rustc_span::source_map::{FileName, SourceMap, Span, DUMMY_SP};
9-
use rustc_span::symbol::sym;
9+
use rustc_span::symbol::{sym, Symbol};
1010
use syntax::ast::{self, Attribute, Crate, Ident, ItemKind, Mod};
1111
use syntax::attr;
1212
use syntax::token::{self, TokenKind};
@@ -170,7 +170,7 @@ impl<'a> Parser<'a> {
170170
&format!(
171171
"... or maybe `use` the module `{}` instead \
172172
of possibly redeclaring it",
173-
paths.name
173+
Symbol::intern(&paths.name).to_stringified_ident_guess()
174174
),
175175
);
176176
}

‎src/librustc_resolve/diagnostics.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ type Res = def::Res<ast::NodeId>;
3333
crate type Suggestion = (Vec<(Span, String)>, String, Applicability);
3434

3535
crate struct TypoSuggestion {
36-
pub candidate: Ident,
36+
pub candidate: Symbol,
3737
pub res: Res,
3838
}
3939

4040
impl TypoSuggestion {
41-
crate fn from_res(candidate: Ident, res: Res) -> TypoSuggestion {
41+
crate fn from_res(candidate: Symbol, res: Res) -> TypoSuggestion {
4242
TypoSuggestion { candidate, res }
4343
}
4444
}
@@ -107,7 +107,7 @@ impl<'a> Resolver<'a> {
107107
if let Some(binding) = resolution.borrow().binding {
108108
let res = binding.res();
109109
if filter_fn(res) {
110-
names.push(TypoSuggestion::from_res(key.ident, res));
110+
names.push(TypoSuggestion::from_res(key.ident.name, res));
111111
}
112112
}
113113
}
@@ -273,7 +273,7 @@ impl<'a> Resolver<'a> {
273273
let help_msg = format!(
274274
"if you meant to match on a variant or a `const` item, consider \
275275
making the path in the pattern qualified: `?::{}`",
276-
name,
276+
name.to_stringified_ident_guess(),
277277
);
278278
err.span_help(span, &help_msg);
279279
}
@@ -509,7 +509,7 @@ impl<'a> Resolver<'a> {
509509
.get(&expn_id)
510510
.into_iter()
511511
.flatten()
512-
.map(|ident| TypoSuggestion::from_res(*ident, res)),
512+
.map(|ident| TypoSuggestion::from_res(ident.name, res)),
513513
);
514514
}
515515
}
@@ -525,9 +525,11 @@ impl<'a> Resolver<'a> {
525525
false,
526526
false,
527527
) {
528-
suggestions.extend(ext.helper_attrs.iter().map(|name| {
529-
TypoSuggestion::from_res(Ident::new(*name, derive.span), res)
530-
}));
528+
suggestions.extend(
529+
ext.helper_attrs
530+
.iter()
531+
.map(|name| TypoSuggestion::from_res(*name, res)),
532+
);
531533
}
532534
}
533535
}
@@ -536,7 +538,8 @@ impl<'a> Resolver<'a> {
536538
if let LegacyScope::Binding(legacy_binding) = legacy_scope {
537539
let res = legacy_binding.binding.res();
538540
if filter_fn(res) {
539-
suggestions.push(TypoSuggestion::from_res(legacy_binding.ident, res))
541+
suggestions
542+
.push(TypoSuggestion::from_res(legacy_binding.ident.name, res))
540543
}
541544
}
542545
}
@@ -554,40 +557,40 @@ impl<'a> Resolver<'a> {
554557
suggestions.extend(
555558
this.registered_attrs
556559
.iter()
557-
.map(|ident| TypoSuggestion::from_res(*ident, res)),
560+
.map(|ident| TypoSuggestion::from_res(ident.name, res)),
558561
);
559562
}
560563
}
561564
Scope::MacroUsePrelude => {
562565
suggestions.extend(this.macro_use_prelude.iter().filter_map(
563566
|(name, binding)| {
564567
let res = binding.res();
565-
let span = binding.span;
566-
filter_fn(res)
567-
.then_some(TypoSuggestion::from_res(Ident::new(*name, span), res))
568+
filter_fn(res).then_some(TypoSuggestion::from_res(*name, res))
568569
},
569570
));
570571
}
571572
Scope::BuiltinAttrs => {
572573
let res = Res::NonMacroAttr(NonMacroAttrKind::Builtin);
573574
if filter_fn(res) {
574-
suggestions.extend(BUILTIN_ATTRIBUTES.iter().map(|(name, ..)| {
575-
TypoSuggestion::from_res(Ident::with_dummy_span(*name), res)
576-
}));
575+
suggestions.extend(
576+
BUILTIN_ATTRIBUTES
577+
.iter()
578+
.map(|(name, ..)| TypoSuggestion::from_res(*name, res)),
579+
);
577580
}
578581
}
579582
Scope::ExternPrelude => {
580583
suggestions.extend(this.extern_prelude.iter().filter_map(|(ident, _)| {
581584
let res = Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX));
582-
filter_fn(res).then_some(TypoSuggestion::from_res(*ident, res))
585+
filter_fn(res).then_some(TypoSuggestion::from_res(ident.name, res))
583586
}));
584587
}
585588
Scope::ToolPrelude => {
586589
let res = Res::NonMacroAttr(NonMacroAttrKind::Tool);
587590
suggestions.extend(
588591
this.registered_tools
589592
.iter()
590-
.map(|ident| TypoSuggestion::from_res(*ident, res)),
593+
.map(|ident| TypoSuggestion::from_res(ident.name, res)),
591594
);
592595
}
593596
Scope::StdLibPrelude => {
@@ -605,8 +608,7 @@ impl<'a> Resolver<'a> {
605608
let primitive_types = &this.primitive_type_table.primitive_types;
606609
suggestions.extend(primitive_types.iter().flat_map(|(name, prim_ty)| {
607610
let res = Res::PrimTy(*prim_ty);
608-
filter_fn(res)
609-
.then_some(TypoSuggestion::from_res(Ident::with_dummy_span(*name), res))
611+
filter_fn(res).then_some(TypoSuggestion::from_res(*name, res))
610612
}))
611613
}
612614
}
@@ -618,12 +620,12 @@ impl<'a> Resolver<'a> {
618620
suggestions.sort_by_cached_key(|suggestion| suggestion.candidate.as_str());
619621

620622
match find_best_match_for_name(
621-
suggestions.iter().map(|suggestion| &suggestion.candidate.name),
623+
suggestions.iter().map(|suggestion| &suggestion.candidate),
622624
&ident.as_str(),
623625
None,
624626
) {
625627
Some(found) if found != ident.name => {
626-
suggestions.into_iter().find(|suggestion| suggestion.candidate.name == found)
628+
suggestions.into_iter().find(|suggestion| suggestion.candidate == found)
627629
}
628630
_ => None,
629631
}
@@ -803,7 +805,7 @@ impl<'a> Resolver<'a> {
803805
) -> bool {
804806
if let Some(suggestion) = suggestion {
805807
// We shouldn't suggest underscore.
806-
if suggestion.candidate.name == kw::Underscore {
808+
if suggestion.candidate == kw::Underscore {
807809
return false;
808810
}
809811

@@ -822,18 +824,18 @@ impl<'a> Resolver<'a> {
822824
});
823825
let candidate = def_span
824826
.as_ref()
825-
.map(|span| Ident::new(suggestion.candidate.name, *span))
826-
.unwrap_or(suggestion.candidate);
827+
.map(|span| Ident::new(suggestion.candidate, *span).to_string())
828+
.unwrap_or_else(|| suggestion.candidate.to_stringified_ident_guess());
827829

828-
err.span_suggestion(span, &msg, candidate.to_string(), Applicability::MaybeIncorrect);
830+
err.span_suggestion(span, &msg, candidate.clone(), Applicability::MaybeIncorrect);
829831

830832
if let Some(span) = def_span {
831833
err.span_label(
832834
span,
833835
&format!(
834836
"similarly named {} `{}` defined here",
835837
suggestion.res.descr(),
836-
candidate.to_string(),
838+
candidate,
837839
),
838840
);
839841
}
@@ -1477,7 +1479,11 @@ crate fn show_candidates(
14771479
// produce an additional newline to separate the new use statement
14781480
// from the directly following item.
14791481
let additional_newline = if found_use { "" } else { "\n" };
1480-
*candidate = format!("use {};\n{}", candidate, additional_newline);
1482+
*candidate = format!(
1483+
"use {};\n{}",
1484+
Symbol::intern(candidate).to_stringified_ident_guess(),
1485+
additional_newline
1486+
);
14811487
}
14821488

14831489
err.span_suggestions(span, &msg, path_strings.into_iter(), Applicability::Unspecified);

‎src/librustc_resolve/late/diagnostics.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
647647
// Locals and type parameters
648648
for (ident, &res) in &rib.bindings {
649649
if filter_fn(res) {
650-
names.push(TypoSuggestion::from_res(*ident, res));
650+
names.push(TypoSuggestion::from_res(ident.name, res));
651651
}
652652
}
653653
// Items in scope
@@ -672,7 +672,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
672672
);
673673

674674
if filter_fn(crate_mod) {
675-
Some(TypoSuggestion::from_res(*ident, crate_mod))
675+
Some(TypoSuggestion::from_res(ident.name, crate_mod))
676676
} else {
677677
None
678678
}
@@ -689,14 +689,11 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
689689
}
690690
// Add primitive types to the mix
691691
if filter_fn(Res::PrimTy(PrimTy::Bool)) {
692-
names.extend(self.r.primitive_type_table.primitive_types.iter().map(
693-
|(name, prim_ty)| {
694-
TypoSuggestion::from_res(
695-
Ident::with_dummy_span(*name),
696-
Res::PrimTy(*prim_ty),
697-
)
698-
},
699-
))
692+
names.extend(
693+
self.r.primitive_type_table.primitive_types.iter().map(|(name, prim_ty)| {
694+
TypoSuggestion::from_res(*name, Res::PrimTy(*prim_ty))
695+
}),
696+
)
700697
}
701698
} else {
702699
// Search in module.
@@ -715,12 +712,12 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
715712
names.sort_by_cached_key(|suggestion| suggestion.candidate.as_str());
716713

717714
match find_best_match_for_name(
718-
names.iter().map(|suggestion| &suggestion.candidate.name),
715+
names.iter().map(|suggestion| &suggestion.candidate),
719716
&name.as_str(),
720717
None,
721718
) {
722719
Some(found) if found != name => {
723-
names.into_iter().find(|suggestion| suggestion.candidate.name == found)
720+
names.into_iter().find(|suggestion| suggestion.candidate == found)
724721
}
725722
_ => None,
726723
}

‎src/librustc_span/symbol.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,13 @@ impl Symbol {
966966
})
967967
}
968968

969+
/// Represent as stringified identifier, guessing raw formatting
970+
/// (`r#`) if ident can be interpreted as a raw identifier according
971+
/// to the edition used by current crate.
972+
pub fn to_stringified_ident_guess(&self) -> String {
973+
Ident::with_dummy_span(*self).to_string()
974+
}
975+
969976
pub fn as_u32(self) -> u32 {
970977
self.0.as_u32()
971978
}

‎src/librustc_typeck/check/wfcheck.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,11 +1100,14 @@ fn report_bivariance(tcx: TyCtxt<'_>, span: Span, param_name: ast::Name) {
11001100
let msg = if let Some(def_id) = suggested_marker_id {
11011101
format!(
11021102
"consider removing `{}`, referring to it in a field, or using a marker such as `{}`",
1103-
param_name,
1103+
param_name.to_stringified_ident_guess(),
11041104
tcx.def_path_str(def_id),
11051105
)
11061106
} else {
1107-
format!("consider removing `{}` or referring to it in a field", param_name)
1107+
format!(
1108+
"consider removing `{}` or referring to it in a field",
1109+
param_name.to_stringified_ident_guess()
1110+
)
11081111
};
11091112
err.help(&msg);
11101113
err.emit();
@@ -1218,8 +1221,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12181221
}
12191222

12201223
fn error_392(tcx: TyCtxt<'_>, span: Span, param_name: ast::Name) -> DiagnosticBuilder<'_> {
1221-
let mut err =
1222-
struct_span_err!(tcx.sess, span, E0392, "parameter `{}` is never used", param_name);
1224+
let mut err = struct_span_err!(
1225+
tcx.sess,
1226+
span,
1227+
E0392,
1228+
"parameter `{}` is never used",
1229+
param_name.to_stringified_ident_guess()
1230+
);
12231231
err.span_label(span, "unused parameter");
12241232
err
12251233
}

‎src/test/ui/issues/issue-69053.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
struct r#struct<r#fn>;
2+
//~^ WARNING should have an upper camel case name
3+
//~^^ WARNING should have an upper camel case name
4+
//~^^^ ERROR parameter `fn` is never used
5+
6+
fn main() {}

‎src/test/ui/issues/issue-69053.stderr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
warning: type `struct` should have an upper camel case name
2+
--> $DIR/issue-69053.rs:1:8
3+
|
4+
LL | struct r#struct<r#fn>;
5+
| ^^^^^^^^ help: convert the identifier to upper camel case: `Struct`
6+
|
7+
= note: `#[warn(non_camel_case_types)]` on by default
8+
9+
warning: type parameter `fn` should have an upper camel case name
10+
--> $DIR/issue-69053.rs:1:17
11+
|
12+
LL | struct r#struct<r#fn>;
13+
| ^^^^ help: convert the identifier to upper camel case: `Fn`
14+
15+
error[E0392]: parameter `fn` is never used
16+
--> $DIR/issue-69053.rs:1:17
17+
|
18+
LL | struct r#struct<r#fn>;
19+
| ^^^^ unused parameter
20+
|
21+
= help: consider removing `r#fn`, referring to it in a field, or using a marker such as `std::marker::PhantomData`
22+
23+
error: aborting due to previous error
24+
25+
For more information about this error, try `rustc --explain E0392`.

0 commit comments

Comments
 (0)
Please sign in to comment.