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 14 pull requests #87923

Merged
merged 34 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
38c07c7
Implement `Printer` for `&mut SymbolPrinter`
tmiasko Jul 29, 2021
ecb6686
Expand explanation of E0530
kornelski Aug 2, 2021
2a56a4f
removed references to parent/child from std::thread documentation
godmar Aug 7, 2021
eefd790
impl const From<num> for num
usbalbin Dec 27, 2020
09928a9
Add tests
usbalbin Mar 13, 2021
c8bf5ed
Add test for int to float
usbalbin Aug 7, 2021
d777cb8
less opt in const param of
BoxyUwU Aug 7, 2021
5f61271
fmt
BoxyUwU Aug 7, 2021
9a78489
Fix heading colours in Ayu theme
tsoutsman Aug 8, 2021
a4af040
Clarify terms in rustdoc book
tsoutsman Aug 8, 2021
f93cbed
Do not ICE on HIR based WF check when involving lifetimes
estebank Aug 6, 2021
24aa45c
add `windows` count test
lcnr Aug 9, 2021
3e123e4
Remove duplicate trait bounds in `rustc_data_structures::graph`
pierwill Aug 9, 2021
cb19d83
Proper table row formatting in platform support
badboy Aug 9, 2021
bc4ce79
Added the `Option::unzip()` method
Kixiron Jul 30, 2021
eea3520
Added some basic tests for `Option::unzip()` and `Option::zip()` (I n…
Kixiron Jul 30, 2021
9d8081e
Enabled unzip_option feature for core tests & unzip docs
Kixiron Jul 31, 2021
ab2c590
Added tracking issue to unstable attribute
Kixiron Aug 5, 2021
f3021b3
Use smaller spans when suggesting method call disambiguation
estebank Aug 9, 2021
cda6ecf
typeck: better diagnostics for missing inaccessible fields in struct …
TheWastl Aug 10, 2021
3b41447
Rollup merge of #86840 - usbalbin:const_from, r=oli-obk
JohnTitor Aug 10, 2021
43b7cad
Rollup merge of #87582 - tmiasko:symbol-printer, r=michaelwoerister
JohnTitor Aug 10, 2021
bdc92f1
Rollup merge of #87636 - Kixiron:unzip-option, r=scottmcm
JohnTitor Aug 10, 2021
4442806
Rollup merge of #87700 - kornelski:e530text, r=oli-obk
JohnTitor Aug 10, 2021
bcef40e
Rollup merge of #87811 - estebank:issue-87549, r=oli-obk
JohnTitor Aug 10, 2021
6412bf9
Rollup merge of #87848 - godmar:@godmar/thread-join-documentation-fix…
JohnTitor Aug 10, 2021
6c92656
Rollup merge of #87854 - BoxyUwU:var-None, r=oli-obk
JohnTitor Aug 10, 2021
deee28a
Rollup merge of #87861 - tsoutsman:patch-1, r=GuillaumeGomez
JohnTitor Aug 10, 2021
b9b8f5b
Rollup merge of #87865 - tsoutsman:master, r=GuillaumeGomez
JohnTitor Aug 10, 2021
9d21b5a
Rollup merge of #87876 - lcnr:windows_no_panic, r=m-ou-se
JohnTitor Aug 10, 2021
e72754d
Rollup merge of #87880 - pierwill:graph-duplicate-trait-bound, r=LeSe…
JohnTitor Aug 10, 2021
22f864e
Rollup merge of #87881 - badboy:platform-support-formatting, r=ehuss
JohnTitor Aug 10, 2021
4d4915a
Rollup merge of #87889 - estebank:method-call-disambiguate, r=oli-obk
JohnTitor Aug 10, 2021
4be63b2
Rollup merge of #87895 - TheWastl:issue-87872, r=estebank
JohnTitor Aug 10, 2021
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_data_structures/src/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,13 @@ pub trait WithStartNode: DirectedGraph {
}

pub trait ControlFlowGraph:
DirectedGraph + WithStartNode + WithPredecessors + WithStartNode + WithSuccessors + WithNumNodes
DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors + WithNumNodes
{
// convenient trait
}

impl<T> ControlFlowGraph for T where
T: DirectedGraph
+ WithStartNode
+ WithPredecessors
+ WithStartNode
+ WithSuccessors
+ WithNumNodes
T: DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors + WithNumNodes
{
}

Expand Down
53 changes: 39 additions & 14 deletions compiler/rustc_error_codes/src/error_codes/E0530.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
A binding shadowed something it shouldn't.

Erroneous code example:
A match arm or a variable has a name that is already used by
something else, e.g.

* struct name
* enum variant
* static
* associated constant

This error may also happen when an enum variant *with fields* is used
in a pattern, but without its fields.

```compile_fail
enum Enum {
WithField(i32)
}

use Enum::*;
match WithField(1) {
WithField => {} // error: missing (_)
}
```

Match bindings cannot shadow statics:

```compile_fail,E0530
static TEST: i32 = 0;

let r: (i32, i32) = (0, 0);
let r = 123;
match r {
TEST => {} // error: match bindings cannot shadow statics
TEST => {} // error: name of a static
}
```

To fix this error, just change the binding's name in order to avoid shadowing
one of the following:
Fixed examples:

* struct name
* struct/enum variant
* static
* const
* associated const
```
static TEST: i32 = 0;

Fixed example:
let r = 123;
match r {
some_value => {} // ok!
}
```

or

```
static TEST: i32 = 0;
const TEST: i32 = 0; // const, not static

let r: (i32, i32) = (0, 0);
let r = 123;
match r {
something => {} // ok!
TEST => {} // const is ok!
other_values => {}
}
```
11 changes: 6 additions & 5 deletions compiler/rustc_symbol_mangling/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ pub(super) fn mangle(

let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate);

let mut printer = SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false }
let mut printer = SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false };
printer
.print_def_path(
def_id,
if let ty::InstanceDef::DropGlue(_, _) = instance.def {
Expand Down Expand Up @@ -198,7 +199,7 @@ struct SymbolPrinter<'tcx> {
// `PrettyPrinter` aka pretty printing of e.g. types in paths,
// symbol names should have their own printing machinery.

impl Printer<'tcx> for SymbolPrinter<'tcx> {
impl Printer<'tcx> for &mut SymbolPrinter<'tcx> {
type Error = fmt::Error;

type Path = Self;
Expand Down Expand Up @@ -242,7 +243,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
Ok(self)
}

fn print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
fn print_const(self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
// only print integers
if let ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int { .. })) = ct.val {
if ct.ty.is_integral() {
Expand All @@ -253,7 +254,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
Ok(self)
}

fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
self.write_str(&self.tcx.crate_name(cnum).as_str())?;
Ok(self)
}
Expand Down Expand Up @@ -344,7 +345,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
}
}

