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 11 pull requests #87333

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
05dcb78
Dont provide all parent generics to cgdefaults
BoxyUwU Jun 23, 2021
b44be27
Moves changes to explicit_preds_of/inferred_outlives_of/generics_of
BoxyUwU Jul 10, 2021
e276b86
redo tests
BoxyUwU Jul 10, 2021
8c40360
Put checking if anonct is a default into a method on hir map
BoxyUwU Jul 13, 2021
8462a37
avoid temporary vectors
matthiaskrgr Jul 16, 2021
abfd44d
Comments
BoxyUwU Jul 17, 2021
d05a286
Iterate through impls only when permitted
fee1-dead Jul 19, 2021
4b82bbe
Recognize bounds on impls as const bounds
fee1-dead Jul 19, 2021
7066398
Don't render <table> in items' summary
GuillaumeGomez Jul 19, 2021
d6dc840
Add test to ensure tables are not inside items summary
GuillaumeGomez Jul 19, 2021
76ab8a6
:arrow_up: rust-analyzer
lnicola Jul 19, 2021
2a56a68
Add comments explaining the unix command-line argument support.
sunfishcode Jul 19, 2021
64f4e34
Fix typo in compile.rs
Jul 20, 2021
b9b0a5e
Fix VecMap::iter_mut
oli-obk Jul 19, 2021
75d9ed7
Make mir borrowck's use of opaque types independent of the typeck que…
oli-obk Jul 19, 2021
df04b98
Use instrument debugging for more readable logs
oli-obk Jul 20, 2021
1ad1b94
Remove an unnecessary variable
oli-obk Jul 20, 2021
07e11e8
docs: GlobalAlloc: completely replace example with one that works
ijackson Feb 7, 2021
b3aca47
Resolve nested inference variables.
oli-obk Jul 20, 2021
db0324e
Support HIR wf checking for function signatures
Aaron1011 Jul 18, 2021
713044c
Add a regression test
oli-obk Jul 20, 2021
919a8a5
Fix NixOS detection
oxalica Jul 16, 2021
9a888ea
Rollup merge of #81864 - ijackson:globalalloc-example, r=Amanieu
Dylan-DPC Jul 21, 2021
2d05209
Rollup merge of #86580 - BoxyUwU:cgd-subst-ice, r=nikomatsakis
Dylan-DPC Jul 21, 2021
2cc7e85
Rollup merge of #87187 - oxalica:fix-nixos-detect, r=nagisa
Dylan-DPC Jul 21, 2021
2fac195
Rollup merge of #87206 - matthiaskrgr:clippy_collect, r=davidtwco
Dylan-DPC Jul 21, 2021
f4236cc
Rollup merge of #87265 - Aaron1011:hir-wf-fn, r=estebank
Dylan-DPC Jul 21, 2021
a08e0bf
Rollup merge of #87270 - GuillaumeGomez:item-summary-table, r=notriddle
Dylan-DPC Jul 21, 2021
554987a
Rollup merge of #87273 - fee1-dead:impl-const-impl-bounds, r=oli-obk
Dylan-DPC Jul 21, 2021
09e62b1
Rollup merge of #87278 - lnicola:rust-analyzer-2021-07-19, r=lnicola
Dylan-DPC Jul 21, 2021
30c4f2f
Rollup merge of #87279 - sunfishcode:document-unix-argv, r=RalfJung
Dylan-DPC Jul 21, 2021
1c60b82
Rollup merge of #87287 - oli-obk:fixup_fixup_fixup_opaque_types, r=sp…
Dylan-DPC Jul 21, 2021
0141149
Rollup merge of #87301 - chinmaydd:chinmaydd-patch-1-1, r=jyn514
Dylan-DPC Jul 21, 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
10 changes: 3 additions & 7 deletions compiler/rustc_builtin_macros/src/deriving/generic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,9 @@ impl Path {
) -> ast::Path {
let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect();
let lt = mk_lifetimes(cx, span, &self.lifetime);
let tys: Vec<P<ast::Ty>> =
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
let params = lt
.into_iter()
.map(GenericArg::Lifetime)
.chain(tys.into_iter().map(GenericArg::Type))
.collect();
let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics));
let params =
lt.into_iter().map(GenericArg::Lifetime).chain(tys.map(GenericArg::Type)).collect();

