Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a6c4025

Browse files
committedJan 13, 2020
perf: eagerly convert literals to consts, this avoids creating loads on unevaluated consts
which requires a lot of unnecessary work to evaluate them further down the line.
1 parent bf84eb5 commit a6c4025

File tree

18 files changed

+175
-91
lines changed

18 files changed

+175
-91
lines changed
 

‎src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
use crate::hir::map::DefPathHash;
5353
use crate::ich::{Fingerprint, StableHashingContext};
5454
use crate::mir;
55-
use crate::mir::interpret::GlobalId;
55+
use crate::mir::interpret::{GlobalId, LitToConstInput};
5656
use crate::traits;
5757
use crate::traits::query::{
5858
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,

‎src/librustc/mir/interpret/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ use crate::mir;
119119
use crate::ty::codec::TyDecoder;
120120
use crate::ty::layout::{self, Size};
121121
use crate::ty::subst::GenericArgKind;
122-
use crate::ty::{self, Instance, TyCtxt};
122+
use crate::ty::{self, Instance, Ty, TyCtxt};
123123
use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt};
124124
use rustc_data_structures::fx::FxHashMap;
125125
use rustc_data_structures::sync::{HashMapExt, Lock};
@@ -131,6 +131,7 @@ use std::fmt;
131131
use std::io;
132132
use std::num::NonZeroU32;
133133
use std::sync::atomic::{AtomicU32, Ordering};
134+
use syntax::ast::LitKind;
134135

135136
/// Uniquely identifies one of the following:
136137
/// - A constant
@@ -147,6 +148,24 @@ pub struct GlobalId<'tcx> {
147148
pub promoted: Option<mir::Promoted>,
148149
}
149150

151+
/// Input argument for `tcx.lit_to_const`
152+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, HashStable)]
153+
pub struct LitToConstInput<'tcx> {
154+
/// The absolute value of the resultant constant
155+
pub lit: &'tcx LitKind,
156+
/// The type of the constant
157+
pub ty: Ty<'tcx>,
158+
/// If the constant is negative
159+
pub neg: bool,
160+
}
161+
162+
/// Error type for `tcx.lit_to_const`
163+
#[derive(Copy, Clone, Debug, Eq, PartialEq, HashStable)]
164+
pub enum LitToConstError {
165+
UnparseableFloat,
166+
Reported,
167+
}
168+
150169
#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd, Debug)]
151170
pub struct AllocId(pub u64);
152171

‎src/librustc/query/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::dep_graph::{DepKind, DepNode, RecoverKey, SerializedDepNodeIndex};
22
use crate::mir;
3-
use crate::mir::interpret::GlobalId;
3+
use crate::mir::interpret::{GlobalId, LitToConstInput};
44
use crate::traits;
55
use crate::traits::query::{
66
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
@@ -518,6 +518,13 @@ rustc_queries! {
518518
no_force
519519
desc { "get a &core::panic::Location referring to a span" }
520520
}
521+
522+
query lit_to_const(
523+
key: LitToConstInput<'tcx>
524+
) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
525+
no_force
526+
desc { "converting literal to const" }
527+
}
521528
}
522529

523530
TypeChecking {

‎src/librustc/ty/query/keys.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ impl<'tcx> Key for mir::interpret::GlobalId<'tcx> {
5252
}
5353
}
5454

