Skip to content

Commit db6100d

Browse files
bors[bot]matklad
andauthored
Merge #4889
4889: Deprecate hir::Path::from_ast r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 672d160 + b5c4f2f commit db6100d

File tree

7 files changed

+17
-13
lines changed

7 files changed

+17
-13
lines changed

crates/ra_assists/src/ast_transform.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl<'a> SubstituteTypeParams<'a> {
106106
_ => return None,
107107
};
108108
// FIXME: use `hir::Path::from_src` instead.
109+
#[allow(deprecated)]
109110
let path = hir::Path::from_ast(path)?;
110111
let resolution = self.source_scope.resolve_hir_path(&path)?;
111112
match resolution {
@@ -150,6 +151,7 @@ impl<'a> QualifyPaths<'a> {
150151
return None;
151152
}
152153
// FIXME: use `hir::Path::from_src` instead.
154+
#[allow(deprecated)]
153155
let hir_path = hir::Path::from_ast(p.clone());
154156
let resolution = self.source_scope.resolve_hir_path(&hir_path?)?;
155157
match resolution {

crates/ra_hir_def/src/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub enum GenericArg {
154154

155155
impl Path {
156156
/// Converts an `ast::Path` to `Path`. Works with use trees.
157-
/// DEPRECATED: It does not handle `$crate` from macro call.
157+
#[deprecated = "Doesn't handle hygiene, don't add new calls, remove old ones"]
158158
pub fn from_ast(path: ast::Path) -> Option<Path> {
159159
lower::lower_path(path, &Hygiene::new_unhygienic())
160160
}

crates/ra_ide/src/completion/completion_context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ impl<'a> CompletionContext<'a> {
381381
self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some();
382382
self.has_type_args = segment.type_arg_list().is_some();
383383

384+
#[allow(deprecated)]
384385
if let Some(path) = hir::Path::from_ast(path.clone()) {
385386
if let Some(path_prefix) = path.qualifier() {
386387
self.path_prefix = Some(path_prefix);

crates/ra_parser/src/grammar/expressions.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ fn expr_no_struct(p: &mut Parser) {
5050
}
5151

5252
fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool {
53-
match kind {
54-
BIN_EXPR | RANGE_EXPR | IF_EXPR => false,
55-
_ => true,
56-
}
53+
let forbid = matches!(kind, BIN_EXPR | RANGE_EXPR);
54+
!forbid
5755
}
5856

5957
pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {

crates/ra_syntax/test_data/parser/inline/err/0009_attr_on_expr_not_allowed.rast

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,3 @@ SOURCE_FILE@0..48
5656
R_CURLY@46..47 "}"
5757
WHITESPACE@47..48 "\n"
5858
error 24..24: attributes are not allowed on BIN_EXPR
59-
error 44..44: attributes are not allowed on IF_EXPR

crates/test_utils/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
pub mod mark;
1111

1212
use std::{
13-
fs,
13+
env, fs,
1414
path::{Path, PathBuf},
1515
};
1616

17-
pub use ra_cfg::CfgOptions;
17+
use serde_json::Value;
1818
use stdx::split1;
19+
use text_size::{TextRange, TextSize};
1920

21+
pub use ra_cfg::CfgOptions;
2022
pub use relative_path::{RelativePath, RelativePathBuf};
2123
pub use rustc_hash::FxHashMap;
22-
use serde_json::Value;
23-
use text_size::{TextRange, TextSize};
2424

2525
pub use difference::Changeset as __Changeset;
2626

@@ -625,8 +625,6 @@ pub fn skip_slow_tests() -> bool {
625625
should_skip
626626
}
627627

628-
const REWRITE: bool = false;
629-
630628
/// Asserts that `expected` and `actual` strings are equal. If they differ only
631629
/// in trailing or leading whitespace the test won't fail and
632630
/// the contents of `actual` will be written to the file located at `path`.
@@ -642,7 +640,7 @@ fn assert_equal_text(expected: &str, actual: &str, path: &Path) {
642640
fs::write(path, actual).unwrap();
643641
return;
644642
}
645-
if REWRITE {
643+
if env::var("UPDATE_EXPECTATIONS").is_ok() {
646644
println!("rewriting {}", pretty_path.display());
647645
fs::write(path, actual).unwrap();
648646
return;

docs/dev/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ There are two kinds of tests:
342342
The purpose of inline tests is not to achieve full coverage by test cases, but to explain to the reader of the code what each particular `if` and `match` is responsible for.
343343
If you are tempted to add a large inline test, it might be a good idea to leave only the simplest example in place, and move the test to a manual `parser/ok` test.
344344

345+
To update test data, run with `UPDATE_EXPECTATIONS` variable:
346+
347+
```bash
348+
env UPDATE_EXPECTATIONS=1 cargo qt
349+
```
350+
345351
# Logging
346352

347353
Logging is done by both rust-analyzer and VS Code, so it might be tricky to

0 commit comments

Comments
 (0)