Skip to content

Commit 47f4969

Browse files
committed
Auto merge of rust-lang#71111 - Dylan-DPC:rollup-esp17qn, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - rust-lang#70654 (Explain how to work with subtree) - rust-lang#71092 (Remove some usage of `DUMMY_HIR_ID`) - rust-lang#71103 (Add test case for type aliasing `impl Sized`) - rust-lang#71109 (allow const generics in const fn) Failed merges: r? @ghost
2 parents 8e18e26 + dd27462 commit 47f4969

File tree

14 files changed

+108
-73
lines changed

14 files changed

+108
-73
lines changed

CONTRIBUTING.md

+64-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,70 @@ with one another are rolled up.
188188
Speaking of tests, Rust has a comprehensive test suite. More information about
189189
it can be found [here][rctd].
190190

191-
### External Dependencies
191+
### External Dependencies (subtree)
192+
193+
As a developer to this repository, you don't have to treat the following external projects
194+
differently from other crates that are directly in this repo:
195+
196+
* none so far, see https://github.com/rust-lang/rust/issues/70651 for more info
197+
198+
They are just regular files and directories. This is in contrast to `submodule` dependencies
199+
(see below for those). Only tool authors will actually use any operations here.
200+
201+
#### Synchronizing a subtree
202+
203+
There are two synchronization directions: `subtree push` and `subtree pull`.
204+
205+
```
206+
git subtree push -P src/tools/clippy git@github.com:your-github-name/rust-clippy sync-from-rust
207+
```
208+
209+
takes all the changes that
210+
happened to the copy in this repo and creates commits on the remote repo that match the local
211+
changes. Every local commit that touched the subtree causes a commit on the remote repo, but is
212+
modified to move the files from the specified directory to the tool repo root.
213+
214+
Make sure to not pick the `master` branch on the tool repo, so you can open a normal PR to the tool
215+
to merge that subrepo push.
216+
217+
```
218+
git subtree pull -P src/tools/clippy https://github.com/rust-lang/rust-clippy master
219+
```
220+
221+
takes all changes since the last `subtree pull` from the tool repo
222+
repo and adds these commits to the rustc repo + a merge commit that moves the tool changes into
223+
the specified directory in the rust repository.
224+
225+
It is recommended that you always do a push first and get that merged to the tool master branch.
226+
Then, when you do a pull, the merge works without conflicts.
227+
While it's definitely possible to resolve conflicts during a pull, you may have to redo the conflict
228+
resolution if your PR doesn't get merged fast enough and there are new conflicts. Do not try to
229+
rebase the result of a `git subtree pull`, rebasing merge commits is a bad idea in general.
230+
231+
You always need to specify the `-P` prefix to the subtree directory and the corresponding remote
232+
repository. If you specify the wrong directory or repository
233+
you'll get very fun merges that try to push the wrong directory to the wrong remote repository.
234+
Luckily you can just abort this without any consequences by throwing away either the pulled commits
235+
in rustc or the pushed branch on the remote and try again. It is usually fairly obvious
236+
that this is happening because you suddenly get thousands of commits that want to be synchronized.
237+
238+
#### Creating a new subtree dependency
239+
240+
If you want to create a new subtree dependency from an existing repository, call (from this
241+
repository's root directory!)
242+
243+
```
244+
git subtree add -P src/tools/clippy https://github.com/rust-lang/rust-clippy.git master
245+
```
246+
247+
This will create a new commit, which you may not rebase under any circumstances! Delete the commit
248+
and redo the operation if you need to rebase.
249+
250+
Now you're done, the `src/tools/clippy` directory behaves as if clippy were part of the rustc
251+
monorepo, so no one but you (or others that synchronize subtrees) actually needs to use `git subtree`.
252+
253+
254+
### External Dependencies (submodules)
192255

193256
Currently building Rust will also build the following external projects:
194257

@@ -221,7 +284,6 @@ before the PR is merged.
221284

222285
Rust's build system builds a number of tools that make use of the
223286
internals of the compiler. This includes
224-
[Clippy](https://github.com/rust-lang/rust-clippy),
225287
[RLS](https://github.com/rust-lang/rls) and
226288
[rustfmt](https://github.com/rust-lang/rustfmt). If these tools
227289
break because of your changes, you may run into a sort of "chicken and egg"

src/librustc_ast_passes/ast_validation.rs

+1-24
Original file line numberDiff line numberDiff line change
@@ -561,28 +561,6 @@ impl<'a> AstValidator<'a> {
561561
}
562562
}
563563

564-
/// We currently do not permit const generics in `const fn`,
565-
/// as this is tantamount to allowing compile-time dependent typing.
566-
///
567-
/// FIXME(const_generics): Is this really true / necessary? Discuss with @varkor.
568-
/// At any rate, the restriction feels too syntactic. Consider moving it to e.g. typeck.
569-
fn check_const_fn_const_generic(&self, span: Span, sig: &FnSig, generics: &Generics) {
570-
if let Const::Yes(const_span) = sig.header.constness {
571-
// Look for const generics and error if we find any.
572-
for param in &generics.params {
573-
if let GenericParamKind::Const { .. } = param.kind {
574-
self.err_handler()
575-
.struct_span_err(
576-
span,
577-
"const parameters are not permitted in const functions",
578-
)
579-
.span_label(const_span, "`const` because of this")
580-
.emit();
581-
}
582-
}
583-
}
584-
}
585-
586564
fn check_item_named(&self, ident: Ident, kind: &str) {
587565
if ident.name != kw::Underscore {
588566
return;
@@ -966,9 +944,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
966944
.emit();
967945
}
968946
}
969-
ItemKind::Fn(def, ref sig, ref generics, ref body) => {
947+
ItemKind::Fn(def, _, _, ref body) => {
970948
self.check_defaultness(item.span, def);
971-
self.check_const_fn_const_generic(item.span, sig, generics);
972949

973950
if body.is_none() {
974951
let msg = "free function without a body";

src/librustc_infer/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn msg_span_from_early_bound_and_free_regions(
191191
let sm = tcx.sess.source_map();
192192

193193
let scope = region.free_region_binding_scope(tcx);
194-
let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
194+
let node = tcx.hir().as_local_hir_id(scope).unwrap();
195195
let tag = match tcx.hir().find(node) {
196196
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
197197
Some(Node::Item(it)) => item_scope_tag(&it),

src/librustc_lint/builtin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1354,15 +1354,15 @@ declare_lint! {
13541354
}
13551355

13561356
pub struct UnnameableTestItems {
1357-
boundary: hir::HirId, // HirId of the item under which things are not nameable
1357+
boundary: Option<hir::HirId>, // HirId of the item under which things are not nameable
13581358
items_nameable: bool,
13591359
}
13601360

13611361
impl_lint_pass!(UnnameableTestItems => [UNNAMEABLE_TEST_ITEMS]);
13621362

13631363
impl UnnameableTestItems {
13641364
pub fn new() -> Self {
1365-
Self { boundary: hir::DUMMY_HIR_ID, items_nameable: true }
1365+
Self { boundary: None, items_nameable: true }
13661366
}
13671367
}
13681368

@@ -1372,7 +1372,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems {
13721372
if let hir::ItemKind::Mod(..) = it.kind {
13731373
} else {
13741374
self.items_nameable = false;
1375-
self.boundary = it.hir_id;
1375+
self.boundary = Some(it.hir_id);
13761376
}
13771377
return;
13781378
}
@@ -1385,7 +1385,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems {
13851385
}
13861386

13871387
fn check_item_post(&mut self, _cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
1388-
if !self.items_nameable && self.boundary == it.hir_id {
1388+
if !self.items_nameable && self.boundary == Some(it.hir_id) {
13891389
self.items_nameable = true;
13901390
}
13911391
}

src/librustc_lint/types.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ declare_lint! {
4343
#[derive(Copy, Clone)]
4444
pub struct TypeLimits {
4545
/// Id of the last visited negated expression
46-
negated_expr_id: hir::HirId,
46+
negated_expr_id: Option<hir::HirId>,
4747
}
4848

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

5151
impl TypeLimits {
5252
pub fn new() -> TypeLimits {
53-
TypeLimits { negated_expr_id: hir::DUMMY_HIR_ID }
53+
TypeLimits { negated_expr_id: None }
5454
}
5555
}
5656

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

249249
// Detect literal value out of range [min, max] inclusive
250250
// avoiding use of -min to prevent overflow/panic
@@ -397,8 +397,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
397397
match e.kind {
398398
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
399399
// propagate negation, if the negation itself isn't negated
400-
if self.negated_expr_id != e.hir_id {
401-
self.negated_expr_id = expr.hir_id;
400+
if self.negated_expr_id != Some(e.hir_id) {
401+
self.negated_expr_id = Some(expr.hir_id);
402402
}
403403
}
404404
hir::ExprKind::Binary(binop, ref l, ref r) => {

src/librustc_privacy/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ impl DefIdVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {
10121012
struct NamePrivacyVisitor<'a, 'tcx> {
10131013
tcx: TyCtxt<'tcx>,
10141014
tables: &'a ty::TypeckTables<'tcx>,
1015-
current_item: hir::HirId,
1015+
current_item: Option<hir::HirId>,
10161016
empty_tables: &'a ty::TypeckTables<'tcx>,
10171017
}
10181018

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

10761076
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
1077-
let orig_current_item = mem::replace(&mut self.current_item, item.hir_id);
1077+
let orig_current_item = mem::replace(&mut self.current_item, Some(item.hir_id));
10781078
let orig_tables =
10791079
mem::replace(&mut self.tables, item_tables(self.tcx, item.hir_id, self.empty_tables));
10801080
intravisit::walk_item(self, item);
@@ -2059,7 +2059,7 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: DefId) {
20592059
let mut visitor = NamePrivacyVisitor {
20602060
tcx,
20612061
tables: &empty_tables,
2062-
current_item: hir::DUMMY_HIR_ID,
2062+
current_item: None,
20632063
empty_tables: &empty_tables,
20642064
};
20652065
let (module, span, hir_id) = tcx.hir().get_module(module_def_id);

src/librustc_traits/implied_outlives_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn compute_implied_outlives_bounds<'tcx>(
6262
// unresolved inference variables here anyway, but there might be
6363
// during typeck under some circumstances.)
6464
let obligations =
65-
wf::obligations(infcx, param_env, hir::DUMMY_HIR_ID, ty, DUMMY_SP).unwrap_or(vec![]);
65+
wf::obligations(infcx, param_env, hir::CRATE_HIR_ID, ty, DUMMY_SP).unwrap_or(vec![]);
6666

6767
// N.B., all of these predicates *ought* to be easily proven
6868
// true. In fact, their correctness is (mostly) implied by

src/librustc_ty/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
265265
let unnormalized_env =
266266
ty::ParamEnv::new(tcx.intern_predicates(&predicates), traits::Reveal::UserFacing, None);
267267

268-
let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| {
268+
let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::CRATE_HIR_ID, |id| {
269269
tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.hir_id)
270270
});
271271
let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);

src/librustc_typeck/check/demand.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
217217
span: Span,
218218
expected: Ty<'tcx>,
219219
checked_ty: Ty<'tcx>,
220+
hir_id: hir::HirId,
220221
) -> Vec<AssocItem> {
221-
let mut methods = self.probe_for_return_type(
222-
span,
223-
probe::Mode::MethodCall,
224-
expected,
225-
checked_ty,
226-
hir::DUMMY_HIR_ID,
227-
);
222+
let mut methods =
223+
self.probe_for_return_type(span, probe::Mode::MethodCall, expected, checked_ty, hir_id);
228224
methods.retain(|m| {
229225
self.has_no_input_arg(m)
230226
&& self

src/librustc_typeck/check/method/probe.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ fn method_autoderef_steps<'tcx>(
452452
tcx.infer_ctxt().enter_with_canonical(DUMMY_SP, &goal, |ref infcx, goal, inference_vars| {
453453
let ParamEnvAnd { param_env, value: self_ty } = goal;
454454

455-
let mut autoderef = Autoderef::new(infcx, param_env, hir::DUMMY_HIR_ID, DUMMY_SP, self_ty)
455+
let mut autoderef = Autoderef::new(infcx, param_env, hir::CRATE_HIR_ID, DUMMY_SP, self_ty)
456456
.include_raw_pointers()
457457
.silence_errors();
458458
let mut reached_raw_pointer = false;
@@ -1512,7 +1512,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15121512
);
15131513
pcx.allow_similar_names = true;
15141514
pcx.assemble_inherent_candidates();
1515-
pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)?;
15161515

15171516
let method_names = pcx.candidate_method_names();
15181517
pcx.allow_similar_names = false;
@@ -1522,10 +1521,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15221521
pcx.reset();
15231522
pcx.method_name = Some(method_name);
15241523
pcx.assemble_inherent_candidates();
1525-
pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)
1526-
.map_or(None, |_| {
1527-
pcx.pick_core().and_then(|pick| pick.ok()).map(|pick| pick.item)
1528-
})
1524+
pcx.pick_core().and_then(|pick| pick.ok()).map(|pick| pick.item)
15291525
})
15301526
.collect();
15311527

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4981,7 +4981,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
49814981
} else if !self.check_for_cast(err, expr, found, expected) {
49824982
let is_struct_pat_shorthand_field =
49834983
self.is_hir_id_from_struct_pattern_shorthand_field(expr.hir_id, expr.span);
4984-
let methods = self.get_conversion_methods(expr.span, expected, found);
4984+
let methods = self.get_conversion_methods(expr.span, expected, found, expr.hir_id);
49854985
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
49864986
let mut suggestions = iter::repeat(&expr_text)
49874987
.zip(methods.iter())
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
// run-pass
12
#![feature(const_generics)]
23
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
34

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

99
fn main() {
10-
println!("{:?}", const_u32_identity::<18>());
10+
assert_eq!(const_u32_identity::<18>(), 18);
1111
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
error: const parameters are not permitted in const functions
2-
--> $DIR/const-fn-with-const-param.rs:4:1
3-
|
4-
LL | const fn const_u32_identity<const X: u32>() -> u32 {
5-
| ^----
6-
| |
7-
| _`const` because of this
8-
| |
9-
LL | |
10-
LL | | X
11-
LL | | }
12-
| |_^
13-
141
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
15-
--> $DIR/const-fn-with-const-param.rs:1:12
2+
--> $DIR/const-fn-with-const-param.rs:2:12
163
|
174
LL | #![feature(const_generics)]
185
| ^^^^^^^^^^^^^^
196
|
207
= note: `#[warn(incomplete_features)]` on by default
218

22-
error: aborting due to previous error; 1 warning emitted
9+
warning: 1 warning emitted
2310

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
type A = impl Sized;
6+
fn f1() -> A { 0 }
7+
8+
type B = impl ?Sized;
9+
fn f2() -> &'static B { &[0] }
10+
11+
type C = impl ?Sized + 'static;
12+
fn f3() -> &'static C { &[0] }
13+
14+
type D = impl ?Sized;
15+
fn f4() -> &'static D { &1 }
16+
17+
fn main() {}

0 commit comments

Comments
 (0)