impl PrettyPrinter<'tcx> for SymbolPrinter<'tcx> {
impl PrettyPrinter<'tcx> for &mut SymbolPrinter<'tcx> {
fn region_should_not_be_omitted(&self, _region: ty::Region<'_>) -> bool {
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let ObligationCauseCode::WellFormed(Some(wf_loc)) =
root_obligation.cause.code.peel_derives()
{
if let Some(cause) =
self.tcx.diagnostic_hir_wf_check((obligation.predicate, wf_loc.clone()))
{
if let Some(cause) = self.tcx.diagnostic_hir_wf_check((
tcx.erase_regions(obligation.predicate),
wf_loc.clone(),
)) {
obligation.cause = cause;
span = obligation.cause.span;
}
Expand Down
17 changes: 7 additions & 10 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,15 +1313,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.emit();
}
} else if check_completeness && !error_happened && !remaining_fields.is_empty() {
let no_accessible_remaining_fields = remaining_fields
.iter()
.find(|(_, (_, field))| {
field.vis.is_accessible_from(tcx.parent_module(expr_id).to_def_id(), tcx)
})
.is_none();
let inaccessible_remaining_fields = remaining_fields.iter().any(|(_, (_, field))| {
!field.vis.is_accessible_from(tcx.parent_module(expr_id).to_def_id(), tcx)
});

if no_accessible_remaining_fields {
self.report_no_accessible_fields(adt_ty, span);
if inaccessible_remaining_fields {
self.report_inaccessible_fields(adt_ty, span);
} else {
self.report_missing_fields(adt_ty, span, remaining_fields);
}
Expand Down Expand Up @@ -1398,7 +1395,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.emit();
}

/// Report an error for a struct field expression when there are no visible fields.
/// Report an error for a struct field expression when there are invisible fields.
///
/// ```text
/// error: cannot construct `Foo` with struct literal syntax due to inaccessible fields
Expand All @@ -1409,7 +1406,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
///
/// error: aborting due to previous error
/// ```
fn report_no_accessible_fields(&self, adt_ty: Ty<'tcx>, span: Span) {
fn report_inaccessible_fields(&self, adt_ty: Ty<'tcx>, span: Span) {
self.tcx.sess.span_err(
span,
&format!(
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_typeck/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,8 +1695,8 @@ fn print_disambiguation_help(
source_map: &source_map::SourceMap,
) {
let mut applicability = Applicability::MachineApplicable;
let sugg_args = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) {
format!(
let (span, sugg) = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) {
let args = format!(
"({}{})",
if rcvr_ty.is_region_ptr() {
if rcvr_ty.is_mutable_ptr() { "&mut " } else { "&" }
Expand All @@ -1710,12 +1710,12 @@ fn print_disambiguation_help(
}))
.collect::<Vec<_>>()
.join(", "),
)
);
(span, format!("{}::{}{}", trait_name, item_name, args))
} else {
String::new()
(span.with_hi(item_name.span.lo()), format!("{}::", trait_name))
};
let sugg = format!("{}::{}{}", trait_name, item_name, sugg_args);
err.span_suggestion(
err.span_suggestion_verbose(
span,
&format!(
"disambiguate the {} for {}",
Expand Down
32 changes: 22 additions & 10 deletions compiler/rustc_typeck/src/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,15 +1250,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
tcx.sess.struct_span_err(pat.span, "`..` cannot be used in union patterns").emit();
}
} else if !etc && !unmentioned_fields.is_empty() {
let no_accessible_unmentioned_fields = !unmentioned_fields.iter().any(|(field, _)| {
field.vis.is_accessible_from(tcx.parent_module(pat.hir_id).to_def_id(), tcx)
});
let accessible_unmentioned_fields: Vec<_> = unmentioned_fields
.iter()
.copied()
.filter(|(field, _)| {
field.vis.is_accessible_from(tcx.parent_module(pat.hir_id).to_def_id(), tcx)
})
.collect();

if no_accessible_unmentioned_fields {
if accessible_unmentioned_fields.is_empty() {
unmentioned_err = Some(self.error_no_accessible_fields(pat, &fields));
} else {
unmentioned_err =
Some(self.error_unmentioned_fields(pat, &unmentioned_fields, &fields));
unmentioned_err = Some(self.error_unmentioned_fields(
pat,
&accessible_unmentioned_fields,
accessible_unmentioned_fields.len() != unmentioned_fields.len(),
&fields,
));
}
}
match (inexistent_fields_err, unmentioned_err) {
Expand Down Expand Up @@ -1583,17 +1591,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
pat: &Pat<'_>,
unmentioned_fields: &[(&ty::FieldDef, Ident)],
have_inaccessible_fields: bool,
fields: &'tcx [hir::PatField<'tcx>],
) -> DiagnosticBuilder<'tcx> {
let inaccessible = if have_inaccessible_fields { " and inaccessible fields" } else { "" };
let field_names = if unmentioned_fields.len() == 1 {
format!("field `{}`", unmentioned_fields[0].1)
format!("field `{}`{}", unmentioned_fields[0].1, inaccessible)
} else {
let fields = unmentioned_fields
.iter()
.map(|(_, name)| format!("`{}`", name))
.collect::<Vec<String>>()
.join(", ");
format!("fields {}", fields)
format!("fields {}{}", fields, inaccessible)
};
let mut err = struct_span_err!(
self.tcx.sess,
Expand Down Expand Up @@ -1624,17 +1634,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_suggestion(
sp,
&format!(
"include the missing field{} in the pattern",
"include the missing field{} in the pattern{}",
if len == 1 { "" } else { "s" },
if have_inaccessible_fields { " and ignore the inaccessible fields" } else { "" }
),
format!(
"{}{}{}",
"{}{}{}{}",
prefix,
unmentioned_fields
.iter()
.map(|(_, name)| name.to_string())
.collect::<Vec<_>>()
.join(", "),
if have_inaccessible_fields { ", .." } else { "" },
postfix,
),
Applicability::MachineApplicable,
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,12 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
// Try to use the segment resolution if it is valid, otherwise we
// default to the path resolution.
let res = segment.res.filter(|&r| r != Res::Err).unwrap_or(path.res);
use def::CtorOf;
let generics = match res {
Res::Def(DefKind::Ctor(..), def_id) => {
Res::Def(DefKind::Ctor(CtorOf::Variant, _), def_id) => tcx.generics_of(
tcx.parent(def_id).and_then(|def_id| tcx.parent(def_id)).unwrap(),
),
Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Struct, _), def_id) => {
tcx.generics_of(tcx.parent(def_id).unwrap())
}
// Other `DefKind`s don't have generics and would ICE when calling
Expand All @@ -200,7 +204,6 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
DefKind::Struct
| DefKind::Union
| DefKind::Enum
| DefKind::Variant
| DefKind::Trait
| DefKind::OpaqueTy
| DefKind::TyAlias
Expand Down
15 changes: 10 additions & 5 deletions library/core/src/convert/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ impl_float_to_int!(f64 => u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
macro_rules! impl_from {
($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => {
#[$attr]
impl From<$Small> for $Large {
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
impl const From<$Small> for $Large {
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
// Rustdocs on functions do not.
#[doc = $doc]
Expand Down Expand Up @@ -172,7 +173,8 @@ impl_from! { f32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
macro_rules! try_from_unbounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.34.0")]
impl TryFrom<$source> for $target {
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
impl const TryFrom<$source> for $target {
type Error = TryFromIntError;

/// Try to create the target number type from a source
Expand All @@ -190,7 +192,8 @@ macro_rules! try_from_unbounded {
macro_rules! try_from_lower_bounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.34.0")]
impl TryFrom<$source> for $target {
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
impl const TryFrom<$source> for $target {
type Error = TryFromIntError;

/// Try to create the target number type from a source
Expand All @@ -212,7 +215,8 @@ macro_rules! try_from_lower_bounded {
macro_rules! try_from_upper_bounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.34.0")]
impl TryFrom<$source> for $target {
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
impl const TryFrom<$source> for $target {
type Error = TryFromIntError;

/// Try to create the target number type from a source
Expand All @@ -234,7 +238,8 @@ macro_rules! try_from_upper_bounded {
macro_rules! try_from_both_bounded {
($source:ty, $($target:ty),*) => {$(
#[stable(feature = "try_from", since = "1.34.0")]
impl TryFrom<$source> for $target {
#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")]
impl const TryFrom<$source> for $target {
type Error = TryFromIntError;

/// Try to create the target number type from a source
Expand Down
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
#![feature(const_slice_from_raw_parts)]
#![feature(const_slice_ptr_len)]
#![feature(const_swap)]
#![feature(const_trait_impl)]
#![feature(const_type_id)]
#![feature(const_type_name)]
#![feature(const_unreachable_unchecked)]
Expand Down
Loading