Skip to content

Commit 33f6a59

Browse files
committed
Auto merge of #154253 - JonathanBrouwer:rollup-LLZUsz2, r=JonathanBrouwer
Rollup of 13 pull requests Successful merges: - rust-lang/rust#154241 (`rust-analyzer` subtree update) - rust-lang/rust#153686 (`std`: include `dlmalloc` for all non-wasi Wasm targets) - rust-lang/rust#154105 (bootstrap: Pass `--features=rustc` to rustc_transmute) - rust-lang/rust#153069 ([BPF] add target feature allows-misaligned-mem-access) - rust-lang/rust#154085 (Parenthesize or-patterns in prefix pattern positions in pretty printer) - rust-lang/rust#154191 (refactor RangeFromIter overflow-checks impl) - rust-lang/rust#154207 (Refactor query loading) - rust-lang/rust#153540 (drop derive helpers during attribute parsing) - rust-lang/rust#154140 (Document consteval behavior of ub_checks, overflow_checks, is_val_statically_known.) - rust-lang/rust#154161 (On E0277 tweak help when single type impls traits) - rust-lang/rust#154218 (interpret/validity: remove unreachable error kind) - rust-lang/rust#154225 (diagnostics: avoid ICE in confusable_method_name for associated functions) - rust-lang/rust#154228 (Improve inline assembly error messages)
2 parents d188f4c + 7838474 commit 33f6a59

74 files changed

Lines changed: 2814 additions & 810 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ analyzing Rust code. See
2020
[Architecture](https://rust-analyzer.github.io/book/contributing/architecture.html)
2121
in the manual.
2222

23+
[![codecov](https://codecov.io/github/rust-lang/rust-analyzer/graph/badge.svg)](https://app.codecov.io/github/rust-lang/rust-analyzer/tree/master)
24+
2325
## Quick Start
2426

2527
https://rust-analyzer.github.io/book/installation.html

crates/hir-ty/src/next_solver/ir_print.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Things related to IR printing in the next-trait-solver.
22
3-
use std::any::type_name_of_val;
4-
53
use rustc_type_ir::{self as ty, ir_print::IrPrint};
64

75
use super::SolverDefId;
@@ -82,7 +80,10 @@ impl<'db> IrPrint<ty::TraitPredicate<Self>> for DbInterner<'db> {
8280
t: &ty::TraitPredicate<Self>,
8381
fmt: &mut std::fmt::Formatter<'_>,
8482
) -> std::fmt::Result {
85-
fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
83+
match t.polarity {
84+
ty::PredicatePolarity::Positive => write!(fmt, "{:?}", t.trait_ref),
85+
ty::PredicatePolarity::Negative => write!(fmt, "!{:?}", t.trait_ref),
86+
}
8687
}
8788
}
8889
impl<'db> IrPrint<rustc_type_ir::HostEffectPredicate<Self>> for DbInterner<'db> {
@@ -97,7 +98,11 @@ impl<'db> IrPrint<rustc_type_ir::HostEffectPredicate<Self>> for DbInterner<'db>
9798
t: &rustc_type_ir::HostEffectPredicate<Self>,
9899
fmt: &mut std::fmt::Formatter<'_>,
99100
) -> std::fmt::Result {
100-
fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
101+
let prefix = match t.constness {
102+
ty::BoundConstness::Const => "const",
103+
ty::BoundConstness::Maybe => "[const]",
104+
};
105+
write!(fmt, "{prefix} {:?}", t.trait_ref)
101106
}
102107
}
103108
impl<'db> IrPrint<ty::ExistentialTraitRef<Self>> for DbInterner<'db> {
@@ -183,7 +188,7 @@ impl<'db> IrPrint<ty::NormalizesTo<Self>> for DbInterner<'db> {
183188
t: &ty::NormalizesTo<Self>,
184189
fmt: &mut std::fmt::Formatter<'_>,
185190
) -> std::fmt::Result {
186-
fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
191+
write!(fmt, "NormalizesTo({} -> {:?})", t.alias, t.term)
187192
}
188193
}
189194
impl<'db> IrPrint<ty::SubtypePredicate<Self>> for DbInterner<'db> {
@@ -198,7 +203,7 @@ impl<'db> IrPrint<ty::SubtypePredicate<Self>> for DbInterner<'db> {
198203
t: &ty::SubtypePredicate<Self>,
199204
fmt: &mut std::fmt::Formatter<'_>,
200205
) -> std::fmt::Result {
201-
fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
206+
write!(fmt, "{:?} <: {:?}", t.a, t.b)
202207
}
203208
}
204209
impl<'db> IrPrint<ty::CoercePredicate<Self>> for DbInterner<'db> {
@@ -210,7 +215,7 @@ impl<'db> IrPrint<ty::CoercePredicate<Self>> for DbInterner<'db> {
210215
t: &ty::CoercePredicate<Self>,
211216
fmt: &mut std::fmt::Formatter<'_>,
212217
) -> std::fmt::Result {
213-
fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
218+
write!(fmt, "CoercePredicate({:?} -> {:?})", t.a, t.b)
214219
}
215220
}
216221
impl<'db> IrPrint<ty::FnSig<Self>> for DbInterner<'db> {
@@ -219,7 +224,9 @@ impl<'db> IrPrint<ty::FnSig<Self>> for DbInterner<'db> {
219224
}
220225

221226
fn print_debug(t: &ty::FnSig<Self>, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
222-
fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
227+
let tys = t.inputs_and_output.as_slice();
228+
let (output, inputs) = tys.split_last().unwrap();
229+
write!(fmt, "fn({:?}) -> {:?}", inputs, output)
223230
}
224231
}
225232

@@ -235,6 +242,10 @@ impl<'db> IrPrint<rustc_type_ir::PatternKind<DbInterner<'db>>> for DbInterner<'d
235242
t: &rustc_type_ir::PatternKind<DbInterner<'db>>,
236243
fmt: &mut std::fmt::Formatter<'_>,
237244
) -> std::fmt::Result {
238-
fmt.write_str(&format!("TODO: {:?}", type_name_of_val(t)))
245+
match t {
246+
ty::PatternKind::Range { start, end } => write!(fmt, "{:?}..={:?}", start, end),
247+
ty::PatternKind::Or(list) => write!(fmt, "or({:?})", list),
248+
ty::PatternKind::NotNull => fmt.write_str("!null"),
249+
}
239250
}
240251
}

