Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #137775

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9cd1de5
suggest swapping equality on e0277
makai410 Feb 17, 2025
f462cb7
Update `compiler-builtins` to 0.1.149
tgross35 Feb 25, 2025
6e4adbe
Remove visit_const_block in typeck writeback
nbdd0121 Feb 26, 2025
8282181
Use Binder<Vec<T>> instead of Vec<Binder<T>> in new solver
compiler-errors Feb 26, 2025
ad74788
Use bound_coroutine_witnesses in old solver
compiler-errors Feb 26, 2025
f482460
Handle asm const similar to inline const
nbdd0121 Feb 26, 2025
395b0fb
Bless tests
nbdd0121 Feb 26, 2025
f20dd49
Use original command for showing sccache stats
Kobzol Feb 27, 2025
31388f5
checked_ilog tests: deal with a bit of float imprecision
RalfJung Feb 27, 2025
b3cae68
move `rust.description` to `build.description`
onur-ozkan Feb 27, 2025
0becb57
add change-entry
onur-ozkan Feb 27, 2025
f877b12
pass `CFG_VER_DESCRIPTION` to tool builds
onur-ozkan Feb 27, 2025
6cc6b86
Update E0133 docs for 2024 edition
ehuss Feb 27, 2025
d504f70
Unconditionally lower match arm even if it's unneeded for never patte…
mu001999 Feb 27, 2025
0f7da1a
replace `rust.description` with `build.description`
onur-ozkan Feb 27, 2025
cdd8895
Add inference constraining Copy impl test
BoxyUwU Feb 14, 2025
dc6db19
Defer repeat expr `Copy` check
BoxyUwU Feb 14, 2025
6c3243f
Bless
BoxyUwU Feb 15, 2025
86945c0
Tweak incorrect ABI suggestion
estebank Feb 28, 2025
e6b3b88
Rollup merge of #137045 - BoxyUwU:defer_repeat_expr_checks, r=compile…
matthiaskrgr Feb 28, 2025
3a92645
Rollup merge of #137171 - makai410:swapping-e0277, r=compiler-errors
matthiaskrgr Feb 28, 2025
32405da
Rollup merge of #137634 - tgross35:update-builtins, r=tgross35
matthiaskrgr Feb 28, 2025
59a5466
Rollup merge of #137686 - nbdd0121:asm_const, r=compiler-errors
matthiaskrgr Feb 28, 2025
2dd51d1
Rollup merge of #137689 - compiler-errors:coroutine, r=lcnr
matthiaskrgr Feb 28, 2025
ff6c07d
Rollup merge of #137718 - Kobzol:sccache-stats, r=marcoieni
matthiaskrgr Feb 28, 2025
7d3015a
Rollup merge of #137723 - onur-ozkan:cfg-ver-description, r=pietroalb…
matthiaskrgr Feb 28, 2025
c2711e8
Rollup merge of #137730 - RalfJung:checked_ilog_tests, r=tgross35
matthiaskrgr Feb 28, 2025
0ba2a8a
Rollup merge of #137735 - ehuss:e0133-edition-docs, r=compiler-errors
matthiaskrgr Feb 28, 2025
ba63753
Rollup merge of #137742 - mu001999-contrib:fix-137708, r=compiler-errors
matthiaskrgr Feb 28, 2025
1a45baa
Rollup merge of #137771 - estebank:abi-sugg, r=compiler-errors
matthiaskrgr Feb 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ast_lowering_invalid_abi_clobber_abi =
invalid ABI for `clobber_abi`
.note = the following ABIs are supported on this target: {$supported_abis}

ast_lowering_invalid_abi_suggestion = did you mean
ast_lowering_invalid_abi_suggestion = there's a similarly named valid ABI `{$suggestion}`

