Skip to content

Commit 3e4a15e

Browse files
committed
Auto merge of rust-lang#119156 - matthiaskrgr:rollup-482ow65, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#118691 (Add check for possible CStr literals in pre-2021) - rust-lang#118973 (rustc_codegen_ssa: Don't drop `IncorrectCguReuseType` , make `rustc_expected_cgu_reuse` attr work) - rust-lang#119071 (-Znext-solver: adapt overflow rules to avoid breakage) - rust-lang#119089 (effects: fix a comment) - rust-lang#119094 (Add function ABI and type layout to StableMIR) - rust-lang#119102 (Add arm-none-eabi and armv7r-none-eabi platform-support documentation.) - rust-lang#119107 (subtype_predicate: remove unnecessary probe) Failed merges: - rust-lang#119135 (Fix crash due to `CrateItem::kind()` not handling constructors) - rust-lang#119141 (Add method to get instance instantiation arguments) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3095d31 + d6656af commit 3e4a15e

Some content is hidden

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

47 files changed

+1419
-267
lines changed

Diff for: compiler/rustc_codegen_ssa/src/assert_module_sources.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ impl CguReuseTracker {
278278

279279
if error {
280280
let at_least = if at_least { 1 } else { 0 };
281-
errors::IncorrectCguReuseType {
281+
sess.emit_err(errors::IncorrectCguReuseType {
282282
span: *error_span,
283283
cgu_user_name,
284284
actual_reuse,
285285
expected_reuse,
286286
at_least,
287-
};
287+
});
288288
}
289289
} else {
290290
sess.emit_fatal(errors::CguNotRecorded { cgu_user_name, cgu_name });

Diff for: compiler/rustc_hir_analysis/src/astconv/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub fn create_args_for_parent_generic_args<'tcx, 'a>(
262262
// impl const PartialEq for () {}
263263
// ```
264264
//
265-
// Since this is a const impl, we need to insert `<false>` at the end of
265+
// Since this is a const impl, we need to insert a host arg at the end of
266266
// `PartialEq`'s generics, but this errors since `Rhs` isn't specified.
267267
// To work around this, we infer all arguments until we reach the host param.
268268
args.push(ctx.inferred_kind(Some(&args), param, infer_args));

Diff for: compiler/rustc_infer/src/infer/mod.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
713713
}
714714

715715
impl<'tcx, T> InferOk<'tcx, T> {
716-
pub fn unit(self) -> InferOk<'tcx, ()> {
717-
InferOk { value: (), obligations: self.obligations }
718-
}
719-
720716
/// Extracts `value`, registering any obligations into `fulfill_cx`.
721717
pub fn into_value_registering_obligations(
722718
self,
@@ -1025,15 +1021,10 @@ impl<'tcx> InferCtxt<'tcx> {
10251021
_ => {}
10261022
}
10271023

1028-
Ok(self.commit_if_ok(|_snapshot| {
1029-
let ty::SubtypePredicate { a_is_expected, a, b } =
1030-
self.instantiate_binder_with_placeholders(predicate);
1031-
1032-
let ok =
1033-
self.at(cause, param_env).sub_exp(DefineOpaqueTypes::No, a_is_expected, a, b)?;
1024+
let ty::SubtypePredicate { a_is_expected, a, b } =
1025+
self.instantiate_binder_with_placeholders(predicate);
10341026

1035-
Ok(ok.unit())
1036-
}))
1027+
Ok(self.at(cause, param_env).sub_exp(DefineOpaqueTypes::No, a_is_expected, a, b))
10371028
}
10381029

10391030
pub fn region_outlives_predicate(

Diff for: compiler/rustc_middle/src/traits/solve.rs

+21
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,27 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
233233
}
234234
}
235235