55+
impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
56+
fn query_crate(&self) -> CrateNum {
57+
LOCAL_CRATE
58+
}
59+
60+
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
61+
DUMMY_SP
62+
}
63+
}
64+
5565
impl Key for CrateNum {
5666
fn query_crate(&self) -> CrateNum {
5767
*self

‎src/librustc/ty/query/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::middle::stability::{self, DeprecationEntry};
1515
use crate::mir;
1616
use crate::mir::interpret::GlobalId;
1717
use crate::mir::interpret::{ConstEvalRawResult, ConstEvalResult};
18+
use crate::mir::interpret::{LitToConstError, LitToConstInput};
1819
use crate::mir::mono::CodegenUnit;
1920
use crate::session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
2021
use crate::session::CrateDisambiguator;

‎src/librustc_mir/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ pub fn provide(providers: &mut Providers<'_>) {
6262
providers.destructure_const = |tcx, param_env_and_value| {
6363
let (param_env, value) = param_env_and_value.into_parts();
6464
const_eval::destructure_const(tcx, param_env, value)
65-
}
65+
};
6666
}

‎src/librustc_mir_build/hair/constant.rs

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
use rustc::mir::interpret::{ConstValue, Scalar};
2-
use rustc::ty::{self, layout::Size, ParamEnv, Ty, TyCtxt};
1+
use rustc::mir::interpret::{
2+
truncate, Allocation, ConstValue, LitToConstError, LitToConstInput, Scalar,
3+
};
4+
use rustc::ty::{self, layout::Size, ParamEnv, TyCtxt};
35
use rustc_span::symbol::Symbol;
46
use syntax::ast;
57

6-
#[derive(PartialEq)]
7-
crate enum LitToConstError {
8-
UnparseableFloat,
9-
Reported,
10-
}
11-
128
crate fn lit_to_const<'tcx>(
13-
lit: &'tcx ast::LitKind,
149
tcx: TyCtxt<'tcx>,
15-
ty: Ty<'tcx>,
16-
neg: bool,
10+
lit_input: LitToConstInput<'tcx>,
1711
) -> Result<&'tcx ty::Const<'tcx>, LitToConstError> {
18-
use syntax::ast::*;
12+
let LitToConstInput { lit, ty, neg } = lit_input;
1913

2014
let trunc = |n| {
2115
let param_ty = ParamEnv::reveal_all().and(ty);
@@ -26,35 +20,50 @@ crate fn lit_to_const<'tcx>(
2620
Ok(ConstValue::Scalar(Scalar::from_uint(result, width)))
2721
};
2822

29-
use rustc::mir::interpret::*;
3023
let lit = match *lit {
31-
LitKind::Str(ref s, _) => {
24+
ast::LitKind::Str(ref s, _) => {
3225
let s = s.as_str();
3326
let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes());
3427
let allocation = tcx.intern_const_alloc(allocation);
3528
ConstValue::Slice { data: allocation, start: 0, end: s.len() }
3629
}
37-
LitKind::ByteStr(ref data) => {
38-
let id = tcx.allocate_bytes(data);
39-
ConstValue::Scalar(Scalar::Ptr(id.into()))
30+
ast::LitKind::ByteStr(ref data) => {
31+
if let ty::Ref(_, ref_ty, _) = ty.kind {
32+
match ref_ty.kind {
33+
ty::Slice(_) => {
34+
let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>);
35+
let allocation = tcx.intern_const_alloc(allocation);
36+
ConstValue::Slice { data: allocation, start: 0, end: data.len() }
37+
}
38+
ty::Array(_, _) => {
39+
let id = tcx.allocate_bytes(data);
40+
ConstValue::Scalar(Scalar::Ptr(id.into()))
41+
}
42+
_ => {
43+
bug!("bytestring should have type of either &[u8] or &[u8; _], not {}", ty)
44+
}
45+
}
46+
} else {
47+
bug!("bytestring should have type of either &[u8] or &[u8; _], not {}", ty)
48+
}
4049
}
41-
LitKind::Byte(n) => ConstValue::Scalar(Scalar::from_uint(n, Size::from_bytes(1))),
42-
LitKind::Int(n, _) if neg => {
50+
ast::LitKind::Byte(n) => ConstValue::Scalar(Scalar::from_uint(n, Size::from_bytes(1))),
51+
ast::LitKind::Int(n, _) if neg => {
4352
let n = n as i128;
4453
let n = n.overflowing_neg().0;
4554
trunc(n as u128)?
4655
}
47-
LitKind::Int(n, _) => trunc(n)?,
48-
LitKind::Float(n, _) => {
56+
ast::LitKind::Int(n, _) => trunc(n)?,
57+
ast::LitKind::Float(n, _) => {
4958
let fty = match ty.kind {
5059
ty::Float(fty) => fty,
5160
_ => bug!(),
5261
};
5362
parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
5463
}
55-
LitKind::Bool(b) => ConstValue::Scalar(Scalar::from_bool(b)),
56-
LitKind::Char(c) => ConstValue::Scalar(Scalar::from_char(c)),
57-
LitKind::Err(_) => unreachable!(),
64+
ast::LitKind::Bool(b) => ConstValue::Scalar(Scalar::from_bool(b)),
65+
ast::LitKind::Char(c) => ConstValue::Scalar(Scalar::from_char(c)),
66+
ast::LitKind::Err(_) => return Err(LitToConstError::Reported),
5867
};
5968
Ok(tcx.mk_const(ty::Const { val: ty::ConstKind::Value(lit), ty }))
6069
}

‎src/librustc_mir_build/hair/cx/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use crate::hair::util::UserAnnotatedTyHelpers;
66
use crate::hair::*;
77

8-
use crate::hair::constant::{lit_to_const, LitToConstError};
98
use rustc::infer::InferCtxt;
109
use rustc::middle::region;
10+
use rustc::mir::interpret::{LitToConstError, LitToConstInput};
1111
use rustc::ty::layout::VariantIdx;
1212
use rustc::ty::subst::Subst;
1313
use rustc::ty::subst::{GenericArg, InternalSubsts};
@@ -136,7 +136,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
136136
) -> &'tcx ty::Const<'tcx> {
137137
trace!("const_eval_literal: {:#?}, {:?}, {:?}, {:?}", lit, ty, sp, neg);
138138

139-
match lit_to_const(lit, self.tcx, ty, neg) {
139+
match self.tcx.at(sp).lit_to_const(LitToConstInput { lit, ty, neg }) {
140140
Ok(c) => c,
141141
Err(LitToConstError::UnparseableFloat) => {
142142
// FIXME(#31407) this is only necessary because float parsing is buggy

‎src/librustc_mir_build/hair/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir as hir;
1616
use rustc_hir::def_id::DefId;
1717
use rustc_span::Span;
1818

19-
mod constant;
19+
crate mod constant;
2020
crate mod cx;
2121

2222
crate mod pattern;

‎src/librustc_mir_build/hair/pattern/mod.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ mod const_to_pat;
66

77
pub(crate) use self::check_match::check_match;
88

9-
use crate::hair::constant::*;
109
use crate::hair::util::UserAnnotatedTyHelpers;
1110

12-
use rustc::mir::interpret::{get_slice_bytes, sign_extend, ConstValue, ErrorHandled};
11+
use rustc::mir::interpret::{
12+
get_slice_bytes, sign_extend, ConstValue, ErrorHandled, LitToConstError, LitToConstInput,
13+
};
1314
use rustc::mir::UserTypeProjection;
1415
use rustc::mir::{BorrowKind, Field, Mutability};
1516
use rustc::ty::layout::VariantIdx;
@@ -822,35 +823,30 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
822823
/// which would overflow if we tried to evaluate `128_i8` and then negate
823824
/// afterwards.
824825
fn lower_lit(&mut self, expr: &'tcx hir::Expr<'tcx>) -> PatKind<'tcx> {
825-
match expr.kind {
826-
hir::ExprKind::Lit(ref lit) => {
827-
let ty = self.tables.expr_ty(expr);
828-
match lit_to_const(&lit.node, self.tcx, ty, false) {
829-
Ok(val) => *self.const_to_pat(val, expr.hir_id, lit.span).kind,
830-
Err(LitToConstError::UnparseableFloat) => {
831-
self.errors.push(PatternError::FloatBug);
832-
PatKind::Wild
833-
}
834-
Err(LitToConstError::Reported) => PatKind::Wild,
826+
if let hir::ExprKind::Path(ref qpath) = expr.kind {
827+
*self.lower_path(qpath, expr.hir_id, expr.span).kind
828+
} else {
829+
let (lit, neg) = match expr.kind {
830+
hir::ExprKind::Lit(ref lit) => (lit, false),
831+
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
832+
let lit = match expr.kind {
833+
hir::ExprKind::Lit(ref lit) => lit,
834+
_ => span_bug!(expr.span, "not a literal: {:?}", expr),
835+
};
836+
(lit, true)
835837
}
836-
}
837-
hir::ExprKind::Path(ref qpath) => *self.lower_path(qpath, expr.hir_id, expr.span).kind,
838-
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
839-
let ty = self.tables.expr_ty(expr);
840-
let lit = match expr.kind {
841-
hir::ExprKind::Lit(ref lit) => lit,
842-
_ => span_bug!(expr.span, "not a literal: {:?}", expr),
843-
};
844-
match lit_to_const(&lit.node, self.tcx, ty, true) {
845-
Ok(val) => *self.const_to_pat(val, expr.hir_id, lit.span).kind,
846-
Err(LitToConstError::UnparseableFloat) => {
847-
self.errors.push(PatternError::FloatBug);
848-
PatKind::Wild
849-
}
850-
Err(LitToConstError::Reported) => PatKind::Wild,
838+
_ => span_bug!(expr.span, "not a literal: {:?}", expr),
839+
};
840+
841+
let lit_input = LitToConstInput { lit: &lit.node, ty: self.tables.expr_ty(expr), neg };
842+
match self.tcx.at(expr.span).lit_to_const(lit_input) {
843+
Ok(val) => *self.const_to_pat(val, expr.hir_id, lit.span).kind,
844+
Err(LitToConstError::UnparseableFloat) => {
845+
self.errors.push(PatternError::FloatBug);
846+
PatKind::Wild
851847
}
848+
Err(LitToConstError::Reported) => PatKind::Wild,
852849
}
853-
_ => span_bug!(expr.span, "not a literal: {:?}", expr),
854850
}
855851
}
856852
}

‎src/librustc_mir_build/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ use rustc::ty::query::Providers;
2222

2323
pub fn provide(providers: &mut Providers<'_>) {
2424
providers.check_match = hair::pattern::check_match;
25+
providers.lit_to_const = hair::constant::lit_to_const;
2526
providers.mir_built = build::mir_built;
2627
}

‎src/librustc_typeck/astconv.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-tidy-filelength FIXME(#67418) Split up this file
12
//! Conversion from AST representation of types to the `ty.rs` representation.
23
//! The main routine here is `ast_ty_to_ty()`; each use is parameterized by an
34
//! instance of `AstConv`.
@@ -37,6 +38,7 @@ use std::collections::BTreeSet;
3738
use std::iter;
3839
use std::slice;
3940

41+
use rustc::mir::interpret::LitToConstInput;
4042
use rustc_error_codes::*;
4143

4244
#[derive(Debug)]
@@ -2699,17 +2701,28 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26992701
let tcx = self.tcx();
27002702
let def_id = tcx.hir().local_def_id(ast_const.hir_id);
27012703

2702-
let mut const_ = ty::Const {
2703-
val: ty::ConstKind::Unevaluated(
2704-
def_id,
2705-
InternalSubsts::identity_for_item(tcx, def_id),
2706-
None,
2707-
),
2708-
ty,
2704+
let expr = &tcx.hir().body(ast_const.body).value;
2705+
2706+
let lit_input = match expr.kind {
2707+
hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
2708+
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => match expr.kind {
2709+
hir::ExprKind::Lit(ref lit) => {
2710+
Some(LitToConstInput { lit: &lit.node, ty, neg: true })
2711+
}
2712+
_ => None,
2713+
},
2714+
_ => None,
27092715
};
27102716

2711-
let expr = &tcx.hir().body(ast_const.body).value;
2712-
if let Some(def_id) = self.const_param_def_id(expr) {
2717+
if let Some(lit_input) = lit_input {
2718+
// If an error occurred, ignore that it's a literal and leave reporting the error up to
2719+
// mir
2720+
if let Ok(c) = tcx.at(expr.span).lit_to_const(lit_input) {
2721+
return c;
2722+
}
2723+
}
2724+
2725+
let kind = if let Some(def_id) = self.const_param_def_id(expr) {
27132726
// Find the name and index of the const parameter by indexing the generics of the
27142727
// parent item and construct a `ParamConst`.
27152728
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
@@ -2718,10 +2731,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27182731
let generics = tcx.generics_of(item_def_id);
27192732
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(hir_id)];
27202733
let name = tcx.hir().name(hir_id);
2721-
const_.val = ty::ConstKind::Param(ty::ParamConst::new(index, name));
2722-
}
2723-
2724-
tcx.mk_const(const_)
2734+
ty::ConstKind::Param(ty::ParamConst::new(index, name))
2735+
} else {
2736+
ty::ConstKind::Unevaluated(def_id, InternalSubsts::identity_for_item(tcx, def_id), None)
2737+
};
2738+
tcx.mk_const(ty::Const { val: kind, ty })
27252739
}
27262740

27272741
pub fn impl_trait_ty_to_ty(

‎src/libsyntax/ast.rs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,8 +1441,17 @@ pub struct MacroDef {
14411441
pub legacy: bool,
14421442
}
14431443

1444-
// Clippy uses Hash and PartialEq
1445-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, PartialEq, HashStable_Generic)]
1444+
#[derive(
1445+
Clone,
1446+
RustcEncodable,
1447+
RustcDecodable,
1448+
Debug,
1449+
Copy,
1450+
Hash,
1451+
Eq,
1452+
PartialEq,
1453+
HashStable_Generic
1454+
)]
14461455
pub enum StrStyle {
14471456
/// A regular string, like `"foo"`.
14481457
Cooked,
@@ -1491,9 +1500,18 @@ impl StrLit {
14911500
}
14921501
}
14931502

1494-
// Clippy uses Hash and PartialEq
14951503
/// Type of the integer literal based on provided suffix.
1496-
#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)]
1504+
#[derive(
1505+
Clone,
1506+
Copy,
1507+
RustcEncodable,
1508+
RustcDecodable,
1509+
Debug,
1510+
Hash,
1511+
Eq,
1512+
PartialEq,
1513+
HashStable_Generic
1514+
)]
14971515
pub enum LitIntType {
14981516
/// e.g. `42_i32`.
14991517
Signed(IntTy),
@@ -1504,7 +1522,17 @@ pub enum LitIntType {
15041522
}
15051523

15061524
/// Type of the float literal based on provided suffix.
1507-
#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)]
1525+
#[derive(
1526+
Clone,
1527+
Copy,
1528+
RustcEncodable,
1529+
RustcDecodable,
1530+
Debug,
1531+
Hash,
1532+
Eq,
1533+
PartialEq,
1534+
HashStable_Generic
1535+
)]
15081536
pub enum LitFloatType {
15091537
/// A float literal with a suffix (`1f32` or `1E10f32`).
15101538
Suffixed(FloatTy),
@@ -1515,8 +1543,7 @@ pub enum LitFloatType {
15151543
/// Literal kind.
15161544
///
15171545
/// E.g., `"foo"`, `42`, `12.34`, or `bool`.
1518-
// Clippy uses Hash and PartialEq
1519-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Hash, PartialEq, HashStable_Generic)]
1546+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Hash, Eq, PartialEq, HashStable_Generic)]
15201547
pub enum LitKind {
15211548
/// A string literal (`"foo"`).
15221549
Str(Symbol, StrStyle),

‎src/test/ui/consts/const-eval/ub-nonnull.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | / const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
1313
LL | | let ptr: &[u8; 256] = mem::transmute(&0u8); // &0 gets promoted so it does not dangle
1414
LL | | // Use address-of-element for pointer arithmetic. This could wrap around to NULL!
1515
LL | | let out_of_bounds_ptr = &ptr[255];
16-
| | ^^^^^^^^^ Memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of allocation 9 which has size 1
16+
| | ^^^^^^^^^ Memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of allocation 8 which has size 1
1717
LL | | mem::transmute(out_of_bounds_ptr)
1818
LL | | } };
1919
| |____-

