Avoid expanding to unstable internal method

This commit is contained in:
Jacob Pratt 2024-03-29 05:35:45 +00:00
parent d74804636f
commit 0fcdf34861
No known key found for this signature in database
GPG Key ID: FEAC5E6B1E5E6CEF
4 changed files with 70 additions and 9 deletions

View File

@ -48,6 +48,23 @@ pub fn path_all(
ast::Path { span, segments, tokens: None }
}
pub fn macro_call(
&self,
span: Span,
path: ast::Path,
delim: ast::token::Delimiter,
tokens: ast::tokenstream::TokenStream,
) -> P<ast::MacCall> {
P(ast::MacCall {
path,
args: P(ast::DelimArgs {
dspan: ast::tokenstream::DelimSpan { open: span, close: span },
delim,
tokens,
}),
})
}
pub fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
ast::MutTy { ty, mutbl }
}
@ -265,6 +282,10 @@ pub fn expr_field(&self, span: Span, expr: P<Expr>, field: Ident) -> P<ast::Expr
self.expr(span, ast::ExprKind::Field(expr, field))
}
pub fn expr_macro_call(&self, span: Span, call: P<ast::MacCall>) -> P<ast::Expr> {
self.expr(span, ast::ExprKind::MacCall(call))
}
pub fn expr_binary(
&self,
sp: Span,
@ -410,16 +431,19 @@ pub fn expr_tuple(&self, sp: Span, exprs: ThinVec<P<ast::Expr>>) -> P<ast::Expr>
self.expr(sp, ast::ExprKind::Tup(exprs))
}
pub fn expr_fail(&self, span: Span, msg: Symbol) -> P<ast::Expr> {
self.expr_call_global(
span,
[sym::std, sym::rt, sym::begin_panic].iter().map(|s| Ident::new(*s, span)).collect(),
thin_vec![self.expr_str(span, msg)],
)
}
pub fn expr_unreachable(&self, span: Span) -> P<ast::Expr> {
self.expr_fail(span, Symbol::intern("internal error: entered unreachable code"))
self.expr_macro_call(
span,
self.macro_call(
span,
self.path_global(
span,
[sym::std, sym::unreachable].map(|s| Ident::new(s, span)).to_vec(),
),
ast::token::Delimiter::Parenthesis,
ast::tokenstream::TokenStream::default(),
),
)
}
pub fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {

View File

@ -0,0 +1,16 @@
#![crate_type = "lib"]
pub trait Decoder {
type Error;
fn read_enum<T, F>(&mut self, name: &str, f: F) -> Result<T, Self::Error>
where F: FnOnce(&mut Self) -> Result<T, Self::Error>;
fn read_enum_variant<T, F>(&mut self, names: &[&str], f: F)
-> Result<T, Self::Error>
where F: FnMut(&mut Self, usize) -> Result<T, Self::Error>;
}
pub trait Decodable: Sized {
fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error>;
}

View File

@ -0,0 +1,11 @@
//@ check-pass
//@ edition:2021
//@ aux-build:rustc-serialize.rs
#![crate_type = "lib"]
#![allow(deprecated, soft_unstable)]
extern crate rustc_serialize;
#[derive(RustcDecodable)]
pub enum Foo {}

View File

@ -0,0 +1,10 @@
Future incompatibility report: Future breakage diagnostic:
warning: use of unstable library feature 'rustc_encodable_decodable': derive macro for `rustc-serialize`; should not be used in new code
--> $DIR/rustc-decodable-issue-123156.rs:10:10
|
LL | #[derive(RustcDecodable)]
| ^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>