Skip to content

Commit 17527ef

Browse files
committed
Auto merge of rust-lang#130230 - workingjubilee:rollup-0e4ulat, r=workingjubilee
Rollup of 14 pull requests Successful merges: - rust-lang#129260 (Don't suggest adding return type for closures with default return type) - rust-lang#129520 (Suggest the correct pattern syntax on usage of unit variant pattern for a struct variant) - rust-lang#129696 (update stdarch) - rust-lang#129759 (Stabilize `const_refs_to_static`) - rust-lang#129835 (enable const-float-classify test, and test_next_up/down on 32bit x86) - rust-lang#129866 (Clarify documentation labelling and definitions for std::collections) - rust-lang#130052 (Don't leave debug locations for constants sitting on the builder indefinitely) - rust-lang#130077 (Fix linking error when compiling for 32-bit watchOS) - rust-lang#130123 (Report the `note` when specified in `diagnostic::on_unimplemented`) - rust-lang#130156 (Add test for S_OBJNAME & update test for LF_BUILDINFO cl and cmd) - rust-lang#130206 (Map `WSAEDQUOT` to `ErrorKind::FilesystemQuotaExceeded`) - rust-lang#130207 (Map `ERROR_CANT_RESOLVE_FILENAME` to `ErrorKind::FilesystemLoop`) - rust-lang#130219 (Fix false positive with `missing_docs` and `#[test]`) - rust-lang#130221 (Make SearchPath::new public) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f7f8bdf + 2f4edab commit 17527ef

File tree

97 files changed

+770
-826
lines changed

Some content is hidden

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

97 files changed

+770
-826
lines changed

compiler/rustc_builtin_macros/src/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ pub(crate) fn expand_test_or_bench(
277277
cx.attr_nested_word(sym::cfg, sym::test, attr_sp),
278278
// #[rustc_test_marker = "test_case_sort_key"]
279279
cx.attr_name_value_str(sym::rustc_test_marker, test_path_symbol, attr_sp),
280+
// #[doc(hidden)]
281+
cx.attr_nested_word(sym::doc, sym::hidden, attr_sp),
280282
],
281283
// const $ident: test::TestDescAndFn =
282284
ast::ItemKind::Const(

compiler/rustc_builtin_macros/src/test_harness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
326326
let main_attr = ecx.attr_word(sym::rustc_main, sp);
327327
// #[coverage(off)]
328328
let coverage_attr = ecx.attr_nested_word(sym::coverage, sym::off, sp);
329-
// #[allow(missing_docs)]
330-
let missing_docs_attr = ecx.attr_nested_word(sym::allow, sym::missing_docs, sp);
329+
// #[doc(hidden)]
330+
let doc_hidden_attr = ecx.attr_nested_word(sym::doc, sym::hidden, sp);
331331

332332
// pub fn main() { ... }
333333
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new()));
@@ -357,7 +357,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
357357

358358
let main = P(ast::Item {
359359
ident: main_id,
360-
attrs: thin_vec![main_attr, coverage_attr, missing_docs_attr],
360+
attrs: thin_vec![main_attr, coverage_attr, doc_hidden_attr],
361361
id: ast::DUMMY_NODE_ID,
362362
kind: main,
363363
vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None },

compiler/rustc_codegen_gcc/src/debuginfo.rs

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
4848
fn set_dbg_loc(&mut self, dbg_loc: Self::DILocation) {
4949
self.location = Some(dbg_loc);
5050
}
51+
52+
fn clear_dbg_loc(&mut self) {
53+
self.location = None;
54+
}
5155
}
5256

5357
/// Generate the `debug_context` in an MIR Body.

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![doc = include_str!("doc.md")]
22

33
use std::cell::{OnceCell, RefCell};
4-
use std::iter;
54
use std::ops::Range;
5+
use std::{iter, ptr};
66

77
use libc::c_uint;
88
use rustc_codegen_ssa::debuginfo::type_names;
@@ -209,6 +209,12 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
209209
}
210210
}
211211

212+
fn clear_dbg_loc(&mut self) {
213+
unsafe {
214+
llvm::LLVMSetCurrentDebugLocation2(self.llbuilder, ptr::null());
215+
}
216+
}
217+
212218
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
213219
gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
214220
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ unsafe extern "C" {
10411041
pub fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);
10421042

10431043
// Metadata
1044-
pub fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: &'a Metadata);
1044+
pub fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: *const Metadata);
10451045

10461046
// Terminators
10471047
pub fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value;

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+1
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
547547
self.set_debug_loc(bx, var.source_info);
548548
let base =
549549
Self::spill_operand_to_stack(operand, Some(var.name.to_string()), bx);
550+
bx.clear_dbg_loc();
550551