‎src/test/ui/did_you_mean/bad-assoc-ty.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ error[E0223]: ambiguous associated type
5959
--> $DIR/bad-assoc-ty.rs:1:10
6060
|
6161
LL | type A = [u8; 4]::AssocTy;
62-
| ^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<[u8; _] as Trait>::AssocTy`
62+
| ^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<[u8; 4] as Trait>::AssocTy`
6363

6464
error[E0223]: ambiguous associated type
6565
--> $DIR/bad-assoc-ty.rs:5:10

‎src/test/ui/symbol-names/impl1.legacy.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,25 @@ error: def-path(bar::<impl foo::Foo>::baz)
4646
LL | #[rustc_def_path]
4747
| ^^^^^^^^^^^^^^^^^
4848

49-
error: symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17hf07584432cd4d8beE)
49+
error: symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$3$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17h62e540f14f879d56E)
5050
--> $DIR/impl1.rs:62:13
5151
|
5252
LL | #[rustc_symbol_name]
5353
| ^^^^^^^^^^^^^^^^^^^^
5454

55-
error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method::hf07584432cd4d8be)
55+
error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; 3] as impl1::main::{{closure}}::Bar>::method::h62e540f14f879d56)
5656
--> $DIR/impl1.rs:62:13
5757
|
5858
LL | #[rustc_symbol_name]
5959
| ^^^^^^^^^^^^^^^^^^^^
6060