236+
/// Why a specific goal has to be proven.
237+
///
238+
/// This is necessary as we treat nested goals different depending on
239+
/// their source.
240+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
241+
pub enum GoalSource {
242+
Misc,
243+
/// We're proving a where-bound of an impl.
244+
///
245+
/// FIXME(-Znext-solver=coinductive): Explain how and why this
246+
/// changes whether cycles are coinductive.
247+
///
248+
/// This also impacts whether we erase constraints on overflow.
249+
/// Erasing constraints is generally very useful for perf and also
250+
/// results in better error messages by avoiding spurious errors.
251+
/// We do not erase overflow constraints in `normalizes-to` goals unless
252+
/// they are from an impl where-clause. This is necessary due to
253+
/// backwards compatability, cc trait-system-refactor-initiatitive#70.
254+
ImplWhereBound,
255+
}
256+
236257
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable)]
237258
pub enum IsNormalizesToHack {
238259
Yes,

Diff for: compiler/rustc_middle/src/traits/solve/inspect.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
//! [canonicalized]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html
2020
2121
use super::{
22-
CandidateSource, Canonical, CanonicalInput, Certainty, Goal, IsNormalizesToHack, NoSolution,
23-
QueryInput, QueryResult,
22+
CandidateSource, Canonical, CanonicalInput, Certainty, Goal, GoalSource, IsNormalizesToHack,
23+
NoSolution, QueryInput, QueryResult,
2424
};
2525
use crate::{infer::canonical::CanonicalVarValues, ty};
2626
use format::ProofTreeFormatter;
@@ -115,7 +115,7 @@ impl Debug for Probe<'_> {
115115
pub enum ProbeStep<'tcx> {
116116
/// We added a goal to the `EvalCtxt` which will get proven
117117
/// the next time `EvalCtxt::try_evaluate_added_goals` is called.
118-
AddGoal(CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>),
118+
AddGoal(GoalSource, CanonicalState<'tcx, Goal<'tcx, ty::Predicate<'tcx>>>),
119119
/// The inside of a `EvalCtxt::try_evaluate_added_goals` call.
120120
EvaluateGoals(AddedGoalsEvaluation<'tcx>),
121121
/// A call to `probe` while proving the current goal. This is

Diff for: compiler/rustc_middle/src/traits/solve/inspect/format.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
123123
self.nested(|this| {
124124
for step in &probe.steps {
125125
match step {
126-
ProbeStep::AddGoal(goal) => writeln!(this.f, "ADDED GOAL: {goal:?}")?,
126+
ProbeStep::AddGoal(source, goal) => {
127+
let source = match source {
128+
GoalSource::Misc => "misc",
129+
GoalSource::ImplWhereBound => "impl where-bound",
130+
};
131+
writeln!(this.f, "ADDED GOAL ({source}): {goal:?}")?
132+
}
127133
ProbeStep::EvaluateGoals(eval) => this.format_added_goals_evaluation(eval)?,
128134
ProbeStep::NestedProbe(probe) => this.format_probe(probe)?,
129135
ProbeStep::CommitIfOkStart => writeln!(this.f, "COMMIT_IF_OK START")?,

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+29-7
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use crate::errors::{
1010
ConstGenericWithoutBracesSugg, DocCommentDoesNotDocumentAnything, DocCommentOnParamType,
1111
DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg,
1212
GenericParamsWithoutAngleBrackets, GenericParamsWithoutAngleBracketsSugg,
13-
HelpIdentifierStartsWithNumber, InInTypo, IncorrectAwait, IncorrectSemicolon,
14-
IncorrectUseOfAwait, PatternMethodParamWithoutBody, QuestionMarkInType, QuestionMarkInTypeSugg,
15-
SelfParamNotFirst, StructLiteralBodyWithoutPath, StructLiteralBodyWithoutPathSugg,
16-
StructLiteralNeedingParens, StructLiteralNeedingParensSugg, SuggAddMissingLetStmt,
17-
SuggEscapeIdentifier, SuggRemoveComma, TernaryOperator, UnexpectedConstInGenericParam,
18-
UnexpectedConstParamDeclaration, UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets,
19-
UseEqInstead, WrapType,
13+
HelpIdentifierStartsWithNumber, HelpUseLatestEdition, InInTypo, IncorrectAwait,
14+
IncorrectSemicolon, IncorrectUseOfAwait, PatternMethodParamWithoutBody, QuestionMarkInType,
15+
QuestionMarkInTypeSugg, SelfParamNotFirst, StructLiteralBodyWithoutPath,
16+
StructLiteralBodyWithoutPathSugg, StructLiteralNeedingParens, StructLiteralNeedingParensSugg,
17+
SuggAddMissingLetStmt, SuggEscapeIdentifier, SuggRemoveComma, TernaryOperator,
18+
UnexpectedConstInGenericParam, UnexpectedConstParamDeclaration,
19+
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead, WrapType,
2020
};
2121
use crate::fluent_generated as fluent;
2222
use crate::parser;
@@ -640,6 +640,28 @@ impl<'a> Parser<'a> {
640640
}
641641
}
642642

643+
// Try to detect an intended c-string literal while using a pre-2021 edition. The heuristic
644+
// here is to identify a cooked, uninterpolated `c` id immediately followed by a string, or
645+
// a cooked, uninterpolated `cr` id immediately followed by a string or a `#`, in an edition
646+
// where c-string literals are not allowed. There is the very slight possibility of a false
647+
// positive for a `cr#` that wasn't intended to start a c-string literal, but identifying
648+
// that in the parser requires unbounded lookahead, so we only add a hint to the existing
649+
// error rather than replacing it entirely.
650+
if ((self.prev_token.kind == TokenKind::Ident(sym::c, false)
651+
&& matches!(&self.token.kind, TokenKind::Literal(token::Lit { kind: token::Str, .. })))
652+
|| (self.prev_token.kind == TokenKind::Ident(sym::cr, false)
653+
&& matches!(
654+
&self.token.kind,
655+
TokenKind::Literal(token::Lit { kind: token::Str, .. }) | token::Pound
656+
)))
657+
&& self.prev_token.span.hi() == self.token.span.lo()
658+
&& !self.token.span.at_least_rust_2021()
659+
{
660+
err.note("you may be trying to write a c-string literal");
661+
err.note("c-string literals require Rust 2021 or later");
662+
HelpUseLatestEdition::new().add_to_diagnostic(&mut err);
663+
}
664+
643665
// `pub` may be used for an item or `pub(crate)`
644666
if self.prev_token.is_ident_named(sym::public)
645667
&& (self.token.can_begin_item()

Diff for: compiler/rustc_smir/src/rustc_internal/internal.rs

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use crate::rustc_smir::Tables;
88
use rustc_middle::ty::{self as rustc_ty, Ty as InternalTy};
99
use rustc_span::Symbol;
10+
use stable_mir::abi::Layout;
1011
use stable_mir::mir::alloc::AllocId;
1112
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
1213
use stable_mir::mir::{Mutability, Safety};
@@ -460,6 +461,14 @@ impl<'tcx> RustcInternal<'tcx> for Span {
460461
}
461462
}
462463

464+
impl<'tcx> RustcInternal<'tcx> for Layout {
465+
type T = rustc_target::abi::Layout<'tcx>;
466+
467+
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
468+
tables.layouts[*self]
469+
}
470+
}
471+
463472
impl<'tcx, T> RustcInternal<'tcx> for &T
464473
where
465474
T: RustcInternal<'tcx>,

Diff for: compiler/rustc_smir/src/rustc_internal/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_middle::ty::TyCtxt;
1212
use rustc_span::def_id::{CrateNum, DefId};
1313
use rustc_span::Span;
1414
use scoped_tls::scoped_thread_local;
15+
use stable_mir::abi::Layout;
1516
use stable_mir::ty::IndexedVal;
1617
use stable_mir::Error;
1718
use std::cell::Cell;
@@ -136,6 +137,10 @@ impl<'tcx> Tables<'tcx> {
136137
pub(crate) fn static_def(&mut self, did: DefId) -> stable_mir::mir::mono::StaticDef {
137138
stable_mir::mir::mono::StaticDef(self.create_def_id(did))
138139
}
140+
141+
pub(crate) fn layout_id(&mut self, layout: rustc_target::abi::Layout<'tcx>) -> Layout {
142+
self.layouts.create_or_fetch(layout)
143+
}
139144
}
140145

141146
pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
@@ -180,6 +185,7 @@ where
180185
types: IndexMap::default(),
181186
instances: IndexMap::default(),
182187
constants: IndexMap::default(),
188+
layouts: IndexMap::default(),
183189
}));
184190
stable_mir::compiler_interface::run(&tables, || init(&tables, f))
185191
}

Diff for: compiler/rustc_smir/src/rustc_smir/context.rs

+73-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
//! This trait is currently the main interface between the Rust compiler,
44
//! and the `stable_mir` crate.
55
6+
#![allow(rustc::usage_of_qualified_ty)]
7+
8+
use rustc_abi::HasDataLayout;
69
use rustc_middle::ty;
10+
use rustc_middle::ty::layout::{
11+
FnAbiOf, FnAbiOfHelpers, HasParamEnv, HasTyCtxt, LayoutOf, LayoutOfHelpers,
12+
};
713
use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
814
use rustc_middle::ty::{
9-
GenericPredicates, Instance, ParamEnv, ScalarInt, TypeVisitableExt, ValTree,
15+
GenericPredicates, Instance, List, ParamEnv, ScalarInt, TyCtxt, TypeVisitableExt, ValTree,
1016
};
1117
use rustc_span::def_id::LOCAL_CRATE;
18+
use stable_mir::abi::{FnAbi, Layout, LayoutShape};
1219
use stable_mir::compiler_interface::Context;
1320
use stable_mir::mir::alloc::GlobalAlloc;
1421
use stable_mir::mir::mono::{InstanceDef, StaticDef};
@@ -280,7 +287,6 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
280287
tables.tcx.mk_ty_from_kind(internal_kind).stable(&mut *tables)
281288
}
282289