match self.kind {
PathKind::Global => cx.path_all(span, true, idents, params),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#![feature(new_uninit)]
#![feature(once_cell)]
#![feature(maybe_uninit_uninit_array)]
#![feature(min_type_alias_impl_trait)]
#![allow(rustc::default_hash_types)]
#![deny(unaligned_references)]

Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_data_structures/src/vec_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Borrow;
use std::iter::FromIterator;
use std::slice::{Iter, IterMut};
use std::slice::Iter;
use std::vec::IntoIter;

use crate::stable_hasher::{HashStable, StableHasher};
Expand Down Expand Up @@ -67,9 +67,13 @@ where
self.into_iter()
}

pub fn iter_mut(&mut self) -> IterMut<'_, (K, V)> {
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)> {
self.into_iter()
}

pub fn retain(&mut self, f: impl Fn(&(K, V)) -> bool) {
self.0.retain(f)
}
}

impl<K, V> Default for VecMap<K, V> {
Expand Down Expand Up @@ -108,12 +112,12 @@ impl<'a, K, V> IntoIterator for &'a VecMap<K, V> {
}

impl<'a, K, V> IntoIterator for &'a mut VecMap<K, V> {
type Item = &'a mut (K, V);
type IntoIter = IterMut<'a, (K, V)>;
type Item = (&'a K, &'a mut V);
type IntoIter = impl Iterator<Item = Self::Item>;

#[inline]
fn into_iter(self) -> Self::IntoIter {
self.0.iter_mut()
self.0.iter_mut().map(|(k, v)| (&*k, v))
}
}

Expand Down
24 changes: 24 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,9 @@ pub type Lit = Spanned<LitKind>;
/// These are usually found nested inside types (e.g., array lengths)
/// or expressions (e.g., repeat counts), and also used to define
/// explicit discriminant values for enum variants.
///
/// You can check if this anon const is a default in a const param
/// `const N: usize = { ... }` with [Map::opt_const_param_default_param_hir_id]
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
pub struct AnonConst {
pub hir_id: HirId,
Expand Down Expand Up @@ -3060,6 +3063,27 @@ impl<'hir> Node<'hir> {
Node::Crate(_) | Node::Visibility(_) => None,
}
}

/// Returns `Constness::Const` when this node is a const fn/impl.
pub fn constness(&self) -> Constness {
match self {
Node::Item(Item {
kind: ItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
..
})
| Node::TraitItem(TraitItem {
kind: TraitItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
..
})
| Node::ImplItem(ImplItem {
kind: ImplItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
..
})
| Node::Item(Item { kind: ItemKind::Impl(Impl { constness, .. }), .. }) => *constness,

_ => Constness::NotConst,
}
}
}

// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let new_lt = generics
.as_ref()
.and_then(|(parent_g, g)| {
let possible: Vec<_> = (b'a'..=b'z').map(|c| format!("'{}", c as char)).collect();
let mut possible = (b'a'..=b'z').map(|c| format!("'{}", c as char));
let mut lts_names = g
.params
.iter()
Expand All @@ -2146,7 +2146,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
);
}
let lts = lts_names.iter().map(|s| -> &str { &*s }).collect::<Vec<_>>();
possible.into_iter().find(|candidate| !lts.contains(&candidate.as_str()))
possible.find(|candidate| !lts.contains(&candidate.as_str()))
})
.unwrap_or("'lt".to_string());
let add_lt_sugg = generics
Expand Down
18 changes: 17 additions & 1 deletion compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
Node::Item(Item { kind: ItemKind::Fn(sig, _, _), .. })
| Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(sig, _), .. })
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(sig, _), .. }) => Some(&sig.decl),
Node::Expr(Expr { kind: ExprKind::Closure(_, fn_decl, ..), .. }) => Some(fn_decl),
Node::Expr(Expr { kind: ExprKind::Closure(_, fn_decl, ..), .. })
| Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, ..), .. }) => {
Some(fn_decl)
}
_ => None,
}
}
Expand Down Expand Up @@ -916,6 +919,19 @@ impl<'hir> Map<'hir> {
pub fn node_to_string(&self, id: HirId) -> String {
hir_id_to_string(self, id)
}

/// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when
/// called with the HirId for the `{ ... }` anon const
pub fn opt_const_param_default_param_hir_id(&self, anon_const: HirId) -> Option<HirId> {
match self.get(self.get_parent_node(anon_const)) {
Node::GenericParam(GenericParam {
hir_id: param_id,
kind: GenericParamKind::Const { .. },
..
}) => Some(*param_id),
_ => None,
}
}
}