61-
error: demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method)
61+
error: demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; 3] as impl1::main::{{closure}}::Bar>::method)
6262
--> $DIR/impl1.rs:62:13
6363
|
6464
LL | #[rustc_symbol_name]
6565
| ^^^^^^^^^^^^^^^^^^^^
6666

67-
error: def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method)
67+
error: def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; 3] as main::{{closure}}#1::Bar>::method)
6868
--> $DIR/impl1.rs:69:13
6969
|
7070
LL | #[rustc_def_path]

‎src/test/ui/symbol-names/impl1.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ fn main() {
6060
// Test type mangling, by putting them in an `impl` header.
6161
impl Bar for [&'_ (dyn Foo<Assoc = extern fn(&u8, ...)> + AutoTrait); 3] {
6262
#[rustc_symbol_name]
63-
//[legacy]~^ ERROR symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method
64-
//[legacy]~| ERROR demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method
65-
//[legacy]~| ERROR demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method)
63+
//[legacy]~^ ERROR symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$3$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method
64+
//[legacy]~| ERROR demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; 3] as impl1::main::{{closure}}::Bar>::method
65+
//[legacy]~| ERROR demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; 3] as impl1::main::{{closure}}::Bar>::method)
6666
//[v0]~^^^^ ERROR symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG_KCRL0_hvEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method)
6767
//[v0]~| ERROR demangling(<[&dyn impl1[317d481089b8c8fe]::Foo<Assoc = for<'a> extern "C" fn(&'a u8, ...)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method)
6868
//[v0]~| ERROR demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a> extern "C" fn(&'a u8, ...)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method)
6969
#[rustc_def_path]
70-
//[legacy]~^ ERROR def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method)
71-
//[v0]~^^ ERROR def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method)
70+
//[legacy]~^ ERROR def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; 3] as main::{{closure}}#1::Bar>::method)
71+
//[v0]~^^ ERROR def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; 3] as main::{{closure}}#1::Bar>::method)
7272
fn method(&self) {}
7373
}
7474
};

‎src/test/ui/symbol-names/impl1.v0.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ error: demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a> extern "C" fn(&'a u8, ..
6464
LL | #[rustc_symbol_name]
6565
| ^^^^^^^^^^^^^^^^^^^^
6666

67-
error: def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method)
67+
error: def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; 3] as main::{{closure}}#1::Bar>::method)
6868
--> $DIR/impl1.rs:69:13
6969
|
7070
LL | #[rustc_def_path]

0 commit comments

Comments
 (0)
Please sign in to comment.