283-
#[allow(rustc::usage_of_qualified_ty)]
284290
fn new_box_ty(&self, ty: stable_mir::ty::Ty) -> stable_mir::ty::Ty {
285291
let mut tables = self.0.borrow_mut();
286292
let inner = ty.internal(&mut *tables);
@@ -335,6 +341,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
335341
instance.ty(tables.tcx, ParamEnv::reveal_all()).stable(&mut *tables)
336342
}
337343

344+
fn instance_abi(&self, def: InstanceDef) -> Result<FnAbi, Error> {
345+
let mut tables = self.0.borrow_mut();
346+
let instance = tables.instances[def];
347+
Ok(tables.fn_abi_of_instance(instance, List::empty())?.stable(&mut *tables))
348+
}
349+
338350
fn instance_def_id(&self, def: InstanceDef) -> stable_mir::DefId {
339351
let mut tables = self.0.borrow_mut();
340352
let def_id = tables.instances[def].def_id();
@@ -473,6 +485,65 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
473485
)
474486
}
475487
}
488+
489+
fn ty_layout(&self, ty: Ty) -> Result<Layout, Error> {
490+
let mut tables = self.0.borrow_mut();
491+
let ty = ty.internal(&mut *tables);
492+
let layout = tables.layout_of(ty)?.layout;
493+
Ok(layout.stable(&mut *tables))
494+
}
495+
496+
fn layout_shape(&self, id: Layout) -> LayoutShape {
497+
let mut tables = self.0.borrow_mut();
498+
id.internal(&mut *tables).0.stable(&mut *tables)
499+
}
476500
}
477501

