Skip to content

Commit

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

Successful merges:

 - #103197 (Stabilize proc_macro::Span::source_text)
 - #103251 (Fix item declaration highlighting)
 - #103262 (Adjusting test to needs-unwind, with linking issue)
 - #103268 (rustdoc: remove no-op CSS `nav.sub { font-size: 1rem }`)
 - #103272 (Remove extra spaces in docs)
 - #103276 (Erase regions before checking for `Default` in uninitialized binding error)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 20, 2022
2 parents 53728ff + e29ecb7 commit 542febd
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 38 deletions.
11 changes: 9 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let Some(default_trait) = tcx.get_diagnostic_item(sym::Default) else {
return false;
};
// Regions are already solved, so we must use a fresh InferCtxt,
// but the type has region variables, so erase those.
tcx.infer_ctxt()
.build()
.type_implements_trait(default_trait, ty, ty::List::empty(), param_env)
.may_apply()
.type_implements_trait(
default_trait,
tcx.erase_regions(ty),
ty::List::empty(),
param_env,
)
.must_apply_modulo_regions()
};

let assign_value = match ty.kind() {
Expand Down
16 changes: 8 additions & 8 deletions library/core/src/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl AtomicBool {
/// ```
/// use std::sync::atomic::AtomicBool;
///
/// let atomic_true = AtomicBool::new(true);
/// let atomic_true = AtomicBool::new(true);
/// let atomic_false = AtomicBool::new(false);
/// ```
#[inline]
Expand Down Expand Up @@ -1179,7 +1179,7 @@ impl<T> AtomicPtr<T> {
/// use std::sync::atomic::{AtomicPtr, Ordering};
///
/// let ptr = &mut 5;
/// let some_ptr = AtomicPtr::new(ptr);
/// let some_ptr = AtomicPtr::new(ptr);
///
/// let value = some_ptr.load(Ordering::Relaxed);
/// ```
Expand All @@ -1206,7 +1206,7 @@ impl<T> AtomicPtr<T> {
/// use std::sync::atomic::{AtomicPtr, Ordering};
///
/// let ptr = &mut 5;
/// let some_ptr = AtomicPtr::new(ptr);
/// let some_ptr = AtomicPtr::new(ptr);
///
/// let other_ptr = &mut 10;
///
Expand Down Expand Up @@ -1238,7 +1238,7 @@ impl<T> AtomicPtr<T> {
/// use std::sync::atomic::{AtomicPtr, Ordering};
///
/// let ptr = &mut 5;
/// let some_ptr = AtomicPtr::new(ptr);
/// let some_ptr = AtomicPtr::new(ptr);
///
/// let other_ptr = &mut 10;
///
Expand Down Expand Up @@ -1290,9 +1290,9 @@ impl<T> AtomicPtr<T> {
/// use std::sync::atomic::{AtomicPtr, Ordering};
///
/// let ptr = &mut 5;
/// let some_ptr = AtomicPtr::new(ptr);
/// let some_ptr = AtomicPtr::new(ptr);
///
/// let other_ptr = &mut 10;
/// let other_ptr = &mut 10;
///
/// let value = some_ptr.compare_and_swap(ptr, other_ptr, Ordering::Relaxed);
/// ```
Expand Down Expand Up @@ -1333,9 +1333,9 @@ impl<T> AtomicPtr<T> {
/// use std::sync::atomic::{AtomicPtr, Ordering};
///
/// let ptr = &mut 5;
/// let some_ptr = AtomicPtr::new(ptr);
/// let some_ptr = AtomicPtr::new(ptr);
///
/// let other_ptr = &mut 10;
/// let other_ptr = &mut 10;
///
/// let value = some_ptr.compare_exchange(ptr, other_ptr,
/// Ordering::SeqCst, Ordering::Relaxed);
Expand Down
2 changes: 1 addition & 1 deletion library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl Span {
/// Note: The observable result of a macro should only rely on the tokens and
/// not on this source text. The result of this function is a best effort to
/// be used for diagnostics only.
#[unstable(feature = "proc_macro_span", issue = "54725")]
#[stable(feature = "proc_macro_source_text", since = "CURRENT_RUSTC_VERSION")]
pub fn source_text(&self) -> Option<String> {
self.0.source_text()
}
Expand Down
41 changes: 20 additions & 21 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -229,44 +229,44 @@ h1 a,
color: var(--main-color);
}

span.enum, a.enum,
span.struct, a.struct,
span.union, a.union,
span.primitive, a.primitive,
span.type, a.type,
span.foreigntype, a.foreigntype {
.content span.enum, .content a.enum,
.content span.struct, .content a.struct,
.content span.union, .content a.union,
.content span.primitive, .content a.primitive,
.content span.type, .content a.type,
.content span.foreigntype, .content a.foreigntype {
color: var(--type-link-color);
}

span.trait, a.trait,
span.traitalias, a.traitalias {
.content span.trait, .content a.trait,
.content span.traitalias, .content a.traitalias {
color: var(--trait-link-color);
}

span.associatedtype, a.associatedtype,
span.constant, a.constant,
span.static, a.static {
.content span.associatedtype, .content a.associatedtype,
.content span.constant, .content a.constant,
.content span.static, .content a.static {
color: var(--assoc-item-link-color);
}

span.fn, a.fn,
.fnname,
span.method, a.method,
span.tymethod, a.tymethod {
.content span.fn, .content a.fn,
.content .fnname,
.content span.method, .content a.method,
.content span.tymethod, .content a.tymethod {
color: var(--function-link-color);
}

span.attr, a.attr,
span.derive, a.derive,
span.macro, a.macro {
.content span.attr, .content a.attr,
.content span.derive, .content a.derive,
.content span.macro, .content a.macro {
color: var(--macro-link-color);
}

span.mod, a.mod {
.content span.mod, .content a.mod {
color: var(--mod-link-color);
}

span.keyword, a.keyword {
.content span.keyword, .content a.keyword {
color: var(--keyword-link-color);
}

Expand Down Expand Up @@ -697,7 +697,6 @@ pre, .rustdoc.source .example-wrap {

nav.sub {
position: relative;
font-size: 1rem;
flex-grow: 1;
margin-bottom: 25px;
}
Expand Down
74 changes: 74 additions & 0 deletions src/test/rustdoc-gui/item-decl-colors.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// This test ensures that the color of the items in the type decl are working as expected.
define-function: (
"check-colors",
(
theme,
attr_color,
trait_color,
struct_color,
enum_color,
primitive_color,
constant_color,
fn_color,
assoc_type_color,
),
[
("goto", "file://" + |DOC_PATH| + "/test_docs/struct.WithGenerics.html"),
("show-text", true),
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
("reload"),
("assert-css", (".item-decl .code-attribute", {"color": |attr_color|}, ALL)),
("assert-css", (".item-decl .trait", {"color": |trait_color|}, ALL)),
// We need to add `code` here because otherwise it would select the parent too.
("assert-css", (".item-decl code .struct", {"color": |struct_color|}, ALL)),
("assert-css", (".item-decl .enum", {"color": |enum_color|}, ALL)),
("assert-css", (".item-decl .primitive", {"color": |primitive_color|}, ALL)),
("goto", "file://" + |DOC_PATH| + "/test_docs/trait.TraitWithoutGenerics.html"),
("assert-css", (".item-decl .constant", {"color": |constant_color|}, ALL)),
("assert-css", (".item-decl .fnname", {"color": |fn_color|}, ALL)),
("assert-css", (".item-decl .associatedtype", {"color": |assoc_type_color|}, ALL)),
],
)

call-function: (
"check-colors",
{
"theme": "ayu",
"attr_color": "rgb(153, 153, 153)",
"trait_color": "rgb(57, 175, 215)",
"struct_color": "rgb(255, 160, 165)",
"enum_color": "rgb(255, 160, 165)",
"primitive_color": "rgb(255, 160, 165)",
"constant_color": "rgb(57, 175, 215)",
"fn_color": "rgb(253, 214, 135)",
"assoc_type_color": "rgb(57, 175, 215)",
},
)
call-function: (
"check-colors",
{
"theme": "dark",
"attr_color": "rgb(153, 153, 153)",
"trait_color": "rgb(183, 140, 242)",
"struct_color": "rgb(45, 191, 184)",
"enum_color": "rgb(45, 191, 184)",
"primitive_color": "rgb(45, 191, 184)",
"constant_color": "rgb(210, 153, 29)",
"fn_color": "rgb(43, 171, 99)",
"assoc_type_color": "rgb(210, 153, 29)",
},
)
call-function: (
"check-colors",
{
"theme": "light",
"attr_color": "rgb(153, 153, 153)",
"trait_color": "rgb(110, 79, 201)",
"struct_color": "rgb(173, 55, 138)",
"enum_color": "rgb(173, 55, 138)",
"primitive_color": "rgb(173, 55, 138)",
"constant_color": "rgb(56, 115, 173)",
"fn_color": "rgb(173, 124, 55)",
"assoc_type_color": "rgb(56, 115, 173)",
},
)
11 changes: 6 additions & 5 deletions src/test/rustdoc-gui/sidebar.goml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ assert-text: (".sidebar-elems section ul > li:nth-child(2)", "Modules")
assert-text: (".sidebar-elems section ul > li:nth-child(3)", "Macros")
assert-text: (".sidebar-elems section ul > li:nth-child(4)", "Structs")
assert-text: (".sidebar-elems section ul > li:nth-child(5)", "Enums")
assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Traits")
assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Functions")
assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Type Definitions")
assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Unions")
assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Keywords")
assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Constants")
assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Traits")
assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Functions")
assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Type Definitions")
assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Unions")
assert-text: (".sidebar-elems section ul > li:nth-child(11)", "Keywords")
assert-text: ("#structs + .item-table .item-left > a", "Foo")
click: "#structs + .item-table .item-left > a"

Expand Down
18 changes: 18 additions & 0 deletions src/test/rustdoc-gui/src/test_docs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![crate_name = "test_docs"]
#![feature(rustdoc_internals)]
#![feature(doc_cfg)]
#![feature(associated_type_defaults)]

/*!
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
Expand Down Expand Up @@ -386,3 +387,20 @@ impl TypeWithNoDocblocks {
pub unsafe fn unsafe_fn() {}

pub fn safe_fn() {}

#[repr(C)]
pub struct WithGenerics<T: TraitWithNoDocblocks, S = String, E = WhoLetTheDogOut, P = i8> {
s: S,
t: T,
e: E,
p: P,
}

pub const CONST: u8 = 0;

pub trait TraitWithoutGenerics {
const C: u8 = CONST;
type T = SomeType;

fn foo();
}
37 changes: 37 additions & 0 deletions src/test/ui/borrowck/issue-103250.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// edition:2021

type TranslateFn = Box<dyn Fn(String, String) -> String>;

pub struct DeviceCluster {
devices: Vec<Device>,
}

impl DeviceCluster {
pub async fn do_something(&mut self) -> Result<String, Box<dyn std::error::Error>> {
let mut last_error: Box<dyn std::error::Error>;

for device in &mut self.devices {
match device.do_something().await {
Ok(info) => {
return Ok(info);
}
Err(e) => {}
}
}

Err(last_error)
//~^ ERROR used binding `last_error` isn't initialized
}
}

pub struct Device {
translate_fn: Option<TranslateFn>,
}

impl Device {
pub async fn do_something(&mut self) -> Result<String, Box<dyn std::error::Error>> {
Ok(String::from(""))
}
}

fn main() {}
17 changes: 17 additions & 0 deletions src/test/ui/borrowck/issue-103250.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0381]: used binding `last_error` isn't initialized
--> $DIR/issue-103250.rs:22:13
|
LL | let mut last_error: Box<dyn std::error::Error>;
| -------------- binding declared here but left uninitialized
...
LL | Err(last_error)
| ^^^^^^^^^^ `last_error` used here but it isn't initialized
|
help: consider assigning a value
|
LL | let mut last_error: Box<dyn std::error::Error> = todo!();
| +++++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0381`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
// ignore-fuchsia Test must be run out-of-process
// needs-unwind (#73509)

#![feature(test)]

Expand Down

0 comments on commit 542febd

Please sign in to comment.