Skip to content

Commit d384ff7

Browse files
committed
Auto merge of #91406 - matthiaskrgr:rollup-a2whn8m, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #91294 (Visit type in process_projection_elem.) - #91340 (Bump compiler_builtins to 0.1.55 to bring in fixes for targets lackin…) - #91366 (Only show notable traits if both types are the same) - #91397 (Emit a warning on generic parameters with doc comments) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 207c80f + 7baafb1 commit d384ff7

File tree

12 files changed

+92
-65
lines changed

12 files changed

+92
-65
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,9 @@ dependencies = [
678678

679679
[[package]]
680680
name = "compiler_builtins"
681-
version = "0.1.53"
681+
version = "0.1.55"
682682
source = "registry+https://github.com/rust-lang/crates.io-index"
683-
checksum = "2467ff455350a4df7d02f1ed1449d0279605a763de5d586dcf6aa7d732508bcb"
683+
checksum = "c9ac60765140c97aaf531dae151a287646b0805ec725805da9e2a3ee31cd501c"
684684
dependencies = [
685685
"cc",
686686
"rustc-std-workspace-core",

compiler/rustc_borrowck/src/renumber.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_index::vec::IndexVec;
22
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
33
use rustc_middle::mir::visit::{MutVisitor, TyContext};
4-
use rustc_middle::mir::{Body, Location, PlaceElem, Promoted};
4+
use rustc_middle::mir::{Body, Location, Promoted};
55
use rustc_middle::ty::subst::SubstsRef;
66
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
77

@@ -62,22 +62,6 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
6262
debug!(?ty);
6363
}
6464

65-
fn process_projection_elem(
66-
&mut self,
67-
elem: PlaceElem<'tcx>,
68-
_: Location,
69-
) -> Option<PlaceElem<'tcx>> {
70-
if let PlaceElem::Field(field, ty) = elem {
71-
let new_ty = self.renumber_regions(ty);
72-
73-
if new_ty != ty {
74-
return Some(PlaceElem::Field(field, new_ty));
75-
}
76-
}
77-
78-
None
79-
}
80-
8165
#[instrument(skip(self), level = "debug")]
8266
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
8367
*substs = self.renumber_regions(*substs);

compiler/rustc_lint/src/builtin.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,10 @@ impl EarlyLintPass for UnusedDocComment {
10791079
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
10801080
warn_if_doc(cx, expr.span, "expressions", &expr.attrs);
10811081
}
1082+
1083+
fn check_generic_param(&mut self, cx: &EarlyContext<'_>, param: &ast::GenericParam) {
1084+
warn_if_doc(cx, param.ident.span, "generic parameters", &param.attrs);
1085+
}
10821086
}
10831087

10841088
declare_lint! {

compiler/rustc_middle/src/mir/visit.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,12 @@ macro_rules! visit_place_fns {
10041004

10051005
if new_local == local { None } else { Some(PlaceElem::Index(new_local)) }
10061006
}
1007+
PlaceElem::Field(field, ty) => {
1008+
let mut new_ty = ty;
1009+
self.visit_ty(&mut new_ty, TyContext::Location(location));
1010+
if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
1011+
}
10071012
PlaceElem::Deref
1008-
| PlaceElem::Field(..)
10091013
| PlaceElem::ConstantIndex { .. }
10101014
| PlaceElem::Subslice { .. }
10111015
| PlaceElem::Downcast(..) => None,

compiler/rustc_mir_transform/src/dest_prop.rs

-22
Original file line numberDiff line numberDiff line change
@@ -316,28 +316,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> {
316316
}
317317
}
318318

319-
fn process_projection_elem(
320-
&mut self,
321-
elem: PlaceElem<'tcx>,
322-
_: Location,
323-
) -> Option<PlaceElem<'tcx>> {
324-
match elem {
325-
PlaceElem::Index(local) => {
326-
if let Some(replacement) = self.replacements.for_src(local) {
327-
bug!(
328-
"cannot replace {:?} with {:?} in index projection {:?}",
329-
local,
330-
replacement,
331-
elem,
332-
);
333-
} else {
334-
None
335-
}
336-
}
337-
_ => None,
338-
}
339-
}
340-
341319
fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) {
342320
if let Some(replacement) = self.replacements.for_src(place.local) {
343321
// Rebase `place`s projections onto `replacement`'s.

compiler/rustc_mir_transform/src/reveal_all.rs

-20
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,4 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
3535
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, _: TyContext) {
3636
*ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
3737
}
38-
39-
#[inline]
40-
fn process_projection_elem(
41-
&mut self,
42-
elem: PlaceElem<'tcx>,
43-
_: Location,
44-
) -> Option<PlaceElem<'tcx>> {
45-
match elem {
46-
PlaceElem::Field(field, ty) => {
47-
let new_ty = self.tcx.normalize_erasing_regions(self.param_env, ty);
48-
if ty != new_ty { Some(PlaceElem::Field(field, new_ty)) } else { None }
49-
}
50-
// None of those contain a Ty.
51-
PlaceElem::Index(..)
52-
| PlaceElem::Deref
53-
| PlaceElem::ConstantIndex { .. }
54-
| PlaceElem::Subslice { .. }
55-
| PlaceElem::Downcast(..) => None,
56-
}
57-
}
5838
}

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ panic_unwind = { path = "../panic_unwind", optional = true }
1616
panic_abort = { path = "../panic_abort" }
1717
core = { path = "../core" }
1818
libc = { version = "0.2.108", default-features = false, features = ['rustc-dep-of-std'] }
19-
compiler_builtins = { version = "0.1.53" }
19+
compiler_builtins = { version = "0.1.55" }
2020
profiler_builtins = { path = "../profiler_builtins", optional = true }
2121
unwind = { path = "../unwind" }
2222
hashbrown = { version = "0.11", default-features = false, features = ['rustc-dep-of-std'] }

