Skip to content

Commit a463b0e

Browse files
committed
Auto merge of #149510 - matthiaskrgr:rollup-5rt6o7z, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #148690 (Implement `clamp_magnitude` method for primitive floats & signed integers) - #149102 (stabilize maybe_uninit_slice) - #149269 (cmse: do not calculate the layout of a type with infer types) - #149299 (Fudge infer vars in the cause code of `Obligation` intentionally) - #149344 (Don't suggest unwrap for Result in const) - #149358 (fix(parse): Limit frontmatter fences to 255 dashes ) - #149445 (make assoc fn inherit const stability from inherent `const impl` blocks) - #149479 (Fix indent in E0591.md) - #149496 (Fix #148889: Add label rib when visiting delegation body) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2fb8053 + e0091c5 commit a463b0e

File tree

46 files changed

+764
-71
lines changed

Some content is hidden

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

46 files changed

+764
-71
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
// tidy-alphabetical-start
1111
#![allow(clippy::mut_from_ref)] // Arena allocators are one place where this pattern is fine.
1212
#![allow(internal_features)]
13+
#![cfg_attr(bootstrap, feature(maybe_uninit_slice))]
1314
#![cfg_attr(test, feature(test))]
1415
#![deny(unsafe_op_in_unsafe_fn)]
1516
#![doc(test(no_crate_inject, attr(deny(warnings), allow(internal_features))))]
1617
#![feature(core_intrinsics)]
1718
#![feature(decl_macro)]
1819
#![feature(dropck_eyepatch)]
19-
#![feature(maybe_uninit_slice)]
2020
#![feature(never_type)]
2121
#![feature(rustc_attrs)]
2222
#![feature(unwrap_infallible)]

compiler/rustc_error_codes/src/error_codes/E0591.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ This pattern should be rewritten. There are a few possible ways to do this:
6262
and do the cast in the fn body (the preferred option)
6363
- cast the fn item of a fn pointer before calling transmute, as shown here:
6464

65-
```
66-
# extern "C" fn foo(_: Box<i32>) {}
67-
# use std::mem::transmute;
68-
# unsafe {
69-
let f: extern "C" fn(*mut i32) = transmute(foo as extern "C" fn(_));
70-
let f: extern "C" fn(*mut i32) = transmute(foo as usize); // works too
71-
# }
72-
```
65+
```
66+
# extern "C" fn foo(_: Box<i32>) {}
67+
# use std::mem::transmute;
68+
# unsafe {
69+
let f: extern "C" fn(*mut i32) = transmute(foo as extern "C" fn(_));
70+
let f: extern "C" fn(*mut i32) = transmute(foo as usize); // works too
71+
# }
72+
```
7373

7474
The same applies to transmutes to `*mut fn()`, which were observed in practice.
7575
Note though that use of this type is generally incorrect.

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ fn is_valid_cmse_inputs<'tcx>(
8686
let fn_sig = tcx.erase_and_anonymize_regions(fn_sig);
8787

8888
for (ty, hir_ty) in fn_sig.inputs().iter().zip(fn_decl.inputs) {
89+
if ty.has_infer_types() {
90+
let err = LayoutError::Unknown(*ty);
91+
return Err((hir_ty.span, tcx.arena.alloc(err)));
92+
}
93+
8994
let layout = tcx
9095
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(*ty))
9196
.map_err(|e| (hir_ty.span, e))?;
@@ -138,6 +143,11 @@ fn is_valid_cmse_output<'tcx>(
138143
return Ok(());
139144
}
140145

146+
if return_type.has_infer_types() {
147+
let err = LayoutError::Unknown(return_type);
148+
return Err(tcx.arena.alloc(err));
149+
}
150+
141151
let typing_env = ty::TypingEnv::fully_monomorphized();
142152
let layout = tcx.layout_of(typing_env.as_query_input(return_type))?;
143153

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,14 +2106,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21062106
)),
21072107
);
21082108

2109-
let (article, kind, variant, sugg_operator) =
2110-
if self.tcx.is_diagnostic_item(sym::Result, adt.did()) {
2111-
("a", "Result", "Err", ret_ty_matches(sym::Result))
2112-
} else if self.tcx.is_diagnostic_item(sym::Option, adt.did()) {
2113-
("an", "Option", "None", ret_ty_matches(sym::Option))
2114-
} else {
2115-
return false;
2116-
};
2109+
let (article, kind, variant, sugg_operator) = if self.tcx.is_diagnostic_item(sym::Result, adt.did())
2110+
// Do not suggest `.expect()` in const context where it's not available. rust-lang/rust#149316
2111+
&& !self.tcx.hir_is_inside_const_context(expr.hir_id)
2112+
{
2113+
("a", "Result", "Err", ret_ty_matches(sym::Result))
2114+
} else if self.tcx.is_diagnostic_item(sym::Option, adt.did()) {
2115+
("an", "Option", "None", ret_ty_matches(sym::Option))
2116+
} else {
2117+
return false;
2118+
};
21172119
if is_ctor || !self.may_coerce(args.type_at(0), expected) {
21182120
return false;
21192121
}

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,14 +3041,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30413041
tcx.def_span(pick.item.def_id),
30423042
format!("the method `{item_name}` exists on the type `{self_ty}`"),
30433043
);
3044-
let (article, kind, variant, question) =
3045-
if tcx.is_diagnostic_item(sym::Result, kind.did()) {
3046-
("a", "Result", "Err", ret_ty_matches(sym::Result))
3047-
} else if tcx.is_diagnostic_item(sym::Option, kind.did()) {
3048-
("an", "Option", "None", ret_ty_matches(sym::Option))
3049-
} else {
3050-
return;
3051-
};
3044+
let (article, kind, variant, question) = if tcx.is_diagnostic_item(sym::Result, kind.did())
3045+
// Do not suggest `.expect()` in const context where it's not available. rust-lang/rust#149316
3046+
&& !tcx.hir_is_inside_const_context(expr.hir_id)
3047+
{
3048+
("a", "Result", "Err", ret_ty_matches(sym::Result))
3049+
} else if tcx.is_diagnostic_item(sym::Option, kind.did()) {
3050+
("an", "Option", "None", ret_ty_matches(sym::Option))
3051+
} else {
3052+
return;
3053+
};
30523054
if question {
30533055
err.span_suggestion_verbose(
30543056
expr.span.shrink_to_hi(),

compiler/rustc_infer/src/traits/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ use crate::infer::InferCtxt;
3737
#[derive(Clone, TypeFoldable, TypeVisitable)]
3838
pub struct Obligation<'tcx, T> {
3939
/// The reason we have to prove this thing.
40+
/// FIXME: we shouldn't ignore the cause but instead change the affected visitors
41+
/// to only visit predicates manually.
4042
#[type_foldable(identity)]
4143
#[type_visitable(ignore)]
4244
pub cause: ObligationCause<'tcx>,

compiler/rustc_parse/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ parse_frontmatter_invalid_opening_preceding_whitespace = invalid preceding white
347347
parse_frontmatter_length_mismatch = frontmatter close does not match the opening
348348
.label_opening = the opening here has {$len_opening} dashes...
349349
.label_close = ...while the close has {$len_close} dashes
350+
parse_frontmatter_too_many_dashes = too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found {$len_opening}
350351
parse_frontmatter_unclosed = unclosed frontmatter
351352
.note = frontmatter opening here was not closed
352353

compiler/rustc_parse/src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,12 @@ pub(crate) struct FrontmatterLengthMismatch {
822822
pub len_close: usize,
823823
}
824824

825+
#[derive(Diagnostic)]
826+
#[diag(parse_frontmatter_too_many_dashes)]
827+
pub(crate) struct FrontmatterTooManyDashes {
828+
pub len_opening: usize,
829+
}
830+
825831
#[derive(Diagnostic)]
826832
#[diag(parse_leading_plus_not_supported)]
827833
pub(crate) struct LeadingPlusNotSupported {

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,11 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
665665
});
666666
}
667667

668+
// Only up to 255 `-`s are allowed in code fences
669+
if u8::try_from(len_opening).is_err() {
670+
self.dcx().emit_err(errors::FrontmatterTooManyDashes { len_opening });
671+
}
672+
668673
if !rest.trim_matches(is_horizontal_whitespace).is_empty() {
669674
let span = self.mk_sp(last_line_start_pos, self.pos);
670675
self.dcx().emit_err(errors::FrontmatterExtraCharactersAfterClose { span });

compiler/rustc_passes/src/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn inherit_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
5454
match def_kind {
5555
DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => {
5656
match tcx.def_kind(tcx.local_parent(def_id)) {
57-
DefKind::Impl { of_trait: true } => true,
57+
DefKind::Impl { .. } => true,
5858
_ => false,
5959
}
6060
}

0 commit comments

Comments
 (0)