Simplify · rust-lang/rust@f50f8fb (original) (raw)

1

1

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

`

2

2

``

3

``

`-

use std::{

`

4

``

`-

cmp::Ordering,

`

5

``

`-

iter::{self, once},

`

6

``

`-

};

`

``

3

`+

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

`

7

4

``

8

5

`use hir_expand::{

`

9

6

` name::{known, AsName, Name},

`

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

`

85

82

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

`

86

83

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

`

87

84

`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())));

`

89

86

`}

`

90

87

``

91

88

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

`

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

`

124

121

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

`

125

122

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

`

126

123

`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)));

`

128

125

`}

`

129

126

`}

`

130

127

``

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

`

209

206

`} else {

`

210

207

`PathKind::Plain

`

211

208

`};

`

212

``

`-

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

`

``

209

`+

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

`

213

210

`}

`

214

211

`}

`

215

212

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

`

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

`

227

224

`);

`

228

225

`if let Some(scope_name) = scope_name {

`

229

226

`// - 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

`+

));

`

231

231

`}

`

232

232

`}

`

233

233

``

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

`

301

301

`});

`

302

302

``

303

303

`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())))

`

305

305

`} else {

`

306

306

`None

`

307

307

`}

`