Auto merge of #12871 - fasterthanlime:sync-from-rust-2, r=Veykril

Sync from `rust-lang/rust`

This is the first subtree sync PR from `rust-lang/rust` to `rust-lang/rust-analyzer`, made by following the instructions at: https://doc.rust-lang.org/nightly/clippy/development/infrastructure/sync.html#performing-the-sync-from-rust-langrust-to-clippy

It includes all the commits that were made in:

  * https://github.com/rust-lang/rust/pull/99603

(And that were reviewed ahead of time by `@Veykril` + `@lnicola)`
This commit is contained in:
bors 2022-07-25 12:58:58 +00:00
commit 0b1ed70c12
23 changed files with 359 additions and 311 deletions

3
.gitattributes vendored
View File

@ -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
# Older git versions try to fix line endings on images, this prevents it.
*.png binary
*.jpg binary

View File

@ -516,6 +516,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)
}
@ -588,6 +591,7 @@ mod tests {
Some(format!("{}:\n{:?}\n", name, map))
})
.sorted()
.collect::<String>();
expect.assert_eq(&actual)
@ -621,15 +625,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)
"#]],
);
}
@ -671,13 +675,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)
"#]],
);
}
@ -697,11 +701,11 @@ mod tests {
}
",
expect![[r#"
lib:
- pub_macro (m)
main:
- m (t)
- m::pub_macro (m)
lib:
- pub_macro (m)
"#]],
);
}
@ -719,14 +723,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)
"#]],
);
}
@ -831,10 +835,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)
"#]],
);
}
@ -860,10 +864,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(
@ -920,13 +924,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)
"#]],
);
@ -935,10 +939,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)
"#]],
);
@ -948,12 +952,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)
"#]],
);
}
@ -989,12 +993,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)
"#]],
);
@ -1003,10 +1007,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)
"#]],
);
@ -1027,10 +1031,10 @@ mod tests {
"main",
Query::new("FMT".to_string()),
expect![[r#"
dep::fmt (t)
dep::FMT (v)
dep::fmt (v)
dep::FMT (t)
dep::FMT (v)
dep::fmt (t)
dep::fmt (v)
"#]],
);
@ -1068,10 +1072,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)
"#]],
);
}
@ -1091,10 +1095,10 @@ mod tests {
"main",
Query::new("FMT".to_string()),
expect![[r#"
dep::fmt (t)
dep::FMT (v)
dep::fmt (v)
dep::FMT (t)
dep::FMT (v)
dep::fmt (t)
dep::fmt (v)
"#]],
);

View File

@ -48,8 +48,8 @@
//! the result
pub mod attr_resolution;
pub mod diagnostics;
mod collector;
pub mod diagnostics;
mod mod_resolution;
mod path_resolution;
mod proc_macro;
@ -57,10 +57,11 @@ 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;
@ -431,7 +432,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);

View File

@ -648,11 +648,11 @@ mod b {
a: t
b: t
crate::b
T: v
crate::a
T: t v
crate::b
T: v
"#]],
);
}
@ -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
"#]],
);
}
@ -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
"#]],
)
}

View File

@ -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
@ -325,14 +330,9 @@ mod d {
crate::c::foo
Y: t v
crate::b
crate::d
Y: t v
foo: t
crate::a
foo: t
crate::a::foo
X: t v
"#]],
);
}

View File

