Skip to content

Commit 5c16969

Browse files
committed
Avoid expanding to unstable internal method
1 parent d748046 commit 5c16969

File tree

5 files changed

+74
-17
lines changed

5 files changed

+74
-17
lines changed

compiler/rustc_builtin_macros/src/deriving/decodable.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,22 @@ fn decodable_substructure(
149149
arms.push(cx.arm(v_span, cx.pat_lit(v_span, cx.expr_usize(v_span, i)), decoded));
150150
}
151151

152-
arms.push(cx.arm_unreachable(trait_span));
152+
let expr_unreachable = cx.expr_macro_call(
153+
trait_span,
154+
cx.macro_call(
155+
trait_span,
156+
cx.path_global(
157+
trait_span,
158+
[sym::std, sym::unreachable]
159+
.map(|s| Ident::new(s, trait_span))
160+
.to_vec(),
161+
),
162+
ast::token::Delimiter::Parenthesis,
163+
ast::tokenstream::TokenStream::default(),
164+
),
165+
);
166+
let arm_unreachable = cx.arm(trait_span, cx.pat_wild(trait_span), expr_unreachable);
167+
arms.push(arm_unreachable);
153168

154169
let result = cx.expr_ok(
155170
trait_span,

compiler/rustc_expand/src/build.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ impl<'a> ExtCtxt<'a> {
4848
ast::Path { span, segments, tokens: None }
4949
}
5050

51+
pub fn macro_call(
52+
&self,
53+
span: Span,
54+
path: ast::Path,
55+
delim: ast::token::Delimiter,
56+
tokens: ast::tokenstream::TokenStream,
57+
) -> P<ast::MacCall> {
58+
P(ast::MacCall {
59+
path,
60+
args: P(ast::DelimArgs {
61+
dspan: ast::tokenstream::DelimSpan { open: span, close: span },
62+
delim,
63+
tokens,
64+
}),
65+
})
66+
}
67+
5168
pub fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
5269
ast::MutTy { ty, mutbl }
5370
}
@@ -265,6 +282,10 @@ impl<'a> ExtCtxt<'a> {
265282
self.expr(span, ast::ExprKind::Field(expr, field))
266283
}
267284

285+
pub fn expr_macro_call(&self, span: Span, call: P<ast::MacCall>) -> P<ast::Expr> {
286+
self.expr(span, ast::ExprKind::MacCall(call))
287+
}
288+
268289
pub fn expr_binary(
269290
&self,
270291
sp: Span,
@@ -410,18 +431,6 @@ impl<'a> ExtCtxt<'a> {
410431
self.expr(sp, ast::ExprKind::Tup(exprs))
411432
}
412433

413-
pub fn expr_fail(&self, span: Span, msg: Symbol) -> P<ast::Expr> {
414-
self.expr_call_global(
415-
span,
416-
[sym::std, sym::rt, sym::begin_panic].iter().map(|s| Ident::new(*s, span)).collect(),
417-
thin_vec![self.expr_str(span, msg)],
418-
)
419-
}
420-
421-
pub fn expr_unreachable(&self, span: Span) -> P<ast::Expr> {
422-
self.expr_fail(span, Symbol::intern("internal error: entered unreachable code"))
423-
}
424-
425434
pub fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
426435
let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
427436
self.expr_call_global(sp, ok, thin_vec![expr])
@@ -519,10 +528,6 @@ impl<'a> ExtCtxt<'a> {
519528
}
520529
}
521530

522-
pub fn arm_unreachable(&self, span: Span) -> ast::Arm {
523-
self.arm(span, self.pat_wild(span), self.expr_unreachable(span))
524-
}
525-
526531
pub fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: ThinVec<ast::Arm>) -> P<Expr> {
527532
self.expr(span, ast::ExprKind::Match(arg, arms, MatchKind::Prefix))
528533
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![crate_type = "lib"]
2+
3+
pub trait Decoder {
4+
type Error;
5+
6+
fn read_enum<T, F>(&mut self, name: &str, f: F) -> Result<T, Self::Error>
7+
where F: FnOnce(&mut Self) -> Result<T, Self::Error>;
8+
fn read_enum_variant<T, F>(&mut self, names: &[&str], f: F)
9+
-> Result<T, Self::Error>
10+
where F: FnMut(&mut Self, usize) -> Result<T, Self::Error>;
11+
12+
}
13+
14+
pub trait Decodable: Sized {
15+
fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error>;
16+
}

tests/ui/derives/issue-123156.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
//@ aux-build:rustc-serialize.rs
4+
5+
#![crate_type = "lib"]
6+
#![allow(deprecated, soft_unstable)]
7+
8+
extern crate rustc_serialize;
9+
10+
#[derive(RustcDecodable)]
11+
pub enum Foo {}

tests/ui/derives/issue-123156.stderr

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

0 commit comments

Comments
 (0)