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 6 pull requests #112449

Closed
wants to merge 12 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
8 changes: 7 additions & 1 deletion compiler/rustc_data_structures/src/intern.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::stable_hasher::{HashStable, StableHasher};
use std::cmp::Ordering;
use std::fmt::{self, Debug};
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::ptr;
Expand All @@ -20,7 +21,6 @@ mod private {
/// The `PrivateZst` field means you can pattern match with `Interned(v, _)`
/// but you can only construct a `Interned` with `new_unchecked`, and not
/// directly.
#[derive(Debug)]
#[rustc_pass_by_value]
pub struct Interned<'a, T>(pub &'a T, pub private::PrivateZst);

Expand Down Expand Up @@ -108,5 +108,11 @@ where
}
}

impl<T: Debug> Debug for Interned<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}

#[cfg(test)]
mod tests;
8 changes: 5 additions & 3 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ pub fn pre_configure_attrs(sess: &Session, attrs: &[Attribute]) -> ast::AttrVec
config_tokens: false,
lint_node_id: ast::CRATE_NODE_ID,
};
let attrs: ast::AttrVec =
attrs.iter().flat_map(|attr| strip_unconfigured.process_cfg_attr(attr)).collect();
if strip_unconfigured.in_cfg(&attrs) { attrs } else { ast::AttrVec::new() }
attrs
.iter()
.flat_map(|attr| strip_unconfigured.process_cfg_attr(attr))
.take_while(|attr| !is_cfg(attr) || strip_unconfigured.cfg_true(attr))
.collect()
}

