Skip to content

Commit 3ca49cf

Browse files
author
The Miri Conjob Bot
committed
Merge from rustc
2 parents 6870634 + 79d6853 commit 3ca49cf

File tree

311 files changed

+1930
-879
lines changed

Some content is hidden

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

311 files changed

+1930
-879
lines changed

compiler/rustc_error_codes/src/error_codes/E0647.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Erroneous code example:
77
88
#[start]
99
fn start(_: isize, _: *const *const u8) -> isize where (): Copy {
10-
//^ error: start function is not allowed to have a where clause
10+
//^ error: `#[start]` function is not allowed to have a where clause
1111
0
1212
}
1313
```

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ impl fmt::Display for DiagnosticLocation {
151151
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
152152
pub enum DiagnosticId {
153153
Error(String),
154-
Lint { name: String, has_future_breakage: bool, is_force_warn: bool },
154+
Lint {
155+
name: String,
156+
/// Indicates whether this lint should show up in cargo's future breakage report.
157+
has_future_breakage: bool,
158+
is_force_warn: bool,
159+
},
155160
}
156161

157162
/// A "sub"-diagnostic attached to a parent diagnostic.
@@ -301,6 +306,7 @@ impl Diagnostic {
301306
}
302307
}
303308

309+
/// Indicates whether this diagnostic should show up in cargo's future breakage report.
304310
pub fn has_future_breakage(&self) -> bool {
305311
match self.code {
306312
Some(DiagnosticId::Lint { has_future_breakage, .. }) => has_future_breakage,

compiler/rustc_errors/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ pub struct HandlerFlags {
519519
/// If false, warning-level lints are suppressed.
520520
/// (rustc: see `--allow warnings` and `--cap-lints`)
521521
pub can_emit_warnings: bool,
522-
/// If true, error-level diagnostics are upgraded to bug-level.
522+
/// If Some, the Nth error-level diagnostic is upgraded to bug-level.
523523
/// (rustc: see `-Z treat-err-as-bug`)
524524
pub treat_err_as_bug: Option<NonZeroUsize>,
525525
/// If true, immediately emit diagnostics that would otherwise be buffered.
@@ -1719,19 +1719,17 @@ impl HandlerInner {
17191719
match (
17201720
self.err_count() + self.lint_err_count,
17211721
self.delayed_bug_count(),
1722-
self.flags.treat_err_as_bug.map(|c| c.get()).unwrap_or(0),
1722+
self.flags.treat_err_as_bug.map(|c| c.get()).unwrap(),
17231723
) {
17241724
(1, 0, 1) => panic!("aborting due to `-Z treat-err-as-bug=1`"),
17251725
(0, 1, 1) => panic!("aborting due delayed bug with `-Z treat-err-as-bug=1`"),
1726-
(count, delayed_count, as_bug) => {
1726+
(count, delayed_count, val) => {
17271727
if delayed_count > 0 {
17281728
panic!(
1729-
"aborting after {count} errors and {delayed_count} delayed bugs due to `-Z treat-err-as-bug={as_bug}`",
1729+
"aborting after {count} errors and {delayed_count} delayed bugs due to `-Z treat-err-as-bug={val}`",
17301730
)
17311731
} else {
1732-
panic!(
1733-
"aborting after {count} errors due to `-Z treat-err-as-bug={as_bug}`",
1734-
)
1732+
panic!("aborting after {count} errors due to `-Z treat-err-as-bug={val}`")
17351733
}
17361734
}
17371735
}

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,20 @@ hir_analysis_simd_ffi_highly_experimental = use of SIMD type{$snip} in FFI is hi
270270
hir_analysis_specialization_trait = implementing `rustc_specialization_trait` traits is unstable
271271
.help = add `#![feature(min_specialization)]` to the crate attributes to enable
272272
273-
hir_analysis_start_function_parameters = start function is not allowed to have type parameters
274-
.label = start function cannot have type parameters
273+
hir_analysis_start_function_parameters = `#[start]` function is not allowed to have type parameters
274+
.label = `#[start]` function cannot have type parameters
275275
276-
hir_analysis_start_function_where = start function is not allowed to have a `where` clause
277-
.label = start function cannot have a `where` clause
276+
hir_analysis_start_function_where = `#[start]` function is not allowed to have a `where` clause
277+
.label = `#[start]` function cannot have a `where` clause
278278
279-
hir_analysis_start_not_async = `start` is not allowed to be `async`
280-
.label = `start` is not allowed to be `async`
279+
hir_analysis_start_not_async = `#[start]` function is not allowed to be `async`
280+
.label = `#[start]` is not allowed to be `async`
281281
282-
hir_analysis_start_not_target_feature = `start` is not allowed to have `#[target_feature]`
283-
.label = `start` is not allowed to have `#[target_feature]`
282+
hir_analysis_start_not_target_feature = `#[start]` function is not allowed to have `#[target_feature]`
283+
.label = `#[start]` function is not allowed to have `#[target_feature]`
284284
285-
hir_analysis_start_not_track_caller = `start` is not allowed to be `#[track_caller]`
286-
.label = `start` is not allowed to be `#[track_caller]`
285+
hir_analysis_start_not_track_caller = `#[start]` function is not allowed to be `#[track_caller]`
286+
.label = `#[start]` function is not allowed to be `#[track_caller]`
287287
288288
hir_analysis_static_specialize = cannot specialize on `'static` lifetime
289289

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_infer::traits::{Obligation, TraitEngineExt as _};
1818
use rustc_lint_defs::builtin::REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS;
1919
use rustc_middle::hir::nested_filter;
2020
use rustc_middle::middle::stability::EvalResult;
21-
use rustc_middle::traits::DefiningAnchor;
21+
use rustc_middle::traits::{DefiningAnchor, ObligationCauseCode};
2222
use rustc_middle::ty::fold::BottomUpFolder;
2323
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
2424
use rustc_middle::ty::util::{Discr, IntTypeExt};
@@ -1626,6 +1626,25 @@ pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
16261626
let obligation = Obligation::new(tcx, cause.clone(), param_env, *predicate);
16271627
fulfillment_cx.register_predicate_obligation(&infcx, obligation);
16281628
}
1629+
1630+
if (tcx.features().unsized_locals || tcx.features().unsized_fn_params)
1631+
&& let Some(generator) = tcx.mir_generator_witnesses(def_id)
1632+
{
1633+
for field_ty in generator.field_tys.iter() {
1634+
fulfillment_cx.register_bound(
1635+
&infcx,
1636+
param_env,
1637+
field_ty.ty,
1638+
tcx.require_lang_item(hir::LangItem::Sized, Some(field_ty.source_info.span)),
1639+
ObligationCause::new(
1640+
field_ty.source_info.span,
1641+
def_id,
1642+
ObligationCauseCode::SizedGeneratorInterior(def_id),
1643+
),
1644+
);
1645+
}
1646+
}
1647+
16291648
let errors = fulfillment_cx.select_all_or_error(&infcx);
16301649
debug!(?errors);
16311650
if !errors.is_empty() {

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_errors::StashKey;
22
use rustc_hir::def_id::LocalDefId;
33
use rustc_hir::intravisit::{self, Visitor};
4-
use rustc_hir::{self as hir, Expr, ImplItem, Item, Node, TraitItem};
4+
use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem};
55
use rustc_middle::hir::nested_filter;
66
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
77
use rustc_span::DUMMY_SP;
@@ -74,9 +74,14 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
7474

