Skip to content

Commit

Permalink
Auto merge of #132099 - matthiaskrgr:rollup-myi94r8, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - #129248 (Taking a raw ref (`&raw (const|mut)`) of a deref of pointer (`*ptr`) is always safe)
 - #131906 (rustdoc: adjust spacing and typography in header)
 - #132084 (Consider param-env candidates even if they have errors)
 - #132096 (Replace an FTP link in comments with an equivalent HTTPS link)
 - #132098 (rustc_feature::Features: explain what that 'Option<Symbol>' is about)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 24, 2024
2 parents 8aca4ba + 7c22f47 commit 5ae4d75
Show file tree
Hide file tree
Showing 43 changed files with 156 additions and 204 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/graph/dominators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Algorithm based on Loukas Georgiadis,
//! "Linear-Time Algorithms for Dominators and Related Problems",
//! <ftp://ftp.cs.princeton.edu/techreports/2005/737.pdf>
//! <https://www.cs.princeton.edu/techreports/2005/737.pdf>
//!
//! Additionally useful is the original Lengauer-Tarjan paper on this subject,
//! "A Fast Algorithm for Finding Dominators in a Flowgraph"
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub struct Features {
}

impl Features {
/// `since` should be set for stable features that are nevertheless enabled with a `#[feature]`
/// attribute, indicating since when they are stable.
pub fn set_enabled_lang_feature(&mut self, name: Symbol, span: Span, since: Option<Symbol>) {
self.enabled_lang_features.push((name, span, since));
self.enabled_features.insert(name);
Expand All @@ -54,6 +56,10 @@ impl Features {
self.enabled_features.insert(name);
}

/// Returns a list of triples with:
/// - feature gate name
/// - the span of the `#[feature]` attribute
/// - (for already stable features) the version since which it is stable
pub fn enabled_lang_features(&self) -> &Vec<(Symbol, Span, Option<Symbol>)> {
&self.enabled_lang_features
}
Expand Down
26 changes: 17 additions & 9 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2657,8 +2657,8 @@ declare_lint! {
///
/// ### Explanation
///
/// Dereferencing a null pointer causes [undefined behavior] even as a place expression,
/// like `&*(0 as *const i32)` or `addr_of!(*(0 as *const i32))`.
/// Dereferencing a null pointer causes [undefined behavior] if it is accessed
/// (loaded from or stored to).
///
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
pub DEREF_NULLPTR,
Expand All @@ -2673,14 +2673,14 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
/// test if expression is a null ptr
fn is_null_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
match &expr.kind {
rustc_hir::ExprKind::Cast(expr, ty) => {
if let rustc_hir::TyKind::Ptr(_) = ty.kind {
hir::ExprKind::Cast(expr, ty) => {
if let hir::TyKind::Ptr(_) = ty.kind {
return is_zero(expr) || is_null_ptr(cx, expr);
}
}
// check for call to `core::ptr::null` or `core::ptr::null_mut`
rustc_hir::ExprKind::Call(path, _) => {
if let rustc_hir::ExprKind::Path(ref qpath) = path.kind {
hir::ExprKind::Call(path, _) => {
if let hir::ExprKind::Path(ref qpath) = path.kind {
if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id() {
return matches!(
cx.tcx.get_diagnostic_name(def_id),
Expand All @@ -2697,7 +2697,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
/// test if expression is the literal `0`
fn is_zero(expr: &hir::Expr<'_>) -> bool {
match &expr.kind {
rustc_hir::ExprKind::Lit(lit) => {
hir::ExprKind::Lit(lit) => {
if let LitKind::Int(a, _) = lit.node {
return a == 0;
}
Expand All @@ -2707,8 +2707,16 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
false
}

if let rustc_hir::ExprKind::Unary(rustc_hir::UnOp::Deref, expr_deref) = expr.kind {
if is_null_ptr(cx, expr_deref) {
if let hir::ExprKind::Unary(hir::UnOp::Deref, expr_deref) = expr.kind
&& is_null_ptr(cx, expr_deref)
{
if let hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::AddrOf(hir::BorrowKind::Raw, ..),
..
}) = cx.tcx.parent_hir_node(expr.hir_id)
{
// `&raw *NULL` is ok.
} else {
cx.emit_span_lint(DEREF_NULLPTR, expr.span, BuiltinDerefNullptr {
label: expr.span,
});
Expand Down
14 changes: 3 additions & 11 deletions compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,20 +509,12 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
}
ExprKind::RawBorrow { arg, .. } => {
if let ExprKind::Scope { value: arg, .. } = self.thir[arg].kind
// THIR desugars UNSAFE_STATIC into *UNSAFE_STATIC_REF, where
// UNSAFE_STATIC_REF holds the addr of the UNSAFE_STATIC, so: take two steps
&& let ExprKind::Deref { arg } = self.thir[arg].kind
// FIXME(workingjubiee): we lack a clear reason to reject ThreadLocalRef here,
// but we also have no conclusive reason to allow it either!
&& let ExprKind::StaticRef { .. } = self.thir[arg].kind
{
// A raw ref to a place expr, even an "unsafe static", is okay!
// We short-circuit to not recursively traverse this expression.
// Taking a raw ref to a deref place expr is always safe.
// Make sure the expression we're deref'ing is safe, though.
visit::walk_expr(self, &self.thir[arg]);
return;
// note: const_mut_refs enables this code, and it currently remains unsafe:
// static mut BYTE: u8 = 0;
// static mut BYTE_PTR: *mut u8 = unsafe { addr_of_mut!(BYTE) };
// static mut DEREF_BYTE_PTR: *mut u8 = unsafe { addr_of_mut!(*BYTE_PTR) };
}
}
ExprKind::Deref { arg } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.param_env
.caller_bounds()
.iter()
.filter(|p| !p.references_error())
.filter_map(|p| p.as_trait_clause())
// Micro-optimization: filter out predicates relating to different traits.
.filter(|p| p.def_id() == stack.obligation.predicate.def_id())
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2010,9 +2010,9 @@ fn render_rightside(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, render
);
if let Some(link) = src_href {
if has_stability {
write!(rightside, " · <a class=\"src\" href=\"{link}\">source</a>")
write!(rightside, " · <a class=\"src\" href=\"{link}\">Source</a>")
} else {
write!(rightside, "<a class=\"src rightside\" href=\"{link}\">source</a>")
write!(rightside, "<a class=\"src rightside\" href=\"{link}\">Source</a>")
}
}
if has_stability && has_src_ref {
Expand Down
10 changes: 8 additions & 2 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ h1, h2, h3, h4 {
grid-template-columns: minmax(105px, 1fr) minmax(0, max-content);
grid-template-rows: minmax(25px, min-content) min-content min-content;
padding-bottom: 6px;
margin-bottom: 11px;
margin-bottom: 15px;
}
.rustdoc-breadcrumbs {
grid-area: main-heading-breadcrumbs;
Expand Down Expand Up @@ -1004,6 +1004,7 @@ nav.sub {
display: flex;
height: 34px;
flex-grow: 1;
margin-bottom: 4px;
}
.src nav.sub {
margin: 0 0 -10px 0;
Expand Down Expand Up @@ -2253,7 +2254,12 @@ in src-script.js and main.js

/* We don't display this button on mobile devices. */
#copy-path {
display: none;
/* display: none; avoided as a layout hack.
When there's one line, we get an effective line-height of 34px,
because that's how big the image is, but if the header wraps,
they're packed more tightly than that. */
width: 0;
visibility: hidden;
}

/* Text label takes up too much space at this size. */
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/templates/print_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>
{% match src_href %}
{% when Some with (href) %}
{% if !stability_since_raw.is_empty() +%} · {%+ endif %}
<a class="src" href="{{href|safe}}">source</a> {#+ #}
<a class="src" href="{{href|safe}}">Source</a> {#+ #}
{% else %}
{% endmatch %}
</span> {# #}
Expand Down
28 changes: 0 additions & 28 deletions tests/crashes/110630.rs

This file was deleted.

27 changes: 0 additions & 27 deletions tests/crashes/115808.rs

This file was deleted.

32 changes: 0 additions & 32 deletions tests/crashes/121052.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/rustdoc-gui/item-info.goml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ store-position: (
{"x": second_line_x, "y": second_line_y},
)
assert: |first_line_x| != |second_line_x| && |first_line_x| == 516 && |second_line_x| == 272
assert: |first_line_y| != |second_line_y| && |first_line_y| == 714 && |second_line_y| == 737
assert: |first_line_y| != |second_line_y| && |first_line_y| == 718 && |second_line_y| == 741

// Now we ensure that they're not rendered on the same line.
set-window-size: (1100, 800)
Expand Down
8 changes: 4 additions & 4 deletions tests/rustdoc-gui/scrape-examples-layout.goml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ click: ".scraped-example .button-holder .expand"
store-value: (offset_y, 4)

// First with desktop
assert-position: (".scraped-example", {"y": 252})
assert-position: (".scraped-example .prev", {"y": 252 + |offset_y|})
assert-position: (".scraped-example", {"y": 256})
assert-position: (".scraped-example .prev", {"y": 256 + |offset_y|})

// Gradient background should be at the top of the code block.
assert-css: (".scraped-example .example-wrap::before", {"top": "0px"})
Expand All @@ -90,8 +90,8 @@ assert-css: (".scraped-example .example-wrap::after", {"bottom": "0px"})
// Then with mobile
set-window-size: (600, 600)
store-size: (".scraped-example .scraped-example-title", {"height": title_height})
assert-position: (".scraped-example", {"y": 287})
assert-position: (".scraped-example .prev", {"y": 287 + |offset_y| + |title_height|})
assert-position: (".scraped-example", {"y": 291})
assert-position: (".scraped-example .prev", {"y": 291 + |offset_y| + |title_height|})

define-function: (
"check_title_and_code_position",
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-gui/sidebar-source-code-display.goml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ click: "#sidebar-button"
wait-for-css: (".src .sidebar > *", {"visibility": "hidden"})
// We scroll to line 117 to change the scroll position.
scroll-to: '//*[@id="117"]'
store-value: (y_offset, "2570")
store-value: (y_offset, "2578")
assert-window-property: {"pageYOffset": |y_offset|}
// Expanding the sidebar...
click: "#sidebar-button"
Expand Down
8 changes: 4 additions & 4 deletions tests/rustdoc-gui/source-anchor-scroll.goml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ set-window-size: (600, 800)
assert-property: ("html", {"scrollTop": "0"})

click: '//a[text() = "barbar" and @href="#5-7"]'
assert-property: ("html", {"scrollTop": "200"})
assert-property: ("html", {"scrollTop": "208"})
click: '//a[text() = "bar" and @href="#28-36"]'
assert-property: ("html", {"scrollTop": "231"})
assert-property: ("html", {"scrollTop": "239"})
click: '//a[normalize-space() = "sub_fn" and @href="#2-4"]'
assert-property: ("html", {"scrollTop": "128"})
assert-property: ("html", {"scrollTop": "136"})

// We now check that clicking on lines doesn't change the scroll
// Extra information: the "sub_fn" function header is on line 1.
click: '//*[@id="6"]'
assert-property: ("html", {"scrollTop": "128"})
assert-property: ("html", {"scrollTop": "136"})
6 changes: 3 additions & 3 deletions tests/rustdoc-gui/source-code-page.goml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ assert-css: (".src-line-numbers", {"text-align": "right"})
// do anything (and certainly not add a `#NaN` to the URL!).
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
// We use this assert-position to know where we will click.
assert-position: ("//*[@id='1']", {"x": 88, "y": 163})
assert-position: ("//*[@id='1']", {"x": 88, "y": 171})
// We click on the left of the "1" anchor but still in the "src-line-number" `<pre>`.
click: (163, 77)
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
Expand Down Expand Up @@ -165,15 +165,15 @@ assert-css: ("nav.sub", {"flex-direction": "row"})
// offsetTop[nav.sub form] = offsetTop[#main-content] - offsetHeight[nav.sub form] - offsetTop[nav.sub form]
assert-position: ("nav.sub form", {"y": 15})
assert-property: ("nav.sub form", {"offsetHeight": 34})
assert-position: ("h1", {"y": 64})
assert-position: ("h1", {"y": 68})
// 15 = 64 - 34 - 15

// Now do the same check on moderately-sized, tablet mobile.
set-window-size: (700, 700)
assert-css: ("nav.sub", {"flex-direction": "row"})
assert-position: ("nav.sub form", {"y": 8})
assert-property: ("nav.sub form", {"offsetHeight": 34})
assert-position: ("h1", {"y": 50})
assert-position: ("h1", {"y": 54})
// 8 = 50 - 34 - 8

// Check the sidebar directory entries have a marker and spacing (tablet).
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc/anchors.no_const_anchor.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<section id="associatedconstant.YOLO" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#16">source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>
<section id="associatedconstant.YOLO" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#16">Source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>
2 changes: 1 addition & 1 deletion tests/rustdoc/anchors.no_const_anchor2.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<section id="associatedconstant.X" class="associatedconstant"><a class="src rightside" href="../src/foo/anchors.rs.html#42">source</a><h4 class="code-header">pub const <a href="#associatedconstant.X" class="constant">X</a>: <a class="primitive" href="{{channel}}/std/primitive.i32.html">i32</a> = 0i32</h4></section>
<section id="associatedconstant.X" class="associatedconstant"><a class="src rightside" href="../src/foo/anchors.rs.html#42">Source</a><h4 class="code-header">pub const <a href="#associatedconstant.X" class="constant">X</a>: <a class="primitive" href="{{channel}}/std/primitive.i32.html">i32</a> = 0i32</h4></section>
2 changes: 1 addition & 1 deletion tests/rustdoc/anchors.no_method_anchor.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<section id="method.new" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#48">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -&gt; Self</h4></section>
<section id="method.new" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#48">Source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -&gt; Self</h4></section>
2 changes: 1 addition & 1 deletion tests/rustdoc/anchors.no_trait_method_anchor.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<section id="method.bar" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#23">source</a><h4 class="code-header">fn <a href="#method.bar" class="fn">bar</a>()</h4></section>
<section id="method.bar" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#23">Source</a><h4 class="code-header">fn <a href="#method.bar" class="fn">bar</a>()</h4></section>
2 changes: 1 addition & 1 deletion tests/rustdoc/anchors.no_tymethod_anchor.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<section id="tymethod.foo" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#20">source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fn">foo</a>()</h4></section>
<section id="tymethod.foo" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#20">Source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fn">foo</a>()</h4></section>
2 changes: 1 addition & 1 deletion tests/rustdoc/anchors.no_type_anchor.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<section id="associatedtype.T" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#13">source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></section>
<section id="associatedtype.T" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#13">Source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></section>
2 changes: 1 addition & 1 deletion tests/rustdoc/anchors.no_type_anchor2.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<section id="associatedtype.Y" class="associatedtype"><a class="src rightside" href="../src/foo/anchors.rs.html#45">source</a><h4 class="code-header">pub type <a href="#associatedtype.Y" class="associatedtype">Y</a> = <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>
<section id="associatedtype.Y" class="associatedtype"><a class="src rightside" href="../src/foo/anchors.rs.html#45">Source</a><h4 class="code-header">pub type <a href="#associatedtype.Y" class="associatedtype">Y</a> = <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>
4 changes: 2 additions & 2 deletions tests/rustdoc/assoc-type-source-link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
pub struct Bar;

impl Bar {
//@ has - '//*[@id="implementations-list"]//*[@id="associatedtype.Y"]/a' 'source'
//@ has - '//*[@id="implementations-list"]//*[@id="associatedtype.Y"]/a' 'Source'
//@ has - '//*[@id="implementations-list"]//*[@id="associatedtype.Y"]/a/@href' \
// '../src/foo/assoc-type-source-link.rs.html#14'
pub type Y = u8;
Expand All @@ -19,7 +19,7 @@ pub trait Foo {
}

impl Foo for Bar {
//@ has - '//*[@id="trait-implementations-list"]//*[@id="associatedtype.Z"]/a' 'source'
//@ has - '//*[@id="trait-implementations-list"]//*[@id="associatedtype.Z"]/a' 'Source'
//@ has - '//*[@id="trait-implementations-list"]//*[@id="associatedtype.Z"]/a/@href' \
// '../src/foo/assoc-type-source-link.rs.html#25'
type Z = u8;
Expand Down
Loading

0 comments on commit 5ae4d75

Please sign in to comment.