478502
pub struct TablesWrapper<'tcx>(pub RefCell<Tables<'tcx>>);
503+
504+
/// Implement error handling for extracting function ABI information.
505+
impl<'tcx> FnAbiOfHelpers<'tcx> for Tables<'tcx> {
506+
type FnAbiOfResult = Result<&'tcx rustc_target::abi::call::FnAbi<'tcx, ty::Ty<'tcx>>, Error>;
507+
508+
#[inline]
509+
fn handle_fn_abi_err(
510+
&self,
511+
err: ty::layout::FnAbiError<'tcx>,
512+
_span: rustc_span::Span,
513+
fn_abi_request: ty::layout::FnAbiRequest<'tcx>,
514+
) -> Error {
515+
Error::new(format!("Failed to get ABI for `{fn_abi_request:?}`: {err:?}"))
516+
}
517+
}
518+
519+
impl<'tcx> LayoutOfHelpers<'tcx> for Tables<'tcx> {
520+
type LayoutOfResult = Result<ty::layout::TyAndLayout<'tcx>, Error>;
521+
522+
#[inline]
523+
fn handle_layout_err(
524+
&self,
525+
err: ty::layout::LayoutError<'tcx>,
526+
_span: rustc_span::Span,
527+
ty: ty::Ty<'tcx>,
528+
) -> Error {
529+
Error::new(format!("Failed to get layout for `{ty}`: {err}"))
530+
}
531+
}
532+
533+
impl<'tcx> HasParamEnv<'tcx> for Tables<'tcx> {
534+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
535+
ty::ParamEnv::reveal_all()
536+
}
537+
}
538+
539+
impl<'tcx> HasTyCtxt<'tcx> for Tables<'tcx> {
540+
fn tcx(&self) -> TyCtxt<'tcx> {
541+
self.tcx
542+
}
543+
}
544+
545+
impl<'tcx> HasDataLayout for Tables<'tcx> {
546+
fn data_layout(&self) -> &rustc_abi::TargetDataLayout {
547+
self.tcx.data_layout()
548+
}
549+
}

0 commit comments

Comments
 (0)