Skip to content

Commit

Permalink
Auto merge of rust-lang#121955 - matthiaskrgr:rollup-1i3lo0j, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#121248 (Move some tests)
 - rust-lang#121528 (Consider middle segments of paths in `unused_qualifications`)
 - rust-lang#121749 (Don't lint on executable crates with `non_snake_case` names)
 - rust-lang#121935 (library/ptr: mention that ptr::without_provenance is equivalent to deriving from the null ptr)
 - rust-lang#121945 (Run some ui-fulldeps tests on stage 1 again)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 3, 2024
2 parents 516b616 + e5a6d21 commit 3fb9000
Show file tree
Hide file tree
Showing 59 changed files with 409 additions and 168 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_lint/src/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::FnKind;
use rustc_hir::{GenericParamKind, PatKind};
use rustc_middle::ty;
use rustc_session::config::CrateType;
use rustc_span::def_id::LocalDefId;
use rustc_span::symbol::{sym, Ident};
use rustc_span::{BytePos, Span};
Expand Down Expand Up @@ -331,6 +332,10 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
return;
}

if cx.tcx.crate_types().iter().all(|&crate_type| crate_type == CrateType::Executable) {
return;
}

let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name {
Some(Ident::from_str(name))
} else {
Expand Down
46 changes: 24 additions & 22 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4150,34 +4150,36 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
PathResult::Indeterminate => bug!("indeterminate path result in resolve_qpath"),
};

if path.len() > 1
&& let Some(res) = result.full_res()
&& let Some((&last_segment, prev_segs)) = path.split_last()
&& prev_segs.iter().all(|seg| !seg.has_generic_args)
&& res != Res::Err
&& path[0].ident.name != kw::PathRoot
&& path[0].ident.name != kw::DollarCrate
{
let unqualified_result = {
match self.resolve_path(&[last_segment], Some(ns), None) {
PathResult::NonModule(path_res) => path_res.expect_full_res(),
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
module.res().unwrap()
}
_ => return Ok(Some(result)),
}
};
if res == unqualified_result {
let lint = lint::builtin::UNUSED_QUALIFICATIONS;
if path.iter().all(|seg| !seg.ident.span.from_expansion()) {
let end_pos =
path.iter().position(|seg| seg.has_generic_args).map_or(path.len(), |pos| pos + 1);
let unqualified =
path[..end_pos].iter().enumerate().skip(1).rev().find_map(|(i, seg)| {
// Preserve the current namespace for the final path segment, but use the type
// namespace for all preceding segments
//
// e.g. for `std::env::args` check the `ValueNS` for `args` but the `TypeNS` for
// `std` and `env`
//
// If the final path segment is beyond `end_pos` all the segments to check will
// use the type namespace
let ns = if i + 1 == path.len() { ns } else { TypeNS };
let res = self.r.partial_res_map.get(&seg.id?)?.full_res()?;
let binding = self.resolve_ident_in_lexical_scope(seg.ident, ns, None, None)?;

(res == binding.res()).then_some(seg)
});

if let Some(unqualified) = unqualified {
self.r.lint_buffer.buffer_lint_with_diagnostic(
lint,
lint::builtin::UNUSED_QUALIFICATIONS,
finalize.node_id,
finalize.path_span,
"unnecessary qualification",
lint::BuiltinLintDiagnostics::UnusedQualifications {
removal_span: finalize.path_span.until(last_segment.ident.span),
removal_span: finalize.path_span.until(unqualified.ident.span),
},
)
);
}
}

Expand Down
4 changes: 4 additions & 0 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ pub const fn null_mut<T: ?Sized + Thin>() -> *mut T {

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

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

0 comments on commit 3fb9000

Please sign in to comment.