crates/hir-ty/src/target_feature.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ const TARGET_FEATURE_IMPLICATIONS_RAW: &[(&str, &[&str])] = &[
217217
("relaxed-simd", &["simd128"]),
218218
// BPF
219219
("alu32", &[]),
220+
("allows-misaligned-mem-access", &[]),
220221
// CSKY
221222
("10e60", &["7e10"]),
222223
("2e3", &["e2"]),

crates/hir/src/diagnostics.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,6 @@ macro_rules! diagnostics {
5151
)*
5252
};
5353
}
54-
// FIXME Accept something like the following in the macro call instead
55-
// diagnostics![
56-
// pub struct BreakOutsideOfLoop {
57-
// pub expr: InFile<AstPtr<ast::Expr>>,
58-
// pub is_break: bool,
59-
// pub bad_value_break: bool,
60-
// }, ...
61-
// or more concisely
62-
// BreakOutsideOfLoop {
63-
// expr: InFile<AstPtr<ast::Expr>>,
64-
// is_break: bool,
65-
// bad_value_break: bool,
66-
// }, ...
67-
// ]
6854

6955
diagnostics![AnyDiagnostic<'db> ->
7056
AwaitOutsideOfAsync,

crates/ide-assists/src/handlers/add_braces.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ fn get_replacement_node(ctx: &AssistContext<'_>) -> Option<(ParentType, ast::Exp
8484
match parent {
8585
ast::LetStmt(it) => it.initializer()?,
8686
ast::LetExpr(it) => it.expr()?,
87+
ast::BinExpr(it) => it.rhs()?,
8788
ast::Static(it) => it.body()?,
8889
ast::Const(it) => it.body()?,
8990
_ => return None,
@@ -174,6 +175,70 @@ fn foo() {
174175
n + 100
175176
};
176177
}
178+
"#,
179+
);
180+
181+
check_assist(
182+
add_braces,
183+
r#"
184+
fn foo() {
185+
let x;
186+
x =$0 n + 100;
187+
}
188+
"#,
189+
r#"
190+
fn foo() {
191+
let x;
192+
x = {
193+
n + 100
194+
};
195+
}
196+
"#,
197+
);
198+
199+
check_assist(
200+
add_braces,
201+
r#"
202+
fn foo() {
203+
if let x =$0 n + 100 {}
204+
}
205+
"#,
206+
r#"
207+
fn foo() {
208+
if let x = {
209+
n + 100
210+
} {}
211+
}
212+
"#,
213+
);
214+
}
215+
216+
#[test]
217+
fn suggest_add_braces_for_const_initializer() {
218+
check_assist(
219+
add_braces,
220+
r#"
221+
const X: i32 =$0 1 + 2;
222+
"#,
223+
r#"
224+
const X: i32 = {
225+
1 + 2
226+
};
227+
"#,
228+
);
229+
}
230+
231+
#[test]
232+
fn suggest_add_braces_for_static_initializer() {
233+
check_assist(
234+
add_braces,
235+
r#"
236+
static X: i32 $0= 1 + 2;
237+
"#,
238+
r#"
239+
static X: i32 = {
240+
1 + 2
241+
};
177242
"#,
178243
);
179244
}

