Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #91596

Closed
wants to merge 13 commits into from
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
13 changes: 8 additions & 5 deletions compiler/rustc_infer/src/infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,6 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
if let Some(def_id) = def_id.as_local() {
let opaque_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let parent_def_id = self.infcx.defining_use_anchor;
let def_scope_default = || {
let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id);
parent_def_id == tcx.hir().local_def_id(opaque_parent_hir_id)
};
let (in_definition_scope, origin) = match tcx.hir().expect_item(def_id).kind
{
// Anonymous `impl Trait`
Expand All @@ -481,7 +477,14 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
}) => {
(may_define_opaque_type(tcx, parent_def_id, opaque_hir_id), origin)
}
_ => (def_scope_default(), hir::OpaqueTyOrigin::TyAlias),
ref itemkind => {
span_bug!(
self.value_span,
"weird opaque type: {:#?}, {:#?}",
ty.kind(),
itemkind
)
}
};
if in_definition_scope {
let opaque_type_key =
Expand Down
25 changes: 11 additions & 14 deletions compiler/rustc_typeck/src/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> bool /* did we suggest to call a function because of missing parentheses? */ {
err.span_label(span, ty.to_string());
if let FnDef(def_id, _) = *ty.kind() {
let source_map = self.tcx.sess.source_map();
if !self.tcx.has_typeck_results(def_id) {
return false;
}
Expand All @@ -517,20 +516,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.lookup_op_method(fn_sig.output(), &[other_ty], Op::Binary(op, is_assign))
.is_ok()
{
if let Ok(snippet) = source_map.span_to_snippet(span) {
let (variable_snippet, applicability) = if !fn_sig.inputs().is_empty() {
(format!("{}( /* arguments */ )", snippet), Applicability::HasPlaceholders)
} else {
(format!("{}()", snippet), Applicability::MaybeIncorrect)
};
let (variable_snippet, applicability) = if !fn_sig.inputs().is_empty() {
("( /* arguments */ )".to_string(), Applicability::HasPlaceholders)
} else {
("()".to_string(), Applicability::MaybeIncorrect)
};

err.span_suggestion(
span,
"you might have forgotten to call this function",
variable_snippet,
applicability,
);
}
err.span_suggestion_verbose(
span.shrink_to_hi(),
"you might have forgotten to call this function",
variable_snippet,
applicability,
);
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// Note that the allocator may give the collection more space than it
/// requests. Therefore, capacity can not be relied upon to be precisely
/// minimal. Prefer [`reserve`] if future insertions are expected.
/// minimal. Prefer [`try_reserve`] if future insertions are expected.
///
/// [`reserve`]: VecDeque::reserve
/// [`try_reserve`]: VecDeque::try_reserve
///
/// # Errors
///
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,9 @@ impl String {
///
/// Note that the allocator may give the collection more space than it
/// requests. Therefore, capacity can not be relied upon to be precisely
/// minimal. Prefer [`reserve`] if future insertions are expected.
/// minimal. Prefer [`try_reserve`] if future insertions are expected.
///
/// [`reserve`]: String::reserve
/// [`try_reserve`]: String::try_reserve
///
/// # Errors
///
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,9 @@ impl<T, A: Allocator> Vec<T, A> {
///
/// Note that the allocator may give the collection more space than it
/// requests. Therefore, capacity can not be relied upon to be precisely
/// minimal. Prefer [`reserve`] if future insertions are expected.
/// minimal. Prefer [`try_reserve`] if future insertions are expected.
///
/// [`reserve`]: Vec::reserve
/// [`try_reserve`]: Vec::try_reserve
///
/// # Errors
///
Expand Down
21 changes: 9 additions & 12 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,28 +583,25 @@ pub fn home_dir() -> Option<PathBuf> {
/// may result in "insecure temporary file" security vulnerabilities. Consider
/// using a crate that securely creates temporary files or directories.
///
/// # Unix
/// # Platform-specific behavior
///
/// Returns the value of the `TMPDIR` environment variable if it is
/// On Unix, returns the value of the `TMPDIR` environment variable if it is
/// set, otherwise for non-Android it returns `/tmp`. If Android, since there
/// is no global temporary folder (it is usually allocated per-app), it returns
/// `/data/local/tmp`.
/// On Windows, the behavior is equivalent to that of [`GetTempPath2`][GetTempPath2] /
/// [`GetTempPath`][GetTempPath], which this function uses internally.
/// Note that, this [may change in the future][changes].
///
/// # Windows
///
/// Returns the value of, in order, the `TMP`, `TEMP`,
/// `USERPROFILE` environment variable if any are set and not the empty
/// string. Otherwise, `temp_dir` returns the path of the Windows directory.
/// This behavior is identical to that of [`GetTempPath`][msdn], which this
/// function uses internally.
///
/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha
/// [changes]: io#platform-specific-behavior
/// [GetTempPath2]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a
/// [GetTempPath]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha
///
/// ```no_run
/// use std::env;
///
/// fn main() {
/// let mut dir = env::temp_dir();
/// let dir = env::temp_dir();
/// println!("Temporary directory: {}", dir.display());
/// }
/// ```
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/sys/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,12 @@ compat_fn! {
-> () {
GetSystemTimeAsFileTime(lpSystemTimeAsFileTime)
}

// >= Win11 / Server 2022
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a
pub fn GetTempPath2W(nBufferLength: DWORD, lpBuffer: LPCWSTR) -> DWORD {
GetTempPathW(nBufferLength, lpBuffer)
}
}

compat_fn! {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/windows/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
}

pub fn temp_dir() -> PathBuf {
super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPathW(sz, buf) }, super::os2path).unwrap()
super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPath2W(sz, buf) }, super::os2path).unwrap()
}

#[cfg(not(target_vendor = "uwp"))]
Expand Down
118 changes: 118 additions & 0 deletions src/test/incremental/issue-85360-eval-obligation-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// revisions:cfail1 cfail2
//[cfail1] compile-flags: --crate-type=lib --edition=2021 -Zassert-incr-state=not-loaded
//[cfail2] compile-flags: --crate-type=lib --edition=2021 -Zassert-incr-state=loaded
// build-pass

use core::any::Any;
use core::marker::PhantomData;

struct DerefWrap<T>(T);

impl<T> core::ops::Deref for DerefWrap<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}

struct Storage<T, D> {
phantom: PhantomData<(T, D)>,
}

type ReadStorage<T> = Storage<T, DerefWrap<MaskedStorage<T>>>;

pub trait Component {
type Storage;
}

struct VecStorage;

struct Pos;

impl Component for Pos {
type Storage = VecStorage;
}

struct GenericComp<T> {
_t: T,
}

impl<T: 'static> Component for GenericComp<T> {
type Storage = VecStorage;
}
struct ReadData {
pos_interpdata: ReadStorage<GenericComp<Pos>>,
}

trait System {
type SystemData;

fn run(data: Self::SystemData, any: Box<dyn Any>);
}

struct Sys;

impl System for Sys {
type SystemData = (ReadData, ReadStorage<Pos>);

fn run((data, pos): Self::SystemData, any: Box<dyn Any>) {
<ReadStorage<GenericComp<Pos>> as SystemData>::setup(any);

ParJoin::par_join((&pos, &data.pos_interpdata));
}
}

trait ParJoin {
fn par_join(self)
where
Self: Sized,
{
}
}

impl<'a, T, D> ParJoin for &'a Storage<T, D>
where
T: Component,
D: core::ops::Deref<Target = MaskedStorage<T>>,
T::Storage: Sync,
{
}

impl<A, B> ParJoin for (A, B)
where
A: ParJoin,
B: ParJoin,
{
}

pub trait SystemData {
fn setup(any: Box<dyn Any>);
}

impl<T: 'static> SystemData for ReadStorage<T>
where
T: Component,
{
fn setup(any: Box<dyn Any>) {
let storage: &MaskedStorage<T> = any.downcast_ref().unwrap();

<dyn Any as CastFrom<MaskedStorage<T>>>::cast(&storage);
}
}

pub struct MaskedStorage<T: Component> {
_inner: T::Storage,
}

pub unsafe trait CastFrom<T> {
fn cast(t: &T) -> &Self;
}

unsafe impl<T> CastFrom<T> for dyn Any
where
T: Any + 'static,
{
fn cast(t: &T) -> &Self {
t
}
}
4 changes: 2 additions & 2 deletions src/test/ui/fn/fn-compare-mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ LL | let x = f == g;
help: you might have forgotten to call this function
|
LL | let x = f() == g;
| ~~~
| ++
help: you might have forgotten to call this function
|
LL | let x = f == g();
| ~~~
| ++

error[E0308]: mismatched types
--> $DIR/fn-compare-mismatch.rs:4:18
Expand Down
16 changes: 12 additions & 4 deletions src/test/ui/issues/issue-59488.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ LL | foo > 12;
| --- ^ -- {integer}
| |
| fn() -> i32 {foo}
| help: you might have forgotten to call this function: `foo()`
|
help: you might have forgotten to call this function
|
LL | foo() > 12;
| ++

error[E0308]: mismatched types
--> $DIR/issue-59488.rs:14:11
Expand All @@ -23,7 +27,11 @@ LL | bar > 13;
| --- ^ -- {integer}
| |
| fn(i64) -> i64 {bar}
| help: you might have forgotten to call this function: `bar( /* arguments */ )`
|
help: you might have forgotten to call this function
|
LL | bar( /* arguments */ ) > 13;
| +++++++++++++++++++

error[E0308]: mismatched types
--> $DIR/issue-59488.rs:18:11
Expand All @@ -45,11 +53,11 @@ LL | foo > foo;
help: you might have forgotten to call this function
|
LL | foo() > foo;
| ~~~~~
| ++
help: you might have forgotten to call this function
|
LL | foo > foo();
| ~~~~~
| ++

error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}`
--> $DIR/issue-59488.rs:25:9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ LL | assert_eq!(a, 0);
| |
| fn() -> i32 {a}
| {integer}
| help: you might have forgotten to call this function: `*left_val()`
|
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you might have forgotten to call this function
|
LL | if !(*left_val() == *right_val) {
| ++

error[E0308]: mismatched types
--> $DIR/issue-70724-add_type_neq_err_label-unwrap.rs:6:5
Expand Down
Loading