Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5ddf866

Browse files
committed
Auto merge of rust-lang#3077 - rust-lang:rustup-2023-09-23, r=saethlin
Automatic sync from rustc
2 parents a0defe0 + 3ca49cf commit 5ddf866

File tree

312 files changed

+1931
-880
lines changed

Some content is hidden

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

312 files changed

+1931
-880
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
}

0 commit comments

Comments
 (0)