Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,7 @@ fn fat_lto(
let data = bc_decoded.data();

unsafe {
if !llvm::LLVMRustLinkerAdd(
linker,
data.as_ptr() as *const libc::c_char,
data.len(),
) {
if !llvm::LLVMRustLinkerAdd(linker, data.as_ptr(), data.len()) {
llvm::LLVMRustLinkerFree(linker);
write::llvm_err(dcx, LlvmError::LoadBitcode { name })
}
Expand All @@ -327,10 +323,9 @@ fn fat_lto(

// Internalize everything below threshold to help strip out more modules and such.
unsafe {
let ptr = symbols_below_threshold.as_ptr();
llvm::LLVMRustRunRestrictionPass(
llmod,
ptr as *const *const libc::c_char,
symbols_below_threshold.as_ptr(),
symbols_below_threshold.len() as libc::size_t,
);
}
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,20 +470,14 @@ pub(crate) fn val_ty(v: &Value) -> &Type {
}

pub(crate) fn bytes_in_context<'ll>(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
unsafe {
let ptr = bytes.as_ptr() as *const c_char;
llvm::LLVMConstStringInContext2(llcx, ptr, bytes.len(), TRUE)
}
unsafe { llvm::LLVMConstStringInContext2(llcx, bytes.as_ptr(), bytes.len(), TRUE) }
}

pub(crate) fn null_terminate_bytes_in_context<'ll>(
llcx: &'ll llvm::Context,
bytes: &[u8],
) -> &'ll Value {
unsafe {
let ptr = bytes.as_ptr() as *const c_char;
llvm::LLVMConstStringInContext2(llcx, ptr, bytes.len(), FALSE)
}
unsafe { llvm::LLVMConstStringInContext2(llcx, bytes.as_ptr(), bytes.len(), FALSE) }
}

pub(crate) fn named_struct<'ll>(ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value {
Expand Down
14 changes: 3 additions & 11 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::{Borrow, Cow};
use std::cell::{Cell, RefCell};
use std::ffi::{CStr, c_char, c_uint};
use std::ffi::{CStr, c_uint};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::str;
Expand Down Expand Up @@ -911,19 +911,11 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
}

pub(crate) fn get_md_kind_id(&self, name: &str) -> llvm::MetadataKindId {
unsafe {
llvm::LLVMGetMDKindIDInContext(
self.llcx(),
name.as_ptr() as *const c_char,
name.len() as c_uint,
)
}
unsafe { llvm::LLVMGetMDKindIDInContext(self.llcx(), name.as_ptr(), name.len() as c_uint) }
}

pub(crate) fn create_metadata(&self, name: &[u8]) -> &'ll Metadata {
unsafe {
llvm::LLVMMDStringInContext2(self.llcx(), name.as_ptr() as *const c_char, name.len())
}
unsafe { llvm::LLVMMDStringInContext2(self.llcx(), name.as_ptr(), name.len()) }
}

