Reduce verbosity for ?
on non-Try
expressions
This commit is contained in:
parent
75b62757e4
commit
caf0c1bb1c
4 changed files with 8 additions and 15 deletions
|
@ -352,6 +352,8 @@ pub enum ObligationCauseCode<'tcx> {
|
||||||
|
|
||||||
ForLoopIterator,
|
ForLoopIterator,
|
||||||
|
|
||||||
|
QuestionMark,
|
||||||
|
|
||||||
/// Well-formed checking. If a `WellFormedLoc` is provided,
|
/// Well-formed checking. If a `WellFormedLoc` is provided,
|
||||||
/// then it will be used to eprform HIR-based wf checking
|
/// then it will be used to eprform HIR-based wf checking
|
||||||
/// after an error occurs, in order to generate a more precise error span.
|
/// after an error occurs, in order to generate a more precise error span.
|
||||||
|
|
|
@ -1964,6 +1964,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
| ObligationCauseCode::BlockTailExpression(_)
|
| ObligationCauseCode::BlockTailExpression(_)
|
||||||
| ObligationCauseCode::AwaitableExpr
|
| ObligationCauseCode::AwaitableExpr
|
||||||
| ObligationCauseCode::ForLoopIterator
|
| ObligationCauseCode::ForLoopIterator
|
||||||
|
| ObligationCauseCode::QuestionMark
|
||||||
| ObligationCauseCode::LetElse => {}
|
| ObligationCauseCode::LetElse => {}
|
||||||
ObligationCauseCode::SliceOrArrayElem => {
|
ObligationCauseCode::SliceOrArrayElem => {
|
||||||
err.note("slice and array elements must have `Sized` type");
|
err.note("slice and array elements must have `Sized` type");
|
||||||
|
|
|
@ -811,7 +811,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
match lang_item {
|
match lang_item {
|
||||||
hir::LangItem::FuturePoll => ObligationCauseCode::AwaitableExpr,
|
hir::LangItem::FuturePoll => ObligationCauseCode::AwaitableExpr,
|
||||||
hir::LangItem::IntoIterIntoIter => ObligationCauseCode::ForLoopIterator,
|
hir::LangItem::IntoIterIntoIter => ObligationCauseCode::ForLoopIterator,
|
||||||
// FIXME: This could also be used for `?`. See if there are others.
|
hir::LangItem::TryTraitBranch => ObligationCauseCode::QuestionMark,
|
||||||
_ => traits::ItemObligation(def_id),
|
_ => traits::ItemObligation(def_id),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -115,15 +115,14 @@ use crate::ops::ControlFlow;
|
||||||
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
#[unstable(feature = "try_trait_v2", issue = "84277")]
|
||||||
#[rustc_on_unimplemented(
|
#[rustc_on_unimplemented(
|
||||||
on(
|
on(
|
||||||
all(from_method = "from_output", from_desugaring = "TryBlock"),
|
all(from_desugaring = "TryBlock"),
|
||||||
message = "a `try` block must return `Result` or `Option` \
|
message = "a `try` block must return `Result` or `Option` \
|
||||||
(or another type that implements `{Try}`)",
|
(or another type that implements `{Try}`)",
|
||||||
label = "could not wrap the final value of the block as `{Self}` doesn't implement `Try`",
|
label = "could not wrap the final value of the block as `{Self}` doesn't implement `Try`",
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
all(from_method = "branch", from_desugaring = "QuestionMark"),
|
all(from_desugaring = "QuestionMark"),
|
||||||
message = "the `?` operator can only be applied to values \
|
message = "the `?` operator can only be applied to values that implement `{Try}`",
|
||||||
that implement `{Try}`",
|
|
||||||
label = "the `?` operator cannot be applied to type `{Self}`"
|
label = "the `?` operator cannot be applied to type `{Self}`"
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
|
@ -226,7 +225,6 @@ pub trait Try: FromResidual {
|
||||||
#[rustc_on_unimplemented(
|
#[rustc_on_unimplemented(
|
||||||
on(
|
on(
|
||||||
all(
|
all(
|
||||||
from_method = "from_residual",
|
|
||||||
from_desugaring = "QuestionMark",
|
from_desugaring = "QuestionMark",
|
||||||
_Self = "std::result::Result<T, E>",
|
_Self = "std::result::Result<T, E>",
|
||||||
R = "std::option::Option<std::convert::Infallible>"
|
R = "std::option::Option<std::convert::Infallible>"
|
||||||
|
@ -238,7 +236,6 @@ pub trait Try: FromResidual {
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
all(
|
all(
|
||||||
from_method = "from_residual",
|
|
||||||
from_desugaring = "QuestionMark",
|
from_desugaring = "QuestionMark",
|
||||||
_Self = "std::result::Result<T, E>",
|
_Self = "std::result::Result<T, E>",
|
||||||
),
|
),
|
||||||
|
@ -252,7 +249,6 @@ pub trait Try: FromResidual {
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
all(
|
all(
|
||||||
from_method = "from_residual",
|
|
||||||
from_desugaring = "QuestionMark",
|
from_desugaring = "QuestionMark",
|
||||||
_Self = "std::option::Option<T>",
|
_Self = "std::option::Option<T>",
|
||||||
R = "std::result::Result<T, E>",
|
R = "std::result::Result<T, E>",
|
||||||
|
@ -264,7 +260,6 @@ pub trait Try: FromResidual {
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
all(
|
all(
|
||||||
from_method = "from_residual",
|
|
||||||
from_desugaring = "QuestionMark",
|
from_desugaring = "QuestionMark",
|
||||||
_Self = "std::option::Option<T>",
|
_Self = "std::option::Option<T>",
|
||||||
),
|
),
|
||||||
|
@ -277,7 +272,6 @@ pub trait Try: FromResidual {
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
all(
|
all(
|
||||||
from_method = "from_residual",
|
|
||||||
from_desugaring = "QuestionMark",
|
from_desugaring = "QuestionMark",
|
||||||
_Self = "std::ops::ControlFlow<B, C>",
|
_Self = "std::ops::ControlFlow<B, C>",
|
||||||
R = "std::ops::ControlFlow<B, C>",
|
R = "std::ops::ControlFlow<B, C>",
|
||||||
|
@ -290,7 +284,6 @@ pub trait Try: FromResidual {
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
all(
|
all(
|
||||||
from_method = "from_residual",
|
|
||||||
from_desugaring = "QuestionMark",
|
from_desugaring = "QuestionMark",
|
||||||
_Self = "std::ops::ControlFlow<B, C>",
|
_Self = "std::ops::ControlFlow<B, C>",
|
||||||
// `R` is not a `ControlFlow`, as that case was matched previously
|
// `R` is not a `ControlFlow`, as that case was matched previously
|
||||||
|
@ -301,10 +294,7 @@ pub trait Try: FromResidual {
|
||||||
enclosing_scope = "this function returns a `ControlFlow`",
|
enclosing_scope = "this function returns a `ControlFlow`",
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
all(
|
all(from_desugaring = "QuestionMark"),
|
||||||
from_method = "from_residual",
|
|
||||||
from_desugaring = "QuestionMark"
|
|
||||||
),
|
|
||||||
message = "the `?` operator can only be used in {ItemContext} \
|
message = "the `?` operator can only be used in {ItemContext} \
|
||||||
that returns `Result` or `Option` \
|
that returns `Result` or `Option` \
|
||||||
(or another type that implements `{FromResidual}`)",
|
(or another type that implements `{FromResidual}`)",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue