Skip to content

Commit 66701c4

Browse files
committed
Auto merge of #132251 - jieyouxu:rollup-mtv9mpd, r=jieyouxu
Rollup of 7 pull requests Successful merges: - #131633 (error on alignments greater than `isize::MAX`) - #132086 (Tweak E0277 highlighting and "long type" path printing) - #132220 (Add GUI regression test for doc struct fields margins) - #132225 (Dynamically link run-make support) - #132227 (Pass constness with span into lower_poly_trait_ref) - #132242 (Support `char::is_digit` in const contexts.) - #132243 (Remove `ObligationCause::span()` method) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6929a48 + 3e3feac commit 66701c4

File tree

66 files changed

+572
-337
lines changed

Some content is hidden

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

66 files changed

+572
-337
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
611611
Err(terr) => {
612612
let mut diag = struct_span_code_err!(
613613
tcx.dcx(),
614-
cause.span(),
614+
cause.span,
615615
E0053,
616616
"method `{}` has an incompatible return type for trait",
617617
trait_m.name
@@ -1169,7 +1169,7 @@ fn extract_spans_for_error_reporting<'tcx>(
11691169
TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => {
11701170
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
11711171
}
1172-
_ => (cause.span(), tcx.hir().span_if_local(trait_m.def_id)),
1172+
_ => (cause.span, tcx.hir().span_if_local(trait_m.def_id)),
11731173
}
11741174
}
11751175

compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ pub fn check_function_signature<'tcx>(
612612
match err {
613613
TypeError::ArgumentMutability(i)
614614
| TypeError::ArgumentSorts(ExpectedFound { .. }, i) => args.nth(i).unwrap(),
615-
_ => cause.span(),
615+
_ => cause.span,
616616
}
617617
}
618618

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

-7
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
168168
match hir_bound {
169169
hir::GenericBound::Trait(poly_trait_ref) => {
170170
let hir::TraitBoundModifiers { constness, polarity } = poly_trait_ref.modifiers;
171-
// FIXME: We could pass these directly into `lower_poly_trait_ref`
172-
// so that we could use these spans in diagnostics within that function...
173-
let constness = match constness {
174-
hir::BoundConstness::Never => None,
175-
hir::BoundConstness::Always(_) => Some(ty::BoundConstness::Const),
176-
hir::BoundConstness::Maybe(_) => Some(ty::BoundConstness::ConstIfConst),
177-
};
178171
let polarity = match polarity {
179172
rustc_ast::BoundPolarity::Positive => ty::PredicatePolarity::Positive,
180173
rustc_ast::BoundPolarity::Negative(_) => ty::PredicatePolarity::Negative,

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
5050
} = self.lower_poly_trait_ref(
5151
&trait_bound.trait_ref,
5252
trait_bound.span,
53-
None,
53+
hir::BoundConstness::Never,
5454
ty::PredicatePolarity::Positive,
5555
dummy_self,
5656
&mut bounds,

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
658658
&self,
659659
trait_ref: &hir::TraitRef<'tcx>,
660660
span: Span,
661-
constness: Option<ty::BoundConstness>,
661+
constness: hir::BoundConstness,
662662
polarity: ty::PredicatePolarity,
663663
self_ty: Ty<'tcx>,
664664
bounds: &mut Bounds<'tcx>,
@@ -681,11 +681,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
681681
Some(self_ty),
682682
);
683683

684-
if let Some(constness) = constness
684+
if let hir::BoundConstness::Always(span) | hir::BoundConstness::Maybe(span) = constness
685685
&& !self.tcx().is_const_trait(trait_def_id)
686686
{
687687
self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
688-
span: trait_ref.path.span,
688+
span,
689689
modifier: constness.as_str(),
690690
});
691691
}
@@ -708,7 +708,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
708708
bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity);
709709

710710
match constness {
711-
Some(ty::BoundConstness::Const) => {
711+
hir::BoundConstness::Always(span) => {
712712
if polarity == ty::PredicatePolarity::Positive {
713713
bounds.push_const_bound(
714714
tcx,
@@ -718,13 +718,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
718718
);
719719
}
720720
}
721-
Some(ty::BoundConstness::ConstIfConst) => {
721+
hir::BoundConstness::Maybe(_) => {
722722
// We don't emit a const bound here, since that would mean that we
723723
// unconditionally need to prove a `HostEffect` predicate, even when
724724
// the predicates are being instantiated in a non-const context. This
725725
// is instead handled in the `const_conditions` query.
726726
}
727-
None => {}
727+
hir::BoundConstness::Never => {}
728728
}
729729
}
730730
// On the flip side, when filtering `ConstIfConst` bounds, we only need to convert
@@ -734,12 +734,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
734734
// here because we only call this on self bounds, and deal with the recursive case
735735
// in `lower_assoc_item_constraint`.
736736
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => match constness {
737-
Some(ty::BoundConstness::ConstIfConst) => {
737+
hir::BoundConstness::Maybe(span) => {
738738
if polarity == ty::PredicatePolarity::Positive {
739739
bounds.push_const_bound(tcx, poly_trait_ref, ty::HostPolarity::Maybe, span);
740740
}
741741
}
742-
None | Some(ty::BoundConstness::Const) => {}
742+
hir::BoundConstness::Always(_) | hir::BoundConstness::Never => {}
743743
},
744744
}
745745

compiler/rustc_hir_typeck/src/_match.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9494
(None, arm.body.span)
9595
};
9696

97-
let (span, code) = match prior_arm {
97+
let code = match prior_arm {
9898
// The reason for the first arm to fail is not that the match arms diverge,
9999
// but rather that there's a prior obligation that doesn't hold.
100-
None => {
101-
(arm_span, ObligationCauseCode::BlockTailExpression(arm.body.hir_id, match_src))
102-
}
103-
Some((prior_arm_block_id, prior_arm_ty, prior_arm_span)) => (
104-
expr.span,
100+
None => ObligationCauseCode::BlockTailExpression(arm.body.hir_id, match_src),
101+
Some((prior_arm_block_id, prior_arm_ty, prior_arm_span)) => {
105102
ObligationCauseCode::MatchExpressionArm(Box::new(MatchExpressionArmCause {
106103
arm_block_id,
107104
arm_span,
@@ -110,13 +107,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
110107
prior_arm_ty,
111108
prior_arm_span,
112109
scrut_span: scrut.span,
110+
expr_span: expr.span,
113111
source: match_src,
114112
prior_non_diverging_arms: prior_non_diverging_arms.clone(),
115113
tail_defines_return_position_impl_trait,
116-
})),
117-
),
114+
}))
115+
}
118116
};
119-
let cause = self.cause(span, code);
117+
let cause = self.cause(arm_span, code);
120118

121119
// This is the moral equivalent of `coercion.coerce(self, cause, arm.body, arm_ty)`.
122120
// We use it this way to be able to expand on the potential error and detect when a

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20272027
}
20282028
Err(_) => {
20292029
span_bug!(
2030-
cause.span(),
2030+
cause.span,
20312031
"subtyping remaining fields of type changing FRU failed: {target_ty} != {fru_ty}: {}::{}",
20322032
variant.name,
20332033
ident.name,

compiler/rustc_hir_typeck/src/method/confirm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
550550
// This has/will have errored in wfcheck, which we cannot depend on from here, as typeck on functions
551551
// may run before wfcheck if the function is used in const eval.
552552
self.dcx().span_delayed_bug(
553-
cause.span(),
553+
cause.span,
554554
format!("{self_ty} was a subtype of {method_self_ty} but now is not?"),
555555
);
556556
}

compiler/rustc_middle/src/traits/mod.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ impl<'tcx> ObligationCause<'tcx> {
9292
ObligationCause { span, body_id: CRATE_DEF_ID, code: Default::default() }
9393
}
9494

95-
pub fn span(&self) -> Span {
96-
match *self.code() {
97-
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
98-
arm_span,
99-
..
100-
}) => arm_span,
101-
_ => self.span,
102-
}
103-
}
104-
10595
#[inline]
10696
pub fn code(&self) -> &ObligationCauseCode<'tcx> {
10797
&self.code
@@ -517,10 +507,17 @@ pub struct MatchExpressionArmCause<'tcx> {
517507
pub prior_arm_block_id: Option<HirId>,
518508
pub prior_arm_ty: Ty<'tcx>,
519509
pub prior_arm_span: Span,
510+
/// Span of the scrutinee of the match (the matched value).
520511
pub scrut_span: Span,
512+
/// Source of the match, i.e. `match` or a desugaring.
521513
pub source: hir::MatchSource,
514+
/// Span of the *whole* match expr.
515+
pub expr_span: Span,
516+
/// Spans of the previous arms except for those that diverge (i.e. evaluate to `!`).
517+
///
518+
/// These are used for pointing out errors that may affect several arms.
522519
pub prior_non_diverging_arms: Vec<Span>,
523-
// Is the expectation of this match expression an RPIT?
520+
/// Is the expectation of this match expression an RPIT?
524521
pub tail_defines_return_position_impl_trait: Option<LocalDefId>,
525522
}
526523

compiler/rustc_passes/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,10 @@ passes_remove_fields =
622622
passes_repr_align_function =
623623
`repr(align)` attributes on functions are unstable
624624
625+
passes_repr_align_greater_than_target_max =
626+
alignment must not be greater than `isize::MAX` bytes
627+
.note = `isize::MAX` is {$size} for the current target
628+
625629
passes_repr_conflicting =
626630
conflicting representation hints
627631

compiler/rustc_passes/src/check_attr.rs

+43-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use rustc_session::lint::builtin::{
3434
use rustc_session::parse::feature_err;
3535
use rustc_span::symbol::{Symbol, kw, sym};
3636
use rustc_span::{BytePos, DUMMY_SP, Span};
37+
use rustc_target::abi::Size;
3738
use rustc_target::spec::abi::Abi;
3839
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
3940
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
@@ -1785,7 +1786,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
17851786
| Target::Union
17861787
| Target::Enum
17871788
| Target::Fn
1788-
| Target::Method(_) => continue,
1789+
| Target::Method(_) => {}
17891790
_ => {
17901791
self.dcx().emit_err(
17911792
errors::AttrApplication::StructEnumFunctionMethodUnion {
@@ -1795,6 +1796,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
17951796
);
17961797
}
17971798
}
1799+
1800+
self.check_align_value(hint);
17981801
}
17991802
sym::packed => {
18001803
if target != Target::Struct && target != Target::Union {
@@ -1892,6 +1895,45 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
18921895
}
18931896
}
18941897

1898+
fn check_align_value(&self, item: &MetaItemInner) {
1899+
match item.singleton_lit_list() {
1900+
Some((
1901+
_,
1902+
MetaItemLit {
1903+
kind: ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed), ..
1904+
},
1905+
)) => {
1906+
let val = literal.get() as u64;
1907+
if val > 2_u64.pow(29) {
1908+
// for values greater than 2^29, a different error will be emitted, make sure that happens
1909+
self.dcx().span_delayed_bug(
1910+
item.span(),
1911+
"alignment greater than 2^29 should be errored on elsewhere",
1912+
);
1913+
} else {
1914+
// only do this check when <= 2^29 to prevent duplicate errors:
1915+
// alignment greater than 2^29 not supported
1916+
// alignment is too large for the current target
1917+
1918+
let max =
1919+
Size::from_bits(self.tcx.sess.target.pointer_width).signed_int_max() as u64;
1920+
if val > max {
1921+
self.dcx().emit_err(errors::InvalidReprAlignForTarget {
1922+
span: item.span(),
1923+
size: max,
1924+
});
1925+
}
1926+
}
1927+
}
1928+
1929+
// if the attribute is malformed, singleton_lit_list may not be of the expected type or may be None
1930+
// but an error will have already been emitted, so this code should just skip such attributes
1931+
Some((_, _)) | None => {
1932+
self.dcx().span_delayed_bug(item.span(), "malformed repr(align(N))");
1933+
}
1934+
}
1935+
}
1936+
18951937
fn check_used(&self, attrs: &[Attribute], target: Target, target_span: Span) {
18961938
let mut used_linker_span = None;
18971939
let mut used_compiler_span = None;

compiler/rustc_passes/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,15 @@ pub(crate) struct ReprConflicting {
567567
pub hint_spans: Vec<Span>,
568568
}
569569

570+
#[derive(Diagnostic)]
571+
#[diag(passes_repr_align_greater_than_target_max, code = E0589)]
572+
#[note]
573+
pub(crate) struct InvalidReprAlignForTarget {
574+
#[primary_span]
575+
pub span: Span,
576+
pub size: u64,
577+
}
578+
570579
#[derive(LintDiagnostic)]
571580
#[diag(passes_repr_conflicting, code = E0566)]
572581
pub(crate) struct ReprConflictingLint;

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
392392
Some(ty) if expected == ty => {
393393
let source_map = self.tcx.sess.source_map();
394394
err.span_suggestion(
395-
source_map.end_point(cause.span()),
395+
source_map.end_point(cause.span),
396396
"try removing this `?`",
397397
"",
398398
Applicability::MachineApplicable,
@@ -412,6 +412,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
412412
source,
413413
ref prior_non_diverging_arms,
414414
scrut_span,
415+
expr_span,
415416
..
416417
}) => match source {
417418
hir::MatchSource::TryDesugar(scrut_hir_id) => {
@@ -430,7 +431,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
430431
Some(ty) if expected == ty => {
431432
let source_map = self.tcx.sess.source_map();
432433
err.span_suggestion(
433-
source_map.end_point(cause.span()),
434+
source_map.end_point(cause.span),
434435
"try removing this `?`",
435436
"",
436437
Applicability::MachineApplicable,
@@ -460,12 +461,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
460461
format!("this and all prior arms are found to be of type `{t}`"),
461462
);
462463
}
463-
let outer = if any_multiline_arm || !source_map.is_multiline(cause.span) {
464+
let outer = if any_multiline_arm || !source_map.is_multiline(expr_span) {
464465
// Cover just `match` and the scrutinee expression, not
465466
// the entire match body, to reduce diagram noise.
466-
cause.span.shrink_to_lo().to(scrut_span)
467+
expr_span.shrink_to_lo().to(scrut_span)
467468
} else {
468-
cause.span
469+
expr_span
469470
};
470471
let msg = "`match` arms have incompatible types";
471472
err.span_label(outer, msg);
@@ -1148,7 +1149,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
11481149
terr: TypeError<'tcx>,
11491150
prefer_label: bool,
11501151
) {
1151-
let span = cause.span();
1152+
let span = cause.span;
11521153

11531154
// For some types of errors, expected-found does not make
11541155
// sense, so just ignore the values we were given.
@@ -1642,7 +1643,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16421643
terr: TypeError<'tcx>,
16431644
) -> Vec<TypeErrorAdditionalDiags> {
16441645
let mut suggestions = Vec::new();
1645-
let span = trace.cause.span();
1646+
let span = trace.cause.span;
16461647
let values = self.resolve_vars_if_possible(trace.values);
16471648
if let Some((expected, found)) = values.ty() {
16481649
match (expected.kind(), found.kind()) {
@@ -1792,7 +1793,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17921793
) -> Diag<'a> {
17931794
debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);
17941795

1795-
let span = trace.cause.span();
1796+
let span = trace.cause.span;
17961797
let failure_code = trace.cause.as_failure_code_diag(
17971798
terr,
17981799
span,

compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
237237
expected_args: GenericArgsRef<'tcx>,
238238
actual_args: GenericArgsRef<'tcx>,
239239
) -> Diag<'tcx> {
240-
let span = cause.span();
240+
let span = cause.span;
241241

242242
let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) =
243243
if let ObligationCauseCode::WhereClause(def_id, span)

0 commit comments

Comments
 (0)