pub(crate) fn get_functions(&self) -> Vec<&'ll Value> {
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,7 @@ pub(crate) mod Enzyme_AD {
let c_fun_name = std::ffi::CString::new(fun_name)
.unwrap_or_else(|err| bug!("failed to set_print_type_fun: {err}"));
unsafe {
(self.EnzymeSetCLString)(
self.EnzymeFunctionToAnalyze,
c_fun_name.as_ptr() as *const c_char,
);
(self.EnzymeSetCLString)(self.EnzymeFunctionToAnalyze, c_fun_name.as_ptr());
}
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ unsafe extern "C" {
pub(crate) fn LLVMContextSetDiscardValueNames(C: &Context, Discard: Bool);
pub(crate) fn LLVMGetMDKindIDInContext(
C: &Context,
Name: *const c_char,
Name: *const c_uchar, // See "PTR_LEN_STR".
SLen: c_uint,
) -> MetadataKindId;

Expand Down Expand Up @@ -1009,7 +1009,7 @@ unsafe extern "C" {
// Operations on metadata
pub(crate) fn LLVMMDStringInContext2(
C: &Context,
Str: *const c_char,
Str: *const c_uchar, // See "PTR_LEN_STR".
SLen: size_t,
) -> &Metadata;
pub(crate) fn LLVMMDNodeInContext2<'a>(
Expand Down Expand Up @@ -1042,7 +1042,7 @@ unsafe extern "C" {
pub(crate) fn LLVMArrayType2(ElementType: &Type, ElementCount: u64) -> &Type;
pub(crate) fn LLVMConstStringInContext2(
C: &Context,
Str: *const c_char,
Str: *const c_uchar, // See "PTR_LEN_STR".
Length: size_t,
DontNullTerminate: Bool,
) -> &Value;
Expand Down Expand Up @@ -2561,7 +2561,7 @@ unsafe extern "C" {
pub(crate) fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
pub(crate) fn LLVMRustLinkerAdd(
linker: &Linker<'_>,
bytecode: *const c_char,
bytecode: *const c_uchar, // See "PTR_LEN_STR".
bytecode_len: usize,
) -> bool;
pub(crate) fn LLVMRustLinkerFree<'a>(linker: &'a mut Linker<'a>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
{
self.tcx.def_span(def.did())
}
ty::Closure(def_id, _) => self.tcx.def_span(*def_id),
_ => DUMMY_SP,
};
if let Some(s) = label {
Expand Down
19 changes: 10 additions & 9 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl Duration {
} else {
let secs = secs
.checked_add((nanos / NANOS_PER_SEC) as u64)
.expect("overflow in Duration::new");
.expect("adding carry-over seconds from nanoseconds should not exceed u64::MAX");
let nanos = nanos % NANOS_PER_SEC;
// SAFETY: nanos % NANOS_PER_SEC < NANOS_PER_SEC, therefore nanos is within the valid range
Duration { secs, nanos: unsafe { Nanoseconds::new_unchecked(nanos) } }
Expand Down Expand Up @@ -1342,7 +1342,7 @@ const impl Add for Duration {

#[inline]
fn add(self, rhs: Duration) -> Duration {
self.checked_add(rhs).expect("overflow when adding durations")
self.checked_add(rhs).expect("adding durations should not exceed u64::MAX")
}
}

Expand All @@ -1362,7 +1362,7 @@ const impl Sub for Duration {

#[inline]
fn sub(self, rhs: Duration) -> Duration {
self.checked_sub(rhs).expect("overflow when subtracting durations")
self.checked_sub(rhs).expect("subtracting durations should not be negative")
}
}

Expand All @@ -1382,7 +1382,7 @@ const impl Mul<u32> for Duration {

#[inline]
fn mul(self, rhs: u32) -> Duration {
self.checked_mul(rhs).expect("overflow when multiplying duration by scalar")
self.checked_mul(rhs).expect("multiplying duration by scalar should not exceed u64::MAX")
}
}

Expand Down Expand Up @@ -1414,7 +1414,7 @@ const impl Div<u32> for Duration {
#[inline]
#[track_caller]
fn div(self, rhs: u32) -> Duration {
self.checked_div(rhs).expect("divide by zero error when dividing duration by scalar")
self.checked_div(rhs).expect("divisor should not be zero")
}
}

Expand All @@ -1434,21 +1434,22 @@ macro_rules! sum_durations {
let mut total_nanos: u64 = 0;

for entry in $iter {
total_secs =
total_secs.checked_add(entry.secs).expect("overflow in iter::sum over durations");
total_secs = total_secs
.checked_add(entry.secs)
.expect("sum over duration iterator should not overflow u64::MAX");
total_nanos = match total_nanos.checked_add(entry.nanos.as_inner() as u64) {
Some(n) => n,
None => {
total_secs = total_secs
.checked_add(total_nanos / NANOS_PER_SEC as u64)
.expect("overflow in iter::sum over durations");
.expect("sum over duration iterator should not overflow u64::MAX");
(total_nanos % NANOS_PER_SEC as u64) + entry.nanos.as_inner() as u64
}
};
}
total_secs = total_secs
.checked_add(total_nanos / NANOS_PER_SEC as u64)
.expect("overflow in iter::sum over durations");
.expect("sum over duration iterator should not overflow u64::MAX");
total_nanos %= NANOS_PER_SEC as u64;
Duration::new(total_secs, total_nanos as u32)
}};
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::formats::item_type::ItemType;
use crate::html::render::{IndexItem, IndexItemInfo};
use crate::visit_lib::RustdocEffectiveVisibilities;

#[derive(Debug)]
pub(crate) struct PathInfo {
/// Parts of the fully qualified path. So in `foo::bar::bib`, it will
/// be `["foo", "bar", "bib"]`.
Expand Down
15 changes: 14 additions & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ fn print_generic_args(generic_args: &clean::GenericArgs, cx: &Context<'_>) -> im
}

// Possible errors when computing href link source for a `DefId`
#[derive(PartialEq, Eq)]
#[derive(PartialEq, Eq, Debug)]
pub(crate) enum HrefError {
/// This item is known to rustdoc, but from a crate that does not have documentation generated.
///
Expand Down Expand Up @@ -338,6 +338,7 @@ pub(crate) enum HrefError {
}

/// Type representing information of an `href` attribute.
#[derive(Debug)]
pub(crate) struct HrefInfo {
/// URL to the item page.
pub(crate) url: String,
Expand Down Expand Up @@ -530,6 +531,18 @@ fn generate_item_def_id_path(
{
def_id = trait_def_id;
} else if let Some(new_def_id) = ty.ty_adt_def().map(|adt| adt.did()) {
// If the inferred item is available in the local path map, it means we're reexporting
// from the current crate, so better use the local path directly.
if cx.cache().paths.contains_key(&new_def_id)
&& let Ok(mut info) =
href_with_jump_to_def_path_depth(new_def_id, cx, jump_to_def_path_depth, None)
{
let kind = ItemType::from_def_id(original_def_id, tcx);
// We need to append the anchor to the URL otherwise we're just linking to the
// parent item...
info.url = format!("{}#{kind}.{}", info.url, tcx.item_name(original_def_id));
return Ok(info);
}
def_id = new_def_id;
maybe_have_impl_not_in_def_crate = !of_trait
&& !original_def_id.is_local()
Expand Down
21 changes: 21 additions & 0 deletions tests/rustdoc-html/jump-to-def/incoherent_impl-inlined.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ aux-build: incoherent_impl1.rs
//@ aux-build: incoherent_impl2.rs
//@ build-aux-docs
//@ compile-flags: -Zunstable-options --generate-link-to-definition

#![crate_name = "foo"]

extern crate incoherent_impl1;
extern crate incoherent_impl2;

pub use incoherent_impl2::Error;

//@ has 'src/foo/incoherent_impl-inlined.rs.html'
//@ has - '//pre//a[@href="../../foo/struct.Error.html#method.new"]' 'new'

//@ has 'foo/struct.Error.html'
//@ has - '//*[@id="method.new"]' 'pub fn new() -> Error'

fn foo() {
let x = Error::new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ LL | check(|| {});
| |
| required by a bound introduced by this call
|
= help: the nightly-only, unstable trait `ConstParamTy_` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}`
help: the nightly-only, unstable trait `ConstParamTy_` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}`
--> $DIR/const_param_ty_bad.rs:8:11
|
LL | check(|| {});
| ^^
note: required by a bound in `check`
--> $DIR/const_param_ty_bad.rs:4:18
|
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/methods/filter-relevant-fn-bounds.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ LL | wrapper.do_something_wrapper(|value| ());
| |
| required by a bound introduced by this call
|
= help: the trait `for<'a> Output<'a>` is not implemented for closure `{closure@$DIR/filter-relevant-fn-bounds.rs:18:34: 18:41}`
help: the trait `for<'a> Output<'a>` is not implemented for closure `{closure@$DIR/filter-relevant-fn-bounds.rs:18:34: 18:41}`
--> $DIR/filter-relevant-fn-bounds.rs:18:34
|
LL | wrapper.do_something_wrapper(|value| ());
| ^^^^^^^
help: this trait has no implementations, consider adding one
--> $DIR/filter-relevant-fn-bounds.rs:1:1
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ LL | let _ = (-10..=10).find(|x: i32| x.signum() == 0);
| |
| required by a bound introduced by this call
|
= help: the trait `for<'a> FnMut(&'a {integer})` is not implemented for closure `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:6:29: 6:37}`
help: the trait `for<'a> FnMut(&'a {integer})` is not implemented for closure `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:6:29: 6:37}`
--> $DIR/closure-arg-type-mismatch-issue-45727.rs:6:29
|
LL | let _ = (-10..=10).find(|x: i32| x.signum() == 0);
| ^^^^^^^^
= note: expected a closure with signature `for<'a> fn(&'a {integer})`
found a closure with signature `fn(i32)`
note: required by a bound in `find`
Expand All @@ -20,7 +24,11 @@ LL | let _ = (-10..=10).find(|x: &&&i32| x.signum() == 0);
| |
| required by a bound introduced by this call
|
= help: the trait `for<'a> FnMut(&'a {integer})` is not implemented for closure `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:9:29: 9:40}`
help: the trait `for<'a> FnMut(&'a {integer})` is not implemented for closure `{closure@$DIR/closure-arg-type-mismatch-issue-45727.rs:9:29: 9:40}`
--> $DIR/closure-arg-type-mismatch-issue-45727.rs:9:29
|
LL | let _ = (-10..=10).find(|x: &&&i32| x.signum() == 0);
| ^^^^^^^^^^^
= note: expected a closure with signature `for<'a> fn(&'a {integer})`
found a closure with signature `fn(&&&i32)`
note: required by a bound in `find`
Expand Down
12 changes: 10 additions & 2 deletions tests/ui/mismatched_types/closure-mismatch.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ LL | baz(|_| ());
| |
| required by a bound introduced by this call
|
= help: the trait `for<'a> FnOnce(&'a ())` is not implemented for closure `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}`
help: the trait `for<'a> FnOnce(&'a ())` is not implemented for closure `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}`
--> $DIR/closure-mismatch.rs:12:9
|
LL | baz(|_| ());
| ^^^
= note: expected a closure with signature `for<'a> fn(&'a ())`
found a closure with signature `fn(&())`
note: required for `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}` to implement `Foo`
Expand All @@ -30,7 +34,11 @@ LL | baz(|x| ());
| |
| required by a bound introduced by this call
|
= help: the trait `for<'a> FnOnce(&'a ())` is not implemented for closure `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}`
help: the trait `for<'a> FnOnce(&'a ())` is not implemented for closure `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}`
--> $DIR/closure-mismatch.rs:16:9
|
LL | baz(|x| ());
| ^^^
= note: expected a closure with signature `for<'a> fn(&'a ())`
found a closure with signature `fn(&())`
note: required for `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}` to implement `Foo`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ LL | bar(closure);
| |
| required by a bound introduced by this call
|
= help: the trait `T` is not implemented for closure `{closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:21}`
help: the trait `T` is not implemented for closure `{closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:21}`
--> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19
|
LL | let closure = || S;
| ^^
note: required by a bound in `bar`
--> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:14:16
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ error[E0277]: `{closure@$DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:33:1
LL | for _ in closure {}
| ^^^^^^^ `{closure@$DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:33:19: 33:21}` is not an iterator
|
= help: the trait `Iterator` is not implemented for closure `{closure@$DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:33:19: 33:21}`
help: the trait `Iterator` is not implemented for closure `{closure@$DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:33:19: 33:21}`
--> $DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:33:19
|
LL | let closure = || vec![1u8].into_iter();
| ^^
= note: required for `{closure@$DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:33:19: 33:21}` to implement `IntoIterator`
help: use parentheses to call this closure
|
Expand All @@ -56,7 +60,11 @@ error[E0277]: `{closure@$DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:36:1
LL | for _ in || vec![1u8].into_iter() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ `{closure@$DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:36:14: 36:16}` is not an iterator
|
= help: the trait `Iterator` is not implemented for closure `{closure@$DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:36:14: 36:16}`
help: the trait `Iterator` is not implemented for closure `{closure@$DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:36:14: 36:16}`
--> $DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:36:14
|
LL | for _ in || vec![1u8].into_iter() {}
| ^^
= note: required for `{closure@$DIR/suggest-calling-fn-in-for-loop-issue-161564.rs:36:14: 36:16}` to implement `IntoIterator`
help: use parentheses to call this closure
|
Expand Down
Loading
Loading