Skip to content

Commit 021861a

Browse files
committed
Auto merge of #120239 - matthiaskrgr:rollup-vqjn6ot, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #118578 (core: introduce split_at{,_mut}_checked) - #119369 (exclude unexported macro bindings from extern crate) - #119408 (xous: misc fixes + add network support) - #119943 (std::net: bind update for using backlog as `-1` too.) - #119948 (Make `unsafe_op_in_unsafe_fn` migrated in edition 2024) - #119999 (remote-test: use u64 to represent file size) - #120152 (add help message for `exclusive_range_pattern` error) - #120213 (Don't actually make bound ty/const for RTN) - #120225 (Fix -Zremap-path-scope typo) Failed merges: - #119972 (Add `ErrCode`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3066253 + 44e44f4 commit 021861a

File tree

60 files changed

+2374
-314
lines changed

Some content is hidden

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

60 files changed

+2374
-314
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
398398
&self,
399399
exclusive_range_pattern,
400400
pattern.span,
401-
"exclusive range pattern syntax is experimental"
401+
"exclusive range pattern syntax is experimental",
402+
"use an inclusive range pattern, like N..=M"
402403
);
403404
}
404405
_ => {}

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+9-25
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
329329
}
330330

331331
let projection_ty = if let ty::AssocKind::Fn = assoc_kind {
332-
let mut emitted_bad_param_err = false;
332+
let mut emitted_bad_param_err = None;
333333
// If we have an method return type bound, then we need to substitute
334334
// the method's early bound params with suitable late-bound params.
335335
let mut num_bound_vars = candidate.bound_vars().len();
@@ -346,46 +346,30 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
346346
)
347347
.into(),
348348
ty::GenericParamDefKind::Type { .. } => {
349-
if !emitted_bad_param_err {
349+
let guar = *emitted_bad_param_err.get_or_insert_with(|| {
350350
tcx.dcx().emit_err(
351351
crate::errors::ReturnTypeNotationIllegalParam::Type {
352352
span: path_span,
353353
param_span: tcx.def_span(param.def_id),
354354
},
355-
);
356-
emitted_bad_param_err = true;
357-
}
358-
Ty::new_bound(
359-
tcx,
360-
ty::INNERMOST,
361-
ty::BoundTy {
362-
var: ty::BoundVar::from_usize(num_bound_vars),
363-
kind: ty::BoundTyKind::Param(param.def_id, param.name),
364-
},
365-
)
366-
.into()
355+
)
356+
});
357+
Ty::new_error(tcx, guar).into()
367358
}
368359
ty::GenericParamDefKind::Const { .. } => {
369-
if !emitted_bad_param_err {
360+
let guar = *emitted_bad_param_err.get_or_insert_with(|| {
370361
tcx.dcx().emit_err(
371362
crate::errors::ReturnTypeNotationIllegalParam::Const {
372363
span: path_span,
373364
param_span: tcx.def_span(param.def_id),
374365
},
375-
);
376-
emitted_bad_param_err = true;
377-
}
366+
)
367+
});
378368
let ty = tcx
379369
.type_of(param.def_id)
380370
.no_bound_vars()
381371
.expect("ct params cannot have early bound vars");
382-
ty::Const::new_bound(
383-
tcx,
384-
ty::INNERMOST,
385-
ty::BoundVar::from_usize(num_bound_vars),
386-
ty,
387-
)
388-
.into()
372+
ty::Const::new_error(tcx, guar, ty).into()
389373
}
390374
};
391375
num_bound_vars += 1;

compiler/rustc_lint_defs/src/builtin.rs

+52
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,11 @@ declare_lint! {
27552755
pub UNSAFE_OP_IN_UNSAFE_FN,
27562756
Allow,
27572757
"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2758+
@future_incompatible = FutureIncompatibleInfo {
2759+
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
2760+
reference: "issue #71668 <https://github.com/rust-lang/rust/issues/71668>",
2761+
explain_reason: false
2762+
};
27582763
@edition Edition2024 => Warn;
27592764
}
27602765