ast_lowering_invalid_asm_template_modifier_const =
asm template modifiers are not allowed for `const` arguments
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}
InlineAsmOperand::Const { anon_const } => hir::InlineAsmOperand::Const {
anon_const: self.lower_anon_const_to_anon_const(anon_const),
anon_const: self.lower_const_block(anon_const),
},
InlineAsmOperand::Sym { sym } => {
let static_def_id = self
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ pub(crate) struct TupleStructWithDefault {
#[derive(Subdiagnostic)]
#[suggestion(
ast_lowering_invalid_abi_suggestion,
code = "{suggestion}",
applicability = "maybe-incorrect"
code = "\"{suggestion}\"",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct InvalidAbiSuggestion {
#[primary_span]
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let span = self.lower_span(arm.span);
self.lower_attrs(hir_id, &arm.attrs, arm.span);
let is_never_pattern = pat.is_never_pattern();
let body = if let Some(body) = &arm.body
// We need to lower the body even if it's unneeded for never pattern in match,
// ensure that we can get HirId for DefId if need (issue #137708).
let body = arm.body.as_ref().map(|x| self.lower_expr(x));
let body = if let Some(body) = body
&& !is_never_pattern
{
self.lower_expr(body)
body
} else {
// Either `body.is_none()` or `is_never_pattern` here.
if !is_never_pattern {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
span: abi.span,
suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion {
span: abi.span,
suggestion: format!("\"{suggested_name}\""),
suggestion: suggested_name.to_string(),
}),
command: "rustc --print=calling-conventions".to_string(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644

[dependencies]
core = { path = "../core", public = true }
-compiler_builtins = { version = "=0.1.148", features = ['rustc-dep-of-std'] }
+compiler_builtins = { version = "=0.1.148", features = ['rustc-dep-of-std', 'no-f16-f128'] }
-compiler_builtins = { version = "=0.1.149", features = ['rustc-dep-of-std'] }
+compiler_builtins = { version = "=0.1.149", features = ['rustc-dep-of-std', 'no-f16-f128'] }

[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0133.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ unsafe fn g() {
```

Linting against this is controlled via the `unsafe_op_in_unsafe_fn` lint, which
is `allow` by default but will be upgraded to `warn` in a future edition.
is `warn` by default in the 2024 edition and `allow` by default in earlier
editions.

[unsafe-section]: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3506,7 +3506,7 @@ pub enum InlineAsmOperand<'hir> {
out_expr: Option<&'hir Expr<'hir>>,
},
Const {
anon_const: &'hir AnonConst,
anon_const: ConstBlock,
},
SymFn {
expr: &'hir Expr<'hir>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ pub fn walk_inline_asm<'v, V: Visitor<'v>>(
visit_opt!(visitor, visit_expr, out_expr);
}
InlineAsmOperand::Const { anon_const, .. } => {
try_visit!(visitor.visit_anon_const(anon_const));
try_visit!(visitor.visit_inline_const(anon_const));
}
InlineAsmOperand::SymFn { expr, .. } => {
try_visit!(visitor.visit_expr(expr));
Expand Down
34 changes: 25 additions & 9 deletions compiler/rustc_hir_analysis/src/check/intrinsicck.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::assert_matches::debug_assert_matches;

use rustc_abi::FieldIdx;
use rustc_ast::InlineAsmTemplatePiece;
use rustc_data_structures::fx::FxIndexSet;
Expand All @@ -21,6 +19,7 @@ pub struct InlineAsmCtxt<'a, 'tcx: 'a> {
typing_env: ty::TypingEnv<'tcx>,
target_features: &'tcx FxIndexSet<Symbol>,
expr_ty: Box<dyn Fn(&hir::Expr<'tcx>) -> Ty<'tcx> + 'a>,
node_ty: Box<dyn Fn(hir::HirId) -> Ty<'tcx> + 'a>,
}

enum NonAsmTypeReason<'tcx> {
Expand All @@ -35,20 +34,26 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
typing_env: ty::TypingEnv<'tcx>,
get_operand_ty: impl Fn(&hir::Expr<'tcx>) -> Ty<'tcx> + 'a,
expr_ty: impl Fn(&hir::Expr<'tcx>) -> Ty<'tcx> + 'a,
node_ty: impl Fn(hir::HirId) -> Ty<'tcx> + 'a,
) -> Self {
InlineAsmCtxt {
tcx,
typing_env,
target_features: tcx.asm_target_features(def_id),
expr_ty: Box::new(get_operand_ty),
expr_ty: Box::new(expr_ty),
node_ty: Box::new(node_ty),
}
}

fn expr_ty(&self, expr: &hir::Expr<'tcx>) -> Ty<'tcx> {
(self.expr_ty)(expr)
}

fn node_ty(&self, hir_id: hir::HirId) -> Ty<'tcx> {
(self.node_ty)(hir_id)
}

// FIXME(compiler-errors): This could use `<$ty as Pointee>::Metadata == ()`
fn is_thin_ptr_ty(&self, ty: Ty<'tcx>) -> bool {
// Type still may have region variables, but `Sized` does not depend
Expand Down Expand Up @@ -487,12 +492,23 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
);
}
}
// Typeck has checked that Const operands are integers.
hir::InlineAsmOperand::Const { anon_const } => {
debug_assert_matches!(
self.tcx.type_of(anon_const.def_id).instantiate_identity().kind(),
ty::Error(_) | ty::Int(_) | ty::Uint(_)
);
let ty = self.node_ty(anon_const.hir_id);
match ty.kind() {
ty::Error(_) => {}
_ if ty.is_integral() => {}
_ => {
self.tcx
.dcx()
.struct_span_err(op_sp, "invalid type for `const` operand")
.with_span_label(
self.tcx.def_span(anon_const.def_id),
format!("is {} `{}`", ty.kind().article(), ty),
)
.with_help("`const` operands must be of an integer type")
.emit();
}
}
}
// Typeck has checked that SymFn refers to a function.
hir::InlineAsmOperand::SymFn { expr } => {
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
{
Some(parent_did)
}
// Exclude `GlobalAsm` here which cannot have generics.
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
if asm.operands.iter().any(|(op, _op_sp)| match op {
hir::InlineAsmOperand::Const { anon_const } => {
anon_const.hir_id == hir_id
}
_ => false,
}) =>
{
Some(parent_did)
}
Node::TyPat(_) => Some(parent_did),
_ => None,
}
Expand Down
34 changes: 1 addition & 33 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::query::plumbing::CyclePlaceholder;
use rustc_middle::ty::fold::fold_regions;
use rustc_middle::ty::print::with_forced_trimmed_paths;
use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::{self, Article, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::{bug, span_bug};
use rustc_span::{DUMMY_SP, Ident, Span};

Expand All @@ -35,13 +35,6 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx
let parent_node_id = tcx.parent_hir_id(hir_id);
let parent_node = tcx.hir_node(parent_node_id);

let find_const = |&(op, op_sp)| match op {
hir::InlineAsmOperand::Const { anon_const } if anon_const.hir_id == hir_id => {
Some((anon_const, op_sp))
}
_ => None,
};

match parent_node {
// Anon consts "inside" the type system.
Node::ConstArg(&ConstArg {
Expand All @@ -50,31 +43,6 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx
..
}) if anon_hir_id == hir_id => const_arg_anon_type_of(icx, arg_hir_id, span),

// Anon consts outside the type system.
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
| Node::Item(&Item { kind: ItemKind::GlobalAsm { asm, .. }, .. })
if let Some((anon_const, op_sp)) = asm.operands.iter().find_map(find_const) =>
{
let ty = tcx.typeck(def_id).node_type(hir_id);

match ty.kind() {
ty::Error(_) => ty,
ty::Int(_) | ty::Uint(_) => ty,
_ => {
let guar = tcx
.dcx()
.struct_span_err(op_sp, "invalid type for `const` operand")
.with_span_label(
tcx.def_span(anon_const.def_id),
format!("is {} `{}`", ty.kind().article(), ty),
)
.with_help("`const` operands must be of an integer type")
.emit();

Ty::new_error(tcx, guar)
}
}
}
Node::Variant(Variant { disr_expr: Some(e), .. }) if e.hir_id == hir_id => {
tcx.adt_def(tcx.hir_get_parent_item(hir_id)).repr().discr_type().to_ty(tcx)
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,8 @@ impl<'a> State<'a> {
hir::InlineAsmOperand::Const { ref anon_const } => {
s.word("const");
s.space();
s.print_anon_const(anon_const);
// Not using `print_inline_const` to avoid additional `const { ... }`
s.ann.nested(s, Nested::Body(anon_const.body))
}
hir::InlineAsmOperand::SymFn { ref expr } => {
s.word("sym_fn");
Expand Down
18 changes: 10 additions & 8 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,12 +1853,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return Ty::new_error(tcx, guar);
}

// We defer checking whether the element type is `Copy` as it is possible to have
// an inference variable as a repeat count and it seems unlikely that `Copy` would
// have inference side effects required for type checking to succeed.
if tcx.features().generic_arg_infer() {
self.deferred_repeat_expr_checks.borrow_mut().push((element, element_ty, count));
// If the length is 0, we don't create any elements, so we don't copy any.
// If the length is 1, we don't copy that one element, we move it. Only check
// for `Copy` if the length is larger, or unevaluated.
// FIXME(min_const_generic_exprs): We could perhaps defer this check so that
// we don't require `<?0t as Tr>::CONST` doesn't unnecessarily require `Copy`.
if count.try_to_target_usize(tcx).is_none_or(|x| x > 1) {
} else if count.try_to_target_usize(self.tcx).is_none_or(|x| x > 1) {
self.enforce_repeat_element_needs_copy_bound(element, element_ty);
}

Expand All @@ -1868,7 +1871,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

/// Requires that `element_ty` is `Copy` (unless it's a const expression itself).
fn enforce_repeat_element_needs_copy_bound(
pub(super) fn enforce_repeat_element_needs_copy_bound(
&self,
element: &hir::Expr<'_>,
element_ty: Ty<'tcx>,
Expand Down Expand Up @@ -3771,13 +3774,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.check_expr_asm_operand(out_expr, false);
}
}
hir::InlineAsmOperand::Const { ref anon_const } => {
self.check_expr_const_block(anon_const, Expectation::NoExpectation);
}
hir::InlineAsmOperand::SymFn { expr } => {
self.check_expr(expr);
}
// `AnonConst`s have their own body and is type-checked separately.
// As they don't flow into the type system we don't need them to
// be well-formed.
hir::InlineAsmOperand::Const { .. } => {}
hir::InlineAsmOperand::SymStatic { .. } => {}
hir::InlineAsmOperand::Label { block } => {
let previous_diverges = self.diverges.get();
Expand Down
51 changes: 40 additions & 11 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})
}

/// Resolves type and const variables in `ty` if possible. Unlike the infcx
/// Resolves type and const variables in `t` if possible. Unlike the infcx
/// version (resolve_vars_if_possible), this version will
/// also select obligations if it seems useful, in an effort
/// to get more type information.
// FIXME(-Znext-solver): A lot of the calls to this method should
// probably be `try_structurally_resolve_type` or `structurally_resolve_type` instead.
#[instrument(skip(self), level = "debug", ret)]
pub(crate) fn resolve_vars_with_obligations(&self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
pub(crate) fn resolve_vars_with_obligations<T: TypeFoldable<TyCtxt<'tcx>>>(
&self,
mut t: T,
) -> T {
// No Infer()? Nothing needs doing.
if !ty.has_non_region_infer() {
if !t.has_non_region_infer() {
debug!("no inference var, nothing needs doing");
return ty;
return t;
}

// If `ty` is a type variable, see whether we already know what it is.
ty = self.resolve_vars_if_possible(ty);
if !ty.has_non_region_infer() {
debug!(?ty);
return ty;
// If `t` is a type variable, see whether we already know what it is.
t = self.resolve_vars_if_possible(t);
if !t.has_non_region_infer() {
debug!(?t);
return t;
}

// If not, try resolving pending obligations as much as
// possible. This can help substantially when there are
// indirect dependencies that don't seem worth tracking
// precisely.
self.select_obligations_where_possible(|_| {});
self.resolve_vars_if_possible(ty)
self.resolve_vars_if_possible(t)
}

pub(crate) fn record_deferred_call_resolution(
Expand Down Expand Up @@ -1454,7 +1457,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
sp: Span,
ct: ty::Const<'tcx>,
) -> ty::Const<'tcx> {
// FIXME(min_const_generic_exprs): We could process obligations here if `ct` is a var.
let ct = self.resolve_vars_with_obligations(ct);

if self.next_trait_solver()
&& let ty::ConstKind::Unevaluated(..) = ct.kind()
Expand Down Expand Up @@ -1510,6 +1513,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

pub(crate) fn structurally_resolve_const(
&self,
sp: Span,
ct: ty::Const<'tcx>,
) -> ty::Const<'tcx> {
let ct = self.try_structurally_resolve_const(sp, ct);

if !ct.is_ct_infer() {
ct
} else {
let e = self.tainted_by_errors().unwrap_or_else(|| {
self.err_ctxt()
.emit_inference_failure_err(
self.body_id,
sp,
ct.into(),
TypeAnnotationNeeded::E0282,
true,
)
.emit()
});
// FIXME: Infer `?ct = {const error}`?
ty::Const::new_error(self.tcx, e)
}
}

pub(crate) fn with_breakable_ctxt<F: FnOnce() -> R, R>(
&self,
id: HirId,
Expand Down
Loading
Loading