aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs303
-rw-r--r--crates/ra_assists/src/lib.rs2
-rw-r--r--crates/ra_assists/src/tests/generated.rs25
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs16
-rw-r--r--crates/ra_hir_ty/src/tests/patterns.rs50
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs1
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tags.rs2
-rw-r--r--crates/rust-analyzer/src/to_proto.rs1
8 files changed, 395 insertions, 5 deletions
diff --git a/crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs b/crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs
new file mode 100644
index 000000000..999aec421
--- /dev/null
+++ b/crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs
@@ -0,0 +1,303 @@
1use crate::{assist_context::AssistBuilder, AssistContext, AssistId, Assists};
2use ast::{NameOwner, ParamList, TypeAscriptionOwner, TypeParamList, TypeRef};
3use ra_syntax::{ast, ast::TypeParamsOwner, AstNode, SyntaxKind, TextRange, TextSize};
4use rustc_hash::FxHashSet;
5
6static ASSIST_NAME: &str = "change_lifetime_anon_to_named";
7static ASSIST_LABEL: &str = "Give anonymous lifetime a name";
8
9// Assist: change_lifetime_anon_to_named
10//
11// Change an anonymous lifetime to a named lifetime.
12//
13// ```
14// impl Cursor<'_<|>> {
15// fn node(self) -> &SyntaxNode {
16// match self {
17// Cursor::Replace(node) | Cursor::Before(node) => node,
18// }
19// }
20// }
21// ```
22// ->
23// ```
24// impl<'a> Cursor<'a> {
25// fn node(self) -> &SyntaxNode {
26// match self {
27// Cursor::Replace(node) | Cursor::Before(node) => node,
28// }
29// }
30// }
31// ```
32// FIXME: How can we handle renaming any one of multiple anonymous lifetimes?
33// FIXME: should also add support for the case fun(f: &Foo) -> &<|>Foo
34pub(crate) fn change_lifetime_anon_to_named(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
35 let lifetime_token = ctx
36 .find_token_at_offset(SyntaxKind::LIFETIME)
37 .filter(|lifetime| lifetime.text() == "'_")?;
38 if let Some(fn_def) = lifetime_token.ancestors().find_map(ast::FnDef::cast) {
39 generate_fn_def_assist(acc, &fn_def, lifetime_token.text_range())
40 } else if let Some(impl_def) = lifetime_token.ancestors().find_map(ast::ImplDef::cast) {
41 // only allow naming the last anonymous lifetime
42 lifetime_token.next_token().filter(|tok| tok.kind() == SyntaxKind::R_ANGLE)?;
43 generate_impl_def_assist(acc, &impl_def, lifetime_token.text_range())
44 } else {
45 None
46 }
47}
48
49/// Generate the assist for the fn def case
50fn generate_fn_def_assist(
51 acc: &mut Assists,
52 fn_def: &ast::FnDef,
53 lifetime_loc: TextRange,
54) -> Option<()> {
55 let param_list: ParamList = fn_def.param_list()?;
56 let new_lifetime_param = generate_unique_lifetime_param_name(&fn_def.type_param_list())?;
57 let end_of_fn_ident = fn_def.name()?.ident_token()?.text_range().end();
58 let self_param =
59 // use the self if it's a reference and has no explicit lifetime
60 param_list.self_param().filter(|p| p.lifetime_token().is_none() && p.amp_token().is_some());
61 // compute the location which implicitly has the same lifetime as the anonymous lifetime
62 let loc_needing_lifetime = if let Some(self_param) = self_param {
63 // if we have a self reference, use that
64 Some(self_param.self_token()?.text_range().start())
65 } else {
66 // otherwise, if there's a single reference parameter without a named liftime, use that
67 let fn_params_without_lifetime: Vec<_> = param_list
68 .params()
69 .filter_map(|param| match param.ascribed_type() {
70 Some(TypeRef::ReferenceType(ascribed_type))
71 if ascribed_type.lifetime_token() == None =>
72 {
73 Some(ascribed_type.amp_token()?.text_range().end())
74 }
75 _ => None,
76 })
77 .collect();
78 match fn_params_without_lifetime.len() {
79 1 => Some(fn_params_without_lifetime.into_iter().nth(0)?),
80 0 => None,
81 // multiple unnnamed is invalid. assist is not applicable
82 _ => return None,
83 }
84 };
85 acc.add(AssistId(ASSIST_NAME), ASSIST_LABEL, lifetime_loc, |builder| {
86 add_lifetime_param(fn_def, builder, end_of_fn_ident, new_lifetime_param);
87 builder.replace(lifetime_loc, format!("'{}", new_lifetime_param));
88 loc_needing_lifetime.map(|loc| builder.insert(loc, format!("'{} ", new_lifetime_param)));
89 })
90}
91
92/// Generate the assist for the impl def case
93fn generate_impl_def_assist(
94 acc: &mut Assists,
95 impl_def: &ast::ImplDef,
96 lifetime_loc: TextRange,
97) -> Option<()> {
98 let new_lifetime_param = generate_unique_lifetime_param_name(&impl_def.type_param_list())?;
99 let end_of_impl_kw = impl_def.impl_token()?.text_range().end();
100 acc.add(AssistId(ASSIST_NAME), ASSIST_LABEL, lifetime_loc, |builder| {
101 add_lifetime_param(impl_def, builder, end_of_impl_kw, new_lifetime_param);
102 builder.replace(lifetime_loc, format!("'{}", new_lifetime_param));
103 })
104}
105
106/// Given a type parameter list, generate a unique lifetime parameter name
107/// which is not in the list
108fn generate_unique_lifetime_param_name(
109 existing_type_param_list: &Option<TypeParamList>,
110) -> Option<char> {
111 match existing_type_param_list {
112 Some(type_params) => {
113 let used_lifetime_params: FxHashSet<_> = type_params
114 .lifetime_params()
115 .map(|p| p.syntax().text().to_string()[1..].to_owned())
116 .collect();
117 (b'a'..=b'z').map(char::from).find(|c| !used_lifetime_params.contains(&c.to_string()))
118 }
119 None => Some('a'),
120 }
121}
122
123/// Add the lifetime param to `builder`. If there are type parameters in `type_params_owner`, add it to the end. Otherwise
124/// add new type params brackets with the lifetime parameter at `new_type_params_loc`.
125fn add_lifetime_param<TypeParamsOwner: ast::TypeParamsOwner>(
126 type_params_owner: &TypeParamsOwner,
127 builder: &mut AssistBuilder,
128 new_type_params_loc: TextSize,
129 new_lifetime_param: char,
130) {
131 match type_params_owner.type_param_list() {
132 // add the new lifetime parameter to an existing type param list
133 Some(type_params) => {
134 builder.insert(
135 (u32::from(type_params.syntax().text_range().end()) - 1).into(),
136 format!(", '{}", new_lifetime_param),
137 );
138 }
139 // create a new type param list containing only the new lifetime parameter
140 None => {
141 builder.insert(new_type_params_loc, format!("<'{}>", new_lifetime_param));
142 }
143 }
144}
145
146#[cfg(test)]
147mod tests {
148 use super::*;
149 use crate::tests::{check_assist, check_assist_not_applicable};
150
151 #[test]
152 fn test_example_case() {
153 check_assist(
154 change_lifetime_anon_to_named,
155 r#"impl Cursor<'_<|>> {
156 fn node(self) -> &SyntaxNode {
157 match self {
158 Cursor::Replace(node) | Cursor::Before(node) => node,
159 }
160 }
161 }"#,
162 r#"impl<'a> Cursor<'a> {
163 fn node(self) -> &SyntaxNode {
164 match self {
165 Cursor::Replace(node) | Cursor::Before(node) => node,
166 }
167 }
168 }"#,
169 );
170 }
171
172 #[test]
173 fn test_example_case_simplified() {
174 check_assist(
175 change_lifetime_anon_to_named,
176 r#"impl Cursor<'_<|>> {"#,
177 r#"impl<'a> Cursor<'a> {"#,
178 );
179 }
180
181 #[test]
182 fn test_example_case_cursor_after_tick() {
183 check_assist(
184 change_lifetime_anon_to_named,
185 r#"impl Cursor<'<|>_> {"#,
186 r#"impl<'a> Cursor<'a> {"#,
187 );
188 }
189
190 #[test]
191 fn test_example_case_cursor_before_tick() {
192 check_assist(
193 change_lifetime_anon_to_named,
194 r#"impl Cursor<<|>'_> {"#,
195 r#"impl<'a> Cursor<'a> {"#,
196 );
197 }
198
199 #[test]
200 fn test_not_applicable_cursor_position() {
201 check_assist_not_applicable(change_lifetime_anon_to_named, r#"impl Cursor<'_><|> {"#);
202 check_assist_not_applicable(change_lifetime_anon_to_named, r#"impl Cursor<|><'_> {"#);
203 }
204
205 #[test]
206 fn test_not_applicable_lifetime_already_name() {
207 check_assist_not_applicable(change_lifetime_anon_to_named, r#"impl Cursor<'a<|>> {"#);
208 check_assist_not_applicable(
209 change_lifetime_anon_to_named,
210 r#"fn my_fun<'a>() -> X<'a<|>>"#,
211 );
212 }
213
214 #[test]
215 fn test_with_type_parameter() {
216 check_assist(
217 change_lifetime_anon_to_named,
218 r#"impl<T> Cursor<T, '_<|>>"#,
219 r#"impl<T, 'a> Cursor<T, 'a>"#,
220 );
221 }
222
223 #[test]
224 fn test_with_existing_lifetime_name_conflict() {
225 check_assist(
226 change_lifetime_anon_to_named,
227 r#"impl<'a, 'b> Cursor<'a, 'b, '_<|>>"#,
228 r#"impl<'a, 'b, 'c> Cursor<'a, 'b, 'c>"#,
229 );
230 }
231
232 #[test]
233 fn test_function_return_value_anon_lifetime_param() {
234 check_assist(
235 change_lifetime_anon_to_named,
236 r#"fn my_fun() -> X<'_<|>>"#,
237 r#"fn my_fun<'a>() -> X<'a>"#,
238 );
239 }
240
241 #[test]
242 fn test_function_return_value_anon_reference_lifetime() {
243 check_assist(
244 change_lifetime_anon_to_named,
245 r#"fn my_fun() -> &'_<|> X"#,
246 r#"fn my_fun<'a>() -> &'a X"#,
247 );
248 }
249
250 #[test]
251 fn test_function_param_anon_lifetime() {
252 check_assist(
253 change_lifetime_anon_to_named,
254 r#"fn my_fun(x: X<'_<|>>)"#,
255 r#"fn my_fun<'a>(x: X<'a>)"#,
256 );
257 }
258
259 #[test]
260 fn test_function_add_lifetime_to_params() {
261 check_assist(
262 change_lifetime_anon_to_named,
263 r#"fn my_fun(f: &Foo) -> X<'_<|>>"#,
264 r#"fn my_fun<'a>(f: &'a Foo) -> X<'a>"#,
265 );
266 }
267
268 #[test]
269 fn test_function_add_lifetime_to_params_in_presence_of_other_lifetime() {
270 check_assist(
271 change_lifetime_anon_to_named,
272 r#"fn my_fun<'other>(f: &Foo, b: &'other Bar) -> X<'_<|>>"#,
273 r#"fn my_fun<'other, 'a>(f: &'a Foo, b: &'other Bar) -> X<'a>"#,
274 );
275 }
276
277 #[test]
278 fn test_function_not_applicable_without_self_and_multiple_unnamed_param_lifetimes() {
279 // this is not permitted under lifetime elision rules
280 check_assist_not_applicable(
281 change_lifetime_anon_to_named,
282 r#"fn my_fun(f: &Foo, b: &Bar) -> X<'_<|>>"#,
283 );
284 }
285
286 #[test]
287 fn test_function_add_lifetime_to_self_ref_param() {
288 check_assist(
289 change_lifetime_anon_to_named,
290 r#"fn my_fun<'other>(&self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#,
291 r#"fn my_fun<'other, 'a>(&'a self, f: &Foo, b: &'other Bar) -> X<'a>"#,
292 );
293 }
294
295 #[test]
296 fn test_function_add_lifetime_to_param_with_non_ref_self() {
297 check_assist(
298 change_lifetime_anon_to_named,
299 r#"fn my_fun<'other>(self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#,
300 r#"fn my_fun<'other, 'a>(self, f: &'a Foo, b: &'other Bar) -> X<'a>"#,
301 );
302 }
303}
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 464bc03dd..3f8f7ffbf 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -112,6 +112,7 @@ mod handlers {
112 mod add_turbo_fish; 112 mod add_turbo_fish;
113 mod apply_demorgan; 113 mod apply_demorgan;
114 mod auto_import; 114 mod auto_import;
115 mod change_lifetime_anon_to_named;
115 mod change_return_type_to_result; 116 mod change_return_type_to_result;
116 mod change_visibility; 117 mod change_visibility;
117 mod early_return; 118 mod early_return;
@@ -151,6 +152,7 @@ mod handlers {
151 add_turbo_fish::add_turbo_fish, 152 add_turbo_fish::add_turbo_fish,
152 apply_demorgan::apply_demorgan, 153 apply_demorgan::apply_demorgan,
153 auto_import::auto_import, 154 auto_import::auto_import,
155 change_lifetime_anon_to_named::change_lifetime_anon_to_named,
154 change_return_type_to_result::change_return_type_to_result, 156 change_return_type_to_result::change_return_type_to_result,
155 change_visibility::change_visibility, 157 change_visibility::change_visibility,
156 early_return::convert_to_guarded_return, 158 early_return::convert_to_guarded_return,
diff --git a/crates/ra_assists/src/tests/generated.rs b/crates/ra_assists/src/tests/generated.rs
index 4e0536828..73d43283d 100644
--- a/crates/ra_assists/src/tests/generated.rs
+++ b/crates/ra_assists/src/tests/generated.rs
@@ -288,6 +288,31 @@ pub mod std { pub mod collections { pub struct HashMap { } } }
288} 288}
289 289
290#[test] 290#[test]
291fn doctest_change_lifetime_anon_to_named() {
292 check_doc_test(
293 "change_lifetime_anon_to_named",
294 r#####"
295impl Cursor<'_<|>> {
296 fn node(self) -> &SyntaxNode {
297 match self {
298 Cursor::Replace(node) | Cursor::Before(node) => node,
299 }
300 }
301}
302"#####,
303 r#####"
304impl<'a> Cursor<'a> {
305 fn node(self) -> &SyntaxNode {
306 match self {
307 Cursor::Replace(node) | Cursor::Before(node) => node,
308 }
309 }
310}
311"#####,
312 )
313}
314
315#[test]
291fn doctest_change_return_type_to_result() { 316fn doctest_change_return_type_to_result() {
292 check_doc_test( 317 check_doc_test(
293 "change_return_type_to_result", 318 "change_return_type_to_result",
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 54bab3476..78084cb57 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -140,13 +140,13 @@ impl<'a> InferenceContext<'a> {
140 140
141 let mut sig_tys = Vec::new(); 141 let mut sig_tys = Vec::new();
142 142
143 for (arg_pat, arg_type) in args.iter().zip(arg_types.iter()) { 143 // collect explicitly written argument types
144 let expected = if let Some(type_ref) = arg_type { 144 for arg_type in arg_types.iter() {
145 let arg_ty = if let Some(type_ref) = arg_type {
145 self.make_ty(type_ref) 146 self.make_ty(type_ref)
146 } else { 147 } else {
147 Ty::Unknown 148 self.table.new_type_var()
148 }; 149 };
149 let arg_ty = self.infer_pat(*arg_pat, &expected, BindingMode::default());
150 sig_tys.push(arg_ty); 150 sig_tys.push(arg_ty);
151 } 151 }
152 152
@@ -158,7 +158,7 @@ impl<'a> InferenceContext<'a> {
158 sig_tys.push(ret_ty.clone()); 158 sig_tys.push(ret_ty.clone());
159 let sig_ty = Ty::apply( 159 let sig_ty = Ty::apply(
160 TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, 160 TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 },
161 Substs(sig_tys.into()), 161 Substs(sig_tys.clone().into()),
162 ); 162 );
163 let closure_ty = 163 let closure_ty =
164 Ty::apply_one(TypeCtor::Closure { def: self.owner, expr: tgt_expr }, sig_ty); 164 Ty::apply_one(TypeCtor::Closure { def: self.owner, expr: tgt_expr }, sig_ty);
@@ -168,6 +168,12 @@ impl<'a> InferenceContext<'a> {
168 // infer the body. 168 // infer the body.
169 self.coerce(&closure_ty, &expected.ty); 169 self.coerce(&closure_ty, &expected.ty);
170 170
171 // Now go through the argument patterns
172 for (arg_pat, arg_ty) in args.iter().zip(sig_tys) {
173 let resolved = self.resolve_ty_as_possible(arg_ty);
174 self.infer_pat(*arg_pat, &resolved, BindingMode::default());
175 }
176
171 let prev_diverges = mem::replace(&mut self.diverges, Diverges::Maybe); 177 let prev_diverges = mem::replace(&mut self.diverges, Diverges::Maybe);
172 let prev_ret_ty = mem::replace(&mut self.return_ty, ret_ty.clone()); 178 let prev_ret_ty = mem::replace(&mut self.return_ty, ret_ty.clone());
173 179
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs
index 0c5f972a2..fe62587c0 100644
--- a/crates/ra_hir_ty/src/tests/patterns.rs
+++ b/crates/ra_hir_ty/src/tests/patterns.rs
@@ -520,3 +520,53 @@ fn main() {
520 105..107 '()': () 520 105..107 '()': ()
521 ") 521 ")
522} 522}
523
524#[test]
525fn match_ergonomics_in_closure_params() {
526 assert_snapshot!(
527 infer(r#"
528#[lang = "fn_once"]
529trait FnOnce<Args> {
530 type Output;
531}
532
533fn foo<T, U, F: FnOnce(T) -> U>(t: T, f: F) -> U { loop {} }
534
535fn test() {
536 foo(&(1, "a"), |&(x, y)| x); // normal, no match ergonomics
537 foo(&(1, "a"), |(x, y)| x);
538}
539"#),
540 @r###"
541 94..95 't': T
542 100..101 'f': F
543 111..122 '{ loop {} }': U
544 113..120 'loop {}': !
545 118..120 '{}': ()
546 134..233 '{ ... x); }': ()
547 140..143 'foo': fn foo<&(i32, &str), i32, |&(i32, &str)| -> i32>(&(i32, &str), |&(i32, &str)| -> i32) -> i32
548 140..167 'foo(&(...y)| x)': i32
549 144..153 '&(1, "a")': &(i32, &str)
550 145..153 '(1, "a")': (i32, &str)
551 146..147 '1': i32
552 149..152 '"a"': &str
553 155..166 '|&(x, y)| x': |&(i32, &str)| -> i32
554 156..163 '&(x, y)': &(i32, &str)
555 157..163 '(x, y)': (i32, &str)
556 158..159 'x': i32
557 161..162 'y': &str
558 165..166 'x': i32
559 204..207 'foo': fn foo<&(i32, &str), &i32, |&(i32, &str)| -> &i32>(&(i32, &str), |&(i32, &str)| -> &i32) -> &i32
560 204..230 'foo(&(...y)| x)': &i32
561 208..217 '&(1, "a")': &(i32, &str)
562 209..217 '(1, "a")': (i32, &str)
563 210..211 '1': i32
564 213..216 '"a"': &str
565 219..229 '|(x, y)| x': |&(i32, &str)| -> &i32
566 220..226 '(x, y)': (i32, &str)
567 221..222 'x': &i32
568 224..225 'y': &&str
569 228..229 'x': &i32
570 "###
571 );
572}
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 3ab1f0a21..0b53ebe69 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -398,6 +398,7 @@ fn highlight_element(
398 INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), 398 INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(),
399 BYTE => HighlightTag::ByteLiteral.into(), 399 BYTE => HighlightTag::ByteLiteral.into(),
400 CHAR => HighlightTag::CharLiteral.into(), 400 CHAR => HighlightTag::CharLiteral.into(),
401 QUESTION => Highlight::new(HighlightTag::Operator) | HighlightModifier::ControlFlow,
401 LIFETIME => { 402 LIFETIME => {
402 let h = Highlight::new(HighlightTag::Lifetime); 403 let h = Highlight::new(HighlightTag::Lifetime);
403 match element.parent().map(|it| it.kind()) { 404 match element.parent().map(|it| it.kind()) {
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index 46c718c91..1514531de 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -42,6 +42,7 @@ pub enum HighlightTag {
42 Local, 42 Local,
43 UnresolvedReference, 43 UnresolvedReference,
44 FormatSpecifier, 44 FormatSpecifier,
45 Operator,
45} 46}
46 47
47#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 48#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -89,6 +90,7 @@ impl HighlightTag {
89 HighlightTag::Local => "variable", 90 HighlightTag::Local => "variable",
90 HighlightTag::UnresolvedReference => "unresolved_reference", 91 HighlightTag::UnresolvedReference => "unresolved_reference",
91 HighlightTag::FormatSpecifier => "format_specifier", 92 HighlightTag::FormatSpecifier => "format_specifier",
93 HighlightTag::Operator => "operator",
92 } 94 }
93 } 95 }
94} 96}
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 8e8e7033d..2fbbb4e63 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -317,6 +317,7 @@ fn semantic_token_type_and_modifiers(
317 HighlightTag::Keyword => lsp_types::SemanticTokenType::KEYWORD, 317 HighlightTag::Keyword => lsp_types::SemanticTokenType::KEYWORD,
318 HighlightTag::UnresolvedReference => semantic_tokens::UNRESOLVED_REFERENCE, 318 HighlightTag::UnresolvedReference => semantic_tokens::UNRESOLVED_REFERENCE,
319 HighlightTag::FormatSpecifier => semantic_tokens::FORMAT_SPECIFIER, 319 HighlightTag::FormatSpecifier => semantic_tokens::FORMAT_SPECIFIER,
320 HighlightTag::Operator => lsp_types::SemanticTokenType::OPERATOR,
320 }; 321 };
321 322
322 for modifier in highlight.modifiers.iter() { 323 for modifier in highlight.modifiers.iter() {