Skip to content

Commit 89b7830

Browse files
committed
Auto merge of #121955 - matthiaskrgr:rollup-1i3lo0j, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #121248 (Move some tests) - #121528 (Consider middle segments of paths in `unused_qualifications`) - #121749 (Don't lint on executable crates with `non_snake_case` names) - #121935 (library/ptr: mention that ptr::without_provenance is equivalent to deriving from the null ptr) - #121945 (Run some ui-fulldeps tests on stage 1 again) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 70aa0b8 + e5a6d21 commit 89b7830

File tree

59 files changed

+409
-168
lines changed

Some content is hidden

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

59 files changed

+409
-168
lines changed

compiler/rustc_lint/src/nonstandard_style.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_hir::def::{DefKind, Res};
1010
use rustc_hir::intravisit::FnKind;
1111
use rustc_hir::{GenericParamKind, PatKind};
1212
use rustc_middle::ty;
13+
use rustc_session::config::CrateType;
1314
use rustc_span::def_id::LocalDefId;
1415
use rustc_span::symbol::{sym, Ident};
1516
use rustc_span::{BytePos, Span};
@@ -331,6 +332,10 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
331332
return;
332333
}
333334

335+
if cx.tcx.crate_types().iter().all(|&crate_type| crate_type == CrateType::Executable) {
336+
return;
337+
}
338+
334339
let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name {
335340
Some(Ident::from_str(name))
336341
} else {

compiler/rustc_resolve/src/late.rs

+24-22
Original file line numberDiff line numberDiff line change
@@ -4150,34 +4150,36 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
41504150
PathResult::Indeterminate => bug!("indeterminate path result in resolve_qpath"),
41514151
};
41524152

4153-
if path.len() > 1
4154-
&& let Some(res) = result.full_res()
4155-
&& let Some((&last_segment, prev_segs)) = path.split_last()
4156-
&& prev_segs.iter().all(|seg| !seg.has_generic_args)
4157-
&& res != Res::Err
4158-
&& path[0].ident.name != kw::PathRoot
4159-
&& path[0].ident.name != kw::DollarCrate
4160-
{
4161-
let unqualified_result = {
4162-
match self.resolve_path(&[last_segment], Some(ns), None) {
4163-
PathResult::NonModule(path_res) => path_res.expect_full_res(),
4164-
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
4165-
module.res().unwrap()
4166-
}
4167-
_ => return Ok(Some(result)),
4168-
}
4169-
};
4170-
if res == unqualified_result {
4171-
let lint = lint::builtin::UNUSED_QUALIFICATIONS;
4153+
if path.iter().all(|seg| !seg.ident.span.from_expansion()) {
4154+
let end_pos =
4155+
path.iter().position(|seg| seg.has_generic_args).map_or(path.len(), |pos| pos + 1);
4156+
let unqualified =
4157+
path[..end_pos].iter().enumerate().skip(1).rev().find_map(|(i, seg)| {
4158+
// Preserve the current namespace for the final path segment, but use the type
4159+
// namespace for all preceding segments
4160+
//
4161+
// e.g. for `std::env::args` check the `ValueNS` for `args` but the `TypeNS` for
4162+
// `std` and `env`
4163+
//
4164+
// If the final path segment is beyond `end_pos` all the segments to check will
4165+
// use the type namespace
4166+
let ns = if i + 1 == path.len() { ns } else { TypeNS };
4167+
let res = self.r.partial_res_map.get(&seg.id?)?.full_res()?;
4168+
let binding = self.resolve_ident_in_lexical_scope(seg.ident, ns, None, None)?;
4169+
4170+
(res == binding.res()).then_some(seg)
4171+
});
4172+
4173+
if let Some(unqualified) = unqualified {
41724174
self.r.lint_buffer.buffer_lint_with_diagnostic(
4173-
lint,
4175+
lint::builtin::UNUSED_QUALIFICATIONS,
41744176
finalize.node_id,
41754177
finalize.path_span,
41764178
"unnecessary qualification",
41774179
lint::BuiltinLintDiagnostics::UnusedQualifications {
4178-
removal_span: finalize.path_span.until(last_segment.ident.span),
4180+
removal_span: finalize.path_span.until(unqualified.ident.span),
41794181
},
4180-
)
4182+
);
41814183
}
41824184
}
41834185

library/core/src/ptr/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {
574574

575575
/// Creates a pointer with the given address and no provenance.
576576
///
577+
/// This is equivalent to `ptr::null().with_addr(addr)`.
578+
///
577579
/// Without provenance, this pointer is not associated with any actual allocation. Such a
578580
/// no-provenance pointer may be used for zero-sized memory accesses (if suitably aligned), but
579581
/// non-zero-sized memory accesses with a no-provenance pointer are UB. No-provenance pointers are
@@ -616,6 +618,8 @@ pub const fn dangling<T>() -> *const T {
616618

617619
/// Creates a pointer with the given address and no provenance.
618620
///
621+
/// This is equivalent to `ptr::null_mut().with_addr(addr)`.
622+
///
619623
/// Without provenance, this pointer is not associated with any actual allocation. Such a
620624
/// no-provenance pointer may be used for zero-sized memory accesses (if suitably aligned), but
621625
/// non-zero-sized memory accesses with a no-provenance pointer are UB. No-provenance pointers are

0 commit comments

Comments
 (0)