impl<'hir> intravisit::Map<'hir> for Map<'hir> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ rustc_queries! {
/// span) for an *existing* error. Therefore, it is best-effort, and may never handle
/// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
/// because the `ty::Ty`-based wfcheck is always run.
query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, hir::HirId)) -> Option<traits::ObligationCause<'tcx>> {
query diagnostic_hir_wf_check(key: (ty::Predicate<'tcx>, traits::WellFormedLoc)) -> Option<traits::ObligationCause<'tcx>> {
eval_always
no_hash
desc { "performing HIR wf-checking for predicate {:?} at item {:?}", key.0, key.1 }
Expand Down
34 changes: 28 additions & 6 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::ty::{self, AdtKind, Ty, TyCtxt};
use rustc_data_structures::sync::Lrc;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::Constness;
use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP};
Expand Down Expand Up @@ -327,17 +327,39 @@ pub enum ObligationCauseCode<'tcx> {
/// If `X` is the concrete type of an opaque type `impl Y`, then `X` must implement `Y`
OpaqueType,

/// Well-formed checking. If a `HirId` is provided,
/// it is used to perform HIR-based wf checking if an error
/// occurs, in order to generate a more precise error message.
/// Well-formed checking. If a `WellFormedLoc` is provided,
/// then it will be used to eprform HIR-based wf checking
/// after an error occurs, in order to generate a more precise error span.
/// This is purely for diagnostic purposes - it is always
/// correct to use `MiscObligation` instead
WellFormed(Option<hir::HirId>),
/// correct to use `MiscObligation` instead, or to specify
/// `WellFormed(None)`
WellFormed(Option<WellFormedLoc>),

/// From `match_impl`. The cause for us having to match an impl, and the DefId we are matching against.
MatchImpl(Lrc<ObligationCauseCode<'tcx>>, DefId),
}

/// The 'location' at which we try to perform HIR-based wf checking.
/// This information is used to obtain an `hir::Ty`, which
/// we can walk in order to obtain precise spans for any
/// 'nested' types (e.g. `Foo` in `Option<Foo>`).
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
pub enum WellFormedLoc {
/// Use the type of the provided definition.
Ty(LocalDefId),
/// Use the type of the parameter of the provided function.
/// We cannot use `hir::Param`, since the function may
/// not have a body (e.g. a trait method definition)
Param {
/// The function to lookup the parameter in
function: LocalDefId,
/// The index of the parameter to use.
/// Parameters are indexed from 0, with the return type
/// being the last 'parameter'
param_idx: u16,
},
}

impl ObligationCauseCode<'_> {
// Return the base obligation, ignoring derived obligations.
pub fn peel_derives(&self) -> &Self {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ nop_list_lift! {bound_variable_kinds; ty::BoundVariableKind => ty::BoundVariable
// This is the impl for `&'a InternalSubsts<'a>`.
nop_list_lift! {substs; GenericArg<'a> => GenericArg<'tcx>}

CloneLiftImpls! { for<'tcx> { Constness, } }
CloneLiftImpls! { for<'tcx> { Constness, traits::WellFormedLoc, } }

pub mod tls {
use super::{ptr_eq, GlobalCtxt, TyCtxt};
Expand Down
Loading