551552
bx.dbg_var_addr(
552553
dbg_var,

compiler/rustc_codegen_ssa/src/traits/debuginfo.rs

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub trait DebugInfoBuilderMethods: BackendTypes {
8080
fragment: Option<Range<Size>>,
8181
);
8282
fn set_dbg_loc(&mut self, dbg_loc: Self::DILocation);
83+
fn clear_dbg_loc(&mut self);
8384
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self);
8485
fn set_var_name(&mut self, value: Self::Value, name: &str);
8586
}

compiler/rustc_const_eval/src/check_consts/check.rs

-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
355355
{
356356
self.error_emitted = Some(guar);
357357
}
358-
self.check_op_spanned(ops::StaticAccess, span)
359358
}
360359

361360
fn check_local_or_return_ty(&mut self, ty: Ty<'tcx>, local: Local) {

compiler/rustc_const_eval/src/check_consts/ops.rs

-27
Original file line numberDiff line numberDiff line change
@@ -553,33 +553,6 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
553553
}
554554
}
555555

556-
/// An access to a (non-thread-local) `static`.
557-
#[derive(Debug)]
558-
pub(crate) struct StaticAccess;
559-
impl<'tcx> NonConstOp<'tcx> for StaticAccess {
560-
fn status_in_item(&self, ccx: &ConstCx<'_, 'tcx>) -> Status {
561-
if let hir::ConstContext::Static(_) = ccx.const_kind() {
562-
Status::Allowed
563-
} else {
564-
Status::Unstable(sym::const_refs_to_static)
565-
}
566-
}
567-
568-
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
569-
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
570-
let mut err = feature_err(
571-
&ccx.tcx.sess,
572-
sym::const_refs_to_static,
573-
span,
574-
format!("referencing statics in {}s is unstable", ccx.const_kind(),),
575-
);
576-
err
577-
.note("`static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable.")
578-
.help("to fix this, the value can be extracted to a `const` and then used.");
579-
err
580-
}
581-
}
582-
583556
/// An access to a thread-local `static`.
584557
#[derive(Debug)]
585558
pub(crate) struct ThreadLocalAccess;

compiler/rustc_error_codes/src/error_codes/E0013.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ variable cannot refer to a static variable.
55

66
Erroneous code example:
77