@ -1,4 +1,5 @@
use super::*;
use itertools::Itertools;
#[test]
fn macro_rules_are_globally_visible() {
@ -439,15 +440,8 @@ macro_rules! baz {
m7: t
ok_double_macro_use_shadow: v
crate::m7
crate::m1
crate::m5
m6: t
crate::m5::m6
crate::m2
crate::m3
@ -462,6 +456,13 @@ macro_rules! baz {
ok_shadow_deep: v
crate::m3::m5
crate::m5
m6: t
crate::m5::m6
crate::m7
"#]],
);
// FIXME: should not see `NotFoundBefore`
@ -1171,11 +1172,15 @@ fn proc_attr(a: TokenStream, b: TokenStream) -> TokenStream { a }
);
let root = &def_map[def_map.root()].scope;
let actual = root.legacy_macros().map(|(name, _)| format!("{name}\n")).collect::<String>();
let actual = root
.legacy_macros()
.sorted_by(|a, b| std::cmp::Ord::cmp(&a.0, &b.0))
.map(|(name, _)| format!("{name}\n"))
.collect::<String>();
expect![[r#"
macro20
legacy
macro20
proc_attr
"#]]
.assert_eq(&actual);

View File

@ -26,3 +26,6 @@ hir = { path = "../hir", version = "0.0.0" }
test-utils = { path = "../test-utils" }
sourcegen = { path = "../sourcegen" }
expect-test = "1.4.0"
[features]
in-rust-tree = []

View File

@ -1,5 +1,6 @@
mod sourcegen;
mod generated;
#[cfg(not(feature = "in-rust-tree"))]
mod sourcegen;
use expect_test::expect;
use hir::{db::DefDatabase, Semantics};

View File

@ -59,6 +59,7 @@ r#####"
fs::write(dst, contents).unwrap();
}
}
#[derive(Debug)]
struct Section {
doc: String,
@ -104,9 +105,11 @@ impl Assist {
while lines.peek().is_some() {
let doc = take_until(lines.by_ref(), "```").trim().to_string();
assert!(
(doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.')) || assist.sections.len() > 0,
(doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.'))
|| assist.sections.len() > 0,
"\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n",
&assist.id, doc,
&assist.id,
doc,
);
let before = take_until(lines.by_ref(), "```");

View File

@ -29,3 +29,6 @@ expect-test = "1.4.0"
test-utils = { path = "../test-utils" }
sourcegen = { path = "../sourcegen" }
[features]
in-rust-tree = []

View File

@ -1,3 +1,4 @@
#[cfg(not(feature = "in-rust-tree"))]
mod sourcegen;
use expect_test::Expect;

View File

@ -42,3 +42,6 @@ toolchain = { path = "../toolchain", version = "0.0.0" }
[dev-dependencies]
test-utils = { path = "../test-utils" }
expect-test = "1.4.0"
[features]
in-rust-tree = ["ide-assists/in-rust-tree", "ide-diagnostics/in-rust-tree"]

View File

@ -62,17 +62,18 @@ fn main() {
Command::new(toolchain::cargo())
};
let output = cmd
.current_dir(&staging_dir)
cmd.current_dir(&staging_dir)
.args(&["build", "-p", "proc-macro-test-impl", "--message-format", "json"])
// Explicit override the target directory to avoid using the same one which the parent
// cargo is using, or we'll deadlock.
// This can happen when `CARGO_TARGET_DIR` is set or global config forces all cargo
// instance to use the same target directory.
.arg("--target-dir")
.arg(&target_dir)
.output()
.unwrap();
.arg(&target_dir);
println!("Running {:?}", cmd);
let output = cmd.output().unwrap();
if !output.status.success() {
println!("proc-macro-test-impl failed to build");
println!("============ stdout ============");

View File

@ -84,4 +84,9 @@ mbe = { path = "../mbe" }
[features]
jemalloc = ["jemallocator", "profile/jemalloc"]
force-always-assert = ["always-assert/force"]
in-rust-tree = ["proc-macro-srv/sysroot-abi"]
in-rust-tree = [
"proc-macro-srv/sysroot-abi",
"sourcegen/in-rust-tree",
"ide/in-rust-tree",
"syntax/in-rust-tree"
]

View File

@ -10,10 +10,11 @@
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#[cfg(not(feature = "in-rust-tree"))]
mod sourcegen;
mod tidy;
mod testdir;
mod support;
mod testdir;
mod tidy;
use std::{collections::HashMap, path::PathBuf, time::Instant};

View File

@ -3,8 +3,12 @@ use std::{
path::{Path, PathBuf},
};
use xshell::{cmd, Shell};
use xshell::Shell;
#[cfg(not(feature = "in-rust-tree"))]
use xshell::cmd;
#[cfg(not(feature = "in-rust-tree"))]
#[test]
fn check_code_formatting() {
let sh = &Shell::new().unwrap();
@ -168,6 +172,7 @@ See https://github.com/rust-lang/rust-clippy/issues/5537 for discussion.
}
}
#[cfg(not(feature = "in-rust-tree"))]
#[test]
fn check_licenses() {
let sh = &Shell::new().unwrap();

View File

@ -11,3 +11,6 @@ doctest = false
[dependencies]
xshell = "0.2.2"
[features]
in-rust-tree = []

View File

@ -34,3 +34,6 @@ ungrammar = "1.16.1"
test-utils = { path = "../test-utils" }
sourcegen = { path = "../sourcegen" }
[features]
in-rust-tree = []

View File

@ -1,5 +1,7 @@
mod sourcegen_ast;
#[cfg(not(feature = "in-rust-tree"))]
mod ast_src;
#[cfg(not(feature = "in-rust-tree"))]
mod sourcegen_ast;
use std::{
fs,

View File

@ -8,9 +8,9 @@
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
mod assert_linear;
pub mod bench_fixture;
mod fixture;
mod assert_linear;
use std::{
collections::BTreeMap,
@ -391,7 +391,8 @@ fn main() {
/// also creates a file at `./target/.slow_tests_cookie` which serves as a flag
/// that slow tests did run.
pub fn skip_slow_tests() -> bool {
let should_skip = std::env::var("CI").is_err() && std::env::var("RUN_SLOW_TESTS").is_err();
let should_skip = (std::env::var("CI").is_err() && std::env::var("RUN_SLOW_TESTS").is_err())
|| std::env::var("SKIP_SLOW_TESTS").is_ok();
if should_skip {
eprintln!("ignoring slow test");
} else {
@ -475,7 +476,7 @@ pub fn ensure_file_contents(file: &Path, contents: &str) {
pub fn try_ensure_file_contents(file: &Path, contents: &str) -> Result<(), ()> {
match std::fs::read_to_string(file) {
Ok(old_contents) if normalize_newlines(&old_contents) == normalize_newlines(contents) => {
return Ok(())
return Ok(());
}
_ => (),
}