@@ -27,6 +27,8 @@ use rustc_target::spec::abi;
2727use std:: mem;
2828use std:: ops:: { Deref , DerefMut } ;
2929
30+ use crate :: errors:: ForbiddenLet ;
31+
3032const MORE_EXTERN : & str =
3133 "for more information, visit https://doc.rust-lang.org/std/keyword.extern.html" ;
3234
@@ -117,23 +119,7 @@ impl<'a> AstValidator<'a> {
117119
118120 /// Emits an error banning the `let` expression provided in the given location.
119121 fn ban_let_expr ( & self , expr : & ' a Expr , forbidden_let_reason : ForbiddenLetReason ) {
120- let err = "`let` expressions are not supported here" ;
121- let mut diag = self . session . struct_span_err ( expr. span , err) ;
122- diag. note ( "only supported directly in conditions of `if` and `while` expressions" ) ;
123- match forbidden_let_reason {
124- ForbiddenLetReason :: GenericForbidden => { }
125- ForbiddenLetReason :: NotSupportedOr ( span) => {
126- diag. span_note ( span, "`||` operators are not supported in let chain expressions" ) ;
127- }
128- ForbiddenLetReason :: NotSupportedParentheses ( span) => {
129- diag. span_note (
130- span,
131- "`let`s wrapped in parentheses are not supported in a context with let \
132- chains",
133- ) ;
134- }
135- }
136- diag. emit ( ) ;
122+ self . session . emit_err ( ForbiddenLet { span : expr. span , reason : forbidden_let_reason } ) ;
137123 }
138124
139125 fn check_gat_where (
@@ -1876,7 +1862,7 @@ pub fn check_crate(session: &Session, krate: &Crate, lints: &mut LintBuffer) ->
18761862
18771863/// Used to forbid `let` expressions in certain syntactic locations.
18781864#[ derive( Clone , Copy ) ]
1879- enum ForbiddenLetReason {
1865+ pub ( crate ) enum ForbiddenLetReason {
18801866 /// `let` is not valid and the source environment is not important
18811867 GenericForbidden ,
18821868 /// A let chain with the `||` operator
0 commit comments