Skip to content

Commit 6dec953

Browse files
committed
address review comments
1 parent 02b3ae6 commit 6dec953

File tree

6 files changed

+25
-31
lines changed

6 files changed

+25
-31
lines changed

src/libcore/ops/try.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
(or another type that implements `{Try}`)")]
2222
#[cfg_attr(not(stage0),
2323
rustc_on_unimplemented(
24-
on(all(direct, from_desugaring),
24+
on(all(direct, from_desugaring="?"),
2525
message="the `?` operator can only be used in a \
2626
function that returns `Result` \
27-
(or another type that implements `{Try}`)")))]
27+
(or another type that implements `{Try}`)",
28+
label="cannot use the `?` operator in a function that returns `{Self}`")))]
2829
pub trait Try {
2930
/// The type of this value when viewed as successful.
3031
#[unstable(feature = "try_trait", issue = "42327")]

src/librustc/traits/error_reporting.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
327327
.unwrap_or(trait_ref.def_id());
328328
let trait_ref = *trait_ref.skip_binder();
329329

330+
let s;
330331
let mut flags = vec![];
331332
let direct = match obligation.cause.code {
332333
ObligationCauseCode::BuiltinDerivedObligation(..) |
@@ -336,11 +337,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
336337
if direct {
337338
// this is a "direct", user-specified, rather than derived,
338339
// obligation.
339-
flags.push("direct");
340+
flags.push(("direct", None));
340341
}
341342

342-
if let Some(_) = obligation.cause.span.compiler_desugaring_kind() {
343-
flags.push("from_desugaring");
343+
if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {
344+
s = k.as_symbol().as_str();
345+
flags.push(("from_desugaring", None));
346+
flags.push(("from_desugaring", Some(&*s)));
344347
}
345348

346349
if let Ok(Some(command)) = OnUnimplementedDirective::of_item(

src/librustc/traits/on_unimplemented.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
171171
pub fn evaluate(&self,
172172
tcx: TyCtxt<'a, 'gcx, 'tcx>,
173173
trait_ref: ty::TraitRef<'tcx>,
174-
options: &[&str])
174+
options: &[(&str, Option<&str>)])
175175
-> OnUnimplementedNote
176176
{
177177
let mut message = None;
@@ -180,7 +180,11 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
180180
for command in self.subcommands.iter().chain(Some(self)).rev() {
181181
if let Some(ref condition) = command.condition {
182182
if !attr::eval_condition(condition, &tcx.sess.parse_sess, &mut |c| {
183-
options.iter().any(|o| c.check_name(o))
183+
options.contains(&(&c.name().as_str(),
184+
match c.value_str().map(|s| s.as_str()) {
185+
Some(ref s) => Some(s),
186+
None => None
187+
}))
184188
}) {
185189
debug!("evaluate: skipping {:?} due to condition", command);
186190
continue

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,7 @@ fn check_on_unimplemented<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12181218
item: &hir::Item) {
12191219
let item_def_id = tcx.hir.local_def_id(item.id);
12201220
// an error would be reported if this fails.
1221-
let _ = traits::OnUnimplementedDirective::of_item(
1222-
tcx, trait_def_id, item_def_id);
1221+
let _ = traits::OnUnimplementedDirective::of_item(tcx, trait_def_id, item_def_id);
12231222
}
12241223

12251224
fn report_forbidden_specialization<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

src/test/ui/suggestions/try-operator-on-main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(try_trait)]
12+
1113
use std::ops::Try;
1214

1315
fn main() {
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,22 @@
1-
error: use of unstable library feature 'try_trait' (see issue #42327)
2-
--> $DIR/try-operator-on-main.rs:11:5
3-
|
4-
11 | use std::ops::Try;
5-
| ^^^^^^^^^^^^^
6-
|
7-
= help: add #![feature(try_trait)] to the crate attributes to enable
8-
9-
error: use of unstable library feature 'try_trait' (see issue #42327)
10-
--> $DIR/try-operator-on-main.rs:19:25
11-
|
12-
19 | fn try_trait_generic<T: Try>() {}
13-
| ^^^
14-
|
15-
= help: add #![feature(try_trait)] to the crate attributes to enable
16-
171
error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)
18-
--> $DIR/try-operator-on-main.rs:14:5
2+
--> $DIR/try-operator-on-main.rs:16:5
193
|
20-
14 | std::fs::File::open("foo")?;
4+
16 | std::fs::File::open("foo")?;
215
| ---------------------------
226
| |
23-
| the trait `std::ops::Try` is not implemented for `()`
7+
| cannot use the `?` operator in a function that returns `()`
248
| in this macro invocation
259
|
10+
= help: the trait `std::ops::Try` is not implemented for `()`
2611
= note: required by `std::ops::Try::from_error`
2712

2813
error[E0277]: the trait bound `(): std::ops::Try` is not satisfied
29-
--> $DIR/try-operator-on-main.rs:16:5
14+
--> $DIR/try-operator-on-main.rs:18:5
3015
|
31-
16 | try_trait_generic::<()>();
16+
18 | try_trait_generic::<()>();
3217
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::ops::Try` is not implemented for `()`
3318
|
3419
= note: required by `try_trait_generic`
3520

36-
error: aborting due to 4 previous errors
21+
error: aborting due to 2 previous errors
3722

0 commit comments

Comments
 (0)