Skip to content

Commit 616a8f8

Browse files
committed
Auto merge of rust-lang#123814 - matthiaskrgr:rollup-lxn0t4t, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#123459 (Correctly handle inlining of doc hidden foreign items) - rust-lang#123740 (Reduce Size of `ModifierInfo`) - rust-lang#123770 (Correct broken link in core::pin doc) - rust-lang#123777 (Deduplicate some function implementations between the parser and AST/HIR) - rust-lang#123808 (codegen tests: Tolerate `nuw` `nsw` on `trunc`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents aa6a697 + a710de9 commit 616a8f8

File tree

11 files changed

+67
-72
lines changed

11 files changed

+67
-72
lines changed

compiler/rustc_ast/src/ast.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -920,14 +920,8 @@ impl BinOpKind {
920920
matches!(self, BinOpKind::And | BinOpKind::Or)
921921
}
922922

923-
pub fn is_comparison(&self) -> bool {
924-
use BinOpKind::*;
925-
// Note for developers: please keep this match exhaustive;
926-
// we want compilation to fail if another variant is added.
927-
match *self {
928-
Eq | Lt | Le | Ne | Gt | Ge => true,
929-
And | Or | Add | Sub | Mul | Div | Rem | BitXor | BitAnd | BitOr | Shl | Shr => false,
930-
}
923+
pub fn is_comparison(self) -> bool {
924+
crate::util::parser::AssocOp::from_ast_binop(self).is_comparison()
931925
}
932926

933927
/// Returns `true` if the binary operator takes its arguments by value.

compiler/rustc_hir_pretty/src/lib.rs

+1-28
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ impl<'a> State<'a> {
11421142
}
11431143

11441144
fn print_expr_binary(&mut self, op: hir::BinOp, lhs: &hir::Expr<'_>, rhs: &hir::Expr<'_>) {
1145-
let assoc_op = bin_op_to_assoc_op(op.node);
1145+
let assoc_op = AssocOp::from_ast_binop(op.node);
11461146
let prec = assoc_op.precedence() as i8;
11471147
let fixity = assoc_op.fixity();
11481148

@@ -2328,33 +2328,6 @@ fn stmt_ends_with_semi(stmt: &hir::StmtKind<'_>) -> bool {
23282328
}
23292329
}
23302330

2331-
fn bin_op_to_assoc_op(op: hir::BinOpKind) -> AssocOp {
2332-
use crate::hir::BinOpKind::*;
2333-
match op {
2334-
Add => AssocOp::Add,
2335-
Sub => AssocOp::Subtract,
2336-
Mul => AssocOp::Multiply,
2337-
Div => AssocOp::Divide,
2338-
Rem => AssocOp::Modulus,
2339-
2340-
And => AssocOp::LAnd,
2341-
Or => AssocOp::LOr,
2342-
2343-
BitXor => AssocOp::BitXor,
2344-
BitAnd => AssocOp::BitAnd,
2345-
BitOr => AssocOp::BitOr,
2346-
Shl => AssocOp::ShiftLeft,
2347-
Shr => AssocOp::ShiftRight,
2348-
2349-
Eq => AssocOp::Equal,
2350-
Lt => AssocOp::Less,
2351-
Le => AssocOp::LessEqual,
2352-
Ne => AssocOp::NotEqual,
2353-
Ge => AssocOp::GreaterEqual,
2354-
Gt => AssocOp::Greater,
2355-
}
2356-
}
2357-
23582331
/// Expressions that syntactically contain an "exterior" struct literal, i.e., not surrounded by any
23592332
/// parens or other delimiters, e.g., `X { y: 1 }`, `X { y: 1 }.method()`, `foo == X { y: 1 }` and
23602333
/// `X { y: 1 } == foo` all do, but `(X { y: 1 }) == foo` does not.

compiler/rustc_target/src/asm/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use std::str::FromStr;
99
pub struct ModifierInfo {
1010
pub modifier: char,
1111
pub result: &'static str,
12-
pub size: u64,
12+
pub size: u16,
1313
}
1414

15-
impl From<(char, &'static str, u64)> for ModifierInfo {
16-
fn from((modifier, result, size): (char, &'static str, u64)) -> Self {
15+
impl From<(char, &'static str, u16)> for ModifierInfo {
16+
fn from((modifier, result, size): (char, &'static str, u16)) -> Self {
1717
Self { modifier, result, size }
1818
}
1919
}

library/core/src/pin.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@
379379
//!
380380
//! Exposing access to the inner field which you want to remain pinned must then be carefully
381381
//! considered as well! Remember, exposing a method that gives access to a
382-
//! <code>[Pin]<[&mut] InnerT>></code> where `InnerT: [Unpin]` would allow safe code to trivially
383-
//! move the inner value out of that pinning pointer, which is precisely what you're seeking to
384-
//! prevent! Exposing a field of a pinned value through a pinning pointer is called "projecting"
385-
//! a pin, and the more general case of deciding in which cases a pin should be able to be
386-
//! projected or not is called "structural pinning." We will go into more detail about this
382+
//! <code>[Pin]<[&mut] InnerT>></code> where <code>InnerT: [Unpin]</code> would allow safe code to
383+
//! trivially move the inner value out of that pinning pointer, which is precisely what you're
384+
//! seeking to prevent! Exposing a field of a pinned value through a pinning pointer is called
385+
//! "projecting" a pin, and the more general case of deciding in which cases a pin should be able
386+
//! to be projected or not is called "structural pinning." We will go into more detail about this
387387
//! [below][structural-pinning].
388388
//!
389389
//! # Examples of address-sensitive types

src/librustdoc/clean/inline.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ pub(crate) fn try_inline(
6363

6464
let import_def_id = attrs.and_then(|(_, def_id)| def_id);
6565

66-
let (attrs, cfg) = merge_attrs(cx, load_attrs(cx, did), attrs);
67-
6866
let kind = match res {
6967
Res::Def(DefKind::Trait, did) => {
7068
record_extern_fqn(cx, did, ItemType::Trait);
@@ -134,7 +132,11 @@ pub(crate) fn try_inline(
134132
cx.with_param_env(did, |cx| clean::ConstantItem(build_const(cx, did)))
135133
}
136134
Res::Def(DefKind::Macro(kind), did) => {
137-
let mac = build_macro(cx, did, name, import_def_id, kind, attrs.is_doc_hidden());
135+
let is_doc_hidden = cx.tcx.is_doc_hidden(did)
136+
|| attrs_without_docs
137+
.map(|(attrs, _)| attrs)
138+
.is_some_and(|attrs| utils::attrs_have_doc_flag(attrs.iter(), sym::hidden));
139+
let mac = build_macro(cx, did, name, import_def_id, kind, is_doc_hidden);
138140

139141
let type_kind = match kind {
140142
MacroKind::Bang => ItemType::Macro,
@@ -148,8 +150,14 @@ pub(crate) fn try_inline(
148150
};
149151

150152
cx.inlined.insert(did.into());
151-
let mut item =
152-
clean::Item::from_def_id_and_attrs_and_parts(did, Some(name), kind, Box::new(attrs), cfg);
153+
let mut item = crate::clean::generate_item_with_correct_attrs(
154+
cx,
155+
kind,
156+
did,
157+
name,
158+
import_def_id.and_then(|def_id| def_id.as_local()),
159+
None,
160+
);
153161
// The visibility needs to reflect the one from the reexport and not from the "source" DefId.
154162
item.inline_stmt_id = import_def_id;
155163
ret.push(item);
@@ -179,6 +187,7 @@ pub(crate) fn try_inline_glob(
179187
.iter()
180188
.filter(|child| !child.reexport_chain.is_empty())
181189
.filter_map(|child| child.res.opt_def_id())
190+
.filter(|def_id| !cx.tcx.is_doc_hidden(def_id))
182191
.collect();
183192
let attrs = cx.tcx.hir().attrs(import.hir_id());
184193
let mut items = build_module_items(

src/librustdoc/clean/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -3007,22 +3007,22 @@ fn clean_use_statement_inner<'tcx>(
30073007
// were specifically asked for it
30083008
denied = true;
30093009
}
3010-
if !denied {
3011-
if let Some(mut items) = inline::try_inline(
3010+
if !denied
3011+
&& let Some(mut items) = inline::try_inline(
30123012
cx,
30133013
path.res,
30143014
name,
30153015
Some((attrs, Some(import_def_id))),
30163016
&mut Default::default(),
3017-
) {
3018-
items.push(Item::from_def_id_and_parts(
3019-
import_def_id,
3020-
None,
3021-
ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)),
3022-
cx,
3023-
));
3024-
return items;
3025-
}
3017+
)
3018+
{
3019+
items.push(Item::from_def_id_and_parts(
3020+
import_def_id,
3021+
None,
3022+
ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)),
3023+
cx,
3024+
));
3025+
return items;
30263026
}
30273027
Import::new_simple(name, resolve_use_source(cx, path), true)
30283028
};

src/librustdoc/clean/utils.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,14 @@ pub(crate) fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Opti
580580
/// This function exists because it runs on `hir::Attributes` whereas the other is a
581581
/// `clean::Attributes` method.
582582
pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool {
583-
tcx.get_attrs(did, sym::doc)
583+
attrs_have_doc_flag(tcx.get_attrs(did, sym::doc), flag)
584+
}
585+
586+
pub(crate) fn attrs_have_doc_flag<'a>(
587+
mut attrs: impl Iterator<Item = &'a ast::Attribute>,
588+
flag: Symbol,
589+
) -> bool {
590+
attrs
584591
.any(|attr| attr.meta_item_list().is_some_and(|l| rustc_attr::list_contains_name(&l, flag)))
585592
}
586593

src/librustdoc/formats/cache.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ impl Cache {
203203
impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
204204
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
205205
if item.item_id.is_local() {
206-
let is_stripped = matches!(*item.kind, clean::ItemKind::StrippedItem(..));
207206
debug!(
208-
"folding {} (stripped: {is_stripped:?}) \"{:?}\", id {:?}",
207+
"folding {} (stripped: {:?}) \"{:?}\", id {:?}",
209208
item.type_(),
209+
item.is_stripped(),
210210
item.name,
211211
item.item_id
212212
);
@@ -246,13 +246,11 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
246246
// trait.
247247
if let clean::TraitItem(ref t) = *item.kind {
248248
self.cache.traits.entry(item.item_id.expect_def_id()).or_insert_with(|| (**t).clone());
249-
}
250-
251-
// Collect all the implementors of traits.
252-
if let clean::ImplItem(ref i) = *item.kind
249+
} else if let clean::ImplItem(ref i) = *item.kind
253250
&& let Some(trait_) = &i.trait_
254251
&& !i.kind.is_blanket()
255252
{
253+
// Collect all the implementors of traits.
256254
self.cache
257255
.implementors
258256
.entry(trait_.def_id())

tests/codegen/ascii-char.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn unwrap_digit_from_remainder(v: u32) -> AsciiChar {
1212
// CHECK-NOT: panic
1313

1414
// CHECK: %[[R:.+]] = urem i32 %v, 10
15-
// CHECK-NEXT: %[[T:.+]] = trunc i32 %[[R]] to i8
15+
// CHECK-NEXT: %[[T:.+]] = trunc{{( nuw)?( nsw)?}} i32 %[[R]] to i8
1616
// CHECK-NEXT: %[[D:.+]] = or{{( disjoint)?}} i8 %[[T]], 48
1717
// CHECK-NEXT: ret i8 %[[D]]
1818

tests/codegen/unchecked_shifts.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub unsafe fn unchecked_shl_unsigned_smaller(a: u16, b: u32) -> u16 {
2222

2323
// CHECK-DAG: %[[INRANGE:.+]] = icmp ult i32 %b, 16
2424
// CHECK-DAG: tail call void @llvm.assume(i1 %[[INRANGE]])
25-
// CHECK-DAG: %[[TRUNC:.+]] = trunc i32 %b to i16
25+
// CHECK-DAG: %[[TRUNC:.+]] = trunc{{( nuw)?( nsw)?}} i32 %b to i16
2626
// CHECK-DAG: shl i16 %a, %[[TRUNC]]
2727
a.unchecked_shl(b)
2828
}
@@ -54,7 +54,7 @@ pub unsafe fn unchecked_shr_signed_smaller(a: i16, b: u32) -> i16 {
5454

5555
// CHECK-DAG: %[[INRANGE:.+]] = icmp ult i32 %b, 16
5656
// CHECK-DAG: tail call void @llvm.assume(i1 %[[INRANGE]])
57-
// CHECK-DAG: %[[TRUNC:.+]] = trunc i32 %b to i16
57+
// CHECK-DAG: %[[TRUNC:.+]] = trunc{{( nuw)?( nsw)?}} i32 %b to i16
5858
// CHECK-DAG: ashr i16 %a, %[[TRUNC]]
5959
a.unchecked_shr(b)
6060
}
@@ -94,7 +94,7 @@ pub unsafe fn unchecked_shl_u8_i128(a: u8, b: i128) -> u8 {
9494

9595
// CHECK-DAG: %[[INRANGE:.+]] = icmp ult i128 %b, 8
9696
// CHECK-DAG: tail call void @llvm.assume(i1 %[[INRANGE]])
97-
// CHECK-DAG: %[[TRUNC:.+]] = trunc i128 %b to i8
97+
// CHECK-DAG: %[[TRUNC:.+]] = trunc{{( nuw)?( nsw)?}} i128 %b to i8
9898
// CHECK-DAG: shl i8 %a, %[[TRUNC]]
9999
std::intrinsics::unchecked_shl(a, b)
100100
}
@@ -107,7 +107,7 @@ pub unsafe fn unchecked_shr_i8_u128(a: i8, b: u128) -> i8 {
107107

108108
// CHECK-DAG: %[[INRANGE:.+]] = icmp ult i128 %b, 8
109109
// CHECK-DAG: tail call void @llvm.assume(i1 %[[INRANGE]])
110-
// CHECK-DAG: %[[TRUNC:.+]] = trunc i128 %b to i8
110+
// CHECK-DAG: %[[TRUNC:.+]] = trunc{{( nuw)?( nsw)?}} i128 %b to i8
111111
// CHECK-DAG: ashr i8 %a, %[[TRUNC]]
112112
std::intrinsics::unchecked_shr(a, b)
113113
}

tests/rustdoc/inline_cross/inline_hidden.rs

+14
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,23 @@
44

55
extern crate rustdoc_hidden;
66

7+
// @has inline_hidden/index.html
8+
// Ensures this item is not inlined.
9+
// @has - '//*[@id="reexport.Foo"]/code' 'pub use rustdoc_hidden::Foo;'
710
#[doc(no_inline)]
811
pub use rustdoc_hidden::Foo;
912

13+
// Even if the foreign item has `doc(hidden)`, we should be able to inline it.
14+
// @has - '//*[@class="item-name"]/a[@class="struct"]' 'Inlined'
15+
#[doc(inline)]
16+
pub use rustdoc_hidden::Foo as Inlined;
17+
18+
// Even with this import, we should not see `Foo`.
19+
// @count - '//*[@class="item-name"]' 4
20+
// @has - '//*[@class="item-name"]/a[@class="struct"]' 'Bar'
21+
// @has - '//*[@class="item-name"]/a[@class="fn"]' 'foo'
22+
pub use rustdoc_hidden::*;
23+
1024
// @has inline_hidden/fn.foo.html
1125
// @!has - '//a/@title' 'Foo'
1226
pub fn foo(_: Foo) {}

0 commit comments

Comments
 (0)