@@ -4604,3 +4609,50 @@ declare_lint! {
46044609
reference: "issue #X <https://github.com/rust-lang/rust/issues/X>",
46054610
};
46064611
}
4612+
4613+
declare_lint! {
4614+
/// The `private_macro_use` lint detects private macros that are imported
4615+
/// with `#[macro_use]`.
4616+
///
4617+
/// ### Example
4618+
///
4619+
/// ```rust,ignore (needs extern crate)
4620+
/// // extern_macro.rs
4621+
/// macro_rules! foo_ { () => {}; }
4622+
/// use foo_ as foo;
4623+
///
4624+
/// // code.rs
4625+
///
4626+
/// #![deny(private_macro_use)]
4627+
///
4628+
/// #[macro_use]
4629+
/// extern crate extern_macro;
4630+
///
4631+
/// fn main() {
4632+
/// foo!();
4633+
/// }
4634+
/// ```
4635+
///
4636+
/// This will produce:
4637+
///
4638+
/// ```text
4639+
/// error: cannot find macro `foo` in this scope
4640+
/// ```
4641+
///
4642+
/// ### Explanation
4643+
///
4644+
/// This lint arises from overlooking visibility checks for macros
4645+
/// in an external crate.
4646+
///
4647+
/// This is a [future-incompatible] lint to transition this to a
4648+
/// hard error in the future.
4649+
///
4650+
/// [future-incompatible]: ../index.md#future-incompatible-lints
4651+
pub PRIVATE_MACRO_USE,
4652+
Warn,
4653+
"detects certain macro bindings that should not be re-exported",
4654+
@future_incompatible = FutureIncompatibleInfo {
4655+
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
4656+
reference: "issue #120192 <https://github.com/rust-lang/rust/issues/120192>",
4657+
};
4658+
}

compiler/rustc_mir_build/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl AddToDiagnostic for UnsafeNotInheritedLintNote {
430430
diag.tool_only_multipart_suggestion(
431431
fluent::mir_build_wrap_suggestion,
432432
vec![(body_start, "{ unsafe ".into()), (body_end, "}".into())],
433-
Applicability::MaybeIncorrect,
433+
Applicability::MachineApplicable,
434434
);
435435
}
436436
}

compiler/rustc_resolve/src/build_reduced_graph.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -1029,9 +1029,9 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10291029
}
10301030
}
10311031