src/librustdoc/clean/types.rs

+39
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,45 @@ crate enum Type {
14681468
rustc_data_structures::static_assert_size!(Type, 72);
14691469

14701470
impl Type {
1471+
/// When comparing types for equality, it can help to ignore `&` wrapping.
1472+
crate fn without_borrowed_ref(&self) -> &Type {
1473+
let mut result = self;
1474+
while let Type::BorrowedRef { type_, .. } = result {
1475+
result = &*type_;
1476+
}
1477+
result
1478+
}
1479+
1480+
/// Check if two types are "potentially the same".
1481+
/// This is different from `Eq`, because it knows that things like
1482+
/// `Placeholder` are possible matches for everything.
1483+
crate fn is_same(&self, other: &Self, cache: &Cache) -> bool {
1484+
match (self, other) {
1485+
// Recursive cases.
1486+
(Type::Tuple(a), Type::Tuple(b)) => {
1487+
a.len() == b.len() && a.iter().zip(b).all(|(a, b)| a.is_same(&b, cache))
1488+
}
1489+
(Type::Slice(a), Type::Slice(b)) => a.is_same(&b, cache),
1490+
(Type::Array(a, al), Type::Array(b, bl)) => al == bl && a.is_same(&b, cache),
1491+
(Type::RawPointer(mutability, type_), Type::RawPointer(b_mutability, b_type_)) => {
1492+
mutability == b_mutability && type_.is_same(&b_type_, cache)
1493+
}
1494+
(
1495+
Type::BorrowedRef { mutability, type_, .. },
1496+
Type::BorrowedRef { mutability: b_mutability, type_: b_type_, .. },
1497+
) => mutability == b_mutability && type_.is_same(&b_type_, cache),
1498+
// Placeholders and generics are equal to all other types.
1499+
(Type::Infer, _) | (_, Type::Infer) => true,
1500+
(Type::Generic(_), _) | (_, Type::Generic(_)) => true,
1501+
// Other cases, such as primitives, just use recursion.
1502+
(a, b) => a
1503+
.def_id(cache)
1504+
.and_then(|a| Some((a, b.def_id(cache)?)))
1505+
.map(|(a, b)| a == b)
1506+
.unwrap_or(false),
1507+
}
1508+
}
1509+
14711510
crate fn primitive_type(&self) -> Option<PrimitiveType> {
14721511
match *self {
14731512
Primitive(p) | BorrowedRef { type_: box Primitive(p), .. } => Some(p),

src/librustdoc/html/render/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1235,10 +1235,17 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
12351235
fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
12361236
let mut out = Buffer::html();
12371237

1238-
if let Some(did) = decl.output.as_return().and_then(|t| t.def_id(cx.cache())) {
1238+
if let Some((did, ty)) = decl.output.as_return().and_then(|t| Some((t.def_id(cx.cache())?, t)))
1239+
{
12391240
if let Some(impls) = cx.cache().impls.get(&did) {
12401241
for i in impls {
12411242
let impl_ = i.inner_impl();
1243+
if !impl_.for_.without_borrowed_ref().is_same(ty.without_borrowed_ref(), cx.cache())
1244+
{
1245+
// Two different types might have the same did,
1246+
// without actually being the same.
1247+
continue;
1248+
}
12421249
if let Some(trait_) = &impl_.trait_ {
12431250
let trait_did = trait_.def_id();
12441251

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(doc_notable_trait)]
2+
3+
#[doc(notable_trait)]
4+
pub trait SomeTrait {}
5+
6+
pub struct SomeStruct;
7+
pub struct OtherStruct;
8+
impl SomeTrait for &[SomeStruct] {}
9+
10+
// @has doc_notable_trait_slice/fn.bare_fn_matches.html
11+
// @has - '//code[@class="content"]' 'impl SomeTrait for &[SomeStruct]'
12+
pub fn bare_fn_matches() -> &'static [SomeStruct] {
13+
&[]
14+
}
15+
16+
// @has doc_notable_trait_slice/fn.bare_fn_no_matches.html
17+
// @!has - '//code[@class="content"]' 'impl SomeTrait for &[SomeStruct]'
18+
pub fn bare_fn_no_matches() -> &'static [OtherStruct] {
19+
&[]
20+
}

src/test/ui/lint/unused/unused-doc-comments-edge-cases.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ fn doc_comment_on_expr(num: u8) -> bool {
2626
num == 3
2727
}
2828

29+
fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {}
30+
//~^ ERROR: unused doc comment
31+
2932
fn main() {}

src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ LL | num == 3
4141
|
4242
= help: use `//` for a plain comment
4343

44+
error: unused doc comment
45+
--> $DIR/unused-doc-comments-edge-cases.rs:29:27
46+
|
47+
LL | fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {}
48+
| ^^^^^^^^^^^^ - rustdoc does not generate documentation for generic parameters
49+
|
50+
= help: use `//` for a plain comment
51+
4452
error[E0308]: mismatched types
4553
--> $DIR/unused-doc-comments-edge-cases.rs:14:9
4654
|
@@ -55,7 +63,7 @@ help: you might have meant to return this value
5563
LL | return true;
5664
| ++++++ +
5765

58-
error: aborting due to 5 previous errors
66+
error: aborting due to 6 previous errors
5967

6068
Some errors have detailed explanations: E0308, E0658.
6169
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)