crates/ide-assists/src/handlers/add_label_to_loop.rs

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ use ide_db::{
33
};
44
use syntax::{
55
SyntaxToken, T,
6-
ast::{
7-
self, AstNode, HasLoopBody,
8-
make::{self, tokens},
9-
syntax_factory::SyntaxFactory,
10-
},
6+
ast::{self, AstNode, HasLoopBody, syntax_factory::SyntaxFactory},
117
syntax_editor::{Position, SyntaxEditor},
128
};
139

@@ -35,9 +31,9 @@ use crate::{AssistContext, AssistId, Assists};
3531
// }
3632
// ```
3733
pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
38-
let loop_kw = ctx.find_token_syntax_at_offset(T![loop])?;
39-
let loop_expr = loop_kw.parent().and_then(ast::LoopExpr::cast)?;
40-
if loop_expr.label().is_some() {
34+
let loop_expr = ctx.find_node_at_offset::<ast::AnyHasLoopBody>()?;
35+
let loop_kw = loop_token(&loop_expr)?;
36+
if loop_expr.label().is_some() || !loop_kw.text_range().contains_inclusive(ctx.offset()) {
4137
return None;
4238
}
4339

@@ -52,8 +48,8 @@ pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
5248
let label = make.lifetime("'l");
5349
let elements = vec![
5450
label.syntax().clone().into(),
55-
make::token(T![:]).into(),
56-
tokens::single_space().into(),
51+
make.token(T![:]).into(),
52+
make.whitespace(" ").into(),
5753
];
5854
editor.insert_all(Position::before(&loop_kw), elements);
5955

@@ -80,6 +76,14 @@ pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
8076
)
8177
}
8278

79+
fn loop_token(loop_expr: &ast::AnyHasLoopBody) -> Option<syntax::SyntaxToken> {
80+
loop_expr
81+
.syntax()
82+
.children_with_tokens()
83+
.filter_map(|it| it.into_token())
84+
.find(|it| matches!(it.kind(), T![for] | T![loop] | T![while]))
85+
}
86+
8387
fn insert_label_after_token(
8488
editor: &mut SyntaxEditor,
8589
make: &SyntaxFactory,
@@ -88,7 +92,7 @@ fn insert_label_after_token(
8892
builder: &mut SourceChangeBuilder,
8993
) {
9094
let label = make.lifetime("'l");
91-
let elements = vec![tokens::single_space().into(), label.syntax().clone().into()];
95+
let elements = vec![make.whitespace(" ").into(), label.syntax().clone().into()];
9296
editor.insert_all(Position::after(token), elements);
9397

9498
if let Some(cap) = ctx.config.snippet_cap {
@@ -123,6 +127,48 @@ fn main() {
123127
);
124128
}
125129

130+
#[test]
131+
fn add_label_to_while_expr() {
132+
check_assist(
133+
add_label_to_loop,
134+
r#"
135+
fn main() {
136+
while$0 true {
137+
break;
138+
continue;
139+
}
140+
}"#,
141+
r#"
142+
fn main() {
143+
${1:'l}: while true {
144+
break ${2:'l};
145+
continue ${0:'l};
146+
}
147+
}"#,
148+
);
149+
}
150+
151+
#[test]
152+
fn add_label_to_for_expr() {
153+
check_assist(
154+
add_label_to_loop,
155+
r#"
156+
fn main() {
157+
for$0 _ in 0..5 {
158+
break;
159+
continue;
160+
}
161+
}"#,
162+
r#"
163+
fn main() {
164+
${1:'l}: for _ in 0..5 {
165+
break ${2:'l};
166+
continue ${0:'l};
167+
}
168+
}"#,
169+
);
170+
}
171+
126172
#[test]
127173
fn add_label_to_outer_loop() {
128174
check_assist(
@@ -191,6 +237,31 @@ fn main() {
191237
break 'l;
192238
continue 'l;
193239
}
240+
}"#,
241+
);
242+
}
243+
244+
#[test]
245+
fn do_not_add_label_if_outside_keyword() {
246+
check_assist_not_applicable(
247+
add_label_to_loop,
248+
r#"
249+
fn main() {
250+
'l: loop {$0
251+
break 'l;
252+
continue 'l;
253+
}
254+
}"#,
255+
);
256+
257+
check_assist_not_applicable(
258+
add_label_to_loop,
259+
r#"
260+
fn main() {
261+
'l: while true {$0
262+
break 'l;
263+
continue 'l;
264+
}
194265
}"#,
195266
);
196267
}

0 commit comments

Comments
 (0)