1032-
let macro_use_import = |this: &Self, span| {
1032+
let macro_use_import = |this: &Self, span, warn_private| {
10331033
this.r.arenas.alloc_import(ImportData {
1034-
kind: ImportKind::MacroUse,
1034+
kind: ImportKind::MacroUse { warn_private },
10351035
root_id: item.id,
10361036
parent_scope: this.parent_scope,
10371037
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
@@ -1048,11 +1048,25 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10481048

10491049
let allow_shadowing = self.parent_scope.expansion == LocalExpnId::ROOT;
10501050
if let Some(span) = import_all {
1051-
let import = macro_use_import(self, span);
1051+
let import = macro_use_import(self, span, false);
10521052
self.r.potentially_unused_imports.push(import);
10531053
module.for_each_child(self, |this, ident, ns, binding| {
10541054
if ns == MacroNS {
1055-
let imported_binding = this.r.import(binding, import);
1055+
let imported_binding =
1056+
if this.r.is_accessible_from(binding.vis, this.parent_scope.module) {
1057+
this.r.import(binding, import)
1058+
} else if !this.r.is_builtin_macro(binding.res())
1059+
&& !this.r.macro_use_prelude.contains_key(&ident.name)
1060+
{
1061+
// - `!r.is_builtin_macro(res)` excluding the built-in macros such as `Debug` or `Hash`.
1062+
// - `!r.macro_use_prelude.contains_key(name)` excluding macros defined in other extern
1063+
// crates such as `std`.
1064+
// FIXME: This branch should eventually be removed.
1065+
let import = macro_use_import(this, span, true);
1066+
this.r.import(binding, import)
1067+
} else {
1068+
return;
1069+
};
10561070
this.add_macro_use_binding(ident.name, imported_binding, span, allow_shadowing);
10571071
}
10581072
});
@@ -1065,7 +1079,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10651079
&self.parent_scope,
10661080
);
10671081
if let Ok(binding) = result {
1068-
let import = macro_use_import(self, ident.span);
1082+
let import = macro_use_import(self, ident.span, false);
10691083
self.r.potentially_unused_imports.push(import);
10701084
let imported_binding = self.r.import(binding, import);
10711085
self.add_macro_use_binding(

compiler/rustc_resolve/src/check_unused.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl Resolver<'_, '_> {
290290
|| import.expect_vis().is_public()
291291
|| import.span.is_dummy() =>
292292
{
293-
if let ImportKind::MacroUse = import.kind {
293+
if let ImportKind::MacroUse { .. } = import.kind {
294294
if !import.span.is_dummy() {
295295
self.lint_buffer.buffer_lint(
296296
MACRO_USE_EXTERN_CRATE,
@@ -315,7 +315,7 @@ impl Resolver<'_, '_> {
315315
maybe_unused_extern_crates.insert(id, import.span);
316316
}
317317
}
318-
ImportKind::MacroUse => {
318+
ImportKind::MacroUse { .. } => {
319319
let msg = "unused `#[macro_use]` import";
320320
self.lint_buffer.buffer_lint(UNUSED_IMPORTS, import.root_id, import.span, msg);
321321
}

compiler/rustc_resolve/src/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
285285
use NameBindingKind::Import;
286286
let can_suggest = |binding: NameBinding<'_>, import: self::Import<'_>| {
287287
!binding.span.is_dummy()
288-
&& !matches!(import.kind, ImportKind::MacroUse | ImportKind::MacroExport)
288+
&& !matches!(import.kind, ImportKind::MacroUse { .. } | ImportKind::MacroExport)
289289
};
290290
let import = match (&new_binding.kind, &old_binding.kind) {
291291
// If there are two imports where one or both have attributes then prefer removing the
@@ -1819,9 +1819,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18191819
next_ident = source;
18201820
Some(binding)
18211821
}
1822-
ImportKind::Glob { .. } | ImportKind::MacroUse | ImportKind::MacroExport => {
1823-
Some(binding)
1824-
}
1822+
ImportKind::Glob { .. }
1823+
| ImportKind::MacroUse { .. }
1824+
| ImportKind::MacroExport => Some(binding),
18251825
ImportKind::ExternCrate { .. } => None,
18261826
},
18271827
_ => None,

compiler/rustc_resolve/src/imports.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ pub(crate) enum ImportKind<'a> {
8080
target: Ident,
8181
id: NodeId,
8282
},
83-
MacroUse,
83+
MacroUse {
84+
/// A field has been added indicating whether it should be reported as a lint,
85+
/// addressing issue#119301.
86+
warn_private: bool,
87+
},
8488
MacroExport,
8589
}
8690

@@ -127,7 +131,7 @@ impl<'a> std::fmt::Debug for ImportKind<'a> {
127131
.field("target", target)
128132
.field("id", id)
129133
.finish(),
130-
MacroUse => f.debug_struct("MacroUse").finish(),
134+
MacroUse { .. } => f.debug_struct("MacroUse").finish(),
131135
MacroExport => f.debug_struct("MacroExport").finish(),
132136
}
133137
}
@@ -197,7 +201,7 @@ impl<'a> ImportData<'a> {
197201
ImportKind::Single { id, .. }
198202
| ImportKind::Glob { id, .. }
199203
| ImportKind::ExternCrate { id, .. } => Some(id),
200-
ImportKind::MacroUse | ImportKind::MacroExport => None,
204+
ImportKind::MacroUse { .. } | ImportKind::MacroExport => None,
201205
}
202206
}
203207

@@ -207,7 +211,7 @@ impl<'a> ImportData<'a> {
207211
ImportKind::Single { id, .. } => Reexport::Single(to_def_id(id)),
208212
ImportKind::Glob { id, .. } => Reexport::Glob(to_def_id(id)),
209213
ImportKind::ExternCrate { id, .. } => Reexport::ExternCrate(to_def_id(id)),
210-
ImportKind::MacroUse => Reexport::MacroUse,
214+
ImportKind::MacroUse { .. } => Reexport::MacroUse,
211215
ImportKind::MacroExport => Reexport::MacroExport,
212216
}
213217
}
@@ -1482,7 +1486,7 @@ fn import_kind_to_string(import_kind: &ImportKind<'_>) -> String {
14821486
ImportKind::Single { source, .. } => source.to_string(),
14831487
ImportKind::Glob { .. } => "*".to_string(),
14841488
ImportKind::ExternCrate { .. } => "<extern crate>".to_string(),
1485-
ImportKind::MacroUse => "#[macro_use]".to_string(),
1489+
ImportKind::MacroUse { .. } => "#[macro_use]".to_string(),
14861490
ImportKind::MacroExport => "#[macro_export]".to_string(),
14871491
}
14881492
}

compiler/rustc_resolve/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ use rustc_middle::span_bug;
5555
use rustc_middle::ty::{self, MainDefinition, RegisteredTools, TyCtxt};
5656
use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs};
5757
use rustc_query_system::ich::StableHashingContext;
58+
use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
5859
use rustc_session::lint::LintBuffer;
5960
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
6061
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -1799,6 +1800,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
17991800
}
18001801
}
18011802
if let NameBindingKind::Import { import, binding, ref used } = used_binding.kind {
1803+
if let ImportKind::MacroUse { warn_private: true } = import.kind {
1804+
let msg = format!("macro `{ident}` is private");
1805+
self.lint_buffer().buffer_lint(PRIVATE_MACRO_USE, import.root_id, ident.span, msg);
1806+
}
18021807
// Avoid marking `extern crate` items that refer to a name from extern prelude,
18031808
// but not introduce it, as used if they are accessed from lexical scope.
18041809
if is_lexical_scope {

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
#![feature(set_ptr_value)]
186186
#![feature(slice_ptr_get)]
187187
#![feature(slice_split_at_unchecked)]
188+
#![feature(split_at_checked)]
188189
#![feature(str_internals)]
189190
#![feature(str_split_inclusive_remainder)]
190191
#![feature(str_split_remainder)]

0 commit comments

Comments
 (0)