Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

Commit 40a91a2

Browse files
committed
test: up
1 parent 5593c54 commit 40a91a2

4 files changed

Lines changed: 144 additions & 65 deletions

File tree

src/project.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ra_ide::{
1414
};
1515
use ra_ide_db::imports::insert_use::{ImportGranularity, InsertUseConfig, PrefixKind};
1616
use ra_ide_db::{ChangeWithProcMacros, SnippetCap};
17-
use ra_project_model::{CargoConfig, ProjectManifest, ProjectWorkspace};
17+
use ra_project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
1818
use ra_vfs::{AbsPathBuf, VfsPath};
1919
use tempfile::TempDir;
2020

@@ -44,7 +44,6 @@ pub struct Project {
4444
host: Option<AnalysisHost>,
4545
analysis: Analysis,
4646
queries: Vec<(QueryKind, TextSize)>,
47-
no_errors: bool,
4847

4948
line_index: LineIndex,
5049
token_to_ranges: HashMap<TokenId, Vec<TextRange>>,
@@ -161,7 +160,6 @@ impl Project {
161160
let parse_result = find_queries(source);
162161
let source = parse_result.code;
163162
let queries = parse_result.queries;
164-
let no_errors = parse_result.no_errors;
165163

166164
// Always use cargo mode - it's needed for std resolution and external deps
167165
let bootstrap = bootstrap_project_in(
@@ -172,7 +170,10 @@ impl Project {
172170
settings.target_dir,
173171
)?;
174172

175-
let cargo_config = CargoConfig::default();
173+
let cargo_config = CargoConfig {
174+
sysroot: Some(RustLibSource::Discover),
175+
..CargoConfig::default()
176+
};
176177
let no_progress = &|_| ();
177178
let load_cargo_config = LoadCargoConfig {
178179
load_out_dirs_from_check: true,
@@ -206,7 +207,6 @@ impl Project {
206207
host: Some(host),
207208
analysis,
208209
queries,
209-
no_errors,
210210

211211
line_index,
212212
token_to_ranges,
@@ -223,7 +223,6 @@ impl Project {
223223
let parse_result = find_queries(&new_code);
224224
let new_code = parse_result.code;
225225
let queries = parse_result.queries;
226-
let no_errors = parse_result.no_errors;
227226

228227
let (host, analysis, fid) = match self.host {
229228
Some(mut host) => {
@@ -246,7 +245,6 @@ impl Project {
246245
host,
247246
analysis,
248247
queries,
249-
no_errors,
250248
fid,
251249
token_to_ranges,
252250
token_data,
@@ -509,11 +507,7 @@ impl Project {
509507
}
510508

511509
pub fn twoslasher(&self) -> Result<TwoSlash> {
512-
let errors = if self.no_errors {
513-
vec![]
514-
} else {
515-
self.diagnostics()?
516-
};
510+
let errors = self.diagnostics()?;
517511
let static_quick_infos = self.ident_hovers()?;
518512
let queries = self.queries();
519513

src/project_test.rs

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn example() {
7474
},
7575
{
7676
"targetString": "i32",
77-
"text": "i32",
77+
"text": "i32\n\n---\n\nThe 32-bit signed integer type.",
7878
"start": 30,
7979
"length": 3,
8080
"line": 1,
@@ -182,23 +182,23 @@ pub fn example() {
182182
},
183183
{
184184
"targetString": "i32",
185-
"text": "i32",
185+
"text": "i32\n\n---\n\nThe 32-bit signed integer type.",
186186
"start": 10,
187187
"length": 3,
188188
"line": 0,
189189
"character": 10
190190
},
191191
{
192192
"targetString": "i32",
193-
"text": "i32",
193+
"text": "i32\n\n---\n\nThe 32-bit signed integer type.",
194194
"start": 18,
195195
"length": 3,
196196
"line": 0,
197197
"character": 18
198198
},
199199
{
200200
"targetString": "i32",
201-
"text": "i32",
201+
"text": "i32\n\n---\n\nThe 32-bit signed integer type.",
202202
"start": 26,
203203
"length": 3,
204204
"line": 0,
@@ -339,15 +339,15 @@ pub fn example() {
339339
},
340340
{
341341
"targetString": "f64",
342-
"text": "f64",
342+
"text": "f64\n\n---\n\nA 64-bit floating-point type (specifically, the \"binary64\" type defined in IEEE 754-2008).\n\nThis type is very similar to [`prim@f32`](`prim@f32`), but has increased precision by using twice as many\nbits. Please see [the documentation for `f32`](prim@f32) or [Wikipedia on double-precision\nvalues](https://en.wikipedia.org/wiki/Double-precision_floating-point_format) for more information.\n\n*[See also the `std::f64::consts` module](crate::f64::consts).*",
343343
"start": 26,
344344
"length": 3,
345345
"line": 1,
346346
"character": 7
347347
},
348348
{
349349
"targetString": "f64",
350-
"text": "f64",
350+
"text": "f64\n\n---\n\nA 64-bit floating-point type (specifically, the \"binary64\" type defined in IEEE 754-2008).\n\nThis type is very similar to [`prim@f32`](`prim@f32`), but has increased precision by using twice as many\nbits. Please see [the documentation for `f32`](prim@f32) or [Wikipedia on double-precision\nvalues](https://en.wikipedia.org/wiki/Double-precision_floating-point_format) for more information.\n\n*[See also the `std::f64::consts` module](crate::f64::consts).*",
351351
"start": 38,
352352
"length": 3,
353353
"line": 2,
@@ -475,7 +475,7 @@ pub fn example() {
475475
},
476476
{
477477
"targetString": "i32",
478-
"text": "i32",
478+
"text": "i32\n\n---\n\nThe 32-bit signed integer type.",
479479
"start": 30,
480480
"length": 3,
481481
"line": 1,
@@ -491,7 +491,7 @@ pub fn example() {
491491
},
492492
{
493493
"targetString": "u64",
494-
"text": "u64",
494+
"text": "u64\n\n---\n\nThe 64-bit unsigned integer type.",
495495
"start": 50,
496496
"length": 3,
497497
"line": 2,
@@ -666,7 +666,7 @@ pub fn example() {
666666
},
667667
{
668668
"targetString": "i32",
669-
"text": "i32",
669+
"text": "i32\n\n---\n\nThe 32-bit signed integer type.",
670670
"start": 30,
671671
"length": 3,
672672
"line": 1,
@@ -783,15 +783,15 @@ pub fn example() {
783783
},
784784
{
785785
"targetString": "i32",
786-
"text": "i32",
786+
"text": "i32\n\n---\n\nThe 32-bit signed integer type.",
787787
"start": 30,
788788
"length": 3,
789789
"line": 1,
790790
"character": 13
791791
},
792792
{
793793
"targetString": "i32",
794-
"text": "i32",
794+
"text": "i32\n\n---\n\nThe 32-bit signed integer type.",
795795
"start": 48,
796796
"length": 3,
797797
"line": 2,
@@ -852,6 +852,12 @@ pub fn example() {
852852
{
853853
"name": "baz"
854854
},
855+
{
856+
"name": "try_into"
857+
},
858+
{
859+
"name": "into"
860+
},
855861
{
856862
"name": "ref"
857863
},
@@ -1032,15 +1038,15 @@ pub fn example() {
10321038
},
10331039
{
10341040
"targetString": "i32",
1035-
"text": "i32",
1041+
"text": "i32\n\n---\n\nThe 32-bit signed integer type.",
10361042
"start": 32,
10371043
"length": 3,
10381044
"line": 1,
10391045
"character": 11
10401046
},
10411047
{
10421048
"targetString": "i32",
1043-
"text": "i32",
1049+
"text": "i32\n\n---\n\nThe 32-bit signed integer type.",
10441050
"start": 145,
10451051
"length": 3,
10461052
"line": 8,
@@ -1138,6 +1144,12 @@ pub fn example() {
11381144
{
11391145
"name": "value"
11401146
},
1147+
{
1148+
"name": "try_into"
1149+
},
1150+
{
1151+
"name": "into"
1152+
},
11411153
{
11421154
"name": "get"
11431155
},
@@ -1208,16 +1220,6 @@ pub fn example() {
12081220
"length": 3,
12091221
"line": 15,
12101222
"character": 6
1211-
},
1212-
{
1213-
"renderedMessage": "cannot move `i32` out of reference",
1214-
"id": "E0507",
1215-
"category": "Error",
1216-
"code": 0,
1217-
"start": 159,
1218-
"length": 10,
1219-
"line": 9,
1220-
"character": 8
12211223
}
12221224
],
12231225
"playgroundURL": "https://play.rust-lang.org"
@@ -1334,20 +1336,28 @@ pub fn example() {
13341336
"staticQuickInfos": [
13351337
{
13361338
"targetString": "Config",
1337-
"text": "test_project\n\npub struct Config {\n pub name: {unknown},\n pub value: i32,\n}",
1339+
"text": "test_project\n\npub struct Config {\n pub name: String,\n pub value: i32,\n}",
13381340
"start": 33,
13391341
"length": 6,
13401342
"line": 1,
13411343
"character": 14
13421344
},
13431345
{
13441346
"targetString": "name",
1345-
"text": "test_project::Config\n\npub name: {unknown}",
1347+
"text": "test_project::Config\n\npub name: String",
13461348
"start": 42,
13471349
"length": 4,
13481350
"line": 1,
13491351
"character": 23
13501352
},
1353+
{
1354+
"targetString": "String",
1355+
"text": "alloc::string\n\npub struct String {\n vec: Vec<u8>,\n}\n\n---\n\nA UTF-8–encoded, growable string.\n\n`String` is the most common string type. It has ownership over the contents\nof the string, stored in a heap-allocated buffer (see [Representation](https://doc.rust-lang.org/stable/alloc/string/struct.String.html#representation)).\nIt is closely related to its borrowed counterpart, the primitive [`str`].\n\n# Examples\n\nYou can create a `String` from [a literal string](https://doc.rust-lang.org/stable/alloc/str/index.html) with [`String::from`]:\n\nlet hello = String::from(\"Hello, world!\");\n\nYou can append a [`char`](https://doc.rust-lang.org/nightly/core/primitive.char.html) to a `String` with the [`push`] method, and\nappend a [`&str`] with the [`push_str`] method:\n\nlet mut hello = String::from(\"Hello, \");\n\nhello.push('w');\nhello.push_str(\"orld!\");\n\nIf you have a vector of UTF-8 bytes, you can create a `String` from it with\nthe [`from_utf8`] method:\n\n// some bytes, in a vector\nlet sparkle_heart = vec![240, 159, 146, 150];\n\n// We know these bytes are valid, so we'll use `unwrap()`.\nlet sparkle_heart = String::from_utf8(sparkle_heart).unwrap();\n\nassert_eq!(\"💖\", sparkle_heart);\n\n# UTF-8\n\n`String`s are always valid UTF-8. If you need a non-UTF-8 string, consider\n[`OsString`](https://doc.rust-lang.org/stable/std/ffi/struct.OsString.html). It is similar, but without the UTF-8 constraint. Because UTF-8\nis a variable width encoding, `String`s are typically smaller than an array of\nthe same `char`s:\n\n// `s` is ASCII which represents each `char` as one byte\nlet s = \"hello\";\nassert_eq!(s.len(), 5);\n\n// A `char` array with the same contents would be longer because\n// every `char` is four bytes\nlet s = ['h', 'e', 'l', 'l', 'o'];\nlet size: usize = s.into_iter().map(|c| size_of_val(&c)).sum();\nassert_eq!(size, 20);\n\n// However, for non-ASCII strings, the difference will be smaller\n// and sometimes they are the same\nlet s = \"💖💖💖💖💖\";\nassert_eq!(s.len(), 20);\n\nlet s = ['💖', '💖', '💖', '💖', '💖'];\nlet size: usize = s.into_iter().map(|c| size_of_val(&c)).sum();\nassert_eq!(size, 20);\n\nThis raises interesting questions as to how `s[i]` should work.\nWhat should `i` be here? Several options include byte indices and\n`char` indices but, because of UTF-8 encoding, only byte indices\nwould provide constant time indexing. Getting the `i`th `char`, for\nexample, is available using [`chars`]:\n\nlet s = \"hello\";\nlet third_character = s.chars().nth(2);\nassert_eq!(third_character, Some('l'));\n\nlet s = \"💖💖💖💖💖\";\nlet third_character = s.chars().nth(2);\nassert_eq!(third_character, Some('💖'));\n\nNext, what should `s[i]` return? Because indexing returns a reference\nto underlying data it could be `&u8`, `&[u8]`, or something similar.\nSince we're only providing one index, `&u8` makes the most sense but that\nmight not be what the user expects and can be explicitly achieved with\n[`as_bytes()`]:\n\n// The first byte is 104 - the byte value of `'h'`\nlet s = \"hello\";\nassert_eq!(s.as_bytes()[0], 104);\n// or\nassert_eq!(s.as_bytes()[0], b'h');\n\n// The first byte is 240 which isn't obviously useful\nlet s = \"💖💖💖💖💖\";\nassert_eq!(s.as_bytes()[0], 240);\n\nDue to these ambiguities/restrictions, indexing with a `usize` is simply\nforbidden:\n\n```compile_fail,E0277\nlet s = \"hello\";\n\n// The following will not compile!\nprintln!(\"The first letter of s is {}\", s[0]);\n\nIt is more clear, however, how `&s[i..j]` should work (that is,\nindexing with a range). It should accept byte indices (to be constant-time)\nand return a `&str` which is UTF-8 encoded. This is also called \"string slicing\".\nNote this will panic if the byte indices provided are not character\nboundaries - see [`is_char_boundary`] for more details. See the implementations\nfor [`SliceIndex<str>`] for more details on string slicing. For a non-panicking\nversion of string slicing, see [`get`].\n\nThe [`bytes`] and [`chars`] methods return iterators over the bytes and\ncodepoints of the string, respectively. To iterate over codepoints along\nwith byte indices, use [`char_indices`].\n\n# Deref\n\n`String` implements <code>\n[Deref]\\<Target = [str]\\></code>, and so inherits all of [`str`]'s\nmethods. In addition, this means that you can pass a `String` to a\nfunction which takes a [`&str`] by using an ampersand (`&`):\n\nfn takes_str(s: &str) { }\n\nlet s = String::from(\"Hello\");\n\ntakes_str(&s);\n\nThis will create a [`&str`] from the `String` and pass it in. This\nconversion is very inexpensive, and so generally, functions will accept\n[`&str`]s as arguments unless they need a `String` for some specific\nreason.\n\nIn certain cases Rust doesn't have enough information to make this\nconversion, known as [`Deref`] coercion. In the following example a string\nslice [`&'a str`](https://doc.rust-lang.org/stable/alloc/str/index.html) implements the trait `TraitExample`, and the function\n`example_func` takes anything that implements the trait. In this case Rust\nwould need to make two implicit conversions, which Rust doesn't have the\nmeans to do. For that reason, the following example will not compile.\n\n```compile_fail,E0277\ntrait TraitExample {}\n\nimpl<'a> TraitExample for &'a str {}\n\nfn example_func<A: TraitExample>(example_arg: A) {}\n\nlet example_string = String::from(\"example_string\");\nexample_func(&example_string);\n\nThere are two options that would work instead. The first would be to\nchange the line `example_func(&example_string);` to\n`example_func(example_string.as_str());`, using the method [`as_str()`]\nto explicitly extract the string slice containing the string. The second\nway changes `example_func(&example_string);` to\n`example_func(&*example_string);`. In this case we are dereferencing a\n`String` to a [`str`], then referencing the [`str`] back to\n[`&str`]. The second way is more idiomatic, however both work to do the\nconversion explicitly rather than relying on the implicit conversion.\n\n# Representation\n\nA `String` is made up of three components: a pointer to some bytes, a\nlength, and a capacity. The pointer points to the internal buffer which `String`\nuses to store its data. The length is the number of bytes currently stored\nin the buffer, and the capacity is the size of the buffer in bytes. As such,\nthe length will always be less than or equal to the capacity.\n\nThis buffer is always stored on the heap.\n\nYou can look at these with the [`as_ptr`], [`len`], and [`capacity`]\nmethods:\n\nuse std::mem;\n\nlet story = String::from(\"Once upon a time...\");\n\n// Prevent automatically dropping the String's data\nlet mut story = mem::ManuallyDrop::new(story);\n\nlet ptr = story.as_mut_ptr();\nlet len = story.len();\nlet capacity = story.capacity();\n\n// story has nineteen bytes\nassert_eq!(19, len);\n\n// We can re-build a String out of ptr, len, and capacity. This is all\n// unsafe because we are responsible for making sure the components are\n// valid:\nlet s = unsafe { String::from_raw_parts(ptr, len, capacity) } ;\n\nassert_eq!(String::from(\"Once upon a time...\"), s);\n\nIf a `String` has enough capacity, adding elements to it will not\nre-allocate. For example, consider this program:\n\nlet mut s = String::new();\n\nprintln!(\"{}\", s.capacity());\n\nfor _ in 0..5 {\n s.push_str(\"hello\");\n println!(\"{}\", s.capacity());\n}\n\nThis will output the following:\n\n```text\n0\n8\n16\n16\n32\n32\n\nAt first, we have no memory allocated at all, but as we append to the\nstring, it increases its capacity appropriately. If we instead use the\n[`with_capacity`] method to allocate the correct capacity initially:\n\nlet mut s = String::with_capacity(25);\n\nprintln!(\"{}\", s.capacity());\n\nfor _ in 0..5 {\n s.push_str(\"hello\");\n println!(\"{}\", s.capacity());\n}\n\nWe end up with a different output:\n\n```text\n25\n25\n25\n25\n25\n25\n\nHere, there's no need to allocate more memory inside the loop.",
1356+
"start": 48,
1357+
"length": 6,
1358+
"line": 1,
1359+
"character": 29
1360+
},
13511361
{
13521362
"targetString": "value",
13531363
"text": "test_project::Config\n\npub value: i32",
@@ -1371,6 +1381,14 @@ pub fn example() {
13711381
"length": 3,
13721382
"line": 1,
13731383
"character": 8
1384+
},
1385+
{
1386+
"targetString": "new",
1387+
"text": "alloc::string::String\n\npub const fn new() -> String\n\n---\n\nCreates a new empty `String`.\n\nGiven that the `String` is empty, this will not allocate any initial\nbuffer. While that means that this initial operation is very\ninexpensive, it may cause excessive allocation later when you add\ndata. If you have an idea of how much data the `String` will hold,\nconsider the [`with_capacity`] method to prevent excessive\nre-allocation.\n\n# Examples\n\nlet s = String::new();",
1388+
"start": 56,
1389+
"length": 3,
1390+
"line": 1,
1391+
"character": 37
13741392
}
13751393
],
13761394
"queries": [
@@ -1384,7 +1402,18 @@ pub fn example() {
13841402
}
13851403
],
13861404
"tags": [],
1387-
"errors": [],
1405+
"errors": [
1406+
{
1407+
"renderedMessage": "unused variable",
1408+
"id": "unused_variables",
1409+
"category": "Warning",
1410+
"code": 0,
1411+
"start": 27,
1412+
"length": 3,
1413+
"line": 1,
1414+
"character": 8
1415+
}
1416+
],
13881417
"playgroundURL": "https://play.rust-lang.org"
13891418
}
13901419
"#);

0 commit comments

Comments
 (0)