Skip to content

Commit 7515e71

Browse files
committed
review comments
1 parent 1e8945b commit 7515e71

File tree

6 files changed

+48
-46
lines changed

6 files changed

+48
-46
lines changed

src/librustc_resolve/diagnostics.rs

+33
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,39 @@ use crate::{import_candidate_to_enum_paths, is_self_type, is_self_value, path_na
1818
use crate::{AssocSuggestion, CrateLint, ImportSuggestion, ModuleOrUniformRoot, PathResult,
1919
PathSource, Resolver, Segment, Suggestion};
2020

21+
#[derive(Clone, Copy)]
22+
crate enum CurrentScope {
23+
Const,
24+
Static,
25+
Type,
26+
Other,
27+
}
28+
29+
impl CurrentScope {
30+
crate fn is_other(&self) -> bool {
31+
match self {
32+
CurrentScope::Other => true,
33+
_ => false,
34+
}
35+
}
36+
37+
crate fn description(&self) -> &'static str {
38+
match self {
39+
Self::Const => "a `const`",
40+
Self::Static => "a `static`",
41+
Self::Type => "associated type",
42+
Self::Other => "outer function",
43+
}
44+
}
45+
46+
crate fn generic_param_resolution_error_message(&self) -> String {
47+
match self {
48+
Self::Other => format!("from {}", self.description()),
49+
_ => format!("in {}", self.description()),
50+
}
51+
}
52+
}
53+
2154
impl<'a> Resolver<'a> {
2255
/// Handles error reporting for `smart_resolve_path_fragment` function.
2356
/// Creates base error and amends it with one short label and possibly some longer helps/notes.

src/librustc_resolve/lib.rs

+3-34
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ use rustc_data_structures::ptr_key::PtrKey;
7070
use rustc_data_structures::sync::Lrc;
7171
use smallvec::SmallVec;
7272

73-
use diagnostics::{find_span_of_binding_until_next_binding, extend_span_to_previous_binding};
73+
use diagnostics::{
74+
find_span_of_binding_until_next_binding, extend_span_to_previous_binding, CurrentScope,
75+
};
7476
use resolve_imports::{ImportDirective, ImportDirectiveSubclass, NameResolution, ImportResolver};
7577
use macros::{InvocationData, LegacyBinding, ParentScope};
7678

@@ -194,39 +196,6 @@ enum ResolutionError<'a> {
194196
ConstParamDependentOnTypeParam,
195197
}
196198

197-
#[derive(Clone, Copy)]
198-
enum CurrentScope {
199-
Const,
200-
Static,
201-
Type,
202-
Other,
203-
}
204-
205-
impl CurrentScope {
206-
fn is_other(&self) -> bool {
207-
match self {
208-
CurrentScope::Other => true,
209-
_ => false,
210-
}
211-
}
212-
213-
fn description(&self) -> &'static str {
214-
match self {
215-
Self::Const => "`const` associated item",
216-
Self::Static => "`static` associated item",
217-
Self::Type => "associated type",
218-
Self::Other => "outer function",
219-
}
220-
}
221-
222-
fn generic_param_resolution_error_message(&self) -> String {
223-
match self {
224-
Self::Other => format!("from {}", self.description()),
225-
_ => format!("in {}", self.description()),
226-
}
227-
}
228-
}
229-
230199
/// Combines an error with provided span and emits it.
231200
///
232201
/// This takes the error provided, combines it with the span and any additional spans inside the

src/test/ui/inner-static-type-parameter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ enum Bar<T> { What } //~ ERROR parameter `T` is never used
44

55
fn foo<T>() {
66
static a: Bar<T> = Bar::What;
7-
//~^ ERROR can't use generic parameters in `static` associated item
7+
//~^ ERROR can't use generic parameters in a `static`
88
}
99

1010
fn main() {

src/test/ui/inner-static-type-parameter.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0401]: can't use generic parameters in `static` associated item
1+
error[E0401]: can't use generic parameters in a `static`
22
--> $DIR/inner-static-type-parameter.rs:6:19
33
|
44
LL | fn foo<T>() {
55
| - type parameter being used
66
LL | static a: Bar<T> = Bar::What;
7-
| ^ use of generic parameter in `static` associated item
7+
| ^ use of generic parameter in a `static`
88
|
9-
= help: `static` associated item need a type instead of a generic parameter
9+
= help: a `static` need a type instead of a generic parameter
1010

1111
error[E0392]: parameter `T` is never used
1212
--> $DIR/inner-static-type-parameter.rs:3:10

src/test/ui/issues/issue-45447.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ trait Foo { const FOO: Self; }
22
impl Foo for u32 { const FOO: Self = 1; }
33
fn bar<T: Foo>(n: T) {
44
const BASE: T = T::FOO;
5-
//~^ ERROR can't use generic parameters in `const` associated item
6-
//~| ERROR can't use generic parameters in `const` associated item
5+
//~^ ERROR can't use generic parameters in a `const`
6+
//~| ERROR can't use generic parameters in a `const`
77
type Type = T;
88
//~^ ERROR can't use generic parameters in associated type
99
}

src/test/ui/issues/issue-45447.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
error[E0401]: can't use generic parameters in `const` associated item
1+
error[E0401]: can't use generic parameters in a `const`
22
--> $DIR/issue-45447.rs:4:17
33
|
44
LL | fn bar<T: Foo>(n: T) {
55
| - type parameter being used
66
LL | const BASE: T = T::FOO;
7-
| ^ use of generic parameter in `const` associated item
7+
| ^ use of generic parameter in a `const`
88
|
9-
= help: `const` associated item need a type instead of a generic parameter
9+
= help: a `const` need a type instead of a generic parameter
1010

11-
error[E0401]: can't use generic parameters in `const` associated item
11+
error[E0401]: can't use generic parameters in a `const`
1212
--> $DIR/issue-45447.rs:4:21
1313
|
1414
LL | fn bar<T: Foo>(n: T) {
1515
| - type parameter being used
1616
LL | const BASE: T = T::FOO;
17-
| ^^^^^^ use of generic parameter in `const` associated item
17+
| ^^^^^^ use of generic parameter in a `const`
1818
|
19-
= help: `const` associated item need a type instead of a generic parameter
19+
= help: a `const` need a type instead of a generic parameter
2020

2121
error[E0401]: can't use generic parameters in associated type
2222
--> $DIR/issue-45447.rs:7:17

0 commit comments

Comments
 (0)