Skip to content

Commit

Permalink
Auto merge of #71111 - Dylan-DPC:rollup-esp17qn, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #70654 (Explain how to work with subtree)
 - #71092 (Remove some usage of `DUMMY_HIR_ID`)
 - #71103 (Add test case for type aliasing `impl Sized`)
 - #71109 (allow const generics in const fn)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Apr 13, 2020
2 parents 8e18e26 + dd27462 commit 47f4969
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 73 deletions.
66 changes: 64 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,70 @@ with one another are rolled up.
Speaking of tests, Rust has a comprehensive test suite. More information about
it can be found [here][rctd].

### External Dependencies
### External Dependencies (subtree)

As a developer to this repository, you don't have to treat the following external projects
differently from other crates that are directly in this repo:

* none so far, see https://github.com/rust-lang/rust/issues/70651 for more info

They are just regular files and directories. This is in contrast to `submodule` dependencies
(see below for those). Only tool authors will actually use any operations here.

#### Synchronizing a subtree

There are two synchronization directions: `subtree push` and `subtree pull`.

```
git subtree push -P src/tools/clippy git@github.com:your-github-name/rust-clippy sync-from-rust
```

takes all the changes that
happened to the copy in this repo and creates commits on the remote repo that match the local
changes. Every local commit that touched the subtree causes a commit on the remote repo, but is
modified to move the files from the specified directory to the tool repo root.

Make sure to not pick the `master` branch on the tool repo, so you can open a normal PR to the tool
to merge that subrepo push.

```
git subtree pull -P src/tools/clippy https://github.com/rust-lang/rust-clippy master
```

takes all changes since the last `subtree pull` from the tool repo
repo and adds these commits to the rustc repo + a merge commit that moves the tool changes into
the specified directory in the rust repository.

It is recommended that you always do a push first and get that merged to the tool master branch.
Then, when you do a pull, the merge works without conflicts.
While it's definitely possible to resolve conflicts during a pull, you may have to redo the conflict
resolution if your PR doesn't get merged fast enough and there are new conflicts. Do not try to
rebase the result of a `git subtree pull`, rebasing merge commits is a bad idea in general.

You always need to specify the `-P` prefix to the subtree directory and the corresponding remote
repository. If you specify the wrong directory or repository
you'll get very fun merges that try to push the wrong directory to the wrong remote repository.
Luckily you can just abort this without any consequences by throwing away either the pulled commits
in rustc or the pushed branch on the remote and try again. It is usually fairly obvious
that this is happening because you suddenly get thousands of commits that want to be synchronized.

#### Creating a new subtree dependency

