Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync from rust-lang/rust #12871

Merged
merged 11 commits into from
Jul 25, 2022
Merged
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
* text=auto eol=lf

# git grep shouldn't match entries in this benchmark data
bench_data/** binary
crates/syntax/test_data/** -text eof=LF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a fun story! The short answer it: it caused bors to fail to merge the rust-lang/rust subtree PR.

The longer story is: that change was introduced in #2166 - but it never did what was intended.

eof is not a gitattribute setting. eol is, but even that line used eol, it still wouldn't do anything, because of -text. So by mistake, 3 files were treated as binary, and checked out with CRLF line endings (those were the ones bors choked on).

After removing this line from .gitattribute, I re-added the folder to git, removed it from disk and used git restore to write it with the proper line endings. The relevant commit is here: rust-lang/rust@1bb63df

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did a fresh clone of that branch from Windows and ran cargo test with the latest stable, no issues whatsoever.

I'm still convinced #2166 wasn't needed, as explained here: #2166 (comment)


# Older git versions try to fix line endings on images, this prevents it.
*.png binary
*.jpg binary
Expand Down
86 changes: 43 additions & 43 deletions crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@ fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> ImportMap {

let visible_items = mod_data.scope.entries().filter_map(|(name, per_ns)| {
let per_ns = per_ns.filter_visibility(|vis| vis == Visibility::Public);
if per_ns.is_none() {
None
} else {
Some((name, per_ns))
}
if per_ns.is_none() { None } else { Some((name, per_ns)) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the result of some nightly only options rust-lang/rust uses: https://github.com/rust-lang/rust/blob/2f320a224e827b400be25966755a621779f797cc/rustfmt.toml#L2-L4 Stable rustfmt without those options as used in this repo will revert these changes. You will need to do one of:

  • Copy the options to a rustfmt.toml in this repo and switch to nightly rustfmt
  • Ignore rust-analyzer for rustfmt in rust-lang/rust
  • Explicitly use the stable defaults of those options in rustfmt.toml in this repo and hope rustfmt will pick them in favor of the global rustfmt.toml of rust-lang/rust

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one's my bad, I had "format on save" set up when doing those edits. I'll revert them in this PR.

});

for (name, per_ns) in visible_items {
Expand Down Expand Up @@ -516,6 +512,9 @@ mod tests {
mark
))
})
// HashSet iteration order isn't defined - it's different on
// x86_64 and i686 at the very least
.sorted()
.collect::<String>();
expect.assert_eq(&actual)
}
Expand Down Expand Up @@ -588,6 +587,7 @@ mod tests {

Some(format!("{}:\n{:?}\n", name, map))
})
.sorted()
.collect::<String>();

expect.assert_eq(&actual)
Expand Down Expand Up @@ -621,15 +621,15 @@ mod tests {
struct Priv;
",
expect![[r#"
lib:
- Pub (t)
- Pub2 (t)
- Pub2 (v)
main:
- publ1 (t)
- real_pu2 (t)
- real_pub (t)
- real_pub::Pub (t)
lib:
- Pub (t)
- Pub2 (t)
- Pub2 (v)
"#]],
);
}
Expand Down Expand Up @@ -671,13 +671,13 @@ mod tests {
pub struct S;
",
expect![[r#"
lib:
- S (t)
- S (v)
main:
- m (t)
- m::S (t)
- m::S (v)
lib:
- S (t)
- S (v)
"#]],
);
}
Expand All @@ -697,11 +697,11 @@ mod tests {
}
",
expect![[r#"
lib:
- pub_macro (m)
main:
- m (t)
- m::pub_macro (m)
lib:
- pub_macro (m)
"#]],
);
}
Expand All @@ -719,14 +719,14 @@ mod tests {
}
",
expect![[r#"
main:
- reexported_module (t)
- reexported_module::S (t)
- reexported_module::S (v)
lib:
- module (t)
- module::S (t)
- module::S (v)
main:
- reexported_module (t)
- reexported_module::S (t)
- reexported_module::S (v)
"#]],
);
}
Expand Down Expand Up @@ -831,10 +831,10 @@ mod tests {
Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
expect![[r#"
dep::fmt (t)
dep::fmt::Display::format_method (a)
dep::fmt::Display (t)
dep::fmt::Display::FMT_CONST (a)
dep::fmt::Display::format_function (a)
dep::fmt::Display::format_method (a)
"#]],
);
}
Expand All @@ -860,10 +860,10 @@ mod tests {
"main",
Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy).assoc_items_only(),
expect![[r#"
dep::fmt::Display::format_method (a)
dep::fmt::Display::FMT_CONST (a)
dep::fmt::Display::format_function (a)
"#]],
dep::fmt::Display::FMT_CONST (a)
dep::fmt::Display::format_function (a)
dep::fmt::Display::format_method (a)
"#]],
);

check_search(
Expand Down Expand Up @@ -920,13 +920,13 @@ mod tests {
"main",
Query::new("fmt".to_string()).search_mode(SearchMode::Fuzzy),
expect![[r#"
dep::fmt (t)
dep::format (f)
dep::Fmt (v)
dep::Fmt (m)
dep::Fmt (t)
dep::fmt::Display::fmt (a)
dep::Fmt (v)
dep::fmt (t)
dep::fmt::Display (t)
dep::fmt::Display::fmt (a)
dep::format (f)
"#]],
);

Expand All @@ -935,10 +935,10 @@ mod tests {
"main",
Query::new("fmt".to_string()).search_mode(SearchMode::Equals),
expect![[r#"
dep::fmt (t)
dep::Fmt (v)
dep::Fmt (m)
dep::Fmt (t)
dep::Fmt (v)
dep::fmt (t)
dep::fmt::Display::fmt (a)
"#]],
);
Expand All @@ -948,12 +948,12 @@ mod tests {
"main",
Query::new("fmt".to_string()).search_mode(SearchMode::Contains),
expect![[r#"
dep::fmt (t)
dep::Fmt (v)
dep::Fmt (m)
dep::Fmt (t)
dep::fmt::Display::fmt (a)
dep::Fmt (v)
dep::fmt (t)
dep::fmt::Display (t)
dep::fmt::Display::fmt (a)
"#]],
);
}
Expand Down Expand Up @@ -989,12 +989,12 @@ mod tests {
"main",
Query::new("fmt".to_string()),
expect![[r#"
dep::fmt (t)
dep::Fmt (v)
dep::Fmt (m)
dep::Fmt (t)
dep::fmt::Display::fmt (a)
dep::Fmt (v)
dep::fmt (t)
dep::fmt::Display (t)
dep::fmt::Display::fmt (a)
"#]],
);

Expand All @@ -1003,10 +1003,10 @@ mod tests {
"main",
Query::new("fmt".to_string()).name_only(),
expect![[r#"
dep::fmt (t)
dep::Fmt (v)
dep::Fmt (m)
dep::Fmt (t)
dep::Fmt (v)
dep::fmt (t)
dep::fmt::Display::fmt (a)
"#]],
);
Expand All @@ -1027,10 +1027,10 @@ mod tests {
"main",
Query::new("FMT".to_string()),
expect![[r#"
dep::fmt (t)
dep::FMT (t)
dep::FMT (v)
dep::fmt (t)
dep::fmt (v)
dep::FMT (t)
"#]],
);

Expand Down Expand Up @@ -1068,10 +1068,10 @@ mod tests {
"main",
Query::new("".to_string()).limit(2),
expect![[r#"
dep::fmt (t)
dep::Fmt (m)
dep::Fmt (t)
dep::Fmt (v)
dep::Fmt (m)
dep::fmt (t)
"#]],
);
}
Expand All @@ -1091,10 +1091,10 @@ mod tests {
"main",
Query::new("FMT".to_string()),
expect![[r#"
dep::fmt (t)
dep::FMT (t)
dep::FMT (v)
dep::fmt (t)
dep::fmt (v)
dep::FMT (t)
"#]],
);

Expand Down
15 changes: 7 additions & 8 deletions crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,20 @@
//! the result

pub mod attr_resolution;
pub mod diagnostics;
mod collector;
pub mod diagnostics;
mod mod_resolution;
mod path_resolution;
mod proc_macro;

#[cfg(test)]
mod tests;

use std::sync::Arc;
use std::{cmp::Ord, sync::Arc};

use base_db::{CrateId, Edition, FileId};
use hir_expand::{name::Name, InFile, MacroDefId};
use itertools::Itertools;
use la_arena::Arena;
use profile::Count;
use rustc_hash::FxHashMap;
Expand Down Expand Up @@ -333,11 +334,7 @@ impl DefMap {

pub(crate) fn crate_root(&self, db: &dyn DefDatabase) -> ModuleId {
self.with_ancestor_maps(db, self.root, &mut |def_map, _module| {
if def_map.block.is_none() {
Some(def_map.module_id(def_map.root))
} else {
None
}
if def_map.block.is_none() { Some(def_map.module_id(def_map.root)) } else { None }
})
.expect("DefMap chain without root")
}
Expand Down Expand Up @@ -431,7 +428,9 @@ impl DefMap {

map.modules[module].scope.dump(buf);

for (name, child) in map.modules[module].children.iter() {
for (name, child) in
map.modules[module].children.iter().sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
{
let path = format!("{}::{}", path, name);
buf.push('\n');
go(buf, map, &path, *child);
Expand Down
20 changes: 10 additions & 10 deletions crates/hir-def/src/nameres/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,11 +648,11 @@ mod b {
a: t
b: t

crate::b
T: v

crate::a
T: t v

crate::b
T: v
"#]],
);
}
Expand Down Expand Up @@ -704,13 +704,13 @@ use crate::reex::*;
reex: t
tr: t

crate::tr
PrivTr: t
PubTr: t

crate::reex
_: t
_: t

crate::tr
PrivTr: t
PubTr: t
"#]],
);
}
Expand Down Expand Up @@ -920,14 +920,14 @@ use some_module::unknown_func;
some_module: t
unknown_func: v

crate::some_module
unknown_func: v

crate::other_module
some_submodule: t

crate::other_module::some_submodule
unknown_func: v

crate::some_module
unknown_func: v
"#]],
)
}
18 changes: 9 additions & 9 deletions crates/hir-def/src/nameres/tests/globs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,13 @@ mod d {
c: t
d: t

crate::d
Y: t v
crate::a
foo: t

crate::a::foo
X: t v

crate::b
foo: t

crate::c
Expand All @@ -325,14 +330,9 @@ mod d {
crate::c::foo
Y: t v

crate::b
foo: t

crate::a
crate::d
Y: t v
foo: t

crate::a::foo
X: t v
"#]],
);
}
Loading