8-
```compile_fail,E0658
8+
```
99
static X: i32 = 42;
1010
const Y: i32 = X;
1111
```

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ declare_features! (
145145
(accepted, const_panic, "1.57.0", Some(51999)),
146146
/// Allows dereferencing raw pointers during const eval.
147147
(accepted, const_raw_ptr_deref, "1.58.0", Some(51911)),
148+
/// Allows creating pointers and references to `static` items in constants.
149+
(accepted, const_refs_to_static, "CURRENT_RUSTC_VERSION", Some(119618)),
148150
/// Allows implementing `Copy` for closures where possible (RFC 2132).
149151
(accepted, copy_closures, "1.26.0", Some(44490)),
150152
/// Allows `crate` in paths.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,6 @@ declare_features! (
413413
(unstable, const_precise_live_drops, "1.46.0", Some(73255)),
414414
/// Allows references to types with interior mutability within constants
415415
(unstable, const_refs_to_cell, "1.51.0", Some(80384)),
416-
/// Allows creating pointers and references to `static` items in constants.
417-
(unstable, const_refs_to_static, "1.78.0", Some(119618)),
418416
/// Allows `impl const Trait for T` syntax.
419417
(unstable, const_trait_impl, "1.42.0", Some(67792)),
420418
/// Allows the `?` operator in const contexts.

compiler/rustc_hir_typeck/src/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
389389
{
390390
// check that the `if` expr without `else` is the fn body's expr
391391
if expr.span == sp {
392-
return self.get_fn_decl(hir_id).map(|(_, fn_decl, _)| {
392+
return self.get_fn_decl(hir_id).map(|(_, fn_decl)| {
393393
let (ty, span) = match fn_decl.output {
394394
hir::FnRetTy::DefaultReturn(span) => ("()".to_string(), span),
395395
hir::FnRetTy::Return(ty) => (ty_to_string(&self.tcx, ty), ty.span),

compiler/rustc_hir_typeck/src/coercion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1860,10 +1860,10 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18601860
};
18611861

18621862
// If this is due to an explicit `return`, suggest adding a return type.
1863-
if let Some((fn_id, fn_decl, can_suggest)) = fcx.get_fn_decl(block_or_return_id)
1863+
if let Some((fn_id, fn_decl)) = fcx.get_fn_decl(block_or_return_id)
18641864
&& !due_to_block
18651865
{
1866-
fcx.suggest_missing_return_type(&mut err, fn_decl, expected, found, can_suggest, fn_id);
1866+
fcx.suggest_missing_return_type(&mut err, fn_decl, expected, found, fn_id);
18671867
}
18681868

18691869
// If this is due to a block, then maybe we forgot a `return`/`break`.

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
774774
self.ret_coercion_span.set(Some(expr.span));
775775
}
776776
let cause = self.cause(expr.span, ObligationCauseCode::ReturnNoExpression);
777-
if let Some((_, fn_decl, _)) = self.get_fn_decl(expr.hir_id) {
777+
if let Some((_, fn_decl)) = self.get_fn_decl(expr.hir_id) {
778778
coercion.coerce_forced_unit(
779779
self,
780780
&cause,

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+13-26
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::{bug, span_bug};
3030
use rustc_session::lint;
3131
use rustc_span::def_id::LocalDefId;
3232
use rustc_span::hygiene::DesugaringKind;
33-
use rustc_span::symbol::{kw, sym};
33+
use rustc_span::symbol::kw;
3434
use rustc_span::Span;
3535
use rustc_target::abi::FieldIdx;
3636
use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
@@ -859,38 +859,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
859859
)
860860
}
861861

862-
/// Given a `HirId`, return the `HirId` of the enclosing function, its `FnDecl`, and whether a
863-
/// suggestion can be made, `None` otherwise.
862+
/// Given a `HirId`, return the `HirId` of the enclosing function and its `FnDecl`.
864863
pub(crate) fn get_fn_decl(
865864
&self,
866865
blk_id: HirId,
867-
) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>, bool)> {
866+
) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>)> {
868867
// Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or
869868
// `while` before reaching it, as block tail returns are not available in them.
870869
self.tcx.hir().get_fn_id_for_return_block(blk_id).and_then(|item_id| {
871870
match self.tcx.hir_node(item_id) {
872871
Node::Item(&hir::Item {
873-
ident,
874-
kind: hir::ItemKind::Fn(ref sig, ..),
875-
owner_id,
876-
..
877-
}) => {
878-
// This is less than ideal, it will not suggest a return type span on any
879-
// method called `main`, regardless of whether it is actually the entry point,
880-
// but it will still present it as the reason for the expected type.
881-
Some((owner_id.def_id, sig.decl, ident.name != sym::main))
882-
}
872+
kind: hir::ItemKind::Fn(ref sig, ..), owner_id, ..
873+
}) => Some((owner_id.def_id, sig.decl)),
883874
Node::TraitItem(&hir::TraitItem {
884875
kind: hir::TraitItemKind::Fn(ref sig, ..),
885876
owner_id,
886877
..
887-
}) => Some((owner_id.def_id, sig.decl, true)),
888-
// FIXME: Suggestable if this is not a trait implementation
878+
}) => Some((owner_id.def_id, sig.decl)),
889879
Node::ImplItem(&hir::ImplItem {
890880
kind: hir::ImplItemKind::Fn(ref sig, ..),
891881
owner_id,
892882
..
893-
}) => Some((owner_id.def_id, sig.decl, false)),
883+
}) => Some((owner_id.def_id, sig.decl)),
894884
Node::Expr(&hir::Expr {
895885
hir_id,
896886
kind: hir::ExprKind::Closure(&hir::Closure { def_id, kind, fn_decl, .. }),
@@ -901,33 +891,30 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
901891
// FIXME(async_closures): Implement this.
902892
return None;
903893
}
904-
hir::ClosureKind::Closure => Some((def_id, fn_decl, true)),
894+
hir::ClosureKind::Closure => Some((def_id, fn_decl)),
905895
hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
906896
_,
907897
hir::CoroutineSource::Fn,
908898
)) => {
909-
let (ident, sig, owner_id) = match self.tcx.parent_hir_node(hir_id) {
899+
let (sig, owner_id) = match self.tcx.parent_hir_node(hir_id) {
910900
Node::Item(&hir::Item {
911-
ident,
912901
kind: hir::ItemKind::Fn(ref sig, ..),
913902
owner_id,
914903
..
915-
}) => (ident, sig, owner_id),
904+
}) => (sig, owner_id),
916905
Node::TraitItem(&hir::TraitItem {
917-
ident,
918906
kind: hir::TraitItemKind::Fn(ref sig, ..),
919907
owner_id,
920908
..
921-
}) => (ident, sig, owner_id),
909+
}) => (sig, owner_id),
922910
Node::ImplItem(&hir::ImplItem {
923-
ident,
924911
kind: hir::ImplItemKind::Fn(ref sig, ..),
925912
owner_id,
926913
..
927-
}) => (ident, sig, owner_id),
914+
}) => (sig, owner_id),
928915
_ => return None,
929916
};
930-
Some((owner_id.def_id, sig.decl, ident.name != sym::main))
917+
Some((owner_id.def_id, sig.decl))
931918
}
932919
_ => None,
933920
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18731873
// that highlight errors inline.
18741874
let mut sp = blk.span;
18751875
let mut fn_span = None;
1876-
if let Some((fn_def_id, decl, _)) = self.get_fn_decl(blk.hir_id) {
1876+
if let Some((fn_def_id, decl)) = self.get_fn_decl(blk.hir_id) {
18771877
let ret_sp = decl.output.span();
18781878
if let Some(block_sp) = self.parent_item_span(blk.hir_id) {
18791879
// HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+36-13
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7979
// `break` type mismatches provide better context for tail `loop` expressions.
8080
return false;
8181
}
82-
if let Some((fn_id, fn_decl, can_suggest)) = self.get_fn_decl(blk_id) {
82+
if let Some((fn_id, fn_decl)) = self.get_fn_decl(blk_id) {
8383
pointing_at_return_type =
84-
self.suggest_missing_return_type(err, fn_decl, expected, found, can_suggest, fn_id);
84+
self.suggest_missing_return_type(err, fn_decl, expected, found, fn_id);
8585
self.suggest_missing_break_or_return_expr(
8686
err, expr, fn_decl, expected, found, blk_id, fn_id,
8787
);
@@ -813,7 +813,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
813813
fn_decl: &hir::FnDecl<'tcx>,
814814
expected: Ty<'tcx>,
815815
found: Ty<'tcx>,
816-
can_suggest: bool,
817816
fn_id: LocalDefId,
818817
) -> bool {
819818
// Can't suggest `->` on a block-like coroutine
@@ -826,28 +825,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
826825
let found =
827826
self.resolve_numeric_literals_with_default(self.resolve_vars_if_possible(found));
828827
// Only suggest changing the return type for methods that
829-
// haven't set a return type at all (and aren't `fn main()` or an impl).
828+
// haven't set a return type at all (and aren't `fn main()`, impl or closure).
830829
match &fn_decl.output {
831-
&hir::FnRetTy::DefaultReturn(span) if expected.is_unit() && !can_suggest => {
832-
// `fn main()` must return `()`, do not suggest changing return type
833-
err.subdiagnostic(errors::ExpectedReturnTypeLabel::Unit { span });
834-
return true;
835-
}
830+
// For closure with default returns, don't suggest adding return type
831+
&hir::FnRetTy::DefaultReturn(_) if self.tcx.is_closure_like(fn_id.to_def_id()) => {}
836832
&hir::FnRetTy::DefaultReturn(span) if expected.is_unit() => {
837-
if let Some(found) = found.make_suggestable(self.tcx, false, None) {
833+
if !self.can_add_return_type(fn_id) {
834+
err.subdiagnostic(errors::ExpectedReturnTypeLabel::Unit { span });
835+
} else if let Some(found) = found.make_suggestable(self.tcx, false, None) {
838836
err.subdiagnostic(errors::AddReturnTypeSuggestion::Add {
839837
span,
840838
found: found.to_string(),
841839
});
842-
return true;
843840
} else if let Some(sugg) = suggest_impl_trait(self, self.param_env, found) {
844841
err.subdiagnostic(errors::AddReturnTypeSuggestion::Add { span, found: sugg });
845-
return true;
846842
} else {
847843
// FIXME: if `found` could be `impl Iterator` we should suggest that.
848844
err.subdiagnostic(errors::AddReturnTypeSuggestion::MissingHere { span });
849-
return true;
850845
}
846+
847+
return true;
851848
}
852849
hir::FnRetTy::Return(hir_ty) => {
853850
if let hir::TyKind::OpaqueDef(item_id, ..) = hir_ty.kind
@@ -905,6 +902,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
905902
false
906903
}
907904

905+
/// Checks whether we can add a return type to a function.
906+
/// Assumes given function doesn't have a explicit return type.
907+
fn can_add_return_type(&self, fn_id: LocalDefId) -> bool {
908+
match self.tcx.hir_node_by_def_id(fn_id) {
909+
Node::Item(&hir::Item { ident, .. }) => {
910+
// This is less than ideal, it will not suggest a return type span on any
911+
// method called `main`, regardless of whether it is actually the entry point,
912+
// but it will still present it as the reason for the expected type.
913+
ident.name != sym::main
914+
}
915+
Node::ImplItem(item) => {
916+
// If it doesn't impl a trait, we can add a return type
917+
let Node::Item(&hir::Item {
918+
kind: hir::ItemKind::Impl(&hir::Impl { of_trait, .. }),
919+
..
920+
}) = self.tcx.parent_hir_node(item.hir_id())
921+
else {
922+
unreachable!();
923+
};
924+
925+
of_trait.is_none()
926+
}
927+
_ => true,
928+
}
929+
}
930+
908931
fn try_note_caller_chooses_ty_for_ty_param(
909932
&self,
910933
diag: &mut Diag<'_>,

0 commit comments

Comments
 (0)