If you want to create a new subtree dependency from an existing repository, call (from this
repository's root directory!)

```
git subtree add -P src/tools/clippy https://github.com/rust-lang/rust-clippy.git master
```

This will create a new commit, which you may not rebase under any circumstances! Delete the commit
and redo the operation if you need to rebase.

Now you're done, the `src/tools/clippy` directory behaves as if clippy were part of the rustc
monorepo, so no one but you (or others that synchronize subtrees) actually needs to use `git subtree`.


### External Dependencies (submodules)

Currently building Rust will also build the following external projects:

Expand Down Expand Up @@ -221,7 +284,6 @@ before the PR is merged.

Rust's build system builds a number of tools that make use of the
internals of the compiler. This includes
[Clippy](https://github.com/rust-lang/rust-clippy),
[RLS](https://github.com/rust-lang/rls) and
[rustfmt](https://github.com/rust-lang/rustfmt). If these tools
break because of your changes, you may run into a sort of "chicken and egg"
Expand Down
25 changes: 1 addition & 24 deletions src/librustc_ast_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,28 +561,6 @@ impl<'a> AstValidator<'a> {
}
}

/// We currently do not permit const generics in `const fn`,
/// as this is tantamount to allowing compile-time dependent typing.
///
/// FIXME(const_generics): Is this really true / necessary? Discuss with @varkor.
/// At any rate, the restriction feels too syntactic. Consider moving it to e.g. typeck.
fn check_const_fn_const_generic(&self, span: Span, sig: &FnSig, generics: &Generics) {
if let Const::Yes(const_span) = sig.header.constness {
// Look for const generics and error if we find any.
for param in &generics.params {
if let GenericParamKind::Const { .. } = param.kind {
self.err_handler()
.struct_span_err(
span,
"const parameters are not permitted in const functions",
)
.span_label(const_span, "`const` because of this")
.emit();
}
}
}
}

fn check_item_named(&self, ident: Ident, kind: &str) {
if ident.name != kw::Underscore {
return;
Expand Down Expand Up @@ -966,9 +944,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
.emit();
}
}
ItemKind::Fn(def, ref sig, ref generics, ref body) => {
ItemKind::Fn(def, _, _, ref body) => {
self.check_defaultness(item.span, def);
self.check_const_fn_const_generic(item.span, sig, generics);

if body.is_none() {
let msg = "free function without a body";
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn msg_span_from_early_bound_and_free_regions(
let sm = tcx.sess.source_map();

let scope = region.free_region_binding_scope(tcx);
let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
let node = tcx.hir().as_local_hir_id(scope).unwrap();
let tag = match tcx.hir().find(node) {
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
Some(Node::Item(it)) => item_scope_tag(&it),
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,15 +1354,15 @@ declare_lint! {
}

pub struct UnnameableTestItems {
boundary: hir::HirId, // HirId of the item under which things are not nameable
boundary: Option<hir::HirId>, // HirId of the item under which things are not nameable
items_nameable: bool,
}

impl_lint_pass!(UnnameableTestItems => [UNNAMEABLE_TEST_ITEMS]);

impl UnnameableTestItems {
pub fn new() -> Self {
Self { boundary: hir::DUMMY_HIR_ID, items_nameable: true }
Self { boundary: None, items_nameable: true }
}
}

Expand All @@ -1372,7 +1372,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems {
if let hir::ItemKind::Mod(..) = it.kind {
} else {
self.items_nameable = false;
self.boundary = it.hir_id;
self.boundary = Some(it.hir_id);
}
return;
}
Expand All @@ -1385,7 +1385,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems {
}

fn check_item_post(&mut self, _cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
if !self.items_nameable && self.boundary == it.hir_id {
if !self.items_nameable && self.boundary == Some(it.hir_id) {
self.items_nameable = true;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ declare_lint! {
#[derive(Copy, Clone)]
pub struct TypeLimits {
/// Id of the last visited negated expression
negated_expr_id: hir::HirId,
negated_expr_id: Option<hir::HirId>,
}

impl_lint_pass!(TypeLimits => [UNUSED_COMPARISONS, OVERFLOWING_LITERALS]);

impl TypeLimits {
pub fn new() -> TypeLimits {
TypeLimits { negated_expr_id: hir::DUMMY_HIR_ID }
TypeLimits { negated_expr_id: None }
}
}

Expand Down Expand Up @@ -244,7 +244,7 @@ fn lint_int_literal<'a, 'tcx>(
let int_type = t.normalize(cx.sess().target.ptr_width);
let (min, max) = int_ty_range(int_type);
let max = max as u128;
let negative = type_limits.negated_expr_id == e.hir_id;
let negative = type_limits.negated_expr_id == Some(e.hir_id);

// Detect literal value out of range [min, max] inclusive
// avoiding use of -min to prevent overflow/panic
Expand Down Expand Up @@ -397,8 +397,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
match e.kind {
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
// propagate negation, if the negation itself isn't negated
if self.negated_expr_id != e.hir_id {
self.negated_expr_id = expr.hir_id;
if self.negated_expr_id != Some(e.hir_id) {
self.negated_expr_id = Some(expr.hir_id);
}
}
hir::ExprKind::Binary(binop, ref l, ref r) => {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ impl DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {
struct NamePrivacyVisitor<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
tables: &'a ty::TypeckTables<'tcx>,
current_item: hir::HirId,
current_item: Option<hir::HirId>,
empty_tables: &'a ty::TypeckTables<'tcx>,
}

Expand All @@ -1028,7 +1028,7 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
) {
// definition of the field
let ident = Ident::new(kw::Invalid, use_ctxt);
let current_hir = self.current_item;
let current_hir = self.current_item.unwrap();
let def_id = self.tcx.adjust_ident_and_get_scope(ident, def.did, current_hir).1;
if !def.is_enum() && !field.vis.is_accessible_from(def_id, self.tcx) {
let label = if in_update_syntax {
Expand Down Expand Up @@ -1074,7 +1074,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> {
}

fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
let orig_current_item = mem::replace(&mut self.current_item, item.hir_id);
let orig_current_item = mem::replace(&mut self.current_item, Some(item.hir_id));
let orig_tables =
mem::replace(&mut self.tables, item_tables(self.tcx, item.hir_id, self.empty_tables));
intravisit::walk_item(self, item);
Expand Down Expand Up @@ -2059,7 +2059,7 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: DefId) {
let mut visitor = NamePrivacyVisitor {
tcx,
tables: &empty_tables,
current_item: hir::DUMMY_HIR_ID,
current_item: None,
empty_tables: &empty_tables,
};
let (module, span, hir_id) = tcx.hir().get_module(module_def_id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_traits/implied_outlives_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn compute_implied_outlives_bounds<'tcx>(
// unresolved inference variables here anyway, but there might be
// during typeck under some circumstances.)
let obligations =
wf::obligations(infcx, param_env, hir::DUMMY_HIR_ID, ty, DUMMY_SP).unwrap_or(vec![]);
wf::obligations(infcx, param_env, hir::CRATE_HIR_ID, ty, DUMMY_SP).unwrap_or(vec![]);

// N.B., all of these predicates *ought* to be easily proven
// true. In fact, their correctness is (mostly) implied by
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ty/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
let unnormalized_env =
ty::ParamEnv::new(tcx.intern_predicates(&predicates), traits::Reveal::UserFacing, None);

let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| {
let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::CRATE_HIR_ID, |id| {
tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.hir_id)
});
let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);
Expand Down
10 changes: 3 additions & 7 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span,
expected: Ty<'tcx>,
checked_ty: Ty<'tcx>,
hir_id: hir::HirId,
) -> Vec<AssocItem> {
let mut methods = self.probe_for_return_type(
span,
probe::Mode::MethodCall,
expected,
checked_ty,
hir::DUMMY_HIR_ID,
);
let mut methods =
self.probe_for_return_type(span, probe::Mode::MethodCall, expected, checked_ty, hir_id);
methods.retain(|m| {
self.has_no_input_arg(m)
&& self
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ fn method_autoderef_steps<'tcx>(
tcx.infer_ctxt().enter_with_canonical(DUMMY_SP, &goal, |ref infcx, goal, inference_vars| {
let ParamEnvAnd { param_env, value: self_ty } = goal;

let mut autoderef = Autoderef::new(infcx, param_env, hir::DUMMY_HIR_ID, DUMMY_SP, self_ty)
let mut autoderef = Autoderef::new(infcx, param_env, hir::CRATE_HIR_ID, DUMMY_SP, self_ty)
.include_raw_pointers()
.silence_errors();
let mut reached_raw_pointer = false;
Expand Down Expand Up @@ -1512,7 +1512,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
);
pcx.allow_similar_names = true;
pcx.assemble_inherent_candidates();
pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)?;

let method_names = pcx.candidate_method_names();
pcx.allow_similar_names = false;
Expand All @@ -1522,10 +1521,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
pcx.reset();
pcx.method_name = Some(method_name);
pcx.assemble_inherent_candidates();
pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)
.map_or(None, |_| {
pcx.pick_core().and_then(|pick| pick.ok()).map(|pick| pick.item)
})
pcx.pick_core().and_then(|pick| pick.ok()).map(|pick| pick.item)
})
.collect();

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4981,7 +4981,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else if !self.check_for_cast(err, expr, found, expected) {
let is_struct_pat_shorthand_field =
self.is_hir_id_from_struct_pattern_shorthand_field(expr.hir_id, expr.span);
let methods = self.get_conversion_methods(expr.span, expected, found);
let methods = self.get_conversion_methods(expr.span, expected, found, expr.hir_id);
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
let mut suggestions = iter::repeat(&expr_text)
.zip(methods.iter())
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/const-fn-with-const-param.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// run-pass
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash

const fn const_u32_identity<const X: u32>() -> u32 {
//~^ ERROR const parameters are not permitted in const functions
X
}

fn main() {
println!("{:?}", const_u32_identity::<18>());
assert_eq!(const_u32_identity::<18>(), 18);
}
17 changes: 2 additions & 15 deletions src/test/ui/const-generics/const-fn-with-const-param.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
error: const parameters are not permitted in const functions
--> $DIR/const-fn-with-const-param.rs:4:1
|
LL | const fn const_u32_identity<const X: u32>() -> u32 {
| ^----
| |
| _`const` because of this
| |
LL | |
LL | | X
LL | | }
| |_^

warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/const-fn-with-const-param.rs:1:12
--> $DIR/const-fn-with-const-param.rs:2:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error: aborting due to previous error; 1 warning emitted
warning: 1 warning emitted

17 changes: 17 additions & 0 deletions src/test/ui/type-alias-impl-trait/type-alias-impl-trait-sized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// check-pass

#![feature(type_alias_impl_trait)]

type A = impl Sized;
fn f1() -> A { 0 }

type B = impl ?Sized;
fn f2() -> &'static B { &[0] }

type C = impl ?Sized + 'static;
fn f3() -> &'static C { &[0] }

type D = impl ?Sized;
fn f4() -> &'static D { &1 }

fn main() {}

0 comments on commit 47f4969

Please sign in to comment.