#[macro_export]
Expand Down
20 changes: 16 additions & 4 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,12 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized {
) -> Result<Self::OutputTy, Self> {
Ok(noop_flat_map(node, collector))
}
fn expand_cfg_false(&mut self, collector: &mut InvocationCollector<'_, '_>, span: Span) {
fn expand_cfg_false(
&mut self,
collector: &mut InvocationCollector<'_, '_>,
_pos: usize,
span: Span,
) {
collector.cx.emit_err(RemoveNodeNotSupported { span, descr: Self::descr() });
}

Expand Down Expand Up @@ -1409,8 +1414,15 @@ impl InvocationCollectorNode for ast::Crate {
fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
noop_visit_crate(self, visitor)
}
fn expand_cfg_false(&mut self, collector: &mut InvocationCollector<'_, '_>, _span: Span) {
self.attrs.clear();
fn expand_cfg_false(
&mut self,
collector: &mut InvocationCollector<'_, '_>,
pos: usize,
_span: Span,
) {
// Attributes above `cfg(FALSE)` are left in place, because we may want to configure
// some global crate properties even on fully unconfigured crates.
self.attrs.truncate(pos);
// Standard prelude imports are left in the crate for backward compatibility.
self.items.truncate(collector.cx.num_standard_library_imports);
}
Expand Down Expand Up @@ -1804,7 +1816,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
continue;
}

node.expand_cfg_false(self, span);
node.expand_cfg_false(self, pos, span);
continue;
}
sym::cfg_attr => {
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2081,13 +2081,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
},
_ => {
// prevent all specified fields from being suggested
let skip_fields = skip_fields.iter().map(|x| x.ident.name);
if let Some(field_name) = self.suggest_field_name(
variant,
field.ident.name,
skip_fields.collect(),
expr_span,
) {
let skip_fields: Vec<_> = skip_fields.iter().map(|x| x.ident.name).collect();
if let Some(field_name) =
self.suggest_field_name(variant, field.ident.name, &skip_fields, expr_span)
{
err.span_suggestion(
field.ident.span,
"a field with a similar name exists",
Expand All @@ -2108,9 +2105,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
format!("`{ty}` does not have this field"),
);
}
let available_field_names =
let mut available_field_names =
self.available_field_names(variant, expr_span);
if !available_field_names.is_empty() {
available_field_names
.retain(|name| skip_fields.iter().all(|skip| name != skip));
if available_field_names.is_empty() {
err.note("all struct fields are already assigned");
} else {
err.note(format!(
"available fields are: {}",
self.name_series_display(available_field_names)
Expand All @@ -2130,7 +2131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
variant: &'tcx ty::VariantDef,
field: Symbol,
skip: Vec<Symbol>,
skip: &[Symbol],
// The span where stability will be checked
span: Span,
) -> Option<Symbol> {
Expand Down Expand Up @@ -2582,7 +2583,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
access_span: Span,
) {
if let Some(suggested_field_name) =
self.suggest_field_name(def.non_enum_variant(), field.name, vec![], access_span)
self.suggest_field_name(def.non_enum_variant(), field.name, &[], access_span)
{
err.span_suggestion(
field.span,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// They can denote both statically and dynamically-sized byte arrays.
let mut pat_ty = ty;
if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(..), .. }) = lt.kind {
let expected = self.structurally_resolved_type(span, expected);
if let ty::Ref(_, inner_ty, _) = expected.kind()
&& matches!(inner_ty.kind(), ty::Slice(_))
if let ty::Ref(_, inner_ty, _) = *self.structurally_resolved_type(span, expected).kind()
&& self.structurally_resolved_type(span, inner_ty).is_slice()
{
let tcx = self.tcx;
trace!(?lt.hir_id.local_id, "polymorphic byte string lit");
Expand Down
35 changes: 34 additions & 1 deletion compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,27 @@ fn rustc_generator_to_generator(
}
}

fn rustc_inline_asm_operand_to_inline_asm_operand(
operand: &rustc_middle::mir::InlineAsmOperand<'_>,
) -> stable_mir::mir::InlineAsmOperand {
use rustc_middle::mir::InlineAsmOperand;

let (in_value, out_place) = match operand {
InlineAsmOperand::In { value, .. } => (Some(rustc_op_to_op(value)), None),
InlineAsmOperand::Out { place, .. } => {
(None, place.map(|place| rustc_place_to_place(&place)))
}
InlineAsmOperand::InOut { in_value, out_place, .. } => {
(Some(rustc_op_to_op(in_value)), out_place.map(|place| rustc_place_to_place(&place)))
}
InlineAsmOperand::Const { .. }
| InlineAsmOperand::SymFn { .. }
| InlineAsmOperand::SymStatic { .. } => (None, None),
};

stable_mir::mir::InlineAsmOperand { in_value, out_place, raw_rpr: format!("{:?}", operand) }
}

fn rustc_terminator_to_terminator(
terminator: &rustc_middle::mir::Terminator<'_>,
) -> stable_mir::mir::Terminator {
Expand Down Expand Up @@ -330,7 +351,19 @@ fn rustc_terminator_to_terminator(
target: target.as_usize(),
unwind: rustc_unwind_to_unwind(unwind),
},
InlineAsm { .. } => todo!(),
InlineAsm { template, operands, options, line_spans, destination, unwind } => {
Terminator::InlineAsm {
template: format!("{:?}", template),
operands: operands
.iter()
.map(|operand| rustc_inline_asm_operand_to_inline_asm_operand(operand))
.collect(),
options: format!("{:?}", options),
line_spans: format!("{:?}", line_spans),
destination: destination.map(|d| d.as_usize()),
unwind: rustc_unwind_to_unwind(unwind),
}
}
Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(),
}
}
17 changes: 17 additions & 0 deletions compiler/rustc_smir/src/stable_mir/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ pub enum Terminator {
unwind: UnwindAction,
},
GeneratorDrop,
InlineAsm {
template: String,
operands: Vec<InlineAsmOperand>,
options: String,
line_spans: String,
destination: Option<usize>,
unwind: UnwindAction,
},
}

#[derive(Clone, Debug)]
pub struct InlineAsmOperand {
pub in_value: Option<Operand>,
pub out_place: Option<Place>,
// This field has a raw debug representation of MIR's InlineAsmOperand.
// For now we care about place/operand + the rest in a debug format.
pub raw_rpr: String,
}

#[derive(Clone, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/async-await/drop-track-bad-field-in-fru.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[E0559]: variant `Option<_>::None` has no field named `value`
|
LL | None { value: (), ..Default::default() }.await;
| ^^^^^ `Option<_>::None` does not have this field
|
= note: all struct fields are already assigned

error[E0277]: `Option<_>` is not a future
--> $DIR/drop-track-bad-field-in-fru.rs:7:46
Expand Down
6 changes: 2 additions & 4 deletions tests/ui/cfg/auxiliary/cfg_false_lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// It is unclear whether a fully unconfigured crate should link to standard library,
// or what its `no_std`/`no_core`/`compiler_builtins` status, more precisely.
// Currently the usual standard library prelude is added to such crates,
// and therefore they link to libstd.
// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(FALSE)`.
// This crate has no such attribute, therefore this crate does link to libstd.

#![cfg(FALSE)]
5 changes: 5 additions & 0 deletions tests/ui/cfg/auxiliary/cfg_false_lib_no_std_after.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(FALSE)`.
// Therefore this crate does link to libstd.

#![cfg(FALSE)]
#![no_std]
8 changes: 8 additions & 0 deletions tests/ui/cfg/auxiliary/cfg_false_lib_no_std_before.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(FALSE)`.
// Therefore this crate doesn't link to libstd.

// no-prefer-dynamic

#![no_std]
#![crate_type = "lib"]
#![cfg(FALSE)]
6 changes: 2 additions & 4 deletions tests/ui/cfg/cfg-false-feature.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// It is unclear which features should be in effect in a fully unconfigured crate (issue #104633).
// Currently none on the features are in effect, so we get the feature gates reported.
// Features above `cfg(FALSE)` are in effect in a fully unconfigured crate (issue #104633).

// check-pass
// compile-flags: --crate-type lib
Expand All @@ -8,8 +7,7 @@
#![cfg(FALSE)]
#![feature(box_syntax)]

macro mac() {} //~ WARN `macro` is experimental
//~| WARN unstable syntax can change at any point in the future
macro mac() {} // OK

trait A = Clone; //~ WARN trait aliases are experimental
//~| WARN unstable syntax can change at any point in the future
Expand Down
17 changes: 3 additions & 14 deletions tests/ui/cfg/cfg-false-feature.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: trait aliases are experimental
--> $DIR/cfg-false-feature.rs:14:1
--> $DIR/cfg-false-feature.rs:12:1
|
LL | trait A = Clone;
| ^^^^^^^^^^^^^^^^
Expand All @@ -9,19 +9,8 @@ LL | trait A = Clone;
= warning: unstable syntax can change at any point in the future, causing a hard error!
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>

warning: `macro` is experimental
--> $DIR/cfg-false-feature.rs:11:1
|
LL | macro mac() {}
| ^^^^^^^^^^^^^^
|
= note: see issue #39412 <https://github.com/rust-lang/rust/issues/39412> for more information
= help: add `#![feature(decl_macro)]` to the crate attributes to enable
= warning: unstable syntax can change at any point in the future, causing a hard error!
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>

warning: box pattern syntax is experimental
--> $DIR/cfg-false-feature.rs:18:9
--> $DIR/cfg-false-feature.rs:16:9
|
LL | let box _ = Box::new(0);
| ^^^^^
Expand All @@ -31,5 +20,5 @@ LL | let box _ = Box::new(0);
= warning: unstable syntax can change at any point in the future, causing a hard error!
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>

warning: 3 warnings emitted
warning: 2 warnings emitted

10 changes: 10 additions & 0 deletions tests/ui/cfg/cfg_false_no_std-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// No error, panic handler is supplied by libstd linked though the empty library.

// check-pass
// aux-build: cfg_false_lib_no_std_after.rs

#![no_std]

extern crate cfg_false_lib_no_std_after as _;

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/cfg/cfg_false_no_std-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Error, the linked empty library is `no_std` and doesn't provide a panic handler.

// dont-check-compiler-stderr
// error-pattern: `#[panic_handler]` function required, but not found
// aux-build: cfg_false_lib_no_std_before.rs

#![no_std]

extern crate cfg_false_lib_no_std_before as _;

fn main() {}
3 changes: 1 addition & 2 deletions tests/ui/cfg/cfg_false_no_std.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Currently no error because the panic handler is supplied by libstd linked though the empty
// library, but the desirable behavior is unclear (see comments in cfg_false_lib.rs).
// No error, panic handler is supplied by libstd linked though the empty library.

// check-pass
// aux-build: cfg_false_lib.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error[E0560]: struct `Demo` has no field named `egregiously_nonexistent_field`
LL | Self { secret_integer: 3, egregiously_nonexistent_field: () }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Demo` does not have this field
|
= note: available fields are: `favorite_integer`, `secret_integer`, `innocently_misspellable`, `another_field`, `yet_another_field` ... and 2 others
= note: available fields are: `favorite_integer`, `innocently_misspellable`, `another_field`, `yet_another_field`, `always_more_fields`, `and_ever`

error[E0609]: no field `inocently_mispellable` on type `Demo`
--> $DIR/issue-42599_available_fields_note.rs:32:41
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0560.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0560]: struct `Simba` has no field named `father`
LL | let s = Simba { mother: 1, father: 0 };
| ^^^^^^ `Simba` does not have this field
|
= note: available fields are: `mother`
= note: all struct fields are already assigned

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-5439.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0560]: struct `Foo` has no field named `nonexistent`
LL | return Box::new(Foo { nonexistent: self, foo: i });
| ^^^^^^^^^^^ `Foo` does not have this field
|
= note: available fields are: `foo`
= note: all struct fields are already assigned

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/span-preservation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ error[E0560]: struct `Foo` has no field named `b`
LL | let y = Foo { a: 10, b: 10isize };
| ^ `Foo` does not have this field
|
= note: available fields are: `a`
= note: all struct fields are already assigned

error[E0308]: mismatched types
--> $DIR/span-preservation.rs:39:5
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/structs/struct-field-cfg.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error[E0560]: struct `Foo` has no field named `absent`
LL | let _ = Foo { present: (), #[cfg(all())] absent: () };
| ^^^^^^ `Foo` does not have this field
|
= note: available fields are: `present`
= note: all struct fields are already assigned

error[E0027]: pattern does not mention field `present`
--> $DIR/struct-field-cfg.rs:13:9
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/structs/struct-fields-shorthand.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0560]: struct `Foo` has no field named `z`
LL | x, y, z
| ^ `Foo` does not have this field
|
= note: available fields are: `x`, `y`
= note: all struct fields are already assigned

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/structs/struct-fields-too-many.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0560]: struct `BuildData` has no field named `bar`
LL | bar: 0
| ^^^ `BuildData` does not have this field
|
= note: available fields are: `foo`
= note: all struct fields are already assigned

error: aborting due to previous error

Expand Down
Loading