Skip to content

Commit dba95f2

Browse files
committed
made some fixes
1 parent 9a92054 commit dba95f2

File tree

3 files changed

+69
-9
lines changed

3 files changed

+69
-9
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
27642764

27652765
let (msg, sugg) = match source {
27662766
PathSource::Type | PathSource::PreciseCapturingArg(TypeNS) => {
2767-
("you might be missing a type parameter", ident)
2767+
("you might be missing a type parameter", ident.clone())
27682768
}
27692769
PathSource::Expr(_) | PathSource::PreciseCapturingArg(ValueNS) => (
27702770
"you might be missing a const parameter",
@@ -2786,16 +2786,15 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
27862786
"Item", "Output", "Error", "Target", "Value", "Args",
27872787
"Res", "Ret", "This", "Iter", "Type",
27882788
];
2789-
let is_common_generic = common_generic_names.contains(&sugg.as_str());
2790-
let looks_like_camel_case = sugg
2789+
let is_common_generic = common_generic_names.contains(&&*ident);
2790+
let looks_like_camel_case = ident
27912791
.chars()
27922792
.next()
2793-
.map(|c| c.is_uppercase())
2794-
.unwrap_or(false)
2795-
&& sugg.chars().skip(1).any(|c| c.is_lowercase());
2793+
.is_some_and(|c| c.is_uppercase())
2794+
&& ident.chars().skip(1).any(|c| c.is_lowercase());
27962795

27972796
// If it's not a known generic name and looks like a concrete type, skip the suggestion.
2798-
if !is_common_generic && looks_like_camel_case && sugg.len() > 3 {
2797+
if !is_common_generic && looks_like_camel_case && ident.len() > 3 {
27992798
return None;
28002799
}
28012800
let (span, sugg) = if let [.., param] = &generics.params[..] {

tests/ui/traits/missing-type-param-suggestion-issue-139999.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,20 @@ fn do_something() -> Option<ForgotToImport> {
33
None
44
}
55

6+
fn do_something_T() -> Option<T> {
7+
//~^ cannot find type `T` in this scope [E0412]
8+
None
9+
}
10+
11+
fn do_something_Type() -> Option<Type> {
12+
//~^ cannot find type `Type` in this scope [E0412]
13+
None
14+
}
15+
16+
fn do_something_const() -> [(); N] {
17+
//~^ cannot find value `N` in this scope [E0425]
18+
[(); N]
19+
//~^ cannot find value `N` in this scope [E0425]
20+
}
21+
622
fn main() {}

tests/ui/traits/missing-type-param-suggestion-issue-139999.stderr

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,51 @@ error[E0412]: cannot find type `ForgotToImport` in this scope
44
LL | fn do_something() -> Option<ForgotToImport> {
55
| ^^^^^^^^^^^^^^ not found in this scope
66

7-
error: aborting due to 1 previous error
7+
error[E0412]: cannot find type `T` in this scope
8+
--> $DIR/missing-type-param-suggestion-issue-139999.rs:6:31
9+
|
10+
LL | fn do_something_T() -> Option<T> {
11+
| ^ not found in this scope
12+
|
13+
help: you might be missing a type parameter
14+
|
15+
LL | fn do_something_T<T>() -> Option<T> {
16+
| +++
17+
18+
error[E0412]: cannot find type `Type` in this scope
19+
--> $DIR/missing-type-param-suggestion-issue-139999.rs:11:34
20+
|
21+
LL | fn do_something_Type() -> Option<Type> {
22+
| ^^^^ not found in this scope
23+
|
24+
help: you might be missing a type parameter
25+
|
26+
LL | fn do_something_Type<Type>() -> Option<Type> {
27+
| ++++++
28+
29+
error[E0425]: cannot find value `N` in this scope
30+
--> $DIR/missing-type-param-suggestion-issue-139999.rs:16:33
31+
|
32+
LL | fn do_something_const() -> [(); N] {
33+
| ^ not found in this scope
34+
|
35+
help: you might be missing a const parameter
36+
|
37+
LL | fn do_something_const<const N: /* Type */>() -> [(); N] {
38+
| +++++++++++++++++++++
39+
40+
error[E0425]: cannot find value `N` in this scope
41+
--> $DIR/missing-type-param-suggestion-issue-139999.rs:18:10
42+
|
43+
LL | [(); N]
44+
| ^ not found in this scope
45+
|
46+
help: you might be missing a const parameter
47+
|
48+
LL | fn do_something_const<const N: /* Type */>() -> [(); N] {
49+
| +++++++++++++++++++++
50+
51+
error: aborting due to 5 previous errors
852

9-
For more information about this error, try `rustc --explain E0412`.
53+
Some errors have detailed explanations: E0412, E0425.
54+
For more information about an error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)