Auto merge of #101296 - compiler-errors:head-span-for-enclosing-scope, r=oli-obk
Use head span for `rustc_on_unimplemented`'s `enclosing_scope` attr This may make #101281 slightly easier to understand
This commit is contained in:
commit
a2cdcb3fea
14 changed files with 287 additions and 288 deletions
|
@ -662,7 +662,6 @@ symbols! {
|
||||||
emit_struct,
|
emit_struct,
|
||||||
emit_struct_field,
|
emit_struct_field,
|
||||||
enable,
|
enable,
|
||||||
enclosing_scope,
|
|
||||||
encode,
|
encode,
|
||||||
end,
|
end,
|
||||||
env,
|
env,
|
||||||
|
@ -1065,6 +1064,7 @@ symbols! {
|
||||||
panic_unwind,
|
panic_unwind,
|
||||||
panicking,
|
panicking,
|
||||||
param_attrs,
|
param_attrs,
|
||||||
|
parent_label,
|
||||||
partial_cmp,
|
partial_cmp,
|
||||||
partial_ord,
|
partial_ord,
|
||||||
passes,
|
passes,
|
||||||
|
|
|
@ -349,7 +349,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
message,
|
message,
|
||||||
label,
|
label,
|
||||||
note,
|
note,
|
||||||
enclosing_scope,
|
parent_label,
|
||||||
append_const_msg,
|
append_const_msg,
|
||||||
} = self.on_unimplemented_note(trait_ref, &obligation);
|
} = self.on_unimplemented_note(trait_ref, &obligation);
|
||||||
let have_alt_message = message.is_some() || label.is_some();
|
let have_alt_message = message.is_some() || label.is_some();
|
||||||
|
@ -530,7 +530,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
// If it has a custom `#[rustc_on_unimplemented]` note, let's display it
|
// If it has a custom `#[rustc_on_unimplemented]` note, let's display it
|
||||||
err.note(s.as_str());
|
err.note(s.as_str());
|
||||||
}
|
}
|
||||||
if let Some(ref s) = enclosing_scope {
|
if let Some(ref s) = parent_label {
|
||||||
let body = tcx
|
let body = tcx
|
||||||
.hir()
|
.hir()
|
||||||
.opt_local_def_id(obligation.cause.body_id)
|
.opt_local_def_id(obligation.cause.body_id)
|
||||||
|
@ -539,11 +539,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
hir_id: obligation.cause.body_id,
|
hir_id: obligation.cause.body_id,
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
err.span_label(tcx.def_span(body), s);
|
||||||
let enclosing_scope_span =
|
|
||||||
tcx.hir().span_with_body(tcx.hir().local_def_id_to_hir_id(body));
|
|
||||||
|
|
||||||
err.span_label(enclosing_scope_span, s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.suggest_floating_point_literal(&obligation, &mut err, &trait_ref);
|
self.suggest_floating_point_literal(&obligation, &mut err, &trait_ref);
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub struct OnUnimplementedDirective {
|
||||||
pub message: Option<OnUnimplementedFormatString>,
|
pub message: Option<OnUnimplementedFormatString>,
|
||||||
pub label: Option<OnUnimplementedFormatString>,
|
pub label: Option<OnUnimplementedFormatString>,
|
||||||
pub note: Option<OnUnimplementedFormatString>,
|
pub note: Option<OnUnimplementedFormatString>,
|
||||||
pub enclosing_scope: Option<OnUnimplementedFormatString>,
|
pub parent_label: Option<OnUnimplementedFormatString>,
|
||||||
pub append_const_msg: Option<Option<Symbol>>,
|
pub append_const_msg: Option<Option<Symbol>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ pub struct OnUnimplementedNote {
|
||||||
pub message: Option<String>,
|
pub message: Option<String>,
|
||||||
pub label: Option<String>,
|
pub label: Option<String>,
|
||||||
pub note: Option<String>,
|
pub note: Option<String>,
|
||||||
pub enclosing_scope: Option<String>,
|
pub parent_label: Option<String>,
|
||||||
/// Append a message for `~const Trait` errors. `None` means not requested and
|
/// Append a message for `~const Trait` errors. `None` means not requested and
|
||||||
/// should fallback to a generic message, `Some(None)` suggests using the default
|
/// should fallback to a generic message, `Some(None)` suggests using the default
|
||||||
/// appended message, `Some(Some(s))` suggests use the `s` message instead of the
|
/// appended message, `Some(Some(s))` suggests use the `s` message instead of the
|
||||||
|
@ -74,7 +74,7 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
let mut message = None;
|
let mut message = None;
|
||||||
let mut label = None;
|
let mut label = None;
|
||||||
let mut note = None;
|
let mut note = None;
|
||||||
let mut enclosing_scope = None;
|
let mut parent_label = None;
|
||||||
let mut subcommands = vec![];
|
let mut subcommands = vec![];
|
||||||
let mut append_const_msg = None;
|
let mut append_const_msg = None;
|
||||||
|
|
||||||
|
@ -94,9 +94,9 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
note = parse_value(note_)?;
|
note = parse_value(note_)?;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if item.has_name(sym::enclosing_scope) && enclosing_scope.is_none() {
|
} else if item.has_name(sym::parent_label) && parent_label.is_none() {
|
||||||
if let Some(enclosing_scope_) = item.value_str() {
|
if let Some(parent_label_) = item.value_str() {
|
||||||
enclosing_scope = parse_value(enclosing_scope_)?;
|
parent_label = parse_value(parent_label_)?;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if item.has_name(sym::on)
|
} else if item.has_name(sym::on)
|
||||||
|
@ -135,7 +135,7 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
message,
|
message,
|
||||||
label,
|
label,
|
||||||
note,
|
note,
|
||||||
enclosing_scope,
|
parent_label,
|
||||||
append_const_msg,
|
append_const_msg,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
attr.span,
|
attr.span,
|
||||||
)?),
|
)?),
|
||||||
note: None,
|
note: None,
|
||||||
enclosing_scope: None,
|
parent_label: None,
|
||||||
append_const_msg: None,
|
append_const_msg: None,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
|
@ -181,7 +181,7 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
let mut message = None;
|
let mut message = None;
|
||||||
let mut label = None;
|
let mut label = None;
|
||||||
let mut note = None;
|
let mut note = None;
|
||||||
let mut enclosing_scope = None;
|
let mut parent_label = None;
|
||||||
let mut append_const_msg = None;
|
let mut append_const_msg = None;
|
||||||
info!("evaluate({:?}, trait_ref={:?}, options={:?})", self, trait_ref, options);
|
info!("evaluate({:?}, trait_ref={:?}, options={:?})", self, trait_ref, options);
|
||||||
|
|
||||||
|
@ -217,8 +217,8 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
note = Some(note_.clone());
|
note = Some(note_.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref enclosing_scope_) = command.enclosing_scope {
|
if let Some(ref parent_label_) = command.parent_label {
|
||||||
enclosing_scope = Some(enclosing_scope_.clone());
|
parent_label = Some(parent_label_.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
append_const_msg = command.append_const_msg;
|
append_const_msg = command.append_const_msg;
|
||||||
|
@ -228,7 +228,7 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
label: label.map(|l| l.format(tcx, trait_ref, &options_map)),
|
label: label.map(|l| l.format(tcx, trait_ref, &options_map)),
|
||||||
message: message.map(|m| m.format(tcx, trait_ref, &options_map)),
|
message: message.map(|m| m.format(tcx, trait_ref, &options_map)),
|
||||||
note: note.map(|n| n.format(tcx, trait_ref, &options_map)),
|
note: note.map(|n| n.format(tcx, trait_ref, &options_map)),
|
||||||
enclosing_scope: enclosing_scope.map(|e_s| e_s.format(tcx, trait_ref, &options_map)),
|
parent_label: parent_label.map(|e_s| e_s.format(tcx, trait_ref, &options_map)),
|
||||||
append_const_msg,
|
append_const_msg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,87 @@ pub trait Try: FromResidual {
|
||||||
/// Every `Try` type needs to be recreatable from its own associated
|
/// Every `Try` type needs to be recreatable from its own associated
|
||||||
/// `Residual` type, but can also have additional `FromResidual` implementations
|
/// `Residual` type, but can also have additional `FromResidual` implementations
|
||||||
/// to support interconversion with other `Try` types.
|
/// to support interconversion with other `Try` types.
|
||||||
#[rustc_on_unimplemented(
|
#[cfg_attr(not(bootstrap), rustc_on_unimplemented(
|
||||||
|
on(
|
||||||
|
all(
|
||||||
|
from_desugaring = "QuestionMark",
|
||||||
|
_Self = "std::result::Result<T, E>",
|
||||||
|
R = "std::option::Option<std::convert::Infallible>"
|
||||||
|
),
|
||||||
|
message = "the `?` operator can only be used on `Result`s, not `Option`s, \
|
||||||
|
in {ItemContext} that returns `Result`",
|
||||||
|
label = "use `.ok_or(...)?` to provide an error compatible with `{Self}`",
|
||||||
|
parent_label = "this function returns a `Result`"
|
||||||
|
),
|
||||||
|
on(
|
||||||
|
all(
|
||||||
|
from_desugaring = "QuestionMark",
|
||||||
|
_Self = "std::result::Result<T, E>",
|
||||||
|
),
|
||||||
|
// There's a special error message in the trait selection code for
|
||||||
|
// `From` in `?`, so this is not shown for result-in-result errors,
|
||||||
|
// and thus it can be phrased more strongly than `ControlFlow`'s.
|
||||||
|
message = "the `?` operator can only be used on `Result`s \
|
||||||
|
in {ItemContext} that returns `Result`",
|
||||||
|
label = "this `?` produces `{R}`, which is incompatible with `{Self}`",
|
||||||
|
parent_label = "this function returns a `Result`"
|
||||||
|
),
|
||||||
|
on(
|
||||||
|
all(
|
||||||
|
from_desugaring = "QuestionMark",
|
||||||
|
_Self = "std::option::Option<T>",
|
||||||
|
R = "std::result::Result<T, E>",
|
||||||
|
),
|
||||||
|
message = "the `?` operator can only be used on `Option`s, not `Result`s, \
|
||||||
|
in {ItemContext} that returns `Option`",
|
||||||
|
label = "use `.ok()?` if you want to discard the `{R}` error information",
|
||||||
|
parent_label = "this function returns an `Option`"
|
||||||
|
),
|
||||||
|
on(
|
||||||
|
all(
|
||||||
|
from_desugaring = "QuestionMark",
|
||||||
|
_Self = "std::option::Option<T>",
|
||||||
|
),
|
||||||
|
// `Option`-in-`Option` always works, as there's only one possible
|
||||||
|
// residual, so this can also be phrased strongly.
|
||||||
|
message = "the `?` operator can only be used on `Option`s \
|
||||||
|
in {ItemContext} that returns `Option`",
|
||||||
|
label = "this `?` produces `{R}`, which is incompatible with `{Self}`",
|
||||||
|
parent_label = "this function returns an `Option`"
|
||||||
|
),
|
||||||
|
on(
|
||||||
|
all(
|
||||||
|
from_desugaring = "QuestionMark",
|
||||||
|
_Self = "std::ops::ControlFlow<B, C>",
|
||||||
|
R = "std::ops::ControlFlow<B, C>",
|
||||||
|
),
|
||||||
|
message = "the `?` operator in {ItemContext} that returns `ControlFlow<B, _>` \
|
||||||
|
can only be used on other `ControlFlow<B, _>`s (with the same Break type)",
|
||||||
|
label = "this `?` produces `{R}`, which is incompatible with `{Self}`",
|
||||||
|
parent_label = "this function returns a `ControlFlow`",
|
||||||
|
note = "unlike `Result`, there's no `From`-conversion performed for `ControlFlow`"
|
||||||
|
),
|
||||||
|
on(
|
||||||
|
all(
|
||||||
|
from_desugaring = "QuestionMark",
|
||||||
|
_Self = "std::ops::ControlFlow<B, C>",
|
||||||
|
// `R` is not a `ControlFlow`, as that case was matched previously
|
||||||
|
),
|
||||||
|
message = "the `?` operator can only be used on `ControlFlow`s \
|
||||||
|
in {ItemContext} that returns `ControlFlow`",
|
||||||
|
label = "this `?` produces `{R}`, which is incompatible with `{Self}`",
|
||||||
|
parent_label = "this function returns a `ControlFlow`",
|
||||||
|
),
|
||||||
|
on(
|
||||||
|
all(from_desugaring = "QuestionMark"),
|
||||||
|
message = "the `?` operator can only be used in {ItemContext} \
|
||||||
|
that returns `Result` or `Option` \
|
||||||
|
(or another type that implements `{FromResidual}`)",
|
||||||
|
label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`",
|
||||||
|
parent_label = "this function should return `Result` or `Option` to accept `?`"
|
||||||
|
),
|
||||||
|
))]
|
||||||
|
#[cfg_attr(bootstrap, rustc_on_unimplemented(
|
||||||
on(
|
on(
|
||||||
all(
|
all(
|
||||||
from_desugaring = "QuestionMark",
|
from_desugaring = "QuestionMark",
|
||||||
|
@ -301,7 +381,7 @@ pub trait Try: FromResidual {
|
||||||
label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`",
|
label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`",
|
||||||
enclosing_scope = "this function should return `Result` or `Option` to accept `?`"
|
enclosing_scope = "this function should return `Result` or `Option` to accept `?`"
|
||||||
),
|
),
|
||||||
)]
|
))]
|
||||||
#[rustc_diagnostic_item = "FromResidual"]
|
#[rustc_diagnostic_item = "FromResidual"]
|
||||||
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
||||||
pub trait FromResidual<R = <Self as Try>::Residual> {
|
pub trait FromResidual<R = <Self as Try>::Residual> {
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
// Test scope annotations from `enclosing_scope` parameter
|
|
||||||
|
|
||||||
#![feature(rustc_attrs)]
|
|
||||||
|
|
||||||
#[rustc_on_unimplemented(enclosing_scope="in this scope")]
|
|
||||||
trait Trait{}
|
|
||||||
|
|
||||||
struct Foo;
|
|
||||||
|
|
||||||
fn f<T: Trait>(x: T) {}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let x = || {
|
|
||||||
f(Foo{}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
|
|
||||||
let y = || {
|
|
||||||
f(Foo{}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
{
|
|
||||||
{
|
|
||||||
f(Foo{}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
f(Foo{}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
|
|
||||||
}
|
|
|
@ -1,86 +0,0 @@
|
||||||
error[E0277]: the trait bound `Foo: Trait` is not satisfied
|
|
||||||
--> $DIR/enclosing-scope.rs:14:11
|
|
||||||
|
|
|
||||||
LL | let x = || {
|
|
||||||
| _____________-
|
|
||||||
LL | | f(Foo{});
|
|
||||||
| | - ^^^^^ the trait `Trait` is not implemented for `Foo`
|
|
||||||
| | |
|
|
||||||
| | required by a bound introduced by this call
|
|
||||||
LL | | let y = || {
|
|
||||||
LL | | f(Foo{});
|
|
||||||
LL | | };
|
|
||||||
LL | | };
|
|
||||||
| |_____- in this scope
|
|
||||||
|
|
|
||||||
note: required by a bound in `f`
|
|
||||||
--> $DIR/enclosing-scope.rs:10:9
|
|
||||||
|
|
|
||||||
LL | fn f<T: Trait>(x: T) {}
|
|
||||||
| ^^^^^ required by this bound in `f`
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `Foo: Trait` is not satisfied
|
|
||||||
--> $DIR/enclosing-scope.rs:16:15
|
|
||||||
|
|
|
||||||
LL | let y = || {
|
|
||||||
| _________________-
|
|
||||||
LL | | f(Foo{});
|
|
||||||
| | - ^^^^^ the trait `Trait` is not implemented for `Foo`
|
|
||||||
| | |
|
|
||||||
| | required by a bound introduced by this call
|
|
||||||
LL | | };
|
|
||||||
| |_________- in this scope
|
|
||||||
|
|
|
||||||
note: required by a bound in `f`
|
|
||||||
--> $DIR/enclosing-scope.rs:10:9
|
|
||||||
|
|
|
||||||
LL | fn f<T: Trait>(x: T) {}
|
|
||||||
| ^^^^^ required by this bound in `f`
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `Foo: Trait` is not satisfied
|
|
||||||
--> $DIR/enclosing-scope.rs:22:15
|
|
||||||
|
|
|
||||||
LL | / fn main() {
|
|
||||||
LL | | let x = || {
|
|
||||||
LL | | f(Foo{});
|
|
||||||
LL | | let y = || {
|
|
||||||
... |
|
|
||||||
LL | | f(Foo{});
|
|
||||||
| | - ^^^^^ the trait `Trait` is not implemented for `Foo`
|
|
||||||
| | |
|
|
||||||
| | required by a bound introduced by this call
|
|
||||||
... |
|
|
||||||
LL | | f(Foo{});
|
|
||||||
LL | | }
|
|
||||||
| |_- in this scope
|
|
||||||
|
|
|
||||||
note: required by a bound in `f`
|
|
||||||
--> $DIR/enclosing-scope.rs:10:9
|
|
||||||
|
|
|
||||||
LL | fn f<T: Trait>(x: T) {}
|
|
||||||
| ^^^^^ required by this bound in `f`
|
|
||||||
|
|
||||||
error[E0277]: the trait bound `Foo: Trait` is not satisfied
|
|
||||||
--> $DIR/enclosing-scope.rs:26:7
|
|
||||||
|
|
|
||||||
LL | / fn main() {
|
|
||||||
LL | | let x = || {
|
|
||||||
LL | | f(Foo{});
|
|
||||||
LL | | let y = || {
|
|
||||||
... |
|
|
||||||
LL | | f(Foo{});
|
|
||||||
| | - ^^^^^ the trait `Trait` is not implemented for `Foo`
|
|
||||||
| | |
|
|
||||||
| | required by a bound introduced by this call
|
|
||||||
LL | | }
|
|
||||||
| |_- in this scope
|
|
||||||
|
|
|
||||||
note: required by a bound in `f`
|
|
||||||
--> $DIR/enclosing-scope.rs:10:9
|
|
||||||
|
|
|
||||||
LL | fn f<T: Trait>(x: T) {}
|
|
||||||
| ^^^^^ required by this bound in `f`
|
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0277`.
|
|
27
src/test/ui/on-unimplemented/parent-label.rs
Normal file
27
src/test/ui/on-unimplemented/parent-label.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// Test scope annotations from `parent_label` parameter
|
||||||
|
|
||||||
|
#![feature(rustc_attrs)]
|
||||||
|
|
||||||
|
#[rustc_on_unimplemented(parent_label = "in this scope")]
|
||||||
|
trait Trait {}
|
||||||
|
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
fn f<T: Trait>(x: T) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = || {
|
||||||
|
f(Foo {}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
|
||||||
|
let y = || {
|
||||||
|
f(Foo {}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
{
|
||||||
|
f(Foo {}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f(Foo {}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
|
||||||
|
}
|
69
src/test/ui/on-unimplemented/parent-label.stderr
Normal file
69
src/test/ui/on-unimplemented/parent-label.stderr
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
error[E0277]: the trait bound `Foo: Trait` is not satisfied
|
||||||
|
--> $DIR/parent-label.rs:14:11
|
||||||
|
|
|
||||||
|
LL | let x = || {
|
||||||
|
| -- in this scope
|
||||||
|
LL | f(Foo {});
|
||||||
|
| - ^^^^^^ the trait `Trait` is not implemented for `Foo`
|
||||||
|
| |
|
||||||
|
| required by a bound introduced by this call
|
||||||
|
|
|
||||||
|
note: required by a bound in `f`
|
||||||
|
--> $DIR/parent-label.rs:10:9
|
||||||
|
|
|
||||||
|
LL | fn f<T: Trait>(x: T) {}
|
||||||
|
| ^^^^^ required by this bound in `f`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `Foo: Trait` is not satisfied
|
||||||
|
--> $DIR/parent-label.rs:16:15
|
||||||
|
|
|
||||||
|
LL | let y = || {
|
||||||
|
| -- in this scope
|
||||||
|
LL | f(Foo {});
|
||||||
|
| - ^^^^^^ the trait `Trait` is not implemented for `Foo`
|
||||||
|
| |
|
||||||
|
| required by a bound introduced by this call
|
||||||
|
|
|
||||||
|
note: required by a bound in `f`
|
||||||
|
--> $DIR/parent-label.rs:10:9
|
||||||
|
|
|
||||||
|
LL | fn f<T: Trait>(x: T) {}
|
||||||
|
| ^^^^^ required by this bound in `f`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `Foo: Trait` is not satisfied
|
||||||
|
--> $DIR/parent-label.rs:22:15
|
||||||
|
|
|
||||||
|
LL | fn main() {
|
||||||
|
| --------- in this scope
|
||||||
|
...
|
||||||
|
LL | f(Foo {});
|
||||||
|
| - ^^^^^^ the trait `Trait` is not implemented for `Foo`
|
||||||
|
| |
|
||||||
|
| required by a bound introduced by this call
|
||||||
|
|
|
||||||
|
note: required by a bound in `f`
|
||||||
|
--> $DIR/parent-label.rs:10:9
|
||||||
|
|
|
||||||
|
LL | fn f<T: Trait>(x: T) {}
|
||||||
|
| ^^^^^ required by this bound in `f`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `Foo: Trait` is not satisfied
|
||||||
|
--> $DIR/parent-label.rs:26:7
|
||||||
|
|
|
||||||
|
LL | fn main() {
|
||||||
|
| --------- in this scope
|
||||||
|
...
|
||||||
|
LL | f(Foo {});
|
||||||
|
| - ^^^^^^ the trait `Trait` is not implemented for `Foo`
|
||||||
|
| |
|
||||||
|
| required by a bound introduced by this call
|
||||||
|
|
|
||||||
|
note: required by a bound in `f`
|
||||||
|
--> $DIR/parent-label.rs:10:9
|
||||||
|
|
|
||||||
|
LL | fn f<T: Trait>(x: T) {}
|
||||||
|
| ^^^^^ required by this bound in `f`
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
|
@ -1493,17 +1493,11 @@ LL | if (let 0 = 0)? {}
|
||||||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
||||||
--> $DIR/disallowed-positions.rs:132:19
|
--> $DIR/disallowed-positions.rs:132:19
|
||||||
|
|
|
|
||||||
LL | / fn nested_within_if_expr() {
|
LL | fn nested_within_if_expr() {
|
||||||
LL | | if &let 0 = 0 {}
|
| -------------------------- this function should return `Result` or `Option` to accept `?`
|
||||||
LL | |
|
...
|
||||||
LL | |
|
LL | if (let 0 = 0)? {}
|
||||||
... |
|
| ^ cannot use the `?` operator in a function that returns `()`
|
||||||
LL | | if (let 0 = 0)? {}
|
|
||||||
| | ^ cannot use the `?` operator in a function that returns `()`
|
|
||||||
... |
|
|
||||||
LL | |
|
|
||||||
LL | | }
|
|
||||||
| |_- this function should return `Result` or `Option` to accept `?`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<_>` is not implemented for `()`
|
= help: the trait `FromResidual<_>` is not implemented for `()`
|
||||||
|
|
||||||
|
@ -1693,17 +1687,11 @@ LL | while (let 0 = 0)? {}
|
||||||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
||||||
--> $DIR/disallowed-positions.rs:224:22
|
--> $DIR/disallowed-positions.rs:224:22
|
||||||
|
|
|
|
||||||
LL | / fn nested_within_while_expr() {
|
LL | fn nested_within_while_expr() {
|
||||||
LL | | while &let 0 = 0 {}
|
| ----------------------------- this function should return `Result` or `Option` to accept `?`
|
||||||
LL | |
|
...
|
||||||
LL | |
|
LL | while (let 0 = 0)? {}
|
||||||
... |
|
| ^ cannot use the `?` operator in a function that returns `()`
|
||||||
LL | | while (let 0 = 0)? {}
|
|
||||||
| | ^ cannot use the `?` operator in a function that returns `()`
|
|
||||||
... |
|
|
||||||
LL | |
|
|
||||||
LL | | }
|
|
||||||
| |_- this function should return `Result` or `Option` to accept `?`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<_>` is not implemented for `()`
|
= help: the trait `FromResidual<_>` is not implemented for `()`
|
||||||
|
|
||||||
|
@ -1881,17 +1869,11 @@ LL | (let 0 = 0)?;
|
||||||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
||||||
--> $DIR/disallowed-positions.rs:325:16
|
--> $DIR/disallowed-positions.rs:325:16
|
||||||
|
|
|
|
||||||
LL | / fn outside_if_and_while_expr() {
|
LL | fn outside_if_and_while_expr() {
|
||||||
LL | | &let 0 = 0;
|
| ------------------------------ this function should return `Result` or `Option` to accept `?`
|
||||||
LL | |
|
...
|
||||||
LL | |
|
LL | (let 0 = 0)?;
|
||||||
... |
|
| ^ cannot use the `?` operator in a function that returns `()`
|
||||||
LL | | (let 0 = 0)?;
|
|
||||||
| | ^ cannot use the `?` operator in a function that returns `()`
|
|
||||||
... |
|
|
||||||
LL | |
|
|
||||||
LL | | }
|
|
||||||
| |_- this function should return `Result` or `Option` to accept `?`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<_>` is not implemented for `()`
|
= help: the trait `FromResidual<_>` is not implemented for `()`
|
||||||
|
|
||||||
|
|
|
@ -22,13 +22,10 @@ LL | Ok(Err(123_i32)?)
|
||||||
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
|
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
|
||||||
--> $DIR/bad-interconversion.rs:11:12
|
--> $DIR/bad-interconversion.rs:11:12
|
||||||
|
|
|
|
||||||
LL | / fn option_to_result() -> Result<u64, String> {
|
LL | fn option_to_result() -> Result<u64, String> {
|
||||||
LL | | Some(3)?;
|
| -------------------------------------------- this function returns a `Result`
|
||||||
| | ^ use `.ok_or(...)?` to provide an error compatible with `Result<u64, String>`
|
LL | Some(3)?;
|
||||||
LL | |
|
| ^ use `.ok_or(...)?` to provide an error compatible with `Result<u64, String>`
|
||||||
LL | | Ok(10)
|
|
||||||
LL | | }
|
|
||||||
| |_- this function returns a `Result`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u64, String>`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u64, String>`
|
||||||
= help: the following other types implement trait `FromResidual<R>`:
|
= help: the following other types implement trait `FromResidual<R>`:
|
||||||
|
@ -38,12 +35,10 @@ LL | | }
|
||||||
error[E0277]: the `?` operator can only be used on `Result`s in a function that returns `Result`
|
error[E0277]: the `?` operator can only be used on `Result`s in a function that returns `Result`
|
||||||
--> $DIR/bad-interconversion.rs:17:31
|
--> $DIR/bad-interconversion.rs:17:31
|
||||||
|
|
|
|
||||||
LL | / fn control_flow_to_result() -> Result<u64, String> {
|
LL | fn control_flow_to_result() -> Result<u64, String> {
|
||||||
LL | | Ok(ControlFlow::Break(123)?)
|
| -------------------------------------------------- this function returns a `Result`
|
||||||
| | ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Result<u64, String>`
|
LL | Ok(ControlFlow::Break(123)?)
|
||||||
LL | |
|
| ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Result<u64, String>`
|
||||||
LL | | }
|
|
||||||
| |_- this function returns a `Result`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Result<u64, String>`
|
= help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Result<u64, String>`
|
||||||
= help: the following other types implement trait `FromResidual<R>`:
|
= help: the following other types implement trait `FromResidual<R>`:
|
||||||
|
@ -53,12 +48,10 @@ LL | | }
|
||||||
error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option`
|
error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option`
|
||||||
--> $DIR/bad-interconversion.rs:22:22
|
--> $DIR/bad-interconversion.rs:22:22
|
||||||
|
|
|
|
||||||
LL | / fn result_to_option() -> Option<u16> {
|
LL | fn result_to_option() -> Option<u16> {
|
||||||
LL | | Some(Err("hello")?)
|
| ------------------------------------ this function returns an `Option`
|
||||||
| | ^ use `.ok()?` if you want to discard the `Result<Infallible, &str>` error information
|
LL | Some(Err("hello")?)
|
||||||
LL | |
|
| ^ use `.ok()?` if you want to discard the `Result<Infallible, &str>` error information
|
||||||
LL | | }
|
|
||||||
| |_- this function returns an `Option`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `Option<u16>`
|
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `Option<u16>`
|
||||||
= help: the following other types implement trait `FromResidual<R>`:
|
= help: the following other types implement trait `FromResidual<R>`:
|
||||||
|
@ -68,12 +61,10 @@ LL | | }
|
||||||
error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option`
|
error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option`
|
||||||
--> $DIR/bad-interconversion.rs:27:33
|
--> $DIR/bad-interconversion.rs:27:33
|
||||||
|
|
|
|
||||||
LL | / fn control_flow_to_option() -> Option<u64> {
|
LL | fn control_flow_to_option() -> Option<u64> {
|
||||||
LL | | Some(ControlFlow::Break(123)?)
|
| ------------------------------------------ this function returns an `Option`
|
||||||
| | ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Option<u64>`
|
LL | Some(ControlFlow::Break(123)?)
|
||||||
LL | |
|
| ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Option<u64>`
|
||||||
LL | | }
|
|
||||||
| |_- this function returns an `Option`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Option<u64>`
|
= help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Option<u64>`
|
||||||
= help: the following other types implement trait `FromResidual<R>`:
|
= help: the following other types implement trait `FromResidual<R>`:
|
||||||
|
@ -83,12 +74,10 @@ LL | | }
|
||||||
error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
|
error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
|
||||||
--> $DIR/bad-interconversion.rs:32:39
|
--> $DIR/bad-interconversion.rs:32:39
|
||||||
|
|
|
|
||||||
LL | / fn result_to_control_flow() -> ControlFlow<String> {
|
LL | fn result_to_control_flow() -> ControlFlow<String> {
|
||||||
LL | | ControlFlow::Continue(Err("hello")?)
|
| -------------------------------------------------- this function returns a `ControlFlow`
|
||||||
| | ^ this `?` produces `Result<Infallible, &str>`, which is incompatible with `ControlFlow<String>`
|
LL | ControlFlow::Continue(Err("hello")?)
|
||||||
LL | |
|
| ^ this `?` produces `Result<Infallible, &str>`, which is incompatible with `ControlFlow<String>`
|
||||||
LL | | }
|
|
||||||
| |_- this function returns a `ControlFlow`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `ControlFlow<String>`
|
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `ControlFlow<String>`
|
||||||
= help: the trait `FromResidual` is implemented for `ControlFlow<B, C>`
|
= help: the trait `FromResidual` is implemented for `ControlFlow<B, C>`
|
||||||
|
@ -96,13 +85,10 @@ LL | | }
|
||||||
error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
|
error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
|
||||||
--> $DIR/bad-interconversion.rs:37:12
|
--> $DIR/bad-interconversion.rs:37:12
|
||||||
|
|
|
|
||||||
LL | / fn option_to_control_flow() -> ControlFlow<u64> {
|
LL | fn option_to_control_flow() -> ControlFlow<u64> {
|
||||||
LL | | Some(3)?;
|
| ----------------------------------------------- this function returns a `ControlFlow`
|
||||||
| | ^ this `?` produces `Option<Infallible>`, which is incompatible with `ControlFlow<u64>`
|
LL | Some(3)?;
|
||||||
LL | |
|
| ^ this `?` produces `Option<Infallible>`, which is incompatible with `ControlFlow<u64>`
|
||||||
LL | | ControlFlow::Break(10)
|
|
||||||
LL | | }
|
|
||||||
| |_- this function returns a `ControlFlow`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `ControlFlow<u64>`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `ControlFlow<u64>`
|
||||||
= help: the trait `FromResidual` is implemented for `ControlFlow<B, C>`
|
= help: the trait `FromResidual` is implemented for `ControlFlow<B, C>`
|
||||||
|
@ -110,13 +96,10 @@ LL | | }
|
||||||
error[E0277]: the `?` operator in a function that returns `ControlFlow<B, _>` can only be used on other `ControlFlow<B, _>`s (with the same Break type)
|
error[E0277]: the `?` operator in a function that returns `ControlFlow<B, _>` can only be used on other `ControlFlow<B, _>`s (with the same Break type)
|
||||||
--> $DIR/bad-interconversion.rs:43:29
|
--> $DIR/bad-interconversion.rs:43:29
|
||||||
|
|
|
|
||||||
LL | / fn control_flow_to_control_flow() -> ControlFlow<i64> {
|
LL | fn control_flow_to_control_flow() -> ControlFlow<i64> {
|
||||||
LL | | ControlFlow::Break(4_u8)?;
|
| ----------------------------------------------------- this function returns a `ControlFlow`
|
||||||
| | ^ this `?` produces `ControlFlow<u8, Infallible>`, which is incompatible with `ControlFlow<i64>`
|
LL | ControlFlow::Break(4_u8)?;
|
||||||
LL | |
|
| ^ this `?` produces `ControlFlow<u8, Infallible>`, which is incompatible with `ControlFlow<i64>`
|
||||||
LL | | ControlFlow::Continue(())
|
|
||||||
LL | | }
|
|
||||||
| |_- this function returns a `ControlFlow`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<ControlFlow<u8, Infallible>>` is not implemented for `ControlFlow<i64>`
|
= help: the trait `FromResidual<ControlFlow<u8, Infallible>>` is not implemented for `ControlFlow<i64>`
|
||||||
= note: unlike `Result`, there's no `From`-conversion performed for `ControlFlow`
|
= note: unlike `Result`, there's no `From`-conversion performed for `ControlFlow`
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
|
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
|
||||||
--> $DIR/option-to-result.rs:5:6
|
--> $DIR/option-to-result.rs:5:6
|
||||||
|
|
|
|
||||||
LL | / fn test_result() -> Result<(),()> {
|
LL | fn test_result() -> Result<(),()> {
|
||||||
LL | | let a:Option<()> = Some(());
|
| --------------------------------- this function returns a `Result`
|
||||||
LL | | a?;
|
LL | let a:Option<()> = Some(());
|
||||||
| | ^ use `.ok_or(...)?` to provide an error compatible with `Result<(), ()>`
|
LL | a?;
|
||||||
LL | | Ok(())
|
| ^ use `.ok_or(...)?` to provide an error compatible with `Result<(), ()>`
|
||||||
LL | | }
|
|
||||||
| |_- this function returns a `Result`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<(), ()>`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<(), ()>`
|
||||||
= help: the following other types implement trait `FromResidual<R>`:
|
= help: the following other types implement trait `FromResidual<R>`:
|
||||||
|
@ -17,13 +15,11 @@ LL | | }
|
||||||
error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option`
|
error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option`
|
||||||
--> $DIR/option-to-result.rs:11:6
|
--> $DIR/option-to-result.rs:11:6
|
||||||
|
|
|
|
||||||
LL | / fn test_option() -> Option<i32>{
|
LL | fn test_option() -> Option<i32>{
|
||||||
LL | | let a:Result<i32, i32> = Ok(5);
|
| ------------------------------- this function returns an `Option`
|
||||||
LL | | a?;
|
LL | let a:Result<i32, i32> = Ok(5);
|
||||||
| | ^ use `.ok()?` if you want to discard the `Result<Infallible, i32>` error information
|
LL | a?;
|
||||||
LL | | Some(5)
|
| ^ use `.ok()?` if you want to discard the `Result<Infallible, i32>` error information
|
||||||
LL | | }
|
|
||||||
| |_- this function returns an `Option`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Result<Infallible, i32>>` is not implemented for `Option<i32>`
|
= help: the trait `FromResidual<Result<Infallible, i32>>` is not implemented for `Option<i32>`
|
||||||
= help: the following other types implement trait `FromResidual<R>`:
|
= help: the following other types implement trait `FromResidual<R>`:
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
||||||
--> $DIR/try-on-option-diagnostics.rs:7:6
|
--> $DIR/try-on-option-diagnostics.rs:7:6
|
||||||
|
|
|
|
||||||
LL | / fn a_function() -> u32 {
|
LL | fn a_function() -> u32 {
|
||||||
LL | | let x: Option<u32> = None;
|
| ---------------------- this function should return `Result` or `Option` to accept `?`
|
||||||
LL | | x?;
|
LL | let x: Option<u32> = None;
|
||||||
| | ^ cannot use the `?` operator in a function that returns `u32`
|
LL | x?;
|
||||||
LL | | 22
|
| ^ cannot use the `?` operator in a function that returns `u32`
|
||||||
LL | | }
|
|
||||||
| |_- this function should return `Result` or `Option` to accept `?`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
|
||||||
|
|
||||||
|
@ -15,37 +13,32 @@ error[E0277]: the `?` operator can only be used in a closure that returns `Resul
|
||||||
--> $DIR/try-on-option-diagnostics.rs:14:10
|
--> $DIR/try-on-option-diagnostics.rs:14:10
|
||||||
|
|
|
|
||||||
LL | let a_closure = || {
|
LL | let a_closure = || {
|
||||||
| _____________________-
|
| -- this function should return `Result` or `Option` to accept `?`
|
||||||
LL | | let x: Option<u32> = None;
|
LL | let x: Option<u32> = None;
|
||||||
LL | | x?;
|
LL | x?;
|
||||||
| | ^ cannot use the `?` operator in a closure that returns `{integer}`
|
| ^ cannot use the `?` operator in a closure that returns `{integer}`
|
||||||
LL | | 22
|
|
||||||
LL | | };
|
|
||||||
| |_____- this function should return `Result` or `Option` to accept `?`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `{integer}`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `{integer}`
|
||||||
|
|
||||||
error[E0277]: the `?` operator can only be used in a method that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
error[E0277]: the `?` operator can only be used in a method that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
||||||
--> $DIR/try-on-option-diagnostics.rs:26:14
|
--> $DIR/try-on-option-diagnostics.rs:26:14
|
||||||
|
|
|
|
||||||
LL | / fn a_method() {
|
LL | fn a_method() {
|
||||||
LL | | let x: Option<u32> = None;
|
| ------------- this function should return `Result` or `Option` to accept `?`
|
||||||
LL | | x?;
|
LL | let x: Option<u32> = None;
|
||||||
| | ^ cannot use the `?` operator in a method that returns `()`
|
LL | x?;
|
||||||
LL | | }
|
| ^ cannot use the `?` operator in a method that returns `()`
|
||||||
| |_________- this function should return `Result` or `Option` to accept `?`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `()`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `()`
|
||||||
|
|
||||||
error[E0277]: the `?` operator can only be used in a trait method that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
error[E0277]: the `?` operator can only be used in a trait method that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
||||||
--> $DIR/try-on-option-diagnostics.rs:39:14
|
--> $DIR/try-on-option-diagnostics.rs:39:14
|
||||||
|
|
|
|
||||||
LL | / fn a_trait_method() {
|
LL | fn a_trait_method() {
|
||||||
LL | | let x: Option<u32> = None;
|
| ------------------- this function should return `Result` or `Option` to accept `?`
|
||||||
LL | | x?;
|
LL | let x: Option<u32> = None;
|
||||||
| | ^ cannot use the `?` operator in a trait method that returns `()`
|
LL | x?;
|
||||||
LL | | }
|
| ^ cannot use the `?` operator in a trait method that returns `()`
|
||||||
| |_________- this function should return `Result` or `Option` to accept `?`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `()`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `()`
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
|
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
|
||||||
--> $DIR/try-on-option.rs:5:6
|
--> $DIR/try-on-option.rs:5:6
|
||||||
|
|
|
|
||||||
LL | / fn foo() -> Result<u32, ()> {
|
LL | fn foo() -> Result<u32, ()> {
|
||||||
LL | | let x: Option<u32> = None;
|
| --------------------------- this function returns a `Result`
|
||||||
LL | | x?;
|
LL | let x: Option<u32> = None;
|
||||||
| | ^ use `.ok_or(...)?` to provide an error compatible with `Result<u32, ()>`
|
LL | x?;
|
||||||
LL | | Ok(22)
|
| ^ use `.ok_or(...)?` to provide an error compatible with `Result<u32, ()>`
|
||||||
LL | | }
|
|
||||||
| |_- this function returns a `Result`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u32, ()>`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u32, ()>`
|
||||||
= help: the following other types implement trait `FromResidual<R>`:
|
= help: the following other types implement trait `FromResidual<R>`:
|
||||||
|
@ -17,13 +15,11 @@ LL | | }
|
||||||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
||||||
--> $DIR/try-on-option.rs:11:6
|
--> $DIR/try-on-option.rs:11:6
|
||||||
|
|
|
|
||||||
LL | / fn bar() -> u32 {
|
LL | fn bar() -> u32 {
|
||||||
LL | | let x: Option<u32> = None;
|
| --------------- this function should return `Result` or `Option` to accept `?`
|
||||||
LL | | x?;
|
LL | let x: Option<u32> = None;
|
||||||
| | ^ cannot use the `?` operator in a function that returns `u32`
|
LL | x?;
|
||||||
LL | | 22
|
| ^ cannot use the `?` operator in a function that returns `u32`
|
||||||
LL | | }
|
|
||||||
| |_- this function should return `Result` or `Option` to accept `?`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `u32`
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
||||||
--> $DIR/try-operator-on-main.rs:7:31
|
--> $DIR/try-operator-on-main.rs:7:31
|
||||||
|
|
|
|
||||||
LL | / fn main() {
|
LL | fn main() {
|
||||||
LL | | // error for a `Try` type on a non-`Try` fn
|
| --------- this function should return `Result` or `Option` to accept `?`
|
||||||
LL | | std::fs::File::open("foo")?;
|
LL | // error for a `Try` type on a non-`Try` fn
|
||||||
| | ^ cannot use the `?` operator in a function that returns `()`
|
LL | std::fs::File::open("foo")?;
|
||||||
LL | |
|
| ^ cannot use the `?` operator in a function that returns `()`
|
||||||
... |
|
|
||||||
LL | | try_trait_generic::<()>();
|
|
||||||
LL | | }
|
|
||||||
| |_- this function should return `Result` or `Option` to accept `?`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()`
|
= help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()`
|
||||||
|
|
||||||
|
@ -24,17 +20,11 @@ LL | ()?;
|
||||||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
|
||||||
--> $DIR/try-operator-on-main.rs:10:7
|
--> $DIR/try-operator-on-main.rs:10:7
|
||||||
|
|
|
|
||||||
LL | / fn main() {
|
LL | fn main() {
|
||||||
LL | | // error for a `Try` type on a non-`Try` fn
|
| --------- this function should return `Result` or `Option` to accept `?`
|
||||||
LL | | std::fs::File::open("foo")?;
|
...
|
||||||
LL | |
|
LL | ()?;
|
||||||
LL | | // a non-`Try` type on a non-`Try` fn
|
| ^ cannot use the `?` operator in a function that returns `()`
|
||||||
LL | | ()?;
|
|
||||||
| | ^ cannot use the `?` operator in a function that returns `()`
|
|
||||||
... |
|
|
||||||
LL | | try_trait_generic::<()>();
|
|
||||||
LL | | }
|
|
||||||
| |_- this function should return `Result` or `Option` to accept `?`
|
|
||||||
|
|
|
|
||||||
= help: the trait `FromResidual<_>` is not implemented for `()`
|
= help: the trait `FromResidual<_>` is not implemented for `()`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue