Simplify · rust-lang/rust@f50f8fb

11

//! An algorithm to find a path to refer to a certain item.

223-

use std::{

4-

cmp::Ordering,

5-

iter::{self, once},

6-

};

3+

use std::{cmp::Ordering, iter};

7485

use hir_expand::{

96

name::{known, AsName, Name},

@@ -85,7 +82,7 @@ struct FindPathCtx<'db> {

8582

fn find_path_inner(ctx: FindPathCtx<'_>, item: ItemInNs, from: ModuleId) -> Option<ModPath> {

8683

// - if the item is a builtin, it's in scope

8784

if let ItemInNs::Types(ModuleDefId::BuiltinType(builtin)) = item {

88-

return Some(ModPath::from_segments(PathKind::Plain, once(builtin.as_name())));

85+

return Some(ModPath::from_segments(PathKind::Plain, iter::once(builtin.as_name())));

8986

}

90879188

let def_map = from.def_map(ctx.db);

@@ -124,7 +121,7 @@ fn find_path_inner(ctx: FindPathCtx<'_>, item: ItemInNs, from: ModuleId) -> Opti

124121

// - if the item is already in scope, return the name under which it is

125122

let scope_name = find_in_scope(ctx.db, &def_map, from, item, ctx.ignore_local_imports);

126123

if let Some(scope_name) = scope_name {

127-

return Some(ModPath::from_segments(prefix.path_kind(), Some(scope_name)));

124+

return Some(ModPath::from_segments(prefix.path_kind(), iter::once(scope_name)));

128125

}

129126

}

130127

@@ -209,7 +206,7 @@ fn find_path_for_module(

209206

} else {

210207

PathKind::Plain

211208

};

212-

return Some((ModPath::from_segments(kind, once(name.clone())), Stable));

209+

return Some((ModPath::from_segments(kind, iter::once(name.clone())), Stable));

213210

}

214211

}

215212

let prefix = if module_id.is_within_block() { PrefixKind::Plain } else { ctx.prefix };

@@ -227,7 +224,10 @@ fn find_path_for_module(

227224

);

228225

if let Some(scope_name) = scope_name {

229226

// - if the item is already in scope, return the name under which it is

230-

return Some((ModPath::from_segments(prefix.path_kind(), once(scope_name)), Stable));

227+

return Some((

228+

ModPath::from_segments(prefix.path_kind(), iter::once(scope_name)),

229+

Stable,

230+

));

231231

}

232232

}

233233

@@ -301,7 +301,7 @@ fn find_in_prelude(

301301

});

302302303303

if found_and_same_def.unwrap_or(true) {

304-

Some(ModPath::from_segments(PathKind::Plain, once(name.clone())))

304+

Some(ModPath::from_segments(PathKind::Plain, iter::once(name.clone())))

305305

} else {

306306

None

307307

}