Skip to content

Commit fa496c9

Browse files
committed
Ignore obligations coming from desugared call spans
1 parent 02e3fb8 commit fa496c9

File tree

7 files changed

+195
-289
lines changed

7 files changed

+195
-289
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,21 +3273,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32733273
if let Err(
32743274
mut errors,
32753275
) = self.fulfillment_cx.borrow_mut().select_where_possible(self) {
3276-
for error in &mut errors {
3277-
if let ty::Predicate::Trait(predicate) = error.obligation.predicate {
3278-
let mut referenced_in = vec![];
3279-
for (i, ty) in &final_arg_types {
3280-
let ty = self.resolve_vars_if_possible(ty);
3281-
info!("final ty {} {:?}", i, ty);
3282-
for ty in ty.walk() {
3283-
info!("walk {:?}", ty);
3284-
if ty == predicate.skip_binder().self_ty() {
3285-
referenced_in.push(*i);
3276+
if !sp.desugaring_kind().is_some() {
3277+
// We *do not* do this for desugared call spans to keep good diagnostics
3278+
// involving try.
3279+
for error in &mut errors {
3280+
if let ty::Predicate::Trait(predicate) = error.obligation.predicate {
3281+
let mut referenced_in = vec![];
3282+
for (i, ty) in &final_arg_types {
3283+
let ty = self.resolve_vars_if_possible(ty);
3284+
for ty in ty.walk() {
3285+
if ty == predicate.skip_binder().self_ty() {
3286+
referenced_in.push(*i);
3287+
}
32863288
}
32873289
}
3288-
}
3289-
if referenced_in.len() == 1 {
3290-
error.obligation.cause.span = args[referenced_in[0]].span;
3290+
if referenced_in.len() == 1 {
3291+
error.obligation.cause.span = args[referenced_in[0]].span;
3292+
}
32913293
}
32923294
}
32933295
}

src/test/ui/async-await/await-keyword/incorrect-syntax-suggestions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ async fn foo2() -> Result<(), ()> {
1414
}
1515
async fn foo3() -> Result<(), ()> {
1616
let _ = await bar()?; //~ ERROR incorrect use of `await`
17-
//~^ ERROR the trait bound `impl std::future::Future: std::ops::Try` is not satisfied
18-
//~| ERROR the trait bound `impl std::future::Future: std::ops::Try` is not satisfied
17+
//~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
1918
Ok(())
2019
}
2120
async fn foo21() -> Result<(), ()> {

src/test/ui/async-await/await-keyword/incorrect-syntax-suggestions.stderr

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,117 +17,117 @@ LL | let _ = await bar()?;
1717
| ^^^^^^^^^^^^ help: `await` is a postfix operation: `bar()?.await`
1818

1919
error: incorrect use of `await`
20-
--> $DIR/incorrect-syntax-suggestions.rs:22:13
20+
--> $DIR/incorrect-syntax-suggestions.rs:21:13
2121
|
2222
LL | let _ = await { bar() };
2323
| ^^^^^^^^^^^^^^^ help: `await` is a postfix operation: `{ bar() }.await`
2424

2525
error: incorrect use of `await`
26-
--> $DIR/incorrect-syntax-suggestions.rs:26:13
26+
--> $DIR/incorrect-syntax-suggestions.rs:25:13
2727
|
2828
LL | let _ = await(bar());
2929
| ^^^^^^^^^^^^ help: `await` is a postfix operation: `(bar()).await`
3030

3131
error: incorrect use of `await`
32-
--> $DIR/incorrect-syntax-suggestions.rs:30:13
32+
--> $DIR/incorrect-syntax-suggestions.rs:29:13
3333
|
3434
LL | let _ = await { bar() }?;
3535
| ^^^^^^^^^^^^^^^ help: `await` is a postfix operation: `{ bar() }.await`
3636

3737
error: incorrect use of `await`
38-
--> $DIR/incorrect-syntax-suggestions.rs:34:14
38+
--> $DIR/incorrect-syntax-suggestions.rs:33:14
3939
|
4040
LL | let _ = (await bar())?;
4141
| ^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
4242

4343
error: incorrect use of `await`
44-
--> $DIR/incorrect-syntax-suggestions.rs:38:24
44+
--> $DIR/incorrect-syntax-suggestions.rs:37:24
4545
|
4646
LL | let _ = bar().await();
4747
| ^^ help: `await` is not a method call, remove the parentheses
4848

4949
error: incorrect use of `await`
50-
--> $DIR/incorrect-syntax-suggestions.rs:42:24
50+
--> $DIR/incorrect-syntax-suggestions.rs:41:24
5151
|
5252
LL | let _ = bar().await()?;
5353
| ^^ help: `await` is not a method call, remove the parentheses
5454

5555
error: incorrect use of `await`
56-
--> $DIR/incorrect-syntax-suggestions.rs:54:13
56+
--> $DIR/incorrect-syntax-suggestions.rs:53:13
5757
|
5858
LL | let _ = await bar();
5959
| ^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
6060

6161
error: incorrect use of `await`
62-
--> $DIR/incorrect-syntax-suggestions.rs:59:13
62+
--> $DIR/incorrect-syntax-suggestions.rs:58:13
6363
|
6464
LL | let _ = await? bar();
6565
| ^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await?`
6666

6767
error: incorrect use of `await`
68-
--> $DIR/incorrect-syntax-suggestions.rs:64:13
68+
--> $DIR/incorrect-syntax-suggestions.rs:63:13
6969
|
7070
LL | let _ = await bar()?;
7171
| ^^^^^^^^^^^^ help: `await` is a postfix operation: `bar()?.await`
7272

7373
error: incorrect use of `await`
74-
--> $DIR/incorrect-syntax-suggestions.rs:69:14
74+
--> $DIR/incorrect-syntax-suggestions.rs:68:14
7575
|
7676
LL | let _ = (await bar())?;
7777
| ^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
7878

7979
error: incorrect use of `await`
80-
--> $DIR/incorrect-syntax-suggestions.rs:74:24
80+
--> $DIR/incorrect-syntax-suggestions.rs:73:24
8181
|
8282
LL | let _ = bar().await();
8383
| ^^ help: `await` is not a method call, remove the parentheses
8484

8585
error: incorrect use of `await`
86-
--> $DIR/incorrect-syntax-suggestions.rs:79:24
86+
--> $DIR/incorrect-syntax-suggestions.rs:78:24
8787
|
8888
LL | let _ = bar().await()?;
8989
| ^^ help: `await` is not a method call, remove the parentheses
9090

9191
error: incorrect use of `await`
92-
--> $DIR/incorrect-syntax-suggestions.rs:107:13
92+
--> $DIR/incorrect-syntax-suggestions.rs:106:13
9393
|
9494
LL | let _ = await!(bar());
9595
| ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
9696

9797
error: incorrect use of `await`
98-
--> $DIR/incorrect-syntax-suggestions.rs:111:13
98+
--> $DIR/incorrect-syntax-suggestions.rs:110:13
9999
|
100100
LL | let _ = await!(bar())?;
101101
| ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
102102

103103
error: incorrect use of `await`
104-
--> $DIR/incorrect-syntax-suggestions.rs:116:17
104+
--> $DIR/incorrect-syntax-suggestions.rs:115:17
105105
|
106106
LL | let _ = await!(bar())?;
107107
| ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
108108

109109
error: incorrect use of `await`
110-
--> $DIR/incorrect-syntax-suggestions.rs:124:17
110+
--> $DIR/incorrect-syntax-suggestions.rs:123:17
111111
|
112112
LL | let _ = await!(bar())?;
113113
| ^^^^^^^^^^^^^ help: `await` is a postfix operation: `bar().await`
114114

115115
error: expected expression, found `=>`
116-
--> $DIR/incorrect-syntax-suggestions.rs:132:25
116+
--> $DIR/incorrect-syntax-suggestions.rs:131:25
117117
|
118118
LL | match await { await => () }
119119
| ----- ^^ expected expression
120120
| |
121121
| while parsing this incorrect await expression
122122

123123
error: incorrect use of `await`
124-
--> $DIR/incorrect-syntax-suggestions.rs:132:11
124+
--> $DIR/incorrect-syntax-suggestions.rs:131:11
125125
|
126126
LL | match await { await => () }
127127
| ^^^^^^^^^^^^^^^^^^^^^ help: `await` is a postfix operation: `{ await => () }.await`
128128

129129
error: expected one of `.`, `?`, `{`, or an operator, found `}`
130-
--> $DIR/incorrect-syntax-suggestions.rs:135:1
130+
--> $DIR/incorrect-syntax-suggestions.rs:134:1
131131
|
132132
LL | match await { await => () }
133133
| ----- - expected one of `.`, `?`, `{`, or an operator here
@@ -138,115 +138,110 @@ LL | }
138138
| ^ unexpected token
139139

140140
error[E0728]: `await` is only allowed inside `async` functions and blocks
141-
--> $DIR/incorrect-syntax-suggestions.rs:54:13
141+
--> $DIR/incorrect-syntax-suggestions.rs:53:13
142142
|
143143
LL | fn foo9() -> Result<(), ()> {
144144
| ---- this is not `async`
145145
LL | let _ = await bar();
146146
| ^^^^^^^^^^^ only allowed inside `async` functions and blocks
147147

148148
error[E0728]: `await` is only allowed inside `async` functions and blocks
149-
--> $DIR/incorrect-syntax-suggestions.rs:59:13
149+
--> $DIR/incorrect-syntax-suggestions.rs:58:13
150150
|
151151
LL | fn foo10() -> Result<(), ()> {
152152
| ----- this is not `async`
153153
LL | let _ = await? bar();
154154
| ^^^^^^^^^^^^ only allowed inside `async` functions and blocks
155155

156156
error[E0728]: `await` is only allowed inside `async` functions and blocks
157-
--> $DIR/incorrect-syntax-suggestions.rs:64:13
157+
--> $DIR/incorrect-syntax-suggestions.rs:63:13
158158
|
159159
LL | fn foo11() -> Result<(), ()> {
160160
| ----- this is not `async`
161161
LL | let _ = await bar()?;
162162
| ^^^^^^^^^^^^ only allowed inside `async` functions and blocks
163163

164164
error[E0728]: `await` is only allowed inside `async` functions and blocks
165-
--> $DIR/incorrect-syntax-suggestions.rs:69:14
165+
--> $DIR/incorrect-syntax-suggestions.rs:68:14
166166
|
167167
LL | fn foo12() -> Result<(), ()> {
168168
| ----- this is not `async`
169169
LL | let _ = (await bar())?;
170170
| ^^^^^^^^^^^ only allowed inside `async` functions and blocks
171171

172172
error[E0728]: `await` is only allowed inside `async` functions and blocks
173-
--> $DIR/incorrect-syntax-suggestions.rs:74:13
173+
--> $DIR/incorrect-syntax-suggestions.rs:73:13
174174
|
175175
LL | fn foo13() -> Result<(), ()> {
176176
| ----- this is not `async`
177177
LL | let _ = bar().await();
178178
| ^^^^^^^^^^^ only allowed inside `async` functions and blocks
179179

180180
error[E0728]: `await` is only allowed inside `async` functions and blocks
181-
--> $DIR/incorrect-syntax-suggestions.rs:79:13
181+
--> $DIR/incorrect-syntax-suggestions.rs:78:13
182182
|
183183
LL | fn foo14() -> Result<(), ()> {
184184
| ----- this is not `async`
185185
LL | let _ = bar().await()?;
186186
| ^^^^^^^^^^^ only allowed inside `async` functions and blocks
187187

188188
error[E0728]: `await` is only allowed inside `async` functions and blocks
189-
--> $DIR/incorrect-syntax-suggestions.rs:84:13
189+
--> $DIR/incorrect-syntax-suggestions.rs:83:13
190190
|
191191
LL | fn foo15() -> Result<(), ()> {
192192
| ----- this is not `async`
193193
LL | let _ = bar().await;
194194
| ^^^^^^^^^^^ only allowed inside `async` functions and blocks
195195

196196
error[E0728]: `await` is only allowed inside `async` functions and blocks
197-
--> $DIR/incorrect-syntax-suggestions.rs:88:13
197+
--> $DIR/incorrect-syntax-suggestions.rs:87:13
198198
|
199199
LL | fn foo16() -> Result<(), ()> {
200200
| ----- this is not `async`
201201
LL | let _ = bar().await?;
202202
| ^^^^^^^^^^^ only allowed inside `async` functions and blocks
203203

204204
error[E0728]: `await` is only allowed inside `async` functions and blocks
205-
--> $DIR/incorrect-syntax-suggestions.rs:93:17
205+
--> $DIR/incorrect-syntax-suggestions.rs:92:17
206206
|
207207
LL | fn foo() -> Result<(), ()> {
208208
| --- this is not `async`
209209
LL | let _ = bar().await?;
210210
| ^^^^^^^^^^^ only allowed inside `async` functions and blocks
211211

212212
error[E0728]: `await` is only allowed inside `async` functions and blocks
213-
--> $DIR/incorrect-syntax-suggestions.rs:100:17
213+
--> $DIR/incorrect-syntax-suggestions.rs:99:17
214214
|
215215
LL | let foo = || {
216216
| -- this is not `async`
217217
LL | let _ = bar().await?;
218218
| ^^^^^^^^^^^ only allowed inside `async` functions and blocks
219219

220220
error[E0728]: `await` is only allowed inside `async` functions and blocks
221-
--> $DIR/incorrect-syntax-suggestions.rs:116:17
221+
--> $DIR/incorrect-syntax-suggestions.rs:115:17
222222
|
223223
LL | fn foo() -> Result<(), ()> {
224224
| --- this is not `async`
225225
LL | let _ = await!(bar())?;
226226
| ^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
227227

228228
error[E0728]: `await` is only allowed inside `async` functions and blocks
229-
--> $DIR/incorrect-syntax-suggestions.rs:124:17
229+
--> $DIR/incorrect-syntax-suggestions.rs:123:17
230230
|
231231
LL | let foo = || {
232232
| -- this is not `async`
233233
LL | let _ = await!(bar())?;
234234
| ^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
235235

236-
error[E0277]: the trait bound `impl std::future::Future: std::ops::Try` is not satisfied
236+
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
237237
--> $DIR/incorrect-syntax-suggestions.rs:16:19
238238
|
239239
LL | let _ = await bar()?;
240-
| ^^^^^ the trait `std::ops::Try` is not implemented for `impl std::future::Future`
240+
| ^^^^^^ the `?` operator cannot be applied to type `impl std::future::Future`
241241
|
242+
= help: the trait `std::ops::Try` is not implemented for `impl std::future::Future`
242243
= note: required by `std::ops::Try::into_result`
243244

244-
error[E0277]: the trait bound `impl std::future::Future: std::ops::Try` is not satisfied
245-
--> $DIR/incorrect-syntax-suggestions.rs:16:19
246-
|
247-
LL | let _ = await bar()?;
248-
| ^^^^^^ the trait `std::ops::Try` is not implemented for `impl std::future::Future`
249-
250-
error: aborting due to 36 previous errors
245+
error: aborting due to 35 previous errors
251246

252247
For more information about this error, try `rustc --explain E0277`.

src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ fn nested_within_if_expr() {
4040

4141
fn _check_try_binds_tighter() -> Result<(), ()> {
4242
if let 0 = 0? {}
43-
//~^ ERROR the trait bound `{integer}: std::ops::Try` is not satisfied
44-
//~| ERROR the trait bound `{integer}: std::ops::Try` is not satisfied
43+
//~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
4544
Ok(())
4645
}
4746
if (let 0 = 0)? {} //~ ERROR `let` expressions are not supported here
48-
//~^ ERROR the trait bound `bool: std::ops::Try` is not satisfied
49-
//~| ERROR the trait bound `bool: std::ops::Try` is not satisfied
50-
//~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option`
47+
//~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
48+
//~| ERROR the `?` operator can only be used in a function that returns `Result`
5149

5250
if true || let 0 = 0 {} //~ ERROR `let` expressions are not supported here
5351
if (true || let 0 = 0) {} //~ ERROR `let` expressions are not supported here
@@ -106,14 +104,12 @@ fn nested_within_while_expr() {
106104

107105
fn _check_try_binds_tighter() -> Result<(), ()> {
108106
while let 0 = 0? {}
109-
//~^ ERROR the trait bound `{integer}: std::ops::Try` is not satisfied
110-
//~| ERROR the trait bound `{integer}: std::ops::Try` is not satisfied
107+
//~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
111108
Ok(())
112109
}
113110
while (let 0 = 0)? {} //~ ERROR `let` expressions are not supported here
114-
//~^ ERROR the trait bound `bool: std::ops::Try` is not satisfied
115-
//~| ERROR the trait bound `bool: std::ops::Try` is not satisfied
116-
//~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option`
111+
//~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
112+
//~| ERROR the `?` operator can only be used in a function that returns `Result`
117113

118114
while true || let 0 = 0 {} //~ ERROR `let` expressions are not supported here
119115
while (true || let 0 = 0) {} //~ ERROR `let` expressions are not supported here
@@ -181,14 +177,12 @@ fn outside_if_and_while_expr() {
181177

182178
fn _check_try_binds_tighter() -> Result<(), ()> {
183179
let 0 = 0?;
184-
//~^ ERROR the trait bound `{integer}: std::ops::Try` is not satisfied
185-
//~| ERROR the trait bound `{integer}: std::ops::Try` is not satisfied
180+
//~^ ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
186181
Ok(())
187182
}
188183
(let 0 = 0)?; //~ ERROR `let` expressions are not supported here
189-
//~^ ERROR the trait bound `bool: std::ops::Try` is not satisfied
190-
//~| ERROR the trait bound `bool: std::ops::Try` is not satisfied
191-
//~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option`
184+
//~^ ERROR the `?` operator can only be used in a function that returns `Result`
185+
//~| ERROR the `?` operator can only be applied to values that implement `std::ops::Try`
192186

193187
true || let 0 = 0; //~ ERROR `let` expressions are not supported here
194188
(true || let 0 = 0); //~ ERROR `let` expressions are not supported here

0 commit comments

Comments
 (0)