7575
hidden.ty
7676
} else {
77+
let mut parent_def_id = def_id;
78+
while tcx.def_kind(parent_def_id) == def::DefKind::OpaqueTy {
79+
// Account for `type Alias = impl Trait<Foo = impl Trait>;` (#116031)
80+
parent_def_id = tcx.local_parent(parent_def_id);
81+
}
7782
let reported = tcx.sess.emit_err(UnconstrainedOpaqueType {
7883
span: tcx.def_span(def_id),
79-
name: tcx.item_name(tcx.local_parent(def_id).to_def_id()),
84+
name: tcx.item_name(parent_def_id.to_def_id()),
8085
what: match tcx.hir().get(scope) {
8186
_ if scope == hir::CRATE_HIR_ID => "module",
8287
Node::Item(hir::Item { kind: hir::ItemKind::Mod(_), .. }) => "module",

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,9 @@ impl<'a, 'tcx> CastCheck<'tcx> {
725725
},
726726
// array-ptr-cast
727727
Ptr(mt) => {
728+
if !fcx.type_is_sized_modulo_regions(fcx.param_env, mt.ty) {
729+
return Err(CastError::IllegalCast);
730+
}
728731
self.check_ref_cast(fcx, TypeAndMut { mutbl, ty: inner_ty }, mt)
729732
}
730733
_ => Err(CastError::NonScalar),
@@ -735,15 +738,13 @@ impl<'a, 'tcx> CastCheck<'tcx> {
735738
}
736739
_ => return Err(CastError::NonScalar),
737740
};
738-
739741
if let ty::Adt(adt_def, _) = *self.expr_ty.kind() {
740742
if adt_def.did().krate != LOCAL_CRATE {
741743
if adt_def.variants().iter().any(VariantDef::is_field_list_non_exhaustive) {
742744
return Err(CastError::ForeignNonExhaustiveAdt);
743745
}
744746
}
745747
}
746-
747748
match (t_from, t_cast) {
748749
// These types have invariants! can't cast into them.
749750
(_, Int(CEnum) | FnPtr) => Err(CastError::NonScalar),

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
525525
_ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0,
526526
};
527527

528-
if let ty::FnDef(did, ..) = *ty.kind() {
528+
if let ty::FnDef(did, callee_args) = *ty.kind() {
529529
let fn_sig = ty.fn_sig(tcx);
530+
531+
// HACK: whenever we get a FnDef in a non-const context, enforce effects to get the
532+
// default `host = true` to avoid inference errors later.
533+
if tcx.hir().body_const_context(self.body_id).is_none() {
534+
self.enforce_context_effects(expr.hir_id, qpath.span(), did, callee_args);
535+
}
530536
if tcx.fn_sig(did).skip_binder().abi() == RustIntrinsic
531537
&& tcx.item_name(did) == sym::transmute
532538
{

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,10 +664,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
664664
);
665665
self.walk_pat(discr_place, arm.pat, arm.guard.is_some());
666666

667-
if let Some(hir::Guard::If(e)) = arm.guard {
668-
self.consume_expr(e)
669-
} else if let Some(hir::Guard::IfLet(ref l)) = arm.guard {
670-
self.consume_expr(l.init)
667+
match arm.guard {
668+
Some(hir::Guard::If(ref e)) => self.consume_expr(e),
669+
Some(hir::Guard::IfLet(ref l)) => {
670+
self.walk_local(l.init, l.pat, None, |t| t.borrow_expr(l.init, ty::ImmBorrow))
671+
}
672+
None => {}
671673
}
672674

673675
self.consume_expr(arm.body);

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
518518
self.select_obligations_where_possible(|_| {});
519519

520520
let mut generators = self.deferred_generator_interiors.borrow_mut();
521-
for (_, body_id, interior, kind) in generators.drain(..) {
522-
crate::generator_interior::resolve_interior(self, def_id, body_id, interior, kind);
521+
for (generator_def_id, body_id, interior, kind) in generators.drain(..) {
522+
crate::generator_interior::resolve_interior(
523+
self,
524+
def_id,
525+
generator_def_id,
526+
body_id,
527+
interior,
528+
kind,
529+
);
523530
self.select_obligations_where_possible(|_| {});
524531
}
525532
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
273273
//
274274
// This check is here because there is currently no way to express a trait bound for `FnDef` types only.
275275
if is_const_eval_select && (1..=2).contains(&idx) {
276-
if let ty::FnDef(def_id, _) = checked_ty.kind() {
277-
if idx == 1 && !self.tcx.is_const_fn_raw(*def_id) {
278-
self.tcx
279-
.sess
280-
.emit_err(errors::ConstSelectMustBeConst { span: provided_arg.span });
276+
if let ty::FnDef(def_id, args) = *checked_ty.kind() {
277+
if idx == 1 {
278+
if !self.tcx.is_const_fn_raw(def_id) {
279+
self.tcx.sess.emit_err(errors::ConstSelectMustBeConst {
280+
span: provided_arg.span,
281+
});
282+
} else {
283+
self.enforce_context_effects(
284+
provided_arg.hir_id,
285+
provided_arg.span,
286+
def_id,
287+
args,
288+
)
289+
}
281290
}
282291
} else {
283292
self.tcx.sess.emit_err(errors::ConstSelectMustBeFn {

compiler/rustc_hir_typeck/src/generator_interior/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
99
use rustc_errors::{pluralize, DelayDm};
1010
use rustc_hir as hir;
1111
use rustc_hir::def::{CtorKind, DefKind, Res};
12-
use rustc_hir::def_id::DefId;
12+
use rustc_hir::def_id::{DefId, LocalDefId};
1313
use rustc_hir::hir_id::HirIdSet;
1414
use rustc_hir::intravisit::{self, Visitor};
1515
use rustc_hir::{Arm, Expr, ExprKind, Guard, HirId, Pat, PatKind};
1616
use rustc_infer::infer::{DefineOpaqueTypes, RegionVariableOrigin};
1717
use rustc_middle::middle::region::{self, Scope, ScopeData, YieldData};
18+
use rustc_middle::traits::ObligationCauseCode;
1819
use rustc_middle::ty::fold::FnMutDelegate;
1920
use rustc_middle::ty::{self, BoundVariableKind, RvalueScopes, Ty, TyCtxt, TypeVisitableExt};
2021
use rustc_span::symbol::sym;
@@ -188,6 +189,7 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
188189
pub fn resolve_interior<'a, 'tcx>(
189190
fcx: &'a FnCtxt<'a, 'tcx>,
190191
def_id: DefId,
192+
generator_def_id: LocalDefId,
191193
body_id: hir::BodyId,
192194
interior: Ty<'tcx>,
193195
kind: hir::GeneratorKind,
@@ -214,6 +216,16 @@ pub fn resolve_interior<'a, 'tcx>(
214216
// The types are already kept in insertion order.
215217
let types = visitor.types;
216218

219+
if fcx.tcx.features().unsized_locals || fcx.tcx.features().unsized_fn_params {
220+
for interior_ty in &types {
221+
fcx.require_type_is_sized(
222+
interior_ty.ty,
223+
interior_ty.span,
224+
ObligationCauseCode::SizedGeneratorInterior(generator_def_id),
225+
);
226+
}
227+
}
228+
217229
// The types in the generator interior contain lifetimes local to the generator itself,
218230
// which should not be exposed outside of the generator. Therefore, we replace these
219231
// lifetimes with existentially-bound lifetimes, which reflect the exact value of the

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use rustc_hir::intravisit::{self, Visitor};
4141
use rustc_infer::infer::UpvarRegion;
4242
use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind};
4343
use rustc_middle::mir::FakeReadCause;
44+
use rustc_middle::traits::ObligationCauseCode;
4445
use rustc_middle::ty::{
4546
self, ClosureSizeProfileData, Ty, TyCtxt, TypeckResults, UpvarArgs, UpvarCapture,
4647
};
@@ -295,6 +296,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
295296
let final_upvar_tys = self.final_upvar_tys(closure_def_id);
296297
debug!(?closure_hir_id, ?args, ?final_upvar_tys);
297298

299+
if self.tcx.features().unsized_locals || self.tcx.features().unsized_fn_params {
300+
for capture in
301+
self.typeck_results.borrow().closure_min_captures_flattened(closure_def_id)
302+
{
303+
if let UpvarCapture::ByValue = capture.info.capture_kind {
304+
self.require_type_is_sized(
305+
capture.place.ty(),
306+
capture.get_path_span(self.tcx),
307+
ObligationCauseCode::SizedClosureCapture(closure_def_id),
308+
);
309+
}
310+
}
311+
}
312+
298313
// Build a tuple (U0..Un) of the final upvar types U0..Un
299314
// and unify the upvar tuple type in the closure with it:
300315
let final_tupled_upvars_type = Ty::new_tup(self.tcx, &final_upvar_tys);

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
16161616
// | expected `()`, found closure
16171617
// |
16181618
// = note: expected unit type `()`
1619-
// found closure `[closure@$DIR/issue-20862.rs:2:5: 2:14 x:_]`
1619+
// found closure `{closure@$DIR/issue-20862.rs:2:5: 2:14 x:_}`
16201620
//
16211621
// Also ignore opaque `Future`s that come from async fns.
16221622
if !self.ignore_span.overlaps(span)

compiler/rustc_lint/src/array_into_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ declare_lint! {
3434
Warn,
3535
"detects calling `into_iter` on arrays in Rust 2015 and 2018",
3636
@future_incompatible = FutureIncompatibleInfo {
37-
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>",
3837
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2021),
38+
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>",
3939
};
4040
}
4141

compiler/rustc_lint/src/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,8 @@ declare_lint! {
844844
Warn,
845845
"detects anonymous parameters",
846846
@future_incompatible = FutureIncompatibleInfo {
847-
reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",
848847
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
848+
reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",
849849
};
850850
}
851851

@@ -1669,8 +1669,8 @@ declare_lint! {
16691669
Warn,
16701670
"`...` range patterns are deprecated",
16711671
@future_incompatible = FutureIncompatibleInfo {
1672-
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>",
16731672
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
1673+
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>",
16741674
};
16751675
}
16761676

@@ -1804,8 +1804,8 @@ declare_lint! {
18041804
Allow,
18051805
"detects edition keywords being used as an identifier",
18061806
@future_incompatible = FutureIncompatibleInfo {
1807-
reference: "issue #49716 <https://github.com/rust-lang/rust/issues/49716>",
18081807
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
1808+
reference: "issue #49716 <https://github.com/rust-lang/rust/issues/49716>",
18091809
};
18101810
}
18111811

compiler/rustc_lint/src/deref_into_dyn_supertrait.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55

66
use rustc_hir as hir;
77
use rustc_middle::{traits::util::supertraits, ty};
8+
use rustc_session::lint::FutureIncompatibilityReason;
89
use rustc_span::sym;
910

1011
declare_lint! {
@@ -48,6 +49,7 @@ declare_lint! {
4849
Warn,
4950
"`Deref` implementation usage with a supertrait trait object for output might be shadowed in the future",
5051
@future_incompatible = FutureIncompatibleInfo {
52+
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
5153
reference: "issue #89460 <https://github.com/rust-lang/rust/issues/89460>",
5254
};
5355
}

0 commit comments

Comments
 (0)