Skip to content

Commit 4800aa5

Browse files
committed
Merge branch 'master' of https://github.com/gabrielBusta/rust into port_trait_selection_diagnostics
2 parents d32aa33 + 4a24f08 commit 4800aa5

File tree

303 files changed

+5028
-2733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

303 files changed

+5028
-2733
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4321,6 +4321,7 @@ dependencies = [
43214321
"rustc_ast",
43224322
"rustc_errors",
43234323
"rustc_lint",
4324+
"rustc_macros",
43244325
"rustc_metadata",
43254326
"rustc_session",
43264327
"rustc_span",
@@ -4992,9 +4993,9 @@ checksum = "da73c8f77aebc0e40c300b93f0a5f1bece7a248a36eee287d4e095f35c7b7d6e"
49924993

49934994
[[package]]
49944995
name = "snapbox"
4995-
version = "0.2.9"
4996+
version = "0.3.3"
49964997
source = "registry+https://github.com/rust-lang/crates.io-index"
4997-
checksum = "c1f212b806d6f56d19838e36a0aaa7e79a0bc9ca177e873fb87651ad92f983e2"
4998+
checksum = "44d199ccf8f606592df2d145db26f2aa45344e23c64b074cc5a4047f1d99b0f7"
49984999
dependencies = [
49995000
"concolor",
50005001
"content_inspector",
@@ -5010,9 +5011,9 @@ dependencies = [
50105011

50115012
[[package]]
50125013
name = "snapbox-macros"
5013-
version = "0.2.1"
5014+
version = "0.3.0"
50145015
source = "registry+https://github.com/rust-lang/crates.io-index"
5015-
checksum = "c01dea7e04cbb27ef4c86e9922184608185f7cd95c1763bc30d727cda4a5e930"
5016+
checksum = "8a253e6f894cfa440cba00600a249fa90869d8e0ec45ab274a456e043a0ce8f2"
50165017

50175018
[[package]]
50185019
name = "socket2"
@@ -5295,7 +5296,6 @@ name = "tidy"
52955296
version = "0.1.0"
52965297
dependencies = [
52975298
"cargo_metadata 0.14.0",
5298-
"crossbeam-utils",
52995299
"lazy_static",
53005300
"regex",
53015301
"walkdir",

compiler/rustc_ast/src/ast.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,8 @@ pub enum LitFloatType {
17511751
/// E.g., `"foo"`, `42`, `12.34`, or `bool`.
17521752
#[derive(Clone, Encodable, Decodable, Debug, Hash, Eq, PartialEq, HashStable_Generic)]
17531753
pub enum LitKind {
1754-
/// A string literal (`"foo"`).
1754+
/// A string literal (`"foo"`). The symbol is unescaped, and so may differ
1755+
/// from the original token's symbol.
17551756
Str(Symbol, StrStyle),
17561757
/// A byte string (`b"foo"`).
17571758
ByteStr(Lrc<[u8]>),
@@ -1761,12 +1762,13 @@ pub enum LitKind {
17611762
Char(char),
17621763
/// An integer literal (`1`).
17631764
Int(u128, LitIntType),
1764-
/// A float literal (`1f64` or `1E10f64`).
1765+
/// A float literal (`1f64` or `1E10f64`). Stored as a symbol rather than
1766+
/// `f64` so that `LitKind` can impl `Eq` and `Hash`.
17651767
Float(Symbol, LitFloatType),
17661768
/// A boolean literal.
17671769
Bool(bool),
17681770
/// Placeholder for a literal that wasn't well-formed in some way.
1769-
Err(Symbol),
1771+
Err,
17701772
}
17711773

17721774
impl LitKind {
@@ -1805,7 +1807,7 @@ impl LitKind {
18051807
| LitKind::Int(_, LitIntType::Unsuffixed)
18061808
| LitKind::Float(_, LitFloatType::Unsuffixed)
18071809
| LitKind::Bool(..)
1808-
| LitKind::Err(..) => false,
1810+
| LitKind::Err => false,
18091811
}
18101812
}
18111813
}

compiler/rustc_ast/src/token.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,30 @@ impl Token {
436436
|| self == &OpenDelim(Delimiter::Parenthesis)
437437
}
438438

439+
/// Returns `true` if the token can appear at the start of an item.
440+
pub fn can_begin_item(&self) -> bool {
441+
match self.kind {
442+
Ident(name, _) => [
443+
kw::Fn,
444+
kw::Use,
445+
kw::Struct,
446+
kw::Enum,
447+
kw::Pub,
448+
kw::Trait,
449+
kw::Extern,
450+
kw::Impl,
451+
kw::Unsafe,
452+
kw::Static,
453+
kw::Union,
454+
kw::Macro,
455+
kw::Mod,
456+
kw::Type,
457+
]
458+
.contains(&name),
459+
_ => false,
460+
}
461+
}
462+
439463
/// Returns `true` if the token is any literal.
440464
pub fn is_lit(&self) -> bool {
441465
matches!(self.kind, Literal(..))

compiler/rustc_ast/src/util/literal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl LitKind {
146146

147147
LitKind::ByteStr(bytes.into())
148148
}
149-
token::Err => LitKind::Err(symbol),
149+
token::Err => LitKind::Err,
150150
})
151151
}
152152

@@ -199,7 +199,7 @@ impl LitKind {
199199
let symbol = if value { kw::True } else { kw::False };
200200
(token::Bool, symbol, None)
201201
}
202-
LitKind::Err(symbol) => (token::Err, symbol, None),
202+
LitKind::Err => unreachable!(),
203203
};
204204

205205
token::Lit::new(kind, symbol, suffix)

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
928928
} else {
929929
Lit {
930930
token_lit: token::Lit::new(token::LitKind::Err, kw::Empty, None),
931-
kind: LitKind::Err(kw::Empty),
931+
kind: LitKind::Err,
932932
span: DUMMY_SP,
933933
}
934934
};

compiler/rustc_builtin_macros/src/concat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn expand_concat(
3939
ast::LitKind::Byte(..) | ast::LitKind::ByteStr(..) => {
4040
cx.span_err(e.span, "cannot concatenate a byte string literal");
4141
}
42-
ast::LitKind::Err(_) => {
42+
ast::LitKind::Err => {
4343
has_errors = true;
4444
}
4545
},

compiler/rustc_builtin_macros/src/concat_bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn invalid_type_err(cx: &mut base::ExtCtxt<'_>, expr: &P<rustc_ast::Expr>, is_ne
4242
ast::LitKind::Bool(_) => {
4343
cx.span_err(expr.span, "cannot concatenate boolean literals");
4444
}
45-
ast::LitKind::Err(_) => {}
45+
ast::LitKind::Err => {}
4646
ast::LitKind::Int(_, _) if !is_nested => {
4747
let mut err = cx.struct_span_err(expr.span, "cannot concatenate numeric literals");
4848
if let Ok(snippet) = cx.sess.source_map().span_to_snippet(expr.span) {

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ impl<'a, 'b> Context<'a, 'b> {
413413
/// Verifies one piece of a parse string, and remembers it if valid.
414414
/// All errors are not emitted as fatal so we can continue giving errors
415415
/// about this and possibly other format strings.
416-
fn verify_piece(&mut self, p: &parse::Piece<'_>) {
416+
fn verify_piece(&mut self, p: &parse::Piece<'a>) {
417417
match *p {
418418
parse::String(..) => {}
419419
parse::NextArgument(ref arg) => {
@@ -433,6 +433,11 @@ impl<'a, 'b> Context<'a, 'b> {
433433
let has_precision = arg.format.precision != Count::CountImplied;
434434
let has_width = arg.format.width != Count::CountImplied;
435435

436+
if has_precision || has_width {
437+
// push before named params are resolved to aid diagnostics
438+
self.arg_with_formatting.push(arg.format);
439+
}
440+
436441
// argument second, if it's an implicit positional parameter
437442
// it's written second, so it should come after width/precision.
438443
let pos = match arg.position {
@@ -581,7 +586,11 @@ impl<'a, 'b> Context<'a, 'b> {
581586
let mut zero_based_note = false;
582587

583588
let count = self.pieces.len()
584-
+ self.arg_with_formatting.iter().filter(|fmt| fmt.precision_span.is_some()).count();
589+
+ self
590+
.arg_with_formatting
591+
.iter()
592+
.filter(|fmt| matches!(fmt.precision, parse::CountIsParam(_)))
593+
.count();
585594
if self.names.is_empty() && !numbered_position_args && count != self.num_args() {
586595
e = self.ecx.struct_span_err(
587596
sp,
@@ -647,7 +656,7 @@ impl<'a, 'b> Context<'a, 'b> {
647656
+ self
648657
.arg_with_formatting
649658
.iter()
650-
.filter(|fmt| fmt.precision_span.is_some())
659+
.filter(|fmt| matches!(fmt.precision, parse::CountIsParam(_)))
651660
.count();
652661
e.span_label(
653662
span,
@@ -899,26 +908,22 @@ impl<'a, 'b> Context<'a, 'b> {
899908
},
900909
position_span: arg.position_span,
901910
format: parse::FormatSpec {
902-
fill: arg.format.fill,
911+
fill: None,
903912
align: parse::AlignUnknown,
904913
flags: 0,
905914
precision: parse::CountImplied,
906-
precision_span: None,
915+
precision_span: arg.format.precision_span,
907916
width: parse::CountImplied,
908-
width_span: None,
917+
width_span: arg.format.width_span,
909918
ty: arg.format.ty,
910919
ty_span: arg.format.ty_span,
911920
},
912921
};
913922

914923
let fill = arg.format.fill.unwrap_or(' ');
915-
916924
let pos_simple = arg.position.index() == simple_arg.position.index();
917925

918-
if arg.format.precision_span.is_some() || arg.format.width_span.is_some() {
919-
self.arg_with_formatting.push(arg.format);
920-
}
921-
if !pos_simple || arg.format != simple_arg.format || fill != ' ' {
926+
if !pos_simple || arg.format != simple_arg.format {
922927
self.all_pieces_simple = false;
923928
}
924929

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -798,58 +798,55 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
798798
let mut op = self.codegen_operand(&mut bx, arg);
799799

800800
if let (0, Some(ty::InstanceDef::Virtual(_, idx))) = (i, def) {
801-
if let Pair(..) = op.val {
802-
// In the case of Rc<Self>, we need to explicitly pass a
803-
// *mut RcBox<Self> with a Scalar (not ScalarPair) ABI. This is a hack
804-
// that is understood elsewhere in the compiler as a method on
805-
// `dyn Trait`.
806-
// To get a `*mut RcBox<Self>`, we just keep unwrapping newtypes until
807-
// we get a value of a built-in pointer type
808-
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
809-
&& !op.layout.ty.is_region_ptr()
810-
{
811-
for i in 0..op.layout.fields.count() {
812-
let field = op.extract_field(&mut bx, i);
813-
if !field.layout.is_zst() {
814-
// we found the one non-zero-sized field that is allowed
815-
// now find *its* non-zero-sized field, or stop if it's a
816-
// pointer
817-
op = field;
818-
continue 'descend_newtypes;
801+
match op.val {
802+
Pair(data_ptr, meta) => {
803+
// In the case of Rc<Self>, we need to explicitly pass a
804+
// *mut RcBox<Self> with a Scalar (not ScalarPair) ABI. This is a hack
805+
// that is understood elsewhere in the compiler as a method on
806+
// `dyn Trait`.
807+
// To get a `*mut RcBox<Self>`, we just keep unwrapping newtypes until
808+
// we get a value of a built-in pointer type
809+
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
810+
&& !op.layout.ty.is_region_ptr()
811+
{
812+
for i in 0..op.layout.fields.count() {
813+
let field = op.extract_field(&mut bx, i);
814+
if !field.layout.is_zst() {
815+
// we found the one non-zero-sized field that is allowed
816+
// now find *its* non-zero-sized field, or stop if it's a
817+
// pointer
818+
op = field;
819+
continue 'descend_newtypes;
820+
}
819821
}
822+
823+
span_bug!(span, "receiver has no non-zero-sized fields {:?}", op);
820824
}
821825

822-
span_bug!(span, "receiver has no non-zero-sized fields {:?}", op);
826+
// now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
827+
// data pointer and vtable. Look up the method in the vtable, and pass
828+
// the data pointer as the first argument
829+
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
830+
&mut bx,
831+
meta,
832+
op.layout.ty,
833+
&fn_abi,
834+
));
835+
llargs.push(data_ptr);
836+
continue 'make_args;
823837
}
824-
825-
// now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
826-
// data pointer and vtable. Look up the method in the vtable, and pass
827-
// the data pointer as the first argument
828-
match op.val {
829-
Pair(data_ptr, meta) => {
830-
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
831-
&mut bx,
832-
meta,
833-
op.layout.ty,
834-
&fn_abi,
835-
));
836-
llargs.push(data_ptr);
837-
continue 'make_args;
838-
}
839-
other => bug!("expected a Pair, got {:?}", other),
838+
Ref(data_ptr, Some(meta), _) => {
839+
// by-value dynamic dispatch
840+
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
841+
&mut bx,
842+
meta,
843+
op.layout.ty,
844+
&fn_abi,
845+
));
846+
llargs.push(data_ptr);
847+
continue;
840848
}
841-
} else if let Ref(data_ptr, Some(meta), _) = op.val {
842-
// by-value dynamic dispatch
843-
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
844-
&mut bx,
845-
meta,
846-
op.layout.ty,
847-
&fn_abi,
848-
));
849-
llargs.push(data_ptr);
850-
continue;
851-
} else {
852-
span_bug!(span, "can't codegen a virtual call on {:?}", op);
849+
_ => span_bug!(span, "can't codegen a virtual call on {:?}", op),
853850
}
854851
}
855852

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
8181
}
8282

8383
/// The `InterpCx` is only meant to be used to do field and index projections into constants for
84-
/// `simd_shuffle` and const patterns in match arms.
84+
/// `simd_shuffle` and const patterns in match arms. It never performs alignment checks.
8585
///
8686
/// The function containing the `match` that is currently being analyzed may have generic bounds
8787
/// that inform us about the generic bounds of the constant. E.g., using an associated constant
@@ -98,7 +98,11 @@ pub(super) fn mk_eval_cx<'mir, 'tcx>(
9898
tcx,
9999
root_span,
100100
param_env,
101-
CompileTimeInterpreter::new(tcx.const_eval_limit(), can_access_statics),
101+
CompileTimeInterpreter::new(
102+
tcx.const_eval_limit(),
103+
can_access_statics,
104+
/*check_alignment:*/ false,
105+
),
102106
)
103107
}
104108

@@ -203,7 +207,13 @@ pub(crate) fn turn_into_const_value<'tcx>(
203207
let cid = key.value;
204208
let def_id = cid.instance.def.def_id();
205209
let is_static = tcx.is_static(def_id);
206-
let ecx = mk_eval_cx(tcx, tcx.def_span(key.value.instance.def_id()), key.param_env, is_static);
210+
// This is just accessing an already computed constant, so no need to check alginment here.
211+
let ecx = mk_eval_cx(
212+
tcx,
213+
tcx.def_span(key.value.instance.def_id()),
214+
key.param_env,
215+
/*can_access_statics:*/ is_static,
216+
);
207217

208218
let mplace = ecx.raw_const_to_mplace(constant).expect(
209219
"can only fail if layout computation failed, \
@@ -300,7 +310,11 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
300310
key.param_env,
301311
// Statics (and promoteds inside statics) may access other statics, because unlike consts
302312
// they do not have to behave "as if" they were evaluated at runtime.
303-
CompileTimeInterpreter::new(tcx.const_eval_limit(), /*can_access_statics:*/ is_static),
313+
CompileTimeInterpreter::new(
314+
tcx.const_eval_limit(),
315+
/*can_access_statics:*/ is_static,
316+
/*check_alignment:*/ tcx.sess.opts.unstable_opts.extra_const_ub_checks,
317+
),
304318
);
305319

306320
let res = ecx.load_mir(cid.instance.def, cid.promoted);

0 commit comments

Comments
 (0)